[RFC PATCH 08/10] dmaengine: reintroduce DMA_MEMCPY_SG

From: Daniel Byrne

Date: Tue Dec 01 2026 - 09:20:15 EST


Reintroduce the DMA_MEMCPY_SG transaction type and
device_prep_dma_memcpy_sg(), removed by commit 0cae04373b77 ("dmaengine:
remove DMA_MEMCPY_SG once again") when the last in-tree user went away.
The migration copy offload added later in this series is the new
user. It hands the provider a scatter/gather memcpy in one call so
that batch-capable engines such as DSA can turn the operation into a
single hardware batch descriptor. The transfer copies min(src, dst)
total bytes.

Signed-off-by: Daniel Byrne <daniel1.byrne@xxxxxxxxx>
---
The cover letter of RFC v6 lists this hook as a follow-up. This is the
dmaengine core part. No provider implements it in this series.

.../driver-api/dmaengine/provider.rst | 10 ++++++++++
drivers/dma/dmaengine.c | 1 +
include/linux/dmaengine.h | 20 +++++++++++++++++++
3 files changed, 31 insertions(+)

diff --git a/Documentation/driver-api/dmaengine/provider.rst b/Documentation/driver-api/dmaengine/provider.rst
index be47852e5a0f..e844c7c0fce0 100644
--- a/Documentation/driver-api/dmaengine/provider.rst
+++ b/Documentation/driver-api/dmaengine/provider.rst
@@ -162,6 +162,16 @@ Currently, the types available are:

- The device is able to do memory to memory copies

+- DMA_MEMCPY_SG
+
+ - The device supports memory to memory scatter-gather transfers.
+
+ - Even though a plain memcpy can look like a particular case of a
+ scatter-gather transfer, with a single chunk to copy, it's a distinct
+ transaction type in the mem2mem transfer case. This is because some very
+ simple devices might be able to do contiguous single-chunk memory copies,
+ but have no support for more complex SG transfers.
+
- No matter what the overall size of the combined chunks for source and
destination is, only as many bytes as the smallest of the two will be
transmitted. That means the number and size of the scatter-gather buffers in
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 34be53487a21..bed2a80cb538 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -1219,6 +1219,7 @@ int dma_async_device_register(struct dma_device *device)
}

CHECK_CAP(dma_memcpy, DMA_MEMCPY);
+ CHECK_CAP(dma_memcpy_sg, DMA_MEMCPY_SG);
CHECK_CAP(dma_xor, DMA_XOR);
CHECK_CAP(dma_xor_val, DMA_XOR_VAL);
CHECK_CAP(dma_pq, DMA_PQ);
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index 805668fbe437..5df4bfc000a6 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -50,6 +50,7 @@ enum dma_status {
*/
enum dma_transaction_type {
DMA_MEMCPY,
+ DMA_MEMCPY_SG,
DMA_XOR,
DMA_PQ,
DMA_XOR_VAL,
@@ -860,6 +861,7 @@ struct dma_filter {
* @device_router_config: optional callback for DMA router configuration
* @device_free_chan_resources: release DMA channel's resources
* @device_prep_dma_memcpy: prepares a memcpy operation
+ * @device_prep_dma_memcpy_sg: prepares a memcpy_sg operation
* @device_prep_dma_xor: prepares a xor operation
* @device_prep_dma_xor_val: prepares a xor validation operation
* @device_prep_dma_pq: prepares a pq operation
@@ -940,6 +942,11 @@ struct dma_device {
struct dma_async_tx_descriptor *(*device_prep_dma_memcpy)(
struct dma_chan *chan, dma_addr_t dst, dma_addr_t src,
size_t len, unsigned long flags);
+ struct dma_async_tx_descriptor *(*device_prep_dma_memcpy_sg)(
+ struct dma_chan *chan,
+ struct scatterlist *dst_sg, unsigned int dst_nents,
+ struct scatterlist *src_sg, unsigned int src_nents,
+ unsigned long flags);
struct dma_async_tx_descriptor *(*device_prep_dma_xor)(
struct dma_chan *chan, dma_addr_t dst, dma_addr_t *src,
unsigned int src_cnt, size_t len, unsigned long flags);
@@ -1246,6 +1253,19 @@ static inline struct dma_async_tx_descriptor *dmaengine_prep_dma_memcpy(
len, flags);
}

+static inline struct dma_async_tx_descriptor *dmaengine_prep_dma_memcpy_sg(
+ struct dma_chan *chan,
+ struct scatterlist *dst_sg, unsigned int dst_nents,
+ struct scatterlist *src_sg, unsigned int src_nents,
+ unsigned long flags)
+{
+ if (!chan || !chan->device || !chan->device->device_prep_dma_memcpy_sg)
+ return NULL;
+
+ return chan->device->device_prep_dma_memcpy_sg(chan, dst_sg, dst_nents,
+ src_sg, src_nents, flags);
+}
+
/**
* dmaengine_get_max_xor - get the maximum number of XOR sources for a channel
* @chan: DMA channel
--
2.43.0