amd-xgbe: introduce support for ethtool selftests
Subsystems (3)
Raju Rangoju
maintainerv3 cover amd-xgbe: introduce support for ethtool selftests
This patch series introduces support for ethtool selftests, which helps in finding the misconfiguration of HW. Supports the following tests:
- MAC loopback selftest
- PHY loopback selftest
- Split header selftest
- Jubmo frame selftest
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 (4):
amd-xgbe: introduce support ethtool selftest
amd-xgbe: add ethtool phy selftest
amd-xgbe: add ethtool split header selftest
amd-xgbe: add ethtool jumbo frame selftest
drivers/net/ethernet/amd/xgbe/Makefile | 2 +- drivers/net/ethernet/amd/xgbe/xgbe-dev.c | 2 + drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c | 7 + drivers/net/ethernet/amd/xgbe/xgbe-selftest.c | 511 ++++++++++++++++++ drivers/net/ethernet/amd/xgbe/xgbe.h | 6 + 5 files changed, 527 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/amd/xgbe/xgbe-selftest.c
Signature · 1 line
2.34.1
Raju Rangoju
maintainerPATCH v3 1/4 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.
---
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/xgbe/Makefile | 2 +- drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c | 7 + drivers/net/ethernet/amd/xgbe/xgbe-selftest.c | 402 ++++++++++++++++++ drivers/net/ethernet/amd/xgbe/xgbe.h | 5 + 4 files changed, 415 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/amd/xgbe/xgbe-selftest.c
drivers/net/ethernet/amd/xgbe/Makefile +1 -1
@@ -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-ethtool.c +7 -0
@@ -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 +402 -0
402 lines not on this page · raw message
drivers/net/ethernet/amd/xgbe/xgbe.h +5 -0
@@ -1321,6 +1321,11 @@ 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); +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); +#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
Raju Rangoju
maintainerPATCH v3 2/4 amd-xgbe: add ethtool phy selftest
In reply to Raju RangojuAdds support for ethtool PHY loopback selftest. It uses genphy_loopback function, which use BMCR loopback bit to enable or disable loopback.
---
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
@@ -25,6 +25,7 @@#define XGBE_LOOPBACK_NONE 0#define XGBE_LOOPBACK_MAC 1 +#define XGBE_LOOPBACK_PHY 2struct 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 ;
Signature · 1 line
2.34.1
Re: [PATCH net-next v3 2/4] amd-xgbe: add ethtool phy selftest
Hi Raju,
Quoted 5 lines · Raju Rangoju
Adds support for ethtool PHY loopback selftest. It uses
genphy_loopbackfunction, which use BMCR loopback bit to enable or disable loopback.Signed-off-by Raju Rangoju <[email protected]>
This all looks a lot like the stmmac selftests, hopefully one day we can extract that logic into a more generic selftest framework for all drivers to use.
But in any case, this looks good to me :)
Maxime
Re: [PATCH net-next v3 2/4] amd-xgbe: add ethtool phy selftest
Quoted 7 lines · Maxime Chevallier
Hi Raju,
Quoted 4 lines · Raju Rangoju
Adds support for ethtool PHY loopback selftest. It uses
genphy_loopbackfunction, which use BMCR loopback bit to enable or disable loopback.
Quoted 5 lines
Quoted 1 line
Signed-off-by Raju Rangoju <[email protected]>This all looks a lot like the stmmac selftests, hopefully one day we can extract that logic into a more generic selftest framework for all drivers to use.
https://elixir.bootlin.com/linux/v6.17.3/source/net/core/selftests.c#L441
Sorry, not looked at the patch to see if this is relevant for this driver. But we do have a generic selftest framework...
Andrew
Re: [PATCH net-next v3 2/4] amd-xgbe: add ethtool phy selftest
Quoted 14 lines · Andrew Lunn
Quoted 7 lines · Maxime Chevallier
Hi Raju,
Quoted 4 lines · Raju Rangoju
Adds support for ethtool PHY loopback selftest. It uses
genphy_loopbackfunction, which use BMCR loopback bit to enable or disable loopback.Quoted 5 lines
Quoted 1 line
Signed-off-by Raju Rangoju <[email protected]>This all looks a lot like the stmmac selftests, hopefully one day we can extract that logic into a more generic selftest framework for all drivers to use.
Quoted 6 lines
https://elixir.bootlin.com/linux/v6.17.3/source/net/core/selftests.c#L441
Sorry, not looked at the patch to see if this is relevant for this driver. But we do have a generic selftest framework...
Andrew
Ah ! And this also looks like this driver code. It seems to me that the main diffence that the amd-xgbe selftest brings is the ability to fallback to MAC-side loopback should PHY loopback fails, so they don't 1:1 map to these, but we could consider extending the existing selftests.
Besides that it seems that the generic selftest are more efficient wrt how they deal with PHY loopback, as they don't re-configure it for each selftest.
I don't necessarly think this series should be reworked but this is starting to be a lot of code duplication.
Raju, maybe you can re-use at least the generic packet generation functions (i.e net_tst_get_skb() ) ?
Maxime
Rangoju, Raju
maintainerRe: [PATCH net-next v3 2/4] amd-xgbe: add ethtool phy selftest
Quoted 34 lines · Maxime Chevallier
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Quoted 14 lines · Andrew Lunn
Quoted 7 lines · Maxime Chevallier
Hi Raju,
Quoted 4 lines · Raju Rangoju
Adds support for ethtool PHY loopback selftest. It uses
genphy_loopbackfunction, which use BMCR loopback bit to enable or disable loopback.Quoted 5 lines
Quoted 1 line
Signed-off-by Raju Rangoju <[email protected]>This all looks a lot like the stmmac selftests, hopefully one day we can extract that logic into a more generic selftest framework for all drivers to use.
Quoted 6 lines
https://elixir.bootlin.com/linux/v6.17.3/source/net/core/selftests.c#L441
Sorry, not looked at the patch to see if this is relevant for this driver. But we do have a generic selftest framework...
Andrew
Ah ! And this also looks like this driver code. It seems to me that the main diffence that the amd-xgbe selftest brings is the ability to fallback to MAC-side loopback should PHY loopback fails, so they don't 1:1 map to these, but we could consider extending the existing selftests.
Besides that it seems that the generic selftest are more efficient wrt how they deal with PHY loopback, as they don't re-configure it for each selftest.
Quoted 5 lines
I don't necessarly think this series should be reworked but this is starting to be a lot of code duplication.
Raju, maybe you can re-use at least the generic packet generation functions (i.e
net_tst_get_skb()
Sure Maxime. The net_test_get_skb() is currently not exported, let me see if these can be re-used.
Thanks,
Raju
Quoted 2 lines
Maxime
Raju Rangoju
maintainerPATCH v3 3/4 amd-xgbe: add ethtool split header selftest
In reply to Raju RangojuAdds 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-selftest.c | 46 +++++++++++++++++++ drivers/net/ethernet/amd/xgbe/xgbe.h | 1 + 2 files changed, 47 insertions(+)
drivers/net/ethernet/amd/xgbe/xgbe-selftest.c +46 -0
@@ -337,6 +337,48 @@ static int xgbe_test_phy_loopback(struct xgbe_prv_data *pdata)return ret; } +static int xgbe_test_sph (struct xgbe_prv_data *pdata) +{ +unsigned long cnt_end, cnt_start; +struct xgbe_pkt_attrs attr = {}; +int ret; + + cnt_start = pdata->ext_stats.rx_split_header_packets; + +if (!pdata->sph) { +netdev_err (pdata->netdev,"Split Header not enabled\n" ); +return -EOPNOTSUPP ; + } + +/* UDP test */ + attr.dst = pdata->netdev->dev_addr; + attr.tcp = false; + + ret =__xgbe_test_loopback (pdata, &attr); +if (ret) +return ret; + + cnt_end = pdata->ext_stats.rx_split_header_packets; +if (cnt_end <= cnt_start) +return -EINVAL ; + +/* TCP test */ + cnt_start = cnt_end; + + attr.dst = pdata->netdev->dev_addr; + attr.tcp = true; + + ret =__xgbe_test_loopback (pdata, &attr); +if (ret) +return ret; + + cnt_end = pdata->ext_stats.rx_split_header_packets; +if (cnt_end <= cnt_start) +return -EINVAL ; + +return 0 ; +} +static const struct xgbe_test xgbe_selftests[] = { { .name ="MAC Loopback " ,
@@ -346,6 +388,10 @@ static const struct xgbe_test xgbe_selftests[] = { .name = "PHY Loopback ", .lb = XGBE_LOOPBACK_NONE, .fn = xgbe_test_phy_loopback, + }, { + .name = "Split Header ", + .lb = XGBE_LOOPBACK_PHY, + .fn = xgbe_test_sph, }, };
drivers/net/ethernet/amd/xgbe/xgbe.h +1 -0
@@ -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
Raju Rangoju
maintainerPATCH v3 4/4 amd-xgbe: add ethtool jumbo frame selftest
In reply to Raju RangojuAdds support for jumbo frame selftest. Works only for mtu size greater than 1500.
--- drivers/net/ethernet/amd/xgbe/xgbe-dev.c | 2 ++ drivers/net/ethernet/amd/xgbe/xgbe-selftest.c | 25 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-)
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +2 -0
@@ -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 +24 -1
@@ -207,10 +207,18 @@ static int xgbe_test_loopback_validate(struct sk_buff *skb,struct iphdr *ih;struct tcphdr *th;struct udphdr *uh; +int eat; skb =skb_unshare (skb,GFP_ATOMIC );if (!skb) - goto out; +return -1 ; + + eat = (skb->tail + skb->data_len) - skb->end; +if (eat >0 &&skb_shared (skb)) { + skb =skb_share_check (skb,GFP_ATOMIC ); +if (!skb) +return -1 ; + }if (skb_linearize (skb)) goto out;
@@ -379,6 +387,17 @@ static int xgbe_test_sph(struct xgbe_prv_data *pdata)return 0 ; } +static int xgbe_test_jumbo (struct xgbe_prv_data *pdata) +{ +struct xgbe_pkt_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 " ,
@@ -392,6 +411,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