Skip to contentSkip to conversation

net: thunderbolt: Various improvements

PATCH Superseded Mika Westerberg 2 participants 8 messages Nov 27, 2025 – Dec 1, 2025

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover net: thunderbolt: Various improvements

Hi all,

This series improves the Thunderbolt networking driver so that it should work with the bonding driver. I added also possibility of channing MTU which is sometimes needed, and was part of the original driver.

The discussion that started this patch series can be read below:

https://lore.kernel.org/netdev/CAFJzfF9N4Hak23sc-zh0jMobbkjK7rg4odhic1DQ1cC+=MoQoA@mail.gmail.com/

@Ian, please check if this still works for you? I changed your patch slightly to cope with the various speeds the USB4 link can train.

Ian MacDonald (1):
net: thunderbolt: Allow reading link settings

Mika Westerberg (2):
net: thunderbolt: Allow changing MAC address of the device
net: thunderbolt: Allow changing MTU of the device

 drivers/net/thunderbolt/main.c | 88 ++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)
Signature · 1 line
2.50.1
#1 lore raw

PATCH 1/3 net: thunderbolt: Allow changing MAC address of the device

The MAC address we use is based on a suggestion in the USB4 Inter-domain spec but it is not really used in the USB4NET protocol. It is more targeted for the upper layers of the network stack. There is no reason why it should not be changed by the userspace for example if needed for bonding.

---
 drivers/net/thunderbolt/main.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/thunderbolt/main.c +4 -0
index dcaa62377808..57b226afeb84 100644
@@ -1261,6 +1261,7 @@ static const struct net_device_ops tbnet_netdev_ops = {
 	.ndo_open = tbnet_open,
 	.ndo_stop = tbnet_stop,
 	.ndo_start_xmit = tbnet_start_xmit,
+	.ndo_set_mac_address = eth_mac_addr,
 	.ndo_get_stats64 = tbnet_get_stats64,
 };
 
@@ -1281,6 +1282,9 @@ static void tbnet_generate_mac(struct net_device *dev)
 	hash = jhash2((u32 *)xd->local_uuid, 4, hash);
 	addr[5] = hash & 0xff;
 	eth_hw_addr_set(dev, addr);
+
+	/* Allow changing it if needed */
+	dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
 }
 
 static int tbnet_probe(struct tb_service *svc, const struct tb_service_id *id)
Signature · 1 line
2.50.1
#2 lore raw

PATCH 2/3 net: thunderbolt: Allow changing MTU of the device

In reply to Mika Westerberg

In some cases it is useful to be able to use different MTU than the default one. Especially when dealing against non-Linux networking stack. For this reason add possibility to change the MTU of the device.

---
 drivers/net/thunderbolt/main.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/net/thunderbolt/main.c +11 -0
index 57b226afeb84..20bac55a3e20 100644
@@ -1257,12 +1257,23 @@ static void tbnet_get_stats64(struct net_device *dev,
 	stats->rx_missed_errors = net->stats.rx_missed_errors;
 }
 
+static int tbnet_change_mtu(struct net_device *dev, int new_mtu)
+{
+	/* Keep the MTU within supported range */
+	if (new_mtu < 68 || new_mtu > (TBNET_MAX_MTU - ETH_HLEN))
+		return -EINVAL;
+
+	dev->mtu = new_mtu;
+	return 0;
+}
+
 static const struct net_device_ops tbnet_netdev_ops = {
 	.ndo_open = tbnet_open,
 	.ndo_stop = tbnet_stop,
 	.ndo_start_xmit = tbnet_start_xmit,
 	.ndo_set_mac_address = eth_mac_addr,
 	.ndo_get_stats64 = tbnet_get_stats64,
+	.ndo_change_mtu	= tbnet_change_mtu,
 };
 
 static void tbnet_generate_mac(struct net_device *dev)
Signature · 1 line
2.50.1
#3 lore raw

PATCH 3/3 net: thunderbolt: Allow reading link settings

In reply to Mika Westerberg

From: Ian MacDonald <[email protected]>

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.

---
 drivers/net/thunderbolt/main.c | 73 ++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
drivers/net/thunderbolt/main.c +73 -0
index 20bac55a3e20..b056c22ad129 100644
@@ -10,6 +10,7 @@
  */
 
 #include <linux/atomic.h>
+#include <linux/ethtool.h>
 #include <linux/highmem.h>
 #include <linux/if_vlan.h>
 #include <linux/jhash.h>
@@ -1276,6 +1277,77 @@ static const struct net_device_ops tbnet_netdev_ops = {
 	.ndo_change_mtu	= tbnet_change_mtu,
 };
 
+static int tbnet_get_link_ksettings(struct net_device *dev,
+				    struct ethtool_link_ksettings *cmd)
+{
+	const struct tbnet *net = netdev_priv(dev);
+	const struct tb_xdomain *xd = net->xd;
+	int speed;
+
+	ethtool_link_ksettings_zero_link_mode(cmd, supported);
+	ethtool_link_ksettings_zero_link_mode(cmd, advertising);
+
+	/* Figure out the current link speed and width */
+	switch (xd->link_speed) {
+	case 40:
+		/* For Gen 4 80G symmetric link the closest one
+		 * available is 56G so we report that.
+		 */
+		ethtool_link_ksettings_add_link_mode(cmd, supported,
+						     56000baseKR4_Full);
+		ethtool_link_ksettings_add_link_mode(cmd, advertising,
+						     56000baseKR4_Full);
+		speed = SPEED_56000;
+		break;
+
+	case 20:
+		if (xd->link_width == 2) {
+			ethtool_link_ksettings_add_link_mode(cmd, supported,
+							     40000baseKR4_Full);
+			ethtool_link_ksettings_add_link_mode(cmd, advertising,
+							     40000baseKR4_Full);
+			speed = SPEED_40000;
+		} else {
+			ethtool_link_ksettings_add_link_mode(cmd, supported,
+							     20000baseKR2_Full);
+			ethtool_link_ksettings_add_link_mode(cmd, advertising,
+							     20000baseKR2_Full);
+			speed = SPEED_20000;
+		}
+		break;
+
+	case 10:
+		if (xd->link_width == 2) {
+			ethtool_link_ksettings_add_link_mode(cmd, supported,
+							     20000baseKR2_Full);
+			ethtool_link_ksettings_add_link_mode(cmd, advertising,
+							     20000baseKR2_Full);
+			speed = SPEED_20000;
+			break;
+		}
+		fallthrough;
+
+	default:
+		ethtool_link_ksettings_add_link_mode(cmd, supported,
+						     10000baseT_Full);
+		ethtool_link_ksettings_add_link_mode(cmd, advertising,
+						     10000baseT_Full);
+		speed = SPEED_10000;
+		break;
+	}
+
+	cmd->base.speed = speed;
+	cmd->base.duplex = DUPLEX_FULL;
+	cmd->base.autoneg = AUTONEG_DISABLE;
+	cmd->base.port = PORT_OTHER;
+
+	return 0;
+}
+
+static const struct ethtool_ops tbnet_ethtool_ops = {
+	.get_link_ksettings = tbnet_get_link_ksettings,
+};
+
 static void tbnet_generate_mac(struct net_device *dev)
 {
 	const struct tbnet *net = netdev_priv(dev);
@@ -1326,6 +1398,7 @@ static int tbnet_probe(struct tb_service *svc, const struct tb_service_id *id)
 
 	strcpy(dev->name, "thunderbolt%d");
 	dev->netdev_ops = &tbnet_netdev_ops;
+	dev->ethtool_ops = &tbnet_ethtool_ops;
 
 	/* ThunderboltIP takes advantage of TSO packets but instead of
 	 * segmenting them we just split the packet into Thunderbolt
Signature · 1 line
2.50.1
#4 lore raw

Re: [PATCH net-next 3/3] net: thunderbolt: Allow reading link settings

Quoted 11 lines
drivers/net/thunderbolt/main.c +11 -0
+static int tbnet_get_link_ksettings(struct net_device *dev,
+				    struct ethtool_link_ksettings *cmd)
+{
+	const struct tbnet *net = netdev_priv(dev);
+	const struct tb_xdomain *xd = net->xd;
+	int speed;
+
+	ethtool_link_ksettings_zero_link_mode(cmd, supported);
+	ethtool_link_ksettings_zero_link_mode(cmd, advertising);
+
+	/* Figure out the current link speed and width */

drivers/net/thunderbolt/main.c static const struct net_device_ops tbnet_netdev_ops = { · line 1300

Quoted 10 lines
drivers/net/thunderbolt/main.c +10 -0
+	switch (xd->link_speed) {
+	case 40:
+		/* For Gen 4 80G symmetric link the closest one
+		 * available is 56G so we report that.
+		 */
+		ethtool_link_ksettings_add_link_mode(cmd, supported,
+						     56000baseKR4_Full);
+		ethtool_link_ksettings_add_link_mode(cmd, advertising,
+						     56000baseKR4_Full);
+		speed = SPEED_56000;

Please add SPEED_80000.

I commented on the previous version. Is supported and advertising actually needed? If not, please leave them blank.

Andrew

#5 lore raw

Re: [PATCH net-next 3/3] net: thunderbolt: Allow reading link settings

Quoted 15 lines · Andrew Lunn
Quoted 15 lines
drivers/net/thunderbolt/main.c +15 -0
+static int tbnet_get_link_ksettings(struct net_device *dev,
+				    struct ethtool_link_ksettings *cmd)
+{
+	const struct tbnet *net = netdev_priv(dev);
+	const struct tb_xdomain *xd = net->xd;
+	int speed;
+
+	ethtool_link_ksettings_zero_link_mode(cmd, supported);
+	ethtool_link_ksettings_zero_link_mode(cmd, advertising);
+
+	/* Figure out the current link speed and width */
+	switch (xd->link_speed) {
+	case 40:
+		/* For Gen 4 80G symmetric link the closest one
+		 * available is 56G so we report that.
Quoted 8 lines

drivers/net/thunderbolt/main.c static const struct net_device_ops tbnet_netdev_ops = { · line 1300

Quoted 6 lines
drivers/net/thunderbolt/main.c +6 -0
+		 */
+		ethtool_link_ksettings_add_link_mode(cmd, supported,
+						     56000baseKR4_Full);
+		ethtool_link_ksettings_add_link_mode(cmd, advertising,
+						     56000baseKR4_Full);
+		speed = SPEED_56000;

Please add SPEED_80000.

Sure. One additional question though. Comment on top of SPEED_ definitions suggest changing __get_link_speed() of the bonding driver accordingly but it basically converts from SPEED_ to AD_LINK_SPEED_ which I think we need to add too. However, these are user-facing values so should I add the AD_LINK_SPEED_80000 entry to the end of that enum to avoid any possible breakage?

Quoted 2 lines

I commented on the previous version. Is supported and advertising actually needed? If not, please leave them blank.

I don't think they are needed (but I'll double check).

Acked-by Andy Gospodarek
#6 lore raw

Re: [PATCH net-next 3/3] net: thunderbolt: Allow reading link settings

Quoted 25 lines · Mika Westerberg
Quoted 15 lines · Andrew Lunn
Quoted 15 lines
(quoted diff) +15 -0
+static int tbnet_get_link_ksettings(struct net_device *dev,
+				    struct ethtool_link_ksettings *cmd)
+{
+	const struct tbnet *net = netdev_priv(dev);
+	const struct tb_xdomain *xd = net->xd;
+	int speed;
+
+	ethtool_link_ksettings_zero_link_mode(cmd, supported);
+	ethtool_link_ksettings_zero_link_mode(cmd, advertising);
+
+	/* Figure out the current link speed and width */
+	switch (xd->link_speed) {
+	case 40:
+		/* For Gen 4 80G symmetric link the closest one
+		 * available is 56G so we report that.
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+		 */
+		ethtool_link_ksettings_add_link_mode(cmd, supported,
+						     56000baseKR4_Full);
+		ethtool_link_ksettings_add_link_mode(cmd, advertising,
+						     56000baseKR4_Full);
+		speed = SPEED_56000;

Please add SPEED_80000.

Quoted 6 lines

Sure. One additional question though. Comment on top of SPEED_ definitions suggest changing __get_link_speed() of the bonding driver accordingly but it basically converts from SPEED_ to AD_LINK_SPEED_ which I think we need to add too. However, these are user-facing values so should I add the AD_LINK_SPEED_80000 entry to the end of that enum to avoid any possible breakage?

Are they user facing? They should be define in include/uapi if they were. I would keep the list sorted, and Cc: the bonding driver Maintainer, Jay Vosburgh <[email protected]> (maintainer:BONDING DRIVER).

Also:

cb8dda90c28e2 (Jianhua Xie                 2014-11-19 16:48:58 +0800   61) enum ad_link_speed_type {
cb8dda90c28e2 (Jianhua Xie                 2014-11-19 16:48:58 +0800   62)      AD_LINK_SPEED_1MBPS = 1,
cb8dda90c28e2 (Jianhua Xie                 2014-11-19 16:48:58 +0800   63)      AD_LINK_SPEED_10MBPS,
cb8dda90c28e2 (Jianhua Xie                 2014-11-19 16:48:58 +0800   64)      AD_LINK_SPEED_100MBPS,
cb8dda90c28e2 (Jianhua Xie                 2014-11-19 16:48:58 +0800   65)      AD_LINK_SPEED_1000MBPS,
424c3232b04ac (Jianhua Xie                 2014-11-19 16:48:59 +0800   66)      AD_LINK_SPEED_2500MBPS,
c7c550670afda (Thibaut Collet              2017-06-08 11:18:11 +0200   67)      AD_LINK_SPEED_5000MBPS,
424c3232b04ac (Jianhua Xie                 2014-11-19 16:48:59 +0800   68)      AD_LINK_SPEED_10000MBPS,
3fcd64cfa0e9c (Nicolas Dichtel             2017-06-08 11:18:12 +0200   69)      AD_LINK_SPEED_14000MBPS,
424c3232b04ac (Jianhua Xie                 2014-11-19 16:48:59 +0800   70)      AD_LINK_SPEED_20000MBPS,
19ddde1eeca1e (Jarod Wilson                2017-03-14 11:48:32 -0400   71)      AD_LINK_SPEED_25000MBPS,
424c3232b04ac (Jianhua Xie                 2014-11-19 16:48:59 +0800   72)      AD_LINK_SPEED_40000MBPS,
c7c550670afda (Thibaut Collet              2017-06-08 11:18:11 +0200   73)      AD_LINK_SPEED_50000MBPS,
3952af4d50343 (Jiri Pirko                  2015-12-03 12:12:05 +0100   74)      AD_LINK_SPEED_56000MBPS,
3952af4d50343 (Jiri Pirko                  2015-12-03 12:12:05 +0100   75)      AD_LINK_SPEED_100000MBPS,
ab73447c38e4f (Nikolay Aleksandrov         2021-02-10 22:43:31 +0200   76)      AD_LINK_SPEED_200000MBPS,
138e3b3cc0bbb (Nikolay Aleksandrov         2021-02-10 22:43:32 +0200   77)      AD_LINK_SPEED_400000MBPS,
41305d3781d70 (Amit Cohen                  2022-10-20 17:20:05 +0200   78)      AD_LINK_SPEED_800000MBPS,
cb8dda90c28e2 (Jianhua Xie                 2014-11-19 16:48:58 +0800   79) };

suggests you can insert in the middle:

commit c7c550670afda2e16f9e2d06a1473885312eb6b5

Author: Thibaut Collet <[email protected]>
Date:   Thu Jun 8 11:18:11 2017 +0200

bonding: fix 802.3ad support for 5G and 50G speeds

This patch adds [5|50] Gbps enum definition, and fixes aggregated bandwidth calculation based on above slave links.

Fixes c9a70d43461d ("net-next: ethtool: Added port speed macros.")
drivers/net/bonding/bond_3ad.c +2 -0
index b44a6aeb346d..d1b09be63ba4 100644
@@ -90,10 +90,12 @@ enum ad_link_speed_type {
        AD_LINK_SPEED_100MBPS,
        AD_LINK_SPEED_1000MBPS,
        AD_LINK_SPEED_2500MBPS,
+       AD_LINK_SPEED_5000MBPS,
        AD_LINK_SPEED_10000MBPS,
        AD_LINK_SPEED_20000MBPS,
        AD_LINK_SPEED_25000MBPS,
        AD_LINK_SPEED_40000MBPS,
+       AD_LINK_SPEED_50000MBPS,
        AD_LINK_SPEED_56000MBPS,
        AD_LINK_SPEED_100000MBPS,
 

Andrew

#7 lore raw

Re: [PATCH net-next 3/3] net: thunderbolt: Allow reading link settings

Quoted 9 lines · Andrew Lunn
Quoted 8 lines
Quoted 1 line

Please add SPEED_80000.

Sure. One additional question though. Comment on top of SPEED_ definitions suggest changing __get_link_speed() of the bonding driver accordingly but it basically converts from SPEED_ to AD_LINK_SPEED_ which I think we need to add too. However, these are user-facing values so should I add the AD_LINK_SPEED_80000 entry to the end of that enum to avoid any possible breakage?

Quoted 3 lines

Are they user facing? They should be define in include/uapi if they were. I would keep the list sorted, and Cc: the bonding driver Maintainer, Jay Vosburgh <[email protected]> (maintainer:BONDING DRIVER).

Indeed, they look like they are not. As you pointed out these are internals of the drivers/net/bonding/bond_3ad.c and not exposed as is to the userspace.

I'll add the 80G there for both of these in v2 and Cd Jay just in case. Since merge window is open I'll send v2 after v6.19-rc1 is released.