[PATCH net-next v3 2/4] amd-xgbe: add ethtool phy selftest
From: Raju Rangoju <Raju.Rangoju@amd.com>
Date: 2025-10-20 15:23:22
Subsystem:
amd xgbe driver, networking drivers, the rest · Maintainers:
Raju Rangoju, Prashanth Kumar K R, Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds
Adds support for ethtool PHY loopback selftest. It uses genphy_loopback function, which use BMCR loopback bit to enable or disable loopback. Signed-off-by: Raju Rangoju <Raju.Rangoju@amd.com> --- Changes since v2: - fix build warnings for alpha arch drivers/net/ethernet/amd/xgbe/xgbe-selftest.c | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+)
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-selftest.c b/drivers/net/ethernet/amd/xgbe/xgbe-selftest.c
index 54a08f5c4ed8..16909c98bad4 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-selftest.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-selftest.c@@ -25,6 +25,7 @@ #define XGBE_LOOPBACK_NONE 0 #define XGBE_LOOPBACK_MAC 1 +#define XGBE_LOOPBACK_PHY 2 struct xgbe_hdr { __be32 version;
@@ -315,11 +316,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 xgbe_pkt_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, }, };
@@ -351,6 +377,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_config_mac_loopback(pdata, true); break;
@@ -377,6 +410,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_config_mac_loopback(pdata, false); break;
--
2.34.1