mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next v1 1/1] net: macb: fix negative max_mtu size for sama5d3
@ 2022-06-10  9:45 Oleksij Rempel
  2022-06-10 13:06 ` Claudiu.Beznea
  0 siblings, 1 reply; 2+ messages in thread
From: Oleksij Rempel @ 2022-06-10  9:45 UTC (permalink / raw)
  To: Nicolas Ferre, Claudiu Beznea, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev

On Microchip SAMA5D3 the JML will return null. So, after header and FCS length
subtraction we will get negative max_mtu size. This issue was directly
affecting DSA drivers with MTU support (for example KSZ9477).

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/ethernet/cadence/macb_main.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index d89098f4ede8..c7e1c9ac9809 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -4913,10 +4913,24 @@ static int macb_probe(struct platform_device *pdev)
 
 	/* MTU range: 68 - 1500 or 10240 */
 	dev->min_mtu = GEM_MTU_MIN_SIZE;
-	if (bp->caps & MACB_CAPS_JUMBO)
-		dev->max_mtu = gem_readl(bp, JML) - ETH_HLEN - ETH_FCS_LEN;
-	else
+	if (bp->caps & MACB_CAPS_JUMBO) {
+		u32 val;
+
+		if (bp->jumbo_max_len)
+			val = bp->jumbo_max_len;
+		else
+			val = gem_readl(bp, JML);
+
+		if (val < ETH_DATA_LEN) {
+			dev_warn(&pdev->dev, "Suspicious max MTU size (%u), overwriting to %u\n",
+				 val, ETH_DATA_LEN);
+			dev->max_mtu = ETH_DATA_LEN;
+		} else {
+			dev->max_mtu = val - ETH_HLEN - ETH_FCS_LEN;
+		}
+	} else {
 		dev->max_mtu = ETH_DATA_LEN;
+	}
 
 	if (bp->caps & MACB_CAPS_BD_RD_PREFETCH) {
 		val = GEM_BFEXT(RXBD_RDBUFF, gem_readl(bp, DCFG10));
-- 
2.30.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-10 13:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-10  9:45 [PATCH net-next v1 1/1] net: macb: fix negative max_mtu size for sama5d3 Oleksij Rempel
2022-06-10 13:06 ` Claudiu.Beznea

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®