1 /*
2 * linux/drivers/net/ehea/ehea_ethtool.c
3 *
4 * eHEA ethernet device driver for IBM eServer System p
5 *
6 * (C) Copyright IBM Corp. 2006
7 *
8 * Authors:
9 * Christoph Raisch <raisch@de.ibm.com>
10 * Jan-Bernd Themann <themann@de.ibm.com>
11 * Thomas Klein <tklein@de.ibm.com>
12 *
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
17 * any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 */
28
29 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
31 #include "ehea.h"
32 #include "ehea_phyp.h"
33
ehea_get_settings(struct net_device * dev,struct ethtool_cmd * cmd)34 static int ehea_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
35 {
36 struct ehea_port *port = netdev_priv(dev);
37 int ret;
38
39 ret = ehea_sense_port_attr(port);
40
41 if (ret)
42 return ret;
43
44 if (netif_carrier_ok(dev)) {
45 switch (port->port_speed) {
46 case EHEA_SPEED_10M: cmd->speed = SPEED_10; break;
47 case EHEA_SPEED_100M: cmd->speed = SPEED_100; break;
48 case EHEA_SPEED_1G: cmd->speed = SPEED_1000; break;
49 case EHEA_SPEED_10G: cmd->speed = SPEED_10000; break;
50 }
51 cmd->duplex = port->full_duplex == 1 ?
52 DUPLEX_FULL : DUPLEX_HALF;
53 } else {
54 cmd->speed = -1;
55 cmd->duplex = -1;
56 }
57
58 if (cmd->speed == SPEED_10000) {
59 cmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
60 cmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
61 cmd->port = PORT_FIBRE;
62 } else {
63 cmd->supported = (SUPPORTED_1000baseT_Full | SUPPORTED_100baseT_Full
64 | SUPPORTED_100baseT_Half | SUPPORTED_10baseT_Full
65 | SUPPORTED_10baseT_Half | SUPPORTED_Autoneg
66 | SUPPORTED_TP);
67 cmd->advertising = (ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg
68 | ADVERTISED_TP);
69 cmd->port = PORT_TP;
70 }
71
72 cmd->autoneg = port->autoneg == 1 ? AUTONEG_ENABLE : AUTONEG_DISABLE;
73
74 return 0;
75 }
76
ehea_set_settings(struct net_device * dev,struct ethtool_cmd * cmd)77 static int ehea_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
78 {
79 struct ehea_port *port = netdev_priv(dev);
80 int ret = 0;
81 u32 sp;
82
83 if (cmd->autoneg == AUTONEG_ENABLE) {
84 sp = EHEA_SPEED_AUTONEG;
85 goto doit;
86 }
87
88 switch (cmd->speed) {
89 case SPEED_10:
90 if (cmd->duplex == DUPLEX_FULL)
91 sp = H_SPEED_10M_F;
92 else
93 sp = H_SPEED_10M_H;
94 break;
95
96 case SPEED_100:
97 if (cmd->duplex == DUPLEX_FULL)
98 sp = H_SPEED_100M_F;
99 else
100 sp = H_SPEED_100M_H;
101 break;
102
103 case SPEED_1000:
104 if (cmd->duplex == DUPLEX_FULL)
105 sp = H_SPEED_1G_F;
106 else
107 ret = -EINVAL;
108 break;
109
110 case SPEED_10000:
111 if (cmd->duplex == DUPLEX_FULL)
112 sp = H_SPEED_10G_F;
113 else
114 ret = -EINVAL;
115 break;
116
117 default:
118 ret = -EINVAL;
119 break;
120 }
121
122 if (ret)
123 goto out;
124 doit:
125 ret = ehea_set_portspeed(port, sp);
126
127 if (!ret)
128 netdev_info(dev,
129 "Port speed successfully set: %dMbps %s Duplex\n",
130 port->port_speed,
131 port->full_duplex == 1 ? "Full" : "Half");
132 out:
133 return ret;
134 }
135
ehea_nway_reset(struct net_device * dev)136 static int ehea_nway_reset(struct net_device *dev)
137 {
138 struct ehea_port *port = netdev_priv(dev);
139 int ret;
140
141 ret = ehea_set_portspeed(port, EHEA_SPEED_AUTONEG);
142
143 if (!ret)
144 netdev_info(port->netdev,
145 "Port speed successfully set: %dMbps %s Duplex\n",
146 port->port_speed,
147 port->full_duplex == 1 ? "Full" : "Half");
148 return ret;
149 }
150
ehea_get_drvinfo(struct net_device * dev,struct ethtool_drvinfo * info)151 static void ehea_get_drvinfo(struct net_device *dev,
152 struct ethtool_drvinfo *info)
153 {
154 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
155 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
156 }
157
ehea_get_msglevel(struct net_device * dev)158 static u32 ehea_get_msglevel(struct net_device *dev)
159 {
160 struct ehea_port *port = netdev_priv(dev);
161 return port->msg_enable;
162 }
163
ehea_set_msglevel(struct net_device * dev,u32 value)164 static void ehea_set_msglevel(struct net_device *dev, u32 value)
165 {
166 struct ehea_port *port = netdev_priv(dev);
167 port->msg_enable = value;
168 }
169
ehea_get_rx_csum(struct net_device * dev)170 static u32 ehea_get_rx_csum(struct net_device *dev)
171 {
172 return 1;
173 }
174
175 static char ehea_ethtool_stats_keys[][ETH_GSTRING_LEN] = {
176 {"sig_comp_iv"},
177 {"swqe_refill_th"},
178 {"port resets"},
179 {"Receive errors"},
180 {"TCP cksum errors"},
181 {"IP cksum errors"},
182 {"Frame cksum errors"},
183 {"num SQ stopped"},
184 {"SQ stopped"},
185 {"PR0 free_swqes"},
186 {"PR1 free_swqes"},
187 {"PR2 free_swqes"},
188 {"PR3 free_swqes"},
189 {"PR4 free_swqes"},
190 {"PR5 free_swqes"},
191 {"PR6 free_swqes"},
192 {"PR7 free_swqes"},
193 {"LRO aggregated"},
194 {"LRO flushed"},
195 {"LRO no_desc"},
196 };
197
ehea_get_strings(struct net_device * dev,u32 stringset,u8 * data)198 static void ehea_get_strings(struct net_device *dev, u32 stringset, u8 *data)
199 {
200 if (stringset == ETH_SS_STATS) {
201 memcpy(data, &ehea_ethtool_stats_keys,
202 sizeof(ehea_ethtool_stats_keys));
203 }
204 }
205
ehea_get_sset_count(struct net_device * dev,int sset)206 static int ehea_get_sset_count(struct net_device *dev, int sset)
207 {
208 switch (sset) {
209 case ETH_SS_STATS:
210 return ARRAY_SIZE(ehea_ethtool_stats_keys);
211 default:
212 return -EOPNOTSUPP;
213 }
214 }
215
ehea_get_ethtool_stats(struct net_device * dev,struct ethtool_stats * stats,u64 * data)216 static void ehea_get_ethtool_stats(struct net_device *dev,
217 struct ethtool_stats *stats, u64 *data)
218 {
219 int i, k, tmp;
220 struct ehea_port *port = netdev_priv(dev);
221
222 for (i = 0; i < ehea_get_sset_count(dev, ETH_SS_STATS); i++)
223 data[i] = 0;
224 i = 0;
225
226 data[i++] = port->sig_comp_iv;
227 data[i++] = port->port_res[0].swqe_refill_th;
228 data[i++] = port->resets;
229
230 for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++)
231 tmp += port->port_res[k].p_stats.poll_receive_errors;
232 data[i++] = tmp;
233
234 for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++)
235 tmp += port->port_res[k].p_stats.err_tcp_cksum;
236 data[i++] = tmp;
237
238 for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++)
239 tmp += port->port_res[k].p_stats.err_ip_cksum;
240 data[i++] = tmp;
241
242 for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++)
243 tmp += port->port_res[k].p_stats.err_frame_crc;
244 data[i++] = tmp;
245
246 for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++)
247 tmp += port->port_res[k].p_stats.queue_stopped;
248 data[i++] = tmp;
249
250 for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++)
251 tmp |= port->port_res[k].queue_stopped;
252 data[i++] = tmp;
253
254 for (k = 0; k < 8; k++)
255 data[i++] = atomic_read(&port->port_res[k].swqe_avail);
256
257 for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++)
258 tmp |= port->port_res[k].lro_mgr.stats.aggregated;
259 data[i++] = tmp;
260
261 for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++)
262 tmp |= port->port_res[k].lro_mgr.stats.flushed;
263 data[i++] = tmp;
264
265 for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++)
266 tmp |= port->port_res[k].lro_mgr.stats.no_desc;
267 data[i++] = tmp;
268
269 }
270
ehea_set_flags(struct net_device * dev,u32 data)271 static int ehea_set_flags(struct net_device *dev, u32 data)
272 {
273 /* Avoid changing the VLAN flags */
274 if ((data & (ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN)) !=
275 (ethtool_op_get_flags(dev) & (ETH_FLAG_RXVLAN |
276 ETH_FLAG_TXVLAN))){
277 return -EINVAL;
278 }
279
280 return ethtool_op_set_flags(dev, data, ETH_FLAG_LRO
281 | ETH_FLAG_TXVLAN
282 | ETH_FLAG_RXVLAN);
283 }
284
285 const struct ethtool_ops ehea_ethtool_ops = {
286 .get_settings = ehea_get_settings,
287 .get_drvinfo = ehea_get_drvinfo,
288 .get_msglevel = ehea_get_msglevel,
289 .set_msglevel = ehea_set_msglevel,
290 .get_link = ethtool_op_get_link,
291 .set_tso = ethtool_op_set_tso,
292 .get_strings = ehea_get_strings,
293 .get_sset_count = ehea_get_sset_count,
294 .get_ethtool_stats = ehea_get_ethtool_stats,
295 .get_rx_csum = ehea_get_rx_csum,
296 .set_settings = ehea_set_settings,
297 .get_flags = ethtool_op_get_flags,
298 .set_flags = ehea_set_flags,
299 .nway_reset = ehea_nway_reset, /* Restart autonegotiation */
300 };
301
ehea_set_ethtool_ops(struct net_device * netdev)302 void ehea_set_ethtool_ops(struct net_device *netdev)
303 {
304 SET_ETHTOOL_OPS(netdev, &ehea_ethtool_ops);
305 }
306