Skip to contentSkip to conversation

netdevsim: add link speed support

PATCH NAK Hangbin Liu 3 participants 21 messages Aug 31 – Sep 2

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

cover netdevsim: add link speed support

Add link speed support for netdevsim, so users could test different‑speed NICs. Currently, I am still using max speed 5000. Maybe we should increase the max speed in the future.

The 2nd patch adds a simple selftest for the speed feature.

---
Hangbin Liu (2):
netdevsim: add link speed support
selftests: netdevsim: add speed testing

 drivers/net/netdevsim/dev.c                        |  6 ----
 drivers/net/netdevsim/ethtool.c                    | 30 ++++++++++++++++++++
 drivers/net/netdevsim/netdevsim.h                  |  8 ++++++
 .../selftests/drivers/net/netdevsim/Makefile       |  1 +
 .../drivers/net/netdevsim/ethtool-speed.sh         | 33 ++++++++++++++++++++++
 5 files changed, 72 insertions(+), 6 deletions(-)

---
base-commit: 1bb784eb6e38fd73143f021608e4ef3095d0c0d7
change-id: 20260821-nsim_speed-d61e5c415b02

Best regards,

Signature · 1 line
Hangbin Liu <[email protected]>
#1 lore raw

PATCH 1/2 netdevsim: add link speed support

From: Hangbin Liu <[email protected]>

Add ethtool get/set_link_ksettings callbacks to netdevsim so the simulated link speed and duplex can be queried and configured from userspace.

Move NSIM_LINK_SPEED_MAX and NSIM_LINK_SPEED_UNIT from dev.c to netdevsim.h so they are available to both the devlink rate path and the new ethtool code. The set callback rejects speeds exceeding NSIM_LINK_SPEED_MAX.

The default link speed is set to SPEED_5000 with DUPLEX_FULL, matching the existing NSIM_LINK_SPEED_MAX definition.

---
 drivers/net/netdevsim/dev.c       |  6 ------
 drivers/net/netdevsim/ethtool.c   | 30 ++++++++++++++++++++++++++++++
 drivers/net/netdevsim/netdevsim.h |  8 ++++++++
 3 files changed, 38 insertions(+), 6 deletions(-)
drivers/net/netdevsim/dev.c +0 -6
index feb88ccbbced..729ce80f6c83 100644
@@ -1138,12 +1138,6 @@ nsim_dev_devlink_trap_policer_counter_get(struct devlink *devlink,
 	return 0;
 }
 
-#define NSIM_LINK_SPEED_MAX     5000 /* Mbps */
-#define NSIM_LINK_SPEED_UNIT    125000 /* 1 Mbps given in bytes/sec to avoid
-					* u64 overflow during conversion from
-					* bytes to bits.
-					*/
-
 static int nsim_rate_bytes_to_units(char *name, u64 *rate, struct netlink_ext_ack *extack)
 {
 	u64 val;
drivers/net/netdevsim/ethtool.c +30 -0
index 025ea79879f3..59768bd7b620 100644
@@ -205,6 +205,30 @@ static int nsim_get_ts_info(struct net_device *dev,
 	return 0;
 }
 
+static int nsim_get_link_ksettings(struct net_device *dev,
+				   struct ethtool_link_ksettings *cmd)
+{
+	struct netdevsim *ns = netdev_priv(dev);
+
+	cmd->base.speed		= ns->ethtool.speed;
+	cmd->base.duplex	= ns->ethtool.duplex;
+	cmd->base.port		= PORT_OTHER;
+	cmd->base.autoneg	= AUTONEG_DISABLE;
+	return 0;
+}
+
+static int nsim_set_link_ksettings(struct net_device *dev,
+				   const struct ethtool_link_ksettings *cmd)
+{
+	struct netdevsim *ns = netdev_priv(dev);
+
+	if (cmd->base.speed > NSIM_LINK_SPEED_MAX)
+		return -EINVAL;
+
+	return ethtool_virtdev_set_link_ksettings(dev, cmd, &ns->ethtool.speed,
+						  &ns->ethtool.duplex);
+}
+
 static const struct ethtool_ops nsim_ethtool_ops = {
 	.supported_coalesce_params	= ETHTOOL_COALESCE_ALL_PARAMS,
 	.supported_ring_params		= ETHTOOL_RING_USE_TCP_DATA_SPLIT |
@@ -223,6 +247,8 @@ static const struct ethtool_ops nsim_ethtool_ops = {
 	.set_fecparam			= nsim_set_fecparam,
 	.get_fec_stats			= nsim_get_fec_stats,
 	.get_ts_info			= nsim_get_ts_info,
+	.get_link_ksettings		= nsim_get_link_ksettings,
+	.set_link_ksettings		= nsim_set_link_ksettings,
 };
 
 static void nsim_ethtool_ring_init(struct netdevsim *ns)
@@ -250,12 +276,16 @@ void nsim_ethtool_init(struct netdevsim *ns)
 	ns->ethtool.fec.active_fec = ETHTOOL_FEC_NONE;
 
 	ns->ethtool.channels = ns->nsim_bus_dev->num_queues;
+	ns->ethtool.duplex = DUPLEX_FULL;
+	ns->ethtool.speed = SPEED_5000;
 
 	ethtool = debugfs_create_dir("ethtool", ns->nsim_dev_port->ddir);
 	ns->ethtool_ddir = ethtool;
 
 	debugfs_create_u32("get_err", 0600, ethtool, &ns->ethtool.get_err);
 	debugfs_create_u32("set_err", 0600, ethtool, &ns->ethtool.set_err);
+	debugfs_create_u32("speed", 0600, ethtool, &ns->ethtool.speed);
+	debugfs_create_u8("duplex", 0600, ethtool, &ns->ethtool.duplex);
 
 	dir = debugfs_create_dir("pause", ethtool);
 	debugfs_create_bool("report_stats_rx", 0600, dir,
drivers/net/netdevsim/netdevsim.h +8 -0
index 55aec41237b9..ce0d0dea00fb 100644
@@ -39,6 +39,11 @@
 
 #define NSIM_HDS_THRESHOLD_MAX		1024
 
+#define NSIM_LINK_SPEED_MAX     5000 /* Mbps */
+#define NSIM_LINK_SPEED_UNIT    125000 /* 1 Mbps given in bytes/sec to avoid
+					* u64 overflow during conversion from
+					* bytes to bits.
+					*/
 struct nsim_sa {
 	struct xfrm_state *xs;
 	__be32 ipaddr[4];
@@ -95,6 +100,9 @@ struct nsim_ethtool {
 	struct ethtool_coalesce coalesce;
 	struct ethtool_ringparam ring;
 	struct ethtool_fecparam fec;
+
+	u32 speed;
+	u8 duplex;
 };
 
 struct nsim_rq {
Signature · 1 line
2.55.0
maintainer
#2 lore raw
Quoted 5 lines

static void nsim_ethtool_ring_init(struct netdevsim *ns)

drivers/net/netdevsim/ethtool.c +0 -0
@@ -250,12 +276,16 @@ void nsim_ethtool_init(struct netdevsim *ns)
 	ns->ethtool.fec.active_fec = ETHTOOL_FEC_NONE;
 
 	ns->ethtool.channels = ns->nsim_bus_dev->num_queues;

drivers/net/netdevsim/ethtool.c void nsim_ethtool_init(struct netdevsim *ns) · line 288

Quoted 10 lines
drivers/net/netdevsim/ethtool.c +4 -0
+	ns->ethtool.duplex = DUPLEX_FULL;
+	ns->ethtool.speed = SPEED_5000;
 
 	ethtool = debugfs_create_dir("ethtool", ns->nsim_dev_port->ddir);
 	ns->ethtool_ddir = ethtool;
 
 	debugfs_create_u32("get_err", 0600, ethtool, &ns->ethtool.get_err);
 	debugfs_create_u32("set_err", 0600, ethtool, &ns->ethtool.set_err);
+	debugfs_create_u32("speed", 0600, ethtool, &ns->ethtool.speed);
+	debugfs_create_u8("duplex", 0600, ethtool, &ns->ethtool.duplex);

debugfs_create_bool() ?

Andrew

#3 lore raw
Quoted 11 lines · Andrew Lunn
Quoted 11 lines

static void nsim_ethtool_ring_init(struct netdevsim *ns)

drivers/net/netdevsim/ethtool.c +2 -0
@@ -250,12 +276,16 @@ void nsim_ethtool_init(struct netdevsim *ns)
 	ns->ethtool.fec.active_fec = ETHTOOL_FEC_NONE;
 
 	ns->ethtool.channels = ns->nsim_bus_dev->num_queues;
+	ns->ethtool.duplex = DUPLEX_FULL;
+	ns->ethtool.speed = SPEED_5000;
 
 	ethtool = debugfs_create_dir("ethtool", ns->nsim_dev_port->ddir);
 	ns->ethtool_ddir = ethtool;
 
Quoted 6 lines

drivers/net/netdevsim/ethtool.c void nsim_ethtool_init(struct netdevsim *ns) · line 288

Quoted 4 lines
drivers/net/netdevsim/ethtool.c +2 -0
 	debugfs_create_u32("get_err", 0600, ethtool, &ns->ethtool.get_err);
 	debugfs_create_u32("set_err", 0600, ethtool, &ns->ethtool.set_err);
+	debugfs_create_u32("speed", 0600, ethtool, &ns->ethtool.speed);
+	debugfs_create_u8("duplex", 0600, ethtool, &ns->ethtool.duplex);

debugfs_create_bool() ?

I'm not sure if anyone want to set nsim duplex to unknown for testing. Do you think that we should disable this behavior?

Thanks
Hangbin

maintainer
#4 lore raw
Quoted 19 lines · Hangbin Liu
Quoted 11 lines · Andrew Lunn
Quoted 11 lines

static void nsim_ethtool_ring_init(struct netdevsim *ns)

drivers/net/netdevsim/ethtool.c +2 -0
@@ -250,12 +276,16 @@ void nsim_ethtool_init(struct netdevsim *ns)
 	ns->ethtool.fec.active_fec = ETHTOOL_FEC_NONE;
 
 	ns->ethtool.channels = ns->nsim_bus_dev->num_queues;
+	ns->ethtool.duplex = DUPLEX_FULL;
+	ns->ethtool.speed = SPEED_5000;
 
 	ethtool = debugfs_create_dir("ethtool", ns->nsim_dev_port->ddir);
 	ns->ethtool_ddir = ethtool;
 
Quoted 6 lines

drivers/net/netdevsim/ethtool.c void nsim_ethtool_init(struct netdevsim *ns) · line 288

Quoted 4 lines
drivers/net/netdevsim/ethtool.c +2 -0
 	debugfs_create_u32("get_err", 0600, ethtool, &ns->ethtool.get_err);
 	debugfs_create_u32("set_err", 0600, ethtool, &ns->ethtool.set_err);
+	debugfs_create_u32("speed", 0600, ethtool, &ns->ethtool.speed);
+	debugfs_create_u8("duplex", 0600, ethtool, &ns->ethtool.duplex);

debugfs_create_bool() ?

Quoted 2 lines

I'm not sure if anyone want to set nsim duplex to unknown for testing. Do you think that we should disable this behavior?

Ah, i did not think of DUPLEX_UNKNOWN.

We need to consider Jakubs reply, what are you actually testing here, do such tests make any sense?

If they do, i think some validation would be good here. We already have:

static inline int ethtool_validate_duplex(__u8 duplex)

{
	switch (duplex) {
	case DUPLEX_HALF:
	case DUPLEX_FULL:
	case DUPLEX_UNKNOWN:
		return 1;
	}

	return 0;
}

We don't expect a driver to set duplex to 42, so why should the user be allowed to do that?

Also, SPEED_UNKNOWN is -1, so you need debugfs_create_s32().

Andrew

#5 lore raw
Quoted 20 lines · Andrew Lunn
Quoted 19 lines · Hangbin Liu
Quoted 17 lines · Andrew Lunn
Quoted 5 lines

static void nsim_ethtool_ring_init(struct netdevsim *ns)

drivers/net/netdevsim/ethtool.c +0 -0
@@ -250,12 +276,16 @@ void nsim_ethtool_init(struct netdevsim *ns)
 	ns->ethtool.fec.active_fec = ETHTOOL_FEC_NONE;
 
 	ns->ethtool.channels = ns->nsim_bus_dev->num_queues;

drivers/net/netdevsim/ethtool.c void nsim_ethtool_init(struct netdevsim *ns) · line 288

Quoted 10 lines
drivers/net/netdevsim/ethtool.c +4 -0
+	ns->ethtool.duplex = DUPLEX_FULL;
+	ns->ethtool.speed = SPEED_5000;
 
 	ethtool = debugfs_create_dir("ethtool", ns->nsim_dev_port->ddir);
 	ns->ethtool_ddir = ethtool;
 
 	debugfs_create_u32("get_err", 0600, ethtool, &ns->ethtool.get_err);
 	debugfs_create_u32("set_err", 0600, ethtool, &ns->ethtool.set_err);
+	debugfs_create_u32("speed", 0600, ethtool, &ns->ethtool.speed);
+	debugfs_create_u8("duplex", 0600, ethtool, &ns->ethtool.duplex);

debugfs_create_bool() ?

Quoted 7 lines
Quoted 2 lines

I'm not sure if anyone want to set nsim duplex to unknown for testing. Do you think that we should disable this behavior?

Ah, i did not think of DUPLEX_UNKNOWN.

We need to consider Jakubs reply, what are you actually testing here, do such tests make any sense?

I'm fixing a bug in bonding that need to test with different speed slaves. So I add this feature for netdevsim.

Quoted 16 lines

If they do, i think some validation would be good here. We already have:

static inline int ethtool_validate_duplex(__u8 duplex)

{
	switch (duplex) {
	case DUPLEX_HALF:
	case DUPLEX_FULL:
	case DUPLEX_UNKNOWN:
		return 1;
	}

	return 0;
}
Quoted 2 lines

We don't expect a driver to set duplex to 42, so why should the user be allowed to do that?

The user interface (ethtool) setting is already handled by ethtool_virtdev_set_link_ksettings(). Here is the debugfs issue. Since no one is asking for setting DUPLEX_UNKNOWN, I can use debugfs_create_bool first.

Quoted 2 lines

Also, SPEED_UNKNOWN is -1, so you need debugfs_create_s32().

Ah, yes. Thanks

Hangbin

maintainer
#6 lore raw
Quoted 24 lines · Hangbin Liu
Quoted 23 lines · Andrew Lunn
Quoted 21 lines · Hangbin Liu
Quoted 11 lines · Andrew Lunn
Quoted 11 lines

static void nsim_ethtool_ring_init(struct netdevsim *ns)

drivers/net/netdevsim/ethtool.c +2 -0
@@ -250,12 +276,16 @@ void nsim_ethtool_init(struct netdevsim *ns)
 	ns->ethtool.fec.active_fec = ETHTOOL_FEC_NONE;
 
 	ns->ethtool.channels = ns->nsim_bus_dev->num_queues;
+	ns->ethtool.duplex = DUPLEX_FULL;
+	ns->ethtool.speed = SPEED_5000;
 
 	ethtool = debugfs_create_dir("ethtool", ns->nsim_dev_port->ddir);
 	ns->ethtool_ddir = ethtool;
 
Quoted 6 lines

drivers/net/netdevsim/ethtool.c void nsim_ethtool_init(struct netdevsim *ns) · line 288

Quoted 4 lines
drivers/net/netdevsim/ethtool.c +2 -0
 	debugfs_create_u32("get_err", 0600, ethtool, &ns->ethtool.get_err);
 	debugfs_create_u32("set_err", 0600, ethtool, &ns->ethtool.set_err);
+	debugfs_create_u32("speed", 0600, ethtool, &ns->ethtool.speed);
+	debugfs_create_u8("duplex", 0600, ethtool, &ns->ethtool.duplex);

debugfs_create_bool() ?

I'm not sure if anyone want to set nsim duplex to unknown for testing. Do you think that we should disable this behavior?

Quoted 7 lines
Quoted 4 lines

Ah, i did not think of DUPLEX_UNKNOWN.

We need to consider Jakubs reply, what are you actually testing here, do such tests make any sense?

I'm fixing a bug in bonding that need to test with different speed slaves. So I add this feature for netdevsim.

That would of been useful to put into the commit message, after the

---.

Better still, create a self test for the bonding bug you have found, show that it fails. Then have the fix, and show that the self test then passes. That makes it a lot clearer why this change is useful, plus it gives us a regression test to ensure bonding does not break again.

Andrew

maintainer
#7 lore raw
In reply to Hangbin Liu

drivers/net/netdevsim/ethtool.c static int nsim_get_ts_info(struct net_device *dev, · line 216

Quoted 9 lines
drivers/net/netdevsim/ethtool.c +9 -0
+static int nsim_get_link_ksettings(struct net_device *dev,
+				   struct ethtool_link_ksettings *cmd)
+{
+	struct netdevsim *ns = netdev_priv(dev);
+
+	cmd->base.speed		= ns->ethtool.speed;
+	cmd->base.duplex	= ns->ethtool.duplex;
+	cmd->base.port		= PORT_OTHER;
+	cmd->base.autoneg	= AUTONEG_DISABLE;

Here you hard code autoneg as disabled.

drivers/net/netdevsim/ethtool.c static int nsim_get_ts_info(struct net_device *dev, · line 229

Quoted 10 lines
drivers/net/netdevsim/ethtool.c +10 -0
+static int nsim_set_link_ksettings(struct net_device *dev,
+				   const struct ethtool_link_ksettings *cmd)
+{
+	struct netdevsim *ns = netdev_priv(dev);
+
+	if (cmd->base.speed > NSIM_LINK_SPEED_MAX)
+		return -EINVAL;
+
+	return ethtool_virtdev_set_link_ksettings(dev, cmd, &ns->ethtool.speed,
+						  &ns->ethtool.duplex);

but here you don't appear to block enabling autoneg. I would expect a test and EOPNOTSUPP.

Andrew

#8 lore raw

Hi Andrew,

Quoted 12 lines · Andrew Lunn

drivers/net/netdevsim/ethtool.c static int nsim_get_ts_info(struct net_device *dev, · line 216

Quoted 9 lines
drivers/net/netdevsim/ethtool.c +9 -0
+static int nsim_get_link_ksettings(struct net_device *dev,
+				   struct ethtool_link_ksettings *cmd)
+{
+	struct netdevsim *ns = netdev_priv(dev);
+
+	cmd->base.speed		= ns->ethtool.speed;
+	cmd->base.duplex	= ns->ethtool.duplex;
+	cmd->base.port		= PORT_OTHER;
+	cmd->base.autoneg	= AUTONEG_DISABLE;

Here you hard code autoneg as disabled.

Quoted 13 lines

drivers/net/netdevsim/ethtool.c static int nsim_get_ts_info(struct net_device *dev, · line 229

Quoted 10 lines
drivers/net/netdevsim/ethtool.c +10 -0
+static int nsim_set_link_ksettings(struct net_device *dev,
+				   const struct ethtool_link_ksettings *cmd)
+{
+	struct netdevsim *ns = netdev_priv(dev);
+
+	if (cmd->base.speed > NSIM_LINK_SPEED_MAX)
+		return -EINVAL;
+
+	return ethtool_virtdev_set_link_ksettings(dev, cmd, &ns->ethtool.speed,
+						  &ns->ethtool.duplex);

but here you don't appear to block enabling autoneg. I would expect a test and EOPNOTSUPP.

ethtool_virtdev_set_link_ksettings will check the cmds and only allow user to set speed and duplex. If a user tries to set autoneg it will return -EINVAL. Do you want nsim to return -EOPNOTSUPP specifically?

Thanks
Hangbin

maintainer
#9 lore raw
In reply to Hangbin Liu
Quoted 9 lines · On Mon, 31 Aug 2026 11:28:10 +0800 Hangbin Liu wrote:

Add ethtool get/set_link_ksettings callbacks to netdevsim so the simulated link speed and duplex can be queried and configured from userspace.

Move NSIM_LINK_SPEED_MAX and NSIM_LINK_SPEED_UNIT from dev.c to netdevsim.h so they are available to both the devlink rate path and the new ethtool code. The set callback rejects speeds exceeding NSIM_LINK_SPEED_MAX.

The default link speed is set to SPEED_5000 with DUPLEX_FULL, matching the existing NSIM_LINK_SPEED_MAX definition.

This breaks TDC which uses netdevsim for taprio testing. You posted 2 series for net-next and both broke tests. Please try harder to test stuff locally.
Matt added support for Docker to NIPA so you should be able to repro all ksfts locally. If something doesn't work please report back.

#10 lore raw
Quoted 4 lines · Jakub Kicinski
Quoted 3 lines · On Mon, 31 Aug 2026 11:28:10 +0800 Hangbin Liu wrote:

Add ethtool get/set_link_ksettings callbacks to netdevsim so the simulated link speed and duplex can be queried and configured from userspace.

Quoted 8 lines
Quoted 6 lines

Move NSIM_LINK_SPEED_MAX and NSIM_LINK_SPEED_UNIT from dev.c to netdevsim.h so they are available to both the devlink rate path and the new ethtool code. The set callback rejects speeds exceeding NSIM_LINK_SPEED_MAX.

The default link speed is set to SPEED_5000 with DUPLEX_FULL, matching the existing NSIM_LINK_SPEED_MAX definition.

This breaks TDC which uses netdevsim for taprio testing.

Sigh, I really didn't expect a speed feature could break the tc qdisc testing... I will check the reason.

Quoted 2 lines

You posted 2 series for net-next and both broke tests. Please try harder to test stuff locally.

Sorry for the extra work this caused you. You know I did not mean for this to happen.

Every time I prepare a patch, I build it locally, run the relevant selftests, and get an AI review before posting.

The selftest lib patch touches too many files. The fib_test failed locally without producing any useful error output: it returns 1, but I cannot spot the it by human viewing. The netdevsim test failed during tc testing, which I did not expect at all.

Quoted 3 lines

Matt added support for Docker to NIPA so you should be able to repro all ksfts locally. If something doesn't work please report back.

I will give this a try. NIPA could help capture this return‑1 failure.

Regarding the tc‑related failures: do you run the full set of network selftests for every single patch, or are there rules to select tests based on the changes? As you know, not all companies have testing resources comparable to RedHat. I have to run all these tests on my personal laptop.

Thanks
Hangbin

#11 lore raw
Quoted 9 lines · Hangbin Liu
Quoted 8 lines · Jakub Kicinski
Quoted 7 lines · On Mon, 31 Aug 2026 11:28:10 +0800 Hangbin Liu wrote:

Add ethtool get/set_link_ksettings callbacks to netdevsim so the simulated link speed and duplex can be queried and configured from userspace.

Move NSIM_LINK_SPEED_MAX and NSIM_LINK_SPEED_UNIT from dev.c to netdevsim.h so they are available to both the devlink rate path and the new ethtool code. The set callback rejects speeds exceeding NSIM_LINK_SPEED_MAX.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

The default link speed is set to SPEED_5000 with DUPLEX_FULL, matching the existing NSIM_LINK_SPEED_MAX definition.

This breaks TDC which uses netdevsim for taprio testing.

Sigh, I really didn't expect a speed feature could break the tc qdisc testing... I will check the reason.

OK, here is the reason. In taprio_set_picos_per_byte(), it init NIC speed to SPEED_10. If the NIC doesn't support get_link_ksettings, the final calculated picos_per_byte would be a extremely large number 800000. The later tc taprio testing tc qdisc ... sched-entry S 02 300 will always failed in fill_sched_entry(), as min_duration is also a large number 48000.

After we supports get_link_ksettings for netdevsim, the speed is 5000 and picos_per_byte will be init to 1600. The later min_duration checking in fill_sched_entry() is 300 vs 96. So the tc qdisc command always return 0.

To fix the test, I think we should reduce the interval number. e.g.

tools/testing/selftests/tc-testing/tc-tests/qdiscs/taprio.json +1 -1
index cd19d05925e4..c3418bde9ad6 100644
@@ -145,7 +145,7 @@
         "setup": [
             "echo \"1 1 8\" > /sys/bus/netdevsim/new_device"
         ],
-        "cmdUnderTest": "$TC qdisc add dev $ETH root handle 1: taprio num_tc 2 queues 1@0 1@1 sched-entry S 01 300 sched-entry S 02 1700 clockid CLOCK_TAI",
+        "cmdUnderTest": "$TC qdisc add dev $ETH root handle 1: taprio num_tc 2 queues 1@0 1@1 sched-entry S 01 30 sched-entry S 02 70 clockid CLOCK_TAI",
         "expExitCode": "2",
         "verifyCmd": "$TC qdisc show dev $ETH",
         "matchPattern": "qdisc taprio 1: root refcnt",

Thanks
Hangbin

maintainer
#12 lore raw
Quoted 24 lines · Hangbin Liu
Quoted 9 lines · Hangbin Liu
Quoted 8 lines · Jakub Kicinski
Quoted 7 lines · On Mon, 31 Aug 2026 11:28:10 +0800 Hangbin Liu wrote:

Add ethtool get/set_link_ksettings callbacks to netdevsim so the simulated link speed and duplex can be queried and configured from userspace.

Move NSIM_LINK_SPEED_MAX and NSIM_LINK_SPEED_UNIT from dev.c to netdevsim.h so they are available to both the devlink rate path and the new ethtool code. The set callback rejects speeds exceeding NSIM_LINK_SPEED_MAX.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

The default link speed is set to SPEED_5000 with DUPLEX_FULL, matching the existing NSIM_LINK_SPEED_MAX definition.

This breaks TDC which uses netdevsim for taprio testing.

Sigh, I really didn't expect a speed feature could break the tc qdisc testing... I will check the reason.

OK, here is the reason. In taprio_set_picos_per_byte(), it init NIC speed to SPEED_10. If the NIC doesn't support get_link_ksettings, the final calculated picos_per_byte would be a extremely large number 800000. The later tc taprio testing tc qdisc ... sched-entry S 02 300 will always failed in fill_sched_entry(), as min_duration is also a large number 48000.

Quoted 5 lines

After we supports get_link_ksettings for netdevsim, the speed is 5000 and picos_per_byte will be init to 1600. The later min_duration checking in fill_sched_entry() is 300 vs 96. So the tc qdisc command always return 0.

To fix the test, I think we should reduce the interval number. e.g.

Why not just set the initial speed to SPEED_10, so nothing changes?

Andrew

#13 lore raw
Quoted 6 lines · Andrew Lunn
Quoted 6 lines

OK, here is the reason. In taprio_set_picos_per_byte(), it init NIC speed to SPEED_10. If the NIC doesn't support get_link_ksettings, the final calculated picos_per_byte would be a extremely large number 800000. The later tc taprio testing tc qdisc ... sched-entry S 02 300 will always failed in fill_sched_entry(), as min_duration is also a large number 48000.

Quoted 8 lines
Quoted 5 lines

After we supports get_link_ksettings for netdevsim, the speed is 5000 and picos_per_byte will be init to 1600. The later min_duration checking in fill_sched_entry() is 300 vs 96. So the tc qdisc command always return 0.

To fix the test, I think we should reduce the interval number. e.g.

Why not just set the initial speed to SPEED_10, so nothing changes?

nsim_leaf_tx_share_set and nsim_leaf_tx_max_set compare against NSIM_LINK_SPEED_MAX for TX‑rate setting. Using SPEED_10 as the value appears too small. I am concerned this could break other existing tests.

Hangbin

maintainer
#14 lore raw
Quoted 11 lines · Hangbin Liu
Quoted 10 lines · Andrew Lunn
Quoted 10 lines

OK, here is the reason. In taprio_set_picos_per_byte(), it init NIC speed to SPEED_10. If the NIC doesn't support get_link_ksettings, the final calculated picos_per_byte would be a extremely large number 800000. The later tc taprio testing tc qdisc ... sched-entry S 02 300 will always failed in fill_sched_entry(), as min_duration is also a large number 48000.

After we supports get_link_ksettings for netdevsim, the speed is 5000 and picos_per_byte will be init to 1600. The later min_duration checking in fill_sched_entry() is 300 vs 96. So the tc qdisc command always return 0.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

To fix the test, I think we should reduce the interval number. e.g.

Why not just set the initial speed to SPEED_10, so nothing changes?

nsim_leaf_tx_share_set and nsim_leaf_tx_max_set compare against NSIM_LINK_SPEED_MAX for TX‑rate setting. Using SPEED_10 as the value appears too small. I am concerned this could break other existing tests.

Well, 10MBps has been around since 1983. I've not counted, but if you look at all the devices which Linux supports, i expect it is the most popular speed.

I suggest you give it a try, and run all the tests. See what happens. But to me, it is a safe choice.

Andrew

maintainer
#15 lore raw
In reply to Hangbin Liu
Quoted 3 lines

Regarding the tc‑related failures: do you run the full set of network selftests for every single patch, or are there rules to select tests based on the changes?

Not every single patch. Patchsets get collected into a bundle, and then all tests are run on a bundle.

Andrew

#16 lore raw

PATCH 2/2 selftests: netdevsim: add speed testing

In reply to Hangbin Liu

From: Hangbin Liu <[email protected]>

Add a script for netdevsim speed test. Make sure the speed and duplex could be changed. And the speed can't be larger than the max speed.

---
 .../selftests/drivers/net/netdevsim/Makefile       |  1 +
 .../drivers/net/netdevsim/ethtool-speed.sh         | 33 ++++++++++++++++++++++
 2 files changed, 34 insertions(+)
tools/testing/selftests/drivers/net/netdevsim/Makefile +1 -0
index 9808c2fbae9e..bd3d0f5ee07a 100644
@@ -8,6 +8,7 @@ TEST_PROGS := \
 	ethtool-features.sh \
 	ethtool-fec.sh \
 	ethtool-pause.sh \
+	ethtool-speed.sh \
 	fib.sh \
 	fib_notifications.sh \
 	hw_stats_l3.sh \
tools/testing/selftests/drivers/net/netdevsim/ethtool-speed.sh new file +33 -0
new file mode 100755
index 000000000000..c8aefa9c8a1f
@@ -0,0 +1,33 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+
+source ethtool-common.sh
+
+NSIM_NETDEV=$(make_netdev)
+
+set -o pipefail
+
+s=$(ethtool --json "$NSIM_NETDEV" | jq '.[].speed')
+check $? "$s" "5000"
+
+s=$(ethtool --json "$NSIM_NETDEV" | jq -r '.[].duplex')
+check $? "$s" "Full"
+
+ethtool -s "$NSIM_NETDEV" speed 1000 duplex half
+
+s=$(ethtool --json "$NSIM_NETDEV" | jq '.[].speed')
+check $? "$s" "1000"
+
+s=$(ethtool --json "$NSIM_NETDEV" | jq -r '.[].duplex')
+check $? "$s" "Half"
+
+ethtool -s "$NSIM_NETDEV" speed 10000 2>/dev/null
+check $? "" "" 1
+
+if [ "$num_errors" -eq 0 ]; then
+    echo "PASSED all $((num_passes)) checks"
+    exit 0
+else
+    echo "FAILED $num_errors/$((num_errors+num_passes)) checks"
+    exit 1
+fi
Signature · 1 line
2.55.0
maintainer NAK
#17 lore raw

Re: [PATCH net-next 2/2] selftests: netdevsim: add speed testing

Quoted 2 lines · On Mon, 31 Aug 2026 11:28:11 +0800 Hangbin Liu wrote:

Add a script for netdevsim speed test. Make sure the speed and duplex could be changed. And the speed can't be larger than the max speed.

nak, this is not a meaningful test

#18 lore raw

Re: [PATCH net-next 2/2] selftests: netdevsim: add speed testing

Quoted 5 lines · Jakub Kicinski
Quoted 2 lines · On Mon, 31 Aug 2026 11:28:11 +0800 Hangbin Liu wrote:

Add a script for netdevsim speed test. Make sure the speed and duplex could be changed. And the speed can't be larger than the max speed.

nak, this is not a meaningful test

OK, I thought we should add selftests for new features. And there are netdevsim ethtool tests like ethtool-pause.sh. Since you think this test is meaningless. I will drop it in next version.

Hangbin

maintainer
#19 lore raw

Re: [PATCH net-next 2/2] selftests: netdevsim: add speed testing

Quoted 10 lines · On Tue, 1 Sep 2026 14:42:06 +0800 Hangbin Liu wrote:
Quoted 5 lines · Jakub Kicinski
Quoted 2 lines · On Mon, 31 Aug 2026 11:28:11 +0800 Hangbin Liu wrote:

Add a script for netdevsim speed test. Make sure the speed and duplex could be changed. And the speed can't be larger than the max speed.

nak, this is not a meaningful test

OK, I thought we should add selftests for new features. And there are netdevsim ethtool tests like ethtool-pause.sh. Since you think this test is meaningless. I will drop it in next version.

to be clear - the entire patch set, not just the test.

#20 lore raw

Re: [PATCH net-next 2/2] selftests: netdevsim: add speed testing

Quoted 6 lines · Jakub Kicinski
Quoted 5 lines · On Tue, 1 Sep 2026 14:42:06 +0800 Hangbin Liu wrote:
Quoted 4 lines · Jakub Kicinski
Quoted 2 lines · On Mon, 31 Aug 2026 11:28:11 +0800 Hangbin Liu wrote:

Add a script for netdevsim speed test. Make sure the speed and duplex could be changed. And the speed can't be larger than the max speed.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

nak, this is not a meaningful test

OK, I thought we should add selftests for new features. And there are netdevsim ethtool tests like ethtool-pause.sh. Since you think this test is meaningless. I will drop it in next version.

to be clear - the entire patch set, not just the test.

OK... Thank you for the clarification. I will drop this patch set.

Regards
Hangbin