Skip to contentSkip to conversation

net: stmmac: Guard against txfifosz=0

PATCH In review Florian Fainelli 4 participants 8 messages Apr 12, 2020 – Apr 14, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: stmmac: Guard against txfifosz=0

After commit bfcb813203e619a8960a819bf533ad2a108d8105 ("net: dsa:
configure the MTU for switch ports") my Lamobo R1 platform which uses an allwinner,sun7i-a20-gmac compatible Ethernet MAC started to fail by rejecting a MTU of 1536. The reason for that is that the DMA capabilities are not readable on this version of the IP, and there is also no 'tx-fifo-depth' property being provided in Device Tree. The property is documented as optional, and is not provided.

The minimum MTU that the network device accepts is ETH_ZLEN - ETH_HLEN, so rejecting the new MTU based on the txfifosz value unchecked seems a bit too heavy handed here.

Fixes eaf4fac47807 ("net: stmmac: Do not accept invalid MTU values")
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index e6898fd5223f..9c63ba6f86a9 100644
@@ -3993,7 +3993,7 @@ static int stmmac_change_mtu(struct net_device *dev, int new_mtu)
 	new_mtu = STMMAC_ALIGN(new_mtu);
 
 	/* If condition true, FIFO is too small or MTU too large */
-	if ((txfifosz < new_mtu) || (new_mtu > BUF_SIZE_16KiB))
+	if ((txfifosz < new_mtu && txfifosz) || (new_mtu > BUF_SIZE_16KiB))
 		return -EINVAL;
 
 	dev->mtu = new_mtu;
Signature · 1 line
2.19.1
maintainer
#1 lore raw
Quoted 11 lines · On Sat, 11 Apr 2020 20:49:31 -0700 Florian Fainelli wrote:

After commit bfcb813203e619a8960a819bf533ad2a108d8105 ("net: dsa:
configure the MTU for switch ports") my Lamobo R1 platform which uses an allwinner,sun7i-a20-gmac compatible Ethernet MAC started to fail by rejecting a MTU of 1536. The reason for that is that the DMA capabilities are not readable on this version of the IP, and there is also no 'tx-fifo-depth' property being provided in Device Tree. The property is documented as optional, and is not provided.

The minimum MTU that the network device accepts is ETH_ZLEN - ETH_HLEN, so rejecting the new MTU based on the txfifosz value unchecked seems a bit too heavy handed here.

OTOH is it safe to assume MTUs up to 16k are valid if device tree lacks the optional property? Is this change purely to preserve backward (bug-ward?) compatibility, even if it's not entirely correct to allow high MTU values? (I think that'd be worth stating in the commit message more explicitly.) Is there no "reasonable default" we could select for txfifosz if property is missing?

Quoted 11 lines
Fixes eaf4fac47807 ("net: stmmac: Do not accept invalid MTU values")
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
index e6898fd5223f..9c63ba6f86a9 100644

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int stmmac_change_mtu(struct net_device *dev, int new_mtu) · line 3999

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
@@ -3993,7 +3993,7 @@ static int stmmac_change_mtu(struct net_device *dev, int new_mtu)
 	new_mtu = STMMAC_ALIGN(new_mtu);
 
 	/* If condition true, FIFO is too small or MTU too large */
-	if ((txfifosz < new_mtu) || (new_mtu > BUF_SIZE_16KiB))
+	if ((txfifosz < new_mtu && txfifosz) || (new_mtu > BUF_SIZE_16KiB))
 		return -EINVAL;
 
 	dev->mtu = new_mtu;

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#2 lore raw
Quoted 13 lines · Jakub Kicinski
Quoted 11 lines · On Sat, 11 Apr 2020 20:49:31 -0700 Florian Fainelli wrote:

After commit bfcb813203e619a8960a819bf533ad2a108d8105 ("net: dsa:
configure the MTU for switch ports") my Lamobo R1 platform which uses an allwinner,sun7i-a20-gmac compatible Ethernet MAC started to fail by rejecting a MTU of 1536. The reason for that is that the DMA capabilities are not readable on this version of the IP, and there is also no 'tx-fifo-depth' property being provided in Device Tree. The property is documented as optional, and is not provided.

The minimum MTU that the network device accepts is ETH_ZLEN - ETH_HLEN, so rejecting the new MTU based on the txfifosz value unchecked seems a bit too heavy handed here.

Quoted 6 lines

OTOH is it safe to assume MTUs up to 16k are valid if device tree lacks the optional property? Is this change purely to preserve backward (bug-ward?) compatibility, even if it's not entirely correct to allow high MTU values? (I think that'd be worth stating in the commit message more explicitly.) Is there no "reasonable default" we could select for txfifosz if property is missing?

Those are good questions, and I do not know how to answer them as I am not familiar with the stmmac HW design, but I am hoping Jose can respond on this patch. It does sound like providing a default TX FIFO size would solve that MTU problem, too, but without a 'tx-fifo-depth' property specified in Device Tree, and with the "dma_cap" being empty for this chip, I have no idea what to set it to.

Quoted 21 lines
Quoted 20 lines
Fixes eaf4fac47807 ("net: stmmac: Do not accept invalid MTU values")
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index e6898fd5223f..9c63ba6f86a9 100644
@@ -3993,7 +3993,7 @@ static int stmmac_change_mtu(struct net_device *dev, int new_mtu)
 	new_mtu = STMMAC_ALIGN(new_mtu);
 
 	/* If condition true, FIFO is too small or MTU too large */
-	if ((txfifosz < new_mtu) || (new_mtu > BUF_SIZE_16KiB))
+	if ((txfifosz < new_mtu && txfifosz) || (new_mtu > BUF_SIZE_16KiB))
 		return -EINVAL;
 
 	dev->mtu = new_mtu;
Signature · 1 line
Florian
#3 lore raw

From: Florian Fainelli <[email protected]>
Date: Apr/12/2020, 19:31:55 (UTC+00:00)

Quoted 23 lines · Jakub Kicinski
Quoted 13 lines · On Sat, 11 Apr 2020 20:49:31 -0700 Florian Fainelli wrote:
Quoted 11 lines

After commit bfcb813203e619a8960a819bf533ad2a108d8105 ("net: dsa:
configure the MTU for switch ports") my Lamobo R1 platform which uses an allwinner,sun7i-a20-gmac compatible Ethernet MAC started to fail by rejecting a MTU of 1536. The reason for that is that the DMA capabilities are not readable on this version of the IP, and there is also no 'tx-fifo-depth' property being provided in Device Tree. The property is documented as optional, and is not provided.

The minimum MTU that the network device accepts is ETH_ZLEN - ETH_HLEN, so rejecting the new MTU based on the txfifosz value unchecked seems a bit too heavy handed here.

Quoted 6 lines

OTOH is it safe to assume MTUs up to 16k are valid if device tree lacks the optional property? Is this change purely to preserve backward (bug-ward?) compatibility, even if it's not entirely correct to allow high MTU values? (I think that'd be worth stating in the commit message more explicitly.) Is there no "reasonable default" we could select for txfifosz if property is missing?

Quoted 6 lines

Those are good questions, and I do not know how to answer them as I am not familiar with the stmmac HW design, but I am hoping Jose can respond on this patch. It does sound like providing a default TX FIFO size would solve that MTU problem, too, but without a 'tx-fifo-depth' property specified in Device Tree, and with the "dma_cap" being empty for this chip, I have no idea what to set it to.

Unfortunately, allwinner uses GMAC which does not have any mean to detect TX FIFO Size. Default value in HW is 2k but this can not be the case in these platforms if HW team decided to change it.

Anyway, your patch looks sane to me. But if you start seeing TX Queue Timeout for higher MTU values then you'll need to add tx-fifo-depth property.

---
Thanks,
Jose Miguel Abreu

#4 lore raw
Quoted 34 lines · Jose Abreu

From: Florian Fainelli <[email protected]>
Date: Apr/12/2020, 19:31:55 (UTC+00:00)

Quoted 23 lines · Jakub Kicinski
Quoted 13 lines · On Sat, 11 Apr 2020 20:49:31 -0700 Florian Fainelli wrote:
Quoted 11 lines

After commit bfcb813203e619a8960a819bf533ad2a108d8105 ("net: dsa:
configure the MTU for switch ports") my Lamobo R1 platform which uses an allwinner,sun7i-a20-gmac compatible Ethernet MAC started to fail by rejecting a MTU of 1536. The reason for that is that the DMA capabilities are not readable on this version of the IP, and there is also no 'tx-fifo-depth' property being provided in Device Tree. The property is documented as optional, and is not provided.

The minimum MTU that the network device accepts is ETH_ZLEN - ETH_HLEN, so rejecting the new MTU based on the txfifosz value unchecked seems a bit too heavy handed here.

Quoted 6 lines

OTOH is it safe to assume MTUs up to 16k are valid if device tree lacks the optional property? Is this change purely to preserve backward (bug-ward?) compatibility, even if it's not entirely correct to allow high MTU values? (I think that'd be worth stating in the commit message more explicitly.) Is there no "reasonable default" we could select for txfifosz if property is missing?

Quoted 6 lines

Those are good questions, and I do not know how to answer them as I am not familiar with the stmmac HW design, but I am hoping Jose can respond on this patch. It does sound like providing a default TX FIFO size would solve that MTU problem, too, but without a 'tx-fifo-depth' property specified in Device Tree, and with the "dma_cap" being empty for this chip, I have no idea what to set it to.

Quoted 3 lines

Unfortunately, allwinner uses GMAC which does not have any mean to detect TX FIFO Size. Default value in HW is 2k but this can not be the case in these platforms if HW team decided to change it.

I looked at all the publicly available datasheets and Allwinner uses 4K TX FIFO and 16K RX FIFO in all SoCs. Not sure if this would help.

ChenYu

Quoted 11 lines

Anyway, your patch looks sane to me. But if you start seeing TX Queue Timeout for higher MTU values then you'll need to add tx-fifo-depth property.

---
Thanks,
Jose Miguel Abreu
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#5 lore raw

From: Chen-Yu Tsai <[email protected]>
Date: Apr/13/2020, 07:50:47 (UTC+00:00)

Quoted 35 lines · Jose Abreu
Quoted 34 lines

From: Florian Fainelli <[email protected]>
Date: Apr/12/2020, 19:31:55 (UTC+00:00)

Quoted 29 lines · Jakub Kicinski
Quoted 13 lines · On Sat, 11 Apr 2020 20:49:31 -0700 Florian Fainelli wrote:
Quoted 11 lines

After commit bfcb813203e619a8960a819bf533ad2a108d8105 ("net: dsa:
configure the MTU for switch ports") my Lamobo R1 platform which uses an allwinner,sun7i-a20-gmac compatible Ethernet MAC started to fail by rejecting a MTU of 1536. The reason for that is that the DMA capabilities are not readable on this version of the IP, and there is also no 'tx-fifo-depth' property being provided in Device Tree. The property is documented as optional, and is not provided.

The minimum MTU that the network device accepts is ETH_ZLEN - ETH_HLEN, so rejecting the new MTU based on the txfifosz value unchecked seems a bit too heavy handed here.

Quoted 6 lines

OTOH is it safe to assume MTUs up to 16k are valid if device tree lacks the optional property? Is this change purely to preserve backward (bug-ward?) compatibility, even if it's not entirely correct to allow high MTU values? (I think that'd be worth stating in the commit message more explicitly.) Is there no "reasonable default" we could select for txfifosz if property is missing?

Those are good questions, and I do not know how to answer them as I am not familiar with the stmmac HW design, but I am hoping Jose can respond on this patch. It does sound like providing a default TX FIFO size would solve that MTU problem, too, but without a 'tx-fifo-depth' property specified in Device Tree, and with the "dma_cap" being empty for this chip, I have no idea what to set it to.

Quoted 6 lines
Quoted 3 lines

Unfortunately, allwinner uses GMAC which does not have any mean to detect TX FIFO Size. Default value in HW is 2k but this can not be the case in these platforms if HW team decided to change it.

I looked at all the publicly available datasheets and Allwinner uses 4K TX FIFO and 16K RX FIFO in all SoCs. Not sure if this would help.

Yes, thanks for finding this!

So, I think correct fix is then to hard-code these values in dwmac-sunxi.c probe function using the already available platform data structure.

---
Thanks,
Jose Miguel Abreu
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#6 lore raw
Quoted 43 lines · Jose Abreu

From: Chen-Yu Tsai <[email protected]>
Date: Apr/13/2020, 07:50:47 (UTC+00:00)

Quoted 39 lines · Jose Abreu
Quoted 37 lines

From: Florian Fainelli <[email protected]>
Date: Apr/12/2020, 19:31:55 (UTC+00:00)

Quoted 23 lines · Jakub Kicinski
Quoted 13 lines · On Sat, 11 Apr 2020 20:49:31 -0700 Florian Fainelli wrote:
Quoted 11 lines

After commit bfcb813203e619a8960a819bf533ad2a108d8105 ("net: dsa:
configure the MTU for switch ports") my Lamobo R1 platform which uses an allwinner,sun7i-a20-gmac compatible Ethernet MAC started to fail by rejecting a MTU of 1536. The reason for that is that the DMA capabilities are not readable on this version of the IP, and there is also no 'tx-fifo-depth' property being provided in Device Tree. The property is documented as optional, and is not provided.

The minimum MTU that the network device accepts is ETH_ZLEN - ETH_HLEN, so rejecting the new MTU based on the txfifosz value unchecked seems a bit too heavy handed here.

Quoted 6 lines

OTOH is it safe to assume MTUs up to 16k are valid if device tree lacks the optional property? Is this change purely to preserve backward (bug-ward?) compatibility, even if it's not entirely correct to allow high MTU values? (I think that'd be worth stating in the commit message more explicitly.) Is there no "reasonable default" we could select for txfifosz if property is missing?

Quoted 6 lines

Those are good questions, and I do not know how to answer them as I am not familiar with the stmmac HW design, but I am hoping Jose can respond on this patch. It does sound like providing a default TX FIFO size would solve that MTU problem, too, but without a 'tx-fifo-depth' property specified in Device Tree, and with the "dma_cap" being empty for this chip, I have no idea what to set it to.

Unfortunately, allwinner uses GMAC which does not have any mean to detect TX FIFO Size. Default value in HW is 2k but this can not be the case in these platforms if HW team decided to change it.

Quoted 7 lines
Quoted 2 lines

I looked at all the publicly available datasheets and Allwinner uses 4K TX FIFO and 16K RX FIFO in all SoCs. Not sure if this would help.

Yes, thanks for finding this!

So, I think correct fix is then to hard-code these values in dwmac-sunxi.c probe function using the already available platform data structure.

I guess we should also set this in the device trees, so that all DT users can benefit.

ChenYu

#7 lore raw
Quoted 47 lines · Chen-Yu Tsai
Quoted 46 lines · Jose Abreu

From: Chen-Yu Tsai <[email protected]>
Date: Apr/13/2020, 07:50:47 (UTC+00:00)

Quoted 41 lines · Jose Abreu
Quoted 34 lines

From: Florian Fainelli <[email protected]>
Date: Apr/12/2020, 19:31:55 (UTC+00:00)

Quoted 23 lines · Jakub Kicinski
Quoted 13 lines · On Sat, 11 Apr 2020 20:49:31 -0700 Florian Fainelli wrote:
Quoted 11 lines

After commit bfcb813203e619a8960a819bf533ad2a108d8105 ("net: dsa:
configure the MTU for switch ports") my Lamobo R1 platform which uses an allwinner,sun7i-a20-gmac compatible Ethernet MAC started to fail by rejecting a MTU of 1536. The reason for that is that the DMA capabilities are not readable on this version of the IP, and there is also no 'tx-fifo-depth' property being provided in Device Tree. The property is documented as optional, and is not provided.

The minimum MTU that the network device accepts is ETH_ZLEN - ETH_HLEN, so rejecting the new MTU based on the txfifosz value unchecked seems a bit too heavy handed here.

Quoted 6 lines

OTOH is it safe to assume MTUs up to 16k are valid if device tree lacks the optional property? Is this change purely to preserve backward (bug-ward?) compatibility, even if it's not entirely correct to allow high MTU values? (I think that'd be worth stating in the commit message more explicitly.) Is there no "reasonable default" we could select for txfifosz if property is missing?

Quoted 6 lines

Those are good questions, and I do not know how to answer them as I am not familiar with the stmmac HW design, but I am hoping Jose can respond on this patch. It does sound like providing a default TX FIFO size would solve that MTU problem, too, but without a 'tx-fifo-depth' property specified in Device Tree, and with the "dma_cap" being empty for this chip, I have no idea what to set it to.

Quoted 3 lines

Unfortunately, allwinner uses GMAC which does not have any mean to detect TX FIFO Size. Default value in HW is 2k but this can not be the case in these platforms if HW team decided to change it.

I looked at all the publicly available datasheets and Allwinner uses 4K TX FIFO and 16K RX FIFO in all SoCs. Not sure if this would help.

Quoted 7 lines
Quoted 4 lines

Yes, thanks for finding this!

So, I think correct fix is then to hard-code these values in dwmac-sunxi.c probe function using the already available platform data structure.

I guess we should also set this in the device trees, so that all DT users can benefit.

Sure, but that will be a bit harder to roll in as a bug fix. I will go ahead and submit a fix for dwmac-sunxi.c to specify a 4KB TX FIFO and 16KB RX FIFO. Thanks!

Signature · 1 line
Florian