2 * linux/drivers/net/ethernet/ibm/ehea/ehea_ethtool.c
4 * eHEA ethernet device driver for IBM eServer System p
6 * (C) Copyright IBM Corp. 2006
9 * Christoph Raisch <raisch@de.ibm.com>
10 * Jan-Bernd Themann <themann@de.ibm.com>
11 * Thomas Klein <tklein@de.ibm.com>
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)
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.
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.
29 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32 #include "ehea_phyp.h"
34 static int ehea_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
36 struct ehea_port
*port
= netdev_priv(dev
);
40 ret
= ehea_sense_port_attr(port
);
45 if (netif_carrier_ok(dev
)) {
46 switch (port
->port_speed
) {
63 cmd
->duplex
= port
->full_duplex
== 1 ?
64 DUPLEX_FULL
: DUPLEX_HALF
;
69 ethtool_cmd_speed_set(cmd
, speed
);
71 if (cmd
->speed
== SPEED_10000
) {
72 cmd
->supported
= (SUPPORTED_10000baseT_Full
| SUPPORTED_FIBRE
);
73 cmd
->advertising
= (ADVERTISED_10000baseT_Full
| ADVERTISED_FIBRE
);
74 cmd
->port
= PORT_FIBRE
;
76 cmd
->supported
= (SUPPORTED_1000baseT_Full
| SUPPORTED_100baseT_Full
77 | SUPPORTED_100baseT_Half
| SUPPORTED_10baseT_Full
78 | SUPPORTED_10baseT_Half
| SUPPORTED_Autoneg
80 cmd
->advertising
= (ADVERTISED_1000baseT_Full
| ADVERTISED_Autoneg
85 cmd
->autoneg
= port
->autoneg
== 1 ? AUTONEG_ENABLE
: AUTONEG_DISABLE
;
90 static int ehea_set_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
92 struct ehea_port
*port
= netdev_priv(dev
);
96 if (cmd
->autoneg
== AUTONEG_ENABLE
) {
97 sp
= EHEA_SPEED_AUTONEG
;
101 switch (cmd
->speed
) {
103 if (cmd
->duplex
== DUPLEX_FULL
)
110 if (cmd
->duplex
== DUPLEX_FULL
)
117 if (cmd
->duplex
== DUPLEX_FULL
)
124 if (cmd
->duplex
== DUPLEX_FULL
)
138 ret
= ehea_set_portspeed(port
, sp
);
142 "Port speed successfully set: %dMbps %s Duplex\n",
144 port
->full_duplex
== 1 ? "Full" : "Half");
149 static int ehea_nway_reset(struct net_device
*dev
)
151 struct ehea_port
*port
= netdev_priv(dev
);
154 ret
= ehea_set_portspeed(port
, EHEA_SPEED_AUTONEG
);
157 netdev_info(port
->netdev
,
158 "Port speed successfully set: %dMbps %s Duplex\n",
160 port
->full_duplex
== 1 ? "Full" : "Half");
164 static void ehea_get_drvinfo(struct net_device
*dev
,
165 struct ethtool_drvinfo
*info
)
167 strlcpy(info
->driver
, DRV_NAME
, sizeof(info
->driver
));
168 strlcpy(info
->version
, DRV_VERSION
, sizeof(info
->version
));
171 static u32
ehea_get_msglevel(struct net_device
*dev
)
173 struct ehea_port
*port
= netdev_priv(dev
);
174 return port
->msg_enable
;
177 static void ehea_set_msglevel(struct net_device
*dev
, u32 value
)
179 struct ehea_port
*port
= netdev_priv(dev
);
180 port
->msg_enable
= value
;
183 static const char ehea_ethtool_stats_keys
[][ETH_GSTRING_LEN
] = {
188 {"TCP cksum errors"},
190 {"Frame cksum errors"},
210 static void ehea_get_strings(struct net_device
*dev
, u32 stringset
, u8
*data
)
212 if (stringset
== ETH_SS_STATS
) {
213 memcpy(data
, &ehea_ethtool_stats_keys
,
214 sizeof(ehea_ethtool_stats_keys
));
218 static int ehea_get_sset_count(struct net_device
*dev
, int sset
)
222 return ARRAY_SIZE(ehea_ethtool_stats_keys
);
228 static void ehea_get_ethtool_stats(struct net_device
*dev
,
229 struct ethtool_stats
*stats
, u64
*data
)
232 struct ehea_port
*port
= netdev_priv(dev
);
234 for (i
= 0; i
< ehea_get_sset_count(dev
, ETH_SS_STATS
); i
++)
238 data
[i
++] = port
->sig_comp_iv
;
239 data
[i
++] = port
->port_res
[0].swqe_refill_th
;
240 data
[i
++] = port
->resets
;
242 for (k
= 0, tmp
= 0; k
< EHEA_MAX_PORT_RES
; k
++)
243 tmp
+= port
->port_res
[k
].p_stats
.poll_receive_errors
;
246 for (k
= 0, tmp
= 0; k
< EHEA_MAX_PORT_RES
; k
++)
247 tmp
+= port
->port_res
[k
].p_stats
.err_tcp_cksum
;
250 for (k
= 0, tmp
= 0; k
< EHEA_MAX_PORT_RES
; k
++)
251 tmp
+= port
->port_res
[k
].p_stats
.err_ip_cksum
;
254 for (k
= 0, tmp
= 0; k
< EHEA_MAX_PORT_RES
; k
++)
255 tmp
+= port
->port_res
[k
].p_stats
.err_frame_crc
;
258 for (k
= 0, tmp
= 0; k
< EHEA_MAX_PORT_RES
; k
++)
259 tmp
+= port
->port_res
[k
].p_stats
.queue_stopped
;
262 for (k
= 0; k
< 16; k
++)
263 data
[i
++] = atomic_read(&port
->port_res
[k
].swqe_avail
);
266 static const struct ethtool_ops ehea_ethtool_ops
= {
267 .get_settings
= ehea_get_settings
,
268 .get_drvinfo
= ehea_get_drvinfo
,
269 .get_msglevel
= ehea_get_msglevel
,
270 .set_msglevel
= ehea_set_msglevel
,
271 .get_link
= ethtool_op_get_link
,
272 .get_strings
= ehea_get_strings
,
273 .get_sset_count
= ehea_get_sset_count
,
274 .get_ethtool_stats
= ehea_get_ethtool_stats
,
275 .set_settings
= ehea_set_settings
,
276 .nway_reset
= ehea_nway_reset
, /* Restart autonegotiation */
279 void ehea_set_ethtool_ops(struct net_device
*netdev
)
281 SET_ETHTOOL_OPS(netdev
, &ehea_ethtool_ops
);