net: ethernet: mtk_wed: skip ring reset in wdma_tx_ring_setup for WED v3
Subsystems (4)
PATCH v3 1/2 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.
---
Changes in v3:
- new patch addressing WED v3 ring reset issue raised by Sashiko
- Link to the review: https://lore.kernel.org/netdev/[email protected]/
--- drivers/net/ethernet/mediatek/mtk_wed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mediatek/mtk_wed.c +1 -1
@@ -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.47.3
PATCH v3 2/2 net:ethernet: mtk_wed: setup WDMA_RING_TX(0) for non-DBDC MT7986
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.
---
Changes in v3:
- no change
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Address warm reset concern raised by AI review.
- Return value concern is skipped until further comment from reviewers.
- Added a comment to explain this special case.
- Link to v1: https://lore.kernel.org/r/[email protected]
--- drivers/net/ethernet/mediatek/mtk_wed.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/net/ethernet/mediatek/mtk_wed.c +7 -0
@@ -2334,6 +2334,13 @@ mtk_wed_start(struct mtk_wed_device *dev, u32 irq_mask)if (!dev->rx_wdma[i].desc)mtk_wed_wdma_rx_ring_setup (dev, i,16 , false); +/* +* 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) +mtk_wed_wdma_tx_ring_setup (dev,0 ,MTK_WED_WDMA_RING_SIZE , !!dev->tx_wdma[0 ].desc); +if (dev->wlan.hw_rro) {for (i =0 ; i <MTK_WED_RX_PAGE_QUEUES ; i++) { u32 addr = MTK_WED_RRO_MSDU_PG_CTRL0(i) +
Signature · 1 line
2.47.3
Paolo Abeni
maintainerRe: [PATCH net v3 2/2] net:ethernet: mtk_wed: setup WDMA_RING_TX(0) for non-DBDC MT7986
From: AI Reviewer <[email protected]>
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
Full review at: https://sashiko.dev/
---
--- Patch [2]: [PATCH net v3 2/2] net:ethernet: mtk_wed: setup WDMA_RING_TX(0) for non-DBDC MT7986 --- commit 30cd2d1bc8bf876e5d201d631684431920a3f165
Author: Zhi-Jun You <[email protected]>
net:ethernet: mtk_wed: setup WDMA_RING_TX(0) for non-DBDC MT7986
This commit fixes an issue on non-DBDC MT7986 where WDMA_RING_TX(0) is never set up because idx is 1, even though it is required for WED RX to function. It addresses this by explicitly calling mtk_wed_wdma_tx_ring_setup if the WED version is v2 and rx_ring[0] is unallocated.
Quoted 3 lines
drivers/net/ethernet/mediatek/mtk_wed.c +0
-0
[ ... ]
drivers/net/ethernet/mediatek/mtk_wed.c mtk_wed_start(struct mtk_wed_device *dev, u32 irq_mask) · line 2335
Quoted 3 lines
drivers/net/ethernet/mediatek/mtk_wed.c +0
-0@@ -2334,6 +2334,13 @@ mtk_wed_start(struct mtk_wed_device *dev, u32 irq_mask)if (!dev->rx_wdma[i].desc)mtk_wed_wdma_rx_ring_setup (dev, i,16 , false);
[Severity: High]
This is a pre-existing issue, but does this code ignore the return value from mtk_wed_wdma_rx_ring_setup()?
If mtk_wed_ring_alloc() fails due to memory pressure, it returns an error without configuring the hardware base registers. Because the error is ignored, when DMA is later enabled in mtk_wed_start(), could the hardware attempt to fetch from unmapped physical addresses and cause an IOMMU fault?
drivers/net/ethernet/mediatek/mtk_wed.c mtk_wed_start(struct mtk_wed_device *dev, u32 irq_mask) · line 2342
Quoted 7 lines
drivers/net/ethernet/mediatek/mtk_wed.c +6
-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) +mtk_wed_wdma_tx_ring_setup (dev,0 ,MTK_WED_WDMA_RING_SIZE , !!dev->tx_wdma[0 ].desc);
[Severity: High]
Does this new call to mtk_wed_wdma_tx_ring_setup() also need to check its return value?
Similar to the RX ring above, if mtk_wed_ring_alloc() fails to allocate memory, the hardware base registers won't be configured. Since the caller proceeds to enable hardware DMA regardless, might this lead to the WED processing descriptors from unmapped memory and causing memory corruption or a system crash?
Quoted 3 lines
drivers/net/ethernet/mediatek/mtk_wed.c +1
-0+if (dev->wlan.hw_rro) {for (i =0 ; i <MTK_WED_RX_PAGE_QUEUES ; i++) {
Signature · 1 line
This is an AI-generated review.
Quoted 9 lines · Zhi-Jun You
Currently WED v3 tx wdma ring, ring reset happens in a separate code block unconditionally.
Moreover, v3 has double the size of
wdma_descand has different init values.mtk_wed_ring_resetdoens't deal with that and would corrupt thewdma_desc.Fix this by skipping
mtk_wed_ring_resetinmtk_wdma_tx_ring_setupfor WED v3.
Commenting on Sashiko's report:
https://sashiko.dev/#/patchset/20260724172040.1653-1-hujy652%40gmail.com
Quoted 16 lines
Fixes e2f64db13aa1 ("net: ethernet: mtk_wed: introduce WED support for MT7988")Signed-off-by Zhi-Jun You <[email protected]>---
Changes in v3:
- new patch addressing WED v3 ring reset issue raised by Sashiko
- Link to the review: https://lore.kernel.org/netdev/[email protected]/--- drivers/net/ethernet/mediatek/mtk_wed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ethernet/mediatek/mtk_wed.c +0
-0
drivers/net/ethernet/mediatek/mtk_wed.c mtk_wed_wdma_tx_ring_setup(struct mtk_wed_device *dev, int idx, int size, · line 1944
Quoted 8 lines
drivers/net/ethernet/mediatek/mtk_wed.c +1
-1@@ -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) {
-This is a pre-existing issue, but while reviewing the WDMA ring reset logic,
I noticed what looks like reversed logic in mtk_wdma_rx_reset():
drivers/net/ethernet/mediatek/mtk_wed.c:mtk_wdma_rx_reset() {
...
for (i = 0; i < ARRAY_SIZE(dev->rx_wdma); i++) {
if (dev->rx_wdma[i].desc)
continue;
wdma_w32(dev,
MTK_WDMA_RING_RX(i) + MTK_WED_RING_OFS_CPU_IDX, 0);
}
...
}
Does the if (dev->rx_wdma[i].desc) continue; check skip the CPU_IDX reset for active rings?
When a WDMA RX reset occurs (e.g., during recovery from a hang), the hardware index is reset to 0, but the CPU_IDX register won't be reset for active rings since they have a non-NULL desc.
Could this desynchronize the driver and hardware, leading to a permanent stall of the WDMA RX rings and network traffic failure?
- ACK I will add a patch addressing this.
Best regards,
Zhi-Jun
Quoted 3 lines
Signature · 1 line
2.47.3
Re: [PATCH net v3 2/2] net:ethernet: mtk_wed: setup WDMA_RING_TX(0) for non-DBDC MT7986
In reply to Paolo AbeniQuoted 49 lines · Paolo Abeni
From: AI Reviewer <[email protected]>
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
Full review at: https://sashiko.dev/
---
--- Patch [2]: [PATCH net v3 2/2] net:ethernet:mtk_wed: setupWDMA_RING_TX(0)for non-DBDC MT7986 --- commit30cd2d1bc8bf876e5d201d631684431920a3f165
Author: Zhi-Jun You <[email protected]>net:ethernet:
mtk_wed: setupWDMA_RING_TX(0)for non-DBDC MT7986This commit fixes an issue on non-DBDC MT7986 where
WDMA_RING_TX(0)is never set up because idx is 1, even though it is required for WED RX to function. It addresses this by explicitly callingmtk_wed_wdma_tx_ring_setupif the WED version is v2 and rx_ring[0] is unallocated.Quoted 3 lines
drivers/net/ethernet/mediatek/mtk_wed.c +0
-0[ ... ]
drivers/net/ethernet/mediatek/mtk_wed.c mtk_wed_start(struct mtk_wed_device *dev, u32 irq_mask) · line 2335
Quoted 3 lines
drivers/net/ethernet/mediatek/mtk_wed.c +0
-0@@ -2334,6 +2334,13 @@ mtk_wed_start(struct mtk_wed_device *dev, u32 irq_mask)if (!dev->rx_wdma[i].desc)mtk_wed_wdma_rx_ring_setup (dev, i,16 , false);[Severity: High]
This is a pre-existing issue, but does this code ignore the return value frommtk_wed_wdma_rx_ring_setup()?If
mtk_wed_ring_alloc()fails due to memory pressure, it returns an error without configuring the hardware base registers. Because the error is ignored, when DMA is later enabled inmtk_wed_start(), could the hardware attempt to fetch from unmapped physical addresses and cause an IOMMU fault?drivers/net/ethernet/mediatek/mtk_wed.c mtk_wed_start(struct mtk_wed_device *dev, u32 irq_mask) · line 2342
Quoted 7 lines
drivers/net/ethernet/mediatek/mtk_wed.c +6
-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) +mtk_wed_wdma_tx_ring_setup (dev,0 ,MTK_WED_WDMA_RING_SIZE , !!dev->tx_wdma[0 ].desc);[Severity: High]
Does this new call tomtk_wed_wdma_tx_ring_setup()also need to check its return value?
Quoted 6 lines
Similar to the RX ring above, if
mtk_wed_ring_alloc()fails to allocate memory, the hardware base registers won't be configured. Since the caller proceeds to enable hardware DMA regardless, might this lead to the WED processing descriptors from unmapped memory and causing memory corruption or a system crash?
I am not sure how to proceed with this.
Can Felix or Lorenzo comment this?
Best regards,
Zhi-Jun
Quoted 6 lines
Quoted 3 lines
drivers/net/ethernet/mediatek/mtk_wed.c +1
-0+if (dev->wlan.hw_rro) {for (i =0 ; i <MTK_WED_RX_PAGE_QUEUES ; i++) {Signature · 1 line
This is an AI-generated review.