Skip to content

Commit 67e13e8

Browse files
ADESTMvinodkoul
authored andcommitted
dmaengine: stm32-dma: fix residue in case of MDMA chaining
In case of MDMA chaining, DMA is configured in Double-Buffer Mode (DBM) with two periods, but if transfer has been prepared with _prep_slave_sg(), the transfer is not marked cyclic (=!chan->desc->cyclic). However, as DBM is activated for MDMA chaining, residue computation must take into account cyclic constraints. With only two periods in MDMA chaining, and no update due to Transfer Complete interrupt masked, n_sg is always 0. If DMA current memory address (depending on SxCR.CT and SxM0AR/SxM1AR) does not correspond, it means n_sg should be increased. Then, the residue of the current period is the one read from SxNDTR and should not be overwritten with the full period length. Fixes: 7237951 ("dmaengine: stm32-dma: add support to trigger STM32 MDMA") Signed-off-by: Amelie Delaunay <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 2df467e commit 67e13e8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/dma/stm32-dma.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,11 +1389,12 @@ static size_t stm32_dma_desc_residue(struct stm32_dma_chan *chan,
13891389

13901390
residue = stm32_dma_get_remaining_bytes(chan);
13911391

1392-
if (chan->desc->cyclic && !stm32_dma_is_current_sg(chan)) {
1392+
if ((chan->desc->cyclic || chan->trig_mdma) && !stm32_dma_is_current_sg(chan)) {
13931393
n_sg++;
13941394
if (n_sg == chan->desc->num_sgs)
13951395
n_sg = 0;
1396-
residue = sg_req->len;
1396+
if (!chan->trig_mdma)
1397+
residue = sg_req->len;
13971398
}
13981399

13991400
/*
@@ -1403,7 +1404,7 @@ static size_t stm32_dma_desc_residue(struct stm32_dma_chan *chan,
14031404
* residue = remaining bytes from NDTR + remaining
14041405
* periods/sg to be transferred
14051406
*/
1406-
if (!chan->desc->cyclic || n_sg != 0)
1407+
if ((!chan->desc->cyclic && !chan->trig_mdma) || n_sg != 0)
14071408
for (i = n_sg; i < desc->num_sgs; i++)
14081409
residue += desc->sg_req[i].len;
14091410

0 commit comments

Comments
 (0)