2021-04-15 13:09:42

by Oleksij Rempel

[permalink] [raw]
Subject: [PATCH net-next v2 0/7] provide generic net selftest support

changes v2:
- make this tests available for all netowking devices.
- enable them on FEC, ag71xx and all DSA switches.
- add and test loopback support on more PHYs.

This patch set provides diagnostic capabilities for some iMX, ag71xx or
any DSA based devices. For proper functionality, PHY loopback support is
needed.
So far there is only initial infrastructure with basic tests.

Oleksij Rempel (7):
net: phy: genphy_loopback: add link speed configuration
net: phy: micrel: KSZ8081 & KSZ9031: add loopback support
net: phy: at803x: AR8085 & AR9331: add loopback support
net: add generic selftest support
net: fec: make use of generic NET_SELFTESTS library
net: ag71xx: make use of generic NET_SELFTESTS library
net: dsa: enable selftest support for all switches by default

drivers/net/ethernet/atheros/Kconfig | 1 +
drivers/net/ethernet/atheros/ag71xx.c | 20 +-
drivers/net/ethernet/freescale/Kconfig | 1 +
drivers/net/ethernet/freescale/fec_main.c | 7 +
drivers/net/phy/at803x.c | 2 +
drivers/net/phy/micrel.c | 2 +
drivers/net/phy/phy.c | 3 +-
drivers/net/phy/phy_device.c | 21 +-
include/linux/phy.h | 1 +
include/net/dsa.h | 2 +
include/net/selftests.h | 12 +
net/Kconfig | 4 +
net/core/Makefile | 1 +
net/core/selftests.c | 366 ++++++++++++++++++++++
net/dsa/Kconfig | 1 +
net/dsa/slave.c | 21 ++
16 files changed, 458 insertions(+), 7 deletions(-)
create mode 100644 include/net/selftests.h
create mode 100644 net/core/selftests.c

--
2.29.2


2021-04-15 13:10:11

by Oleksij Rempel

[permalink] [raw]
Subject: [PATCH v2 6/7] net: ag71xx: make use of generic NET_SELFTESTS library

With this patch the ag71xx on Atheros AR9331 will able to run generic net
selftests.

Signed-off-by: Oleksij Rempel <[email protected]>
---
drivers/net/ethernet/atheros/Kconfig | 1 +
drivers/net/ethernet/atheros/ag71xx.c | 20 ++++++++++++++++----
2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/atheros/Kconfig b/drivers/net/ethernet/atheros/Kconfig
index fb803bf92ded..6842b74b0696 100644
--- a/drivers/net/ethernet/atheros/Kconfig
+++ b/drivers/net/ethernet/atheros/Kconfig
@@ -20,6 +20,7 @@ if NET_VENDOR_ATHEROS
config AG71XX
tristate "Atheros AR7XXX/AR9XXX built-in ethernet mac support"
depends on ATH79
+ select NET_SELFTESTS
select PHYLINK
help
If you wish to compile a kernel for AR7XXX/91XXX and enable
diff --git a/drivers/net/ethernet/atheros/ag71xx.c b/drivers/net/ethernet/atheros/ag71xx.c
index 7352f98123c7..eb067ce978ae 100644
--- a/drivers/net/ethernet/atheros/ag71xx.c
+++ b/drivers/net/ethernet/atheros/ag71xx.c
@@ -37,6 +37,7 @@
#include <linux/reset.h>
#include <linux/clk.h>
#include <linux/io.h>
+#include <net/selftests.h>

/* For our NAPI weight bigger does *NOT* mean better - it means more
* D-cache misses and lots more wasted cycles than we'll ever
@@ -497,12 +498,17 @@ static int ag71xx_ethtool_set_pauseparam(struct net_device *ndev,
static void ag71xx_ethtool_get_strings(struct net_device *netdev, u32 sset,
u8 *data)
{
- if (sset == ETH_SS_STATS) {
- int i;
+ int i;

+ switch (sset) {
+ case ETH_SS_STATS:
for (i = 0; i < ARRAY_SIZE(ag71xx_statistics); i++)
memcpy(data + i * ETH_GSTRING_LEN,
ag71xx_statistics[i].name, ETH_GSTRING_LEN);
+ break;
+ case ETH_SS_TEST:
+ net_selftest_get_strings(data);
+ break;
}
}

@@ -519,9 +525,14 @@ static void ag71xx_ethtool_get_stats(struct net_device *ndev,

static int ag71xx_ethtool_get_sset_count(struct net_device *ndev, int sset)
{
- if (sset == ETH_SS_STATS)
+ switch (sset) {
+ case ETH_SS_STATS:
return ARRAY_SIZE(ag71xx_statistics);
- return -EOPNOTSUPP;
+ case ETH_SS_TEST:
+ return net_selftest_get_count();
+ default:
+ return -EOPNOTSUPP;
+ }
}

static const struct ethtool_ops ag71xx_ethtool_ops = {
@@ -536,6 +547,7 @@ static const struct ethtool_ops ag71xx_ethtool_ops = {
.get_strings = ag71xx_ethtool_get_strings,
.get_ethtool_stats = ag71xx_ethtool_get_stats,
.get_sset_count = ag71xx_ethtool_get_sset_count,
+ .self_test = net_selftest,
};

static int ag71xx_mdio_wait_busy(struct ag71xx *ag)
--
2.29.2

2021-04-15 13:10:28

by Oleksij Rempel

[permalink] [raw]
Subject: [PATCH v2 2/7] net: phy: micrel: KSZ8081 & KSZ9031: add loopback support

PHY loopback is needed for the ethernet controller self test support.
This PHY was tested with the generic net sefltest in combination with
FEC ethernet controller and SJA1105 switch.

Signed-off-by: Oleksij Rempel <[email protected]>
---
drivers/net/phy/micrel.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index a14a00328fa3..26066b1e02e5 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -1311,6 +1311,7 @@ static struct phy_driver ksphy_driver[] = {
.get_stats = kszphy_get_stats,
.suspend = kszphy_suspend,
.resume = kszphy_resume,
+ .set_loopback = genphy_loopback,
}, {
.phy_id = PHY_ID_KSZ8061,
.name = "Micrel KSZ8061",
@@ -1356,6 +1357,7 @@ static struct phy_driver ksphy_driver[] = {
.get_stats = kszphy_get_stats,
.suspend = genphy_suspend,
.resume = kszphy_resume,
+ .set_loopback = genphy_loopback,
}, {
.phy_id = PHY_ID_LAN8814,
.phy_id_mask = MICREL_PHY_ID_MASK,
--
2.29.2

2021-04-15 13:11:14

by Oleksij Rempel

[permalink] [raw]
Subject: [PATCH v2 7/7] net: dsa: enable selftest support for all switches by default

Most of generic selftest should be able to work with probably all ethernet
controllers. The DSA switches are not exception, so enable it by default at
least for DSA.

This patch was tested with SJA1105 and AR9331.

Signed-off-by: Oleksij Rempel <[email protected]>
---
include/net/dsa.h | 2 ++
net/dsa/Kconfig | 1 +
net/dsa/slave.c | 21 +++++++++++++++++++++
3 files changed, 24 insertions(+)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 57b2c49f72f4..b4f89522b545 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -577,6 +577,8 @@ struct dsa_switch_ops {
int port, uint64_t *data);
void (*get_stats64)(struct dsa_switch *ds, int port,
struct rtnl_link_stats64 *s);
+ void (*self_test)(struct dsa_switch *ds, int port,
+ struct ethtool_test *etest, u64 *data);

/*
* ethtool Wake-on-LAN
diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig
index 8746b07668ae..cbc2bd643ab2 100644
--- a/net/dsa/Kconfig
+++ b/net/dsa/Kconfig
@@ -9,6 +9,7 @@ menuconfig NET_DSA
select NET_SWITCHDEV
select PHYLINK
select NET_DEVLINK
+ select NET_SELFTESTS
help
Say Y if you want to enable support for the hardware switches supported
by the Distributed Switch Architecture.
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 995e0e16f295..e282b422f733 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -15,6 +15,7 @@
#include <linux/mdio.h>
#include <net/rtnetlink.h>
#include <net/pkt_cls.h>
+#include <net/selftests.h>
#include <net/tc_act/tc_mirred.h>
#include <linux/if_bridge.h>
#include <linux/if_hsr.h>
@@ -748,7 +749,10 @@ static void dsa_slave_get_strings(struct net_device *dev,
if (ds->ops->get_strings)
ds->ops->get_strings(ds, dp->index, stringset,
data + 4 * len);
+ } else if (stringset == ETH_SS_TEST) {
+ net_selftest_get_strings(data);
}
+
}

static void dsa_slave_get_ethtool_stats(struct net_device *dev,
@@ -794,11 +798,27 @@ static int dsa_slave_get_sset_count(struct net_device *dev, int sset)
count += ds->ops->get_sset_count(ds, dp->index, sset);

return count;
+ } else if (sset == ETH_SS_TEST) {
+ return net_selftest_get_count();
}

return -EOPNOTSUPP;
}

+static void dsa_slave_net_selftest(struct net_device *ndev,
+ struct ethtool_test *etest, u64 *buf)
+{
+ struct dsa_port *dp = dsa_slave_to_port(ndev);
+ struct dsa_switch *ds = dp->ds;
+
+ if (ds->ops->self_test) {
+ ds->ops->self_test(ds, dp->index, etest, buf);
+ return;
+ }
+
+ net_selftest(ndev, etest, buf);
+}
+
static void dsa_slave_get_wol(struct net_device *dev, struct ethtool_wolinfo *w)
{
struct dsa_port *dp = dsa_slave_to_port(dev);
@@ -1630,6 +1650,7 @@ static const struct ethtool_ops dsa_slave_ethtool_ops = {
.get_rxnfc = dsa_slave_get_rxnfc,
.set_rxnfc = dsa_slave_set_rxnfc,
.get_ts_info = dsa_slave_get_ts_info,
+ .self_test = dsa_slave_net_selftest,
};

/* legacy way, bypassing the bridge *****************************************/
--
2.29.2

2021-04-15 13:12:11

by Oleksij Rempel

[permalink] [raw]
Subject: [PATCH v2 3/7] net: phy: at803x: AR8085 & AR9331: add loopback support

PHY loopback is needed for the ethernet controller self test support.
This PHY was tested with the generic net sefltest in combination with
FEC ethernet controller and AR9331 switch.

Signed-off-by: Oleksij Rempel <[email protected]>
---
drivers/net/phy/at803x.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c
index d7799beb811c..f74f427a8da5 100644
--- a/drivers/net/phy/at803x.c
+++ b/drivers/net/phy/at803x.c
@@ -1128,6 +1128,7 @@ static struct phy_driver at803x_driver[] = {
.get_wol = at803x_get_wol,
.suspend = at803x_suspend,
.resume = at803x_resume,
+ .set_loopback = genphy_loopback,
/* PHY_GBIT_FEATURES */
.read_status = at803x_read_status,
.config_intr = at803x_config_intr,
@@ -1207,6 +1208,7 @@ static struct phy_driver at803x_driver[] = {
.read_status = at803x_read_status,
.soft_reset = genphy_soft_reset,
.config_aneg = at803x_config_aneg,
+ .set_loopback = genphy_loopback,
} };

module_phy_driver(at803x_driver);
--
2.29.2

2021-04-15 13:12:36

by Oleksij Rempel

[permalink] [raw]
Subject: [PATCH v2 5/7] net: fec: make use of generic NET_SELFTESTS library

With this patch FEC on iMX will able to run generic net selftests

Signed-off-by: Oleksij Rempel <[email protected]>
---
drivers/net/ethernet/freescale/Kconfig | 1 +
drivers/net/ethernet/freescale/fec_main.c | 7 +++++++
2 files changed, 8 insertions(+)

diff --git a/drivers/net/ethernet/freescale/Kconfig b/drivers/net/ethernet/freescale/Kconfig
index 3f9175bdce77..3d937b4650b2 100644
--- a/drivers/net/ethernet/freescale/Kconfig
+++ b/drivers/net/ethernet/freescale/Kconfig
@@ -26,6 +26,7 @@ config FEC
ARCH_MXC || SOC_IMX28 || COMPILE_TEST)
default ARCH_MXC || SOC_IMX28 if ARM
select CRC32
+ select NET_SELFTESTS
select PHYLIB
imply PTP_1588_CLOCK
help
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 70aea9c274fe..d51b2eb1de71 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -38,6 +38,7 @@
#include <linux/in.h>
#include <linux/ip.h>
#include <net/ip.h>
+#include <net/selftests.h>
#include <net/tso.h>
#include <linux/tcp.h>
#include <linux/udp.h>
@@ -2481,6 +2482,9 @@ static void fec_enet_get_strings(struct net_device *netdev,
memcpy(data + i * ETH_GSTRING_LEN,
fec_stats[i].name, ETH_GSTRING_LEN);
break;
+ case ETH_SS_TEST:
+ net_selftest_get_strings(data);
+ break;
}
}

@@ -2489,6 +2493,8 @@ static int fec_enet_get_sset_count(struct net_device *dev, int sset)
switch (sset) {
case ETH_SS_STATS:
return ARRAY_SIZE(fec_stats);
+ case ETH_SS_TEST:
+ return net_selftest_get_count();
default:
return -EOPNOTSUPP;
}
@@ -2740,6 +2746,7 @@ static const struct ethtool_ops fec_enet_ethtool_ops = {
.set_wol = fec_enet_set_wol,
.get_link_ksettings = phy_ethtool_get_link_ksettings,
.set_link_ksettings = phy_ethtool_set_link_ksettings,
+ .self_test = net_selftest,
};

static int fec_enet_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
--
2.29.2

2021-04-15 17:00:25

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH v2 5/7] net: fec: make use of generic NET_SELFTESTS library

On Thu, 15 Apr 2021 15:07:36 +0200 Oleksij Rempel wrote:
> With this patch FEC on iMX will able to run generic net selftests
>
> Signed-off-by: Oleksij Rempel <[email protected]>

allmodconfig build fails starting from this patch and still fails
after patch 7:

net/core/selftests.o: In function `net_selftest':
selftests.c:(.text+0x75c): undefined reference to `phy_loopback'
selftests.c:(.text+0x7c2): undefined reference to `phy_loopback'

2021-04-15 20:32:48

by Florian Fainelli

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] net: phy: micrel: KSZ8081 & KSZ9031: add loopback support



On 4/15/2021 6:07 AM, Oleksij Rempel wrote:
> PHY loopback is needed for the ethernet controller self test support.
> This PHY was tested with the generic net sefltest in combination with
> FEC ethernet controller and SJA1105 switch.
>
> Signed-off-by: Oleksij Rempel <[email protected]>
> ---
> drivers/net/phy/micrel.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
> index a14a00328fa3..26066b1e02e5 100644
> --- a/drivers/net/phy/micrel.c
> +++ b/drivers/net/phy/micrel.c
> @@ -1311,6 +1311,7 @@ static struct phy_driver ksphy_driver[] = {
> .get_stats = kszphy_get_stats,
> .suspend = kszphy_suspend,
> .resume = kszphy_resume,
> + .set_loopback = genphy_loopback,

The generic loopback is really generic and is defined by the 802.3
standard, we should just mandate that drivers implement a custom
loopback if the generic one cannot work. I would change the PHY library
to do something like this:

if (phydev->drv->set_loopback)
ret = phydev->drv->set_loopback(phydev, ...)
else
ret = genphy_loopback(phydev, ...)

This would enable many more drivers than that we currently have today.

> }, {
> .phy_id = PHY_ID_KSZ8061,
> .name = "Micrel KSZ8061",
> @@ -1356,6 +1357,7 @@ static struct phy_driver ksphy_driver[] = {
> .get_stats = kszphy_get_stats,
> .suspend = genphy_suspend,
> .resume = kszphy_resume,
> + .set_loopback = genphy_loopback,
> }, {
> .phy_id = PHY_ID_LAN8814,
> .phy_id_mask = MICREL_PHY_ID_MASK,
>

--
Florian