1 From 907bd68a2edc491849e2fdcfe52c4596627bca94 Mon Sep 17 00:00:00 2001
2 From: Dirk Behme <dirk.behme@de.bosch.com>
3 Date: Fri, 12 Apr 2019 07:29:13 +0200
4 Subject: dmaengine: sh: rcar-dmac: With cyclic DMA residue 0 is valid
6 From: Dirk Behme <dirk.behme@de.bosch.com>
8 commit 907bd68a2edc491849e2fdcfe52c4596627bca94 upstream.
10 Having a cyclic DMA, a residue 0 is not an indication of a completed
11 DMA. In case of cyclic DMA make sure that dma_set_residue() is called
12 and with this a residue of 0 is forwarded correctly to the caller.
14 Fixes: 3544d2878817 ("dmaengine: rcar-dmac: use result of updated get_residue in tx_status")
15 Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
16 Signed-off-by: Achim Dahlhoff <Achim.Dahlhoff@de.bosch.com>
17 Signed-off-by: Hiroyuki Yokoyama <hiroyuki.yokoyama.vx@renesas.com>
18 Signed-off-by: Yao Lihua <ylhuajnu@outlook.com>
19 Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
20 Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
21 Cc: <stable@vger.kernel.org> # v4.8+
22 Signed-off-by: Vinod Koul <vkoul@kernel.org>
23 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
26 drivers/dma/sh/rcar-dmac.c | 4 +++-
27 1 file changed, 3 insertions(+), 1 deletion(-)
29 --- a/drivers/dma/sh/rcar-dmac.c
30 +++ b/drivers/dma/sh/rcar-dmac.c
31 @@ -1311,6 +1311,7 @@ static enum dma_status rcar_dmac_tx_stat
32 enum dma_status status;
37 status = dma_cookie_status(chan, cookie, txstate);
38 if (status == DMA_COMPLETE || !txstate)
39 @@ -1318,10 +1319,11 @@ static enum dma_status rcar_dmac_tx_stat
41 spin_lock_irqsave(&rchan->lock, flags);
42 residue = rcar_dmac_chan_get_residue(rchan, cookie);
43 + cyclic = rchan->desc.running ? rchan->desc.running->cyclic : false;
44 spin_unlock_irqrestore(&rchan->lock, flags);
46 /* if there's no residue, the cookie is complete */
48 + if (!residue && !cyclic)
51 dma_set_residue(txstate, residue);