linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nandor Han <nandor.han@ge.com>
To: =Dan Williams <dan.j.williams@intel.com>,
	Vinod Koul <vinod.koul@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jslaby@suse.com>
Cc: Nandor Han <nandor.han@ge.com>,
	dmaengine@vger.kernel.org, linux-serial@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Peter Senna Tschudin <peter.senna@collabora.com>
Subject: [PATCH 2/4] dmaengine: imx-sdma - update the residue calculation for cyclic channels
Date: Mon,  8 Aug 2016 15:38:26 +0300	[thread overview]
Message-ID: <0e47cf5eb88ef63f844f310bfbd836264f65ccdf.1470656658.git.nandor.han@ge.com> (raw)
In-Reply-To: <cover.1470656657.git.nandor.han@ge.com>
In-Reply-To: <cover.1470656657.git.nandor.han@ge.com>

The calculation of the DMA transaction residue supports only fixed
size data transfers. This implementation is not covering all
operations (e.g. data receiving) when we need to know the exact amount
of bytes transferred.

The loop channels handling was changed to clear the buffer
descriptor errors and use the bd->mode.count to calculate the
residue.

Tested-by: Peter Senna Tschudin <peter.senna@collabora.com>
Acked-by: Peter Senna Tschudin <peter.senna@collabora.com>
Reviewed-by: Vinod Koul <vinod.koul@intel.com>
Signed-off-by: Nandor Han <nandor.han@ge.com>
---
 drivers/dma/imx-sdma.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index aa35a77..3cb4738 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -651,6 +651,8 @@ static void sdma_event_disable(struct sdma_channel *sdmac, unsigned int event)
 static void sdma_update_channel_loop(struct sdma_channel *sdmac)
 {
 	struct sdma_buffer_descriptor *bd;
+	int error = 0;
+	enum dma_status	old_status = sdmac->status;
 
 	/*
 	 * loop mode. Iterate over descriptors, re-setup them and
@@ -662,10 +664,20 @@ static void sdma_update_channel_loop(struct sdma_channel *sdmac)
 		if (bd->mode.status & BD_DONE)
 			break;
 
-		if (bd->mode.status & BD_RROR)
+		if (bd->mode.status & BD_RROR) {
+			bd->mode.status &= ~BD_RROR;
 			sdmac->status = DMA_ERROR;
+			error = -EIO;
+		}
 
+	       /*
+		* We use bd->mode.count to calculate the residue, since contains
+		* the number of bytes present in the current buffer descriptor.
+		*/
+
+		sdmac->chn_real_count = bd->mode.count;
 		bd->mode.status |= BD_DONE;
+		bd->mode.count = sdmac->period_len;
 
 		/*
 		 * The callback is called from the interrupt context in order
@@ -679,6 +691,9 @@ static void sdma_update_channel_loop(struct sdma_channel *sdmac)
 
 		sdmac->buf_tail++;
 		sdmac->buf_tail %= sdmac->num_bd;
+
+		if (error)
+			sdmac->status = old_status;
 	}
 }
 
@@ -1349,7 +1364,8 @@ static enum dma_status sdma_tx_status(struct dma_chan *chan,
 	u32 residue;
 
 	if (sdmac->flags & IMX_DMA_SG_LOOP)
-		residue = (sdmac->num_bd - sdmac->buf_tail) * sdmac->period_len;
+		residue = (sdmac->num_bd - sdmac->buf_tail) *
+			   sdmac->period_len - sdmac->chn_real_count;
 	else
 		residue = sdmac->chn_count - sdmac->chn_real_count;
 
-- 
2.8.3

  parent reply	other threads:[~2016-08-08 14:11 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-09 12:16 [PATCH RFC 0/4] serial,dma: use DMA cyclic for IMX UART driver Nandor Han
2016-06-09 12:16 ` [PATCH RFC 1/4] dma: imx-sdma - reduce transfer latency for DMA cyclic clients Nandor Han
2016-06-28 14:34   ` Vinod Koul
2016-07-01 14:59     ` EXT: " Nandor Han
2016-07-02 17:27       ` Vinod Koul
2016-07-14  8:32   ` Peter Senna Tschudin
2016-06-09 12:16 ` [PATCH RFC 2/4] dma: imx-sdma - update the residue calculation for cyclic channels Nandor Han
2016-06-09 12:16 ` [PATCH RFC 3/4] serial: imx-serial - update UART IMX driver to use cyclic DMA Nandor Han
2016-06-09 12:16 ` [PATCH RFC 4/4] serial: imx-serial - update RX error counters when DMA is used Nandor Han
2016-08-08 12:38 ` [PATCH 0/4] serial,dmaengine: use DMA cyclic for IMX UART driver Nandor Han
2016-08-08 12:38   ` [PATCH 1/4] dmaengine: imx-sdma - reduce transfer latency for DMA cyclic clients Nandor Han
2016-08-08 12:38   ` Nandor Han [this message]
2016-08-08 12:38   ` [PATCH 3/4] serial: imx-serial - update UART IMX driver to use cyclic DMA Nandor Han
2016-08-08 12:38   ` [PATCH 4/4] serial: imx-serial - update RX error counters when DMA is used Nandor Han

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=0e47cf5eb88ef63f844f310bfbd836264f65ccdf.1470656658.git.nandor.han@ge.com \
    --to=nandor.han@ge.com \
    --cc=dan.j.williams@intel.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=peter.senna@collabora.com \
    --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).