Skip to contentSkip to conversation

net: ethernet: mtk_wed: misc fixes

PATCH Applied Zhi-Jun You 3 participants 8 messages Oct 26 – Oct 30

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

v6 cover net: ethernet: mtk_wed: misc fixes

Ths patch series includes some fixes for issues that were discovered by Sashiko and one original patch fixing issue I encountered.

Patch 1,2,3 fix issues that were found by Sashiko. Patch 1 was compiled test only.
Patch 2,3,4 were tested on a mt7986.

Patch 1 fixes tx wdma ring reset for WED v3. Patch 2 fixes the reset condition for rx wdma. Patch 3 fixes rx ring and tx wdma ring not being freed up Patch 4 fixes WED on non-DBDC mt7986.

---
Changes in v6:
- Update cover letter to address the platform that the patches were tested on.
- Update message of patch 2 to clarify what's the issue.
- Update patch 3 to rely on ring descriptor instead of an extra flag.
- Squashed patch 5 into patch 4.
- Lin to v5: https://lore.kernel.org/all/[email protected]/

Changes in v5:
- Add cover letter.
- Add patch 3 to address Sashiko review on rx ring and tx wdma ring not
being freed up.
- Add patch 5 to address Sashiko review on error handling.
- Link to review: https://lore.kernel.org/all/[email protected]/

Changes in v4:
- Add patch 2 to address Sashiko review on rx wdma reset condition.
- Link to review: https://lore.kernel.org/all/[email protected]/

Changes in v3:
- Add patch 1 to address Sashiko review on WED v3 tx wdma ring reset.
- Link to review: https://lore.kernel.org/netdev/[email protected]/

Changes in v2:
- Address issues raisied by Sashiko in patch 4
- Link to review: https://lore.kernel.org/all/[email protected]/
- Add comment to explain the special case
- Link to v1: https://lore.kernel.org/all/[email protected]/
---

To: Felix Fietkau <[email protected]>
To: Lorenzo Bianconi <[email protected]>
To: Andrew Lunn <[email protected]>
To: "David S. Miller" <[email protected]>
To: Eric Dumazet <[email protected]>
To: Jakub Kicinski <[email protected]>
To: Paolo Abeni <[email protected]>
To: Matthias Brugger <[email protected]>
To: AngeloGioacchino Del Regno <[email protected]>
To: Sujuan Chen <[email protected]>
To: Rex Lu <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
Zhi-Jun You (4):
net: ethernet: mtk_wed: skip ring reset in wdma_tx_ring_setup for WED v3
net: ethernet: mtk_wed: fix reset condition for rx wdma
net: ethernet: mtk_wed: free up rings during detach
net: ethernet: mtk_wed: setup WDMA_RING_TX(0) for non-DBDC MT7986

 drivers/net/ethernet/mediatek/mtk_wed.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

---
base-commit: 7076f684d5132e6a6145e1da2fa74771ecd052e5
change-id: 20261018-wedfix-a60905150472

Best regards,

Signature · 1 line
Zhi-Jun You <[email protected]>
#1 lore raw

PATCH v6 1/4 net: ethernet: mtk_wed: skip ring reset in wdma_tx_ring_setup for WED v3

Currently WED v3 tx wdma ring, ring reset happens in a separate code block unconditionally.

Moreover, v3 has double the size of wdma_desc and has different init values. mtk_wed_ring_reset doens't deal with that and would corrupt the wdma_desc.

Fix this by skipping mtk_wed_ring_reset in mtk_wdma_tx_ring_setup for WED v3.

Fixes e2f64db13aa1 ("net: ethernet: mtk_wed: introduce WED support for MT7988")
---
 drivers/net/ethernet/mediatek/mtk_wed.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mediatek/mtk_wed.c +1 -1
index 53d3b7e00e1c..d55042ccaff1 100644
@@ -1938,7 +1938,7 @@ mtk_wed_wdma_tx_ring_setup(struct mtk_wed_device *dev, int idx, int size,
 	wdma_w32(dev, MTK_WDMA_RING_TX(idx) + MTK_WED_RING_OFS_CPU_IDX, 0);
 	wdma_w32(dev, MTK_WDMA_RING_TX(idx) + MTK_WED_RING_OFS_DMA_IDX, 0);
 
-	if (reset)
+	if (!mtk_wed_is_v3_or_greater(dev->hw) && reset)
 		mtk_wed_ring_reset(wdma, MTK_WED_WDMA_RING_SIZE, true);
 
 	if (!idx)  {
Signature · 1 line
2.55.0
#2 lore raw

PATCH v6 2/4 net: ethernet: mtk_wed: fix reset condition for rx wdma

In reply to Zhi-Jun You

In mtk_wdma_rx_reset, currently only resets the CPU index of the rings that doesn't have a descriptor. This is wrong because no descriptor means the ring is not configured.

Also mtk_wed_start makes sure that all rx_wdma rings are set up this would lead to no ring getting their CPU index reset.

Fix this by inverting the reset condition so allocated rings will be reset.

Fixes 4c5de09eb0d0 ("net: ethernet: mtk_wed: add configure wed wo support")
---
 drivers/net/ethernet/mediatek/mtk_wed.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mediatek/mtk_wed.c +1 -1
index d55042ccaff1..3f0be70c3f14 100644
@@ -257,7 +257,7 @@ mtk_wdma_rx_reset(struct mtk_wed_device *dev)
 	wdma_w32(dev, MTK_WDMA_RESET_IDX, 0);
 
 	for (i = 0; i < ARRAY_SIZE(dev->rx_wdma); i++) {
-		if (dev->rx_wdma[i].desc)
+		if (!dev->rx_wdma[i].desc)
 			continue;
 
 		wdma_w32(dev,
Signature · 1 line
2.55.0
#3 lore raw

PATCH v6 3/4 net: ethernet: mtk_wed: free up rings during detach

In reply to Zhi-Jun You

During __mtk_wed_detach, rx_ring and tx_wdma aren't freed up.

Fix this by add them to mtk_wed_free_rx_rings.

This patch is pulled from mtk-openwrt-feeds to address Sashiko's review and edit to rely on ring->desc instead of an extra flag.

---
 drivers/net/ethernet/mediatek/mtk_wed.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/net/ethernet/mediatek/mtk_wed.c +8 -0
index 3f0be70c3f14..3044a7a8ea03 100644
@@ -949,6 +949,14 @@ mtk_wed_free_ring(struct mtk_wed_device *dev, struct mtk_wed_ring *ring)
 static void
 mtk_wed_free_rx_rings(struct mtk_wed_device *dev)
 {
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(dev->rx_ring); i++)
+		mtk_wed_free_ring(dev, &dev->rx_ring[i]);
+
+	for (i = 0; i < ARRAY_SIZE(dev->tx_wdma); i++)
+		mtk_wed_free_ring(dev, &dev->tx_wdma[i]);
+
 	mtk_wed_free_rx_buffer(dev);
 	mtk_wed_free_ring(dev, &dev->rro.ring);
 }
Signature · 1 line
2.55.0
#4 lore raw

Re: [PATCH net v6 3/4] net: ethernet: mtk_wed: free up rings during detach

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] After this patch, mtk_wed_free_rx_rings() (drivers/net/ethernet/mediatek/mtk_wed.c:954-958) calls…

--

net: ethernet: mtk_wed: free up rings during detach

This commit makes mtk_wed_free_rx_rings() also free the rx_ring[] and tx_wdma[] descriptor rings. Before this, __mtk_wed_detach() leaked them. The change comes from mtk-openwrt-feeds and was modified to check ring->desc instead of an extra flag.

Quoted 5 lines
drivers/net/ethernet/mediatek/mtk_wed.c +0 -0
index 3f0be70c3f145..3044a7a8ea03e 100644

drivers/net/ethernet/mediatek/mtk_wed.c mtk_wed_free_ring(struct mtk_wed_device *dev, struct mtk_wed_ring *ring) · line 958

Quoted 10 lines
drivers/net/ethernet/mediatek/mtk_wed.c +7 -0
@@ -949,6 +949,14 @@ mtk_wed_free_ring(struct mtk_wed_device *dev, struct mtk_wed_ring *ring)
 static void
 mtk_wed_free_rx_rings(struct mtk_wed_device *dev)
 {
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(dev->rx_ring); i++)
+		mtk_wed_free_ring(dev, &dev->rx_ring[i]);
+
+	for (i = 0; i < ARRAY_SIZE(dev->tx_wdma); i++)
+		mtk_wed_free_ring(dev, &dev->tx_wdma[i]);

[Severity: Low]
Could the WDMA engine still be writing to the tx_wdma[] descriptors when they are freed here?

In __mtk_wed_detach(), these rings are freed right after mtk_wed_wo_reset(), which returns void:

__mtk_wed_detach()

    mtk_wed_wo_reset(dev);
        mtk_wdma_tx_reset(dev);
    mtk_wed_free_rx_rings(dev);
        dma_free_coherent(..., tx_wdma[i].desc, ...)

If the TX_DMA_BUSY poll in mtk_wdma_tx_reset() times out, the timeout is only logged:

mtk_wdma_tx_reset() {
    ...
	wdma_clr(dev, MTK_WDMA_GLO_CFG, MTK_WDMA_GLO_CFG_TX_DMA_EN);
	if (readx_poll_timeout(mtk_wdma_read_reset, dev, status,
			       !(status & mask), 0, 10000))
		dev_err(dev->hw->dev, "tx reset failed\n");
    ...
	for (i = 0; i < ARRAY_SIZE(dev->tx_wdma); i++)
		wdma_w32(dev,
			 MTK_WDMA_RING_TX(i) + MTK_WED_RING_OFS_CPU_IDX, 0);
}

mtk_wdma_v3_tx_reset() handles timeouts in its prefetch and writeback BUSY polls the same way.

Only the CPU_IDX registers are cleared. The MTK_WDMA_RING_TX(i) BASE registers and the WED WDMA_RING_TX BASE registers still point at desc_phys.

If the engine has not gone idle, can a late descriptor fetch or writeback land in coherent memory that has already gone back to the allocator? Before this patch the rings were leaked, so such a write could only reach memory that nothing else was using.

This depends on a hardware timeout, and I could not confirm from the code that a late writeback really happens. TX_DMA_EN has already been cleared in mtk_wed_dma_disable(), and MTK_WED_RESET_WED has been asserted.

The same function already frees rx_wdma[] in mtk_wed_free_tx_rings() right after mtk_wdma_rx_reset(), whose -ETIMEDOUT return is ignored, so this follows an existing pattern in the driver. Would it be worth either skipping the free on a reset timeout or clearing the ring BASE registers before freeing?

Quoted 4 lines
drivers/net/ethernet/mediatek/mtk_wed.c +1 -0
+
 	mtk_wed_free_rx_buffer(dev);
 	mtk_wed_free_ring(dev, &dev->rro.ring);
 }
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261026-wedfix-v6-0-a52f6b15d2fc%40gmail.com
#5 lore raw

PATCH v6 4/4 net: ethernet: mtk_wed: setup WDMA_RING_TX(0) for non-DBDC MT7986

In reply to Zhi-Jun You

WDMA_RING_TX(0) is required to set MTK_WED_WDMA_RING_TX for WED RX but on a non-DBDC MT7986 it is never setup because idx is 1.

Setting MTK_WED_WDMA_RING_TX with WDMA_RING_TX(1) is not feasible because WED still tries to send through WDMA_RING_TX(0). This is verified with register dump.

Fix this by calling mtk_wed_wdma_tx_ring_setup if wed is v2 and rx_ring[0] is not allocated and reset tx_wdma[0] if it's already allocated also add error messages and bail when mtk_wed_start fails.

Fixes 4c5de09eb0d0 ("net: ethernet: mtk_wed: add configure wed wo support")
---
 drivers/net/ethernet/mediatek/mtk_wed.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/net/ethernet/mediatek/mtk_wed.c +14 -1
index 3044a7a8ea03..f40ac5794341 100644
@@ -2345,7 +2345,20 @@ mtk_wed_start(struct mtk_wed_device *dev, u32 irq_mask)
 
 	for (i = 0; i < ARRAY_SIZE(dev->rx_wdma); i++)
 		if (!dev->rx_wdma[i].desc)
-			mtk_wed_wdma_rx_ring_setup(dev, i, 16, false);
+			if (mtk_wed_wdma_rx_ring_setup(dev, i, 16, false)) {
+				dev_err(dev->hw->dev, "wdma rx ring %d setup failed\n", i);
+				return;
+			}
+
+	/*
+	 * non-DBDC MT7986 allocates only rx_ring[1] and tx_wdma[1] during setup
+	 * but tx_wdma[0] is also needed for WED to function.
+	 */
+	if (mtk_wed_is_v2(dev->hw) && !dev->rx_ring[0].desc)
+		if (mtk_wed_wdma_tx_ring_setup(dev, 0, MTK_WED_WDMA_RING_SIZE, !!dev->tx_wdma[0].desc)) {
+			dev_err(dev->hw->dev, "wdma tx ring 0 setup failed\n");
+			return;
+		}
 
 	if (dev->wlan.hw_rro) {
 		for (i = 0; i < MTK_WED_RX_PAGE_QUEUES; i++) {
Signature · 1 line
2.55.0
#6 lore raw

Re: [PATCH net v6 4/4] net: ethernet: mtk_wed: setup WDMA_RING_TX(0) for non-DBDC MT7986

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The patch adds two early returns to mtk_wed_start() in drivers/net/ethernet/mediatek/mtk_wed.c.

--

net: ethernet: mtk_wed: setup WDMA_RING_TX(0) for non-DBDC MT7986

On v2 WED hardware where rx_ring[0] is not allocated (non-DBDC MT7986), this patch makes mtk_wed_start() program WDMA_RING_TX(0), because WED RX still sends through that ring. It also adds error messages and early returns for when the WDMA RX or TX ring setup fails.

Quoted 13 lines
drivers/net/ethernet/mediatek/mtk_wed.c +4 -1
index 3044a7a8ea03e..f40ac5794341c 100644
@@ -2345,7 +2345,20 @@ mtk_wed_start(struct mtk_wed_device *dev, u32 irq_mask)
 
 	for (i = 0; i < ARRAY_SIZE(dev->rx_wdma); i++)
 		if (!dev->rx_wdma[i].desc)
-			mtk_wed_wdma_rx_ring_setup(dev, i, 16, false);
+			if (mtk_wed_wdma_rx_ring_setup(dev, i, 16, false)) {
+				dev_err(dev->hw->dev, "wdma rx ring %d setup failed\n", i);
+				return;
+			}

drivers/net/ethernet/mediatek/mtk_wed.c mtk_wed_start(struct mtk_wed_device *dev, u32 irq_mask) · line 2361

Quoted 10 lines
drivers/net/ethernet/mediatek/mtk_wed.c +10 -0
+
+	/*
+	 * non-DBDC MT7986 allocates only rx_ring[1] and tx_wdma[1] during setup
+	 * but tx_wdma[0] is also needed for WED to function.
+	 */
+	if (mtk_wed_is_v2(dev->hw) && !dev->rx_ring[0].desc)
+		if (mtk_wed_wdma_tx_ring_setup(dev, 0, MTK_WED_WDMA_RING_SIZE, !!dev->tx_wdma[0].desc)) {
+			dev_err(dev->hw->dev, "wdma tx ring 0 setup failed\n");
+			return;
+		}

[Severity: Medium]
Can these early returns leave WED half-configured without the caller noticing?

mtk_wed_start() is static void, and the ops callback is void (*start)(struct mtk_wed_device *dev, u32 irq_mask), so the error goes no further than this function.

Both returns happen after mtk_wed_rx_buffer_alloc() has succeeded, and maybe after some WDMA_RING_RX(i) and MTK_WED_WDMA_RING_RX(i) registers have been written. They then skip mtk_wed_hw_init(), mtk_wed_configure_irq(), mtk_wed_set_ext_int(), mtk_wed_dma_enable() and dev->running = true.

In mt76, mt7915_dma_start() has already written the WED IRQ mask to MT_INT_MASK_CSR or MT_INT_WED_MASK_CSR. It then continues as if WED were running:

drivers/net/wireless/mediatek/mt76/mt7915/dma.c:mt7915_dma_start() {
    ...
		mtk_wed_device_start(&dev->mt76.mmio.wed, wed_irq_mask);
	}

	irq_mask = reset ? MT_INT_MCU_CMD : irq_mask;

	mt7915_irq_enable(dev, irq_mask);
	mt7915_irq_disable(dev, 0);

	return 0;
}

mtk_wed_device_active() is just !!(_dev)->ops. So the WLAN driver keeps sending traffic and IRQ handling through a WED whose DMA was never enabled, and the only sign is the dev_err in the log. mt7996 calls mtk_wed_device_start() the same way.

The rx_wdma change also alters behavior that is unrelated to the WDMA_RING_TX(0) fix. Before this patch, a failed rx_wdma allocation left only that one WDMA RX ring unprogrammed, and WED still started. Now one dma_alloc_coherent() failure in mtk_wed_ring_alloc() stops the whole WED datapath from being enabled.

This can only happen on the first start under allocation failure. SER restarts reuse the rings that were already allocated.

The commit message says "add error messages and bail when mtk_wed_start fails". It does not mention that callers cannot see the bail, or that no state is rolled back.

Would it be better to propagate the error? For example, the start op could return int and the mt7915/mt7996 dma_start paths could handle the failure. Another option is to fall back to non-WED operation.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261026-wedfix-v6-0-a52f6b15d2fc%40gmail.com
#7 lore raw
In reply to Zhi-Jun You
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Mon, 26 Oct 2026 17:57:27 +0800 you wrote:

Ths patch series includes some fixes for issues that were discovered by Sashiko and one original patch fixing issue I encountered.

Patch 1,2,3 fix issues that were found by Sashiko. Patch 1 was compiled test only.
Patch 2,3,4 were tested on a mt7986.

[...]

Here is the summary with links:
- [net,v6,1/4] net: ethernet: mtk_wed: skip ring reset in wdma_tx_ring_setup for WED v3

    https://git.kernel.org/netdev/net/c/cb50f16f37fc
  - [net,v6,2/4] net: ethernet: mtk_wed: fix reset condition for rx wdma
    https://git.kernel.org/netdev/net/c/7180a42d8e61
  - [net,v6,3/4] net: ethernet: mtk_wed: free up rings during detach
    https://git.kernel.org/netdev/net/c/5b8d12512cbd
  - [net,v6,4/4] net: ethernet: mtk_wed: setup WDMA_RING_TX(0) for non-DBDC MT7986
    https://git.kernel.org/netdev/net/c/dd6efae55291

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html