Skip to contentSkip to conversation

net: stmmac: More selftest-related fixes

PATCH Superseded Maxime Chevallier 2 participants 11 messages Sep 9 – Sep 10

Subsystems (4)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Maxime Chevallier

author maintainer
#0 lore raw

cover net: stmmac: More selftest-related fixes

Hi everyone,

This is another round of stmmac selftest fixes, mostly about the selftests themselves but a few things were discovered w.r.t MTU and buffer size handling, see patch 5.

I've continued expanding the test devices I'm running this on, more devices should come in the future. With this series, _almost_ everything is green, except for some flow control stuff that is either a false positive or a real thing that needs investigating.

After this is merged, I consider the selftests to be now reliable enough to run them nightly on every stmmac series that's sent, and I'll be requiring clean selftests for new glue drivers.

I've been running this on :

- Altera CycloneV (dwmac-socfpga, dwmac1000 IP, v3.70a)
- NXP imx8mp (dwmac-imx, dwmac4, v5.10a)
- Allwinner H2S (dwmac-sun8i, dwmac1000)
- Amlogic S905X3 (dwmac-meson8b, dwmac1000, v3.70a)
- STM32mp157a (dwmac-stm32, dwmac4, v4.20a)
- SiFive JH7110 (dwmac-starfive, dwmac4, v5.20)
- Motorcomm YT8061 (PCIe, dwmac-motorcomm, dwmac4)
- Qualcomm IPQ8064 (dwmac-ipq806x, dwmac1000)

Tests are OK if return is 0 or -95 (-EOPNOTSUPP), tests are KO otherwise

Before the series :

Test imx socfpga sun8i meson8b stm32 starV mcom ipq806x

MAC Loopback              0     0      0     0       0     0     0    -110
MMC Counters              0     0      -95   0       0     0     0    -110
EEE                       -95   -95    -95   -110    -110  -95   -95  -95
Hash Filter MC            0     0      -95   0       0     0     0    -95
Perfect Filter UC         -95   0      0     -95     -95   -95   -95  -95
MC Filter                 -95   0      -95   -95     -95   -95   -95  -95
UC Filter                 -95   0      -95   -95     -95   -95   -95  -95
Flow Control              -95   0      -110  0       -110  -95   -110 -110
RSS                       -95   -95    -95   -95     -95   -95   -95  -95
VLAN Filtering            -110  -95    -95   -95     -110  -110  -95  -95
VLAN Filtering (perf)     -110  -95    -95   -95     -110  -110  -95  -95
Double VLAN Filter        -110  -95    -95   -95     -110  -110  -95  -95
Double VLAN Filter (perf) -110  -95    -95   -95     -110  -110  -95  -95
Flexible RX Parser        0     -95    -95   -95     -95   -95   -95  -95
SA Insertion (desc)       0     -95    -95   -95     0     0     0    -95
SA Replacement (desc)     0     -95    -95   -95     0     0     0    -95
SA Insertion (reg         0     -95    -95   -95     0     0     0    -95
SA Replacement (reg)      0     -95    -95   -95     0     0     0    -95
VLAN TX Insertion         -110  -95    -95   -95     -110  -110  -110 -95
SVLAN TX Insertion        -110  -95    -95   -95     -110  -95   -110 -95
L3 DA Filtering           0     -95    -95   -95     -95   -95   -95  -95
L3 SA Filtering           0     -95    -95   -95     -95   -95   -95  -95
L4 DA TCP Filtering       0     -95    -95   -95     -95   -95   -95  -95
L4 SA TCP Filtering       0     -95    -95   -95     -95   -95   -95  -95
L4 DA UDP Filtering       0     -95    -95   -95     -95   -95   -95  -95
L4 SA UDP Filtering       0     -95    -95   -95     -95   -95   -95  -95
ARP Offload               -95   -95    -95   -95     -110  -110  -110 -95
Jumbo Frame               0     -110   -110  0       0     0     0    -110
Multichannel Jumbo        0     -95    -95   -95     -95   -95   -95  -95
Split Header             --95   -95    -95   -95     -95   -95   0    -95
TBS (ETF Scheduler)      --95   -95    -95   -95     -95   -95   -95  -95

ARP offload's still there as this was a net-next patch and I've ran these checks on the net tree.

Jumbo frame tests on dwmac1000 started failing after :

commit 23680bf5f8c6 ("net: stmmac: restore NET_IP_ALIGN in the RX DMA offset")

This commit is OK though, it just made the selftest reveal the cracks hiding beneath the surface of MTU/bufsz handling.

After this series :

Test imx socfpga sun8i meson8b stm32 starV mcom ipq806x

MAC Loopback              0      0     0       0     0     0     0    0
MMC Counters              0      0     -95     0     0     0     0    0
EEE                       -95    -95   -95     0     0     -95   -95  -95
Hash Filter MC            0      0     -95     0     0     0     0    -95
Perfect Filter UC         -95    0     0       -95   -95   -95   -95  -95
MC Filter                 -95    0     -95     -95   -95   -95   -95  -95
UC Filter                 -95    0     -95     -95   -95   -95   -95  -95
Flow Control              -95    0     -110    0     -110  -95   -110 -110
RSS                       -95    -95   -95     -95   -95   -95   -95  -95
VLAN Filtering            0      -95   -95     -95   0     0     -95  -95
VLAN Filtering (perf)     0      -95   -95     -95   0     0     -95  -95
Double VLAN Filter        0      -95   -95     -95   0     0     -95  -95
Double VLAN Filter (perf) 0      -95   -95     -95   0     0     -95  -95
Flexible RX Parser        0      -95   -95     -95   -95   -95   -95  -95
SA Insertion (desc)       0      -95   -95     -95   0     0     0    -95
SA Replacement (desc)     0      -95   -95     -95   0     0     0    -95
SA Insertion (reg         0      -95   -95     -95   0     0     0    -95
SA Replacement (reg)      0      -95   -95     -95   0     0     0    -95
VLAN TX Insertion         0      -95   -95     -95   0     0     0    -95
SVLAN TX Insertion        -95    -95   -95     -95   -95   -95   -95  -95
L3 DA Filtering           0      -95   -95     -95   -95   -95   -95  -95
L3 SA Filtering           0      -95   -95     -95   -95   -95   -95  -95
L4 DA TCP Filtering       0      -95   -95     -95   -95   -95   -95  -95
L4 SA TCP Filtering       0      -95   -95     -95   -95   -95   -95  -95
L4 DA UDP Filtering       0      -95   -95     -95   -95   -95   -95  -95
L4 SA UDP Filtering       0      -95   -95     -95   -95   -95   -95  -95
ARP Offload               -95    -95   -95     -95   -110  -110  -110 -95
Jumbo Frame               0      0     0       0     0     0     0    0
Multichannel Jumbo        0      -95   -95     -95   -95   -95   -95  -95
Split Header              -95    -95   -95     -95   -95   -95   0    -95
TBS (ETF Scheduler)       -95    -95   -95     -95   -95   -95   -95  -95

ARP can be ignored, and Flow control needs some more attention, but we're getting there :)

Thanks,

Maxime

Maxime Chevallier (6):
net: stmmac: selftests: Support running selftests on DSA conduits
net: stmmac: selftests: Validate EEE based on the actual LPI timer
value
net: stmmac: selftests: Check the dev->features for S-TAG offload
testing
net: stmmac: selftests: Capture all packets for vlan checks
net: stmmac: size the RX buffers from the frame length, not the MTU
net: stmmac: selftests: Account for alignment shift on dwmac1000 for
Jumbo test

 .../net/ethernet/stmicro/stmmac/stmmac_main.c |  20 ++--
 .../stmicro/stmmac/stmmac_selftests.c         | 110 +++++++++++++++---
 2 files changed, 102 insertions(+), 28 deletions(-)
Signature · 1 line
2.55.0
author maintainer
#2 lore raw

PATCH 2/6 net: stmmac: selftests: Validate EEE based on the actual LPI timer value

The EEE selftest is a 2-step test :
- It validates that we enter in LPI mode with the irq_tx_path_in_lpi_mode_n counter
- It then validates that we exit LPI when sending a frame, with the irq_tx_path_exit_lpi_mode_n counter.

The current state of the test lacks 2 main things :

- We don't know exactly when was the previous frame sent (it's from the previous selftest)

- The timeout is hardcoded, while the LPI is entered after a user-configurable delay. On top of that, the timeout loop uses a pre-decrement iterator (--retries) that actually only iterate nine times, so 900ms while the default LPI value is 1 second.

Let's therefore make it more deterministic :

- Send a frame at the beginning of the test
- Wait for more than the lpi timer value, we timeout after about twice the value,
- Then send another frame, and verify that we do go out of LPI, also with a timeout.

Note that the test's goal isn't to validate the LPI timer value itself, only that we enter/leave LPI mode.

Fixes 091810dbded9 ("net: stmmac: Introduce selftests support")
---
 .../stmicro/stmmac/stmmac_selftests.c         | 33 ++++++++++++++-----
 1 file changed, 25 insertions(+), 8 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +25 -8
index 6503678b646e..4564b9f29194 100644
@@ -462,7 +462,7 @@ static int stmmac_test_mmc(struct stmmac_priv *priv)
 static int stmmac_test_eee(struct stmmac_priv *priv)
 {
 	struct stmmac_extra_stats *initial, *final;
-	int retries = 10;
+	unsigned long timeout, max_duration;
 	int ret;
 
 	if (!priv->dma_cap.eee || !priv->eee_active)
@@ -478,14 +478,18 @@ static int stmmac_test_eee(struct stmmac_priv *priv)
 		goto out_free_initial;
 	}
 
-	memcpy(initial, &priv->xstats, sizeof(*initial));
-
+	/* Send a frame, then wait to enter LPI */
 	ret = stmmac_test_mac_loopback(priv);
 	if (ret)
 		goto out_free_final;
 
+	max_duration = usecs_to_jiffies(2 * priv->tx_lpi_timer);
+
+	memcpy(initial, &priv->xstats, sizeof(*initial));
+
 	/* We have no traffic in the line so, sooner or later it will go LPI */
-	while (--retries) {
+	timeout = jiffies + max_duration;
+	while (!time_after(jiffies, timeout)) {
 		memcpy(final, &priv->xstats, sizeof(*final));
 
 		if (final->irq_tx_path_in_lpi_mode_n >
@@ -494,17 +498,30 @@ static int stmmac_test_eee(struct stmmac_priv *priv)
 		msleep(100);
 	}
 
-	if (!retries) {
+	memcpy(final, &priv->xstats, sizeof(*final));
+	if (final->irq_tx_path_in_lpi_mode_n <=
+	    initial->irq_tx_path_in_lpi_mode_n) {
 		ret = -ETIMEDOUT;
 		goto out_free_final;
 	}
 
-	if (final->irq_tx_path_in_lpi_mode_n <=
-	    initial->irq_tx_path_in_lpi_mode_n) {
-		ret = -EINVAL;
+	/* TX something so we go out of LPI */
+	ret = stmmac_test_mac_loopback(priv);
+	if (ret)
 		goto out_free_final;
+
+	/* Wait for the exit LPI interrupt */
+	timeout = jiffies + max_duration;
+	while (!time_after(jiffies, timeout)) {
+		memcpy(final, &priv->xstats, sizeof(*final));
+
+		if (final->irq_tx_path_exit_lpi_mode_n >
+		    initial->irq_tx_path_exit_lpi_mode_n)
+			break;
+		msleep(100);
 	}
 
+	memcpy(final, &priv->xstats, sizeof(*final));
 	if (final->irq_tx_path_exit_lpi_mode_n <=
 	    initial->irq_tx_path_exit_lpi_mode_n) {
 		ret = -EINVAL;
Signature · 1 line
2.55.0
author maintainer
#1 lore raw

PATCH 1/6 net: stmmac: selftests: Support running selftests on DSA conduits

In reply to Maxime Chevallier

Most stmmac selftests rely on dev_add_pack() to add custom handlers, that validate the packets sent to ourselves through MAC loopback.

However, when the stmmac-driven interface is a DSA CPU conduit, all frames that are received have ETH_P_XDSA as a protocol, even though they don't actually contain any tag as they come from the loopback and not the switch.

This will prevent any incoming packet to match our packet handlers.

Let's register a ETH_P_ALL packet handler when we detect that we're a DSA conduit, and use a proxy packet handler to filter the h_proto.

Note that we may still receive incoming packets from the switch, but these frames shouldn't interfere with the very specific frames used for selftests, and stmmac selftests in general aren't safe against external traffic interferences.

This was validated on a WPQ864 devkit for IPQ8064, that has the SoC connected to a QCA8k switch.

The ARP offload's packet handler is left alone, this feature is just not implemented in stmmac and due for removal.

Fixes 091810dbded9 ("net: stmmac: Introduce selftests support")
---
 .../stmicro/stmmac/stmmac_selftests.c         | 68 ++++++++++++++++---
 1 file changed, 58 insertions(+), 10 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +58 -10
index 6372ec7c3f31..6503678b646e 100644
@@ -12,6 +12,7 @@
 #include <linux/ethtool.h>
 #include <linux/ip.h>
 #include <linux/udp.h>
+#include <net/dsa.h>
 #include <net/pkt_cls.h>
 #include <net/pkt_sched.h>
 #include <net/tcp.h>
@@ -237,6 +238,9 @@ struct stmmac_test_priv {
 	struct stmmac_packet_attrs *packet;
 	struct packet_type pt;
 	struct completion comp;
+	__be16 packet_type;
+	int (*func)(struct sk_buff *skb, struct net_device *ndev,
+		    struct packet_type *pt, struct net_device *orig_ndev);
 	int double_vlan;
 	int vlan_id;
 	int ok;
@@ -316,6 +320,50 @@ static int stmmac_test_loopback_validate(struct sk_buff *skb,
 	return 0;
 }
 
+static int stmmac_sft_filter(struct sk_buff *skb, struct net_device *ndev,
+			     struct packet_type *pt,
+			     struct net_device *orig_ndev)
+{
+	struct stmmac_test_priv *tpriv = pt->af_packet_priv;
+	struct ethhdr *hdr = eth_hdr(skb);
+	int ret = 0;
+
+	if (hdr->h_proto == tpriv->packet_type) {
+		struct sk_buff *nskb = skb_clone(skb, GFP_ATOMIC);
+
+		if (nskb)
+			ret = tpriv->func(nskb, ndev, pt, orig_ndev);
+	}
+
+	kfree_skb(skb);
+	return ret;
+}
+
+static void stmmac_sft_add_pack(struct packet_type *pt)
+{
+	struct stmmac_test_priv *tpriv = pt->af_packet_priv;
+
+	if (netdev_uses_dsa(tpriv->pt.dev)) {
+		tpriv->packet_type = tpriv->pt.type;
+		tpriv->func = tpriv->pt.func;
+
+		/* DSA conduit will report ETH_P_XDSA, so our packet handler
+		 * won't match. Let's register a ETH_P_ALL match and filter
+		 * manually in stmmac_sft_filter.
+		 */
+		tpriv->pt.type = htons(ETH_P_ALL);
+		tpriv->pt.func = stmmac_sft_filter;
+		tpriv->pt.ignore_outgoing = true;
+	}
+
+	dev_add_pack(pt);
+}
+
+static void stmmac_sft_remove_pack(struct packet_type *pt)
+{
+	dev_remove_pack(pt);
+}
+
 static int __stmmac_test_loopback(struct stmmac_priv *priv,
 				  struct stmmac_packet_attrs *attr)
 {
@@ -337,7 +385,7 @@ static int __stmmac_test_loopback(struct stmmac_priv *priv,
 	tpriv->packet = attr;
 
 	if (!attr->dont_wait)
-		dev_add_pack(&tpriv->pt);
+		stmmac_sft_add_pack(&tpriv->pt);
 
 	skb = stmmac_test_get_udp_skb(priv, attr);
 	if (!skb) {
@@ -360,7 +408,7 @@ static int __stmmac_test_loopback(struct stmmac_priv *priv,
 
 cleanup:
 	if (!attr->dont_wait)
-		dev_remove_pack(&tpriv->pt);
+		stmmac_sft_remove_pack(&tpriv->pt);
 	kfree(tpriv);
 	return ret;
 }
@@ -767,7 +815,7 @@ static int stmmac_test_flowctrl(struct stmmac_priv *priv)
 	tpriv->pt.func = stmmac_test_flowctrl_validate;
 	tpriv->pt.dev = priv->dev;
 	tpriv->pt.af_packet_priv = tpriv;
-	dev_add_pack(&tpriv->pt);
+	stmmac_sft_add_pack(&tpriv->pt);
 
 	/* Compute minimum number of packets to make FIFO full */
 	pkt_count = rx_fifo_size;
@@ -823,7 +871,7 @@ static int stmmac_test_flowctrl(struct stmmac_priv *priv)
 cleanup:
 	dev_mc_del(priv->dev, paddr);
 	dev_set_promiscuity(priv->dev, -1);
-	dev_remove_pack(&tpriv->pt);
+	stmmac_sft_remove_pack(&tpriv->pt);
 	kfree(tpriv);
 	return ret;
 }
@@ -928,7 +976,7 @@ static int __stmmac_test_vlanfilt(struct stmmac_priv *priv)
 	 * HASH values.
 	 */
 	tpriv->vlan_id = 0x123;
-	dev_add_pack(&tpriv->pt);
+	stmmac_sft_add_pack(&tpriv->pt);
 
 	ret = vlan_vid_add(priv->dev, htons(ETH_P_8021Q), tpriv->vlan_id);
 	if (ret)
@@ -968,7 +1016,7 @@ static int __stmmac_test_vlanfilt(struct stmmac_priv *priv)
 vlan_del:
 	vlan_vid_del(priv->dev, htons(ETH_P_8021Q), tpriv->vlan_id);
 cleanup:
-	dev_remove_pack(&tpriv->pt);
+	stmmac_sft_remove_pack(&tpriv->pt);
 	kfree(tpriv);
 	return ret;
 }
@@ -1022,7 +1070,7 @@ static int __stmmac_test_dvlanfilt(struct stmmac_priv *priv)
 	 * HASH values.
 	 */
 	tpriv->vlan_id = 0x123;
-	dev_add_pack(&tpriv->pt);
+	stmmac_sft_add_pack(&tpriv->pt);
 
 	ret = vlan_vid_add(priv->dev, htons(ETH_P_8021AD), tpriv->vlan_id);
 	if (ret)
@@ -1062,7 +1110,7 @@ static int __stmmac_test_dvlanfilt(struct stmmac_priv *priv)
 vlan_del:
 	vlan_vid_del(priv->dev, htons(ETH_P_8021AD), tpriv->vlan_id);
 cleanup:
-	dev_remove_pack(&tpriv->pt);
+	stmmac_sft_remove_pack(&tpriv->pt);
 	kfree(tpriv);
 	return ret;
 }
@@ -1293,7 +1341,7 @@ static int stmmac_test_vlanoff_common(struct stmmac_priv *priv, bool svlan)
 	tpriv->pt.af_packet_priv = tpriv;
 	tpriv->packet = &attr;
 	tpriv->vlan_id = 0x123;
-	dev_add_pack(&tpriv->pt);
+	stmmac_sft_add_pack(&tpriv->pt);
 
 	ret = vlan_vid_add(priv->dev, htons(proto), tpriv->vlan_id);
 	if (ret)
@@ -1320,7 +1368,7 @@ static int stmmac_test_vlanoff_common(struct stmmac_priv *priv, bool svlan)
 vlan_del:
 	vlan_vid_del(priv->dev, htons(proto), tpriv->vlan_id);
 cleanup:
-	dev_remove_pack(&tpriv->pt);
+	stmmac_sft_remove_pack(&tpriv->pt);
 	kfree(tpriv);
 	return ret;
 }
Signature · 1 line
2.55.0
author maintainer
#8 lore raw

PATCH 4/6 net: stmmac: selftests: Capture all packets for vlan checks

In reply to Maxime Chevallier

While we use vlan_vid_add to trigger the tag filtering machinery in the driver, there's no netdev associated to the VLAN. This causes the skb to arrive with empty skb->vlan_tci fields, as the packet is marked OTHERHOST in __netif_receive_skb_core(), and we fail our validation.

Let's use the proxy mechanism introduced for DSA, that registers a ETH_P_ALL packet handler that runs earlier, before the vlan netdev lookup, then filters for the correct ethertype before passing an skb clone to our validation function.

Fixes 091810dbded9 ("net: stmmac: Introduce selftests support")
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +5 -1
index af480cdf2172..2fc0badb65a7 100644
@@ -241,6 +241,7 @@ struct stmmac_test_priv {
 	__be16 packet_type;
 	int (*func)(struct sk_buff *skb, struct net_device *ndev,
 		    struct packet_type *pt, struct net_device *orig_ndev);
+	bool capture_all;
 	int double_vlan;
 	int vlan_id;
 	int ok;
@@ -343,7 +344,7 @@ static void stmmac_sft_add_pack(struct packet_type *pt)
 {
 	struct stmmac_test_priv *tpriv = pt->af_packet_priv;
 
-	if (netdev_uses_dsa(tpriv->pt.dev)) {
+	if (netdev_uses_dsa(tpriv->pt.dev) || tpriv->capture_all) {
 		tpriv->packet_type = tpriv->pt.type;
 		tpriv->func = tpriv->pt.func;
 
@@ -986,6 +987,7 @@ static int __stmmac_test_vlanfilt(struct stmmac_priv *priv)
 	tpriv->pt.dev = priv->dev;
 	tpriv->pt.af_packet_priv = tpriv;
 	tpriv->packet = &attr;
+	tpriv->capture_all = true;
 
 	/*
 	 * As we use HASH filtering, false positives may appear. This is a
@@ -1080,6 +1082,7 @@ static int __stmmac_test_dvlanfilt(struct stmmac_priv *priv)
 	tpriv->pt.dev = priv->dev;
 	tpriv->pt.af_packet_priv = tpriv;
 	tpriv->packet = &attr;
+	tpriv->capture_all = true;
 
 	/*
 	 * As we use HASH filtering, false positives may appear. This is a
@@ -1358,6 +1361,7 @@ static int stmmac_test_vlanoff_common(struct stmmac_priv *priv, bool svlan)
 	tpriv->pt.af_packet_priv = tpriv;
 	tpriv->packet = &attr;
 	tpriv->vlan_id = 0x123;
+	tpriv->capture_all = true;
 	stmmac_sft_add_pack(&tpriv->pt);
 
 	ret = vlan_vid_add(priv->dev, htons(proto), tpriv->vlan_id);
Signature · 1 line
2.55.0
author maintainer
#9 lore raw

PATCH 5/6 net: stmmac: size the RX buffers from the frame length, not the MTU

In reply to Maxime Chevallier

When picking the buffsize to use based on the MTU, we shouldn't check only the MTU value, but also :
- ETH_HLEN for the L2 header,
- up to 2 VLAN tags,
- the FCS,
- the NET_IP_ALIGN

The default bufsize is 1536 bytes, which is enough to contain all the above so this hasn't surfaced before, but the addition of NET_IP_ALIGN to the start of buffer address tripped the Jumbo selftest, leading to this discovery.

With that, we don't need the '>=' checks on the buffer len, we can use more consistent comparison operators in stmmac_set_bfsize.

Fixes 286a83721720 ("stmmac: add CHAINED descriptor mode support (V4)")
---
 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 20 ++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +11 -9
index 24656b35350b..8a23562196d9 100644
@@ -1536,17 +1536,17 @@ static unsigned int stmmac_rx_offset(struct stmmac_priv *priv)
 	return NET_SKB_PAD + NET_IP_ALIGN;
 }
 
-static int stmmac_set_bfsize(int mtu)
+static int stmmac_set_bfsize(int len)
 {
 	int ret;
 
-	if (mtu >= BUF_SIZE_8KiB)
+	if (len > BUF_SIZE_8KiB)
 		ret = BUF_SIZE_16KiB;
-	else if (mtu >= BUF_SIZE_4KiB)
+	else if (len > BUF_SIZE_4KiB)
 		ret = BUF_SIZE_8KiB;
-	else if (mtu >= BUF_SIZE_2KiB)
+	else if (len > BUF_SIZE_2KiB)
 		ret = BUF_SIZE_4KiB;
-	else if (mtu > DEFAULT_BUFSIZE)
+	else if (len > DEFAULT_BUFSIZE)
 		ret = BUF_SIZE_2KiB;
 	else
 		ret = DEFAULT_BUFSIZE;
@@ -4063,7 +4063,7 @@ static struct stmmac_dma_conf *
 stmmac_setup_dma_desc(struct stmmac_priv *priv, unsigned int mtu)
 {
 	struct stmmac_dma_conf *dma_conf;
-	int bfsize, ret;
+	int bfsize, len, ret;
 	u8 chan;
 
 	dma_conf = kzalloc_obj(*dma_conf);
@@ -4073,13 +4073,15 @@ stmmac_setup_dma_desc(struct stmmac_priv *priv, unsigned int mtu)
 		return ERR_PTR(-ENOMEM);
 	}
 
-	/* Returns 0 or BUF_SIZE_16KiB if mtu > 8KiB and dwmac4 or ring mode */
-	bfsize = stmmac_set_16kib_bfsize(priv, mtu);
+	len = mtu + ETH_HLEN + 2 * VLAN_HLEN + ETH_FCS_LEN + NET_IP_ALIGN;
+
+	/* Returns 0 or BUF_SIZE_16KiB if len > 8KiB and dwmac4 or ring mode */
+	bfsize = stmmac_set_16kib_bfsize(priv, len);
 	if (bfsize < 0)
 		bfsize = 0;
 
 	if (bfsize < BUF_SIZE_16KiB)
-		bfsize = stmmac_set_bfsize(mtu);
+		bfsize = stmmac_set_bfsize(len);
 
 	dma_conf->dma_buf_sz = bfsize;
 	/* Chose the tx/rx size from the already defined one in the
Signature · 1 line
2.55.0
author maintainer
#10 lore raw

PATCH 6/6 net: stmmac: selftests: Account for alignment shift on dwmac1000 for Jumbo test

In reply to Maxime Chevallier

On dwmac1000, we currently only support single-descriptor frames. The Jumbo test started failing when NET_IP_ALIGN was added to align the IP header, as this tests tries to send the biggest possible frame.

On dwmac1000 the DMA transfer is aligned on 4-bytes, so adding a 2-byte shift at the start-of-buffer address means it takes a whole extra 4-byte DMA burst to receive the Jumbo packet, causing it to spill over the next descriptor.

This doesn't seem to happen on dwmac4 and xgmac that appear to correctly handle unaligned xfers (only tested on dwmac4)

Let's account for that in the Jumbo test, reduce the size of our big packet by the align size.

Fixes 23680bf5f8c6 ("net: stmmac: restore NET_IP_ALIGN in the RX DMA offset")
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +3 -0
index 2fc0badb65a7..ffc58c210d0d 100644
@@ -1768,6 +1768,9 @@ static int __stmmac_test_jumbo(struct stmmac_priv *priv, u16 queue)
 	struct stmmac_packet_attrs attr = { };
 	int size = priv->dma_conf.dma_buf_sz;
 
+	if (!dwmac_is_xmac(priv->plat->core_type))
+		size -= NET_IP_ALIGN;
+
 	attr.dst = priv->dev->dev_addr;
 	attr.max_size = size - ETH_FCS_LEN;
 	attr.queue_mapping = queue;
Signature · 1 line
2.55.0
#3 lore raw

Re: [PATCH net 2/6] net: stmmac: selftests: Validate EEE based on the actual LPI timer value

In reply to Maxime Chevallier

Hi Maxime

Quoted 41 lines · Maxime Chevallier

The EEE selftest is a 2-step test :
- It validates that we enter in LPI mode with the irq_tx_path_in_lpi_mode_n counter
- It then validates that we exit LPI when sending a frame, with the irq_tx_path_exit_lpi_mode_n counter.

The current state of the test lacks 2 main things :

- We don't know exactly when was the previous frame sent (it's from
the
previous selftest)

- The timeout is hardcoded, while the LPI is entered after a user-configurable delay. On top of that, the timeout loop uses a pre-decrement iterator (--retries) that actually only iterate nine times, so 900ms while the default LPI value is 1 second.

Let's therefore make it more deterministic :

- Send a frame at the beginning of the test
- Wait for more than the lpi timer value, we timeout after about twice the value,
- Then send another frame, and verify that we do go out of LPI, also with a timeout.

Note that the test's goal isn't to validate the LPI timer value itself, only that we enter/leave LPI mode.

Fixes 091810dbded9 ("net: stmmac: Introduce selftests support")
---
 .../stmicro/stmmac/stmmac_selftests.c         | 33 ++++++++++++++-----
 1 file changed, 25 insertions(+), 8 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +0 -0
index 6503678b646e..4564b9f29194 100644
 
[...]
 

drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c static int stmmac_test_eee(struct stmmac_priv *priv) · line 488

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +4 -2
-	memcpy(initial, &priv->xstats, sizeof(*initial));
-
+	/* Send a frame, then wait to enter LPI */
 	ret = stmmac_test_mac_loopback(priv);
 	if (ret)
 		goto out_free_final;
 
+	max_duration = usecs_to_jiffies(2 * priv->tx_lpi_timer);
+
+	memcpy(initial, &priv->xstats, sizeof(*initial));

Is the LPI entry already counted here? AFAIU with tx-lpi-timer=0 on dwmac4 the MAC goes directly into LPI after the frame, before stmmac_test_mac_loopback() returns. The loop below would time out although LPI is working.

Snapshot before the first frame, and take a second snapshot right before the second loopback for the exit check?

drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c static int stmmac_test_eee(struct stmmac_priv *priv) · line 527

Quoted 6 lines

[...]

drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +1 -0
+	memcpy(final, &priv->xstats, sizeof(*final));
 	if (final->irq_tx_path_exit_lpi_mode_n <=
 	    initial->irq_tx_path_exit_lpi_mode_n) {
 		ret = -EINVAL;

nit: -ETIMEDOUT here as well, to match the entry check?

Thanks
Nicolai

#6 lore raw

Re: [PATCH net 2/6] net: stmmac: selftests: Validate EEE based on the actual LPI timer value

In reply to Maxime Chevallier
Quoted 25 lines · Maxime Chevallier

The EEE selftest is a 2-step test :
- It validates that we enter in LPI mode with the irq_tx_path_in_lpi_mode_n counter
- It then validates that we exit LPI when sending a frame, with the irq_tx_path_exit_lpi_mode_n counter.

The current state of the test lacks 2 main things :

- We don't know exactly when was the previous frame sent (it's from
the
previous selftest)

- The timeout is hardcoded, while the LPI is entered after a user-configurable delay. On top of that, the timeout loop uses a pre-decrement iterator (--retries) that actually only iterate nine times, so 900ms while the default LPI value is 1 second.

Let's therefore make it more deterministic :

- Send a frame at the beginning of the test
- Wait for more than the lpi timer value, we timeout after about twice the value,
- Then send another frame, and verify that we do go out of LPI, also with a timeout.

Quoted 8 lines

Note that the test's goal isn't to validate the LPI timer value itself, only that we enter/leave LPI mode.

Fixes 091810dbded9 ("net: stmmac: Introduce selftests support")

---

[...]

Forget to mention in my last comment:
The series seems to be broken. I can't find patch 3 and also the cover letter is missing on lore and my inbox?

Nicolai

author maintainer
#7 lore raw

Re: [PATCH net 2/6] net: stmmac: selftests: Validate EEE based on the actual LPI timer value

Quoted 32 lines · Nicolai Buchwitz
Quoted 30 lines · Maxime Chevallier

The EEE selftest is a 2-step test :
 - It validates that we enter in LPI mode with the irq_tx_path_in_lpi_mode_n counter
 - It then validates that we exit LPI when sending a frame, with the irq_tx_path_exit_lpi_mode_n counter.

The current state of the test lacks 2 main things :

 - We don't know exactly when was the previous frame sent (it's from the previous selftest)

 - The timeout is hardcoded, while the LPI is entered after a user-configurable delay. On top of that, the timeout loop uses a pre-decrement iterator (--retries) that actually only iterate nine times, so 900ms while the default LPI value is 1 second.

Let's therefore make it more deterministic :

 - Send a frame at the beginning of the test
 - Wait for more than the lpi timer value, we timeout after about twice the value,
 - Then send another frame, and verify that we do go out of LPI, also with a timeout.

Note that the test's goal isn't to validate the LPI timer value itself, only that we enter/leave LPI mode.

Fixes 091810dbded9 ("net: stmmac: Introduce selftests support")

---

Quoted 5 lines
Quoted 1 line

[...]

Forget to mention in my last comment:
The series seems to be broken. I can't find patch 3 and also the cover letter is missing on lore and my inbox?

Huh that's strange indeed, it's on lkml but not netdev@ ?

https://lore.kernel.org/lkml/[email protected]/

meh I'll resend if need be

Maxime

Quoted 2 lines

Nicolai

author maintainer
#4 lore raw

Re: [PATCH net 2/6] net: stmmac: selftests: Validate EEE based on the actual LPI timer value

In reply to Nicolai Buchwitz

Hi,

Quoted 50 lines · Nicolai Buchwitz

Hi Maxime

Quoted 47 lines · Maxime Chevallier

The EEE selftest is a 2-step test :
 - It validates that we enter in LPI mode with the irq_tx_path_in_lpi_mode_n counter
 - It then validates that we exit LPI when sending a frame, with the irq_tx_path_exit_lpi_mode_n counter.

The current state of the test lacks 2 main things :

 - We don't know exactly when was the previous frame sent (it's from the previous selftest)

 - The timeout is hardcoded, while the LPI is entered after a user-configurable delay. On top of that, the timeout loop uses a pre-decrement iterator (--retries) that actually only iterate nine times, so 900ms while the default LPI value is 1 second.

Let's therefore make it more deterministic :

 - Send a frame at the beginning of the test
 - Wait for more than the lpi timer value, we timeout after about twice the value,
 - Then send another frame, and verify that we do go out of LPI, also with a timeout.

Note that the test's goal isn't to validate the LPI timer value itself, only that we enter/leave LPI mode.

Fixes 091810dbded9 ("net: stmmac: Introduce selftests support")

---
 .../stmicro/stmmac/stmmac_selftests.c         | 33 ++++++++++++++-----

 1 file changed, 25 insertions(+), 8 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +1 -2
index 6503678b646e..4564b9f29194 100644
 
[...]
 
-    memcpy(initial, &priv->xstats, sizeof(*initial));
-
+    /* Send a frame, then wait to enter LPI */

     ret = stmmac_test_mac_loopback(priv);
     if (ret)
         goto out_free_final;

Quoted 7 lines
Quoted 3 lines

+    max_duration = usecs_to_jiffies(2 * priv->tx_lpi_timer); +
+    memcpy(initial, &priv->xstats, sizeof(*initial));

Is the LPI entry already counted here? AFAIU with tx-lpi-timer=0 on dwmac4 the MAC goes directly into LPI after the frame, before stmmac_test_mac_loopback() returns. The loop below would time out although LPI is working.

hmmm this is a good point ! I'll test and send a V2 :)

Quoted 4 lines

Snapshot before the first frame, and take a second snapshot right before the second loopback for the exit check?

Quoted 8 lines
Quoted 6 lines

[...]

+    memcpy(final, &priv->xstats, sizeof(*final)); if (final->irq_tx_path_exit_lpi_mode_n <= initial->irq_tx_path_exit_lpi_mode_n) { ret = -EINVAL;

nit: -ETIMEDOUT here as well, to match the entry check?

This is the old behaviour, if we don't entry we timeout, if we did enter but don't record an exit event this is an error, it kinda makes sense to me no ?

Thanks for looking at this,

Maxime

author maintainer
#5 lore raw

Re: [PATCH net 2/6] net: stmmac: selftests: Validate EEE based on the actual LPI timer value

In reply to Nicolai Buchwitz

Hi,

Quoted 61 lines · Nicolai Buchwitz

Hi Maxime

Quoted 47 lines · Maxime Chevallier

The EEE selftest is a 2-step test :
 - It validates that we enter in LPI mode with the irq_tx_path_in_lpi_mode_n counter
 - It then validates that we exit LPI when sending a frame, with the irq_tx_path_exit_lpi_mode_n counter.

The current state of the test lacks 2 main things :

 - We don't know exactly when was the previous frame sent (it's from the previous selftest)

 - The timeout is hardcoded, while the LPI is entered after a user-configurable delay. On top of that, the timeout loop uses a pre-decrement iterator (--retries) that actually only iterate nine times, so 900ms while the default LPI value is 1 second.

Let's therefore make it more deterministic :

 - Send a frame at the beginning of the test
 - Wait for more than the lpi timer value, we timeout after about twice the value,
 - Then send another frame, and verify that we do go out of LPI, also with a timeout.

Note that the test's goal isn't to validate the LPI timer value itself, only that we enter/leave LPI mode.

Fixes 091810dbded9 ("net: stmmac: Introduce selftests support")

---
 .../stmicro/stmmac/stmmac_selftests.c         | 33 ++++++++++++++-----

 1 file changed, 25 insertions(+), 8 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +1 -2
index 6503678b646e..4564b9f29194 100644
 
[...]
 
-    memcpy(initial, &priv->xstats, sizeof(*initial));
-
+    /* Send a frame, then wait to enter LPI */

     ret = stmmac_test_mac_loopback(priv);
     if (ret)
         goto out_free_final;

Quoted 3 lines

+    max_duration = usecs_to_jiffies(2 * priv->tx_lpi_timer); +
+    memcpy(initial, &priv->xstats, sizeof(*initial));

Is the LPI entry already counted here? AFAIU with tx-lpi-timer=0 on dwmac4 the MAC goes directly into LPI after the frame, before stmmac_test_mac_loopback() returns. The loop below would time out although LPI is working.

Snapshot before the first frame, and take a second snapshot right before the second loopback for the exit check?

Quoted 8 lines
Quoted 6 lines

[...]

+    memcpy(final, &priv->xstats, sizeof(*final)); if (final->irq_tx_path_exit_lpi_mode_n <= initial->irq_tx_path_exit_lpi_mode_n) { ret = -EINVAL;

nit: -ETIMEDOUT here as well, to match the entry check?

I ended up changing my mind and following you call here, V2 is incoming, hopefully with all the patches this time :)

Maxime

Quoted 3 lines

Thanks
Nicolai