Skip to content

net: ethernet: mtk_eth_soc: 9K jumbo frame support

Sandeep Haemoon linux-arm-kernel linux-mediatek lkml netdev 9 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v9 Latest2 patches 1 replyIn review
  2. v83 patches 0 repliesSuperseded
  3. v73 patches 5 repliesSuperseded
Earlier versions · 6
VersionPostedPatchesRepliesStatus
v63 patches1 replySuperseded
v53 patches0 repliesSuperseded
v43 patches1 replySuperseded
v32 patches0 repliesSuperseded
v22 patches1 replySuperseded
v12 patches3 repliesSuperseded

Changes in v9 from the cover letter

- 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.

Patches in v9 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2net: ethernet: mtk_eth_soc: skip page_pooldrivers/net/ethernet/mediatek/mtk_eth_soc.c+7 -10 replies
2/2net: ethernet: mtk_eth_soc: add 9K jumbodrivers/net/ethernet/mediatek/mtk_eth_soc.c drivers/net/ethernet/mediatek/mtk_eth_soc.h+392 -590 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v9 yet.

Read the v9 thread

Cover letter [PATCH net-next v9 0/2] net: ethernet: mtk_eth_soc: 9K jumbo frame support

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/[email protected]/ (v7)
https://lore.kernel.org/all/[email protected]/ (v6)
https://lore.kernel.org/all/[email protected]/ (v5)
https://lore.kernel.org/all/[email protected]/ (v4)
https://lore.kernel.org/all/[email protected]/ (v3)
https://lore.kernel.org/all/[email protected]/ (v2)
https://lore.kernel.org/all/[email protected]/ (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

Signature · 1 line
2.53.0