Skip to contentSkip to conversation

dmaengine: xilinx_dma: MCDMA descriptor and metadata handling improvements

PATCH Superseded Srinivas Neeli 3 participants 10 messages Jul 13 – Jul 14

Subsystems (5)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 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 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               | 86 ++++++++++++++++---
 .../net/ethernet/xilinx/xilinx_axienet_main.c | 14 ++-
 2 files changed, 77 insertions(+), 23 deletions(-)

--
2.25.1

#1 lore raw

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

Fixes 6ccd692bfb7f ("dmaengine: xilinx_dma: Add Xilinx AXI MCDMA Engine driver support")

---
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
index 98b41b8f8915..ff5b29a808e9 100644
@@ -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.25.1
#2 lore raw

PATCH v4 2/4 dmaengine: xilinx_dma: Move descriptors to done list based on completion bit

In reply to Srinivas Neeli

In 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").

Fixes 6ccd692bfb7f ("dmaengine: xilinx_dma: Add Xilinx AXI MCDMA Engine driver support")

---
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
index ff5b29a808e9..1b5b00f08c5f 100644
@@ -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.25.1
#7 lore raw

PATCH v4 4/4 dmaengine: xilinx_dma: Extend metadata handling for AXI DMA and MCDMA

In reply to Srinivas Neeli

From: Suraj Gupta <[email protected]>

xilinx_dma_get_metadata_ptr() exposed only the descriptor APP fields. Each descriptor also carries a status word, and AXI MCDMA carries an AXI4-Stream sideband word holding TID, TDEST and TUSER that clients may need. Return a pointer to the status word so clients can read the status, the sideband and the APP fields together. The exact index layout is documented at the function.

Take the pointer from the End-Of-Frame descriptor, where the hardware writes these fields. For AXI DMA the pointer now starts at the status word of the EOF descriptor instead of the APP fields of the first descriptor, and the payload grows from 20 to 24 bytes. No in-tree consumer is affected, since axienet reads the RX frame length from result->residue rather than the APP fields.

Read xlnx,axistream-connected for MCDMA as well, and attach metadata_ops in xilinx_mcdma_prep_slave_sg() when an AXI Stream interface is present, so MCDMA clients use the metadata API the same way as AXI DMA clients.

---
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 | 49 ++++++++++++++++++++++++++++-----
 1 file changed, 42 insertions(+), 7 deletions(-)
drivers/dma/xilinx/xilinx_dma.c +42 -7
index 1b5b00f08c5f..2be95f0ba3ea 100644
@@ -651,18 +651,49 @@ 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 hardware writes the status, sideband and APP fields into the last
+ * (End-Of-Frame) descriptor. These words are contiguous, so a client reads
+ * them by index from the returned pointer:
+ *
+ *   AXI DMA:          [0] status,        [1..] app
+ *   AXI MCDMA (S2MM): [0] status,        [1] sideband (TID/TDEST/TUSER), [2..] app
+ *   AXI MCDMA (MM2S): [0] ctrl sideband, [1] status,                     [2..] app
+ *
+ * For MCDMA the pointer and payload length are the same in both directions
+ * because the union members overlay the same descriptor words.
+ *
+ * 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_axidma_tx_segment *seg;
+	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 =
+			list_last_entry(&desc->segments,
+					struct xilinx_aximcdma_tx_segment, node);
 
-	*max_len = *payload_len = sizeof(u32) * XILINX_DMA_NUM_APP_WORDS;
-	seg = list_first_entry(&desc->segments,
-			       struct xilinx_axidma_tx_segment, node);
-	return seg->hw.app;
+		/*
+		 * The union members overlay the same words, so one pointer and
+		 * length cover both directions (see the layout above).
+		 */
+		*max_len = *payload_len = sizeof(seg->hw.s2mm_status) +
+					  sizeof(seg->hw.s2mm_sideband_status) +
+					  sizeof(seg->hw.app);
+		return &seg->hw.s2mm_status;
+	}
+
+	/* Only AXIDMA and MCDMA attach metadata_ops, so this is AXIDMA. */
+	struct xilinx_axidma_tx_segment *seg =
+		list_last_entry(&desc->segments,
+				struct xilinx_axidma_tx_segment, node);
+
+	*max_len = *payload_len = sizeof(seg->hw.status) +
+				  sizeof(seg->hw.app);
+	return &seg->hw.status;
 }
 
 static struct dma_descriptor_metadata_ops xilinx_dma_metadata_ops = {
@@ -2639,6 +2670,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 +3321,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.25.1
#4 lore raw

PATCH v4 3/4 net: xilinx: axienet: Derive RX frame length from residue in dmaengine path

In reply to 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_APP macro.

The transmit path is unaffected. It still passes APP metadata for checksum offload and derives its length from the skb.

---
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
index fcf517069d16..67d1b8e91d68 100644
@@ -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.25.1
Reviewed-by Radhey Shyam Pandey on v4 3/4
#5 lore raw

Re: [PATCH v4 3/4] net: xilinx: axienet: Derive RX frame length from residue in dmaengine path

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

Quoted 8 lines

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.

Thanks!

Quoted 67 lines

---
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
index fcf517069d16..67d1b8e91d68 100644
@@ -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;
Reviewed-by Radhey Shyam Pandey on v4 4/4
#8 lore raw

Re: [PATCH v4 4/4] dmaengine: xilinx_dma: Extend metadata handling for AXI DMA and MCDMA

In reply to Srinivas Neeli
Quoted 16 lines

From: Suraj Gupta <[email protected]>

xilinx_dma_get_metadata_ptr() exposed only the descriptor APP fields. Each descriptor also carries a status word, and AXI MCDMA carries an AXI4-Stream sideband word holding TID, TDEST and TUSER that clients may need. Return a pointer to the status word so clients can read the status, the sideband and the APP fields together. The exact index layout is documented at the function.

Take the pointer from the End-Of-Frame descriptor, where the hardware writes these fields. For AXI DMA the pointer now starts at the status word of the EOF descriptor instead of the APP fields of the first descriptor, and the payload grows from 20 to 24 bytes. No in-tree consumer is affected, since axienet reads the RX frame length from result->residue rather than the APP fields.

Quoted 7 lines

Read xlnx,axistream-connected for MCDMA as well, and attach metadata_ops in xilinx_mcdma_prep_slave_sg() when an AXI Stream interface is present, so MCDMA clients use the metadata API the same way as AXI DMA clients.

Thanks!

Quoted 114 lines

---
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 | 49 ++++++++++++++++++++++++++++-----
  1 file changed, 42 insertions(+), 7 deletions(-)
drivers/dma/xilinx/xilinx_dma.c +42 -7
index 1b5b00f08c5f..2be95f0ba3ea 100644
@@ -651,18 +651,49 @@ 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 hardware writes the status, sideband and APP fields into the last
+ * (End-Of-Frame) descriptor. These words are contiguous, so a client reads
+ * them by index from the returned pointer:
+ *
+ *   AXI DMA:          [0] status,        [1..] app
+ *   AXI MCDMA (S2MM): [0] status,        [1] sideband (TID/TDEST/TUSER), [2..] app
+ *   AXI MCDMA (MM2S): [0] ctrl sideband, [1] status,                     [2..] app
+ *
+ * For MCDMA the pointer and payload length are the same in both directions
+ * because the union members overlay the same descriptor words.
+ *
+ * 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_axidma_tx_segment *seg;
+	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 =
+			list_last_entry(&desc->segments,
+					struct xilinx_aximcdma_tx_segment, node);
 
-	*max_len = *payload_len = sizeof(u32) * XILINX_DMA_NUM_APP_WORDS;
-	seg = list_first_entry(&desc->segments,
-			       struct xilinx_axidma_tx_segment, node);
-	return seg->hw.app;
+		/*
+		 * The union members overlay the same words, so one pointer and
+		 * length cover both directions (see the layout above).
+		 */
+		*max_len = *payload_len = sizeof(seg->hw.s2mm_status) +
+					  sizeof(seg->hw.s2mm_sideband_status) +
+					  sizeof(seg->hw.app);
+		return &seg->hw.s2mm_status;
+	}
+
+	/* Only AXIDMA and MCDMA attach metadata_ops, so this is AXIDMA. */
+	struct xilinx_axidma_tx_segment *seg =
+		list_last_entry(&desc->segments,
+				struct xilinx_axidma_tx_segment, node);
+
+	*max_len = *payload_len = sizeof(seg->hw.status) +
+				  sizeof(seg->hw.app);
+	return &seg->hw.status;
  }
 
  static struct dma_descriptor_metadata_ops xilinx_dma_metadata_ops = {
@@ -2639,6 +2670,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 +3321,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");
  	}
#3 lore raw

Re: [PATCH v4 2/4] dmaengine: xilinx_dma: Move descriptors to done list based on completion bit

In reply to Srinivas Neeli
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

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

New issues:
- [High] Unconditionally setting chan->idle = true after an early loop break causes the driver to incorrectly assume the DMA hardware has stopped, leading to channel corruption.
- [High] Missing read memory barrier (dma_rmb()) after polling the DMA descriptor completion bit from coherent memory.

Pre-existing issues:
- [High] MCDMA delay interrupt does not complete descriptors, causing descriptors stranded on active_list to hang indefinitely. --

--- Patch [2]: [PATCH v4 2/4] dmaengine: xilinx_dma: Move descriptors to done list based on completion bit --- commit 8891a603d60f283d523f7e4fb993dc400bd9bd8e
Author: Srinivas Neeli <[email protected]>
Subject: dmaengine: xilinx_dma: Move descriptors to done list based on completion bit

This commit modifies the MCDMA completion logic to check the descriptor completion bit before moving entries from the active list to the done list. This addresses an issue where interrupt coalescing could cause descriptors to be reported as completed prematurely.

Quoted 9 lines
drivers/dma/xilinx/xilinx_dma.c +1 -0
index 965fb69a2a3ad..9b8b6f1acd4ea 100644
@@ -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]
Does this code need a read memory barrier (dma_rmb()) here?

Since the status is read from coherent memory, weakly-ordered CPU architectures might speculatively reorder the reads of the segment payloads and status fields to occur before the completion bit check resolves. This could lead to reading stale, pre-transfer data from the descriptor or the actual DMA buffer, causing incorrect residue reporting or corrupted network packets.

[Severity: High]
Also, when this breaks early, unfinished descriptors are left in active_list. Will this cause a DMA channel hang? Looking at xilinx_mcdma_irq_handler():

xilinx_mcdma_irq_handler() {
    ...
    if (status & XILINX_MCDMA_IRQ_IOC_MASK) {
        spin_lock(&chan->lock);
        xilinx_dma_complete_descriptor(chan);
        chan->idle = true;
        chan->start_transfer(chan);
        spin_unlock(&chan->lock);
    }
    ...
}

The interrupt handler unconditionally sets chan->idle = true and calls chan->start_transfer(), even if active descriptors are still running due to the early break.

Since chan->idle is true, start_transfer() attempts to program the CDESC and TDESC registers with new, unlinked descriptors from pending_list while the hardware is actively processing active_list, which seems invalid and likely to cause a complete hardware desynchronization.

[Severity: High]
This is a pre-existing issue, but this patch highlights a fatal flaw for small transfers. Unlike the standard AXI DMA handler, xilinx_mcdma_irq_handler() does not invoke xilinx_dma_complete_descriptor() on a delay interrupt:

xilinx_mcdma_irq_handler() {
    ...
    if (status & XILINX_MCDMA_IRQ_DELAY_MASK) {
        /*
         * Device takes too long to do the transfer when user requires
         * responsiveness.
         */
        dev_dbg(chan->dev, "Inter-packet latency too long\n");
    }
    ...
}

If the number of submitted descriptors is below the interrupt coalescing threshold, the hardware triggers a delay interrupt instead of an IOC interrupt. Since the delay interrupt doesn't complete descriptors, trailing segments will remain stranded in active_list indefinitely because they are never processed, causing a channel hang.

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
#6 lore raw

Re: [PATCH v4 3/4] net: xilinx: axienet: Derive RX frame length from residue in dmaengine path

In reply to Srinivas Neeli
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:

Pre-existing issues:
- [High] The dmaengine teardown path leaks all in-flight SKBs and DMA mappings when the interface is stopped. --

--- Patch [3]: [PATCH v4 3/4] net: xilinx: axienet: Derive RX frame length from residue in dmaengine path --- commit 99e70bd1e2ac117d993d11234fd0dea54d95440b
Author: Srinivas Neeli <[email protected]>
Subject: net: xilinx: axienet: Derive RX frame length from residue in dmaengine path

This commit updates the dmaengine RX path to derive the received frame length from the dmaengine residue rather than descriptor APP metadata. This removes the dependency on the optional AXI4-Stream status/control interface.

drivers/net/ethernet/xilinx/xilinx_axienet_main.c

Quoted 5 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -0
index fcf517069d161..67d1b8e91d683 100644
@@ -53,7 +53,6 @@

[ ... ]

While reviewing this code, I noticed a pre-existing issue in axienet_stop():

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);
    ...
}

[Severity: High]
This is a pre-existing issue, but does this dmaengine teardown path leak all in-flight SKBs and DMA mappings when the interface is stopped?

When using dmaengine, the DMA channels are terminated which aborts transfers without calling completion callbacks. The code then iterates through the descriptor arrays and frees each skbuf_dma_descriptor container.

It appears to fail to unmap the dma_address and free the actual skb stored within the descriptor.

Could toggling the interface down and up repeatedly leak the entire RX ring and any pending TX SKBs along with their DMA mappings, potentially exhausting system memory and IOMMU space over time?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#9 lore raw

Re: [PATCH v4 4/4] dmaengine: xilinx_dma: Extend metadata handling for AXI DMA and MCDMA

In reply to Srinivas Neeli
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

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

New issues:
- [Medium] xilinx_dma_get_metadata_ptr() incorrectly returns the End-Of-Frame (EOF) descriptor's metadata for TX (MM2S) operations, breaking TX metadata offload and corrupting completion status.

Pre-existing issues:
- [High] Providing a scatterlist with zero sg_len or zero sg_dma_len entries results in an empty desc->segments list, causing out-of-bounds memory corruption in prep functions.
- [High] Missing channel lock when freeing DMA segments on descriptor preparation error paths leads to free_seg_list corruption.
--

--- Patch [4]: [PATCH v4 4/4] dmaengine: xilinx_dma: Extend metadata handling for AXI DMA and MCDMA --- commit 416ce331f02cd7e51a8987299d3d59436877b288
Author: Suraj Gupta <[email protected]>

dmaengine: xilinx_dma: Extend metadata handling for AXI DMA and MCDMA

This patch extends metadata handling to AXI MCDMA and exposes descriptor status words in addition to the APP fields. It modifies the metadata API to fetch fields from the End-Of-Frame descriptor, and attaches metadata operations for MCDMA when an AXI Stream interface is present.

Quoted 5 lines
drivers/dma/xilinx/xilinx_dma.c +0 -0
index 9b8b6f1acd4ea..0b7bc6ab27cbe 100644
@@ -649,18 +649,49 @@ static inline void xilinx_aximcdma_buf(struct xilinx_dma_chan *chan,

[ ... ]

drivers/dma/xilinx/xilinx_dma.c static inline void xilinx_aximcdma_buf(struct xilinx_dma_chan *chan, · line 677

Quoted 11 lines

static void *xilinx_dma_get_metadata_ptr(struct dma_async_tx_descriptor *tx,

drivers/dma/xilinx/xilinx_dma.c +6 -1
 					 size_t *payload_len, size_t *max_len)
 {
 	struct xilinx_dma_tx_descriptor *desc = to_dma_tx_descriptor(tx);
-	struct xilinx_axidma_tx_segment *seg;
+	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 =
+			list_last_entry(&desc->segments,
+					struct xilinx_aximcdma_tx_segment, node);

[Severity: Medium]
Does using list_last_entry() unconditionally for both directions break TX (MM2S) metadata offload?

Hardware strictly reads transmit control, sideband, and APP data from the Start-Of-Frame (SOP) descriptor, not the EOF descriptor.

Additionally, for MCDMA, since the returned pointer overlays the mm2s_status field, could a client writing to this array before submission accidentally set the completion bit and cause premature descriptor completion?

Quoted 15 lines
drivers/dma/xilinx/xilinx_dma.c +10 -5
-
-	*max_len = *payload_len = sizeof(u32) * XILINX_DMA_NUM_APP_WORDS;
-	seg = list_first_entry(&desc->segments,
-			       struct xilinx_axidma_tx_segment, node);
-	return seg->hw.app;
+
+		/*
+		 * The union members overlay the same words, so one pointer and
+		 * length cover both directions (see the layout above).
+		 */
+		*max_len = *payload_len = sizeof(seg->hw.s2mm_status) +
+					  sizeof(seg->hw.s2mm_sideband_status) +
+					  sizeof(seg->hw.app);
+		return &seg->hw.s2mm_status;
+	}

[ ... ]

drivers/dma/xilinx/xilinx_dma.c xilinx_mcdma_prep_slave_sg(struct dma_chan *dchan, struct scatterlist *sgl, · line 2655

Quoted 3 lines
drivers/dma/xilinx/xilinx_dma.c +0 -0
@@ -2623,6 +2654,9 @@ xilinx_mcdma_prep_slave_sg(struct dma_chan *dchan, struct scatterlist *sgl,
 		segment->hw.control |= XILINX_MCDMA_BD_EOP;
 	}

[Severity: High]
This is a pre-existing issue, but if a client provides a scatterlist with a zero sg_len or where all entries have zero length, desc->segments will be empty after the loop.

Looking slightly above this context in xilinx_mcdma_prep_slave_sg(), the code calls list_first_entry() and list_last_entry() on desc->segments without checking if it is empty:

xilinx_mcdma_prep_slave_sg() {
    ...
    segment = list_first_entry(&desc->segments, ...);
    desc->async_tx.phys = segment->phys;
    ...
    if (chan->direction == DMA_MEM_TO_DEV) {
        segment->hw.control |= XILINX_MCDMA_BD_SOP;
        ...
}

Doesn't this evaluate to an out-of-bounds pointer within desc->async_tx, potentially corrupting desc->async_tx.callback when segment->hw.control is overwritten? The same pattern appears to exist in xilinx_dma_prep_slave_sg().

drivers/dma/xilinx/xilinx_dma.c xilinx_mcdma_prep_slave_sg(struct dma_chan *dchan, struct scatterlist *sgl, · line 2678

Quoted 7 lines
drivers/dma/xilinx/xilinx_dma.c +3 -0
+	if (chan->xdev->has_axistream_connected)
+		desc->async_tx.metadata_ops = &xilinx_dma_metadata_ops;
+
 	return &desc->async_tx;
 
 error:

[Severity: High]
This isn't a bug introduced by this patch, but does the error path in xilinx_mcdma_prep_slave_sg() corrupt chan->free_seg_list?

When jumping to the error label, xilinx_dma_free_tx_descriptor() is called, which subsequently calls xilinx_mcdma_free_tx_segment(). This adds the segment to chan->free_seg_list via list_add_tail() without acquiring chan->lock.

Can this race with concurrent successful allocations (which acquire the lock) and tasklet cleanups?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4