Skip to contentSkip to conversation

net: stmmac: Selftests

PATCH Superseded Jose Abreu 4 participants 25 messages May 8, 2019 – May 9, 2019

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
author
#1 lore raw

PATCH 1/11 net: stmmac: Add MAC loopback callback to HWIF

In reply to Jose Abreu

In preparation for the addition of selftests support for stmmac we add a new callback to HWIF that can be used to set the controller in loopback mode.

Cc Joao Pinto <[email protected]>
Cc David S. Miller <[email protected]>
Cc Giuseppe Cavallaro <[email protected]>
Cc Alexandre Torgue <[email protected]>
---
 drivers/net/ethernet/stmicro/stmmac/hwif.h | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/ethernet/stmicro/stmmac/hwif.h +4 -0
index 5bb00234d961..9a000dc31d9e 100644
@@ -324,6 +324,8 @@ struct stmmac_ops {
 	int (*flex_pps_config)(void __iomem *ioaddr, int index,
 			       struct stmmac_pps_cfg *cfg, bool enable,
 			       u32 sub_second_inc, u32 systime_flags);
+	/* Loopback for selftests */
+	void (*set_mac_loopback)(void __iomem *ioaddr, bool enable);
 };
 
 #define stmmac_core_init(__priv, __args...) \
@@ -392,6 +394,8 @@ struct stmmac_ops {
 	stmmac_do_callback(__priv, mac, rxp_config, __args)
 #define stmmac_flex_pps_config(__priv, __args...) \
 	stmmac_do_callback(__priv, mac, flex_pps_config, __args)
+#define stmmac_set_mac_loopback(__priv, __args...) \
+	stmmac_do_void_callback(__priv, mac, set_mac_loopback, __args)
 
 /* PTP and HW Timer helpers */
 struct stmmac_hwtimestamp {
Signature · 1 line
2.7.4
author
#2 lore raw

PATCH 2/11 net: stmmac: dwmac100: Add MAC loopback support

In reply to Jose Abreu

In preparation for the addition of stmmac selftests we implement the MAC loopback callback in dwmac100 core.

Cc Joao Pinto <[email protected]>
Cc David S. Miller <[email protected]>
Cc Giuseppe Cavallaro <[email protected]>
Cc Alexandre Torgue <[email protected]>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c +13 -0
index b735143987e1..d621b5189c41 100644
@@ -160,6 +160,18 @@ static void dwmac100_pmt(struct mac_device_info *hw, unsigned long mode)
 	return;
 }
 
+static void dwmac100_set_mac_loopback(void __iomem *ioaddr, bool enable)
+{
+	u32 value = readl(ioaddr + MAC_CONTROL);
+
+	if (enable)
+		value |= MAC_CONTROL_OM;
+	else
+		value &= ~MAC_CONTROL_OM;
+
+	writel(value, ioaddr + MAC_CONTROL);
+}
+
 const struct stmmac_ops dwmac100_ops = {
 	.core_init = dwmac100_core_init,
 	.set_mac = stmmac_set_mac,
@@ -171,6 +183,7 @@ const struct stmmac_ops dwmac100_ops = {
 	.pmt = dwmac100_pmt,
 	.set_umac_addr = dwmac100_set_umac_addr,
 	.get_umac_addr = dwmac100_get_umac_addr,
+	.set_mac_loopback = dwmac100_set_mac_loopback,
 };
 
 int dwmac100_setup(struct stmmac_priv *priv)
Signature · 1 line
2.7.4

Jose Abreu

author
#0 lore raw

cover net: stmmac: Selftests

[ Submitting with net-next closed for proper review and testing. ]

This introduces selftests support in stmmac driver. We add 4 basic sanity checks and MAC loopback support for all cores within the driver. This way more tests can easily be added in the future and can be run in virtually any MAC/GMAC/QoS/XGMAC platform.

Having this we can find regressions and missing features in the driver while at the same time we can check if the IP is correctly working.

We have been using this for some time now and I do have more tests to submit in the feature. My experience is that although writing the tests adds more development time, the gain results are obvious.

I let this feature optional within the driver under a Kconfig option.

For this series the output result will be something like this (e.g. for dwmac1000):
----

# ethtool -t eth0
The test result is PASS
The test extra info:
1. MAC Loopback                 0
2. PHY Loopback                 -95
3. MMC Counters                 0
4. EEE                          -95
5. Hash Filter MC               0
6. Perfect Filter UC            0
7. Flow Control                 0
----

(Error code -95 means EOPNOTSUPP in current HW).

Cc Joao Pinto <[email protected]>
Cc David S. Miller <[email protected]>
Cc Giuseppe Cavallaro <[email protected]>
Cc Alexandre Torgue <[email protected]>

Jose Abreu (11):
net: stmmac: Add MAC loopback callback to HWIF
net: stmmac: dwmac100: Add MAC loopback support
net: stmmac: dwmac1000: Add MAC loopback support
net: stmmac: dwmac4/5: Add MAC loopback support
net: stmmac: dwxgmac2: Add MAC loopback support
net: stmmac: Switch MMC functions to HWIF callbacks
net: stmmac: dwmac1000: Also pass control frames while in promisc mode
net: stmmac: dwmac4/5: Also pass control frames while in promisc mode
net: stmmac: dwxgmac2: Also pass control frames while in promisc mode
net: stmmac: Introduce selftests support
net: stmmac: dwmac1000: Fix Hash Filter

 drivers/net/ethernet/stmicro/stmmac/Kconfig        |   9 +
 drivers/net/ethernet/stmicro/stmmac/Makefile       |   2 +
 drivers/net/ethernet/stmicro/stmmac/common.h       |   1 +
 drivers/net/ethernet/stmicro/stmmac/dwmac1000.h    |   1 +
 .../net/ethernet/stmicro/stmmac/dwmac1000_core.c   |  16 +-
 .../net/ethernet/stmicro/stmmac/dwmac100_core.c    |  13 +
 drivers/net/ethernet/stmicro/stmmac/dwmac4.h       |   2 +
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c  |  17 +-
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h     |   2 +
 .../net/ethernet/stmicro/stmmac/dwxgmac2_core.c    |  15 +-
 drivers/net/ethernet/stmicro/stmmac/hwif.c         |   9 +
 drivers/net/ethernet/stmicro/stmmac/hwif.h         |  21 +
 drivers/net/ethernet/stmicro/stmmac/mmc.h          |   4 -
 drivers/net/ethernet/stmicro/stmmac/mmc_core.c     |  13 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac.h       |  22 +
 .../net/ethernet/stmicro/stmmac/stmmac_ethtool.c   |   8 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  |   4 +-
 .../net/ethernet/stmicro/stmmac/stmmac_selftests.c | 743 +++++++++++++++++++++
 18 files changed, 889 insertions(+), 13 deletions(-)
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
Signature · 1 line
2.7.4
author
#4 lore raw

PATCH 4/11 net: stmmac: dwmac4/5: Add MAC loopback support

In preparation for the addition of stmmac selftests we implement the MAC loopback callback in dwmac4/5 cores.

Cc Joao Pinto <[email protected]>
Cc David S. Miller <[email protected]>
Cc Giuseppe Cavallaro <[email protected]>
Cc Alexandre Torgue <[email protected]>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac4.h      |  1 +
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 15 +++++++++++++++
 2 files changed, 16 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac4.h +1 -0
index eb013d54025a..3dddd7902b0f 100644
@@ -160,6 +160,7 @@ enum power_event {
 #define GMAC_CONFIG_PS			BIT(15)
 #define GMAC_CONFIG_FES			BIT(14)
 #define GMAC_CONFIG_DM			BIT(13)
+#define GMAC_CONFIG_LM			BIT(12)
 #define GMAC_CONFIG_DCRS		BIT(9)
 #define GMAC_CONFIG_TE			BIT(1)
 #define GMAC_CONFIG_RE			BIT(0)
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +15 -0
index 7e5d5db0d516..2f1a2a6f9b33 100644
@@ -701,6 +701,18 @@ static void dwmac4_debug(void __iomem *ioaddr, struct stmmac_extra_stats *x,
 		x->mac_gmii_rx_proto_engine++;
 }
 
+static void dwmac4_set_mac_loopback(void __iomem *ioaddr, bool enable)
+{
+	u32 value = readl(ioaddr + GMAC_CONFIG);
+
+	if (enable)
+		value |= GMAC_CONFIG_LM;
+	else
+		value &= ~GMAC_CONFIG_LM;
+
+	writel(value, ioaddr + GMAC_CONFIG);
+}
+
 const struct stmmac_ops dwmac4_ops = {
 	.core_init = dwmac4_core_init,
 	.set_mac = stmmac_set_mac,
@@ -730,6 +742,7 @@ const struct stmmac_ops dwmac4_ops = {
 	.pcs_get_adv_lp = dwmac4_get_adv_lp,
 	.debug = dwmac4_debug,
 	.set_filter = dwmac4_set_filter,
+	.set_mac_loopback = dwmac4_set_mac_loopback,
 };
 
 const struct stmmac_ops dwmac410_ops = {
@@ -761,6 +774,7 @@ const struct stmmac_ops dwmac410_ops = {
 	.pcs_get_adv_lp = dwmac4_get_adv_lp,
 	.debug = dwmac4_debug,
 	.set_filter = dwmac4_set_filter,
+	.set_mac_loopback = dwmac4_set_mac_loopback,
 };
 
 const struct stmmac_ops dwmac510_ops = {
@@ -797,6 +811,7 @@ const struct stmmac_ops dwmac510_ops = {
 	.safety_feat_dump = dwmac5_safety_feat_dump,
 	.rxp_config = dwmac5_rxp_config,
 	.flex_pps_config = dwmac5_flex_pps_config,
+	.set_mac_loopback = dwmac4_set_mac_loopback,
 };
 
 int dwmac4_setup(struct stmmac_priv *priv)
Signature · 1 line
2.7.4
author
#7 lore raw

PATCH 7/11 net: stmmac: dwmac1000: Also pass control frames while in promisc mode

In reply to Jose Abreu

In order for the selftests to run the Flow Control selftest we need to also pass control frames to the stack.

Pass this type of frames while in promiscuous mode.

Cc Joao Pinto <[email protected]>
Cc David S. Miller <[email protected]>
Cc Giuseppe Cavallaro <[email protected]>
Cc Alexandre Torgue <[email protected]>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac1000.h      | 1 +
 drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwmac1000.h +1 -0
index 184ca13c8f79..56a69fb6f0b9 100644
@@ -146,6 +146,7 @@ enum inter_frame_gap {
 #define GMAC_FRAME_FILTER_DAIF	0x00000008	/* DA Inverse Filtering */
 #define GMAC_FRAME_FILTER_PM	0x00000010	/* Pass all multicast */
 #define GMAC_FRAME_FILTER_DBF	0x00000020	/* Disable Broadcast frames */
+#define GMAC_FRAME_FILTER_PCF	0x00000080	/* Pass Control frames */
 #define GMAC_FRAME_FILTER_SAIF	0x00000100	/* Inverse Filtering */
 #define GMAC_FRAME_FILTER_SAF	0x00000200	/* Source Address Filter */
 #define GMAC_FRAME_FILTER_HPF	0x00000400	/* Hash or perfect Filter */
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +1 -1
index 398303c783f4..8ca73bd15e07 100644
@@ -172,7 +172,7 @@ static void dwmac1000_set_filter(struct mac_device_info *hw,
 	memset(mc_filter, 0, sizeof(mc_filter));
 
 	if (dev->flags & IFF_PROMISC) {
-		value = GMAC_FRAME_FILTER_PR;
+		value = GMAC_FRAME_FILTER_PR | GMAC_FRAME_FILTER_PCF;
 	} else if (dev->flags & IFF_ALLMULTI) {
 		value = GMAC_FRAME_FILTER_PM;	/* pass all multi */
 	} else if (!netdev_mc_empty(dev)) {
Signature · 1 line
2.7.4
author
#12 lore raw

PATCH 10/11 net: stmmac: Introduce selftests support

In reply to Jose Abreu

We add support for selftests on stmmac driver with 4 basic sanity checks for now:
- MAC Loopback
- PHY Loopback
- MMC Counters
- EEE
- Hash Filter Multicast
- Perfect Filter Unicast
- Flow Control

This allows for fast tracking of regressions in the driver and helps in spotting mis-configuration of HW.

Cc Joao Pinto <[email protected]>
Cc David S. Miller <[email protected]>
Cc Giuseppe Cavallaro <[email protected]>
Cc Alexandre Torgue <[email protected]>
---
 drivers/net/ethernet/stmicro/stmmac/Kconfig        |   9 +
 drivers/net/ethernet/stmicro/stmmac/Makefile       |   2 +
 drivers/net/ethernet/stmicro/stmmac/stmmac.h       |  22 +
 .../net/ethernet/stmicro/stmmac/stmmac_ethtool.c   |   6 +
 .../net/ethernet/stmicro/stmmac/stmmac_selftests.c | 743 +++++++++++++++++++++
 5 files changed, 782 insertions(+)
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
drivers/net/ethernet/stmicro/stmmac/Kconfig +9 -0
index f194235153f9..fd0bb87a41ee 100644
@@ -12,6 +12,15 @@ config STMMAC_ETH
 
 if STMMAC_ETH
 
+config STMMAC_SELFTESTS
+	bool "Support for STMMAC Selftests"
+	depends on STMMAC_ETH
+	default n
+	---help---
+	  This adds support for STMMAC Selftests using ethtool. Enable this
+	  feature if you are facing problems with your HW and submit the test
+	  results to the netdev Mailing List.
+
 config STMMAC_PLATFORM
 	tristate "STMMAC Platform bus support"
 	depends on STMMAC_ETH
drivers/net/ethernet/stmicro/stmmac/Makefile +2 -0
index c529c21e9bdd..c59926d96bcc 100644
@@ -8,6 +8,8 @@ stmmac-objs:= stmmac_main.o stmmac_ethtool.o stmmac_mdio.o ring_mode.o	\
 	      stmmac_tc.o dwxgmac2_core.o dwxgmac2_dma.o dwxgmac2_descs.o \
 	      $(stmmac-y)
 
+stmmac-$(CONFIG_STMMAC_SELFTESTS) += stmmac_selftests.o
+
 # Ordering matters. Generic driver must be last.
 obj-$(CONFIG_STMMAC_PLATFORM)	+= stmmac-platform.o
 obj-$(CONFIG_DWMAC_ANARION)	+= dwmac-anarion.o
drivers/net/ethernet/stmicro/stmmac/stmmac.h +22 -0
index dd95d959c1ce..a16ada8b8507 100644
@@ -229,4 +229,26 @@ int stmmac_dvr_probe(struct device *device,
 void stmmac_disable_eee_mode(struct stmmac_priv *priv);
 bool stmmac_eee_init(struct stmmac_priv *priv);
 
+#if IS_ENABLED(CONFIG_STMMAC_SELFTESTS)
+void stmmac_selftest_run(struct net_device *dev,
+			 struct ethtool_test *etest, u64 *buf);
+void stmmac_selftest_get_strings(struct stmmac_priv *priv, u8 *data);
+int stmmac_selftest_get_count(struct stmmac_priv *priv);
+#else
+static inline void stmmac_selftest_run(struct net_device *dev,
+				       struct ethtool_test *etest, u64 *buf)
+{
+	/* Not enabled */
+}
+static inline void stmmac_selftest_get_strings(struct stmmac_priv *priv,
+					       u8 *data)
+{
+	/* Not enabled */
+}
+static inline int stmmac_selftest_get_count(struct stmmac_priv *priv)
+{
+	return -EOPNOTSUPP;
+}
+#endif /* CONFIG_STMMAC_SELFTESTS */
+
 #endif /* __STMMAC_H__ */
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +6 -0
index b9f29df7e98a..19ffb4fa90a8 100644
@@ -589,6 +589,8 @@ static int stmmac_get_sset_count(struct net_device *netdev, int sset)
 		}
 
 		return len;
+	case ETH_SS_TEST:
+		return stmmac_selftest_get_count(priv);
 	default:
 		return -EOPNOTSUPP;
 	}
@@ -625,6 +627,9 @@ static void stmmac_get_strings(struct net_device *dev, u32 stringset, u8 *data)
 			p += ETH_GSTRING_LEN;
 		}
 		break;
+	case ETH_SS_TEST:
+		stmmac_selftest_get_strings(priv, p);
+		break;
 	default:
 		WARN_ON(1);
 		break;
@@ -890,6 +895,7 @@ static const struct ethtool_ops stmmac_ethtool_ops = {
 	.nway_reset = phy_ethtool_nway_reset,
 	.get_pauseparam = stmmac_get_pauseparam,
 	.set_pauseparam = stmmac_set_pauseparam,
+	.self_test = stmmac_selftest_run,
 	.get_ethtool_stats = stmmac_get_ethtool_stats,
 	.get_strings = stmmac_get_strings,
 	.get_wol = stmmac_get_wol,
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +743 -0

743 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#17 lore raw

PATCH 11/11 net: stmmac: dwmac1000: Fix Hash Filter

In reply to Jose Abreu

In order for hash filter to work we need to set the HPF bit.

Found out while running stmmac selftests.

Cc Joao Pinto <[email protected]>
Cc David S. Miller <[email protected]>
Cc Giuseppe Cavallaro <[email protected]>
Cc Alexandre Torgue <[email protected]>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +1 -0
index 8ca73bd15e07..bc91af6c01b6 100644
@@ -198,6 +198,7 @@ static void dwmac1000_set_filter(struct mac_device_info *hw,
 		}
 	}
 
+	value |= GMAC_FRAME_FILTER_HPF;
 	dwmac1000_set_mchash(ioaddr, mc_filter, mcbitslog2);
 
 	/* Handle multiple unicast addresses (perfect filtering) */
Signature · 1 line
2.7.4
author
#3 lore raw

PATCH 3/11 net: stmmac: dwmac1000: Add MAC loopback support

In reply to Jose Abreu

In preparation for the addition of stmmac selftests we implement the MAC loopback callback in dwmac1000 core.

Cc Joao Pinto <[email protected]>
Cc David S. Miller <[email protected]>
Cc Giuseppe Cavallaro <[email protected]>
Cc Alexandre Torgue <[email protected]>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +13 -0
index 0877bde6e860..398303c783f4 100644
@@ -499,6 +499,18 @@ static void dwmac1000_debug(void __iomem *ioaddr, struct stmmac_extra_stats *x,
 		x->mac_gmii_rx_proto_engine++;
 }
 
+static void dwmac1000_set_mac_loopback(void __iomem *ioaddr, bool enable)
+{
+	u32 value = readl(ioaddr + GMAC_CONTROL);
+
+	if (enable)
+		value |= GMAC_CONTROL_LM;
+	else
+		value &= ~GMAC_CONTROL_LM;
+
+	writel(value, ioaddr + GMAC_CONTROL);
+}
+
 const struct stmmac_ops dwmac1000_ops = {
 	.core_init = dwmac1000_core_init,
 	.set_mac = stmmac_set_mac,
@@ -518,6 +530,7 @@ const struct stmmac_ops dwmac1000_ops = {
 	.pcs_ctrl_ane = dwmac1000_ctrl_ane,
 	.pcs_rane = dwmac1000_rane,
 	.pcs_get_adv_lp = dwmac1000_get_adv_lp,
+	.set_mac_loopback = dwmac1000_set_mac_loopback,
 };
 
 int dwmac1000_setup(struct stmmac_priv *priv)
Signature · 1 line
2.7.4
author
#11 lore raw

PATCH 9/11 net: stmmac: dwxgmac2: Also pass control frames while in promisc mode

In reply to Jose Abreu

In order for the selftests to run the Flow Control selftest we need to also pass control frames to the stack.

Pass this type of frames while in promiscuous mode.

Cc Joao Pinto <[email protected]>
Cc David S. Miller <[email protected]>
Cc Giuseppe Cavallaro <[email protected]>
Cc Alexandre Torgue <[email protected]>
---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h      | 1 +
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h +1 -0
index f629ccc8932a..b8296eb41011 100644
@@ -40,6 +40,7 @@
 #define XGMAC_CORE_INIT_RX		0
 #define XGMAC_PACKET_FILTER		0x00000008
 #define XGMAC_FILTER_RA			BIT(31)
+#define XGMAC_FILTER_PCF		BIT(7)
 #define XGMAC_FILTER_PM			BIT(4)
 #define XGMAC_FILTER_HMC		BIT(2)
 #define XGMAC_FILTER_PR			BIT(0)
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c +1 -1
index c27b3ca052ea..bfa7d6913fd4 100644
@@ -310,7 +310,7 @@ static void dwxgmac2_set_filter(struct mac_device_info *hw,
 	u32 value = XGMAC_FILTER_RA;
 
 	if (dev->flags & IFF_PROMISC) {
-		value |= XGMAC_FILTER_PR;
+		value |= XGMAC_FILTER_PR | XGMAC_FILTER_PCF;
 	} else if ((dev->flags & IFF_ALLMULTI) ||
 		   (netdev_mc_count(dev) > HASH_TABLE_SIZE)) {
 		value |= XGMAC_FILTER_PM;
Signature · 1 line
2.7.4
author
#10 lore raw

PATCH 8/11 net: stmmac: dwmac4/5: Also pass control frames while in promisc mode

In reply to Jose Abreu

In order for the selftests to run the Flow Control selftest we need to also pass control frames to the stack.

Pass this type of frames while in promiscuous mode.

Cc Joao Pinto <[email protected]>
Cc David S. Miller <[email protected]>
Cc Giuseppe Cavallaro <[email protected]>
Cc Alexandre Torgue <[email protected]>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac4.h      | 1 +
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwmac4.h +1 -0
index 3dddd7902b0f..c3cbca804bcd 100644
@@ -64,6 +64,7 @@
 #define GMAC_PACKET_FILTER_PR		BIT(0)
 #define GMAC_PACKET_FILTER_HMC		BIT(2)
 #define GMAC_PACKET_FILTER_PM		BIT(4)
+#define GMAC_PACKET_FILTER_PCF		BIT(7)
 
 #define GMAC_MAX_PERFECT_ADDRESSES	128
 
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +1 -1
index 2f1a2a6f9b33..02a3a7e2db6e 100644
@@ -404,7 +404,7 @@ static void dwmac4_set_filter(struct mac_device_info *hw,
 	unsigned int value = 0;
 
 	if (dev->flags & IFF_PROMISC) {
-		value = GMAC_PACKET_FILTER_PR;
+		value = GMAC_PACKET_FILTER_PR | GMAC_PACKET_FILTER_PCF;
 	} else if ((dev->flags & IFF_ALLMULTI) ||
 			(netdev_mc_count(dev) > HASH_TABLE_SIZE)) {
 		/* Pass all multi */
Signature · 1 line
2.7.4
author
#6 lore raw

PATCH 6/11 net: stmmac: Switch MMC functions to HWIF callbacks

In reply to Jose Abreu

XGMAC has a different MMC module. Lets use HWIF callbacks for MMC module so that correct callbacks are automatically selected.

Cc Joao Pinto <[email protected]>
Cc David S. Miller <[email protected]>
Cc Giuseppe Cavallaro <[email protected]>
Cc Alexandre Torgue <[email protected]>
---
 drivers/net/ethernet/stmicro/stmmac/common.h         |  1 +
 drivers/net/ethernet/stmicro/stmmac/hwif.c           |  9 +++++++++
 drivers/net/ethernet/stmicro/stmmac/hwif.h           | 17 +++++++++++++++++
 drivers/net/ethernet/stmicro/stmmac/mmc.h            |  4 ----
 drivers/net/ethernet/stmicro/stmmac/mmc_core.c       | 13 ++++++++++---
 drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c |  2 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c    |  4 ++--
 7 files changed, 40 insertions(+), 10 deletions(-)
drivers/net/ethernet/stmicro/stmmac/common.h +1 -0
index 272b9ca66314..1961fe9144ca 100644
@@ -424,6 +424,7 @@ struct mac_device_info {
 	const struct stmmac_mode_ops *mode;
 	const struct stmmac_hwtimestamp *ptp;
 	const struct stmmac_tc_ops *tc;
+	const struct stmmac_mmc_ops *mmc;
 	struct mii_regs mii;	/* MII register Addresses */
 	struct mac_link link;
 	void __iomem *pcsr;     /* vpointer to device CSRs */
drivers/net/ethernet/stmicro/stmmac/hwif.c +9 -0
index 81b966a8261b..6c61b753b55e 100644
@@ -81,6 +81,7 @@ static const struct stmmac_hwif_entry {
 	const void *hwtimestamp;
 	const void *mode;
 	const void *tc;
+	const void *mmc;
 	int (*setup)(struct stmmac_priv *priv);
 	int (*quirks)(struct stmmac_priv *priv);
 } stmmac_hw[] = {
@@ -100,6 +101,7 @@ static const struct stmmac_hwif_entry {
 		.hwtimestamp = &stmmac_ptp,
 		.mode = NULL,
 		.tc = NULL,
+		.mmc = &dwmac_mmc_ops,
 		.setup = dwmac100_setup,
 		.quirks = stmmac_dwmac1_quirks,
 	}, {
@@ -117,6 +119,7 @@ static const struct stmmac_hwif_entry {
 		.hwtimestamp = &stmmac_ptp,
 		.mode = NULL,
 		.tc = NULL,
+		.mmc = &dwmac_mmc_ops,
 		.setup = dwmac1000_setup,
 		.quirks = stmmac_dwmac1_quirks,
 	}, {
@@ -134,6 +137,7 @@ static const struct stmmac_hwif_entry {
 		.hwtimestamp = &stmmac_ptp,
 		.mode = NULL,
 		.tc = &dwmac510_tc_ops,
+		.mmc = &dwmac_mmc_ops,
 		.setup = dwmac4_setup,
 		.quirks = stmmac_dwmac4_quirks,
 	}, {
@@ -151,6 +155,7 @@ static const struct stmmac_hwif_entry {
 		.hwtimestamp = &stmmac_ptp,
 		.mode = &dwmac4_ring_mode_ops,
 		.tc = &dwmac510_tc_ops,
+		.mmc = &dwmac_mmc_ops,
 		.setup = dwmac4_setup,
 		.quirks = NULL,
 	}, {
@@ -168,6 +173,7 @@ static const struct stmmac_hwif_entry {
 		.hwtimestamp = &stmmac_ptp,
 		.mode = &dwmac4_ring_mode_ops,
 		.tc = &dwmac510_tc_ops,
+		.mmc = &dwmac_mmc_ops,
 		.setup = dwmac4_setup,
 		.quirks = NULL,
 	}, {
@@ -185,6 +191,7 @@ static const struct stmmac_hwif_entry {
 		.hwtimestamp = &stmmac_ptp,
 		.mode = &dwmac4_ring_mode_ops,
 		.tc = &dwmac510_tc_ops,
+		.mmc = &dwmac_mmc_ops,
 		.setup = dwmac4_setup,
 		.quirks = NULL,
 	}, {
@@ -202,6 +209,7 @@ static const struct stmmac_hwif_entry {
 		.hwtimestamp = &stmmac_ptp,
 		.mode = NULL,
 		.tc = &dwmac510_tc_ops,
+		.mmc = NULL,
 		.setup = dwxgmac2_setup,
 		.quirks = NULL,
 	},
@@ -267,6 +275,7 @@ int stmmac_hwif_init(struct stmmac_priv *priv)
 		mac->ptp = mac->ptp ? : entry->hwtimestamp;
 		mac->mode = mac->mode ? : entry->mode;
 		mac->tc = mac->tc ? : entry->tc;
+		mac->mmc = mac->mmc ? : entry->mmc;
 
 		priv->hw = mac;
 		priv->ptpaddr = priv->ioaddr + entry->regs.ptp_off;
drivers/net/ethernet/stmicro/stmmac/hwif.h +17 -0
index 9a000dc31d9e..2acfbc70e3c8 100644
@@ -6,6 +6,7 @@
 #define __STMMAC_HWIF_H__
 
 #include <linux/netdevice.h>
+#include <linux/stmmac.h>
 
 #define stmmac_do_void_callback(__priv, __module, __cname,  __arg0, __args...) \
 ({ \
@@ -468,6 +469,21 @@ struct stmmac_tc_ops {
 #define stmmac_tc_setup_cbs(__priv, __args...) \
 	stmmac_do_callback(__priv, tc, setup_cbs, __args)
 
+struct stmmac_counters;
+
+struct stmmac_mmc_ops {
+	void (*ctrl)(void __iomem *ioaddr, unsigned int mode);
+	void (*intr_all_mask)(void __iomem *ioaddr);
+	void (*read)(void __iomem *ioaddr, struct stmmac_counters *mmc);
+};
+
+#define stmmac_mmc_ctrl(__priv, __args...) \
+	stmmac_do_void_callback(__priv, mmc, ctrl, __args)
+#define stmmac_mmc_intr_all_mask(__priv, __args...) \
+	stmmac_do_void_callback(__priv, mmc, intr_all_mask, __args)
+#define stmmac_mmc_read(__priv, __args...) \
+	stmmac_do_void_callback(__priv, mmc, read, __args)
+
 struct stmmac_regs_off {
 	u32 ptp_off;
 	u32 mmc_off;
@@ -486,6 +502,7 @@ extern const struct stmmac_tc_ops dwmac510_tc_ops;
 extern const struct stmmac_ops dwxgmac210_ops;
 extern const struct stmmac_dma_ops dwxgmac210_dma_ops;
 extern const struct stmmac_desc_ops dwxgmac210_desc_ops;
+extern const struct stmmac_mmc_ops dwmac_mmc_ops;
 
 #define GMAC_VERSION		0x00000020	/* GMAC CORE Version */
 #define GMAC4_VERSION		0x00000110	/* GMAC4+ CORE Version */
drivers/net/ethernet/stmicro/stmmac/mmc.h +0 -4
index c037326331f5..e2bd90a4d34f 100644
@@ -128,8 +128,4 @@ struct stmmac_counters {
 	unsigned int mmc_rx_icmp_err_octets;
 };
 
-void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode);
-void dwmac_mmc_intr_all_mask(void __iomem *ioaddr);
-void dwmac_mmc_read(void __iomem *ioaddr, struct stmmac_counters *mmc);
-
 #endif /* __MMC_H__ */
drivers/net/ethernet/stmicro/stmmac/mmc_core.c +10 -3
index e9b04c28980f..b8c598125cfe 100644
@@ -20,6 +20,7 @@
 
 #include <linux/kernel.h>
 #include <linux/io.h>
+#include "hwif.h"
 #include "mmc.h"
 
 /* MAC Management Counters register offset */
@@ -128,7 +129,7 @@
 #define MMC_RX_ICMP_GD_OCTETS		0x180
 #define MMC_RX_ICMP_ERR_OCTETS		0x184
 
-void dwmac_mmc_ctrl(void __iomem *mmcaddr, unsigned int mode)
+static void dwmac_mmc_ctrl(void __iomem *mmcaddr, unsigned int mode)
 {
 	u32 value = readl(mmcaddr + MMC_CNTRL);
 
@@ -141,7 +142,7 @@ void dwmac_mmc_ctrl(void __iomem *mmcaddr, unsigned int mode)
 }
 
 /* To mask all all interrupts.*/
-void dwmac_mmc_intr_all_mask(void __iomem *mmcaddr)
+static void dwmac_mmc_intr_all_mask(void __iomem *mmcaddr)
 {
 	writel(MMC_DEFAULT_MASK, mmcaddr + MMC_RX_INTR_MASK);
 	writel(MMC_DEFAULT_MASK, mmcaddr + MMC_TX_INTR_MASK);
@@ -153,7 +154,7 @@ void dwmac_mmc_intr_all_mask(void __iomem *mmcaddr)
  * counter after a read. So all the field of the mmc struct
  * have to be incremented.
  */
-void dwmac_mmc_read(void __iomem *mmcaddr, struct stmmac_counters *mmc)
+static void dwmac_mmc_read(void __iomem *mmcaddr, struct stmmac_counters *mmc)
 {
 	mmc->mmc_tx_octetcount_gb += readl(mmcaddr + MMC_TX_OCTETCOUNT_GB);
 	mmc->mmc_tx_framecount_gb += readl(mmcaddr + MMC_TX_FRAMECOUNT_GB);
@@ -266,3 +267,9 @@ void dwmac_mmc_read(void __iomem *mmcaddr, struct stmmac_counters *mmc)
 	mmc->mmc_rx_icmp_gd_octets += readl(mmcaddr + MMC_RX_ICMP_GD_OCTETS);
 	mmc->mmc_rx_icmp_err_octets += readl(mmcaddr + MMC_RX_ICMP_ERR_OCTETS);
 }
+
+const struct stmmac_mmc_ops dwmac_mmc_ops = {
+	.ctrl = dwmac_mmc_ctrl,
+	.intr_all_mask = dwmac_mmc_intr_all_mask,
+	.read = dwmac_mmc_read,
+};
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +1 -1
index 3c749c327cbd..b9f29df7e98a 100644
@@ -537,7 +537,7 @@ static void stmmac_get_ethtool_stats(struct net_device *dev,
 	if (ret) {
 		/* If supported, for new GMAC chips expose the MMC counters */
 		if (priv->dma_cap.rmon) {
-			dwmac_mmc_read(priv->mmcaddr, &priv->mmc);
+			stmmac_mmc_read(priv, priv->mmcaddr, &priv->mmc);
 
 			for (i = 0; i < STMMAC_MMC_STATS_LEN; i++) {
 				char *p;
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2 -2
index 5ab2733e15e2..571b4a619ed6 100644
@@ -2128,10 +2128,10 @@ static void stmmac_mmc_setup(struct stmmac_priv *priv)
 	unsigned int mode = MMC_CNTRL_RESET_ON_READ | MMC_CNTRL_COUNTER_RESET |
 			    MMC_CNTRL_PRESET | MMC_CNTRL_FULL_HALF_PRESET;
 
-	dwmac_mmc_intr_all_mask(priv->mmcaddr);
+	stmmac_mmc_intr_all_mask(priv, priv->mmcaddr);
 
 	if (priv->dma_cap.rmon) {
-		dwmac_mmc_ctrl(priv->mmcaddr, mode);
+		stmmac_mmc_ctrl(priv, priv->mmcaddr, mode);
 		memset(&priv->mmc, 0, sizeof(struct stmmac_counters));
 	} else
 		netdev_info(priv->dev, "No MAC Management Counters available\n");
Signature · 1 line
2.7.4
author
#5 lore raw

PATCH 5/11 net: stmmac: dwxgmac2: Add MAC loopback support

In reply to Jose Abreu

In preparation for the addition of stmmac selftests we implement the MAC loopback callback in dwxgmac2 core.

Cc Joao Pinto <[email protected]>
Cc David S. Miller <[email protected]>
Cc Giuseppe Cavallaro <[email protected]>
Cc Alexandre Torgue <[email protected]>
---
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h      |  1 +
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 13 +++++++++++++
 2 files changed, 14 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h +1 -0
index 085b700a4994..f629ccc8932a 100644
@@ -29,6 +29,7 @@
 #define XGMAC_CONFIG_GPSL		GENMASK(29, 16)
 #define XGMAC_CONFIG_GPSL_SHIFT		16
 #define XGMAC_CONFIG_S2KP		BIT(11)
+#define XGMAC_CONFIG_LM			BIT(10)
 #define XGMAC_CONFIG_IPC		BIT(9)
 #define XGMAC_CONFIG_JE			BIT(8)
 #define XGMAC_CONFIG_WD			BIT(7)
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c +13 -0
index 64b8cb88ea45..c27b3ca052ea 100644
@@ -321,6 +321,18 @@ static void dwxgmac2_set_filter(struct mac_device_info *hw,
 	writel(value, ioaddr + XGMAC_PACKET_FILTER);
 }
 
+static void dwxgmac2_set_mac_loopback(void __iomem *ioaddr, bool enable)
+{
+	u32 value = readl(ioaddr + XGMAC_RX_CONFIG);
+
+	if (enable)
+		value |= XGMAC_CONFIG_LM;
+	else
+		value &= ~XGMAC_CONFIG_LM;
+
+	writel(value, ioaddr + XGMAC_RX_CONFIG);
+}
+
 const struct stmmac_ops dwxgmac210_ops = {
 	.core_init = dwxgmac2_core_init,
 	.set_mac = dwxgmac2_set_mac,
@@ -350,6 +362,7 @@ const struct stmmac_ops dwxgmac210_ops = {
 	.pcs_get_adv_lp = NULL,
 	.debug = NULL,
 	.set_filter = dwxgmac2_set_filter,
+	.set_mac_loopback = dwxgmac2_set_mac_loopback,
 };
 
 int dwxgmac2_setup(struct stmmac_priv *priv)
Signature · 1 line
2.7.4
#8 lore raw

Re: [PATCH net-next 07/11] net: stmmac: dwmac1000: Also pass control frames while in promisc mode

In reply to Jose Abreu
Quoted 2 lines · Jose Abreu

In order for the selftests to run the Flow Control selftest we need to also pass control frames to the stack.

Hi Jose

Do you mean pause frames?

Thanks
Andrew

author
#9 lore raw

RE: [PATCH net-next 07/11] net: stmmac: dwmac1000: Also pass control frames while in promisc mode

From: Andrew Lunn <[email protected]>
Date: Wed, May 08, 2019 at 13:04:58

Quoted 1 line

Do you mean pause frames?

Yes in order for the test to pass the MAC has to pass the pause frames to the stack.

Thanks,
Jose Miguel Abreu

maintainer
#18 lore raw
In reply to Jose Abreu

From: Jose Abreu <[email protected]>
Date: Wed, 8 May 2019 09:51:00 +0200

Quoted 1 line

[ Submitting with net-next closed for proper review and testing. ]

Please use "RFC" in the subject line when doing this in the future.

Thank you.

#19 lore raw
In reply to Jose Abreu
Quoted 19 lines · Jose Abreu

[ Submitting with net-next closed for proper review and testing. ]

This introduces selftests support in stmmac driver. We add 4 basic sanity checks and MAC loopback support for all cores within the driver. This way more tests can easily be added in the future and can be run in virtually any MAC/GMAC/QoS/XGMAC platform.

Having this we can find regressions and missing features in the driver while at the same time we can check if the IP is correctly working.

We have been using this for some time now and I do have more tests to submit in the feature. My experience is that although writing the tests adds more development time, the gain results are obvious.

I let this feature optional within the driver under a Kconfig option.

For this series the output result will be something like this (e.g. for dwmac1000):
----

Quoted 10 lines
# ethtool -t eth0
The test result is PASS
The test extra info:
1. MAC Loopback                 0
2. PHY Loopback                 -95
3. MMC Counters                 0
4. EEE                          -95
5. Hash Filter MC               0
6. Perfect Filter UC            0
7. Flow Control                 0

Hi Jose

The man page says:

-t --test
Executes adapter selftest on the specified network device. Possible test modes are:

offline
Perform full set of tests, possibly interrupting normal operation during the tests,

online Perform limited set of tests, not interrupting
normal operation,

external_lb
Perform full set of tests, as for offline, and additionally an external-loopback test.

The normal operation is interrupted by the tests you carry out here. But i don't see any code looking for ETH_TEST_FL_OFFLINE

Quoted 1 line

(Error code -95 means EOPNOTSUPP in current HW).

How deep do you have to go before you know about EOPNOTSUPP? It would be better to not return the string and result at all. Or patch ethtool to call strerror(3).

Andrew

#13 lore raw

Re: [PATCH net-next 10/11] net: stmmac: Introduce selftests support

In reply to Jose Abreu
Quoted 14 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +14 -0
+static int stmmac_test_eee(struct stmmac_priv *priv)
+{
+	struct stmmac_extra_stats *initial, *final;
+	int timeout = 100;
+	int ret;
+
+	ret = stmmac_test_loopback(priv);
+	if (ret)
+		goto out_free_final;
+
+	/* We have no traffic in the line so, sooner or later it will go LPI */
+	while (--timeout) {
+		memcpy(final, &priv->xstats, sizeof(*final));
+

drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c line 424

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +10 -0
+		if (final->irq_tx_path_in_lpi_mode_n >
+		    initial->irq_tx_path_in_lpi_mode_n)
+			break;
+		msleep(100);
+	}
+
+	if (!timeout) {
+		ret = -ETIMEDOUT;
+		goto out_free_final;
+	}

Retries would be a better name than timeout.

Also, 100 * 100 ms seems like a long time.

drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c line 451

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +7 -0
+static int stmmac_filter_check(struct stmmac_priv *priv)
+{
+	if (!(priv->dev->flags & IFF_PROMISC))
+		return 0;
+
+	netdev_warn(priv->dev, "Test can't be run in promiscuous mode!\n");
+	return 1;

Maybe return EOPNOTSUPP here,

drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c line 457

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +6 -0
+}
+
+static int stmmac_test_hfilt(struct stmmac_priv *priv)
+{
+	unsigned char gd_addr[ETH_ALEN] = {0x01, 0x0c, 0xcd, 0x04, 0x00, 0x00};
+	unsigned char bd_addr[ETH_ALEN] = {0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b};

What does gd and bd mean?

drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c line 462

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +5 -0
+	struct stmmac_packet_attrs attr = { };
+	int ret;
+
+	if (stmmac_filter_check(priv))
+		return -EOPNOTSUPP;

and just return the error code from the call.

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +7 -0
+
+	ret = dev_mc_add(priv->dev, gd_addr);
+	if (ret)
+		return ret;
+
+	attr.dst = gd_addr;
+

drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c line 479

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +10 -0
+	/* Shall receive packet */
+	ret = __stmmac_test_loopback(priv, &attr);
+	if (ret)
+		goto cleanup;
+
+	attr.dst = bd_addr;
+
+	/* Shall NOT receive packet */
+	ret = __stmmac_test_loopback(priv, &attr);
+	ret = !ret;

What is this test testing? gd is a multicast, where as bd is not. I expect the hardware treats multicast different to unicast. So it would make more sense to test two different multicast addresses, one which has been added via dev_mc_addr, and one that has not?

Quoted 16 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +16 -0
+
+cleanup:
+	dev_mc_del(priv->dev, gd_addr);
+	return ret;
+}
+
+static int stmmac_test_pfilt(struct stmmac_priv *priv)
+{
+	unsigned char gd_addr[ETH_ALEN] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
+	unsigned char bd_addr[ETH_ALEN] = {0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b};
+	struct stmmac_packet_attrs attr = { };
+	int ret;
+
+	if (stmmac_filter_check(priv))
+		return -EOPNOTSUPP;
+

drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c line 505

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +10 -0
+	ret = dev_uc_add(priv->dev, gd_addr);
+	if (ret)
+		return ret;
+
+	attr.dst = gd_addr;
+
+	/* Shall receive packet */
+	ret = __stmmac_test_loopback(priv, &attr);
+	if (ret)
+		goto cleanup;

gb is a multicast address. Does dev_uc_add() return an error? If it does not we should not expect it to actually work, since a multicast address should not match a unicast address?

You also seem to be missing a test for adding a unicast address via dev_uc_add() and receiving packets for that address, but not receiving multicast packets.

drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c line 628

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +9 -0
+static const struct stmmac_test {
+	char name[ETH_GSTRING_LEN];
+	int lb;
+	int (*fn)(struct stmmac_priv *priv);
+} stmmac_selftests[] = {
+	{
+		.name = "MAC Loopback         ",
+		.lb = STMMAC_LOOPBACK_MAC,
+		.fn = stmmac_test_loopback,

stmmac_test_mac_loopback might be a better name.

drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c line 633

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +5 -0
+	}, {
+		.name = "PHY Loopback         ",
+		.lb = STMMAC_LOOPBACK_PHY,
+		.fn = stmmac_test_phy_loopback,
+	}, {

Andrew

author
#20 lore raw
In reply to Andrew Lunn

From: Andrew Lunn <[email protected]>
Date: Wed, May 08, 2019 at 20:50:11

Quoted 2 lines

The normal operation is interrupted by the tests you carry out here. But i don't see any code looking for ETH_TEST_FL_OFFLINE

Ok will fix to only run in offline mode then.

Quoted 6 lines
Quoted 2 lines

(Error code -95 means EOPNOTSUPP in current HW).

How deep do you have to go before you know about EOPNOTSUPP? It would be better to not return the string and result at all. Or patch ethtool to call strerror(3).

When I looked at other drivers I saw that they return positive value (1) or zero so calling strerror in ethtool may not be ideal.

I think its useful to let the user know if a given test is not supported in HW so maybe I can return 1 instead of EOPNOTSUPP ?

Thanks,
Jose Miguel Abreu

author
#14 lore raw

RE: [PATCH net-next 10/11] net: stmmac: Introduce selftests support

In reply to Andrew Lunn

From: Andrew Lunn <[email protected]>
Date: Thu, May 09, 2019 at 03:23:30

Quoted 18 lines
Quoted 18 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +18 -0
+static int stmmac_test_eee(struct stmmac_priv *priv)
+{
+	struct stmmac_extra_stats *initial, *final;
+	int timeout = 100;
+	int ret;
+
+	ret = stmmac_test_loopback(priv);
+	if (ret)
+		goto out_free_final;
+
+	/* We have no traffic in the line so, sooner or later it will go LPI */
+	while (--timeout) {
+		memcpy(final, &priv->xstats, sizeof(*final));
+
+		if (final->irq_tx_path_in_lpi_mode_n >
+		    initial->irq_tx_path_in_lpi_mode_n)
+			break;
+		msleep(100);
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c line 424

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +6 -0
+	}
+
+	if (!timeout) {
+		ret = -ETIMEDOUT;
+		goto out_free_final;
+	}

Retries would be a better name than timeout.

Ok.

Quoted 2 lines

Also, 100 * 100 ms seems like a long time.

Ah, yeah. I will adjust to 0.5 or maybe 1 sec max.

Quoted 10 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c line 451

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +7 -0
+static int stmmac_filter_check(struct stmmac_priv *priv)
+{
+	if (!(priv->dev->flags & IFF_PROMISC))
+		return 0;
+
+	netdev_warn(priv->dev, "Test can't be run in promiscuous mode!\n");
+	return 1;

Maybe return EOPNOTSUPP here,

Ok.

Quoted 9 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c line 457

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +6 -0
+}
+
+static int stmmac_test_hfilt(struct stmmac_priv *priv)
+{
+	unsigned char gd_addr[ETH_ALEN] = {0x01, 0x0c, 0xcd, 0x04, 0x00, 0x00};
+	unsigned char bd_addr[ETH_ALEN] = {0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b};

What does gd and bd mean?

Good and Bad :D

Quoted 23 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c line 462

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +5 -0
+	struct stmmac_packet_attrs attr = { };
+	int ret;
+
+	if (stmmac_filter_check(priv))
+		return -EOPNOTSUPP;

and just return the error code from the call.

Quoted 14 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +14 -0
+
+	ret = dev_mc_add(priv->dev, gd_addr);
+	if (ret)
+		return ret;
+
+	attr.dst = gd_addr;
+
+	/* Shall receive packet */
+	ret = __stmmac_test_loopback(priv, &attr);
+	if (ret)
+		goto cleanup;
+
+	attr.dst = bd_addr;
+
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c line 479

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +3 -0
+	/* Shall NOT receive packet */
+	ret = __stmmac_test_loopback(priv, &attr);
+	ret = !ret;

What is this test testing? gd is a multicast, where as bd is not. I expect the hardware treats multicast different to unicast. So it would make more sense to test two different multicast addresses, one which has been added via dev_mc_addr, and one that has not?

Hmm, yeah makes sense. I will adjust.

Quoted 23 lines
Quoted 23 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +22 -0
+
+cleanup:
+	dev_mc_del(priv->dev, gd_addr);
+	return ret;
+}
+
+static int stmmac_test_pfilt(struct stmmac_priv *priv)
+{
+	unsigned char gd_addr[ETH_ALEN] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
+	unsigned char bd_addr[ETH_ALEN] = {0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b};
+	struct stmmac_packet_attrs attr = { };
+	int ret;
+
+	if (stmmac_filter_check(priv))
+		return -EOPNOTSUPP;
+
+	ret = dev_uc_add(priv->dev, gd_addr);
+	if (ret)
+		return ret;
+
+	attr.dst = gd_addr;
+
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c line 473

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +4 -0
+	/* Shall receive packet */
+	ret = __stmmac_test_loopback(priv, &attr);
+	if (ret)
+		goto cleanup;

gb is a multicast address. Does dev_uc_add() return an error? If it does not we should not expect it to actually work, since a multicast address should not match a unicast address?

It doesn't return an error and it does calls the set_filter callback in netdev. I will adjust to use unicast address.

Quoted 3 lines

You also seem to be missing a test for adding a unicast address via dev_uc_add() and receiving packets for that address, but not receiving multicast packets.

Hmm, what if interface was already configured to receive Multicast before running the tests ?

Quoted 12 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c line 628

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c new file +9 -0
+static const struct stmmac_test {
+	char name[ETH_GSTRING_LEN];
+	int lb;
+	int (*fn)(struct stmmac_priv *priv);
+} stmmac_selftests[] = {
+	{
+		.name = "MAC Loopback         ",
+		.lb = STMMAC_LOOPBACK_MAC,
+		.fn = stmmac_test_loopback,

stmmac_test_mac_loopback might be a better name.

Ok.

Thanks for the review!

Thanks,
Jose Miguel Abreu

#22 lore raw
In reply to Jose Abreu
Quoted 31 lines · Jose Abreu

[ Submitting with net-next closed for proper review and testing. ]

This introduces selftests support in stmmac driver. We add 4 basic sanity checks and MAC loopback support for all cores within the driver. This way more tests can easily be added in the future and can be run in virtually any MAC/GMAC/QoS/XGMAC platform.

Having this we can find regressions and missing features in the driver while at the same time we can check if the IP is correctly working.

We have been using this for some time now and I do have more tests to submit in the feature. My experience is that although writing the tests adds more development time, the gain results are obvious.

I let this feature optional within the driver under a Kconfig option.

For this series the output result will be something like this (e.g. for dwmac1000):
----

# ethtool -t eth0
The test result is PASS
The test extra info:
1. MAC Loopback                 0
2. PHY Loopback                 -95
3. MMC Counters                 0
4. EEE                          -95
5. Hash Filter MC               0
6. Perfect Filter UC            0
7. Flow Control                 0
----
Quoted 2 lines

(Error code -95 means EOPNOTSUPP in current HW).

Hello

I have started to patch dwmac_sun8i for using your patchset and get the following:
The test result is FAIL
The test extra info:

 1. MAC Loopback         	 0
 2. PHY Loopback         	 -95
 3. MMC Counters         	 -95
 4. EEE                  	 -95
 5. Hash Filter MC       	 0
 6. Perfect Filter UC    	 1
 7. Flow Control         	 -95

What means 1 for "Perfect Filter UC" ?

I have added my patch below

Regards

drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +13 -0
@@ -976,6 +976,18 @@ static void sun8i_dwmac_exit(struct platform_device *pdev, void *priv)
                regulator_disable(gmac->regulator);
 }
 
+static void sun8i_dwmac_set_mac_loopback(void __iomem *ioaddr, bool enable)
+{
+       u32 value = readl(ioaddr + EMAC_BASIC_CTL0);
+
+       if (enable)
+               value |= EMAC_LOOPBACK;
+       else
+               value &= ~EMAC_LOOPBACK;
+
+       writel(value, ioaddr + EMAC_BASIC_CTL0);
+}
+
 static const struct stmmac_ops sun8i_dwmac_ops = {
        .core_init = sun8i_dwmac_core_init,
        .set_mac = sun8i_dwmac_set_mac,
@@ -985,6 +997,7 @@ static const struct stmmac_ops sun8i_dwmac_ops = {
        .flow_ctrl = sun8i_dwmac_flow_ctrl,
        .set_umac_addr = sun8i_dwmac_set_umac_addr,
        .get_umac_addr = sun8i_dwmac_get_umac_addr,
+       .set_mac_loopback = sun8i_dwmac_set_mac_loopback,
 };
 
 static struct mac_device_info *sun8i_dwmac_setup(void *ppriv)
author
#23 lore raw

From: Corentin Labbe <[email protected]>
Date: Thu, May 09, 2019 at 10:04:16

Quoted 1 line

What means 1 for "Perfect Filter UC" ?

Thank you for the testing :)

1 means that either the expected packet was not received or that the filter did not work.

For GMAC there is the need to set the HPF bit in order for the test to pass. Do you have such bit in your HW ? It should be in EMAC_RX_FRM_FLT register.

Quoted 1 line

I have added my patch below

Do you want me to add your patch to the series ? If you send me with git-send-email I can apply it with your SoB.

Thanks,
Jose Miguel Abreu

#15 lore raw

Re: [PATCH net-next 10/11] net: stmmac: Introduce selftests support

In reply to Jose Abreu
Quoted 6 lines
Quoted 3 lines

You also seem to be missing a test for adding a unicast address via dev_uc_add() and receiving packets for that address, but not receiving multicast packets.

Hmm, what if interface was already configured to receive Multicast before running the tests ?

The kernel keeps a list of unicast and multicast addresses, which have been added to the filters. You could remove them all, do the test, and then add them back. __dev_mc_unsync(), __dev_mc_sync() etc.

Andrew

author
#16 lore raw

RE: [PATCH net-next 10/11] net: stmmac: Introduce selftests support

From: Andrew Lunn <[email protected]>
Date: Thu, May 09, 2019 at 13:21:18

Quoted 10 lines
Quoted 6 lines
Quoted 3 lines

You also seem to be missing a test for adding a unicast address via dev_uc_add() and receiving packets for that address, but not receiving multicast packets.

Hmm, what if interface was already configured to receive Multicast before running the tests ?

The kernel keeps a list of unicast and multicast addresses, which have been added to the filters. You could remove them all, do the test, and then add them back. __dev_mc_unsync(), __dev_mc_sync() etc.

Thanks! I've implemented the "MC Filter" and "UC Filter" tests and due to that I found another bug in the driver :D

Thanks,
Jose Miguel Abreu

author
#21 lore raw
In reply to Jose Abreu

From: Jose Abreu <[email protected]>
Date: Thu, May 09, 2019 at 09:17:03

Quoted 15 lines

From: Andrew Lunn <[email protected]>
Date: Wed, May 08, 2019 at 20:50:11

Quoted 2 lines

The normal operation is interrupted by the tests you carry out here. But i don't see any code looking for ETH_TEST_FL_OFFLINE

Ok will fix to only run in offline mode then.

Quoted 6 lines
Quoted 2 lines

(Error code -95 means EOPNOTSUPP in current HW).

How deep do you have to go before you know about EOPNOTSUPP? It would be better to not return the string and result at all. Or patch ethtool to call strerror(3).

Quoted 5 lines

When I looked at other drivers I saw that they return positive value (1) or zero so calling strerror in ethtool may not be ideal.

I think its useful to let the user know if a given test is not supported in HW so maybe I can return 1 instead of EOPNOTSUPP ?

After thinking about this in more detail I now realize that returning 1 is not ideal because when a test fails it will also return 1. So if I do it this way and more than one test fails then user won't know if the test really failed or if it wasn't supported in the first time.

Any advice ?

Thanks,
Jose Miguel Abreu

#24 lore raw
In reply to Jose Abreu
Quoted 5 lines · Jose Abreu

From: Corentin Labbe <[email protected]>
Date: Thu, May 09, 2019 at 10:04:16

Quoted 1 line

What means 1 for "Perfect Filter UC" ?

Quoted 8 lines

Thank you for the testing :)

1 means that either the expected packet was not received or that the filter did not work.

For GMAC there is the need to set the HPF bit in order for the test to pass. Do you have such bit in your HW ? It should be in EMAC_RX_FRM_FLT register.

The problem was missing IFF_UNICAST_FLT, so netcore put the device in promiscous when adding an unicast address.

Next step will be to enable Flow Control, but I will start a new thread for that.

Quoted 6 lines
Quoted 2 lines

I have added my patch below

Do you want me to add your patch to the series ? If you send me with git-send-email I can apply it with your SoB.

I will do.
I will send the patch for IFF_UNICAST_FLT appart since it fixes a bug.

Regards