1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * linux/drivers/net/ethernet/ibm/ehea/ehea_ethtool.c
5 * eHEA ethernet device driver for IBM eServer System p
7 * (C) Copyright IBM Corp. 2006
10 * Christoph Raisch <raisch@de.ibm.com>
11 * Jan-Bernd Themann <themann@de.ibm.com>
12 * Thomas Klein <tklein@de.ibm.com>
15 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 #include "ehea_phyp.h"
20 static int ehea_get_link_ksettings(struct net_device
*dev
,
21 struct ethtool_link_ksettings
*cmd
)
23 struct ehea_port
*port
= netdev_priv(dev
);
24 u32 supported
, advertising
;
28 ret
= ehea_sense_port_attr(port
);
33 if (netif_carrier_ok(dev
)) {
34 switch (port
->port_speed
) {
51 cmd
->base
.duplex
= port
->full_duplex
== 1 ?
52 DUPLEX_FULL
: DUPLEX_HALF
;
54 speed
= SPEED_UNKNOWN
;
55 cmd
->base
.duplex
= DUPLEX_UNKNOWN
;
57 cmd
->base
.speed
= speed
;
59 if (cmd
->base
.speed
== SPEED_10000
) {
60 supported
= (SUPPORTED_10000baseT_Full
| SUPPORTED_FIBRE
);
61 advertising
= (ADVERTISED_10000baseT_Full
| ADVERTISED_FIBRE
);
62 cmd
->base
.port
= PORT_FIBRE
;
64 supported
= (SUPPORTED_1000baseT_Full
| SUPPORTED_100baseT_Full
65 | SUPPORTED_100baseT_Half
| SUPPORTED_10baseT_Full
66 | SUPPORTED_10baseT_Half
| SUPPORTED_Autoneg
68 advertising
= (ADVERTISED_1000baseT_Full
| ADVERTISED_Autoneg
70 cmd
->base
.port
= PORT_TP
;
73 cmd
->base
.autoneg
= port
->autoneg
== 1 ?
74 AUTONEG_ENABLE
: AUTONEG_DISABLE
;
76 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.supported
,
78 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.advertising
,
84 static int ehea_set_link_ksettings(struct net_device
*dev
,
85 const struct ethtool_link_ksettings
*cmd
)
87 struct ehea_port
*port
= netdev_priv(dev
);
91 if (cmd
->base
.autoneg
== AUTONEG_ENABLE
) {
92 sp
= EHEA_SPEED_AUTONEG
;
96 switch (cmd
->base
.speed
) {
98 if (cmd
->base
.duplex
== DUPLEX_FULL
)
105 if (cmd
->base
.duplex
== DUPLEX_FULL
)
112 if (cmd
->base
.duplex
== DUPLEX_FULL
)
119 if (cmd
->base
.duplex
== DUPLEX_FULL
)
133 ret
= ehea_set_portspeed(port
, sp
);
137 "Port speed successfully set: %dMbps %s Duplex\n",
139 port
->full_duplex
== 1 ? "Full" : "Half");
144 static int ehea_nway_reset(struct net_device
*dev
)
146 struct ehea_port
*port
= netdev_priv(dev
);
149 ret
= ehea_set_portspeed(port
, EHEA_SPEED_AUTONEG
);
152 netdev_info(port
->netdev
,
153 "Port speed successfully set: %dMbps %s Duplex\n",
155 port
->full_duplex
== 1 ? "Full" : "Half");
159 static void ehea_get_drvinfo(struct net_device
*dev
,
160 struct ethtool_drvinfo
*info
)
162 strlcpy(info
->driver
, DRV_NAME
, sizeof(info
->driver
));
163 strlcpy(info
->version
, DRV_VERSION
, sizeof(info
->version
));
166 static u32
ehea_get_msglevel(struct net_device
*dev
)
168 struct ehea_port
*port
= netdev_priv(dev
);
169 return port
->msg_enable
;
172 static void ehea_set_msglevel(struct net_device
*dev
, u32 value
)
174 struct ehea_port
*port
= netdev_priv(dev
);
175 port
->msg_enable
= value
;
178 static const char ehea_ethtool_stats_keys
[][ETH_GSTRING_LEN
] = {
183 {"TCP cksum errors"},
185 {"Frame cksum errors"},
205 static void ehea_get_strings(struct net_device
*dev
, u32 stringset
, u8
*data
)
207 if (stringset
== ETH_SS_STATS
) {
208 memcpy(data
, &ehea_ethtool_stats_keys
,
209 sizeof(ehea_ethtool_stats_keys
));
213 static int ehea_get_sset_count(struct net_device
*dev
, int sset
)
217 return ARRAY_SIZE(ehea_ethtool_stats_keys
);
223 static void ehea_get_ethtool_stats(struct net_device
*dev
,
224 struct ethtool_stats
*stats
, u64
*data
)
227 struct ehea_port
*port
= netdev_priv(dev
);
229 for (i
= 0; i
< ehea_get_sset_count(dev
, ETH_SS_STATS
); i
++)
233 data
[i
++] = port
->sig_comp_iv
;
234 data
[i
++] = port
->port_res
[0].swqe_refill_th
;
235 data
[i
++] = port
->resets
;
237 for (k
= 0, tmp
= 0; k
< EHEA_MAX_PORT_RES
; k
++)
238 tmp
+= port
->port_res
[k
].p_stats
.poll_receive_errors
;
241 for (k
= 0, tmp
= 0; k
< EHEA_MAX_PORT_RES
; k
++)
242 tmp
+= port
->port_res
[k
].p_stats
.err_tcp_cksum
;
245 for (k
= 0, tmp
= 0; k
< EHEA_MAX_PORT_RES
; k
++)
246 tmp
+= port
->port_res
[k
].p_stats
.err_ip_cksum
;
249 for (k
= 0, tmp
= 0; k
< EHEA_MAX_PORT_RES
; k
++)
250 tmp
+= port
->port_res
[k
].p_stats
.err_frame_crc
;
253 for (k
= 0, tmp
= 0; k
< EHEA_MAX_PORT_RES
; k
++)
254 tmp
+= port
->port_res
[k
].p_stats
.queue_stopped
;
257 for (k
= 0; k
< 16; k
++)
258 data
[i
++] = atomic_read(&port
->port_res
[k
].swqe_avail
);
261 static const struct ethtool_ops ehea_ethtool_ops
= {
262 .get_drvinfo
= ehea_get_drvinfo
,
263 .get_msglevel
= ehea_get_msglevel
,
264 .set_msglevel
= ehea_set_msglevel
,
265 .get_link
= ethtool_op_get_link
,
266 .get_strings
= ehea_get_strings
,
267 .get_sset_count
= ehea_get_sset_count
,
268 .get_ethtool_stats
= ehea_get_ethtool_stats
,
269 .nway_reset
= ehea_nway_reset
, /* Restart autonegotiation */
270 .get_link_ksettings
= ehea_get_link_ksettings
,
271 .set_link_ksettings
= ehea_set_link_ksettings
,
274 void ehea_set_ethtool_ops(struct net_device
*netdev
)
276 netdev
->ethtool_ops
= &ehea_ethtool_ops
;