From: Christopher Freeman <cfreeman@nvidia.com>
To: <ldewangan@nvidia.com>, <swarren@nvidia.com>,
<vinod.koul@intel.com>, <dan.j.williams@intel.com>
Cc: <dmaengine@vger.kernel.org>, <linux-tegra@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
Christopher Freeman <cfreeman@nvidia.com>
Subject: [PATCH v1 1/3] dma: tegra: finer granularity residual for tx_status
Date: Tue, 6 May 2014 14:22:21 -0700 [thread overview]
Message-ID: <1399411343-12222-2-git-send-email-cfreeman@nvidia.com> (raw)
In-Reply-To: <1399411343-12222-1-git-send-email-cfreeman@nvidia.com>
Get word-level granularity from hardware for calculating
the transfer count remaining.
Signed-off-by: Christopher Freeman <cfreeman@nvidia.com>
---
drivers/dma/tegra20-apb-dma.c | 52 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/drivers/dma/tegra20-apb-dma.c b/drivers/dma/tegra20-apb-dma.c
index 03ad64e..cc6b2fd 100644
--- a/drivers/dma/tegra20-apb-dma.c
+++ b/drivers/dma/tegra20-apb-dma.c
@@ -779,15 +779,54 @@ skip_dma_stop:
spin_unlock_irqrestore(&tdc->lock, flags);
}
+static int tegra_dma_wcount_in_bytes(struct dma_chan *dc)
+{
+ struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
+ struct tegra_dma_sg_req *sgreq;
+ unsigned long wcount = 0;
+ unsigned long status = 0;
+ int bytes = 0;
+
+ if (list_empty(&tdc->pending_sg_req) || !tdc->busy)
+ return 0;
+
+ tegra_dma_pause(tdc, true);
+
+ /* in case of interrupt, handle it and don't read wcount reg */
+ status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
+ if (status & TEGRA_APBDMA_STATUS_ISE_EOC) {
+ tdc_write(tdc, TEGRA_APBDMA_CHAN_STATUS, status);
+ dev_info(tdc2dev(tdc), "%s():handling isr\n", __func__);
+ tdc->isr_handler(tdc, false);
+ tegra_dma_resume(tdc);
+ return 0;
+ }
+
+ if (tdc->tdma->chip_data->support_separate_wcount_reg)
+ wcount = tdc_read(tdc, TEGRA_APBDMA_CHAN_WORD_TRANSFER);
+ else
+ wcount = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
+
+ sgreq = list_first_entry(&tdc->pending_sg_req,
+ typeof(*sgreq), node);
+ bytes = get_current_xferred_count(tdc, sgreq, wcount);
+
+ tegra_dma_resume(tdc);
+
+ return bytes;
+}
+
static enum dma_status tegra_dma_tx_status(struct dma_chan *dc,
dma_cookie_t cookie, struct dma_tx_state *txstate)
{
struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
struct tegra_dma_desc *dma_desc;
struct tegra_dma_sg_req *sg_req;
+ struct tegra_dma_sg_req *first_entry = NULL;
enum dma_status ret;
unsigned long flags;
unsigned int residual;
+ unsigned int hw_byte_count = 0;
ret = dma_cookie_status(dc, cookie, txstate);
if (ret == DMA_COMPLETE)
@@ -812,9 +851,22 @@ static enum dma_status tegra_dma_tx_status(struct dma_chan *dc,
list_for_each_entry(sg_req, &tdc->pending_sg_req, node) {
dma_desc = sg_req->dma_desc;
if (dma_desc->txd.cookie == cookie) {
+ hw_byte_count = tegra_dma_wcount_in_bytes(dc);
+
+ if (!list_empty(&tdc->pending_sg_req))
+ first_entry =
+ list_first_entry(&tdc->pending_sg_req,
+ typeof(*first_entry), node);
+
residual = dma_desc->bytes_requested -
(dma_desc->bytes_transferred %
dma_desc->bytes_requested);
+
+ /* hw byte count only applies to current transaction */
+ if (first_entry &&
+ first_entry->dma_desc->txd.cookie == cookie)
+ residual -= hw_byte_count;
+
dma_set_residue(txstate, residual);
ret = dma_desc->dma_status;
spin_unlock_irqrestore(&tdc->lock, flags);
--
1.7.9.5
next prev parent reply other threads:[~2014-05-06 21:22 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-06 21:22 [PATCH v1 0/3] Tegra DMA residue improvements Christopher Freeman
2014-05-06 21:22 ` Christopher Freeman [this message]
2014-05-07 16:37 ` [PATCH v1 1/3] dma: tegra: finer granularity residual for tx_status Stephen Warren
2014-05-07 22:37 ` Christopher Freeman
2014-05-12 17:27 ` Stephen Warren
2014-05-21 6:00 ` Vinod Koul
2014-05-06 21:22 ` [PATCH v1 2/3] dma: tegra: change interrupt-related log levels Christopher Freeman
2014-05-06 21:22 ` [PATCH v1 3/3] dma: tegra: avoid int overflow for transferred count Christopher Freeman
2014-05-07 16:38 ` Stephen Warren
2014-05-07 19:15 ` Lars-Peter Clausen
2014-05-07 22:50 ` Christopher Freeman
2014-05-07 6:38 ` [PATCH v1 0/3] Tegra DMA residue improvements Lars-Peter Clausen
2014-05-07 21:27 ` Christopher Freeman
2014-05-21 5:52 ` Vinod Koul
2014-05-21 6:58 ` Lars-Peter Clausen
2014-05-21 11:06 ` Vinod Koul
2014-05-21 16:21 ` Stephen Warren
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=1399411343-12222-2-git-send-email-cfreeman@nvidia.com \
--to=cfreeman@nvidia.com \
--cc=dan.j.williams@intel.com \
--cc=dmaengine@vger.kernel.org \
--cc=ldewangan@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=swarren@nvidia.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