Skip to contentSkip to conversation

amd-xgbe: introduce support for ethtool selftests

PATCH Applied Raju Rangoju 2 participants 6 messages Oct 31, 2025 – Nov 6, 2025

Subsystems (3)
lore
Share & tools
lore

Raju Rangoju

author maintainer
#0 lore raw

v6 cover amd-xgbe: introduce support for ethtool selftests

This patch series introduces support for ethtool selftests, which helps in finding the misconfiguration of HW. Makes use of network selftest packet creation infrastructure.

Supports the following tests:

- MAC loopback selftest
- PHY loopback selftest
- Split header selftest
- Jubmo frame selftest

Changes since v5:
- follow reverse x-mas tree format
- fix the commit message for phy loopback selftest
Changes since v4:
- remove double semicolon
- move the helper functions to appropriate file
- add inline keyword to static function in header file
Changes since v3:
- add new patch to export packet creation helpers for driver use
Changes since v2:
- fix build warnings for xtensa and alpha arch Changes since v1:
- fix build warnings for s390 arch reported by kernel test robot

Raju Rangoju (5):
net: selftests: export packet creation helpers for driver use
amd-xgbe: introduce support ethtool selftest
amd-xgbe: add ethtool phy loopback selftest
amd-xgbe: add ethtool split header selftest
amd-xgbe: add ethtool jumbo frame selftest

 drivers/net/ethernet/amd/Kconfig              |   1 +
 drivers/net/ethernet/amd/xgbe/Makefile        |   2 +-
 drivers/net/ethernet/amd/xgbe/xgbe-dev.c      |  19 +
 drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c  |   7 +
 drivers/net/ethernet/amd/xgbe/xgbe-selftest.c | 346 ++++++++++++++++++
 drivers/net/ethernet/amd/xgbe/xgbe.h          |  11 +
 include/net/selftests.h                       |  45 +++
 net/core/selftests.c                          |  48 +--
 8 files changed, 437 insertions(+), 42 deletions(-)
 create mode 100644 drivers/net/ethernet/amd/xgbe/xgbe-selftest.c
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v6 2/5 amd-xgbe: introduce support ethtool selftest

Add support for ethtool selftest for MAC loopback. This includes the sanity check and helps in finding the misconfiguration of HW. Uses the existing selftest infrastructure to create test packets.

---
Changes since v5:
- follow reverse x-mas tree format
Changes since v4:
- move the helper functions to appropriate file
Changes since v3:
- reuse the existing selftest framework for packet creation
Changes since v2:
- fix build warnings for xtensa arch
Changes since v1:
- fix build warnings for s390 arch reported by kernel test robot

 drivers/net/ethernet/amd/Kconfig              |   1 +
 drivers/net/ethernet/amd/xgbe/Makefile        |   2 +-
 drivers/net/ethernet/amd/xgbe/xgbe-dev.c      |  17 ++
 drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c  |   7 +
 drivers/net/ethernet/amd/xgbe/xgbe-selftest.c | 237 ++++++++++++++++++
 drivers/net/ethernet/amd/xgbe/xgbe.h          |  10 +
 6 files changed, 273 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/amd/xgbe/xgbe-selftest.c
drivers/net/ethernet/amd/Kconfig +1 -0
index b39c6f3e1eda..d54dca3074eb 100644
@@ -165,6 +165,7 @@ config AMD_XGBE
 	select CRC32
 	select PHYLIB
 	select AMD_XGBE_HAVE_ECC if X86
+	select NET_SELFTESTS
 	help
 	  This driver supports the AMD 10GbE Ethernet device found on an
 	  AMD SoC.
drivers/net/ethernet/amd/xgbe/Makefile +1 -1
index 980e27652237..5992f7fd4d9b 100644
@@ -5,7 +5,7 @@ amd-xgbe-objs := xgbe-main.o xgbe-drv.o xgbe-dev.o \
 		 xgbe-desc.o xgbe-ethtool.o xgbe-mdio.o \
 		 xgbe-hwtstamp.o xgbe-ptp.o xgbe-pps.o \
 		 xgbe-i2c.o xgbe-phy-v1.o xgbe-phy-v2.o \
-		 xgbe-platform.o
+		 xgbe-platform.o xgbe-selftest.o
 
 amd-xgbe-$(CONFIG_PCI) += xgbe-pci.o
 amd-xgbe-$(CONFIG_AMD_XGBE_DCB) += xgbe-dcb.o
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +17 -0
index e5391a2eca51..ffc7d83522c7 100644
@@ -3578,3 +3578,20 @@ void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
 
 	DBGPR("<--xgbe_init_function_ptrs\n");
 }
+
+int xgbe_enable_mac_loopback(struct xgbe_prv_data *pdata)
+{
+	/* Enable MAC loopback mode */
+	XGMAC_IOWRITE_BITS(pdata, MAC_RCR, LM, 1);
+
+	/* Wait for loopback to stabilize */
+	usleep_range(10, 15);
+
+	return 0;
+}
+
+void xgbe_disable_mac_loopback(struct xgbe_prv_data *pdata)
+{
+	/* Disable MAC loopback mode */
+	XGMAC_IOWRITE_BITS(pdata, MAC_RCR, LM, 0);
+}
drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c +7 -0
index b6e1b67a2d0e..0d19b09497a0 100644
@@ -85,6 +85,9 @@ static void xgbe_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
 	int i;
 
 	switch (stringset) {
+	case ETH_SS_TEST:
+		xgbe_selftest_get_strings(pdata, data);
+		break;
 	case ETH_SS_STATS:
 		for (i = 0; i < XGBE_STATS_COUNT; i++)
 			ethtool_puts(&data, xgbe_gstring_stats[i].stat_string);
@@ -131,6 +134,9 @@ static int xgbe_get_sset_count(struct net_device *netdev, int stringset)
 	int ret;
 
 	switch (stringset) {
+	case ETH_SS_TEST:
+		ret = xgbe_selftest_get_count(pdata);
+		break;
 	case ETH_SS_STATS:
 		ret = XGBE_STATS_COUNT +
 		      (pdata->tx_ring_count * 2) +
@@ -760,6 +766,7 @@ static const struct ethtool_ops xgbe_ethtool_ops = {
 	.set_ringparam = xgbe_set_ringparam,
 	.get_channels = xgbe_get_channels,
 	.set_channels = xgbe_set_channels,
+	.self_test = xgbe_selftest_run,
 };
 
 const struct ethtool_ops *xgbe_get_ethtool_ops(void)
drivers/net/ethernet/amd/xgbe/xgbe-selftest.c new file +237 -0

237 lines not on this page · raw message

drivers/net/ethernet/amd/xgbe/xgbe.h +10 -0
index 381f72a33d1a..dc03082c59aa 100644
@@ -1322,6 +1322,16 @@ void xgbe_update_tstamp_time(struct xgbe_prv_data *pdata, unsigned int sec,
 int xgbe_pps_config(struct xgbe_prv_data *pdata, struct xgbe_pps_config *cfg,
 		    int index, bool on);
 
+/* Selftest functions */
+void xgbe_selftest_run(struct net_device *dev,
+		       struct ethtool_test *etest, u64 *buf);
+void xgbe_selftest_get_strings(struct xgbe_prv_data *pdata, u8 *data);
+int xgbe_selftest_get_count(struct xgbe_prv_data *pdata);
+
+/* Loopback control */
+int xgbe_enable_mac_loopback(struct xgbe_prv_data *pdata);
+void xgbe_disable_mac_loopback(struct xgbe_prv_data *pdata);
+
 #ifdef CONFIG_DEBUG_FS
 void xgbe_debugfs_init(struct xgbe_prv_data *);
 void xgbe_debugfs_exit(struct xgbe_prv_data *);
Signature · 1 line
2.34.1
author maintainer
#2 lore raw

PATCH v6 3/5 amd-xgbe: add ethtool phy loopback selftest

In reply to Raju Rangoju

Add support for PHY loopback testing via ethtool self-test. The test uses phy_loopback() which enables PHY-level loopback through the PHY driver's set_loopback callback if provided, else uses the genphy_loopback().

---
Changes since v5:
- fix the commit message
Changes since v2:
- fix build warnings for alpha arch

 drivers/net/ethernet/amd/xgbe/xgbe-selftest.c | 40 +++++++++++++++++++
 1 file changed, 40 insertions(+)
drivers/net/ethernet/amd/xgbe/xgbe-selftest.c +40 -0
index 8a3a6279584d..23b9d568a861 100644
@@ -19,6 +19,7 @@
 
 #define XGBE_LOOPBACK_NONE	0
 #define XGBE_LOOPBACK_MAC	1
+#define XGBE_LOOPBACK_PHY	2
 
 struct xgbe_test {
 	char name[ETH_GSTRING_LEN];
@@ -151,11 +152,36 @@ static int xgbe_test_mac_loopback(struct xgbe_prv_data *pdata)
 	return __xgbe_test_loopback(pdata, &attr);
 }
 
+static int xgbe_test_phy_loopback(struct xgbe_prv_data *pdata)
+{
+	struct net_packet_attrs attr = {};
+	int ret;
+
+	if (!pdata->netdev->phydev) {
+		netdev_err(pdata->netdev, "phydev not found: cannot start PHY loopback test\n");
+		return -EOPNOTSUPP;
+	}
+
+	ret = phy_loopback(pdata->netdev->phydev, true, 0);
+	if (ret)
+		return ret;
+
+	attr.dst = pdata->netdev->dev_addr;
+	ret = __xgbe_test_loopback(pdata, &attr);
+
+	phy_loopback(pdata->netdev->phydev, false, 0);
+	return ret;
+}
+
 static const struct xgbe_test xgbe_selftests[] = {
 	{
 		.name = "MAC Loopback   ",
 		.lb = XGBE_LOOPBACK_MAC,
 		.fn = xgbe_test_mac_loopback,
+	}, {
+		.name = "PHY Loopback   ",
+		.lb = XGBE_LOOPBACK_NONE,
+		.fn = xgbe_test_phy_loopback,
 	},
 };
 
@@ -187,6 +213,13 @@ void xgbe_selftest_run(struct net_device *dev,
 		ret = 0;
 
 		switch (xgbe_selftests[i].lb) {
+		case XGBE_LOOPBACK_PHY:
+			ret = -EOPNOTSUPP;
+			if (dev->phydev)
+				ret = phy_loopback(dev->phydev, true, 0);
+			if (!ret)
+				break;
+			fallthrough;
 		case XGBE_LOOPBACK_MAC:
 			ret = xgbe_enable_mac_loopback(pdata);
 			break;
@@ -213,6 +246,13 @@ void xgbe_selftest_run(struct net_device *dev,
 		buf[i] = ret;
 
 		switch (xgbe_selftests[i].lb) {
+		case XGBE_LOOPBACK_PHY:
+			ret = -EOPNOTSUPP;
+			if (dev->phydev)
+				ret = phy_loopback(dev->phydev, false, 0);
+			if (!ret)
+				break;
+			fallthrough;
 		case XGBE_LOOPBACK_MAC:
 			xgbe_disable_mac_loopback(pdata);
 			break;
Signature · 1 line
2.34.1
author maintainer
#3 lore raw

PATCH v6 4/5 amd-xgbe: add ethtool split header selftest

In reply to Raju Rangoju

Adds support for ethtool split header selftest. Performs UDP and TCP check to ensure split header selft test works for both packet types.

---
 drivers/net/ethernet/amd/xgbe/xgbe-dev.c      |  2 +
 drivers/net/ethernet/amd/xgbe/xgbe-selftest.c | 46 +++++++++++++++++++
 drivers/net/ethernet/amd/xgbe/xgbe.h          |  1 +
 3 files changed, 49 insertions(+)
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +2 -0
index ffc7d83522c7..b646ae575e6a 100644
@@ -211,6 +211,7 @@ static void xgbe_config_sph_mode(struct xgbe_prv_data *pdata)
 	}
 
 	XGMAC_IOWRITE_BITS(pdata, MAC_RCR, HDSMS, XGBE_SPH_HDSMS_SIZE);
+	pdata->sph = true;
 }
 
 static void xgbe_disable_sph_mode(struct xgbe_prv_data *pdata)
@@ -223,6 +224,7 @@ static void xgbe_disable_sph_mode(struct xgbe_prv_data *pdata)
 
 		XGMAC_DMA_IOWRITE_BITS(pdata->channel[i], DMA_CH_CR, SPH, 0);
 	}
+	pdata->sph = false;
 }
 
 static int xgbe_write_rss_reg(struct xgbe_prv_data *pdata, unsigned int type,
drivers/net/ethernet/amd/xgbe/xgbe-selftest.c +46 -0

58 lines not on this page · raw message

drivers/net/ethernet/amd/xgbe/xgbe.h +1 -0
index dc03082c59aa..03ef0f548483 100644
@@ -1246,6 +1246,7 @@ struct xgbe_prv_data {
 	int rx_adapt_retries;
 	bool rx_adapt_done;
 	bool mode_set;
+	bool sph;
 };
 
 /* Function prototypes*/
Signature · 1 line
2.34.1
author maintainer
#4 lore raw

PATCH v6 5/5 amd-xgbe: add ethtool jumbo frame selftest

In reply to Raju Rangoju

Adds support for jumbo frame selftest. Works only for mtu size greater than 1500.

---
Changes since v4:
- remove double semicolon

 drivers/net/ethernet/amd/xgbe/xgbe-selftest.c | 23 +++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/net/ethernet/amd/xgbe/xgbe-selftest.c +23 -0
index 15c51e96bcdf..55e5e467facd 100644
@@ -42,11 +42,19 @@ static int xgbe_test_loopback_validate(struct sk_buff *skb,
 	struct tcphdr *th;
 	struct udphdr *uh;
 	struct iphdr *ih;
+	int eat;
 
 	skb = skb_unshare(skb, GFP_ATOMIC);
 	if (!skb)
 		goto out;
 
+	eat = (skb->tail + skb->data_len) - skb->end;
+	if (eat > 0 && skb_shared(skb)) {
+		skb = skb_share_check(skb, GFP_ATOMIC);
+		if (!skb)
+			goto out;
+	}
+
 	if (skb_linearize(skb))
 		goto out;
 
@@ -215,6 +223,17 @@ static int xgbe_test_sph(struct xgbe_prv_data *pdata)
 	return 0;
 }
 
+static int xgbe_test_jumbo(struct xgbe_prv_data *pdata)
+{
+	struct net_packet_attrs attr = {};
+	int size = pdata->rx_buf_size;
+
+	attr.dst = pdata->netdev->dev_addr;
+	attr.max_size = size - ETH_FCS_LEN;
+
+	return __xgbe_test_loopback(pdata, &attr);
+}
+
 static const struct xgbe_test xgbe_selftests[] = {
 	{
 		.name = "MAC Loopback   ",
@@ -228,6 +247,10 @@ static const struct xgbe_test xgbe_selftests[] = {
 		.name = "Split Header   ",
 		.lb = XGBE_LOOPBACK_PHY,
 		.fn = xgbe_test_sph,
+	}, {
+		.name = "Jumbo Frame    ",
+		.lb = XGBE_LOOPBACK_PHY,
+		.fn = xgbe_test_jumbo,
 	},
 };
 
Signature · 1 line
2.34.1
#5 lore raw
In reply to Raju Rangoju
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Quoted 4 lines · On Fri, 31 Oct 2025 16:45:51 +0530 you wrote:

This patch series introduces support for ethtool selftests, which helps in finding the misconfiguration of HW. Makes use of network selftest packet creation infrastructure.

Quoted 8 lines

Supports the following tests:

- MAC loopback selftest
- PHY loopback selftest
- Split header selftest
- Jubmo frame selftest

[...]

Here is the summary with links:
- [net-next,v6,2/5] amd-xgbe: introduce support ethtool selftest

    https://git.kernel.org/netdev/net-next/c/862a64c83faf
  - [net-next,v6,3/5] amd-xgbe: add ethtool phy loopback selftest
    https://git.kernel.org/netdev/net-next/c/42b06fcc878d
  - [net-next,v6,4/5] amd-xgbe: add ethtool split header selftest
    https://git.kernel.org/netdev/net-next/c/d7735c6bb231
  - [net-next,v6,5/5] amd-xgbe: add ethtool jumbo frame selftest
    https://git.kernel.org/netdev/net-next/c/9c11b6b1abcd
  - [net-next,v6,1/5] net: selftests: export packet creation helpers for driver use
    https://git.kernel.org/netdev/net-next/c/6b47af35a6dd

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html