hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/drivers/staging/fsl-dpaa2/ethsw/ethsw-ethtool.c
....@@ -12,7 +12,7 @@
1212 static struct {
1313 enum dpsw_counter id;
1414 char name[ETH_GSTRING_LEN];
15
-} ethsw_ethtool_counters[] = {
15
+} dpaa2_switch_ethtool_counters[] = {
1616 {DPSW_CNT_ING_FRAME, "rx frames"},
1717 {DPSW_CNT_ING_BYTE, "rx bytes"},
1818 {DPSW_CNT_ING_FLTR_FRAME, "rx filtered frames"},
....@@ -27,10 +27,10 @@
2727
2828 };
2929
30
-#define ETHSW_NUM_COUNTERS ARRAY_SIZE(ethsw_ethtool_counters)
30
+#define DPAA2_SWITCH_NUM_COUNTERS ARRAY_SIZE(dpaa2_switch_ethtool_counters)
3131
32
-static void ethsw_get_drvinfo(struct net_device *netdev,
33
- struct ethtool_drvinfo *drvinfo)
32
+static void dpaa2_switch_get_drvinfo(struct net_device *netdev,
33
+ struct ethtool_drvinfo *drvinfo)
3434 {
3535 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
3636 u16 version_major, version_minor;
....@@ -53,8 +53,8 @@
5353 }
5454
5555 static int
56
-ethsw_get_link_ksettings(struct net_device *netdev,
57
- struct ethtool_link_ksettings *link_ksettings)
56
+dpaa2_switch_get_link_ksettings(struct net_device *netdev,
57
+ struct ethtool_link_ksettings *link_ksettings)
5858 {
5959 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
6060 struct dpsw_link_state state = {0};
....@@ -65,7 +65,7 @@
6565 port_priv->idx,
6666 &state);
6767 if (err) {
68
- netdev_err(netdev, "ERROR %d getting link state", err);
68
+ netdev_err(netdev, "ERROR %d getting link state\n", err);
6969 goto out;
7070 }
7171
....@@ -84,22 +84,25 @@
8484 }
8585
8686 static int
87
-ethsw_set_link_ksettings(struct net_device *netdev,
88
- const struct ethtool_link_ksettings *link_ksettings)
87
+dpaa2_switch_set_link_ksettings(struct net_device *netdev,
88
+ const struct ethtool_link_ksettings *link_ksettings)
8989 {
9090 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
91
+ struct ethsw_core *ethsw = port_priv->ethsw_data;
9192 struct dpsw_link_cfg cfg = {0};
92
- int err = 0;
93
+ bool if_running;
94
+ int err = 0, ret;
9395
94
- netdev_dbg(netdev, "Setting link parameters...");
95
-
96
- /* Due to a temporary MC limitation, the DPSW port must be down
97
- * in order to be able to change link settings. Taking steps to let
98
- * the user know that.
99
- */
100
- if (netif_running(netdev)) {
101
- netdev_info(netdev, "Sorry, interface must be brought down first.\n");
102
- return -EACCES;
96
+ /* Interface needs to be down to change link settings */
97
+ if_running = netif_running(netdev);
98
+ if (if_running) {
99
+ err = dpsw_if_disable(ethsw->mc_io, 0,
100
+ ethsw->dpsw_handle,
101
+ port_priv->idx);
102
+ if (err) {
103
+ netdev_err(netdev, "dpsw_if_disable err %d\n", err);
104
+ return err;
105
+ }
103106 }
104107
105108 cfg.rate = link_ksettings->base.speed;
....@@ -116,67 +119,69 @@
116119 port_priv->ethsw_data->dpsw_handle,
117120 port_priv->idx,
118121 &cfg);
119
- if (err)
120
- /* ethtool will be loud enough if we return an error; no point
121
- * in putting our own error message on the console by default
122
- */
123
- netdev_dbg(netdev, "ERROR %d setting link cfg", err);
124122
123
+ if (if_running) {
124
+ ret = dpsw_if_enable(ethsw->mc_io, 0,
125
+ ethsw->dpsw_handle,
126
+ port_priv->idx);
127
+ if (ret) {
128
+ netdev_err(netdev, "dpsw_if_enable err %d\n", ret);
129
+ return ret;
130
+ }
131
+ }
125132 return err;
126133 }
127134
128
-static int ethsw_ethtool_get_sset_count(struct net_device *dev, int sset)
135
+static int dpaa2_switch_ethtool_get_sset_count(struct net_device *dev, int sset)
129136 {
130137 switch (sset) {
131138 case ETH_SS_STATS:
132
- return ETHSW_NUM_COUNTERS;
139
+ return DPAA2_SWITCH_NUM_COUNTERS;
133140 default:
134141 return -EOPNOTSUPP;
135142 }
136143 }
137144
138
-static void ethsw_ethtool_get_strings(struct net_device *netdev,
139
- u32 stringset, u8 *data)
145
+static void dpaa2_switch_ethtool_get_strings(struct net_device *netdev,
146
+ u32 stringset, u8 *data)
140147 {
141148 int i;
142149
143150 switch (stringset) {
144151 case ETH_SS_STATS:
145
- for (i = 0; i < ETHSW_NUM_COUNTERS; i++)
152
+ for (i = 0; i < DPAA2_SWITCH_NUM_COUNTERS; i++)
146153 memcpy(data + i * ETH_GSTRING_LEN,
147
- ethsw_ethtool_counters[i].name, ETH_GSTRING_LEN);
154
+ dpaa2_switch_ethtool_counters[i].name,
155
+ ETH_GSTRING_LEN);
148156 break;
149157 }
150158 }
151159
152
-static void ethsw_ethtool_get_stats(struct net_device *netdev,
153
- struct ethtool_stats *stats,
154
- u64 *data)
160
+static void dpaa2_switch_ethtool_get_stats(struct net_device *netdev,
161
+ struct ethtool_stats *stats,
162
+ u64 *data)
155163 {
156164 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
157165 int i, err;
158166
159
- memset(data, 0,
160
- sizeof(u64) * ETHSW_NUM_COUNTERS);
161
-
162
- for (i = 0; i < ETHSW_NUM_COUNTERS; i++) {
167
+ for (i = 0; i < DPAA2_SWITCH_NUM_COUNTERS; i++) {
163168 err = dpsw_if_get_counter(port_priv->ethsw_data->mc_io, 0,
164169 port_priv->ethsw_data->dpsw_handle,
165170 port_priv->idx,
166
- ethsw_ethtool_counters[i].id,
171
+ dpaa2_switch_ethtool_counters[i].id,
167172 &data[i]);
168173 if (err)
169174 netdev_err(netdev, "dpsw_if_get_counter[%s] err %d\n",
170
- ethsw_ethtool_counters[i].name, err);
175
+ dpaa2_switch_ethtool_counters[i].name, err);
171176 }
172177 }
173178
174
-const struct ethtool_ops ethsw_port_ethtool_ops = {
175
- .get_drvinfo = ethsw_get_drvinfo,
179
+const struct ethtool_ops dpaa2_switch_port_ethtool_ops = {
180
+ .get_drvinfo = dpaa2_switch_get_drvinfo,
176181 .get_link = ethtool_op_get_link,
177
- .get_link_ksettings = ethsw_get_link_ksettings,
178
- .set_link_ksettings = ethsw_set_link_ksettings,
179
- .get_strings = ethsw_ethtool_get_strings,
180
- .get_ethtool_stats = ethsw_ethtool_get_stats,
181
- .get_sset_count = ethsw_ethtool_get_sset_count,
182
+ .get_link_ksettings = dpaa2_switch_get_link_ksettings,
183
+ .set_link_ksettings = dpaa2_switch_set_link_ksettings,
184
+ .get_strings = dpaa2_switch_ethtool_get_strings,
185
+ .get_ethtool_stats = dpaa2_switch_ethtool_get_stats,
186
+ .get_sset_count = dpaa2_switch_ethtool_get_sset_count,
182187 };