Skip to contentSkip to conversation

net: stmmac: dwmac4: extend timeout for VLAN Tag register busy bit check

PATCH Superseded Shenwei Wang 3 participants 6 messages Sep 18, 2024 – Sep 23, 2024

Subsystems (5)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: stmmac: dwmac4: extend timeout for VLAN Tag register busy bit check

Increase the timeout for checking the busy bit of the VLAN Tag register from 10µs to 500ms. This change is necessary to accommodate scenarios where Energy Efficient Ethernet (EEE) is enabled.

Overnight testing revealed that when EEE is active, the busy bit can remain set for up to approximately 300ms. The new 500ms timeout provides a safety margin.

Fixes ed64639bc1e0 ("net: stmmac: Add support for VLAN Rx filtering")

---
Changes in v2:
- replace the udelay with readl_poll_timeout per Simon's review.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +7 -7
index a1858f083eef..a0cfa2eaebb4 100644
@@ -14,6 +14,7 @@
 #include <linux/slab.h>
 #include <linux/ethtool.h>
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include "stmmac.h"
 #include "stmmac_pcs.h"
 #include "dwmac4.h"
@@ -471,7 +472,7 @@ static int dwmac4_write_vlan_filter(struct net_device *dev,
 				    u8 index, u32 data)
 {
 	void __iomem *ioaddr = (void __iomem *)dev->base_addr;
-	int i, timeout = 10;
+	int ret, timeout = 500000; //500ms
 	u32 val;
 
 	if (index >= hw->num_vlan)
@@ -487,12 +488,11 @@ static int dwmac4_write_vlan_filter(struct net_device *dev,
 
 	writel(val, ioaddr + GMAC_VLAN_TAG);
 
-	for (i = 0; i < timeout; i++) {
-		val = readl(ioaddr + GMAC_VLAN_TAG);
-		if (!(val & GMAC_VLAN_TAG_CTRL_OB))
-			return 0;
-		udelay(1);
-	}
+	ret = readl_poll_timeout(ioaddr + GMAC_VLAN_TAG, val,
+				 !(val & GMAC_VLAN_TAG_CTRL_OB),
+				 1000, timeout);
+	if (!ret)
+		return 0;
 
 	netdev_err(dev, "Timeout accessing MAC_VLAN_Tag_Filter\n");
 

--
2.34.1

#1 lore raw
Quoted 7 lines · Shenwei Wang

Increase the timeout for checking the busy bit of the VLAN Tag register from 10µs to 500ms. This change is necessary to accommodate scenarios where Energy Efficient Ethernet (EEE) is enabled.

Overnight testing revealed that when EEE is active, the busy bit can remain set for up to approximately 300ms. The new 500ms timeout provides a safety margin.

Do you know what EEE has to do with VLAN filtering?

Could there be other registers which suffer from the same problem?

Andrew

#2 lore raw
Quoted 17 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Wednesday, September 18, 2024 6:58 PM
To: Shenwei Wang <[email protected]>
Cc: David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Maxime Coquelin <[email protected]>; [email protected]; Alexandre Torgue <[email protected]>; Jose Abreu <[email protected]>; Ong Boon Leong <[email protected]>; Wong Vee Khee <[email protected]>; Chuah Kim Tatt <[email protected]>; [email protected]; linux-stm32@st-md- mailman.stormreply.com; [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: [EXT] Re: [PATCH v2 net] net: stmmac: dwmac4: extend timeout for VLAN Tag register busy bit check

Quoted 6 lines
Quoted 3 lines

Overnight testing revealed that when EEE is active, the busy bit can remain set for up to approximately 300ms. The new 500ms timeout provides a safety margin.

Do you know what EEE has to do with VLAN filtering?

The exact design details are not available to me, but my understanding is that the Busy Bit is synchronized to the RX clock supplied by the PHY. When EEE is active and the PHY enters LPI state, the RX clock is gated, preventing updates to the Busy Bit.

The question is the significant delay observed, especially considering that the PHY transitions between active and LPI states multiple times during this period. There should have a lot of chances to update the Busy Bit sooner when it is in the active state.

Quoted 2 lines

Could there be other registers which suffer from the same problem?

So far I think it only impact the VLAN status register because those bits are driven by another clock instead of CSR clock. Based on current observations, it appears that this issue primarily affects the VLAN status register. The reason for this is that the bits in the VLAN status register are driven by a clock source distinct from the CSR clock.

Regards,
Shenwei

Quoted 1 line

Andrew

Reviewed-by
#3 lore raw
Quoted 6 lines
Quoted 2 lines

Could there be other registers which suffer from the same problem?

So far I think it only impact the VLAN status register because those bits are driven by another clock instead of CSR clock. Based on current observations, it appears that this issue primarily affects the VLAN status register. The reason for this is that the bits in the VLAN status register are driven by a clock source distinct from the CSR clock.

Thanks for the explanation.

Andrew

#4 lore raw
In reply to Shenwei Wang
Quoted 47 lines · Shenwei Wang

Increase the timeout for checking the busy bit of the VLAN Tag register from 10µs to 500ms. This change is necessary to accommodate scenarios where Energy Efficient Ethernet (EEE) is enabled.

Overnight testing revealed that when EEE is active, the busy bit can remain set for up to approximately 300ms. The new 500ms timeout provides a safety margin.

Fixes ed64639bc1e0 ("net: stmmac: Add support for VLAN Rx filtering")

---
Changes in v2:
- replace the udelay with readl_poll_timeout per Simon's review.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +2 -5
index a1858f083eef..a0cfa2eaebb4 100644
@@ -14,6 +14,7 @@
 #include <linux/slab.h>
 #include <linux/ethtool.h>
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include "stmmac.h"
 #include "stmmac_pcs.h"
 #include "dwmac4.h"
@@ -471,7 +472,7 @@ static int dwmac4_write_vlan_filter(struct net_device *dev,
 				    u8 index, u32 data)
 {
 	void __iomem *ioaddr = (void __iomem *)dev->base_addr;
-	int i, timeout = 10;
+	int ret, timeout = 500000; //500ms
 	u32 val;
 
 	if (index >= hw->num_vlan)
@@ -487,12 +488,11 @@ static int dwmac4_write_vlan_filter(struct net_device *dev,
 
 	writel(val, ioaddr + GMAC_VLAN_TAG);
 
-	for (i = 0; i < timeout; i++) {
-		val = readl(ioaddr + GMAC_VLAN_TAG);
-		if (!(val & GMAC_VLAN_TAG_CTRL_OB))
-			return 0;

drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c static int dwmac4_write_vlan_filter(struct net_device *dev, · line 498

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +5 -2
-		udelay(1);
-	}
 
+	ret = readl_poll_timeout(ioaddr + GMAC_VLAN_TAG, val,
+				 !(val & GMAC_VLAN_TAG_CTRL_OB),
+				 1000, timeout);
+	if (!ret)
+		return 0;
 
 	netdev_err(dev, "Timeout accessing MAC_VLAN_Tag_Filter\n");

1. Just drop the timeout local variable and use the 500000 literal directly. There is no point in such parametrization especially you have already added the delay as is.

2. A more traditional, readable and maintainable pattern is the error-check statement after the call. So seeing you are changing this part of the method anyway, let's convert it to:

+ ret = readl_poll_timeout(ioaddr + GMAC_VLAN_TAG, val,
+ !(val & GMAC_VLAN_TAG_CTRL_OB),
+ 1000, timeout);
+ if (ret) {
+ netdev_err(dev, "Timeout accessing MAC_VLAN_Tag_Filter\n");
+ return ret;
+ }
+
+ return 0;

-Serge(y)

Quoted 5 lines

--
2.34.1

#5 lore raw
Quoted 42 lines

-----Original Message-----
From: Serge Semin <[email protected]>
Sent: Sunday, September 22, 2024 5:18 PM
To: Shenwei Wang <[email protected]>
Cc: David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Maxime Coquelin <[email protected]>; [email protected]; Alexandre Torgue <[email protected]>; Jose Abreu <[email protected]>; Ong Boon Leong <[email protected]>; Wong Vee Khee <[email protected]>; Chuah Kim Tatt <[email protected]>; [email protected]; linux-stm32@st-md- mailman.stormreply.com; [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: [EXT] Re: [PATCH v2 net] net: stmmac: dwmac4: extend timeout for VLAN Tag register busy bit check

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +0 -4
-     for (i = 0; i < timeout; i++) {
-             val = readl(ioaddr + GMAC_VLAN_TAG);
-             if (!(val & GMAC_VLAN_TAG_CTRL_OB))
-                     return 0;

drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c static int dwmac4_write_vlan_filter(struct net_device *dev,

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +5 -2
-             udelay(1);
-     }
 
+     ret = readl_poll_timeout(ioaddr + GMAC_VLAN_TAG, val,
+                              !(val & GMAC_VLAN_TAG_CTRL_OB),
+                              1000, timeout);
+     if (!ret)
+             return 0;
 
      netdev_err(dev, "Timeout accessing MAC_VLAN_Tag_Filter\n");

1. Just drop the timeout local variable and use the 500000 literal directly. There is no point in such parametrization especially you have already added the delay as is.

2. A more traditional, readable and maintainable pattern is the error-check statement after the call. So seeing you are changing this part of the method anyway, let's convert it to:

Review

Quoted 9 lines
(quoted diff) +9 -0
+       ret = readl_poll_timeout(ioaddr + GMAC_VLAN_TAG, val,
+                                !(val & GMAC_VLAN_TAG_CTRL_OB),
+                                1000, timeout);
+       if (ret) {
+               netdev_err(dev, "Timeout accessing MAC_VLAN_Tag_Filter\n");
+               return ret;
+       }
+
+       return 0;

Hi Serge,

Good suggestions! Will send out a new version.

Thanks,
Shenwei

Quoted 7 lines

-Serge(y)

Quoted 5 lines

--
2.34.1