Commit 6e7da747 authored by Achim Dahlhoff's avatar Achim Dahlhoff Committed by Vinod Koul

dmaengine: sh: rcar-dmac: Fix glitch in dmaengine_tx_status

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: 73a47bd0 ("dmaengine: rcar-dmac: use TCRB instead of TCR for residue")
Signed-off-by: default avatarAchim Dahlhoff <Achim.Dahlhoff@de.bosch.com>
Signed-off-by: default avatarDirk Behme <dirk.behme@de.bosch.com>
Reviewed-by: default avatarYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Cc: <stable@vger.kernel.org> # v4.16+
Signed-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent 907bd68a
...@@ -1282,6 +1282,9 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan, ...@@ -1282,6 +1282,9 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan,
enum dma_status status; enum dma_status status;
unsigned int residue = 0; unsigned int residue = 0;
unsigned int dptr = 0; unsigned int dptr = 0;
unsigned int chcrb;
unsigned int tcrb;
unsigned int i;
if (!desc) if (!desc)
return 0; return 0;
...@@ -1329,6 +1332,24 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan, ...@@ -1329,6 +1332,24 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan,
return 0; 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 * In descriptor mode the descriptor running pointer is not maintained
* by the interrupt handler, find the running descriptor from the * 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, ...@@ -1336,8 +1357,7 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan,
* mode just use the running descriptor pointer. * mode just use the running descriptor pointer.
*/ */
if (desc->hwdescs.use) { if (desc->hwdescs.use) {
dptr = (rcar_dmac_chan_read(chan, RCAR_DMACHCRB) & dptr = chcrb >> RCAR_DMACHCRB_DPTR_SHIFT;
RCAR_DMACHCRB_DPTR_MASK) >> RCAR_DMACHCRB_DPTR_SHIFT;
if (dptr == 0) if (dptr == 0)
dptr = desc->nchunks; dptr = desc->nchunks;
dptr--; dptr--;
...@@ -1355,7 +1375,7 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan, ...@@ -1355,7 +1375,7 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan,
} }
/* Add the residue for the current chunk. */ /* 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; return residue;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment