diff mbox series

[v3,1/2] dmaengine: sh: rcar-dmac: With cyclic DMA residue 0 is valid

Message ID 20190412052914.16006-1-dirk.behme@de.bosch.com (mailing list archive)
State Accepted
Delegated to: Geert Uytterhoeven
Headers show
Series [v3,1/2] dmaengine: sh: rcar-dmac: With cyclic DMA residue 0 is valid | expand

Commit Message

Dirk Behme April 12, 2019, 5:29 a.m. UTC
Having a cyclic DMA, a residue 0 is not an indication of a completed
DMA. In case of cyclic DMA make sure that dma_set_residue() is called
and with this a residue of 0 is forwarded correctly to the caller.

Fixes: 3544d2878817 ("dmaengine: rcar-dmac: use result of updated get_residue in tx_status")
Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
Signed-off-by: Achim Dahlhoff <Achim.Dahlhoff@de.bosch.com>
Signed-off-by: Hiroyuki Yokoyama <hiroyuki.yokoyama.vx@renesas.com>
Signed-off-by: Yao Lihua <ylhuajnu@outlook.com>
Cc: <stable@vger.kernel.org> # v4.8+
---
Note: Patch done against mainline v5.0

Changes in v2: None

Changes in v3: Move reading rchan into the spin lock protection.

 drivers/dma/sh/rcar-dmac.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Yoshihiro Shimoda April 12, 2019, 8:33 a.m. UTC | #1
Hi Dirk-san,

> From: Dirk Behme, Sent: Friday, April 12, 2019 2:29 PM
> 
> Having a cyclic DMA, a residue 0 is not an indication of a completed
> DMA. In case of cyclic DMA make sure that dma_set_residue() is called
> and with this a residue of 0 is forwarded correctly to the caller.
> 
> Fixes: 3544d2878817 ("dmaengine: rcar-dmac: use result of updated get_residue in tx_status")
> Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
> Signed-off-by: Achim Dahlhoff <Achim.Dahlhoff@de.bosch.com>
> Signed-off-by: Hiroyuki Yokoyama <hiroyuki.yokoyama.vx@renesas.com>
> Signed-off-by: Yao Lihua <ylhuajnu@outlook.com>
> Cc: <stable@vger.kernel.org> # v4.8+
> ---

Thank you for the patch! Since cyclic transfers will not stop even if
the residue is 0, I agree this driver should not return DMA_COMPLETE
(transaction completed). So,

Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>

Best regards,
Yoshihiro Shimoda
Laurent Pinchart April 12, 2019, 9:54 a.m. UTC | #2
Hi Dirk,

Thank you for the patch.

On Fri, Apr 12, 2019 at 07:29:13AM +0200, Dirk Behme wrote:
> Having a cyclic DMA, a residue 0 is not an indication of a completed
> DMA. In case of cyclic DMA make sure that dma_set_residue() is called
> and with this a residue of 0 is forwarded correctly to the caller.
> 
> Fixes: 3544d2878817 ("dmaengine: rcar-dmac: use result of updated get_residue in tx_status")
> Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
> Signed-off-by: Achim Dahlhoff <Achim.Dahlhoff@de.bosch.com>
> Signed-off-by: Hiroyuki Yokoyama <hiroyuki.yokoyama.vx@renesas.com>
> Signed-off-by: Yao Lihua <ylhuajnu@outlook.com>
> Cc: <stable@vger.kernel.org> # v4.8+

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
> Note: Patch done against mainline v5.0
> 
> Changes in v2: None
> 
> Changes in v3: Move reading rchan into the spin lock protection.
> 
>  drivers/dma/sh/rcar-dmac.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c
> index 2b4f25698169..54810ffd95e2 100644
> --- a/drivers/dma/sh/rcar-dmac.c
> +++ b/drivers/dma/sh/rcar-dmac.c
> @@ -1368,6 +1368,7 @@ static enum dma_status rcar_dmac_tx_status(struct dma_chan *chan,
>  	enum dma_status status;
>  	unsigned long flags;
>  	unsigned int residue;
> +	bool cyclic;
>  
>  	status = dma_cookie_status(chan, cookie, txstate);
>  	if (status == DMA_COMPLETE || !txstate)
> @@ -1375,10 +1376,11 @@ static enum dma_status rcar_dmac_tx_status(struct dma_chan *chan,
>  
>  	spin_lock_irqsave(&rchan->lock, flags);
>  	residue = rcar_dmac_chan_get_residue(rchan, cookie);
> +	cyclic = rchan->desc.running ? rchan->desc.running->cyclic : false;
>  	spin_unlock_irqrestore(&rchan->lock, flags);
>  
>  	/* if there's no residue, the cookie is complete */
> -	if (!residue)
> +	if (!residue && !cyclic)
>  		return DMA_COMPLETE;
>  
>  	dma_set_residue(txstate, residue);
Vinod Koul April 23, 2019, 5:15 a.m. UTC | #3
On 12-04-19, 07:29, Dirk Behme wrote:
> Having a cyclic DMA, a residue 0 is not an indication of a completed
> DMA. In case of cyclic DMA make sure that dma_set_residue() is called
> and with this a residue of 0 is forwarded correctly to the caller.

Applied both, thanks
diff mbox series

Patch

diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c
index 2b4f25698169..54810ffd95e2 100644
--- a/drivers/dma/sh/rcar-dmac.c
+++ b/drivers/dma/sh/rcar-dmac.c
@@ -1368,6 +1368,7 @@  static enum dma_status rcar_dmac_tx_status(struct dma_chan *chan,
 	enum dma_status status;
 	unsigned long flags;
 	unsigned int residue;
+	bool cyclic;
 
 	status = dma_cookie_status(chan, cookie, txstate);
 	if (status == DMA_COMPLETE || !txstate)
@@ -1375,10 +1376,11 @@  static enum dma_status rcar_dmac_tx_status(struct dma_chan *chan,
 
 	spin_lock_irqsave(&rchan->lock, flags);
 	residue = rcar_dmac_chan_get_residue(rchan, cookie);
+	cyclic = rchan->desc.running ? rchan->desc.running->cyclic : false;
 	spin_unlock_irqrestore(&rchan->lock, flags);
 
 	/* if there's no residue, the cookie is complete */
-	if (!residue)
+	if (!residue && !cyclic)
 		return DMA_COMPLETE;
 
 	dma_set_residue(txstate, residue);