Skip to contentSkip to conversation

dmaengine: xilinx_dma: MCDMA descriptor and metadata handling improvements

PATCH Superseded Srinivas Neeli 4 participants 12 messages Mar 13 – Apr 7

Subsystems (3)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover dmaengine: xilinx_dma: MCDMA descriptor and metadata handling improvements

This series improves the Xilinx AXI 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 delay interrupts), and extends metadata handling so APP fields are used when the AXI4-Stream status/control interface is enabled. When APP fields are unavailable, the series still reports transferred byte count via the status field, enabling clients to track progress in both configurations. Device tree bindings are updated to expose the status/control stream presence with a dedicated property, distinct from stream connectivity.

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 for MM2S vs S2MM
dmaengine: xilinx_dma: Move descriptors to done list based on
completion bit
dt-bindings: dma: xlnx,axi-dma: Add "xlnx,include-stscntrl-strm"
property

Suraj Gupta (2):
dmaengine: xilinx_dma: Extend metadata handling for AXI MCDMA
dmaengine: xilinx_dma: Add support for reporting transfer size to AXI
DMA / MCDMA client when app fields are unavailable

 .../bindings/dma/xilinx/xlnx,axi-dma.yaml     |  4 +
 drivers/dma/xilinx/xilinx_dma.c               | 93 ++++++++++++++++---
 2 files changed, 84 insertions(+), 13 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/5 dmaengine: xilinx_dma: Fix MCDMA descriptor fields for MM2S vs S2MM

The MCDMA BD format differs between MM2S and S2MM directions, but the driver was using generic 'status' and 'sideband_status' fields for both. This could lead to incorrect residue calculations when the hardware updates direction-specific fields.

Refactor the descriptor structure to use unions with direction-specific field names (mm2s_status/s2mm_status, etc.). This ensures the driver accesses the correct hardware fields based on channel direction and matches the hardware documentation.

Fixes 6ccd692bfb7f ("dmaengine: xilinx_dma: Add Xilinx AXI MCDMA Engine driver support")
---
 drivers/dma/xilinx/xilinx_dma.c | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)
drivers/dma/xilinx/xilinx_dma.c +22 -7
index b53292e02448..4a83492f2435 100644
@@ -275,8 +275,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 {
@@ -286,8 +288,14 @@ 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);
 
@@ -1013,9 +1021,16 @@ 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 - aximcdma_hw->status) &
-				chan->xdev->max_buffer_len;
+			if (chan->direction == DMA_DEV_TO_MEM)
+				residue +=
+					(aximcdma_hw->control -
+					 aximcdma_hw->s2mm_status) &
+					chan->xdev->max_buffer_len;
+			else
+				residue +=
+					(aximcdma_hw->control -
+					 aximcdma_hw->mm2s_status) &
+					chan->xdev->max_buffer_len;
 		}
 	}
 
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH V2 1/5] dmaengine: xilinx_dma: Fix MCDMA descriptor fields for MM2S vs S2MM

Quoted 1 line · Srinivas Neeli

The MCDMA BD format differs between MM2S and S2MM directions, but the

Can you use DMA_DEV_TO_MEM and DMA_MEM_TO_DEV instead of MM2S and S2MM? or memory to slave, at least first place need extend term MM2S(memory to slave).

Quoted 3 lines

driver was using generic 'status' and 'sideband_status' fields for both. This could lead to incorrect residue calculations when the hardware updates direction-specific fields.

driver was using generic 'status' and 'sideband_status' fields for both, which lead ... (use Affirmative Tone)

Quoted 3 lines

Refactor the descriptor structure to use unions with direction-specific field names (mm2s_status/s2mm_status, etc.). This ensures the driver

Ensure .. (needn't this)

Frank

Quoted 66 lines

accesses the correct hardware fields based on channel direction and matches the hardware documentation.

Fixes 6ccd692bfb7f ("dmaengine: xilinx_dma: Add Xilinx AXI MCDMA Engine driver support")
---
 drivers/dma/xilinx/xilinx_dma.c | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)
drivers/dma/xilinx/xilinx_dma.c +22 -8
index b53292e02448..4a83492f2435 100644
@@ -275,8 +275,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 {
@@ -286,8 +288,14 @@ 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);
 
@@ -1013,9 +1021,16 @@ 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 - aximcdma_hw->status) &
-				chan->xdev->max_buffer_len;
+			if (chan->direction == DMA_DEV_TO_MEM)
+				residue +=
+					(aximcdma_hw->control -
+					 aximcdma_hw->s2mm_status) &
+					chan->xdev->max_buffer_len;
+			else
+				residue +=
+					(aximcdma_hw->control -
+					 aximcdma_hw->mm2s_status) &
+					chan->xdev->max_buffer_len;
 		}
 	}
 
--

2.43.0

#3 lore raw

PATCH v2 2/5 dmaengine: xilinx_dma: Move descriptors to done list based on completion bit

In reply to Srinivas Neeli

In AXIMCDMA scatter-gather mode, the hardware sets the completion bit when a transfer finishes. The driver now checks this bit to free descriptors from the active list and move them to the done list.
This is required when interrupt delay timeout Dly_IrqEn is enabled, as interrupts may be triggered before the configured threshold is reached, even if not all descriptors have completed.

---
 drivers/dma/xilinx/xilinx_dma.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/dma/xilinx/xilinx_dma.c +12 -0
index 4a83492f2435..00200b4c2372 100644
@@ -1762,6 +1762,18 @@ 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;
+			bool completed;
+
+			seg = list_last_entry(&desc->segments,
+					      struct xilinx_aximcdma_tx_segment,
+					      node);
+			completed = (chan->direction == DMA_DEV_TO_MEM) ?
+				(seg->hw.s2mm_status & XILINX_DMA_BD_COMP_MASK) :
+				(seg->hw.mm2s_status & XILINX_DMA_BD_COMP_MASK);
+			if (!completed)
+				break;
 		}
 		if (chan->has_sg && chan->xdev->dma_config->dmatype !=
 		    XDMA_TYPE_VDMA)
Signature · 1 line
2.43.0
#4 lore raw

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

Quoted 3 lines · Srinivas Neeli

In AXIMCDMA scatter-gather mode, the hardware sets the completion bit when a transfer finishes. The driver now checks this bit to free descriptors from the active list and move them to the done list.

Add check complete bit because irq may be triggered before a configured threshold is reached when interrupt delay timeout Dly_IrqEn is enabled.

Frank

Quoted 35 lines

This is required when interrupt delay timeout Dly_IrqEn is enabled, as interrupts may be triggered before the configured threshold is reached, even if not all descriptors have completed.

---
 drivers/dma/xilinx/xilinx_dma.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/dma/xilinx/xilinx_dma.c +12 -1
index 4a83492f2435..00200b4c2372 100644
@@ -1762,6 +1762,18 @@ 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;
+			bool completed;
+
+			seg = list_last_entry(&desc->segments,
+					      struct xilinx_aximcdma_tx_segment,
+					      node);
+			completed = (chan->direction == DMA_DEV_TO_MEM) ?
+				(seg->hw.s2mm_status & XILINX_DMA_BD_COMP_MASK) :
+				(seg->hw.mm2s_status & XILINX_DMA_BD_COMP_MASK);
+			if (!completed)
+				break;
 		}
 		if (chan->has_sg && chan->xdev->dma_config->dmatype !=
 		    XDMA_TYPE_VDMA)
--

2.43.0

#5 lore raw

PATCH v2 3/5 dmaengine: xilinx_dma: Extend metadata handling for AXI MCDMA

In reply to Srinivas Neeli

From: Suraj Gupta <[email protected]>

Extend probe logic to detect AXI Stream connections for MCDMA. When an AXI Stream interface is present, metadata operations are enabled for the MCDMA channel. The xilinx_dma_get_metadata_ptr() is enhanced to retrieve metadata directly from MCDMA descriptors.
Add corresponding channel reference in struct xilinx_dma_tx_descriptor to retrieve associated channel.
These changes ensure proper metadata handling and accurate transfer size reporting for MCDMA transfers.

---
 drivers/dma/xilinx/xilinx_dma.c | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)
drivers/dma/xilinx/xilinx_dma.c +25 -5
index 00200b4c2372..52203d44e7a4 100644
@@ -222,6 +222,8 @@
 #define XILINX_MCDMA_BD_EOP			BIT(30)
 #define XILINX_MCDMA_BD_SOP			BIT(31)
 
+struct xilinx_dma_chan;
+
 /**
  * struct xilinx_vdma_desc_hw - Hardware Descriptor
  * @next_desc: Next Descriptor Pointer @0x00
@@ -371,6 +373,7 @@ struct xilinx_cdma_tx_segment {
 
 /**
  * struct xilinx_dma_tx_descriptor - Per Transaction structure
+ * @chan: DMA channel for which this descriptor is allocated
  * @async_tx: Async transaction descriptor
  * @segments: TX segments list
  * @node: Node in the channel descriptors list
@@ -379,6 +382,7 @@ struct xilinx_cdma_tx_segment {
  * @residue: Residue of the completed descriptor
  */
 struct xilinx_dma_tx_descriptor {
+	struct xilinx_dma_chan *chan;
 	struct dma_async_tx_descriptor async_tx;
 	struct list_head segments;
 	struct list_head node;
@@ -653,12 +657,23 @@ 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;
+	void *metadata_ptr;
+
+	if (desc->chan->xdev->dma_config->dmatype == XDMA_TYPE_AXIMCDMA) {
+		struct xilinx_aximcdma_tx_segment *seg;
 
+		seg = list_first_entry(&desc->segments,
+				       struct xilinx_aximcdma_tx_segment, node);
+		metadata_ptr = seg->hw.app;
+	} else {
+		struct xilinx_axidma_tx_segment *seg;
+
+		seg = list_first_entry(&desc->segments,
+				       struct xilinx_axidma_tx_segment, node);
+		metadata_ptr = seg->hw.app;
+	}
 	*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;
+	return metadata_ptr;
 }
 
 static struct dma_descriptor_metadata_ops xilinx_dma_metadata_ops = {
@@ -848,6 +863,7 @@ xilinx_dma_alloc_tx_descriptor(struct xilinx_dma_chan *chan)
 	if (!desc)
 		return NULL;
 
+	desc->chan = chan;
 	INIT_LIST_HEAD(&desc->segments);
 
 	return desc;
@@ -2613,6 +2629,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:
@@ -3261,7 +3280,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
#6 lore raw

Re: [PATCH V2 3/5] dmaengine: xilinx_dma: Extend metadata handling for AXI MCDMA

Quoted 6 lines · Srinivas Neeli

From: Suraj Gupta <[email protected]>

Extend probe logic to detect AXI Stream connections for MCDMA. When an AXI Stream interface is present, metadata operations are enabled for the MCDMA channel. The xilinx_dma_get_metadata_ptr() is enhanced to retrieve metadata directly from MCDMA descriptors.

Need extra empty line between paragraph

Quoted 34 lines

Add corresponding channel reference in struct xilinx_dma_tx_descriptor to retrieve associated channel.
These changes ensure proper metadata handling and accurate transfer size reporting for MCDMA transfers.

---
 drivers/dma/xilinx/xilinx_dma.c | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)
drivers/dma/xilinx/xilinx_dma.c +3 -0
index 00200b4c2372..52203d44e7a4 100644
@@ -222,6 +222,8 @@
 #define XILINX_MCDMA_BD_EOP			BIT(30)
 #define XILINX_MCDMA_BD_SOP			BIT(31)
 
+struct xilinx_dma_chan;
+
 /**
  * struct xilinx_vdma_desc_hw - Hardware Descriptor
  * @next_desc: Next Descriptor Pointer @0x00
@@ -371,6 +373,7 @@ struct xilinx_cdma_tx_segment {
 
 /**
  * struct xilinx_dma_tx_descriptor - Per Transaction structure
+ * @chan: DMA channel for which this descriptor is allocated
  * @async_tx: Async transaction descriptor
  * @segments: TX segments list
  * @node: Node in the channel descriptors list

drivers/dma/xilinx/xilinx_dma.c struct xilinx_cdma_tx_segment { · line 385

Quoted 4 lines
drivers/dma/xilinx/xilinx_dma.c +1 -0
@@ -379,6 +382,7 @@ struct xilinx_cdma_tx_segment {
  * @residue: Residue of the completed descriptor
  */
 struct xilinx_dma_tx_descriptor {
+	struct xilinx_dma_chan *chan;

async_tx already include dma_chan's information.

Frank

#7 lore raw

PATCH v2 4/5 dt-bindings: dma: xlnx,axi-dma: Add "xlnx,include-stscntrl-strm" property

In reply to Srinivas Neeli

Add an optional boolean DT property "xlnx,include-stscntrl-strm" to indicate that the AXI DMA IP is configured with the AXI4-Stream status and control interface. This enables the use of APP fields in DMA descriptors for metadata reporting.

This property is distinct from "xlnx,axistream-connected" and serves a different purpose:

- "xlnx,include-stscntrl-strm": Indicates whether APP fields are present in DMA descriptors. When enabled, the driver can access status/control metadata through these descriptor fields.

- "xlnx,axistream-connected": Indicates whether a streaming IP (client) is connected to the DMA IP.

These two configurations are independent of each other. For example, in TSN (Time-Sensitive Networking) designs, a streaming client may be connected to the DMA IP, but the status/control stream interface is not enabled. In such cases, "xlnx,axistream-connected" would be present while "xlnx,include-stscntrl-strm" would be absent.

Adding this property allows the driver to correctly determine descriptor layout and access APP fields only when the hardware supports them.

---
 .../devicetree/bindings/dma/xilinx/xlnx,axi-dma.yaml          | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/dma/xilinx/xlnx,axi-dma.yaml +4 -0
index 340ae9e91cb0..ad8afefe7ee3 100644
@@ -105,6 +105,10 @@ properties:
     type: boolean
     description: Tells whether DMA is connected to AXI stream IP.
 
+  xlnx,include-stscntrl-strm:
+    type: boolean
+    description: Tells hardware is configured with AXI4-stream status and control interface.
+
 patternProperties:
   "^dma-channel(-mm2s|-s2mm)?$":
     type: object
Signature · 1 line
2.43.0
maintainer Reviewed-by on v2 4/5
#8 lore raw

Re: [PATCH V2 4/5] dt-bindings: dma: xlnx,axi-dma: Add "xlnx,include-stscntrl-strm" property

Quoted 21 lines · Srinivas Neeli

Add an optional boolean DT property "xlnx,include-stscntrl-strm" to indicate that the AXI DMA IP is configured with the AXI4-Stream status and control interface. This enables the use of APP fields in DMA descriptors for metadata reporting.

This property is distinct from "xlnx,axistream-connected" and serves a different purpose:

- "xlnx,include-stscntrl-strm": Indicates whether APP fields are present in DMA descriptors. When enabled, the driver can access status/control metadata through these descriptor fields.

- "xlnx,axistream-connected": Indicates whether a streaming IP (client) is connected to the DMA IP.

These two configurations are independent of each other. For example, in TSN (Time-Sensitive Networking) designs, a streaming client may be connected to the DMA IP, but the status/control stream interface is not enabled. In such cases, "xlnx,axistream-connected" would be present while "xlnx,include-stscntrl-strm" would be absent.

Quoted 9 lines

Adding this property allows the driver to correctly determine descriptor layout and access APP fields only when the hardware supports them.

---
 .../devicetree/bindings/dma/xilinx/xlnx,axi-dma.yaml          | 4 ++++
 1 file changed, 4 insertions(+)
#9 lore raw

PATCH v2 5/5 dmaengine: xilinx_dma: Add support for reporting transfer size to AXI DMA / MCDMA client when app fields are unavailable

In reply to Srinivas Neeli

From: Suraj Gupta <[email protected]>

The AXI4-stream status and control interface is optional in the AXI DMA / MCDMA IP design; when it is not present, app fields are not available in DMA descriptor. In such cases, the transferred byte count can be communicated to the client using the status field (bits 0-25) of AXI DMA / MCDMA descriptor.

Add a xferred_bytes field to struct xilinx_dma_tx_descriptor to record the number of bytes transferred for each transaction. The value is calculated using the existing xilinx_dma_get_residue() function, which traverses all hardware descriptors associated with the async transaction descriptor, avoiding redundant traversal.

The driver uses the xlnx,include-stscntrl-strm device tree property to determine if the status/control stream interface is present and selects the appropriate metadata source accordingly.

---
 drivers/dma/xilinx/xilinx_dma.c | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)
drivers/dma/xilinx/xilinx_dma.c +24 -4
index 52203d44e7a4..f5ef03a1297c 100644
@@ -380,6 +380,8 @@ struct xilinx_cdma_tx_segment {
  * @cyclic: Check for cyclic transfers.
  * @err: Whether the descriptor has an error.
  * @residue: Residue of the completed descriptor
+ * @xferred_bytes: Number of bytes transferred by this transaction
+ *                 descriptor.
  */
 struct xilinx_dma_tx_descriptor {
 	struct xilinx_dma_chan *chan;
@@ -389,6 +391,7 @@ struct xilinx_dma_tx_descriptor {
 	bool cyclic;
 	bool err;
 	u32 residue;
+	u32 xferred_bytes;
 };
 
 /**
@@ -515,6 +518,7 @@ struct xilinx_dma_config {
  * @mm2s_chan_id: DMA mm2s channel identifier
  * @max_buffer_len: Max buffer length
  * @has_axistream_connected: AXI DMA connected to AXI Stream IP
+ * @has_stsctrl_stream: AXI4-stream status and control interface is enabled
  */
 struct xilinx_dma_device {
 	void __iomem *regs;
@@ -534,6 +538,7 @@ struct xilinx_dma_device {
 	u32 mm2s_chan_id;
 	u32 max_buffer_len;
 	bool has_axistream_connected;
+	bool has_stsctrl_stream;
 };
 
 /* Macros */
@@ -672,8 +677,12 @@ static void *xilinx_dma_get_metadata_ptr(struct dma_async_tx_descriptor *tx,
 				       struct xilinx_axidma_tx_segment, node);
 		metadata_ptr = seg->hw.app;
 	}
-	*max_len = *payload_len = sizeof(u32) * XILINX_DMA_NUM_APP_WORDS;
-	return metadata_ptr;
+	if (desc->chan->xdev->has_stsctrl_stream) {
+		*max_len = *payload_len = sizeof(u32) * XILINX_DMA_NUM_APP_WORDS;
+		return metadata_ptr;
+	}
+	*max_len = *payload_len = sizeof(desc->xferred_bytes);
+	return (void *)&desc->xferred_bytes;
 }
 
 static struct dma_descriptor_metadata_ops xilinx_dma_metadata_ops = {
@@ -864,6 +873,7 @@ xilinx_dma_alloc_tx_descriptor(struct xilinx_dma_chan *chan)
 		return NULL;
 
 	desc->chan = chan;
+	desc->xferred_bytes = 0;
 	INIT_LIST_HEAD(&desc->segments);
 
 	return desc;
@@ -1014,6 +1024,7 @@ static u32 xilinx_dma_get_residue(struct xilinx_dma_chan *chan,
 	struct xilinx_aximcdma_desc_hw *aximcdma_hw;
 	struct list_head *entry;
 	u32 residue = 0;
+	u32 xferred = 0;
 
 	list_for_each(entry, &desc->segments) {
 		if (chan->xdev->dma_config->dmatype == XDMA_TYPE_CDMA) {
@@ -1031,25 +1042,32 @@ static u32 xilinx_dma_get_residue(struct xilinx_dma_chan *chan,
 			axidma_hw = &axidma_seg->hw;
 			residue += (axidma_hw->control - axidma_hw->status) &
 				   chan->xdev->max_buffer_len;
+			xferred += axidma_hw->status & chan->xdev->max_buffer_len;
 		} else {
 			aximcdma_seg =
 				list_entry(entry,
 					   struct xilinx_aximcdma_tx_segment,
 					   node);
 			aximcdma_hw = &aximcdma_seg->hw;
-			if (chan->direction == DMA_DEV_TO_MEM)
+			if (chan->direction == DMA_DEV_TO_MEM) {
 				residue +=
 					(aximcdma_hw->control -
 					 aximcdma_hw->s2mm_status) &
 					chan->xdev->max_buffer_len;
-			else
+				xferred += aximcdma_hw->s2mm_status &
+					chan->xdev->max_buffer_len;
+			} else {
 				residue +=
 					(aximcdma_hw->control -
 					 aximcdma_hw->mm2s_status) &
 					chan->xdev->max_buffer_len;
+				xferred += aximcdma_hw->mm2s_status &
+					chan->xdev->max_buffer_len;
+			}
 		}
 	}
 
+	desc->xferred_bytes = xferred;
 	return residue;
 }
 
@@ -3284,6 +3302,8 @@ static int xilinx_dma_probe(struct platform_device *pdev)
 	    xdev->dma_config->dmatype == XDMA_TYPE_AXIMCDMA) {
 		xdev->has_axistream_connected =
 			of_property_read_bool(node, "xlnx,axistream-connected");
+		xdev->has_stsctrl_stream =
+			of_property_read_bool(node, "xlnx,include-stscntrl-strm");
 	}
 
 	if (xdev->dma_config->dmatype == XDMA_TYPE_VDMA) {
Signature · 1 line
2.43.0
#10 lore raw

Re: [PATCH V2 5/5] dmaengine: xilinx_dma: Add support for reporting transfer size to AXI DMA / MCDMA client when app fields are unavailable

Quoted 8 lines · Srinivas Neeli

From: Suraj Gupta <[email protected]>

The AXI4-stream status and control interface is optional in the AXI DMA / MCDMA IP design; when it is not present, app fields are not available in DMA descriptor. In such cases, the transferred byte count can be communicated to the client using the status field (bits 0-25) of AXI DMA / MCDMA descriptor.

Quoted 5 lines

Add a xferred_bytes field to struct xilinx_dma_tx_descriptor to record the number of bytes transferred for each transaction. The value is calculated using the existing xilinx_dma_get_residue() function, which traverses all hardware descriptors associated with the async transaction descriptor, avoiding redundant traversal.

Can you split this change to new patch?

Frank

Quoted 125 lines

The driver uses the xlnx,include-stscntrl-strm device tree property to determine if the status/control stream interface is present and selects the appropriate metadata source accordingly.

---
 drivers/dma/xilinx/xilinx_dma.c | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)
drivers/dma/xilinx/xilinx_dma.c +24 -5
index 52203d44e7a4..f5ef03a1297c 100644
@@ -380,6 +380,8 @@ struct xilinx_cdma_tx_segment {
  * @cyclic: Check for cyclic transfers.
  * @err: Whether the descriptor has an error.
  * @residue: Residue of the completed descriptor
+ * @xferred_bytes: Number of bytes transferred by this transaction
+ *                 descriptor.
  */
 struct xilinx_dma_tx_descriptor {
 	struct xilinx_dma_chan *chan;
@@ -389,6 +391,7 @@ struct xilinx_dma_tx_descriptor {
 	bool cyclic;
 	bool err;
 	u32 residue;
+	u32 xferred_bytes;
 };
 
 /**
@@ -515,6 +518,7 @@ struct xilinx_dma_config {
  * @mm2s_chan_id: DMA mm2s channel identifier
  * @max_buffer_len: Max buffer length
  * @has_axistream_connected: AXI DMA connected to AXI Stream IP
+ * @has_stsctrl_stream: AXI4-stream status and control interface is enabled
  */
 struct xilinx_dma_device {
 	void __iomem *regs;
@@ -534,6 +538,7 @@ struct xilinx_dma_device {
 	u32 mm2s_chan_id;
 	u32 max_buffer_len;
 	bool has_axistream_connected;
+	bool has_stsctrl_stream;
 };
 
 /* Macros */
@@ -672,8 +677,12 @@ static void *xilinx_dma_get_metadata_ptr(struct dma_async_tx_descriptor *tx,
 				       struct xilinx_axidma_tx_segment, node);
 		metadata_ptr = seg->hw.app;
 	}
-	*max_len = *payload_len = sizeof(u32) * XILINX_DMA_NUM_APP_WORDS;
-	return metadata_ptr;
+	if (desc->chan->xdev->has_stsctrl_stream) {
+		*max_len = *payload_len = sizeof(u32) * XILINX_DMA_NUM_APP_WORDS;
+		return metadata_ptr;
+	}
+	*max_len = *payload_len = sizeof(desc->xferred_bytes);
+	return (void *)&desc->xferred_bytes;
 }
 
 static struct dma_descriptor_metadata_ops xilinx_dma_metadata_ops = {
@@ -864,6 +873,7 @@ xilinx_dma_alloc_tx_descriptor(struct xilinx_dma_chan *chan)
 		return NULL;
 
 	desc->chan = chan;
+	desc->xferred_bytes = 0;
 	INIT_LIST_HEAD(&desc->segments);
 
 	return desc;
@@ -1014,6 +1024,7 @@ static u32 xilinx_dma_get_residue(struct xilinx_dma_chan *chan,
 	struct xilinx_aximcdma_desc_hw *aximcdma_hw;
 	struct list_head *entry;
 	u32 residue = 0;
+	u32 xferred = 0;
 
 	list_for_each(entry, &desc->segments) {
 		if (chan->xdev->dma_config->dmatype == XDMA_TYPE_CDMA) {
@@ -1031,25 +1042,32 @@ static u32 xilinx_dma_get_residue(struct xilinx_dma_chan *chan,
 			axidma_hw = &axidma_seg->hw;
 			residue += (axidma_hw->control - axidma_hw->status) &
 				   chan->xdev->max_buffer_len;
+			xferred += axidma_hw->status & chan->xdev->max_buffer_len;
 		} else {
 			aximcdma_seg =
 				list_entry(entry,
 					   struct xilinx_aximcdma_tx_segment,
 					   node);
 			aximcdma_hw = &aximcdma_seg->hw;
-			if (chan->direction == DMA_DEV_TO_MEM)
+			if (chan->direction == DMA_DEV_TO_MEM) {
 				residue +=
 					(aximcdma_hw->control -
 					 aximcdma_hw->s2mm_status) &
 					chan->xdev->max_buffer_len;
-			else
+				xferred += aximcdma_hw->s2mm_status &
+					chan->xdev->max_buffer_len;
+			} else {
 				residue +=
 					(aximcdma_hw->control -
 					 aximcdma_hw->mm2s_status) &
 					chan->xdev->max_buffer_len;
+				xferred += aximcdma_hw->mm2s_status &
+					chan->xdev->max_buffer_len;
+			}
 		}
 	}
 
+	desc->xferred_bytes = xferred;
 	return residue;
 }
 
@@ -3284,6 +3302,8 @@ static int xilinx_dma_probe(struct platform_device *pdev)
 	    xdev->dma_config->dmatype == XDMA_TYPE_AXIMCDMA) {
 		xdev->has_axistream_connected =
 			of_property_read_bool(node, "xlnx,axistream-connected");
+		xdev->has_stsctrl_stream =
+			of_property_read_bool(node, "xlnx,include-stscntrl-strm");
 	}
 
 	if (xdev->dma_config->dmatype == XDMA_TYPE_VDMA) {
--

2.43.0

#11 lore raw

Re: [PATCH V2 5/5] dmaengine: xilinx_dma: Add support for reporting transfer size to AXI DMA / MCDMA client when app fields are unavailable

Hi Frank,

Quoted 9 lines · Frank Li
Quoted 8 lines · Srinivas Neeli

From: Suraj Gupta <[email protected]>

The AXI4-stream status and control interface is optional in the AXI DMA / MCDMA IP design; when it is not present, app fields are not available in DMA descriptor. In such cases, the transferred byte count can be communicated to the client using the status field (bits 0-25) of AXI DMA / MCDMA descriptor.

Quoted 8 lines
Quoted 5 lines

Add a xferred_bytes field to struct xilinx_dma_tx_descriptor to record the number of bytes transferred for each transaction. The value is calculated using the existing xilinx_dma_get_residue() function, which traverses all hardware descriptors associated with the async transaction descriptor, avoiding redundant traversal.

Can you split this change to new patch?

Frank

The changes related to the xferred_bytes field and the has_stsctrl_stream property are tightly coupled and cannot be cleanly separated without breaking functionality or resulting in incomplete commits. The xferred_bytes field does not serve any meaningful purpose without the has_stsctrl_stream check:
- xferred_bytes is computed in xilinx_dma_get_residue(), but it is only exposed to clients through xilinx_dma_get_metadata_ptr().
- The metadata accessor relies on has_stsctrl_stream to determine whether to return APP fields or xferred_bytes.
- Without this conditional logic, xferred_bytes would still be calculated but would never be consumed by any client

Thanks

Neeli Srinivas

Quoted 124 lines
Quoted 124 lines

The driver uses the xlnx,include-stscntrl-strm device tree property to determine if the status/control stream interface is present and selects the appropriate metadata source accordingly.

---
  drivers/dma/xilinx/xilinx_dma.c | 28 ++++++++++++++++++++++++----
  1 file changed, 24 insertions(+), 4 deletions(-)
drivers/dma/xilinx/xilinx_dma.c +24 -5
index 52203d44e7a4..f5ef03a1297c 100644
@@ -380,6 +380,8 @@ struct xilinx_cdma_tx_segment {
   * @cyclic: Check for cyclic transfers.
   * @err: Whether the descriptor has an error.
   * @residue: Residue of the completed descriptor
+ * @xferred_bytes: Number of bytes transferred by this transaction
+ *                 descriptor.
   */
  struct xilinx_dma_tx_descriptor {
  	struct xilinx_dma_chan *chan;
@@ -389,6 +391,7 @@ struct xilinx_dma_tx_descriptor {
  	bool cyclic;
  	bool err;
  	u32 residue;
+	u32 xferred_bytes;
  };
 
  /**
@@ -515,6 +518,7 @@ struct xilinx_dma_config {
   * @mm2s_chan_id: DMA mm2s channel identifier
   * @max_buffer_len: Max buffer length
   * @has_axistream_connected: AXI DMA connected to AXI Stream IP
+ * @has_stsctrl_stream: AXI4-stream status and control interface is enabled
   */
  struct xilinx_dma_device {
  	void __iomem *regs;
@@ -534,6 +538,7 @@ struct xilinx_dma_device {
  	u32 mm2s_chan_id;
  	u32 max_buffer_len;
  	bool has_axistream_connected;
+	bool has_stsctrl_stream;
  };
 
  /* Macros */
@@ -672,8 +677,12 @@ static void *xilinx_dma_get_metadata_ptr(struct dma_async_tx_descriptor *tx,
  				       struct xilinx_axidma_tx_segment, node);
  		metadata_ptr = seg->hw.app;
  	}
-	*max_len = *payload_len = sizeof(u32) * XILINX_DMA_NUM_APP_WORDS;
-	return metadata_ptr;
+	if (desc->chan->xdev->has_stsctrl_stream) {
+		*max_len = *payload_len = sizeof(u32) * XILINX_DMA_NUM_APP_WORDS;
+		return metadata_ptr;
+	}
+	*max_len = *payload_len = sizeof(desc->xferred_bytes);
+	return (void *)&desc->xferred_bytes;
  }
 
  static struct dma_descriptor_metadata_ops xilinx_dma_metadata_ops = {
@@ -864,6 +873,7 @@ xilinx_dma_alloc_tx_descriptor(struct xilinx_dma_chan *chan)
  		return NULL;
 
  	desc->chan = chan;
+	desc->xferred_bytes = 0;
  	INIT_LIST_HEAD(&desc->segments);
 
  	return desc;
@@ -1014,6 +1024,7 @@ static u32 xilinx_dma_get_residue(struct xilinx_dma_chan *chan,
  	struct xilinx_aximcdma_desc_hw *aximcdma_hw;
  	struct list_head *entry;
  	u32 residue = 0;
+	u32 xferred = 0;
 
  	list_for_each(entry, &desc->segments) {
  		if (chan->xdev->dma_config->dmatype == XDMA_TYPE_CDMA) {
@@ -1031,25 +1042,32 @@ static u32 xilinx_dma_get_residue(struct xilinx_dma_chan *chan,
  			axidma_hw = &axidma_seg->hw;
  			residue += (axidma_hw->control - axidma_hw->status) &
  				   chan->xdev->max_buffer_len;
+			xferred += axidma_hw->status & chan->xdev->max_buffer_len;
  		} else {
  			aximcdma_seg =
  				list_entry(entry,
  					   struct xilinx_aximcdma_tx_segment,
  					   node);
  			aximcdma_hw = &aximcdma_seg->hw;
-			if (chan->direction == DMA_DEV_TO_MEM)
+			if (chan->direction == DMA_DEV_TO_MEM) {
  				residue +=
  					(aximcdma_hw->control -
  					 aximcdma_hw->s2mm_status) &
  					chan->xdev->max_buffer_len;
-			else
+				xferred += aximcdma_hw->s2mm_status &
+					chan->xdev->max_buffer_len;
+			} else {
  				residue +=
  					(aximcdma_hw->control -
  					 aximcdma_hw->mm2s_status) &
  					chan->xdev->max_buffer_len;
+				xferred += aximcdma_hw->mm2s_status &
+					chan->xdev->max_buffer_len;
+			}
  		}
  	}
 
+	desc->xferred_bytes = xferred;
  	return residue;
  }
 
@@ -3284,6 +3302,8 @@ static int xilinx_dma_probe(struct platform_device *pdev)
  	    xdev->dma_config->dmatype == XDMA_TYPE_AXIMCDMA) {
  		xdev->has_axistream_connected =
  			of_property_read_bool(node, "xlnx,axistream-connected");
+		xdev->has_stsctrl_stream =
+			of_property_read_bool(node, "xlnx,include-stscntrl-strm");
  	}
 
  	if (xdev->dma_config->dmatype == XDMA_TYPE_VDMA) {
--

2.43.0