Skip to contentSkip to conversation

net: stmmac: Limit the MTU of normal descriptors to one RX buffer

PATCH New Arun Iyengar 1 participant 1 message Nov 28

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

PATCH v3 1/1 net: stmmac: Limit the MTU of normal descriptors to one RX buffer

As Russell King pointed out in [1], max_mtu for normal descriptors, SKB_MAX_HEAD() (3712 on arm64), is too high: ndesc_get_rx_status() drops every frame that spans more than one descriptor, and the DMA does not always fill the 2047-byte buffer. Chen-Yu Tsai found the reason in the STM32F4 and Arria 10 manuals: the DMA writes whole bus words, counted from the word that holds the buffer start. Andrew Lunn noted that such an offset aligns the IP header; stmmac_rx_offset() adds NET_IP_ALIGN. Maxime Chevallier found the first failing untagged MTU:
2025 on H2+ (arm32, chain mode), 2029 on A20 and 2031 on meson-g12a (ring mode). On H616 (arm64, chain mode) it is 2027.

Take the widest bus, 16 bytes, NET_IP_ALIGN, the two bytes a Type-1 checksum engine appends, two VLAN tags and the FCS. max_mtu is then 2006 on arm64 and 2004 on arm32, two less with Type-1.

Fixes 48febf7e6476 ("stmmac: allow mtu bigger than 1500 in case of normal desc (V4)")
Cc Russell King <[email protected]>

---
Tested on an Orange Pi Zero2 (H616, arm64, Type-2 COE, chain mode) on
net-next: before, MTU 2027 drops every full-size RX frame; after, max MTU 2006, lossless. Untested: arm32, Type-1 COE, ring mode, dwmac1000 JE. Ring-mode RX buffer 2 and normal TX lengths: older bugs, separate patches.

Claude (AI) helped write this patch; I reviewed and tested it.
---
Changes in v3:
- One generic limit (Chen-Yu, Andrew, Maxime's sweep); RX is the limit (Nicolai); sun8i patch dropped; net-next, no Cc stable.
- Sashiko: bus width, NET_IP_ALIGN, Type-1 bytes counted; RBS1 unchanged,
frames end inside the aligned part; JE only lets longer frames in, and
they are dropped as before.
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Limit normal descriptors in the core (patch 1, Andrew Lunn, Maxime Chevallier), keep the lower sun8i limit as patch 2
- Link to v1: https://patch.msgid.link/[email protected]

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +16 -0
index ca4c7fb11b73..bf688ee46c84 100644
@@ -1568,6 +1568,20 @@ static unsigned int stmmac_rx_offset(struct stmmac_priv *priv)
 	return NET_SKB_PAD + NET_IP_ALIGN;
 }
 
+/* A normal descriptor frame must fit one RX buffer. The DMA writes whole bus
+ * words of up to 16 bytes, from the word that holds the NET_IP_ALIGN offset.
+ * Type-1 checksum engines append two bytes.
+ */
+static int stmmac_ndesc_max_mtu(struct stmmac_priv *priv)
+{
+	int len = ALIGN_DOWN(BUF_SIZE_2KiB - 1, 16) - NET_IP_ALIGN;
+
+	if (priv->plat->rx_coe == STMMAC_RX_COE_TYPE1)
+		len -= 2;
+
+	return len - ETH_HLEN - 2 * VLAN_HLEN - ETH_FCS_LEN;
+}
+
 static int stmmac_set_bfsize(int len)
 {
 	int ret;
@@ -8315,6 +8329,8 @@ static int __stmmac_dvr_probe(struct device *device,
 		ndev->max_mtu = XGMAC_JUMBO_LEN;
 	else if (priv->plat->enh_desc || priv->synopsys_id >= DWMAC_CORE_4_00)
 		ndev->max_mtu = JUMBO_LEN;
+	else if (priv->hw->desc == &ndesc_ops)
+		ndev->max_mtu = stmmac_ndesc_max_mtu(priv);
 	else
 		ndev->max_mtu = SKB_MAX_HEAD(NET_SKB_PAD + NET_IP_ALIGN);
 

---
base-commit: f89726ffabef1b08c52e6163b7ab94b0d5f15503
change-id: 20261121-sun8i-emac-mtu-limit-66a936064965

Best regards,

Signature · 1 line
Arun Iyengar <[email protected]>