mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next v9 2/2] net: ethernet: mtk_eth_soc: add 9K jumbo
  2026-11-30 23:16 [PATCH net-next v9 0/2] net: ethernet: mtk_eth_soc: 9K jumbo frame support Sandeep Haemoon
  2026-11-30 23:16 ` [PATCH net-next v9 1/2] net: ethernet: mtk_eth_soc: skip page_pool Sandeep Haemoon
@ 2026-11-30 23:16 ` Sandeep Haemoon
  1 sibling, 0 replies; 3+ messages in thread
From: Sandeep Haemoon @ 2026-11-30 23:16 UTC (permalink / raw)
  To: netdev
  Cc: Felix Fietkau, Lorenzo Bianconi, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Matthias Brugger,
	AngeloGioacchino Del Regno, Russell King, Daniel Golle,
	Mason Chang, Frank Wunderlich, linux-mediatek, linux-arm-kernel,
	linux-kernel

The driver caps max_mtu at 2030 bytes and programs the MAC max-rx
field for at most 2048-byte frames, so an MTU above 2030 is rejected
and 9K jumbo frames are not usable on the 10G XGMII MACs.

Add a MTK_NETSYS_RX_9K capability for MT7988 and:
- advertise a 9194-byte max_mtu on the XGMII MACs, from the DT
  phy_mode at probe time, so DSA can raise the conduit MTU before the
  netdev is opened.  The four bytes below the 9216-byte MAC and ring
  cap keep room for the 802.1Q tag of a maximum-size frame.  On MT7988
  those MACs are GMAC1, the internal 10G switch port, and GMAC2, the
  internal 2.5G PHY; GMAC3 (MII/GMII) keeps its 2030-byte max_mtu.
  GMAC1's limit is the MCR field below, GMAC2's is XMAC_RX_CFG2;
- derive the shared RX buffer length from the largest MTU of any MAC,
  with a 2K floor checked first and the 802.1Q headroom added before
  the 1 KiB round-up, and size the RX rings from it.  The floor keeps
  the 2030-byte MTU of the non-XGMII MACs on 2K buffers, as before.
  The QDMA RX ring is never polled or refilled by the CPU, so it keeps
  its 2K buffers;
- program ADMA_RX_CFG[31:16] from that length on netsys v3+.  The
  MT7988A reference manual names the field "ADMA LRO free buffer SDL",
  the size of a buffer handed to the LRO engine, and its LRO chapter
  requires that size to be at least the largest frame the MAC accepts;
  the downstream driver encodes it as MTK_PDMA_LRO_SDL plus the frame
  area, and that is what is written here.  It is a buffer size, not a
  DMA length, so the per-descriptor PLEN0 still bounds every transfer;
  MT7988 does not use the LRO rings, and the write is kept for parity
  with the downstream driver;
- program XMAC_RX_CFG2 from the same length on the XGMII MACs, keeping
  the bits outside the length field, so a tagged maximum-size frame
  fits from the first 3K class up.  GMAC1 (the built-in switch port,
  phy-mode internal) keeps its MCR programming instead: the XMAC
  register is not used for it, and the MCR max-rx field gets the jumbo
  field (bits 31:28, in 1024-byte units), the encoding the MediaTek
  jumbo code uses on the GDM MACs.  The reference manual defines only
  4'h2 (2 Kbytes) for that field and marks the other encodings
  reserved, and the MT7988 downstream 9K patch does not raise it for
  GMAC1 at all; it is written here so the switch port is not capped at
  2048 if the switch path decodes the field as the vendor code does,
  and the per-descriptor PLEN0 bound protects the rings either way.
  Only GMAC1 gets the length; the other GDM MACs are kept at the
  documented 2 Kbytes encoding, because their max_mtu stays at 2030
  and they must not inherit a jumbo length from another netdev's MTU.
  The write runs after the XGMII setup of mtk_mac_config(), whose
  MAC_MCR_FORCE_LINK_DOWN write is a full-register write that would
  otherwise reset the field to the 1518 bucket;
- drop a descriptor whose PLEN0 exceeds the posted buffer and count it
  in rx_length_errors, which mtk_get_stats64() now merges into the
  exported counter together with the hardware length errors, and
  rx_errors includes the CRC and length errors as if_link.h requires,
  so the drop cannot hand the uninitialised tail of a buffer up the
  stack and it is visible to userspace.  This is needed by the
  build_skb() change below: for those buffers the tailroom now covers
  the whole allocation, so an over-long length would expose
  uninitialised page contents instead of tripping skb_over_panic();
- rewrite the MAC limits on every successful mtk_mac_config(), on
  mtk_hw_init() and on MTU changes while DMA is down, on the SoCs with
  the capability, so no MAC accepts a frame the rings cannot hold, not
  even after a reopen with a smaller MTU.  The limits are a property
  of the shared rings, so changing one device reprograms every MAC,
  and the XMAC limit is written again after the XMAC logic reset that
  mtk_xgdm_mac_link_up() pulses: RX_CFG2 resets to 0x800 (2048 bytes),
  so a reset would otherwise cap the MAC at 2K.  The all-MAC pass runs
  only while DMA is down, which is the only time the shared length can
  change; a shrink while another MAC is up keeps the buffers the rings
  already hold, so its limits still match and the pass would only
  read-modify-write another MAC's MCR under its phylink worker.  The
  other SoCs keep their per-device limits: they never grow their rings,
  and their MCR programming is left exactly as before this patch;
- pass the interface to mtk_set_mcr_max_rx() and re-apply the limit
  from both link-up paths, so a mtk_mac_config() that failed before it
  updated mac->interface no longer leaves the MAC on the wrong register
  or at the reset limit;
- reject a runtime MTU change that would need larger buffers while
  DMA is running (-EBUSY).  Shrinking is allowed: the rings keep the
  buffers they already have.  The rings are shared by every MAC, so
  raising a DSA user port MTU on a live system fails while any MAC is
  up; the runtime reallocation that lifts this is a separate series.

XDP runs only on rings that have a page_pool, and the pool cannot back
buffers larger than MTK_PP_MAX_BUF_SIZE, so an MTU that needs a larger
buffer cannot be combined with XDP; attaching a program is rejected in
that case.  The check uses eth->rx_buf_len, the length the live rings
were actually built with; when the rings are not live, or the attach
itself tears them down, the next open re-derives the length from the
current MTUs and that value is checked instead.  A program can
therefore never attach and silently not run, and an attach on a
closed device is never rejected over a stale ring length.  Detaching
is always allowed: it does not need a page_pool.

With the 1 KiB rounding, the buffer length is order-1 (8 KiB) for
rx_buf_len 4096..7168 (MTU about 3051..7146) and order-2 (16 KiB)
from rx_buf_len 8192 (MTU 7147) up: once any MAC's MTU reaches 7147,
every RX buffer is a 16 KiB compound page, which pins 2048 x 16 KiB
(about 32 MiB) in the single CPU-polled ring on MT7988 while DMA is up
and turns the refill into a high-order GFP_ATOMIC allocation.
skb->truesize reports the size that was actually allocated for those
buffers, not the smaller frag_size.  That correction also covers the
HW-LRO rings on mt2701, mt7622, mt7623 and mt7629, whose ~12.4 KiB
buffers now report 16 KiB.

This is a forward-port of the MediaTek downstream jumbo work: Mason
Chang's "change default rx buffer length" and "add 9k jumbo frame
support" (MediaTek OpenWrt feed 999-eth-30/31, carried in
frank-w/BPI-Router-Linux), plus Frank Wunderlich's "try to fix crash
the right way".  The runtime reallocation of Mason's "dynamic rx
buffer adjustment" (feed 999-eth-33) is not included; it will be sent
separately.  The code is credited by reference rather than with
co-author tags, which need the original authors' own Signed-off-by
lines; the port also diverges from the downstream
implementation (the 2K buffer floor, the per-ring pool gate, the
-EBUSY rule, the XDP checks and the truesize fix are not in the
downstream patches).

Link: https://github.com/frank-w/BPI-Router-Linux/commit/b4c6cb1d5532
Link: https://github.com/mediatek/mtk-openwrt-feeds
Signed-off-by: Sandeep Haemoon <sandeeph@loljews.com>
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 435 +++++++++++++++++---
 drivers/net/ethernet/mediatek/mtk_eth_soc.h |  16 +-
 2 files changed, 392 insertions(+), 59 deletions(-)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index cb05a8e43e..5affaf7fc4 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -170,6 +170,7 @@ static const struct mtk_reg_map mt7988_reg_map = {
 		.pcrx_ptr	= 0x6908,
 		.glo_cfg	= 0x6a04,
 		.rst_idx	= 0x6a08,
+		.rx_cfg		= 0x6a10,
 		.delay_irq	= 0x6a0c,
 		.irq_status	= 0x6a20,
 		.irq_mask	= 0x6a28,
@@ -554,6 +555,112 @@ static int mtk_mac_prepare(struct phylink_config *config, unsigned int mode,
 	return 0;
 }
 
+/* The MACs are fed from the shared RX rings, so the maximum frame they may
+ * accept is a property of the ring buffer length.  GMAC1 on netsys v3+ is
+ * the built-in switch port: it has no XMAC_RX_CFG2 limit register, so it
+ * keeps the MCR programming the other SoCs use, extended with the MCR
+ * jumbo field so its limit can grow with the rings like the XGMII MACs'.
+ * The interface is passed in instead of being taken from mac->interface:
+ * mtk_mac_config() can fail before it updates that field, and phylink
+ * still calls mac_link_up() in that case.
+ */
+static void mtk_set_mcr_max_rx(struct mtk_mac *mac, phy_interface_t interface,
+			       u32 val)
+{
+	struct mtk_eth *eth = mac->hw;
+	u32 mcr_cur, mcr_new;
+
+	if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628))
+		return;
+
+	if (!mtk_interface_mode_is_xgmii(eth, interface) ||
+	    mac->id == MTK_GMAC1_ID) {
+		mcr_cur = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));
+		mcr_new = mcr_cur & ~MAC_MCR_MAX_RX_MASK;
+
+		if (val <= 1518)
+			mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_1518);
+		else if (val <= 1536)
+			mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_1536);
+		else if (val <= 1552)
+			mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_1552);
+		else
+			mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_2048);
+
+		/* The bucket encodes at most 2048; the SoCs with the 9K
+		 * capability need the jumbo field, in 1024-byte units, for
+		 * anything larger.  The MT7988A reference manual defines
+		 * only 4'h2 (2 Kbytes) for that field and marks the rest
+		 * reserved, and the MT7988 downstream 9K patch does not
+		 * raise it for GMAC1 at all; the field is the encoding the
+		 * MediaTek jumbo code uses on the GDM MACs, and GMAC1 gets
+		 * the length so its limit is not capped at the 2048 bucket
+		 * if the switch path decodes the field as the vendor code
+		 * does.  The other GDM MACs keep the
+		 * documented 2 Kbytes encoding: their max_mtu stays at
+		 * 2030 and they must not inherit a jumbo length from
+		 * another netdev's MTU.  Clearing the field together with
+		 * the bucket keeps a stale value from surviving a shrink.
+		 */
+		if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_RX_9K)) {
+			u32 jumbo = DIV_ROUND_UP(val, MTK_MAX_RX_LENGTH_UNIT);
+
+			jumbo = min(jumbo, MTK_MAX_RX_LENGTH_9K /
+					   MTK_MAX_RX_LENGTH_UNIT);
+
+			mcr_new &= ~MAC_MCR_MAX_RX_JUMBO_MASK;
+
+			if (val > 1552) {
+				if (mac->id != MTK_GMAC1_ID)
+					jumbo = 2;
+				mcr_new |= MAC_MCR_MAX_RX_JUMBO(jumbo);
+			}
+		}
+
+		if (mcr_new != mcr_cur)
+			mtk_w32(mac->hw, mcr_new, MTK_MAC_MCR(mac->id));
+	} else {
+		mcr_cur = mtk_r32(mac->hw, MTK_XMAC_RX_CFG2(mac->id));
+		mcr_new = mcr_cur & ~MTK_XMAC_MAX_RX_MASK;
+		mcr_new |= FIELD_PREP(MTK_XMAC_MAX_RX_MASK,
+				      min_t(u32, val, MTK_MAX_RX_LENGTH_9K));
+
+		if (mcr_new != mcr_cur)
+			mtk_w32(mac->hw, mcr_new, MTK_XMAC_RX_CFG2(mac->id));
+	}
+}
+
+/* The RX rings are shared by every MAC, so all of them have to accept at
+ * most the length the buffers can hold.  The XGMII MACs have a per-MAC
+ * register and GMAC1 uses the MCR buckets, so walk all of them.
+ */
+static void mtk_set_all_macs_max_rx(struct mtk_eth *eth)
+{
+	int i;
+
+	if (!MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_RX_9K))
+		return;
+
+	for (i = 0; i < MTK_MAX_DEVS; i++) {
+		struct mtk_mac *mac;
+
+		if (!eth->netdev[i])
+			continue;
+
+		mac = netdev_priv(eth->netdev[i]);
+
+		/* Before the first mac_config() the interface mode is not
+		 * known and the limit would be written to the MCR register
+		 * of an XGMII MAC.  That open programs every MAC from its
+		 * own mac_config() anyway.
+		 */
+		if (mac->interface == PHY_INTERFACE_MODE_NA)
+			continue;
+
+		mtk_set_mcr_max_rx(mac, mac->interface, eth->rx_buf_len);
+	}
+}
+
 static void mtk_mac_config(struct phylink_config *config, unsigned int mode,
 			   const struct phylink_link_state *state)
 {
@@ -678,6 +785,18 @@ static void mtk_mac_config(struct phylink_config *config, unsigned int mode,
 			mtk_setup_bridge_switch(eth);
 	}
 
+	/* On the SoCs with the 9K capability the rings grow with the MTU, so
+	 * rewrite the MAC limit on every successful mac_config, not only
+	 * when the interface mode changes: a reopen after an MTU change
+	 * must narrow the MACs that still carry the previous, larger
+	 * limit.  This must run after the XGMII setup above: its
+	 * MAC_MCR_FORCE_LINK_DOWN write is a full-register write that
+	 * would otherwise reset GMAC1's max-rx field (its limit lives in
+	 * the MCR register, not in XMAC_RX_CFG2) back to the 1518 bucket.
+	 */
+	if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_RX_9K))
+		mtk_set_mcr_max_rx(mac, state->interface, eth->rx_buf_len);
+
 	return;
 
 err_phy:
@@ -843,6 +962,13 @@ static void mtk_gdm_mac_link_up(struct mtk_mac *mac,
 
 	mcr |= MAC_MCR_TX_EN | MAC_MCR_RX_EN | MAC_MCR_FORCE_LINK;
 	mtk_w32(mac->hw, mcr, MTK_MAC_MCR(mac->id));
+
+	/* The limit lives in the same register and mtk_mac_config() may
+	 * not have reached it if it failed early, so set it again now
+	 * that the link is up and the interface mode is known.
+	 */
+	if (MTK_HAS_CAPS(mac->hw->soc->caps, MTK_NETSYS_RX_9K))
+		mtk_set_mcr_max_rx(mac, interface, mac->hw->rx_buf_len);
 }
 
 static void mtk_xgdm_mac_link_up(struct mtk_mac *mac,
@@ -853,8 +979,16 @@ static void mtk_xgdm_mac_link_up(struct mtk_mac *mac,
 {
 	u32 mcr;
 
-	if (mac->id == MTK_GMAC1_ID)
+	if (mac->id == MTK_GMAC1_ID) {
+		/* GMAC1 has no XMAC block to reset; its limit is the MCR
+		 * one, which mtk_mac_config() may not have programmed if it
+		 * failed early.
+		 */
+		if (MTK_HAS_CAPS(mac->hw->soc->caps, MTK_NETSYS_RX_9K))
+			mtk_set_mcr_max_rx(mac, interface,
+					   mac->hw->rx_buf_len);
 		return;
+	}
 
 	/* Eliminate the interference(before link-up) caused by PHY noise */
 	mtk_m32(mac->hw, XMAC_LOGIC_RST, 0, MTK_XMAC_LOGIC_RST(mac->id));
@@ -877,6 +1011,12 @@ static void mtk_xgdm_mac_link_up(struct mtk_mac *mac,
 		mcr |= XMAC_MCR_FORCE_RX_FC;
 
 	mtk_w32(mac->hw, mcr, MTK_XMAC_MCR(mac->id));
+
+	/* The logic reset above can clear the RX size limit programmed from
+	 * mtk_mac_config(), so set it again now that the logic is out of
+	 * reset and the interface mode is known.
+	 */
+	mtk_set_mcr_max_rx(mac, interface, mac->hw->rx_buf_len);
 }
 
 static void mtk_mac_link_up(struct phylink_config *config,
@@ -1231,37 +1371,51 @@ static void mtk_get_stats64(struct net_device *dev,
 		storage->collisions = hw_stats->tx_collisions;
 		storage->rx_length_errors = hw_stats->rx_short_errors +
 			hw_stats->rx_long_errors;
+		storage->rx_errors = hw_stats->rx_checksum_errors +
+				     hw_stats->rx_fcs_errors +
+				     storage->rx_length_errors;
 		storage->rx_over_errors = hw_stats->rx_overflow;
 		storage->rx_crc_errors = hw_stats->rx_fcs_errors;
-		storage->rx_errors = hw_stats->rx_checksum_errors;
 		storage->tx_aborted_errors = hw_stats->tx_skip;
 	} while (u64_stats_fetch_retry(&hw_stats->syncp, start));
 
 	storage->tx_errors = dev->stats.tx_errors;
 	storage->rx_dropped = dev->stats.rx_dropped;
+	storage->rx_length_errors += dev->stats.rx_length_errors;
+	storage->rx_errors += dev->stats.rx_length_errors;
 	storage->tx_dropped = dev->stats.tx_dropped;
 }
 
-static inline int mtk_max_frag_size(int mtu)
+static inline int mtk_max_frag_size(u32 rx_buf_len, int mtu)
 {
-	/* make sure buf_size will be at least MTK_MAX_RX_LENGTH */
-	if (mtu + MTK_RX_ETH_HLEN < MTK_MAX_RX_LENGTH_2K)
-		mtu = MTK_MAX_RX_LENGTH_2K - MTK_RX_ETH_HLEN;
+	/* make sure buf_size will be at least the rx buffer length */
+	if (mtu + MTK_RX_ETH_HLEN < rx_buf_len)
+		mtu = rx_buf_len - MTK_RX_ETH_HLEN;
 
 	return SKB_DATA_ALIGN(MTK_RX_HLEN + mtu) +
 		SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
 }
 
-static inline int mtk_max_buf_size(int frag_size)
+static inline int mtk_max_buf_size(u32 rx_buf_len, int frag_size)
 {
 	int buf_size = frag_size - NET_SKB_PAD - NET_IP_ALIGN -
 		       SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
 
-	WARN_ON(buf_size < MTK_MAX_RX_LENGTH_2K);
+	WARN_ON(buf_size < rx_buf_len);
 
 	return buf_size;
 }
 
+/* The descriptor length a normal RX ring gets for a given shared buffer
+ * length.  The page_pool gate in mtk_rx_alloc() uses the same value, so the
+ * XDP admission checks test exactly what the pool can back.
+ */
+static u32 mtk_rx_ring_buf_size(u32 rx_buf_len)
+{
+	return mtk_max_buf_size(rx_buf_len,
+				mtk_max_frag_size(rx_buf_len, ETH_DATA_LEN));
+}
+
 static bool mtk_rx_get_desc(struct mtk_eth *eth, struct mtk_rx_dma_v2 *rxd,
 			    struct mtk_rx_dma_v2 *dma_rxd)
 {
@@ -1280,9 +1434,17 @@ static bool mtk_rx_get_desc(struct mtk_eth *eth, struct mtk_rx_dma_v2 *rxd,
 	return true;
 }
 
-static void *mtk_max_lro_buf_alloc(gfp_t gfp_mask)
+/* mtk_max_buf_alloc() rounds the buffer up to a whole page order, so
+ * report the size it actually allocated, not the smaller frag_size, in
+ * skb->truesize.
+ */
+static unsigned int mtk_buf_alloc_size(unsigned int size)
+{
+	return PAGE_SIZE << get_order(size);
+}
+
+static void *mtk_max_buf_alloc(unsigned int size, gfp_t gfp_mask)
 {
-	unsigned int size = mtk_max_frag_size(MTK_MAX_LRO_RX_LENGTH);
 	unsigned long data;
 
 	data = __get_free_pages(gfp_mask | __GFP_COMP | __GFP_NOWARN,
@@ -2262,6 +2424,16 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
 
 		pktlen = RX_DMA_GET_PLEN0(trxd.rxd2);
 
+		/* Never pass a descriptor longer than the posted buffer up
+		 * the stack: the refill below gives build_skb() the whole
+		 * allocation as tailroom, so such a length would expose
+		 * uninitialised memory instead of tripping skb_over_panic().
+		 */
+		if (unlikely(pktlen > ring->buf_size)) {
+			netdev->stats.rx_length_errors++;
+			goto release_desc;
+		}
+
 		/* alloc new buffer */
 		if (ring->page_pool) {
 			struct page *page = virt_to_head_page(data);
@@ -2307,10 +2479,15 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
 				skb_metadata_set(skb, metasize);
 			skb_mark_for_recycle(skb);
 		} else {
+			unsigned int alloc_size = ring->frag_size > PAGE_SIZE ?
+				mtk_buf_alloc_size(ring->frag_size) :
+				ring->frag_size;
+
 			if (ring->frag_size <= PAGE_SIZE)
 				new_data = napi_alloc_frag(ring->frag_size);
 			else
-				new_data = mtk_max_lro_buf_alloc(GFP_ATOMIC);
+				new_data = mtk_max_buf_alloc(ring->frag_size,
+							     GFP_ATOMIC);
 
 			if (unlikely(!new_data)) {
 				netdev->stats.rx_dropped++;
@@ -2333,7 +2510,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
 			dma_unmap_single(eth->dma_dev, ((u64)trxd.rxd1 | addr64),
 					 ring->buf_size, DMA_FROM_DEVICE);
 
-			skb = build_skb(data, ring->frag_size);
+			skb = build_skb(data, alloc_size);
 			if (unlikely(!skb)) {
 				netdev->stats.rx_dropped++;
 				skb_free_frag(data);
@@ -2794,6 +2971,7 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag)
 	const struct mtk_soc_data *soc = eth->soc;
 	struct mtk_rx_ring *ring;
 	int rx_data_len, rx_dma_size;
+	u32 buf_len;
 	int i;
 
 	if (rx_flag == MTK_RX_FLAGS_QDMA) {
@@ -2812,8 +2990,19 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag)
 		rx_dma_size = soc->rx.dma_size;
 	}
 
-	ring->frag_size = mtk_max_frag_size(rx_data_len);
-	ring->buf_size = mtk_max_buf_size(ring->frag_size);
+	/* The QDMA RX ring is only ever scratch memory for the engine: the
+	 * CPU neither polls nor refills it, so it keeps its 2K buffers
+	 * even when the polled rings grow.
+	 */
+	if (rx_flag == MTK_RX_FLAGS_QDMA)
+		buf_len = MTK_MAX_RX_LENGTH_2K;
+	else if (rx_flag == MTK_RX_FLAGS_HWLRO)
+		buf_len = max_t(u32, eth->rx_buf_len, MTK_MAX_LRO_RX_LENGTH);
+	else
+		buf_len = eth->rx_buf_len;
+
+	ring->frag_size = mtk_max_frag_size(buf_len, rx_data_len);
+	ring->buf_size  = mtk_max_buf_size(buf_len, ring->frag_size);
 	ring->data = kzalloc_objs(*ring->data, rx_dma_size);
 	if (!ring->data)
 		return -ENOMEM;
@@ -2821,7 +3010,7 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag)
 	/* A page_pool hands out order-0 pages and is created with
 	 * MTK_PP_MAX_BUF_SIZE, so it can only back a ring whose descriptor
 	 * length fits.  Larger rings use the netdev_alloc_frag()/
-	 * mtk_max_lro_buf_alloc() path below instead.
+	 * mtk_max_buf_alloc() path below instead.
 	 */
 	if (mtk_page_pool_enabled(eth) &&
 	    ring->buf_size <= MTK_PP_MAX_BUF_SIZE) {
@@ -2857,7 +3046,8 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag)
 			if (ring->frag_size <= PAGE_SIZE)
 				data = netdev_alloc_frag(ring->frag_size);
 			else
-				data = mtk_max_lro_buf_alloc(GFP_KERNEL);
+				data = mtk_max_buf_alloc(ring->frag_size,
+							 GFP_KERNEL);
 
 			if (!data)
 				return -ENOMEM;
@@ -3253,6 +3443,75 @@ static int mtk_dma_busy_wait(struct mtk_eth *eth)
 	return ret;
 }
 
+static int mtk_max_gmac_mtu(struct mtk_eth *eth)
+{
+	int i, max_mtu = ETH_DATA_LEN;
+
+	for (i = 0; i < ARRAY_SIZE(eth->netdev); i++)
+		if (eth->netdev[i] && eth->netdev[i]->mtu > max_mtu)
+			max_mtu = eth->netdev[i]->mtu;
+
+	return max_mtu;
+}
+
+static u32 mtk_rx_buf_len_from_mtu(struct mtk_eth *eth, int max_mtu)
+{
+	int length;
+
+	/* Only the SoCs with the 9K capability grow the shared rings with
+	 * the MTU.  Everywhere else the buffers stay at 2K, so the largest
+	 * MTU those SoCs advertise keeps working at runtime and the -EBUSY
+	 * rule below never applies to them.
+	 */
+	if (!MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_RX_9K))
+		return MTK_MAX_RX_LENGTH_2K;
+
+	/* Keep everything the 2K buffers already cover on the 2K floor.
+	 * Adding the VLAN headroom first would round the largest MTU the
+	 * non-XGMII MACs advertise (2030) up to 3072 and make a runtime MTU
+	 * change fail with -EBUSY.
+	 */
+	if (max_mtu + MTK_RX_ETH_HLEN <= MTK_MAX_RX_LENGTH_2K)
+		return MTK_MAX_RX_LENGTH_2K;
+
+	length = max_mtu + MTK_RX_ETH_HLEN + VLAN_HLEN;
+
+	return DIV_ROUND_UP(length, 1024) * 1024;
+}
+
+/* The rx rings are shared by every MAC, so their buffers are sized for
+ * the largest MTU configured on any of them.
+ */
+static u32 mtk_rx_buf_len(struct mtk_eth *eth)
+{
+	return mtk_rx_buf_len_from_mtu(eth, mtk_max_gmac_mtu(eth));
+}
+
+/* Program ADMA_RX_CFG[31:16] from the shared RX buffer length on netsys
+ * v3+.  The MT7988A reference manual names the field "ADMA LRO free
+ * buffer SDL": the size of a buffer handed to the LRO engine, which its
+ * LRO chapter requires to be at least the largest frame the MAC accepts.
+ * The MediaTek downstream driver encodes it as MTK_PDMA_LRO_SDL plus the
+ * frame area, and that is what is written here.  It is a buffer size, not
+ * a DMA length, so the per-descriptor PLEN0 still bounds every transfer;
+ * MT7988 does not use the LRO rings, and the write matches the downstream
+ * driver rather than gating the jumbo path.
+ */
+static void mtk_pdma_set_sdl(struct mtk_eth *eth)
+{
+	const struct mtk_reg_map *reg_map = eth->soc->reg_map;
+	u32 val;
+
+	if (!mtk_is_netsys_v3_or_greater(eth))
+		return;
+
+	val = mtk_r32(eth, reg_map->pdma.rx_cfg);
+	val &= ~MTK_RX_CFG_SDL_MASK;
+	val |= FIELD_PREP(MTK_RX_CFG_SDL_MASK,
+			  MTK_PDMA_LRO_SDL + eth->rx_buf_len);
+	mtk_w32(eth, val, reg_map->pdma.rx_cfg);
+}
+
 static int mtk_dma_init(struct mtk_eth *eth)
 {
 	int err;
@@ -3261,6 +3520,15 @@ static int mtk_dma_init(struct mtk_eth *eth)
 	if (mtk_dma_busy_wait(eth))
 		return -EBUSY;
 
+	/* Derived here, at ring allocation, so eth->rx_buf_len always
+	 * describes the buffers the rings actually hold; mtk_change_mtu()
+	 * updates it while DMA is down so it describes the rings-to-be,
+	 * and mtk_mac_config() then never lets a MAC accept a frame the
+	 * rings cannot take.
+	 */
+	eth->rx_buf_len = mtk_rx_buf_len(eth);
+	mtk_set_all_macs_max_rx(eth);
+
 	if (MTK_HAS_CAPS(eth->soc->caps, MTK_QDMA)) {
 		/* QDMA needs scratch memory for internal reordering of the
 		 * descriptors
@@ -3304,6 +3572,8 @@ static int mtk_dma_init(struct mtk_eth *eth)
 		mtk_w32(eth, 0x0, eth->soc->reg_map->qdma.hred);
 	}
 
+	mtk_pdma_set_sdl(eth);
+
 	return 0;
 }
 
@@ -3594,17 +3864,6 @@ static int mtk_device_event(struct notifier_block *n, unsigned long event, void
 	return NOTIFY_DONE;
 }
 
-static int mtk_max_gmac_mtu(struct mtk_eth *eth)
-{
-	int i, max_mtu = ETH_DATA_LEN;
-
-	for (i = 0; i < ARRAY_SIZE(eth->netdev); i++)
-		if (eth->netdev[i] && eth->netdev[i]->mtu > max_mtu)
-			max_mtu = eth->netdev[i]->mtu;
-
-	return max_mtu;
-}
-
 static int mtk_open(struct net_device *dev)
 {
 	struct mtk_mac *mac = netdev_priv(dev);
@@ -3774,6 +4033,7 @@ static int mtk_xdp_setup(struct net_device *dev, struct bpf_prog *prog,
 	struct mtk_mac *mac = netdev_priv(dev);
 	struct mtk_eth *eth = mac->hw;
 	struct bpf_prog *old_prog;
+	u32 rx_buf_len;
 	bool need_update;
 
 	if (eth->hwlro) {
@@ -3781,12 +4041,28 @@ static int mtk_xdp_setup(struct net_device *dev, struct bpf_prog *prog,
 		return -EOPNOTSUPP;
 	}
 
-	if (dev->mtu > MTK_PP_MAX_BUF_SIZE) {
+	need_update = !!eth->prog != !!prog;
+
+	/* XDP only runs on rings that have a page_pool, and the pool is
+	 * only created when the shared RX buffer length fits
+	 * MTK_PP_MAX_BUF_SIZE.  eth->rx_buf_len describes the live rings;
+	 * when the rings are not live, or this attach tears them down,
+	 * the next open re-derives it from the current MTUs, so check
+	 * that value instead.  A detach never needs a pool, so it is not
+	 * checked at all.
+	 */
+	rx_buf_len = eth->rx_buf_len;
+	if (prog &&
+	    (!refcount_read(&eth->dma_refcnt) ||
+	     (netif_running(dev) && need_update &&
+	      refcount_read(&eth->dma_refcnt) == 1)))
+		rx_buf_len = mtk_rx_buf_len(eth);
+
+	if (prog && mtk_rx_ring_buf_size(rx_buf_len) > MTK_PP_MAX_BUF_SIZE) {
 		NL_SET_ERR_MSG_MOD(extack, "MTU too large for XDP");
 		return -EOPNOTSUPP;
 	}
 
-	need_update = !!eth->prog != !!prog;
 	if (netif_running(dev) && need_update)
 		mtk_stop(dev);
 
@@ -3921,30 +4197,6 @@ static void mtk_dim_tx(struct work_struct *work)
 	dim->state = DIM_START_MEASURE;
 }
 
-static void mtk_set_mcr_max_rx(struct mtk_mac *mac, u32 val)
-{
-	struct mtk_eth *eth = mac->hw;
-	u32 mcr_cur, mcr_new;
-
-	if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628))
-		return;
-
-	mcr_cur = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));
-	mcr_new = mcr_cur & ~MAC_MCR_MAX_RX_MASK;
-
-	if (val <= 1518)
-		mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_1518);
-	else if (val <= 1536)
-		mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_1536);
-	else if (val <= 1552)
-		mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_1552);
-	else
-		mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_2048);
-
-	if (mcr_new != mcr_cur)
-		mtk_w32(mac->hw, mcr_new, MTK_MAC_MCR(mac->id));
-}
-
 static void mtk_hw_reset(struct mtk_eth *eth)
 {
 	u32 val;
@@ -4207,13 +4459,25 @@ static int mtk_hw_init(struct mtk_eth *eth, bool reset)
 	 */
 	for (i = 0; i < MTK_MAX_DEVS; i++) {
 		struct net_device *dev = eth->netdev[i];
+		struct mtk_mac *mac;
 
 		if (!dev)
 			continue;
 
+		mac = netdev_priv(dev);
 		mtk_w32(eth, MAC_MCR_FORCE_LINK_DOWN, MTK_MAC_MCR(i));
-		mtk_set_mcr_max_rx(netdev_priv(dev),
-				   dev->mtu + MTK_RX_ETH_HLEN);
+		if (!MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_RX_9K)) {
+			mtk_set_mcr_max_rx(mac, mac->interface,
+					   dev->mtu + MTK_RX_ETH_HLEN);
+		} else if (mac->interface != PHY_INTERFACE_MODE_NA) {
+			/* Before the first mac_config() the interface mode
+			 * is unknown and the limit would land in the MCR
+			 * register of an XGMII MAC; that open programs each
+			 * MAC from its own mac_config() anyway.
+			 */
+			mtk_set_mcr_max_rx(mac, mac->interface,
+					   eth->rx_buf_len);
+		}
 	}
 
 	/* Indicates CDM to parse the MTK special tag from CPU
@@ -4354,15 +4618,61 @@ static int mtk_change_mtu(struct net_device *dev, int new_mtu)
 	int length = new_mtu + MTK_RX_ETH_HLEN;
 	struct mtk_mac *mac = netdev_priv(dev);
 	struct mtk_eth *eth = mac->hw;
+	u32 rx_buf_len;
+	bool running;
 	int max_mtu, i;
 
+	/* The RX rings are shared by every MAC, so the buffer length
+	 * follows the largest MTU of all of them, the new one included.
+	 */
+	max_mtu = new_mtu;
+	for (i = 0; i < MTK_MAX_DEVS; i++) {
+		if (eth->netdev[i] && eth->netdev[i] != dev &&
+		    eth->netdev[i]->mtu > max_mtu)
+			max_mtu = eth->netdev[i]->mtu;
+	}
+	rx_buf_len = mtk_rx_buf_len_from_mtu(eth, max_mtu);
+
 	if (rcu_access_pointer(eth->prog) &&
-	    length > MTK_PP_MAX_BUF_SIZE) {
+	    mtk_rx_ring_buf_size(rx_buf_len) > MTK_PP_MAX_BUF_SIZE) {
 		netdev_err(dev, "Invalid MTU for XDP mode\n");
 		return -EINVAL;
 	}
 
-	mtk_set_mcr_max_rx(mac, length);
+	/* The rings cannot be resized in place while DMA is running: a
+	 * larger buffer can only come from the reallocation at the next
+	 * open, so reject it.  A smaller one is fine, the buffers the
+	 * rings already hold are big enough for it.
+	 */
+	running = refcount_read(&eth->dma_refcnt);
+	if (running && rx_buf_len > eth->rx_buf_len)
+		return -EBUSY;
+
+	/* While DMA is up the rings keep the buffers they were built with;
+	 * update eth->rx_buf_len only when DMA is down so it always
+	 * describes the buffers the rings hold, or will hold at the next
+	 * open.
+	 */
+	if (!running)
+		eth->rx_buf_len = rx_buf_len;
+
+	/* On the SoCs whose rings grow with the MTU every MAC has to be
+	 * narrowed or widened together, because they share the buffers;
+	 * the other SoCs keep the per-device limit they always had.
+	 */
+	if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_RX_9K)) {
+		/* eth->rx_buf_len changes only while DMA is down, so the
+		 * limits the running MACs already have still match their
+		 * buffers.  Skipping the pass in that case also keeps it
+		 * from read-modify-writing another MAC's MCR while that
+		 * MAC's phylink worker configures the same register.
+		 */
+		if (!running)
+			mtk_set_all_macs_max_rx(eth);
+	} else {
+		mtk_set_mcr_max_rx(mac, mac->interface, length);
+	}
+
 	WRITE_ONCE(dev->mtu, new_mtu);
 
 	max_mtu = mtk_max_gmac_mtu(eth);
@@ -5012,8 +5322,17 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
 	eth->netdev[id]->irq = eth->irq[MTK_FE_IRQ_SHARED];
 	eth->netdev[id]->dev.of_node = np;
 
+	/* DSA sets the conduit MTU (user MTU + tag) before the netdev is
+	 * opened, so max_mtu must already be final here.  Deriving it only
+	 * in mtk_open() leaves the conduit at its 1504 default and blocks
+	 * 9K frames on the DSA user ports.
+	 */
 	if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628))
 		eth->netdev[id]->max_mtu = MTK_MAX_RX_LENGTH - MTK_RX_ETH_HLEN;
+	else if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_RX_9K) &&
+		 mtk_interface_mode_is_xgmii(eth, phy_mode))
+		eth->netdev[id]->max_mtu =
+			MTK_MAX_RX_LENGTH_9K - MTK_RX_ETH_HLEN - VLAN_HLEN;
 	else
 		eth->netdev[id]->max_mtu = MTK_MAX_RX_LENGTH_2K - MTK_RX_ETH_HLEN;
 
@@ -5154,6 +5473,8 @@ static int mtk_probe(struct platform_device *pdev)
 	spin_lock_init(&eth->rx_irq_lock);
 	spin_lock_init(&eth->dim_lock);
 
+	eth->rx_buf_len = MTK_MAX_RX_LENGTH_2K;
+
 	eth->rx_dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE;
 	INIT_WORK(&eth->rx_dim.work, mtk_dim_rx);
 	INIT_DELAYED_WORK(&eth->reset.monitor_work, mtk_hw_reset_monitor_work);
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
index 88a9b3b23b..738f42d220 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
@@ -28,7 +28,9 @@
 #define MTK_QDMA_NUM_QUEUES	16
 #define MTK_QDMA_PAGE_SIZE	2048
 #define MTK_MAX_RX_LENGTH	1536
+#define MTK_MAX_RX_LENGTH_UNIT	1024
 #define MTK_MAX_RX_LENGTH_2K	2048
+#define MTK_MAX_RX_LENGTH_9K	9216
 #define MTK_TX_DMA_BUF_LEN	0x3fff
 #define MTK_TX_DMA_BUF_LEN_V2	0xffff
 #define MTK_QDMA_RING_SIZE	2048
@@ -198,9 +200,10 @@
 #define MTK_MULTI_EN		BIT(10)
 #define MTK_PDMA_SIZE_8DWORDS	(1 << 4)
 
-/* PDMA Global Configuration Register */
+/* PDMA RX Configuration Register */
 #define MTK_PDMA_LRO_SDL	0x3000
 #define MTK_RX_CFG_SDL_OFFSET	16
+#define MTK_RX_CFG_SDL_MASK	GENMASK(31, MTK_RX_CFG_SDL_OFFSET)
 
 /* PDMA Reset Index Register */
 #define MTK_PST_DRX_IDX0	BIT(16)
@@ -451,6 +454,9 @@
 
 /* Mac control registers */
 #define MTK_MAC_MCR(x)		(0x10100 + (x * 0x100))
+#define MAC_MCR_MAX_RX_JUMBO_MASK	GENMASK(31, 28)
+#define MAC_MCR_MAX_RX_JUMBO(x)		\
+	FIELD_PREP(MAC_MCR_MAX_RX_JUMBO_MASK, (x))
 #define MAC_MCR_MAX_RX_MASK	GENMASK(25, 24)
 #define MAC_MCR_MAX_RX(_x)	(MAC_MCR_MAX_RX_MASK & ((_x) << 24))
 #define MAC_MCR_MAX_RX_1518	0x0
@@ -530,6 +536,8 @@
 /* XFI Mac control registers */
 #define MTK_XMAC_BASE(x)	(0x12000 + (((x) - 1) * 0x1000))
 #define MTK_XMAC_MCR(x)		(MTK_XMAC_BASE(x))
+#define MTK_XMAC_RX_CFG2(x)	(MTK_XMAC_MCR(x) + 0xd0)
+#define MTK_XMAC_MAX_RX_MASK	GENMASK(13, 0)
 #define XMAC_MCR_TRX_DISABLE	0xf
 #define XMAC_MCR_FORCE_TX_FC	BIT(5)
 #define XMAC_MCR_FORCE_RX_FC	BIT(4)
@@ -985,6 +993,7 @@ enum mkt_eth_capabilities {
 	MTK_INFRA_BIT,
 	MTK_SHARED_SGMII_BIT,
 	MTK_HWLRO_BIT,
+	MTK_NETSYS_RX_9K_BIT,
 	MTK_SHARED_INT_BIT,
 	MTK_TRGMII_MT7621_CLK_BIT,
 	MTK_QDMA_BIT,
@@ -1026,6 +1035,7 @@ enum mkt_eth_capabilities {
 #define MTK_INFRA		BIT_ULL(MTK_INFRA_BIT)
 #define MTK_SHARED_SGMII	BIT_ULL(MTK_SHARED_SGMII_BIT)
 #define MTK_HWLRO		BIT_ULL(MTK_HWLRO_BIT)
+#define MTK_NETSYS_RX_9K	BIT_ULL(MTK_NETSYS_RX_9K_BIT)
 #define MTK_SHARED_INT		BIT_ULL(MTK_SHARED_INT_BIT)
 #define MTK_TRGMII_MT7621_CLK	BIT_ULL(MTK_TRGMII_MT7621_CLK_BIT)
 #define MTK_QDMA		BIT_ULL(MTK_QDMA_BIT)
@@ -1127,7 +1137,7 @@ enum mkt_eth_capabilities {
 
 #define MT7988_CAPS  (MTK_36BIT_DMA | MTK_GDM1_ESW | MTK_GMAC2_2P5GPHY | \
 		      MTK_MUX_GMAC2_TO_2P5GPHY | MTK_QDMA | MTK_RSTCTRL_PPE1 | \
-		      MTK_RSTCTRL_PPE2 | MTK_SRAM)
+		      MTK_RSTCTRL_PPE2 | MTK_SRAM | MTK_NETSYS_RX_9K)
 
 struct mtk_tx_dma_desc_info {
 	dma_addr_t	addr;
@@ -1150,6 +1160,7 @@ struct mtk_reg_map {
 		u32	pcrx_ptr;	/* rx cpu pointer */
 		u32	glo_cfg;	/* global configuration */
 		u32	rst_idx;	/* reset index */
+		u32	rx_cfg;		/* rx dma configuration */
 		u32	delay_irq;	/* delay interrupt */
 		u32	irq_status;	/* interrupt status */
 		u32	irq_mask;	/* interrupt mask */
@@ -1314,6 +1325,7 @@ struct mtk_eth {
 	struct mtk_tx_ring		tx_ring;
 	struct mtk_rx_ring		rx_ring[MTK_MAX_RX_RING_NUM];
 	struct mtk_rx_ring		rx_ring_qdma;
+	u32				rx_buf_len;
 	struct napi_struct		tx_napi;
 	struct napi_struct		rx_napi;
 	void				*scratch_ring;
-- 
2.53.0


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

* [PATCH net-next v9 0/2] net: ethernet: mtk_eth_soc: 9K jumbo frame support
@ 2026-11-30 23:16 Sandeep Haemoon
  2026-11-30 23:16 ` [PATCH net-next v9 1/2] net: ethernet: mtk_eth_soc: skip page_pool Sandeep Haemoon
  2026-11-30 23:16 ` [PATCH net-next v9 2/2] net: ethernet: mtk_eth_soc: add 9K jumbo Sandeep Haemoon
  0 siblings, 2 replies; 3+ messages in thread
From: Sandeep Haemoon @ 2026-11-30 23:16 UTC (permalink / raw)
  To: netdev
  Cc: Felix Fietkau, Lorenzo Bianconi, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Matthias Brugger,
	AngeloGioacchino Del Regno, Russell King, Daniel Golle,
	Mason Chang, Frank Wunderlich, linux-mediatek, linux-arm-kernel,
	linux-kernel

This series makes the MediaTek SoC ethernet driver support 9K jumbo
frames on the 10G XGMII MACs (MT7988).  The driver advertises a
2030-byte max_mtu and programs the MAC max-rx field for at most 2048
bytes, so an MTU above 2030 is rejected and 9K frames are not usable.

The 36-bit DMA fix that was patch 1 of the previous revisions has been
split out and sent to net on its own, with Cc: stable and a field
Tested-by, after a report of real memory corruption on an MT7988 board
with 8 GiB of RAM.  It is not part of this series.

Patch 1 gates the page_pool on the ring's descriptor length: the pool
hands out order-0 pages and maps at most MTK_PP_MAX_BUF_SIZE, so a
ring whose descriptor length is larger has to use the
netdev_alloc_frag()/mtk_max_buf_alloc() path.

Patch 2 adds the MTK_NETSYS_RX_9K capability, advertises a 9194-byte
max_mtu on the XGMII MACs (from the DT phy_mode at probe, so DSA can
raise the conduit MTU before the netdev is opened), programs
XMAC_RX_CFG2 and the PDMA RX SDL, derives the shared RX buffer length
from the largest MTU (802.1Q headroom included) and sizes the RX rings
from it, keeping the never-polled QDMA ring at its 2K buffers.  The
MAC max-rx limits stay in sync with that shared length, including
GMAC1's MCR jumbo field.  A runtime MTU change that needs larger
buffers is rejected with -EBUSY while DMA is running; shrinking is
allowed.  GMAC1, the built-in switch port, keeps its MCR programming
(bucket plus the jumbo field in 1024-byte units), written after the
MAC_MCR_FORCE_LINK_DOWN reset so it survives every mac_config(); only
GMAC1 is given the jumbo length, and whether the internal switch path
decodes it is a hardware property the commit message documents.

This work is a forward-port of the MediaTek downstream jumbo work:
Mason Chang's "change default rx buffer length" and "add 9k jumbo
frame support" (MediaTek OpenWrt feed 999-eth-30/31, carried in
frank-w/BPI-Router-Linux), plus Frank Wunderlich's "try to fix crash
the right way".  The runtime reallocation of Mason's "dynamic rx
buffer adjustment" (feed 999-eth-33) is not included and will be sent
separately.  Attribution is prose plus Link: tags: Co-developed-by
requires the original authors' own Signed-off-by lines, which we do
not have, and the port diverges from the downstream implementation
(2K buffer floor, per-ring pool gate, the -EBUSY rule, the XDP checks
and the truesize fix are not in the downstream patches).

The equivalent change was tested on a BPI-R4 Pro 8X (MT7988, 10G
lan6 / MxL86252) on the 6.18.60 backport: with both ends at MTU 9000,
8K ICMP passes and iperf3 with MSS 8900 reaches ~9.87 Gbit/s (vs
~2.57 Gbit/s at MSS 1460); the DSA conduit (GMAC1, the internal switch
port) is raised to 9004 at boot, so that test exercised the MCR jumbo
path.
This series is compile-tested with CONFIG_NET_MEDIATEK_SOC=y and
COMPILE_TEST=y; no hardware run of this exact tree yet.

With the 1 KiB rounding the RX buffer length is order-1 (8 KiB) for
rx_buf_len 4096..7168 and order-2 (16 KiB) from rx_buf_len 8192 up;
at the 9K ring size the 16 KiB buffers pin about 32 MiB in the polled
ring while DMA is up (the 2K QDMA ring adds about 8 MiB) and make the
refill a high-order GFP_ATOMIC allocation.  That cost
is inherent to the downstream design; skb->truesize now reports the
allocation that was actually made.

Changes in v9 (the v8 AI review on the list, and the field report):

- the 36-bit DMA fix that was patch 1 of the previous revisions has
  been split out and sent to net on its own, with Cc: stable and the
  reporter's Tested-by, after a field report of silent memory
  corruption on an MT7988 board with more than 4 GiB.  This series is
  now two patches; the "1/3"/"3/3" references below describe the
  three-patch v8;
- the MCR jumbo field carries the jumbo length for GMAC1 only.  It is
  the encoding the MediaTek jumbo code uses on the GDM MACs; the
  MT7988A reference manual defines only 4'h2 for the field and marks
  the rest reserved, and the MT7988 downstream 9K patch does not raise
  it for GMAC1.  Only the internal switch port is given the jumbo
  length; the other GDM MACs are now kept at the documented 2 Kbytes
  encoding instead of inheriting another netdev's jumbo length;
- the all-MAC limit pass runs only while DMA is down, which is the only
  time the shared length can change; a shrink while another MAC is up
  keeps the buffers the rings already hold, so its limits still match,
  and skipping the pass keeps it from read-modify-writing that MAC's
  MCR under its phylink worker;
- mtk_set_mcr_max_rx() takes the interface as an argument and is
  re-applied at link-up for both register types, including GMAC1,
  which returns before the XMAC setup, so a mtk_mac_config() that
  failed before it updated mac->interface no longer leaves the MAC on
  the wrong register or at the reset limit;
- rx_errors now includes the CRC and length errors, as if_link.h
  requires, so the new over-long drops appear in the error totals; the
  commit message explains that the check is needed because build_skb()
  now covers the whole allocation with tailroom;
- the PDMA SDL write is described as the LRO free-buffer size the
  reference manual documents, a buffer size and not a DMA length, and
  the message says why it is kept although MT7988 does not use the LRO
  rings;
- the jumbo patch's message no longer claims both that the downstream
  driver programs the GMAC1 jumbo field and that it leaves GMAC1
  unlimited: it now states which encoding is reused, that the MT7988
  downstream patch does not raise the field, that PLEN0 protects the
  rings either way, and it names which MT7988 MACs get which limit
  register;
- it credits the downstream authors by reference and says why it
  carries no co-author tags;
- the cover's buffer-footprint figure is 32 MiB for the polled ring
  (plus about 8 MiB for the 2K QDMA ring), and "MTU above 2030"
  replaces the loose "MTU > 2K";
- the test note now says the 9.87 Gbit/s run went through the DSA
  conduit on GMAC1, i.e. the MCR jumbo path;
- the page_pool patch's subject already says "for RX rings whose
  buffers do not fit"; the review quoted only the folded first line of
  the header.

Changes in v8 (the v7 review and the published reference manual):

- the 2K floor is now applied before the 802.1Q headroom is added, so
  MTU 2027..2030 stays at 2K and neither the SGMII/2500base-x MACs on
  MT7988 nor a DSA user port at 2023..2026 fails a runtime change with
  -EBUSY.  A tagged maximum-size frame in that class is still subject
  to the historical 2K limit;
- MTU changes, mtk_dma_init() and mtk_hw_init() now program every MAC
  with the shared ring length instead of only the device being changed,
  so no MAC keeps a limit larger than the buffers after a shrink or a
  partial reopen.  MACs whose interface mode is not known yet are
  skipped and left to their own mac_config();
- the XMAC max-RX limit is written again after the XMAC logic reset that
  mtk_xgdm_mac_link_up() pulses: the published MT7988A reference manual
  gives RX_CFG2 a reset value of 0x800 (2048 bytes), so a reset would
  otherwise cap the MAC at 2K;
- the PDMA SDL write is now described from the MT7988A reference
  manual: ADMA_RX_CFG[31:16] is the "ADMA LRO free buffer SDL", a
  buffer capacity, not the RX frame-length limit; the mask is widened
  to the documented GENMASK(31, 16).  The write itself is unchanged and
  matches the vendor driver;
- the MCR jumbo field keeps the vendor encoding; the reference manual
  defines only 4'h2 (2 Kbytes) for it and marks the rest reserved, but
  the vendor driver programs the length and jumbo passes on its
  reference hardware;
- the commit messages now describe the over-long descriptor drop and the
  exported rx_length_errors update, the all-MAC limit pass and the
  link-up rewrite; the page_pool comment names mtk_max_buf_alloc() after
  the rename; the new buffer-size helper is not inline;
- 1/3 is retitled to "reset dma_addr for every RX descriptor";
- 2/3 no longer carries Simon Horman's Reviewed-by: the predicate it was
  given for changed in v3, before the tag was carried over.

Tested on a BPI-R4 Pro 8X (MT7988, 10G port) on a 6.18.60 backport:
8K ICMP passes and iperf3 with MSS 8900 at MTU 9000 reaches about
9.87 Gbit/s.  This series is compile-tested with
CONFIG_NET_MEDIATEK_SOC=y and COMPILE_TEST=y.

Changes in v7:

- respin reason: patchwork registered the v6 posting as superseded by the
  v5 posting that went out ten minutes before it, so the series that
  actually applies was hidden behind one that does not.  This repost
  restores a sane version order; the content below also folds in the v6
  review.
- only the SoCs with MTK_NETSYS_RX_9K grow the shared RX rings with the
  MTU.  Everywhere else the buffers stay at 2K, so the 2030-byte maximum
  those SoCs advertise keeps working at runtime and the -EBUSY rule no
  longer applies to them.
- the XDP admission checks now test the same descriptor length the
  page_pool gate uses, instead of the raw buffer length.
- mtk_get_stats64() adds the software rx_length_errors counter, so the
  new over-long descriptor drop is visible in the exported statistics.
- 2/3 names mtk_max_lro_buf_alloc(), the allocator that exists at that
  commit.
- 1/3 gives the commits in the right order and states that the change
  depends on the earlier SER fix it cites; the 3/3 message uses the
  real 32 MiB figure for the single polled ring.

Changes in v6:
- rebase onto current net-next (a76e8bf4be) so the series applies
  again: net-next converted mtk_rx_alloc() to kzalloc_objs(), which
  the hunk context depended on.  No functional change.

Changes in v5 (the v4 review, in full):

- 802.1Q headroom (Medium): the shared RX buffer length now includes
  VLAN_HLEN before the 1 KiB round-up, and the advertised max_mtu is
  lowered by the same four bytes to 9194, so a tagged maximum-size
  frame (9194 + 18 + 4) still fits in rx_buf_len 9216 and the XMAC
  9216 cap.  XMAC_RX_CFG2 and the ring buffers therefore cover a
  tagged frame at every MTU, including the maximum.
- GMAC1 MCR jumbo field (Medium): the vendor driver has a second MCR
  max-rx field we had not ported.  mtk_set_mcr_max_rx() now clears
  and programs the jumbo field (bits 31:28, 1024-byte units,
  MAC_MCR_MAX_RX_JUMBO) for GMAC1, so the driver can program the same
  shared length for the switch port as for the XGMII MACs.  The new
  field handling is limited to the MTK_NETSYS_RX_9K SoCs; every other
  SoC keeps its previous MCR programming bit for bit.
- QDMA ring sizing (Medium): the helpers now take the buffer length
  instead of struct mtk_eth, and mtk_rx_alloc() sizes the
  never-polled QDMA RX ring at the fixed 2K length instead of the
  jumbo length, so it no longer pins ~32 MiB of high-order pages.
  HW-LRO rings keep their 12288-byte sizing.
- pktlen bound (Medium): mtk_poll_rx() drops descriptors whose PLEN0
  exceeds ring->buf_size, with rx_length_errors, before the buffer
  can be passed up, so the larger build_skb() size can no longer hand
  stale memory to the stack if the engine over-reports the length.
- PDMA SDL encoding (Medium): kept as in v4; the comment and commit
  message now say explicitly that the GENMASK(30,16) encoding (frame
  length offset by MTK_PDMA_LRO_SDL) is the vendor's and not publicly
  documented, and that a datasheet confirmation would be welcome.
- XDP detach (Medium): the pool-size check now runs only when a
  program is attached, so a detach always succeeds.  The shared
  eth->prog weakness the review also points out is pre-existing and
  is left to a separate fix.
- 3/3 message (Low): the buffer-size math is corrected (order-1 for
  rx_buf_len 4096..7168, order-2 from 8192) and the message now says
  that the build_skb()/truesize change also covers the HW-LRO rings
  on mt2701, mt7622, mt7623 and mt7629.
- 1/3 subject and message (Low): retitled to describe the fix ("fix
  the RX descriptor address on the release path") and the message now
  cites the commit that introduced the release-path check and the one
  that later changed it, and states the fix's dependency on the latter.

The pre-existing High finding of the review (a failure while filling
an RX ring leaks the partially filled buffers and DMA mappings
because ring->dma_size is still 0) is not part of this series: it is
in the untouched upstream code and will be sent as a separate fix that
sets ring->dma_size before the fill loop.

Simon Horman's Reviewed-by is kept on patch 2 only: patches 1 and 3
are new or changed materially since his review of v1.

Previous versions:
https://lore.kernel.org/all/patch-7d2c457e68de6b53b7348d1bdbeadcec@loljews.com/ (v7)
https://lore.kernel.org/all/patch-9e765e74d06edbba3fd85a0cd49c4bb5@loljews.com/ (v6)
https://lore.kernel.org/all/patch-f1e62a87eb0f914e1ea52a395f465998@loljews.com/ (v5)
https://lore.kernel.org/all/patch-fc08a7ef40667bf3017366e452e6d3c0@loljews.com/ (v4)
https://lore.kernel.org/all/patch-aad4cfa8d9522d1f7dbc9893ea12e813@loljews.com/ (v3)
https://lore.kernel.org/all/patch-2793186c653124c4c0b3d463bde2ea3a@loljews.com/ (v2)
https://lore.kernel.org/all/patch-4f863a941889f0bceca1c082f2d79624@loljews.com/ (v1)

Sandeep Haemoon (2):
  net: ethernet: mtk_eth_soc: skip page_pool for RX rings whose buffers
    do not fit
  net: ethernet: mtk_eth_soc: add 9K jumbo frame support

 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 441 +++++++++++++++++---
 drivers/net/ethernet/mediatek/mtk_eth_soc.h |  16 +-
 2 files changed, 398 insertions(+), 59 deletions(-)

base-commit: a76e8bf4be552eed20801186188e5606365870a0
-- 
2.53.0


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

* [PATCH net-next v9 1/2] net: ethernet: mtk_eth_soc: skip page_pool
  2026-11-30 23:16 [PATCH net-next v9 0/2] net: ethernet: mtk_eth_soc: 9K jumbo frame support Sandeep Haemoon
@ 2026-11-30 23:16 ` Sandeep Haemoon
  2026-11-30 23:16 ` [PATCH net-next v9 2/2] net: ethernet: mtk_eth_soc: add 9K jumbo Sandeep Haemoon
  1 sibling, 0 replies; 3+ messages in thread
From: Sandeep Haemoon @ 2026-11-30 23:16 UTC (permalink / raw)
  To: netdev
  Cc: Felix Fietkau, Lorenzo Bianconi, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Matthias Brugger,
	AngeloGioacchino Del Regno, Russell King, Daniel Golle,
	Mason Chang, Frank Wunderlich, linux-mediatek, linux-arm-kernel,
	linux-kernel

The page_pool is created with order-0 pages and MTK_PP_MAX_BUF_SIZE as
the maximum DMA length, so it can only back a ring whose descriptor
length fits in that.

Gate the pool on ring->buf_size <= MTK_PP_MAX_BUF_SIZE and let larger
rings use the netdev_alloc_frag()/mtk_max_lro_buf_alloc() path that already
exists.  ring->frag_size cannot serve as the limit: it follows the
netdev_alloc_frag() layout, whose headroom and skb_shared_info footprint
differ from the pool's, so a ring can have frag_size <= PAGE_SIZE while
its descriptor length is already larger than the pool can map.

With the current MTU limits every ring fits and the gate always passes;
it becomes active with the 9K jumbo support that follows, when the
shared rings grow past the limit.

Link: https://github.com/mediatek/mtk-openwrt-feeds
Signed-off-by: Sandeep Haemoon <sandeeph@loljews.com>
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 21abeccfe0..cb05a8e43e 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -2818,7 +2818,13 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag)
 	if (!ring->data)
 		return -ENOMEM;
 
-	if (mtk_page_pool_enabled(eth)) {
+	/* A page_pool hands out order-0 pages and is created with
+	 * MTK_PP_MAX_BUF_SIZE, so it can only back a ring whose descriptor
+	 * length fits.  Larger rings use the netdev_alloc_frag()/
+	 * mtk_max_lro_buf_alloc() path below instead.
+	 */
+	if (mtk_page_pool_enabled(eth) &&
+	    ring->buf_size <= MTK_PP_MAX_BUF_SIZE) {
 		struct page_pool *pp;
 
 		pp = mtk_create_page_pool(eth, &ring->xdp_q, ring_no,
-- 
2.53.0


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

end of thread, other threads:[~2026-11-30 23:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 23:16 [PATCH net-next v9 0/2] net: ethernet: mtk_eth_soc: 9K jumbo frame support Sandeep Haemoon
2026-11-30 23:16 ` [PATCH net-next v9 1/2] net: ethernet: mtk_eth_soc: skip page_pool Sandeep Haemoon
2026-11-30 23:16 ` [PATCH net-next v9 2/2] net: ethernet: mtk_eth_soc: add 9K jumbo Sandeep Haemoon

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®