dmaengine.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [v3,1/2] dmaengine: sh: rcar-dmac: With cyclic DMA residue 0 is valid
@ 2019-04-12  5:29 Dirk Behme
  2019-04-12  5:29 ` [PATCH v3 1/2] " Dirk Behme
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Dirk Behme @ 2019-04-12  5:29 UTC (permalink / raw)
  To: linux-renesas-soc
  Cc: dmaengine, vkoul, geert+renesas, niklas.soderlund+renesas,
	laurent.pinchart+renesas, Achim.Dahlhoff, dirk.behme,
	yoshihiro.shimoda.uh, ylhuajnu, hiroyuki.yokoyama.vx,
	kuninori.morimoto.gx, stable

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(-)

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);

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 1/2] dmaengine: sh: rcar-dmac: With cyclic DMA residue 0 is valid
  2019-04-12  5:29 [v3,1/2] dmaengine: sh: rcar-dmac: With cyclic DMA residue 0 is valid Dirk Behme
@ 2019-04-12  5:29 ` Dirk Behme
  2019-04-12  5:29 ` [v3,2/2] dmaengine: sh: rcar-dmac: Fix glitch in dmaengine_tx_status Dirk Behme
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Dirk Behme @ 2019-04-12  5:29 UTC (permalink / raw)
  To: linux-renesas-soc
  Cc: dmaengine, vkoul, geert+renesas, niklas.soderlund+renesas,
	laurent.pinchart+renesas, Achim.Dahlhoff, dirk.behme,
	yoshihiro.shimoda.uh, ylhuajnu, hiroyuki.yokoyama.vx,
	kuninori.morimoto.gx, stable

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(-)

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);
-- 
2.20.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [v3,2/2] dmaengine: sh: rcar-dmac: Fix glitch in dmaengine_tx_status
@ 2019-04-12  5:29 ` Dirk Behme
  2019-04-12  5:29   ` [PATCH v3 2/2] " Dirk Behme
  2019-04-12  8:52   ` [v3,2/2] " Yoshihiro Shimoda
  0 siblings, 2 replies; 12+ messages in thread
From: Dirk Behme @ 2019-04-12  5:29 UTC (permalink / raw)
  To: linux-renesas-soc
  Cc: dmaengine, vkoul, geert+renesas, niklas.soderlund+renesas,
	laurent.pinchart+renesas, Achim.Dahlhoff, dirk.behme,
	yoshihiro.shimoda.uh, ylhuajnu, hiroyuki.yokoyama.vx,
	kuninori.morimoto.gx, stable

From: Achim Dahlhoff <Achim.Dahlhoff@de.bosch.com>

The tx_status poll in the rcar_dmac driver reads the status register
which indicates which chunk is busy (DMACHCRB). Afterwards the point
inside the chunk is read from DMATCRB. It is possible that the chunk
has changed between the two reads. The result is a non-monotonous
increase of the residue. Fix this by introducing a 'safe read' logic.

Fixes: 73a47bd0da66 ("dmaengine: rcar-dmac: use TCRB instead of TCR for residue")
Signed-off-by: Achim Dahlhoff <Achim.Dahlhoff@de.bosch.com>
Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
Cc: <stable@vger.kernel.org> # v4.16+
---
Note: Patch done against mainline v5.0

Changes in v2: Switch goto/retry to for loop

Changes in v3: None

 drivers/dma/sh/rcar-dmac.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c
index 54810ffd95e2..e2a5398f89b5 100644
--- a/drivers/dma/sh/rcar-dmac.c
+++ b/drivers/dma/sh/rcar-dmac.c
@@ -1282,6 +1282,9 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan,
 	enum dma_status status;
 	unsigned int residue = 0;
 	unsigned int dptr = 0;
+	unsigned int chcrb;
+	unsigned int tcrb;
+	unsigned int i;
 
 	if (!desc)
 		return 0;
@@ -1329,6 +1332,24 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan,
 		return 0;
 	}
 
+	/*
+	 * We need to read two registers.
+	 * Make sure the control register does not skip to next chunk
+	 * while reading the counter.
+	 * Trying it 3 times should be enough: Initial read, retry, retry
+	 * for the paranoid.
+	 */
+	for (i = 0; i < 3; i++) {
+		chcrb = rcar_dmac_chan_read(chan, RCAR_DMACHCRB) &
+					    RCAR_DMACHCRB_DPTR_MASK;
+		tcrb = rcar_dmac_chan_read(chan, RCAR_DMATCRB);
+		/* Still the same? */
+		if (chcrb == (rcar_dmac_chan_read(chan, RCAR_DMACHCRB) &
+			      RCAR_DMACHCRB_DPTR_MASK))
+			break;
+	}
+	WARN_ONCE(i >= 3, "residue might be not continuous!");
+
 	/*
 	 * In descriptor mode the descriptor running pointer is not maintained
 	 * by the interrupt handler, find the running descriptor from the
@@ -1336,8 +1357,7 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan,
 	 * mode just use the running descriptor pointer.
 	 */
 	if (desc->hwdescs.use) {
-		dptr = (rcar_dmac_chan_read(chan, RCAR_DMACHCRB) &
-			RCAR_DMACHCRB_DPTR_MASK) >> RCAR_DMACHCRB_DPTR_SHIFT;
+		dptr = chcrb >> RCAR_DMACHCRB_DPTR_SHIFT;
 		if (dptr == 0)
 			dptr = desc->nchunks;
 		dptr--;
@@ -1355,7 +1375,7 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan,
 	}
 
 	/* Add the residue for the current chunk. */
-	residue += rcar_dmac_chan_read(chan, RCAR_DMATCRB) << desc->xfer_shift;
+	residue += tcrb << desc->xfer_shift;
 
 	return residue;
 }

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 2/2] dmaengine: sh: rcar-dmac: Fix glitch in dmaengine_tx_status
  2019-04-12  5:29 ` [v3,2/2] dmaengine: sh: rcar-dmac: Fix glitch in dmaengine_tx_status Dirk Behme
@ 2019-04-12  5:29   ` Dirk Behme
  2019-04-12  8:52   ` [v3,2/2] " Yoshihiro Shimoda
  1 sibling, 0 replies; 12+ messages in thread
From: Dirk Behme @ 2019-04-12  5:29 UTC (permalink / raw)
  To: linux-renesas-soc
  Cc: dmaengine, vkoul, geert+renesas, niklas.soderlund+renesas,
	laurent.pinchart+renesas, Achim.Dahlhoff, dirk.behme,
	yoshihiro.shimoda.uh, ylhuajnu, hiroyuki.yokoyama.vx,
	kuninori.morimoto.gx, stable

From: Achim Dahlhoff <Achim.Dahlhoff@de.bosch.com>

The tx_status poll in the rcar_dmac driver reads the status register
which indicates which chunk is busy (DMACHCRB). Afterwards the point
inside the chunk is read from DMATCRB. It is possible that the chunk
has changed between the two reads. The result is a non-monotonous
increase of the residue. Fix this by introducing a 'safe read' logic.

Fixes: 73a47bd0da66 ("dmaengine: rcar-dmac: use TCRB instead of TCR for residue")
Signed-off-by: Achim Dahlhoff <Achim.Dahlhoff@de.bosch.com>
Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
Cc: <stable@vger.kernel.org> # v4.16+
---
Note: Patch done against mainline v5.0

Changes in v2: Switch goto/retry to for loop

Changes in v3: None

 drivers/dma/sh/rcar-dmac.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c
index 54810ffd95e2..e2a5398f89b5 100644
--- a/drivers/dma/sh/rcar-dmac.c
+++ b/drivers/dma/sh/rcar-dmac.c
@@ -1282,6 +1282,9 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan,
 	enum dma_status status;
 	unsigned int residue = 0;
 	unsigned int dptr = 0;
+	unsigned int chcrb;
+	unsigned int tcrb;
+	unsigned int i;
 
 	if (!desc)
 		return 0;
@@ -1329,6 +1332,24 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan,
 		return 0;
 	}
 
+	/*
+	 * We need to read two registers.
+	 * Make sure the control register does not skip to next chunk
+	 * while reading the counter.
+	 * Trying it 3 times should be enough: Initial read, retry, retry
+	 * for the paranoid.
+	 */
+	for (i = 0; i < 3; i++) {
+		chcrb = rcar_dmac_chan_read(chan, RCAR_DMACHCRB) &
+					    RCAR_DMACHCRB_DPTR_MASK;
+		tcrb = rcar_dmac_chan_read(chan, RCAR_DMATCRB);
+		/* Still the same? */
+		if (chcrb == (rcar_dmac_chan_read(chan, RCAR_DMACHCRB) &
+			      RCAR_DMACHCRB_DPTR_MASK))
+			break;
+	}
+	WARN_ONCE(i >= 3, "residue might be not continuous!");
+
 	/*
 	 * In descriptor mode the descriptor running pointer is not maintained
 	 * by the interrupt handler, find the running descriptor from the
@@ -1336,8 +1357,7 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan,
 	 * mode just use the running descriptor pointer.
 	 */
 	if (desc->hwdescs.use) {
-		dptr = (rcar_dmac_chan_read(chan, RCAR_DMACHCRB) &
-			RCAR_DMACHCRB_DPTR_MASK) >> RCAR_DMACHCRB_DPTR_SHIFT;
+		dptr = chcrb >> RCAR_DMACHCRB_DPTR_SHIFT;
 		if (dptr == 0)
 			dptr = desc->nchunks;
 		dptr--;
@@ -1355,7 +1375,7 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan,
 	}
 
 	/* Add the residue for the current chunk. */
-	residue += rcar_dmac_chan_read(chan, RCAR_DMATCRB) << desc->xfer_shift;
+	residue += tcrb << desc->xfer_shift;
 
 	return residue;
 }
-- 
2.20.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [v3,1/2] dmaengine: sh: rcar-dmac: With cyclic DMA residue 0 is valid
@ 2019-04-12  8:33 ` Yoshihiro Shimoda
  2019-04-12  8:33   ` [PATCH v3 1/2] " Yoshihiro Shimoda
  0 siblings, 1 reply; 12+ messages in thread
From: Yoshihiro Shimoda @ 2019-04-12  8:33 UTC (permalink / raw)
  To: REE dirk.behme@de.bosch.com
  Cc: dmaengine, vkoul, geert+renesas, niklas.soderlund+renesas,
	laurent.pinchart+renesas, Achim.Dahlhoff, ylhuajnu,
	HIROYUKI YOKOYAMA, Kuninori Morimoto, stable, linux-renesas-soc

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH v3 1/2] dmaengine: sh: rcar-dmac: With cyclic DMA residue 0 is valid
  2019-04-12  8:33 ` [v3,1/2] dmaengine: sh: rcar-dmac: With cyclic DMA residue 0 is valid Yoshihiro Shimoda
@ 2019-04-12  8:33   ` Yoshihiro Shimoda
  0 siblings, 0 replies; 12+ messages in thread
From: Yoshihiro Shimoda @ 2019-04-12  8:33 UTC (permalink / raw)
  To: REE dirk.behme@de.bosch.com
  Cc: dmaengine, vkoul, geert+renesas, niklas.soderlund+renesas,
	laurent.pinchart+renesas, Achim.Dahlhoff,
	REE dirk.behme@de.bosch.com, ylhuajnu, HIROYUKI YOKOYAMA,
	Kuninori Morimoto, stable, linux-renesas-soc

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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [v3,2/2] dmaengine: sh: rcar-dmac: Fix glitch in dmaengine_tx_status
@ 2019-04-12  8:52   ` Yoshihiro Shimoda
  2019-04-12  8:52     ` [PATCH v3 2/2] " Yoshihiro Shimoda
  0 siblings, 1 reply; 12+ messages in thread
From: Yoshihiro Shimoda @ 2019-04-12  8:52 UTC (permalink / raw)
  To: REE dirk.behme@de.bosch.com
  Cc: dmaengine, vkoul, geert+renesas, niklas.soderlund+renesas,
	laurent.pinchart+renesas, Achim.Dahlhoff, ylhuajnu,
	HIROYUKI YOKOYAMA, Kuninori Morimoto, stable, linux-renesas-soc

Hi Dirk-san,

> From: Dirk Behme, Sent: Friday, April 12, 2019 2:29 PM
> 
> From: Achim Dahlhoff <Achim.Dahlhoff@de.bosch.com>
> 
> The tx_status poll in the rcar_dmac driver reads the status register
> which indicates which chunk is busy (DMACHCRB). Afterwards the point
> inside the chunk is read from DMATCRB. It is possible that the chunk
> has changed between the two reads. The result is a non-monotonous
> increase of the residue. Fix this by introducing a 'safe read' logic.
> 
> Fixes: 73a47bd0da66 ("dmaengine: rcar-dmac: use TCRB instead of TCR for residue")

I guess this driver has this issue potencially from previous of the commit
(maybe commit ccadee9b1e9 ("dmaengine: rcar-dmac: Implement support for hardware descriptor lists"?).

But, this patch seems good to fix the issue.
So,

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

Best regards,
Yoshihiro Shimoda

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH v3 2/2] dmaengine: sh: rcar-dmac: Fix glitch in dmaengine_tx_status
  2019-04-12  8:52   ` [v3,2/2] " Yoshihiro Shimoda
@ 2019-04-12  8:52     ` Yoshihiro Shimoda
  0 siblings, 0 replies; 12+ messages in thread
From: Yoshihiro Shimoda @ 2019-04-12  8:52 UTC (permalink / raw)
  To: REE dirk.behme@de.bosch.com
  Cc: dmaengine, vkoul, geert+renesas, niklas.soderlund+renesas,
	laurent.pinchart+renesas, Achim.Dahlhoff,
	REE dirk.behme@de.bosch.com, ylhuajnu, HIROYUKI YOKOYAMA,
	Kuninori Morimoto, stable, linux-renesas-soc

Hi Dirk-san,

> From: Dirk Behme, Sent: Friday, April 12, 2019 2:29 PM
> 
> From: Achim Dahlhoff <Achim.Dahlhoff@de.bosch.com>
> 
> The tx_status poll in the rcar_dmac driver reads the status register
> which indicates which chunk is busy (DMACHCRB). Afterwards the point
> inside the chunk is read from DMATCRB. It is possible that the chunk
> has changed between the two reads. The result is a non-monotonous
> increase of the residue. Fix this by introducing a 'safe read' logic.
> 
> Fixes: 73a47bd0da66 ("dmaengine: rcar-dmac: use TCRB instead of TCR for residue")

I guess this driver has this issue potencially from previous of the commit
(maybe commit ccadee9b1e9 ("dmaengine: rcar-dmac: Implement support for hardware descriptor lists"?).

But, this patch seems good to fix the issue.
So,

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

Best regards,
Yoshihiro Shimoda


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [v3,1/2] dmaengine: sh: rcar-dmac: With cyclic DMA residue 0 is valid
@ 2019-04-12  9:54 ` Laurent Pinchart
  2019-04-12  9:54   ` [PATCH v3 1/2] " Laurent Pinchart
  0 siblings, 1 reply; 12+ messages in thread
From: Laurent Pinchart @ 2019-04-12  9:54 UTC (permalink / raw)
  To: Dirk Behme
  Cc: linux-renesas-soc, dmaengine, vkoul, geert+renesas,
	niklas.soderlund+renesas, laurent.pinchart+renesas,
	Achim.Dahlhoff, yoshihiro.shimoda.uh, ylhuajnu,
	hiroyuki.yokoyama.vx, kuninori.morimoto.gx, stable

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);

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 1/2] dmaengine: sh: rcar-dmac: With cyclic DMA residue 0 is valid
  2019-04-12  9:54 ` [v3,1/2] " Laurent Pinchart
@ 2019-04-12  9:54   ` Laurent Pinchart
  0 siblings, 0 replies; 12+ messages in thread
From: Laurent Pinchart @ 2019-04-12  9:54 UTC (permalink / raw)
  To: Dirk Behme
  Cc: linux-renesas-soc, dmaengine, vkoul, geert+renesas,
	niklas.soderlund+renesas, laurent.pinchart+renesas,
	Achim.Dahlhoff, yoshihiro.shimoda.uh, ylhuajnu,
	hiroyuki.yokoyama.vx, kuninori.morimoto.gx, stable

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);

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [v3,1/2] dmaengine: sh: rcar-dmac: With cyclic DMA residue 0 is valid
@ 2019-04-23  5:15 ` Vinod Koul
  2019-04-23  5:15   ` [PATCH v3 1/2] " Vinod Koul
  0 siblings, 1 reply; 12+ messages in thread
From: Vinod Koul @ 2019-04-23  5:15 UTC (permalink / raw)
  To: Dirk Behme
  Cc: linux-renesas-soc, dmaengine, geert+renesas,
	niklas.soderlund+renesas, laurent.pinchart+renesas,
	Achim.Dahlhoff, yoshihiro.shimoda.uh, ylhuajnu,
	hiroyuki.yokoyama.vx, kuninori.morimoto.gx, stable

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 1/2] dmaengine: sh: rcar-dmac: With cyclic DMA residue 0 is valid
  2019-04-23  5:15 ` [v3,1/2] " Vinod Koul
@ 2019-04-23  5:15   ` Vinod Koul
  0 siblings, 0 replies; 12+ messages in thread
From: Vinod Koul @ 2019-04-23  5:15 UTC (permalink / raw)
  To: Dirk Behme
  Cc: linux-renesas-soc, dmaengine, geert+renesas,
	niklas.soderlund+renesas, laurent.pinchart+renesas,
	Achim.Dahlhoff, yoshihiro.shimoda.uh, ylhuajnu,
	hiroyuki.yokoyama.vx, kuninori.morimoto.gx, stable

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
-- 
~Vinod

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-04-23  5:16 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-12  5:29 [v3,1/2] dmaengine: sh: rcar-dmac: With cyclic DMA residue 0 is valid Dirk Behme
2019-04-12  5:29 ` [PATCH v3 1/2] " Dirk Behme
2019-04-12  5:29 ` [v3,2/2] dmaengine: sh: rcar-dmac: Fix glitch in dmaengine_tx_status Dirk Behme
2019-04-12  5:29   ` [PATCH v3 2/2] " Dirk Behme
2019-04-12  8:52   ` [v3,2/2] " Yoshihiro Shimoda
2019-04-12  8:52     ` [PATCH v3 2/2] " Yoshihiro Shimoda
2019-04-12  8:33 ` [v3,1/2] dmaengine: sh: rcar-dmac: With cyclic DMA residue 0 is valid Yoshihiro Shimoda
2019-04-12  8:33   ` [PATCH v3 1/2] " Yoshihiro Shimoda
2019-04-12  9:54 ` [v3,1/2] " Laurent Pinchart
2019-04-12  9:54   ` [PATCH v3 1/2] " Laurent Pinchart
2019-04-23  5:15 ` [v3,1/2] " Vinod Koul
2019-04-23  5:15   ` [PATCH v3 1/2] " Vinod Koul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).