From nobody Sat Sep 26 20:31:42 2026 Received: from mta0.migadu.com (out-167.mta0.migadu.com [91.218.175.167]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F8B63955E7 for ; Mon, 31 Aug 2026 03:28:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.167 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788146913; cv=none; b=XVFopKguu8VSeMf6KaPXF31wkau4lATQZNWX65EYXS7Tg2VInCUbSMLIXZa2Wk/GVXGfEPasuXhwJ7dj3XOEI6NGIfPAIYcIHLN/YEbgvXmNbDBUsM1M3EinnJh2rCIkl5fSS1l4XalngJGL6MaAq+M8wzAxBeZhCWy2wUpG/qA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788146913; c=relaxed/simple; bh=1gsJOXGf/E6xufKHweGQszf77SbKMiZsrOXoexOCrjg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kZrG7pZGhSLye4ePeusTECQTxyJRJPUH+faS+N6/agGXB3RF/CrSjFRcidTbyZIx7Li8v4wv6k6pGoqmPKzM+Ly6E84LOBX3Y1TJaQwUCn0oSbg6NIXzVMF5XIQxbtBPb+qBJVx1X6OT+iFXU30VS5VAyozeTpzS9VhlPmLV8iI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=KdiIF7Lb; arc=none smtp.client-ip=91.218.175.167 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="KdiIF7Lb" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=1gsJOXGf/E6xufKHweGQszf77SbKMiZsrOXoexOCrjg=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1788146909; v=1; x=1788751709; b=KdiIF7LbLxZbd9HdVC4JgQ+SG9D2wHD3WYWCYxDlVVCSiKSUcVk2IAsKXS4AAw3pjvfI+kwJ wyEyFYPgFdw5gi8Memfmt22CybBdzf8qrol0MVzDgy7D7p3iyn3Fx/u4BSPB1f6PbDB0LNFOwmR 4soGvoeQkO4aqEUrLBKO8Y4A= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id d582106826e16177; Mon, 31 Aug 2026 03:28:29 +0000 X-Mizu-Trace-ID: d582106826e16177 X-Migadu-Flow: FLOW_OUT From: Hangbin Liu Date: Mon, 31 Aug 2026 11:28:10 +0800 Subject: [PATCH net-next 1/2] netdevsim: add link speed support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260831-nsim_speed-v1-1-7a651ee65738@kylinos.cn> References: <20260831-nsim_speed-v1-0-7a651ee65738@kylinos.cn> In-Reply-To: <20260831-nsim_speed-v1-0-7a651ee65738@kylinos.cn> To: Jakub Kicinski , Andrew Lunn , "David S. Miller" , Eric Dumazet , Paolo Abeni , Shuah Khan Cc: Hangbin Liu , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Hangbin Liu X-Mailer: b4 0.14.3 From: Hangbin Liu 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. Signed-off-by: Hangbin Liu --- 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(-) diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index feb88ccbbced..729ce80f6c83 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -1138,12 +1138,6 @@ nsim_dev_devlink_trap_policer_counter_get(struct dev= link *devlink, return 0; } =20 -#define NSIM_LINK_SPEED_MAX 5000 /* Mbps */ -#define NSIM_LINK_SPEED_UNIT 125000 /* 1 Mbps given in bytes/sec to avo= id - * 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; diff --git a/drivers/net/netdevsim/ethtool.c b/drivers/net/netdevsim/ethtoo= l.c index 025ea79879f3..59768bd7b620 100644 --- a/drivers/net/netdevsim/ethtool.c +++ b/drivers/net/netdevsim/ethtool.c @@ -205,6 +205,30 @@ static int nsim_get_ts_info(struct net_device *dev, return 0; } =20 +static int nsim_get_link_ksettings(struct net_device *dev, + struct ethtool_link_ksettings *cmd) +{ + struct netdevsim *ns =3D netdev_priv(dev); + + cmd->base.speed =3D ns->ethtool.speed; + cmd->base.duplex =3D ns->ethtool.duplex; + cmd->base.port =3D PORT_OTHER; + cmd->base.autoneg =3D AUTONEG_DISABLE; + return 0; +} + +static int nsim_set_link_ksettings(struct net_device *dev, + const struct ethtool_link_ksettings *cmd) +{ + struct netdevsim *ns =3D 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 =3D { .supported_coalesce_params =3D ETHTOOL_COALESCE_ALL_PARAMS, .supported_ring_params =3D ETHTOOL_RING_USE_TCP_DATA_SPLIT | @@ -223,6 +247,8 @@ static const struct ethtool_ops nsim_ethtool_ops =3D { .set_fecparam =3D nsim_set_fecparam, .get_fec_stats =3D nsim_get_fec_stats, .get_ts_info =3D nsim_get_ts_info, + .get_link_ksettings =3D nsim_get_link_ksettings, + .set_link_ksettings =3D nsim_set_link_ksettings, }; =20 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 =3D ETHTOOL_FEC_NONE; =20 ns->ethtool.channels =3D ns->nsim_bus_dev->num_queues; + ns->ethtool.duplex =3D DUPLEX_FULL; + ns->ethtool.speed =3D SPEED_5000; =20 ethtool =3D debugfs_create_dir("ethtool", ns->nsim_dev_port->ddir); ns->ethtool_ddir =3D ethtool; =20 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); =20 dir =3D debugfs_create_dir("pause", ethtool); debugfs_create_bool("report_stats_rx", 0600, dir, diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netd= evsim.h index 55aec41237b9..ce0d0dea00fb 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -39,6 +39,11 @@ =20 #define NSIM_HDS_THRESHOLD_MAX 1024 =20 +#define NSIM_LINK_SPEED_MAX 5000 /* Mbps */ +#define NSIM_LINK_SPEED_UNIT 125000 /* 1 Mbps given in bytes/sec to avo= id + * 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; }; =20 struct nsim_rq { --=20 2.55.0 From nobody Sat Sep 26 20:31:42 2026 Received: from mta1.migadu.com (out-73.mta1.migadu.com [95.215.58.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69AEE3A75B8 for ; Mon, 31 Aug 2026 03:28:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788146920; cv=none; b=FjhVu1fjrSF9UQkto+tvev1yikx2GMfej8wRvG/3Wy5pOShNgcL1dqflELaYsLTGK5eZNIy3CTRDupwnOiBCzKi1vGOC1A78ygtXGvZG+X8y0JVbhlxmGTi0KQMD+HJLJX+Uej6/g4EP/FrSApFHe5F3piPfewqJ+WFZ54wA458= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788146920; c=relaxed/simple; bh=GdGUFYwI9sLmW78ms41T6yri69KUsRuYa4AHoe0nVuk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bppsAWZLbbfgpeg1BtWS4eDatpXXsDvixvMGvxGEomDLXTM9l3jHUpIsP8yZmc9frmzWAZnQnVJ82Fb0weMYHwivPb2+mp13u3TklBTeWZsFNjO97eMGS7r45YT9vS/Y9VciGtnEgNA+paM4xqRRfnBp9ZHDMtGxS7m05nd3xxk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=nvsCJ2Qv; arc=none smtp.client-ip=95.215.58.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="nvsCJ2Qv" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=GdGUFYwI9sLmW78ms41T6yri69KUsRuYa4AHoe0nVuk=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1788146916; v=1; x=1788751716; b=nvsCJ2QvVObrFoWi9rAZvH8VQsu/siGNvljMvf3Sg3MeKfF6ElFOoLzOFxJZ7pIDxMOvPhHT 6rI6KQ2Ap8Df5LplbVzjktYpBWQbd4P64LiroI/MWtdsYnEU054FOz3+X18NzF9qoSeA1qsCIEs /NnMRbZrKgrhrxMJWS76/csE= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id d7065f2427c3e93a; Mon, 31 Aug 2026 03:28:36 +0000 X-Mizu-Trace-ID: d7065f2427c3e93a X-Migadu-Flow: FLOW_OUT From: Hangbin Liu Date: Mon, 31 Aug 2026 11:28:11 +0800 Subject: [PATCH net-next 2/2] selftests: netdevsim: add speed testing Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260831-nsim_speed-v1-2-7a651ee65738@kylinos.cn> References: <20260831-nsim_speed-v1-0-7a651ee65738@kylinos.cn> In-Reply-To: <20260831-nsim_speed-v1-0-7a651ee65738@kylinos.cn> To: Jakub Kicinski , Andrew Lunn , "David S. Miller" , Eric Dumazet , Paolo Abeni , Shuah Khan Cc: Hangbin Liu , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Hangbin Liu X-Mailer: b4 0.14.3 From: Hangbin Liu 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. Signed-off-by: Hangbin Liu --- .../selftests/drivers/net/netdevsim/Makefile | 1 + .../drivers/net/netdevsim/ethtool-speed.sh | 33 ++++++++++++++++++= ++++ 2 files changed, 34 insertions(+) diff --git a/tools/testing/selftests/drivers/net/netdevsim/Makefile b/tools= /testing/selftests/drivers/net/netdevsim/Makefile index 9808c2fbae9e..bd3d0f5ee07a 100644 --- a/tools/testing/selftests/drivers/net/netdevsim/Makefile +++ b/tools/testing/selftests/drivers/net/netdevsim/Makefile @@ -8,6 +8,7 @@ TEST_PROGS :=3D \ ethtool-features.sh \ ethtool-fec.sh \ ethtool-pause.sh \ + ethtool-speed.sh \ fib.sh \ fib_notifications.sh \ hw_stats_l3.sh \ diff --git a/tools/testing/selftests/drivers/net/netdevsim/ethtool-speed.sh= b/tools/testing/selftests/drivers/net/netdevsim/ethtool-speed.sh new file mode 100755 index 000000000000..c8aefa9c8a1f --- /dev/null +++ b/tools/testing/selftests/drivers/net/netdevsim/ethtool-speed.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only + +source ethtool-common.sh + +NSIM_NETDEV=3D$(make_netdev) + +set -o pipefail + +s=3D$(ethtool --json "$NSIM_NETDEV" | jq '.[].speed') +check $? "$s" "5000" + +s=3D$(ethtool --json "$NSIM_NETDEV" | jq -r '.[].duplex') +check $? "$s" "Full" + +ethtool -s "$NSIM_NETDEV" speed 1000 duplex half + +s=3D$(ethtool --json "$NSIM_NETDEV" | jq '.[].speed') +check $? "$s" "1000" + +s=3D$(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 --=20 2.55.0