From: "M'boumba Cedric Madianga" <cedric.madianga@gmail.com>
To: vinod.koul@intel.com, robh+dt@kernel.org, mark.rutland@arm.com,
mcoquelin.stm32@gmail.com, alexandre.torgue@st.com,
dan.j.williams@intel.com, dmaengine@vger.kernel.org,
devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Cc: "M'boumba Cedric Madianga" <cedric.madianga@gmail.com>
Subject: [PATCH 6/9] dmaengine: stm32-dma: Fix residue computation issue in cyclic mode
Date: Tue, 13 Dec 2016 14:40:48 +0100 [thread overview]
Message-ID: <1481636451-27863-7-git-send-email-cedric.madianga@gmail.com> (raw)
In-Reply-To: <1481636451-27863-1-git-send-email-cedric.madianga@gmail.com>
This patch resolves the residue computation issue detected in cyclic mode.
Now, in cyclic mode, we increment next_sg variable as soon as a period is
transferred instead of after pushing a new sg request.
Then, we take into account that after transferring a complete buffer,
the next_sg variable is equal to 0.
Signed-off-by: M'boumba Cedric Madianga <cedric.madianga@gmail.com>
Reviewed-by: Ludovic BARRE <ludovic.barre@st.com>
---
drivers/dma/stm32-dma.c | 39 ++++++++++++++++++++++++++-------------
1 file changed, 26 insertions(+), 13 deletions(-)
diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index adb846c..ba929a9 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -500,8 +500,6 @@ static void stm32_dma_configure_next_sg(struct stm32_dma_chan *chan)
dev_dbg(chan2dev(chan), "CT=0 <=> SM1AR: 0x%08x\n",
stm32_dma_read(dmadev, STM32_DMA_SM1AR(id)));
}
-
- chan->next_sg++;
}
}
@@ -510,6 +508,7 @@ static void stm32_dma_handle_chan_done(struct stm32_dma_chan *chan)
if (chan->desc) {
if (chan->desc->cyclic) {
vchan_cyclic_callback(&chan->desc->vdesc);
+ chan->next_sg++;
stm32_dma_configure_next_sg(chan);
} else {
chan->busy = false;
@@ -846,26 +845,40 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_dma_memcpy(
return vchan_tx_prep(&chan->vchan, &desc->vdesc, flags);
}
+static u32 stm32_dma_get_remaining_bytes(struct stm32_dma_chan *chan)
+{
+ u32 dma_scr, width, ndtr;
+ struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan);
+
+ dma_scr = stm32_dma_read(dmadev, STM32_DMA_SCR(chan->id));
+ width = STM32_DMA_SCR_PSIZE_GET(dma_scr);
+ ndtr = stm32_dma_read(dmadev, STM32_DMA_SNDTR(chan->id));
+
+ return ndtr << width;
+}
+
static size_t stm32_dma_desc_residue(struct stm32_dma_chan *chan,
struct stm32_dma_desc *desc,
u32 next_sg)
{
- struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan);
- u32 dma_scr, width, residue, count;
+ u32 residue = 0;
int i;
- residue = 0;
+ /*
+ * In cyclic mode, for the last period, residue = remaining bytes from
+ * NDTR
+ */
+ if (chan->desc->cyclic && next_sg == 0)
+ return stm32_dma_get_remaining_bytes(chan);
+ /*
+ * For all other periods in cyclic mode, and in sg mode,
+ * residue = remaining bytes from NDTR + remaining periods/sg to be
+ * transferred
+ */
for (i = next_sg; i < desc->num_sgs; i++)
residue += desc->sg_req[i].len;
-
- if (next_sg != 0) {
- dma_scr = stm32_dma_read(dmadev, STM32_DMA_SCR(chan->id));
- width = STM32_DMA_SCR_PSIZE_GET(dma_scr);
- count = stm32_dma_read(dmadev, STM32_DMA_SNDTR(chan->id));
-
- residue += count << width;
- }
+ residue += stm32_dma_get_remaining_bytes(chan);
return residue;
}
--
1.9.1
next prev parent reply other threads:[~2016-12-13 13:42 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-13 13:40 [PATCH 0/9] dmaengine: stm32-dma: Bug fixes and improvements series M'boumba Cedric Madianga
2016-12-13 13:40 ` [PATCH 1/9] dmaengine: stm32-dma: Set correct args number for DMA request from DT M'boumba Cedric Madianga
2016-12-13 13:40 ` [PATCH 2/9] dmaengine: stm32-dma: Fix typo in Kconfig M'boumba Cedric Madianga
2016-12-13 13:40 ` [PATCH 3/9] dt-bindings: stm32-dma: Fix typo regarding DMA client binding M'boumba Cedric Madianga
2016-12-13 20:09 ` Rob Herring
2016-12-13 13:40 ` [PATCH 4/9] dmaengine: stm32-dma: Fix null pointer dereference in stm32_dma_tx_status M'boumba Cedric Madianga
2016-12-13 13:40 ` [PATCH 5/9] dmaengine: stm32-dma: Rework starting transfer management M'boumba Cedric Madianga
2016-12-13 13:40 ` M'boumba Cedric Madianga [this message]
2016-12-13 13:40 ` [PATCH 7/9] dmaengine: stm32-dma: Add error messages if xlate fails M'boumba Cedric Madianga
2016-12-13 13:40 ` [PATCH 8/9] dmaengine: stm32-dma: Add synchronization support M'boumba Cedric Madianga
2016-12-13 13:40 ` [PATCH 9/9] dmaengine: stm32-dma: Add max_burst support M'boumba Cedric Madianga
2017-01-02 4:14 ` [PATCH 0/9] dmaengine: stm32-dma: Bug fixes and improvements series Vinod Koul
2017-01-02 9:26 ` M'boumba Cedric Madianga
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1481636451-27863-7-git-send-email-cedric.madianga@gmail.com \
--to=cedric.madianga@gmail.com \
--cc=alexandre.torgue@st.com \
--cc=dan.j.williams@intel.com \
--cc=devicetree@vger.kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=robh+dt@kernel.org \
--cc=vinod.koul@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).