net: ag71xx: make use of generic NET_SELFTESTS library
authorOleksij Rempel <o.rempel@pengutronix.de>
Mon, 19 Apr 2021 13:01:05 +0000 (15:01 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 20 Apr 2021 23:08:02 +0000 (16:08 -0700)
With this patch the ag71xx on Atheros AR9331 will able to run generic net
selftests.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/atheros/Kconfig
drivers/net/ethernet/atheros/ag71xx.c

index fb803bf92ded106ad6fa9688e5b11f943ac6f7f4..6842b74b0696b7e521da99eb3332fe7a4b814e05 100644 (file)
@@ -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
index 3a23b92ebfe341c6a7fbfb79d7282f1e4d9c7850..1ba81b1eb6fdbe7a02a46f486015a17745cb9552 100644 (file)
@@ -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)