mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-18 02:46:06 +00:00
dmaengine: dw-edma: Fix invalid interleaved xfers semantics
The interleaved DMA transfer support added by 85e7518f42c8 ("dmaengine: dw-edma: Add device_prep_interleave_dma() support") seems contradictory to what the DMA engine defines. The next conditional statements: if (!xfer->xfer.il->numf) return NULL; if (xfer->xfer.il->numf > 0 && xfer->xfer.il->frame_size > 0) return NULL; mean that numf can't be zero and frame_size must always be zero, otherwise the transfer won't be executed. Furthermore, the transfer execution method takes the frame size from the dma_interleaved_template.sgl[] array for each frame. That array in accordance with [1] is supposed to be of dma_interleaved_template.frame_size size, which as we discovered before the code expects to be zero. So judging by the dw_edma_device_transfer() implementation, the method implies the dma_interleaved_template.sgl[] array being of dma_interleaved_template.numf size, which is wrong. Since the dw_edma_device_transfer() method doesn't permit dma_interleaved_template.frame_size being non-zero, the multi-chunk interleaved transfer turns to be unsupported even though the code implies having it supported. Add fully functioning support of interleaved DMA transfers. First of all, dma_interleaved_template.frame_size is supposed to be greater or equal to one thus having at least simple linear chunked frames. Secondly, we can create a walk-through over all the chunks and frames by initializing the number of the eDMA burst transactions as a multiple of dma_interleaved_template.numf and dma_interleaved_template.frame_size and getting the frame_size-modulo of the iteration step as an index of the dma_interleaved_template.sgl[] array. [1] include/linux/dmaengine.h: doc struct dma_interleaved_template Link: https://lore.kernel.org/r/20230113171409.30470-7-Sergey.Semin@baikalelectronics.ru Fixes: 85e7518f42c8 ("dmaengine: dw-edma: Add device_prep_interleave_dma() support") Tested-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru> Signed-off-by: Lorenzo Pieralisi <lpieralisi@kernel.org> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> Acked-by: Vinod Koul <vkoul@kernel.org>
This commit is contained in:
parent
c8ed491822
commit
7ad06f2184
@ -332,6 +332,7 @@ dw_edma_device_transfer(struct dw_edma_transfer *xfer)
|
||||
struct dw_edma_chunk *chunk;
|
||||
struct dw_edma_burst *burst;
|
||||
struct dw_edma_desc *desc;
|
||||
size_t fsz = 0;
|
||||
u32 cnt = 0;
|
||||
int i;
|
||||
|
||||
@ -381,9 +382,7 @@ dw_edma_device_transfer(struct dw_edma_transfer *xfer)
|
||||
if (xfer->xfer.sg.len < 1)
|
||||
return NULL;
|
||||
} else if (xfer->type == EDMA_XFER_INTERLEAVED) {
|
||||
if (!xfer->xfer.il->numf)
|
||||
return NULL;
|
||||
if (xfer->xfer.il->numf > 0 && xfer->xfer.il->frame_size > 0)
|
||||
if (!xfer->xfer.il->numf || xfer->xfer.il->frame_size < 1)
|
||||
return NULL;
|
||||
if (!xfer->xfer.il->src_inc || !xfer->xfer.il->dst_inc)
|
||||
return NULL;
|
||||
@ -413,10 +412,8 @@ dw_edma_device_transfer(struct dw_edma_transfer *xfer)
|
||||
cnt = xfer->xfer.sg.len;
|
||||
sg = xfer->xfer.sg.sgl;
|
||||
} else if (xfer->type == EDMA_XFER_INTERLEAVED) {
|
||||
if (xfer->xfer.il->numf > 0)
|
||||
cnt = xfer->xfer.il->numf;
|
||||
else
|
||||
cnt = xfer->xfer.il->frame_size;
|
||||
cnt = xfer->xfer.il->numf * xfer->xfer.il->frame_size;
|
||||
fsz = xfer->xfer.il->frame_size;
|
||||
}
|
||||
|
||||
for (i = 0; i < cnt; i++) {
|
||||
@ -438,7 +435,7 @@ dw_edma_device_transfer(struct dw_edma_transfer *xfer)
|
||||
else if (xfer->type == EDMA_XFER_SCATTER_GATHER)
|
||||
burst->sz = sg_dma_len(sg);
|
||||
else if (xfer->type == EDMA_XFER_INTERLEAVED)
|
||||
burst->sz = xfer->xfer.il->sgl[i].size;
|
||||
burst->sz = xfer->xfer.il->sgl[i % fsz].size;
|
||||
|
||||
chunk->ll_region.sz += burst->sz;
|
||||
desc->alloc_sz += burst->sz;
|
||||
@ -481,10 +478,9 @@ dw_edma_device_transfer(struct dw_edma_transfer *xfer)
|
||||
|
||||
if (xfer->type == EDMA_XFER_SCATTER_GATHER) {
|
||||
sg = sg_next(sg);
|
||||
} else if (xfer->type == EDMA_XFER_INTERLEAVED &&
|
||||
xfer->xfer.il->frame_size > 0) {
|
||||
} else if (xfer->type == EDMA_XFER_INTERLEAVED) {
|
||||
struct dma_interleaved_template *il = xfer->xfer.il;
|
||||
struct data_chunk *dc = &il->sgl[i];
|
||||
struct data_chunk *dc = &il->sgl[i % fsz];
|
||||
|
||||
src_addr += burst->sz;
|
||||
if (il->src_sgl)
|
||||
|
Loading…
x
Reference in New Issue
Block a user