dmaengine: xilinx_dma: MCDMA descriptor and metadata handling improvements
Subsystems (5)
v6 cover dmaengine: xilinx_dma: MCDMA descriptor and metadata handling improvements
This series improves the Xilinx AXI DMA and MCDMA driver's descriptor handling and metadata reporting. It fixes direction-specific descriptor field usage, ensures completion is based on the hardware completion bit (important with interrupt coalescing), and extends metadata handling to expose status and sideband fields alongside APP fields.
The axienet driver is updated to derive RX frame length from the standard dmaengine residue mechanism rather than descriptor APP fields, making it work on designs where the AXI4-Stream status/control interface is not present.
Changes in V6:
- Patch4: Added Reviewed-by: Radhey Shyam Pandey
Changes in V5:
- Patch 4: Take the metadata pointer from the SOP descriptor for TX and the EOF descriptor for RX, matching where the hardware reads and writes the fields (TX previously used the EOF descriptor). AXI DMA now exposes only the APP words (20 bytes) in both directions. AXI MCDMA exposes the control sideband, status and APP fields (28 bytes), with the sideband position differing between MM2S and S2MM. Reworked the kernel-doc index table and commit message accordingly.
- Patches 1-3: No functional change.
Changes in V4:
- Patch 1: Added Reviewed-by: Radhey Shyam Pandey.
- Patch 2: Reworded commit message to reference the AXIDMA fix it mirrors; added Reviewed-by: Radhey Shyam Pandey.
- Patch 3: Renamed subject to "...from residue in dmaengine path"; condensed commit message; dropped Fixes tag.
- Patch 4: Restructured get_metadata_ptr() so AXIDMA is the fall-through path (no WARN_ON_ONCE); rewrote the kernel-doc as an index table covering AXI DMA, MCDMA S2MM and MCDMA MM2S; condensed commit message.
Changes in V3:
- Patch 1: Renamed subject, added static_assert for descriptor size, refactored residue calculation for clarity.
- Patch 2: Added Fixes tag, expanded commit message explaining interrupt coalescing scenario, simplified completion check logic.
- Patch 3: New patch - axienet now uses result->residue for RX length instead of APP metadata, removing dependency on status/control stream.
- Patch 4: Complete rewrite - metadata pointer now starts at status field (index 0) exposing status/sideband to clients; uses EOF descriptor; removed 'chan' field from descriptor struct.
- Dropped V2 patches 4/5 (dt-bindings) and 5/5 (xferred_bytes) as the approach changed to use standard residue mechanism.
Changes in V2:
- Rebased on the AXI DMA binding YAML conversion.
- Added xlnx,include-stscntrl-strm in the YAML binding.
- Clarified cover letter to reflect metadata behavior with and without APP fields.
https://lore.kernel.org/all/[email protected]/
Srinivas Neeli (3):
dmaengine: xilinx_dma: Fix MCDMA descriptor fields based on DMA
direction
dmaengine: xilinx_dma: Move descriptors to done list based on
completion bit
net: xilinx: axienet: Derive RX frame length from residue in dmaengine
path
Suraj Gupta (1):
dmaengine: xilinx_dma: Extend metadata handling for AXI DMA and MCDMA
drivers/dma/xilinx/xilinx_dma.c | 85 ++++++++++++++++--- .../net/ethernet/xilinx/xilinx_axienet_main.c | 14 ++- 2 files changed, 78 insertions(+), 21 deletions(-)
Signature · 1 line
2.43.0
PATCH v6 1/4 dmaengine: xilinx_dma: Fix MCDMA descriptor fields based on DMA direction
The MCDMA BD format differs between memory-to-device (MM2S) and device-to-memory (S2MM) directions, but the driver was using generic 'status' and 'sideband_status' fields for both. This led to incorrect residue calculations when the hardware updates direction-specific fields.
Refactor the descriptor structure to use unions with direction-specific field mappings, and update the residue calculation logic to select the correct status field based on DMA direction.
This matches the hardware descriptor layout and fixes incorrect residue reporting.
---
Changes in V6:
- No change.
Changes in V5:
- No change.
Changes in V4:
- Added Reviewed-by: Radhey Shyam Pandey.
Changes in V3:
- Renamed subject from "for MM2S vs S2MM" to "based on DMA direction".
- Reworded commit message for clarity.
- Added XILINX_MCDMA_BD_HW_SIZE macro and static_assert to verify descriptor size at compile time.
- Refactored residue calculation to separate addition and subtraction operations for better readability.
Changes in V2:
- No change.
--- drivers/dma/xilinx/xilinx_dma.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/dma/xilinx/xilinx_dma.c +19 -7
@@ -223,6 +223,7 @@#define XILINX_MCDMA_IRQ_ERR_MASK BIT(7)#define XILINX_MCDMA_BD_EOP BIT(30)#define XILINX_MCDMA_BD_SOP BIT(31) +#define XILINX_MCDMA_BD_HW_SIZE 64/** * struct xilinx_vdma_desc_hw - Hardware Descriptor
@@ -277,8 +278,10 @@ struct xilinx_axidma_desc_hw {* @buf_addr_msb: MSB of Buffer address @0x0C * @rsvd: Reserved field @0x10 * @control: Control Information field @0x14 -* @status: Status field @0x18 -* @sideband_status: Status of sideband signals @0x1C +* @mm2s_ctrl_sideband: Sideband control info for mm2s @0x18 +* @s2mm_status: Status field for s2mm @0x18 +* @mm2s_status: Status field for mm2s @0x1C +* @s2mm_sideband_status: Sideband status for s2mm @0x1C * @app: APP Fields @0x20 - 0x30 */ struct xilinx_aximcdma_desc_hw {
@@ -288,10 +291,17 @@ struct xilinx_aximcdma_desc_hw {u32 buf_addr_msb;u32 rsvd;u32 control; -u32 status; -u32 sideband_status; +union { +u32 mm2s_ctrl_sideband; +u32 s2mm_status; + }; +union { +u32 mm2s_status; +u32 s2mm_sideband_status; + };u32 app[XILINX_DMA_NUM_APP_WORDS ]; }__aligned(64) ; +static_assert (sizeof (struct xilinx_aximcdma_desc_hw ) ==XILINX_MCDMA_BD_HW_SIZE );/** * struct xilinx_cdma_desc_hw - Hardware Descriptor
@@ -1015,9 +1025,11 @@ static u32 xilinx_dma_get_residue(struct xilinx_dma_chan *chan, struct xilinx_aximcdma_tx_segment, node); aximcdma_hw = &aximcdma_seg->hw; - residue += - (aximcdma_hw->control & chan->xdev->max_buffer_len) - - (aximcdma_hw->status & chan->xdev->max_buffer_len); + residue += aximcdma_hw->control & chan->xdev->max_buffer_len; +if (chan->direction ==DMA_DEV_TO_MEM ) + residue -= aximcdma_hw->s2mm_status & chan->xdev->max_buffer_len; +else + residue -= aximcdma_hw->mm2s_status & chan->xdev->max_buffer_len; } }
Signature · 1 line
2.43.0
Re: [PATCH V6 1/4] dmaengine: xilinx_dma: Fix MCDMA descriptor fields based on DMA direction
Quoted 9 lines · Srinivas Neeli
The MCDMA BD format differs between memory-to-device (MM2S) and device-to-memory (S2MM) directions, but the driver was using generic 'status' and '
sideband_status' fields for both. This led to incorrect residue calculations when the hardware updates direction-specific fields.Refactor the descriptor structure to use unions with direction-specific field mappings, and update the residue calculation logic to select the correct status field based on DMA direction.
Quoted 7 lines
This matches the hardware descriptor layout and fixes incorrect residue reporting.
Fixes 6ccd692bfb7f ("dmaengine: xilinx_dma: Add Xilinx AXI MCDMA Engine driver support")Reviewed-by Radhey Shyam Pandey <[email protected]>Signed-off-by Srinivas Neeli <[email protected]>---
Quoted 86 lines
Changes in V6:
- No change.Changes in V5:
- No change.Changes in V4:
- Added Reviewed-by: Radhey Shyam Pandey.Changes in V3:
- Renamed subject from "for MM2S vs S2MM" to "based on DMA direction".
- Reworded commit message for clarity.
- AddedXILINX_MCDMA_BD_HW_SIZEmacro andstatic_assertto verify descriptor size at compile time.
- Refactored residue calculation to separate addition and subtraction operations for better readability.Changes in V2:
- No change.--- drivers/dma/xilinx/xilinx_dma.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)drivers/dma/xilinx/xilinx_dma.c +19
-8@@ -223,6 +223,7 @@#define XILINX_MCDMA_IRQ_ERR_MASK BIT(7)#define XILINX_MCDMA_BD_EOP BIT(30)#define XILINX_MCDMA_BD_SOP BIT(31) +#define XILINX_MCDMA_BD_HW_SIZE 64/** * struct xilinx_vdma_desc_hw - Hardware Descriptor @@ -277,8 +278,10 @@ struct xilinx_axidma_desc_hw {* @buf_addr_msb: MSB of Buffer address @0x0C * @rsvd: Reserved field @0x10 * @control: Control Information field @0x14 -* @status: Status field @0x18 -* @sideband_status: Status of sideband signals @0x1C +* @mm2s_ctrl_sideband: Sideband control info for mm2s @0x18 +* @s2mm_status: Status field for s2mm @0x18 +* @mm2s_status: Status field for mm2s @0x1C +* @s2mm_sideband_status: Sideband status for s2mm @0x1C * @app: APP Fields @0x20 - 0x30 */ struct xilinx_aximcdma_desc_hw {@@ -288,10 +291,17 @@ struct xilinx_aximcdma_desc_hw {u32 buf_addr_msb;u32 rsvd;u32 control; -u32 status; -u32 sideband_status; +union { +u32 mm2s_ctrl_sideband; +u32 s2mm_status; + }; +union { +u32 mm2s_status; +u32 s2mm_sideband_status; + };u32 app[XILINX_DMA_NUM_APP_WORDS ]; }__aligned(64) ; +static_assert (sizeof (struct xilinx_aximcdma_desc_hw ) ==XILINX_MCDMA_BD_HW_SIZE );/** * struct xilinx_cdma_desc_hw - Hardware Descriptor @@ -1015,9 +1025,11 @@ static u32 xilinx_dma_get_residue(struct xilinx_dma_chan *chan, struct xilinx_aximcdma_tx_segment, node); aximcdma_hw = &aximcdma_seg->hw; - residue += - (aximcdma_hw->control & chan->xdev->max_buffer_len) - - (aximcdma_hw->status & chan->xdev->max_buffer_len); + residue += aximcdma_hw->control & chan->xdev->max_buffer_len; +if (chan->direction ==DMA_DEV_TO_MEM ) + residue -= aximcdma_hw->s2mm_status & chan->xdev->max_buffer_len; +else + residue -= aximcdma_hw->mm2s_status & chan->xdev->max_buffer_len; } } --2.43.0
[email protected]
AI reviewRe: [PATCH V6 1/4] dmaengine: xilinx_dma: Fix MCDMA descriptor fields based on DMA direction
In reply to Srinivas NeeliThank 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:
Pre-existing issues:
- [High] xilinx_dma_tx_status ignores the requested cookie when reporting the residue. --
--- Patch [1]: [PATCH V6 1/4] dmaengine: xilinx_dma: Fix MCDMA descriptor fields based on DMA direction --- commit 5b7fc319de466b2688413e1d7e8a139d9c3d5d82
Author: Srinivas Neeli <[email protected]>
dmaengine: xilinx_dma: Fix MCDMA descriptor fields based on DMA direction
The MCDMA BD format differs between memory-to-device (MM2S) and device-to-memory (S2MM) directions. This commit refactors the descriptor structure to use unions with direction-specific field mappings and updates the residue calculation logic to select the correct status field.
Quoted 4 lines
drivers/dma/xilinx/xilinx_dma.c +0
-0
[ ... ]
Quoted 4 lines
drivers/dma/xilinx/xilinx_dma.c +0
-0@@ -1013,9 +1023,11 @@ static u32 xilinx_dma_get_residue(struct xilinx_dma_chan *chan, struct xilinx_aximcdma_tx_segment, node); aximcdma_hw = &aximcdma_seg->hw;
drivers/dma/xilinx/xilinx_dma.c static u32 xilinx_dma_get_residue(struct xilinx_dma_chan *chan, · line 1032
Quoted 10 lines
drivers/dma/xilinx/xilinx_dma.c +5
-3- residue += - (aximcdma_hw->control & chan->xdev->max_buffer_len) - - (aximcdma_hw->status & chan->xdev->max_buffer_len); + residue += aximcdma_hw->control & chan->xdev->max_buffer_len; +if (chan->direction ==DMA_DEV_TO_MEM ) + residue -= aximcdma_hw->s2mm_status & chan->xdev->max_buffer_len; +else + residue -= aximcdma_hw->mm2s_status & chan->xdev->max_buffer_len; } }
[Severity: High]
This isn't a bug introduced by this patch, but does xilinx_dma_tx_status() ignore the requested cookie when reporting the residue?
Looking at xilinx_dma_tx_status() in drivers/dma/xilinx/xilinx_dma.c, it seems to unconditionally compute and return the residue for the last entry in the active list:
desc = list_last_entry(&chan->active_list, struct xilinx_dma_tx_descriptor, node); /* * VDMA and simple mode do not support residue reporting, so the * residue field will always be 0. */ if (chan->has_sg && chan->xdev->dma_config->dmatype != XDMA_TYPE_VDMA) residue = xilinx_dma_get_residue(chan, desc);
This means it will always report the residue of the most recently submitted transaction, rather than the transaction the caller asked about via the cookie.
If a DMA client (e.g. a serial driver polling residue for partial Rx data) queues multiple non-cyclic scatter-gather DMA transactions on a Xilinx DMA channel, issues them, and then calls dmaengine_tx_status() to query the residue of an earlier transaction, it would get the remaining byte count of the last queued descriptor instead.
Should this iterate through the active and pending lists to look up the descriptor associated with the requested cookie?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
RE: [PATCH V6 1/4] dmaengine: xilinx_dma: Fix MCDMA descriptor fields based on DMA direction
AMD General
Hi,
Quoted 76 lines
-----Original Message-----
From: [email protected] <[email protected]>
Sent: Wednesday, August 19, 2026 11:17 PM
To: Neeli, Srinivas <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V6 1/4] dmaengine:xilinx_dma: Fix MCDMA descriptor fields based on DMA directionThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High]xilinx_dma_tx_statusignores the requested cookie when reporting the residue.
----- Patch [1]: [PATCH V6 1/4] dmaengine:
xilinx_dma: Fix MCDMA descriptor fields based on DMA direction --- commit5b7fc319de466b2688413e1d7e8a139d9c3d5d82
Author: Srinivas Neeli <[email protected]>dmaengine:
xilinx_dma: Fix MCDMA descriptor fields based on DMA directionThe MCDMA BD format differs between memory-to-device (MM2S) and device-to-memory (S2MM) directions. This commit refactors the descriptor structure to use unions with direction-specific field mappings and updates the residue calculation logic to select the correct status field.
Quoted 5 lines
(quoted diff) +0
-0
b/drivers/dma/xilinx/xilinx_dma.cindex404235c173538..965fb69a2a3ad100644drivers/dma/xilinx/xilinx_dma.c +0
-0[ ... ]
drivers/dma/xilinx/xilinx_dma.c static u32 xilinx_dma_get_residue(struct
Quoted 1 line
drivers/dma/xilinx/xilinx_dma.c +0
-0@@ -1013,9 +1023,11 @@ static u32 xilinx_dma_get_residue(struct
xilinx_dma_chan*chan,drivers/dma/xilinx/xilinx_dma.c
Quoted 12 lines
drivers/dma/xilinx/xilinx_dma.c +0
-2struct xilinx_aximcdma_tx_segment, node); aximcdma_hw = &aximcdma_seg->hw; - residue += - (aximcdma_hw->control & chan->xdev-
max_buffer_len) -
- (aximcdma_hw->status& chan->xdev-max_buffer_len);
+ residue +=aximcdma_hw->control& chan->xdev-max_buffer_len;drivers/dma/xilinx/xilinx_dma.c +2
-0+if (chan->direction ==DMA_DEV_TO_MEM ) + residue -= aximcdma_hw->s2mm_status &
chan->xdev->max_buffer_len;drivers/dma/xilinx/xilinx_dma.c
Quoted 2 lines
drivers/dma/xilinx/xilinx_dma.c +2
-0+else + residue -= aximcdma_hw->mm2s_status &
chan->xdev->max_buffer_len;Quoted 2 lines
} }[Severity: High]
This isn't a bug introduced by this patch, but doesxilinx_dma_tx_status()ignore the requested cookie when reporting the residue?Looking at
xilinx_dma_tx_status()indrivers/dma/xilinx/xilinx_dma.c, it seems to unconditionally compute and return the residue for the last entry in the active list:desc = list_last_entry(&chan->active_list, struct xilinx_dma_tx_descriptor, node); /* * VDMA and simple mode do not support residue reporting, so the * residue field will always be 0. */ if (chan->has_sg && chan->xdev->dma_config->dmatype != XDMA_TYPE_VDMA) residue = xilinx_dma_get_residue(chan, desc);This means it will always report the residue of the most recently submitted transaction, rather than the transaction the caller asked about via the cookie.
Quoted 9 lines
If a DMA client (e.g. a serial driver polling residue for partial Rx data) queues multiple non-cyclic scatter-gather DMA transactions on a Xilinx DMA channel, issues them, and then calls
dmaengine_tx_status()to query the residue of an earlier transaction, it would get the remaining byte count of the last queued descriptor instead.Should this iterate through the active and pending lists to look up the descriptor associated with the requested cookie?
The issue pointed out is pre-existing and not introduced by this patch. I will address all pre-existing issues in a separate patch series.
Thanks
Srinivas Neeli
Quoted 3 lines
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260818174151.1608971-
[email protected]?part=1
PATCH v6 2/4 dmaengine: xilinx_dma: Move descriptors to done list based on completion bit
In reply to Srinivas NeeliIn AXI MCDMA, xilinx_dma_complete_descriptor() walks the channel's active_list and unconditionally moves every entry to the done_list. The MCDMA IOC interrupt handler invokes this function on every interrupt-on-completion, but with interrupt coalescing (IRQThreshold > 1) an IOC interrupt may fire after only a subset of the queued descriptors have actually been processed by the hardware. As a result, descriptors whose completion bit is not yet set in the BD status were being reported as completed to client drivers.
Add a check for the descriptor completion bit before moving entries from the active list to the done list, using the appropriate direction- specific status field (s2mm_status for DMA_DEV_TO_MEM, mm2s_status for DMA_MEM_TO_DEV).
This mirrors the AXIDMA fix in commit 7bcdaa658102 ("dmaengine:xilinx_dma: Freeup active list based on descriptor completion bit").
---
Changes in V6:
- No change.
Changes in V5:
- No change.
Changes in V4:
- Reworded commit message to reference the AXIDMA fix it mirrors (commit 7bcdaa658102).
- Added Reviewed-by: Radhey Shyam Pandey.
Changes in V3:
- Added Fixes tag.
- Expanded commit message to explain the interrupt coalescing scenario and why the has_sg guard is omitted for MCDMA.
- Changed local variable from 'bool completed' to 'u32 status' for cleaner status field access.
- Simplified completion check logic.
Changes in V2:
- No change.
--- drivers/dma/xilinx/xilinx_dma.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/dma/xilinx/xilinx_dma.c +11 -0
@@ -1784,6 +1784,17 @@ static void xilinx_dma_complete_descriptor(struct xilinx_dma_chan *chan) struct xilinx_axidma_tx_segment, node);if (!(seg->hw.status &XILINX_DMA_BD_COMP_MASK ) && chan->has_sg)break ; + }else if (chan->xdev->dma_config->dmatype ==XDMA_TYPE_AXIMCDMA ) { +struct xilinx_aximcdma_tx_segment *seg; +u32 status; + + seg =list_last_entry (&desc->segments, + struct xilinx_aximcdma_tx_segment, + node); + status = (chan->direction ==DMA_DEV_TO_MEM ) ? + seg->hw.s2mm_status : seg->hw.mm2s_status; +if (!(status &XILINX_DMA_BD_COMP_MASK )) +break ; }if (chan->has_sg && chan->xdev->dma_config->dmatype !=XDMA_TYPE_VDMA )
Signature · 1 line
2.43.0
Re: [PATCH V6 2/4] dmaengine: xilinx_dma: Move descriptors to done list based on completion bit
Quoted 14 lines · Srinivas Neeli
In AXI MCDMA,
xilinx_dma_complete_descriptor()walks the channel'sactive_listand unconditionally moves every entry to thedone_list. The MCDMA IOC interrupt handler invokes this function on every interrupt-on-completion, but with interrupt coalescing (IRQThreshold > 1) an IOC interrupt may fire after only a subset of the queued descriptors have actually been processed by the hardware. As a result, descriptors whose completion bit is not yet set in the BD status were being reported as completed to client drivers.Add a check for the descriptor completion bit before moving entries from the active list to the done list, using the appropriate direction- specific status field (
s2mm_statusforDMA_DEV_TO_MEM,mm2s_statusforDMA_MEM_TO_DEV).
Quoted 7 lines
This mirrors the AXIDMA fix in commit
7bcdaa658102("dmaengine:xilinx_dma: Freeup active list based on descriptor completion bit").Fixes 6ccd692bfb7f ("dmaengine: xilinx_dma: Add Xilinx AXI MCDMA Engine driver support")Reviewed-by Radhey Shyam Pandey <[email protected]>Signed-off-by Srinivas Neeli <[email protected]>---
Quoted 50 lines
Changes in V6:
- No change.Changes in V5:
- No change.Changes in V4:
- Reworded commit message to reference the AXIDMA fix it mirrors (commit7bcdaa658102).
- Added Reviewed-by: Radhey Shyam Pandey.Changes in V3:
- Added Fixes tag.
- Expanded commit message to explain the interrupt coalescing scenario and why thehas_sgguard is omitted for MCDMA.
- Changed local variable from 'bool completed' to 'u32 status' for cleaner status field access.
- Simplified completion check logic.Changes in V2:
- No change.--- drivers/dma/xilinx/xilinx_dma.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/dma/xilinx/xilinx_dma.c +11
-1@@ -1784,6 +1784,17 @@ static void xilinx_dma_complete_descriptor(struct xilinx_dma_chan *chan) struct xilinx_axidma_tx_segment, node);if (!(seg->hw.status &XILINX_DMA_BD_COMP_MASK ) && chan->has_sg)break ; + }else if (chan->xdev->dma_config->dmatype ==XDMA_TYPE_AXIMCDMA ) { +struct xilinx_aximcdma_tx_segment *seg; +u32 status; + + seg =list_last_entry (&desc->segments, + struct xilinx_aximcdma_tx_segment, + node); + status = (chan->direction ==DMA_DEV_TO_MEM ) ? + seg->hw.s2mm_status : seg->hw.mm2s_status; +if (!(status &XILINX_DMA_BD_COMP_MASK )) +break ; }if (chan->has_sg && chan->xdev->dma_config->dmatype !=XDMA_TYPE_VDMA ) --2.43.0
[email protected]
AI reviewRe: [PATCH V6 2/4] dmaengine: xilinx_dma: Move descriptors to done list based on completion bit
In reply to Srinivas NeeliThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Unconditional transition to `chan->idle = true` while `active_list` is not empty causes a…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Unconditional transition to chan->idle = true while active_list is not empty causes a permanent DMA stall and unsafe writes to active hardware registers.
- [High] Missing dma_rmb() after reading the hardware descriptor completion bit allows speculative reads of stale descriptor fields.
--
--- Patch [2]: [PATCH V6 2/4] dmaengine: xilinx_dma: Move descriptors to done list based on completion bit --- commit f3afd1d99816a230e330fe49141913c537fd8bc9
Author: Srinivas Neeli <[email protected]>
dmaengine: xilinx_dma: Move descriptors to done list based on completion bit
This commit updates the descriptor completion logic to check the completion bit before moving MCDMA descriptors from the active list to the done list. This addresses an issue where interrupt coalescing could cause uncompleted descriptors to be erroneously reported as complete.
Quoted 9 lines
drivers/dma/xilinx/xilinx_dma.c +1
-0@@ -1773,6 +1773,17 @@ static void xilinx_dma_complete_descriptor(struct xilinx_dma_chan *chan) struct xilinx_axidma_tx_segment, node);if (!(seg->hw.status &XILINX_DMA_BD_COMP_MASK ) && chan->has_sg)break ; + }else if (chan->xdev->dma_config->dmatype ==XDMA_TYPE_AXIMCDMA ) {
drivers/dma/xilinx/xilinx_dma.c static void xilinx_dma_complete_descriptor(struct xilinx_dma_chan *chan) · line 1786
Quoted 10 lines
drivers/dma/xilinx/xilinx_dma.c +10
-0+struct xilinx_aximcdma_tx_segment *seg; +u32 status; + + seg =list_last_entry (&desc->segments, + struct xilinx_aximcdma_tx_segment, + node); + status = (chan->direction ==DMA_DEV_TO_MEM ) ? + seg->hw.s2mm_status : seg->hw.mm2s_status; +if (!(status &XILINX_DMA_BD_COMP_MASK )) +break ;
[Severity: High]
If this breaks early and leaves uncompleted descriptors in the active list, does it cause issues with the interrupt handler?
Looking at xilinx_mcdma_irq_handler(), it unconditionally calls start_transfer():
xilinx_dma_complete_descriptor(chan); chan->idle = true; chan->start_transfer(chan);
If xilinx_mcdma_start_transfer() is called while the DMA is still actively processing the old chain, it will write the new descriptor chain to the CDESC register:
/* Program current descriptor */ xilinx_write(chan, XILINX_MCDMA_CHAN_CDESC_OFFSET(chan->tdest), head_desc->async_tx.phys);
Could writing to the CDESC register while the channel is still running cause a permanent DMA stall or corrupt the hardware state?
[Severity: High]
Is a read memory barrier needed after reading the hardware descriptor completion bit?
If the completion mask is set, the code may proceed to calculate the transfer residue in xilinx_dma_get_residue():
residue -= aximcdma_hw->s2mm_status & chan->xdev->max_buffer_len;
Without a dma_rmb() between checking the completion bit and reading the preceding segments' status fields, is it possible for weakly ordered architectures to speculatively read stale values, leading to incorrect residue calculations?
Quoted 3 lines
drivers/dma/xilinx/xilinx_dma.c +0
-0}if (chan->has_sg && chan->xdev->dma_config->dmatype !=XDMA_TYPE_VDMA )
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
RE: [PATCH V6 2/4] dmaengine: xilinx_dma: Move descriptors to done list based on completion bit
AMD General
Hi,
Quoted 86 lines
-----Original Message-----
From: [email protected] <[email protected]>
Sent: Wednesday, August 19, 2026 11:17 PM
To: Neeli, Srinivas <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V6 2/4] dmaengine:xilinx_dma: Move descriptors to done list based on completion bitThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Unconditional transition tochan->idle = truewhileactive_listis not empty causes a permanent DMA stall and unsafe writes to active hardware registers.
- [High] Missingdma_rmb()after reading the hardware descriptor completion bit allows speculative reads of stale descriptor fields.
----- Patch [2]: [PATCH V6 2/4] dmaengine:
xilinx_dma: Move descriptors to done list based on completion bit --- commitf3afd1d99816a230e330fe49141913c537fd8bc9
Author: Srinivas Neeli <[email protected]>dmaengine:
xilinx_dma: Move descriptors to done list based on completion bitThis commit updates the descriptor completion logic to check the completion bit before moving MCDMA descriptors from the active list to the done list. This addresses an issue where interrupt coalescing could cause uncompleted descriptors to be erroneously reported as complete.
drivers/dma/xilinx/xilinx_dma.c static void
Quoted 6 lines
(quoted diff) +0
-0
b/drivers/dma/xilinx/xilinx_dma.cindex965fb69a2a3ad..9b8b6f1acd4ea100644drivers/dma/xilinx/xilinx_dma.c +0
-0@@ -1773,6 +1773,17 @@ static void
xilinx_dma_complete_descriptor(struct xilinx_dma_chan *chan)drivers/dma/xilinx/xilinx_dma.c static void · line 1773
Quoted 1 line
drivers/dma/xilinx/xilinx_dma.c +0
-0struct xilinx_axidma_tx_segment,node);
drivers/dma/xilinx/xilinx_dma.c static void · line 1774
Quoted 1 line
drivers/dma/xilinx/xilinx_dma.c +0
-0if (!(seg->hw.status &
XILINX_DMA_BD_COMP_MASK) &&chan->has_sg)drivers/dma/xilinx/xilinx_dma.c static void · line 1776
Quoted 2 lines
drivers/dma/xilinx/xilinx_dma.c +1
-0break ; + } else if (chan->xdev->dma_config->dmatype ==
XDMA_TYPE_AXIMCDMA) {drivers/dma/xilinx/xilinx_dma.c static void xilinx_dma_complete_descriptor(struct xilinx_dma_chan *chan)
Quoted 5 lines
drivers/dma/xilinx/xilinx_dma.c +5
-0+struct xilinx_aximcdma_tx_segment *seg; +u32 status; + + seg =list_last_entry (&desc->segments, + struct
xilinx_aximcdma_tx_segment,drivers/dma/xilinx/xilinx_dma.c static void xilinx_dma_complete_descriptor(struct xilinx_dma_chan *chan) · line 1797
Quoted 6 lines
drivers/dma/xilinx/xilinx_dma.c +5
-0+ node); + status = (chan->direction ==DMA_DEV_TO_MEM ) ? + seg->hw.s2mm_status : seg- hw.mm2s_status; +if (!(status &XILINX_DMA_BD_COMP_MASK )) +break ;[Severity: High]
If this breaks early and leaves uncompleted descriptors in the active list, does it cause issues with the interrupt handler?Looking at
xilinx_mcdma_irq_handler(), it unconditionally callsstart_transfer():xilinx_dma_complete_descriptor(chan); chan->idle = true; chan->start_transfer(chan);If
xilinx_mcdma_start_transfer()is called while the DMA is still actively processing the old chain, it will write the new descriptor chain to the CDESC register:/* Program current descriptor */ xilinx_write(chan, XILINX_MCDMA_CHAN_CDESC_OFFSET(chan-drivers/dma/xilinx/xilinx_dma.c static void · line 1788
Quoted 1 line
drivers/dma/xilinx/xilinx_dma.c +0
-0tdest),head_desc->async_tx.phys);Could writing to the CDESC register while the channel is still running cause a permanent DMA stall or corrupt the hardware state?
[Severity: High]
Is a read memory barrier needed after reading the hardware descriptor completion bit?If the completion mask is set, the code may proceed to calculate the transfer residue in
xilinx_dma_get_residue():
Quoted 12 lines
residue -= aximcdma_hw->s2mm_status & chan->xdev-drivers/dma/xilinx/xilinx_dma.c static void · line 1789
Quoted 1 line
drivers/dma/xilinx/xilinx_dma.c +0
-0max_buffer_len;Without a
dma_rmb()between checking the completion bit and reading the preceding segments' status fields, is it possible for weakly ordered architectures to speculatively read stale values, leading to incorrect residue calculations?Quoted 3 lines
} if (chan->has_sg && chan->xdev->dma_config->dmatype != XDMA_TYPE_VDMA)
The analysis seems to have been performed on an older code base. The current linux-next tree already contains fixes that address these concerns, so the reported issues do not apply to this patch. I am ignoring these comments for this revision.
Thanks
Srinivas Neeli
Quoted 4 lines
--
Sashiko AI review ·
https://sashiko.dev/#/patchset/20260818174151.1608971-1-
[email protected]?part=2
PATCH v6 3/4 net: xilinx: axienet: Derive RX frame length from residue in dmaengine path
In reply to Srinivas NeeliThe dmaengine RX path derived the received frame length from the descriptor APP metadata. That only works when the optional AXI4-Stream status/control interface is present, because the hardware populates the APP fields solely when that interface is enabled. On designs without it the length read back is invalid.
The AXI DMA engine already reports how many bytes it wrote into the buffer through the standard dmaengine residue mechanism. Compute the RX frame length as the posted buffer length minus result->residue, which is independent of the status/control interface and correct across all designs, including multi-descriptor frames where the residue is summed over the chain.
Drop the descriptor metadata lookup, which was only used for this purpose. Detect a failed transfer from dmaengine_result.result instead of the metadata pointer return value, and remove the now unused LEN_APP macro.
The transmit path is unaffected. It still passes APP metadata for checksum offload and derives its length from the skb.
---
Changes in V6:
- No change.
Changes in V5:
- No change.
Changes in V4:
- Renamed subject to "Derive RX frame length from residue in dmaengine path".
- Condensed the commit message.
- Dropped the Fixes tag.
Changes in V3:
- New patch in this series.
- This patch enables axienet to work on designs where the AXI4-Stream status/control interface is not present. By using the standard dmaengine residue mechanism, the driver no longer depends on APP fields being populated by hardware.
- This approach replaces the V2 xferred_bytes mechanism (V2 patch 5/5), making the dt-bindings patch (V2 patch 4/5) for xlnx,include-stscntrl-strm also unnecessary. Both V2 patches are dropped in this series.
--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +5 -9
@@ -53,7 +53,6 @@#define TX_BD_NUM_MAX 4096#define RX_BD_NUM_MAX 4096#define DMA_NUM_APP_WORDS 5 -#define LEN_APP 4#define RX_BUF_NUM_DEFAULT 128/* Must be shorter than length of ethtool_drvinfo.driver field to fit */
@@ -1159,29 +1158,26 @@ axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev)static void axienet_dma_rx_cb (void *data,const struct dmaengine_result *result) {struct skbuf_dma_descriptor *skbuf_dma; -size_t meta_len, meta_max_len, rx_len;struct axienet_local *lp = data;struct sk_buff *skb; -u32 *app_metadata; +size_t rx_len;int i; skbuf_dma =axienet_get_rx_desc (lp, lp->rx_ring_tail++); skb = skbuf_dma->skb; - app_metadata =dmaengine_desc_get_metadata_ptr (skbuf_dma->desc, &meta_len, - &meta_max_len);dma_unmap_single (lp->dev, skbuf_dma->dma_address, lp->max_frm_size,DMA_FROM_DEVICE ); -if (IS_ERR (app_metadata)) { +if (result->result !=DMA_TRANS_NOERROR ) {if (net_ratelimit ()) -netdev_err (lp->ndev,"Failed to get RX metadata pointer\n" ); +netdev_err (lp->ndev,"RX DMA transfer failed\n" );dev_kfree_skb_any (skb); lp->ndev->stats.rx_dropped++; goto rx_submit; } -/* TODO: Derive app word index programmatically */ - rx_len = (app_metadata[LEN_APP ] &0xFFFF ); +/* Actual length = posted buffer length - residue. */ + rx_len = lp->max_frm_size - result->residue;skb_put (skb, rx_len); skb->protocol =eth_type_trans (skb, lp->ndev); skb->ip_summed =CHECKSUM_NONE ;
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH V6 3/4] net: xilinx: axienet: Derive RX frame length from residue in dmaengine path
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] The DMA engine TX submission path fails to decrement tx_ring_head on error, corrupting the ring state and causing use-after-free and double-free on subsequent TX completions.
- [High] The axienet_stop() function leaks pending sk_buff structures and their DMA mappings when using the DMA engine.
--
--- Patch [3]: [PATCH V6 3/4] net: xilinx: axienet: Derive RX frame length from residue in dmaengine path --- commit 86c32a60f9e05880f70cba98d261769dec79ad80
Author: Srinivas Neeli <[email protected]>
net: xilinx: axienet: Derive RX frame length from residue in dmaengine path
The dmaengine RX path derived the received frame length from the descriptor APP metadata. That only works when the optional AXI4-Stream status/control interface is present, because the hardware populates the APP fields solely when that interface is enabled. On designs without it the length read back is invalid.
drivers/net/ethernet/xilinx/xilinx_axienet_main.c
Quoted 4 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0
-0
[ ... ]
[Severity: High]
This isn't a bug introduced by this patch, but while reviewing the DMA ring management, I noticed an issue in axienet_start_xmit_dmaengine() where the ring state can become corrupted on error.
If an error occurs during mapping, tx_ring_head remains incremented while the SKB is freed:
drivers/net/ethernet/xilinx/xilinx_axienet_main.c:axienet_start_xmit_dmaengine() {
lp->tx_ring_head++;
sg_init_table(skbuf_dma->sgl, sg_len);
ret = skb_to_sgvec(skb, skbuf_dma->sgl, 0, skb->len);
if (ret < 0)
goto xmit_error_drop_skb;
...
xmit_error_drop_skb:
dev_kfree_skb_any(skb);
return NETDEV_TX_OK;
}When the next valid packet is successfully submitted and completes, will axienet_dma_tx_cb() fetch the descriptor using lp->tx_ring_tail++ and read the freed skb?
drivers/net/ethernet/xilinx/xilinx_axienet_main.c:axienet_dma_tx_cb() {
...
skbuf_dma = axienet_get_tx_desc(lp, lp->tx_ring_tail++); len = skbuf_dma->skb->len; txq = skb_get_tx_queue(lp->ndev, skbuf_dma->skb); ... dev_consume_skb_any(skbuf_dma->skb); }
Does this out-of-sync ring state lead to a use-after-free and double-free of the SKB?
[Severity: High]
This is a pre-existing issue, but I also noticed a potential memory and DMA mapping leak in axienet_stop() when the interface is brought down.
The teardown loops free the wrapper structures, but do they fail to unmap and free the associated SKBs?
drivers/net/ethernet/xilinx/xilinx_axienet_main.c:axienet_stop() {
...
for (i = 0; i < TX_BD_NUM_MAX; i++) kfree(lp->tx_skb_ring[i]); kfree(lp->tx_skb_ring); for (i = 0; i < RX_BUF_NUM_DEFAULT; i++) kfree(lp->rx_skb_ring[i]); kfree(lp->rx_skb_ring);
...
}
The SKBs and DMA mappings were allocated in axienet_rx_submit_desc():
drivers/net/ethernet/xilinx/xilinx_axienet_main.c:axienet_rx_submit_desc() {
...
addr = dma_map_single(lp->dev, skb->data, lp->max_frm_size, DMA_FROM_DEVICE); ... skbuf_dma->skb = skb; skbuf_dma->dma_address = sg_dma_address(skbuf_dma->sgl);
...
}
Can this cause a permanent leak of SKBs and mappings each time the interface is stopped?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH V6 3/4] net: xilinx: axienet: Derive RX frame length from residue in dmaengine path
Hi,
Quoted 87 lines · On 8/19/2026 11:17 PM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] The DMA engine TX submission path fails to decrementtx_ring_headon error, corrupting the ring state and causing use-after-free and double-free on subsequent TX completions.
- [High] Theaxienet_stop()function leaks pendingsk_buffstructures and their DMA mappings when using the DMA engine.
----- Patch [3]: [PATCH V6 3/4] net: xilinx: axienet: Derive RX frame length from residue in dmaengine path --- commit
86c32a60f9e05880f70cba98d261769dec79ad80
Author: Srinivas Neeli <[email protected]>net: xilinx: axienet: Derive RX frame length from residue in dmaengine path
The dmaengine RX path derived the received frame length from the descriptor APP metadata. That only works when the optional AXI4-Stream status/control interface is present, because the hardware populates the APP fields solely when that interface is enabled. On designs without it the length read back is invalid.
drivers/net/ethernet/xilinx/xilinx_axienet_main.c
Quoted 4 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0
-0[ ... ]
[Severity: High]
This isn't a bug introduced by this patch, but while reviewing the DMA ring management, I noticed an issue inaxienet_start_xmit_dmaengine()where the ring state can become corrupted on error.If an error occurs during mapping,
tx_ring_headremains incremented while the SKB is freed:drivers/net/ethernet/xilinx/xilinx_axienet_main.c:axienet_start_xmit_dmaengine() { lp->tx_ring_head++; sg_init_table(skbuf_dma->sgl, sg_len); ret = skb_to_sgvec(skb, skbuf_dma->sgl, 0, skb->len); if (ret < 0) goto xmit_error_drop_skb; ... xmit_error_drop_skb: dev_kfree_skb_any(skb); return NETDEV_TX_OK; }When the next valid packet is successfully submitted and completes, will
axienet_dma_tx_cb()fetch the descriptor using lp->tx_ring_tail++ and read the freed skb?drivers/net/ethernet/xilinx/xilinx_axienet_main.c:axienet_dma_tx_cb() {
...skbuf_dma = axienet_get_tx_desc(lp, lp->tx_ring_tail++); len = skbuf_dma->skb->len; txq = skb_get_tx_queue(lp->ndev, skbuf_dma->skb); ... dev_consume_skb_any(skbuf_dma->skb); }Does this out-of-sync ring state lead to a use-after-free and double-free of the SKB?
[Severity: High]
This is a pre-existing issue, but I also noticed a potential memory and DMA mapping leak inaxienet_stop()when the interface is brought down.The teardown loops free the wrapper structures, but do they fail to unmap and free the associated SKBs?
drivers/net/ethernet/xilinx/xilinx_axienet_main.c:axienet_stop() {
...for (i = 0; i < TX_BD_NUM_MAX; i++) kfree(lp->tx_skb_ring[i]); kfree(lp->tx_skb_ring); for (i = 0; i < RX_BUF_NUM_DEFAULT; i++) kfree(lp->rx_skb_ring[i]); kfree(lp->rx_skb_ring);...
}The SKBs and DMA mappings were allocated in
axienet_rx_submit_desc():drivers/net/ethernet/xilinx/xilinx_axienet_main.c:axienet_rx_submit_desc() {
...addr = dma_map_single(lp->dev, skb->data, lp->max_frm_size, DMA_FROM_DEVICE); ... skbuf_dma->skb = skb; skbuf_dma->dma_address = sg_dma_address(skbuf_dma->sgl);
Quoted 5 lines
...
}Can this cause a permanent leak of SKBs and mappings each time the interface is stopped?
These issues are pre-existing and are not introduced by this patch. I plan to address them in a separate series.
Thanks
Srinivas Neeli
Re: [PATCH V6 3/4] net: xilinx: axienet: Derive RX frame length from residue in dmaengine path
In reply to Srinivas NeeliHi Jakub,
I would like to follow up on this patch. The dependent DMA patches (1/4, 2/4, and 4/4) from this series have already been applied through the DMAEngine framework. Could you please advise if there are any remaining concerns with this patch or how you would prefer it to be handled on the netdev side? Also, I noticed that you were inadvertently included in the CC list rather than the To list in the original posting. Apologies for that.
Thanks
Srinivas neeli
Quoted 95 lines · Srinivas Neeli
The dmaengine RX path derived the received frame length from the descriptor APP metadata. That only works when the optional AXI4-Stream status/control interface is present, because the hardware populates the APP fields solely when that interface is enabled. On designs without it the length read back is invalid.
The AXI DMA engine already reports how many bytes it wrote into the buffer through the standard dmaengine residue mechanism. Compute the RX frame length as the posted buffer length minus
result->residue, which is independent of the status/control interface and correct across all designs, including multi-descriptor frames where the residue is summed over the chain.Drop the descriptor metadata lookup, which was only used for this purpose. Detect a failed transfer from dmaengine_result.result instead of the metadata pointer return value, and remove the now unused
LEN_APPmacro.The transmit path is unaffected. It still passes APP metadata for checksum offload and derives its length from the skb.
Reviewed-by Radhey Shyam Pandey <[email protected]>Signed-off-by Srinivas Neeli <[email protected]>---
Changes in V6:
- No change.Changes in V5:
- No change.Changes in V4:
- Renamed subject to "Derive RX frame length from residue in dmaenginepath".- Condensed the commit message.
- Dropped the Fixes tag.Changes in V3:
- New patch in this series.
- This patch enables axienet to work on designs where the AXI4-Stream status/control interface is not present. By using the standard dmaengine residue mechanism, the driver no longer depends on APP fields being populated by hardware.
- This approach replaces the V2xferred_bytesmechanism (V2 patch 5/5), making the dt-bindings patch (V2 patch 4/5) for xlnx,include-stscntrl-strm also unnecessary. Both V2 patches are dropped in this series.--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)drivers/net/ethernet/xilinx/xilinx_axienet_main.c +5
-9@@ -53,7 +53,6 @@#define TX_BD_NUM_MAX 4096#define RX_BD_NUM_MAX 4096#define DMA_NUM_APP_WORDS 5 -#define LEN_APP 4#define RX_BUF_NUM_DEFAULT 128/* Must be shorter than length of ethtool_drvinfo.driver field to fit */ @@ -1159,29 +1158,26 @@ axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev)static void axienet_dma_rx_cb (void *data,const struct dmaengine_result *result) {struct skbuf_dma_descriptor *skbuf_dma; -size_t meta_len, meta_max_len, rx_len;struct axienet_local *lp = data;struct sk_buff *skb; -u32 *app_metadata; +size_t rx_len;int i; skbuf_dma =axienet_get_rx_desc (lp, lp->rx_ring_tail++); skb = skbuf_dma->skb; - app_metadata =dmaengine_desc_get_metadata_ptr (skbuf_dma->desc, &meta_len, - &meta_max_len);dma_unmap_single (lp->dev, skbuf_dma->dma_address, lp->max_frm_size,DMA_FROM_DEVICE ); -if (IS_ERR (app_metadata)) { +if (result->result !=DMA_TRANS_NOERROR ) {if (net_ratelimit ()) -netdev_err (lp->ndev,"Failed to get RX metadata pointer\n" ); +netdev_err (lp->ndev,"RX DMA transfer failed\n" );dev_kfree_skb_any (skb); lp->ndev->stats.rx_dropped++; goto rx_submit; } -/* TODO: Derive app word index programmatically */ - rx_len = (app_metadata[LEN_APP ] &0xFFFF ); +/* Actual length = posted buffer length - residue. */ + rx_len = lp->max_frm_size - result->residue;skb_put (skb, rx_len); skb->protocol =eth_type_trans (skb, lp->ndev); skb->ip_summed =CHECKSUM_NONE ;
PATCH v6 4/4 dmaengine: xilinx_dma: Extend metadata handling for AXI DMA and MCDMA
In reply to Srinivas NeeliFrom: Suraj Gupta <[email protected]>
xilinx_dma_get_metadata_ptr() returns the AXI DMA APP words from the SOP descriptor in both directions. This is wrong for RX, where the hardware writes the APP words into the EOF descriptor. It also leaves AXI MCDMA without metadata support.
Return the metadata from the SOP descriptor for TX and from the EOF descriptor for RX, matching where the hardware reads and writes the fields. For AXI DMA, expose the APP words (20 bytes). For AXI MCDMA, expose the control sideband, status, and APP fields (28 bytes). On TX the control sideband holds TID and TUSER configuration for the outgoing stream. On RX the sideband status holds the received TID, TDEST and TUSER from the incoming stream. The field layout differs between MM2S and S2MM, and the wider payload lets a consumer distinguish the two controllers. No in-tree consumer is affected.
Read xlnx,axistream-connected for AXI MCDMA. Attach metadata_ops in xilinx_mcdma_prep_slave_sg() when an AXI4-Stream interface is present, so MCDMA clients use the metadata API the same way as AXI DMA clients.
---
Changes in V6:
- Added Reviewed-by: Radhey Shyam Pandey tag.
Changes in V5:
- Take the metadata pointer from the SOP descriptor for TX and the EOF descriptor for RX, matching where the hardware reads and writes the fields (TX previously used the EOF descriptor).
- AXI DMA now exposes only the APP words (20 bytes) in both directions, instead of the status word followed by APP (24 bytes).
- AXI MCDMA exposes the control sideband, status and APP fields (28 bytes), with the sideband position differing between MM2S and S2MM.
- Reworked the kernel-doc index table and commit message accordingly.
Changes in V4:
- Restructured xilinx_dma_get_metadata_ptr(): AXIDMA is now the fall-through path instead of a separate branch guarded by WARN_ON_ONCE()/ERR_PTR().
- Rewrote the kernel-doc as an index table covering AXI DMA, MCDMA S2MM and MCDMA MM2S, and documented that the pointer and payload length are the same for both MCDMA directions.
- Added an inline comment explaining the union aliasing.
- Condensed the commit message.
Changes in V3:
- Renamed subject to include "AXI DMA and MCDMA" (was "AXI MCDMA" only).
- Complete rewrite of commit message and implementation.
- Metadata pointer now returns status field at index 0 instead of APP fields, exposing status and sideband information to clients.
- Changed from list_first_entry to list_last_entry to return the EOF descriptor where hardware writes status and APP fields.
- Added explicit handling for both AXIDMA and MCDMA types with proper payload length calculation.
- Added WARN_ON_ONCE for unsupported DMA types.
- Removed the 'chan' field from struct xilinx_dma_tx_descriptor (was added in V2) as it's no longer needed; channel is obtained from tx->chan instead.
- Dropped V2 patches 4/5 (dt-bindings xlnx,include-stscntrl-strm) and 5/5 (xferred_bytes support) as the approach changed to use residue.
Changes in V2:
- Added support for MCDMA metadata handling alongside AXIDMA.
- Added 'chan' field to struct xilinx_dma_tx_descriptor.
--- drivers/dma/xilinx/xilinx_dma.c | 48 +++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-)
drivers/dma/xilinx/xilinx_dma.c +43 -5
@@ -651,17 +651,51 @@ static inline void xilinx_aximcdma_buf(struct xilinx_dma_chan *chan,* @tx: async transaction descriptor * @payload_len: metadata payload length * @max_len: metadata max length -* Return: The app field pointer. +* +* The metadata lives in the SOP descriptor for TX and the EOF descriptor for RX. +* Field order depends on dmatype and direction: +* +* AXI DMA: [0..] app +* AXI MCDMA (TX): [0] ctrl_sideband, [1] status, [2..] app +* AXI MCDMA (RX): [0] status, [1] sideband, [2..] app +* +* Return: Pointer to the first metadata word. */ static void *xilinx_dma_get_metadata_ptr (struct dma_async_tx_descriptor *tx,size_t *payload_len,size_t *max_len) {struct xilinx_dma_tx_descriptor *desc =to_dma_tx_descriptor (tx); +struct xilinx_dma_chan *chan =to_xilinx_chan (tx->chan); + +if (chan->xdev->dma_config->dmatype ==XDMA_TYPE_AXIMCDMA ) { +struct xilinx_aximcdma_tx_segment *seg; + +if (chan->direction ==DMA_DEV_TO_MEM ) { + seg =list_last_entry (&desc->segments, + struct xilinx_aximcdma_tx_segment, node); + *max_len = *payload_len =sizeof (seg->hw.s2mm_status) + +sizeof (seg->hw.s2mm_sideband_status) + +sizeof (seg->hw.app); +return &seg->hw.s2mm_status; + } + seg =list_first_entry (&desc->segments, + struct xilinx_aximcdma_tx_segment, node); + *max_len = *payload_len =sizeof (seg->hw.mm2s_ctrl_sideband) + +sizeof (seg->hw.mm2s_status) + +sizeof (seg->hw.app); +return &seg->hw.mm2s_ctrl_sideband; + } +struct xilinx_axidma_tx_segment *seg; - *max_len = *payload_len =sizeof (u32) *XILINX_DMA_NUM_APP_WORDS ; - seg =list_first_entry (&desc->segments, - struct xilinx_axidma_tx_segment, node); +if (chan->direction ==DMA_DEV_TO_MEM ) + seg =list_last_entry (&desc->segments, + struct xilinx_axidma_tx_segment, node); +else + seg =list_first_entry (&desc->segments, + struct xilinx_axidma_tx_segment, node); + + *max_len = *payload_len =sizeof (seg->hw.app);return seg->hw.app; }
@@ -2639,6 +2673,9 @@ xilinx_mcdma_prep_slave_sg(struct dma_chan *dchan, struct scatterlist *sgl, segment->hw.control |=XILINX_MCDMA_BD_EOP ; } +if (chan->xdev->has_axistream_connected) + desc->async_tx.metadata_ops = &xilinx_dma_metadata_ops; +return &desc->async_tx; error:
@@ -3287,7 +3324,8 @@ static int xilinx_dma_probe(struct platform_device *pdev)dma_set_max_seg_size (xdev->dev, xdev->max_buffer_len); -if (xdev->dma_config->dmatype ==XDMA_TYPE_AXIDMA ) { +if (xdev->dma_config->dmatype ==XDMA_TYPE_AXIDMA || + xdev->dma_config->dmatype ==XDMA_TYPE_AXIMCDMA ) { xdev->has_axistream_connected =of_property_read_bool (node,"xlnx,axistream-connected" ); }
Signature · 1 line
2.43.0
Re: [PATCH V6 4/4] dmaengine: xilinx_dma: Extend metadata handling for AXI DMA and MCDMA
Quoted 21 lines · Srinivas Neeli
From: Suraj Gupta <[email protected]>
xilinx_dma_get_metadata_ptr()returns the AXI DMA APP words from the SOP descriptor in both directions. This is wrong for RX, where the hardware writes the APP words into the EOF descriptor. It also leaves AXI MCDMA without metadata support.Return the metadata from the SOP descriptor for TX and from the EOF descriptor for RX, matching where the hardware reads and writes the fields. For AXI DMA, expose the APP words (20 bytes). For AXI MCDMA, expose the control sideband, status, and APP fields (28 bytes). On TX the control sideband holds TID and TUSER configuration for the outgoing stream. On RX the sideband status holds the received TID, TDEST and TUSER from the incoming stream. The field layout differs between MM2S and S2MM, and the wider payload lets a consumer distinguish the two controllers. No in-tree consumer is affected.
Read xlnx,axistream-connected for AXI MCDMA. Attach
metadata_opsinxilinx_mcdma_prep_slave_sg()when an AXI4-Stream interface is present, so MCDMA clients use the metadata API the same way as AXI DMA clients.
Quoted 5 lines
Signed-off-by Suraj Gupta <[email protected]>Co-developed-by Srinivas Neeli <[email protected]>Reviewed-by Radhey Shyam Pandey <[email protected]>Signed-off-by Srinivas Neeli <[email protected]>---
Quoted 129 lines
Changes in V6:
- Added Reviewed-by: Radhey Shyam Pandey tag.Changes in V5:
- Take the metadata pointer from the SOP descriptor for TX and the EOF descriptor for RX, matching where the hardware reads and writes the fields (TX previously used the EOF descriptor).
- AXI DMA now exposes only the APP words (20 bytes) in both directions, instead of the status word followed by APP (24 bytes).
- AXI MCDMA exposes the control sideband, status and APP fields (28 bytes), with the sideband position differing between MM2S and S2MM.
- Reworked the kernel-doc index table and commit message accordingly.Changes in V4:
- Restructuredxilinx_dma_get_metadata_ptr(): AXIDMA is now the fall-through path instead of a separate branch guarded by WARN_ON_ONCE()/ERR_PTR().
- Rewrote the kernel-doc as an index table covering AXI DMA, MCDMA S2MM and MCDMA MM2S, and documented that the pointer and payload length are the same for both MCDMA directions.
- Added an inline comment explaining the union aliasing.
- Condensed the commit message.Changes in V3:
- Renamed subject to include "AXI DMA and MCDMA" (was "AXI MCDMA" only).
- Complete rewrite of commit message and implementation.
- Metadata pointer now returns status field at index 0 instead of APP fields, exposing status and sideband information to clients.
- Changed fromlist_first_entrytolist_last_entryto return the EOF descriptor where hardware writes status and APP fields.
- Added explicit handling for both AXIDMA and MCDMA types with proper payload length calculation.
- AddedWARN_ON_ONCEfor unsupported DMA types.
- Removed the 'chan' field from structxilinx_dma_tx_descriptor(was added in V2) as it's no longer needed; channel is obtained fromtx->chaninstead.
- Dropped V2 patches 4/5 (dt-bindings xlnx,include-stscntrl-strm) and 5/5 (xferred_bytessupport) as the approach changed to use residue.Changes in V2:
- Added support for MCDMA metadata handling alongside AXIDMA.
- Added 'chan' field to structxilinx_dma_tx_descriptor.--- drivers/dma/xilinx/xilinx_dma.c | 48 +++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-)drivers/dma/xilinx/xilinx_dma.c +43
-6@@ -651,17 +651,51 @@ static inline void xilinx_aximcdma_buf(struct xilinx_dma_chan *chan,* @tx: async transaction descriptor * @payload_len: metadata payload length * @max_len: metadata max length -* Return: The app field pointer. +* +* The metadata lives in the SOP descriptor for TX and the EOF descriptor for RX. +* Field order depends on dmatype and direction: +* +* AXI DMA: [0..] app +* AXI MCDMA (TX): [0] ctrl_sideband, [1] status, [2..] app +* AXI MCDMA (RX): [0] status, [1] sideband, [2..] app +* +* Return: Pointer to the first metadata word. */ static void *xilinx_dma_get_metadata_ptr (struct dma_async_tx_descriptor *tx,size_t *payload_len,size_t *max_len) {struct xilinx_dma_tx_descriptor *desc =to_dma_tx_descriptor (tx); +struct xilinx_dma_chan *chan =to_xilinx_chan (tx->chan); + +if (chan->xdev->dma_config->dmatype ==XDMA_TYPE_AXIMCDMA ) { +struct xilinx_aximcdma_tx_segment *seg; + +if (chan->direction ==DMA_DEV_TO_MEM ) { + seg =list_last_entry (&desc->segments, + struct xilinx_aximcdma_tx_segment, node); + *max_len = *payload_len =sizeof (seg->hw.s2mm_status) + +sizeof (seg->hw.s2mm_sideband_status) + +sizeof (seg->hw.app); +return &seg->hw.s2mm_status; + } + seg =list_first_entry (&desc->segments, + struct xilinx_aximcdma_tx_segment, node); + *max_len = *payload_len =sizeof (seg->hw.mm2s_ctrl_sideband) + +sizeof (seg->hw.mm2s_status) + +sizeof (seg->hw.app); +return &seg->hw.mm2s_ctrl_sideband; + } +struct xilinx_axidma_tx_segment *seg; - *max_len = *payload_len =sizeof (u32) *XILINX_DMA_NUM_APP_WORDS ; - seg =list_first_entry (&desc->segments, - struct xilinx_axidma_tx_segment, node); +if (chan->direction ==DMA_DEV_TO_MEM ) + seg =list_last_entry (&desc->segments, + struct xilinx_axidma_tx_segment, node); +else + seg =list_first_entry (&desc->segments, + struct xilinx_axidma_tx_segment, node); + + *max_len = *payload_len =sizeof (seg->hw.app);return seg->hw.app; }@@ -2639,6 +2673,9 @@ xilinx_mcdma_prep_slave_sg(struct dma_chan *dchan, struct scatterlist *sgl, segment->hw.control |=XILINX_MCDMA_BD_EOP ; } +if (chan->xdev->has_axistream_connected) + desc->async_tx.metadata_ops = &xilinx_dma_metadata_ops; +return &desc->async_tx; error:@@ -3287,7 +3324,8 @@ static int xilinx_dma_probe(struct platform_device *pdev)dma_set_max_seg_size (xdev->dev, xdev->max_buffer_len); -if (xdev->dma_config->dmatype ==XDMA_TYPE_AXIDMA ) { +if (xdev->dma_config->dmatype ==XDMA_TYPE_AXIDMA || + xdev->dma_config->dmatype ==XDMA_TYPE_AXIMCDMA ) { xdev->has_axistream_connected =of_property_read_bool (node,"xlnx,axistream-connected" ); } --2.43.0
Re: (subset) [PATCH V6 0/4] dmaengine: xilinx_dma: MCDMA descriptor and metadata handling improvements
In reply to Srinivas NeeliQuoted 6 lines · Srinivas Neeli
This series improves the Xilinx AXI DMA and MCDMA driver's descriptor handling and metadata reporting. It fixes direction-specific descriptor field usage, ensures completion is based on the hardware completion bit (important with interrupt coalescing), and extends metadata handling to expose status and sideband fields alongside APP fields.
Quoted 6 lines
The axienet driver is updated to derive RX frame length from the standard dmaengine residue mechanism rather than descriptor APP fields, making it work on designs where the AXI4-Stream status/control interface is not present.
[...]
Applied, thanks!
[1/4] dmaengine: xilinx_dma: Fix MCDMA descriptor fields based on DMA direction
commit: c791d22ddd7b4940fa3c211b5ee7c5d4ce2d1dc3
[2/4] dmaengine: xilinx_dma: Move descriptors to done list based on completion bit
commit: 5af3ac5de34f9f7a4ae81c690d8dea5dcb523ab0
[4/4] dmaengine: xilinx_dma: Extend metadata handling for AXI DMA and MCDMA
commit: 37c44606eaac6f600fe2c602372bb02ef5ec0c53Best regards,
Signature · 1 line
~Vinod