Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: thunderbolt: Allow reading link settings

In order to use Thunderbolt networking as part of bonding device it
needs to support ->get_link_ksettings() ethtool operation, so that the
bonding driver can read the link speed and the related attributes. Add
support for this to the driver.

Signed-off-by: Ian MacDonald <ian@netstatz.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Link: https://patch.msgid.link/20260115115646.328898-5-mika.westerberg@linux.intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Ian MacDonald and committed by
Jakub Kicinski
7a3d3279 2e62e556

+49
+49
drivers/net/thunderbolt/main.c
··· 10 10 */ 11 11 12 12 #include <linux/atomic.h> 13 + #include <linux/ethtool.h> 13 14 #include <linux/highmem.h> 14 15 #include <linux/if_vlan.h> 15 16 #include <linux/jhash.h> ··· 1266 1265 .ndo_get_stats64 = tbnet_get_stats64, 1267 1266 }; 1268 1267 1268 + static int tbnet_get_link_ksettings(struct net_device *dev, 1269 + struct ethtool_link_ksettings *cmd) 1270 + { 1271 + const struct tbnet *net = netdev_priv(dev); 1272 + const struct tb_xdomain *xd = net->xd; 1273 + int speed; 1274 + 1275 + ethtool_link_ksettings_zero_link_mode(cmd, supported); 1276 + ethtool_link_ksettings_zero_link_mode(cmd, advertising); 1277 + 1278 + /* Figure out the current link speed and width */ 1279 + switch (xd->link_speed) { 1280 + case 40: 1281 + speed = SPEED_80000; 1282 + break; 1283 + 1284 + case 20: 1285 + if (xd->link_width == 2) 1286 + speed = SPEED_40000; 1287 + else 1288 + speed = SPEED_20000; 1289 + break; 1290 + 1291 + case 10: 1292 + if (xd->link_width == 2) { 1293 + speed = SPEED_20000; 1294 + break; 1295 + } 1296 + fallthrough; 1297 + 1298 + default: 1299 + speed = SPEED_10000; 1300 + break; 1301 + } 1302 + 1303 + cmd->base.speed = speed; 1304 + cmd->base.duplex = DUPLEX_FULL; 1305 + cmd->base.autoneg = AUTONEG_DISABLE; 1306 + cmd->base.port = PORT_OTHER; 1307 + 1308 + return 0; 1309 + } 1310 + 1311 + static const struct ethtool_ops tbnet_ethtool_ops = { 1312 + .get_link_ksettings = tbnet_get_link_ksettings, 1313 + }; 1314 + 1269 1315 static void tbnet_generate_mac(struct net_device *dev) 1270 1316 { 1271 1317 const struct tbnet *net = netdev_priv(dev); ··· 1363 1315 1364 1316 strcpy(dev->name, "thunderbolt%d"); 1365 1317 dev->netdev_ops = &tbnet_netdev_ops; 1318 + dev->ethtool_ops = &tbnet_ethtool_ops; 1366 1319 1367 1320 /* ThunderboltIP takes advantage of TSO packets but instead of 1368 1321 * segmenting them we just split the packet into Thunderbolt