Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: Frank Li <Frank.Li@nxp.com>
To: Vinod Koul <vkoul@kernel.org>
Cc: linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org,
	 imx@lists.linux.dev, joy.zou@nxp.com,
	Frank Li <Frank.Li@nxp.com>
Subject: [PATCH RFC 09/12] dmaengine: ll-dma: support multi-descriptor memcpy for large transfers
Date: Wed, 28 Jan 2026 13:05:28 -0500	[thread overview]
Message-ID: <20260128-dma_ll_comlib-v1-9-1b1fa2c671f9@nxp.com> (raw)
In-Reply-To: <20260128-dma_ll_comlib-v1-0-1b1fa2c671f9@nxp.com>

Each DMA descriptor has a maximum transfer length limitation.
When a memcpy request exceeds this limit, split it into multiple
linked DMA descriptors to complete the transfer.

Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
 drivers/dma/ll-dma.c | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/drivers/dma/ll-dma.c b/drivers/dma/ll-dma.c
index da13ba4dcdfe403af0ad3678bf4c0ff60f715a63..313ca274df945081fc569ddb6a172298c25bc11c 100644
--- a/drivers/dma/ll-dma.c
+++ b/drivers/dma/ll-dma.c
@@ -17,6 +17,7 @@
  */
 #include <linux/cleanup.h>
 #include <linux/device.h>
+#include <linux/dma-mapping.h>
 #include <linux/dmapool.h>
 #include <linux/dmaengine.h>
 #include <linux/module.h>
@@ -76,6 +77,15 @@ struct dma_ll_desc *vchan_dma_ll_alloc_desc(struct dma_chan *chan, u32 n,
 			goto err;
 
 		memset(desc->its[i].vaddr, 0, vchan->ll.size);
+
+		if (!i)
+			continue;
+
+		if (vchan->ll.ops->set_ll_next(desc, i - 1,
+					       desc->its[i].paddr)) {
+			i++; /* Need free current one */
+			goto err;
+		}
 	}
 
 	return desc;
@@ -107,21 +117,32 @@ vchan_dma_ll_prep_memcpy(struct dma_chan *chan,
 			 dma_addr_t dma_dst, dma_addr_t dma_src, size_t len,
 			 unsigned long flags)
 {
+	unsigned int max_seg = dma_get_max_seg_size(chan->device->dev);
 	struct virt_dma_chan *vchan = to_virt_chan(chan);
 	struct dma_ll_desc *desc;
-	int ret;
+	unsigned int ndesc;
+	int i, ret;
 
-	desc = vchan_dma_ll_alloc_desc(chan, 1, flags);
+	ndesc = (len + max_seg - 1) / max_seg;
+
+	desc = vchan_dma_ll_alloc_desc(chan, ndesc, flags);
 	if (!desc)
 		return NULL;
 
 	desc->iscyclic = false;
 
-	ret = vchan->ll.ops->set_lli(desc, 0, dma_src, dma_dst,
-				     len, true, NULL);
+	for (i = 0; i < ndesc; i++) {
+		ret = vchan->ll.ops->set_lli(desc, i,
+					     dma_src, dma_dst,
+					     min(len, max_seg),
+					     i == ndesc - 1, NULL);
+		if (ret)
+			goto err;
 
-	if (ret)
-		goto err;
+		dma_src += max_seg;
+		dma_dst += max_seg;
+		len -= max_seg;
+	}
 
 	return __vchan_tx_prep(vchan, &desc->vdesc);
 

-- 
2.34.1


  parent reply	other threads:[~2026-01-28 18:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-28 18:05 [PATCH RFC 00/12] dmaengine: introduce common linked-list DMA controller framework Frank Li
2026-01-28 18:05 ` [PATCH RFC 01/12] dmaengine: Extend virt_chan for link list based DMA engines Frank Li
2026-01-28 18:05 ` [PATCH RFC 02/12] dmaengine: Add common dma_ll_desc and dma_linklist_item for link-list controllers Frank Li
2026-01-28 18:05 ` [PATCH RFC 03/12] dmaengine: fsl-edma: Remove redundant echan from struct fsl_edma_desc Frank Li
2026-01-28 18:05 ` [PATCH RFC 04/12] dmaengine: fsl-edma: Use common dma_ll_desc in vchan Frank Li
2026-01-28 18:05 ` [PATCH RFC 05/12] dmaengine: Add DMA pool allocation in vchan_dma_ll_init() and API vchan_dma_ll_free() Frank Li
2026-01-28 18:05 ` [PATCH RFC 06/12] dmaengine: Move fsl_edma_(alloc|free)_desc() to common library Frank Li
2026-01-28 18:05 ` [PATCH RFC 07/12] dmaengine: virt-dma: split vchan_tx_prep() into init and internal helpers Frank Li
2026-01-28 18:05 ` [PATCH RFC 08/12] dmaengine: Factor out fsl-edma prep_memcpy into common vchan helper Frank Li
2026-01-28 18:05 ` Frank Li [this message]
2026-01-28 18:05 ` [PATCH RFC 10/12] dmaengine: move fsl-edma dma_[un]map_resource() to linked list library Frank Li
2026-01-28 18:05 ` [PATCH RFC 11/12] dmaengine: fsl-edma: use local soff/doff variables Frank Li
2026-01-28 18:05 ` [PATCH RFC 12/12] dmaengine: add vchan_dma_ll_prep_slave_{sg,cyclic} API Frank Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260128-dma_ll_comlib-v1-9-1b1fa2c671f9@nxp.com \
    --to=frank.li@nxp.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=joy.zou@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox