From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CAE7F280308; Thu, 10 Jul 2025 06:23:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.193 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752128585; cv=none; b=q+iGpqUjlpuGIGcpd1ln+ULRFE/yBM1fPsw2KBusAUkr0Ix8iottRJjBRV94uRdUZFFL6ESLZmOAEcxGxKM4i3/4xeSWbsnwz3AEgt2Ig9XkS8ZA+biWgCFNvsOFZdvAq5QJLUsoMFG3SLkexxlC0csvG/SBOo3I0kh4qiOtme8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752128585; c=relaxed/simple; bh=JXTBH1n5C03e9YAeMfPrLiKH4adM3tDux3oo/ksXWBE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BqkE07KGzZWqLSdMvtU0pXBoU3v3THcqvSFMAgjpqJ6A27cXpt9ouHf2FkHwPnim3z0scYDIJckL3iNb5OH6vaYBbuoFWZkxpaldvKmhniR06FE6+ZAz2naIkOxBJtdBb7Wp/kCvVMCNR6m5T5NMIjX/hFzbHZyQnp++4iDqiqU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=XoFfrMXc; arc=none smtp.client-ip=217.70.183.193 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="XoFfrMXc" Received: by mail.gandi.net (Postfix) with ESMTPSA id 4EA0B42E77; Thu, 10 Jul 2025 06:22:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1752128580; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FKLJQx8y+r0nUlrTaPnBNH5DOZUZAbdKtbnXwbqzRRE=; b=XoFfrMXcolqyVgPd+HdseZ3We2zwCCKOHdsVjVwlU9N2O2+6X1RAx9StT1mTwDhUMWRtJ4 RMxeKaMorv3ulyGboQj/ut2ZDT4KU/i3cEOqTvshQVCOB2tYPQvRsmL4COVndxjQuy5e14 k3Hp1iCuyizKbH2RFCFWsd7tVhk90wCZyRUMzoEkRvJUnEgo5hHCOhWHlNLqoGhneqwQDH ifO8A+2Dj8o3AyOC8IQZnt53TyiMi7Ir4hNdQVuiBjoSYhL2jXHQOI29th7VaEuGh7ywA/ YBgNXsoot19TAScvB4qPNjileoTkzpF7gJdtSIEe7dR5sKfdlU+srfL+S8uNcg== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , Florian Fainelli , Heiner Kallweit , Vladimir Oltean , =?UTF-8?q?K=C3=B6ry=20Maincent?= , Oleksij Rempel , Simon Horman , Shuah Khan , linux-kselftest@vger.kernel.org Subject: [PATCH net-next v3 3/3] selftests: ethtool: Introduce ethernet PHY selftests on netdevsim Date: Thu, 10 Jul 2025 08:22:47 +0200 Message-ID: <20250710062248.378459-4-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250710062248.378459-1-maxime.chevallier@bootlin.com> References: <20250710062248.378459-1-maxime.chevallier@bootlin.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdefleejudcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepofgrgihimhgvucevhhgvvhgrlhhlihgvrhcuoehmrgigihhmvgdrtghhvghvrghllhhivghrsegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeevgedtffelffelveeuleelgfejfeevvdejhfehgeefgfffvdefteegvedutefftdenucfkphepvdgrtddumegtsgduleemkegugeehmeegledttdemieehieekmedvlegsudemlegvfhehmegvkegtjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudelmeekugegheemgeeltddtmeeiheeikeemvdelsgdumeelvghfheemvgektgejpdhhvghlohepfhgvughorhgrrdhhohhmvgdpmhgrihhlfhhrohhmpehmrgigihhmvgdrtghhvghvrghllhhivghrsegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopedukedprhgtphhtthhopegurghvvghmsegurghvvghmlhhofhhtrdhnvghtpdhrtghpthhtohepmhgrgihimhgvrdgthhgvvhgrlhhlihgvrhessghoohhtlhhinhdrtghomhdprhgtphhtthhopehnvghtuggvvhesvhhgvghrrdhkv ghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehthhhomhgrshdrphgvthgriiiiohhnihessghoohhtlhhinhdrtghomhdprhgtphhtthhopegrnhgurhgvfieslhhunhhnrdgthhdprhgtphhtthhopehkuhgsrgeskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepvgguuhhmrgiivghtsehgohhoghhlvgdrtghomh X-GND-Sasl: maxime.chevallier@bootlin.com Now that netdevsim supports PHY device simulation, we can start writing some tests to cover a little bit all PHY-related ethtool commands. So far we only test the basic use of "ethtool --show-phys", with : - A simple command to get a PHY we just added - A DUMP command listing PHYs on multiple netdevsim instances - A Filtered DUMP command listing all PHYs on a netdevsim Introduce some helpers to create netdevsim PHYs, and a new test file. Signed-off-by: Maxime Chevallier --- .../selftests/drivers/net/netdevsim/config | 1 + .../drivers/net/netdevsim/ethtool-common.sh | 15 +++++ .../drivers/net/netdevsim/ethtool-phy.sh | 64 +++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100755 tools/testing/selftests/drivers/net/netdevsim/ethtool-phy.sh diff --git a/tools/testing/selftests/drivers/net/netdevsim/config b/tools/testing/selftests/drivers/net/netdevsim/config index 5117c78ddf0a..223e82cb7759 100644 --- a/tools/testing/selftests/drivers/net/netdevsim/config +++ b/tools/testing/selftests/drivers/net/netdevsim/config @@ -6,6 +6,7 @@ CONFIG_NETDEVSIM=m CONFIG_NET_SCH_MQPRIO=y CONFIG_NET_SCH_MULTIQ=y CONFIG_NET_SCH_PRIO=y +CONFIG_PHYLIB=m CONFIG_PSAMPLE=y CONFIG_PTP_1588_CLOCK_MOCK=y CONFIG_VXLAN=m diff --git a/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh b/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh index d9c7a3d397a9..1bd0ac5e7bba 100644 --- a/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh +++ b/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh @@ -53,3 +53,18 @@ function make_netdev { # get new device name ls /sys/bus/netdevsim/devices/netdevsim${NSIM_ID}/net/ } + +function make_phydev_on_netdev { + local parent_ndev_nsim_id=$1 + local parent=$2 + + local ndev_dfs=/sys/kernel/debug/netdevsim/netdevsim$parent_ndev_nsim_id/ports/0 + + old_dev_dfs=$(find $ndev_dfs -type d) + echo $parent > $ndev_dfs/phy_add + new_dev_dfs=$(find $ndev_dfs -type d) + + # The new phydev name corresponds to the new file that was created. Its + # name isn't predictable. + echo $old_dev_dfs $new_dev_dfs | xargs -n1 | sort | uniq -u +} diff --git a/tools/testing/selftests/drivers/net/netdevsim/ethtool-phy.sh b/tools/testing/selftests/drivers/net/netdevsim/ethtool-phy.sh new file mode 100755 index 000000000000..b10440d108b2 --- /dev/null +++ b/tools/testing/selftests/drivers/net/netdevsim/ethtool-phy.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only + +source ethtool-common.sh + +# Bail if ethtool is too old +if ! ethtool -h | grep show-phys >/dev/null 2>&1; then + echo "SKIP: No --show-phys support in ethtool" + exit 4 +fi + +function make_netdev_from_id { + local new_nsim_id="$1" + # Make a netdevsim + echo "$new_nsim_id" > /sys/bus/netdevsim/new_device + udevadm settle + # get new device name + ls /sys/bus/netdevsim/devices/netdevsim"${new_nsim_id}"/net/ +} + +function cleanup_netdev_from_id { + local to_del_nsim_id="$1" + echo "$to_del_nsim_id" > /sys/bus/netdevsim/del_device +} + +NSIM_NETDEV=$(make_netdev) + +set -o pipefail + +# Check simple PHY addition and listing + +# Parent == 0 means that the PHY's parent is the netdev +PHY_DFS=$(make_phydev_on_netdev "$NSIM_ID" 0) + +# First PHY gets index 1 +index=$(ethtool --show-phys "$NSIM_NETDEV" | grep "PHY index" | cut -d ' ' -f 3) +check $? "$index" "1" + +# Insert a second PHY, same parent. It gets index 2. +PHY2_DFS=$(make_phydev_on_netdev "$NSIM_ID" 0) + +# Create another netdev +NSIM_ID2=$((RANDOM % 1024)) +NSIM_NETDEV_2=$(make_netdev_from_id "$NSIM_ID2") + +PHY3_DFS=$(make_phydev_on_netdev "$NSIM_ID2" 0); + +# Check unfiltered PHY Dump +n_phy=$(ethtool --show-phys '*' | grep -c "PHY index") +check $? "$n_phy" "3" + +# Check filtered Dump +n_phy=$(ethtool --show-phys "$NSIM_NETDEV" | grep -c "PHY index") +check $? "$n_phy" "2" + +cleanup_netdev_from_id "$NSIM_ID2" + +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 -- 2.49.0