dmaengine.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jisheng Zhang <jszhang@kernel.org>
To: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>,
	Vinod Koul <vkoul@kernel.org>
Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v3 09/11] dmaengine: dw-axi-dmac: try best to get residue when tx is running
Date: Sun, 21 May 2023 18:12:14 +0800	[thread overview]
Message-ID: <20230521101216.4084-10-jszhang@kernel.org> (raw)
In-Reply-To: <20230521101216.4084-1-jszhang@kernel.org>

When tx is running, vchan_find_desc() will return NULL, try our best
to get the residue in this case.

Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
 drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
index f0bd8a7e3caf..f14fdfc9c7e9 100644
--- a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
+++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
@@ -312,6 +312,7 @@ dma_chan_tx_status(struct dma_chan *dchan, dma_cookie_t cookie,
 		  struct dma_tx_state *txstate)
 {
 	struct axi_dma_chan *chan = dchan_to_axi_dma_chan(dchan);
+	struct axi_dma_desc *desc = NULL;
 	struct virt_dma_desc *vdesc;
 	enum dma_status status;
 	u32 completed_length;
@@ -329,9 +330,15 @@ dma_chan_tx_status(struct dma_chan *dchan, dma_cookie_t cookie,
 
 	vdesc = vchan_find_desc(&chan->vc, cookie);
 	if (vdesc) {
-		length = vd_to_axi_desc(vdesc)->length;
-		completed_blocks = vd_to_axi_desc(vdesc)->completed_blocks;
-		len = vd_to_axi_desc(vdesc)->hw_desc[0].len;
+		desc = vd_to_axi_desc(vdesc);
+	} else if (chan->desc && chan->desc->vd.tx.cookie == cookie) {
+		desc = chan->desc;
+	}
+
+	if (desc) {
+		length = desc->length;
+		completed_blocks = desc->completed_blocks;
+		len = desc->hw_desc[0].len;
 		completed_length = completed_blocks * len;
 		bytes = length - completed_length;
 	}
@@ -432,6 +439,7 @@ static void axi_chan_block_xfer_start(struct axi_dma_chan *chan,
 	axi_chan_irq_set(chan, irq_mask);
 
 	axi_chan_enable(chan);
+	chan->desc = first;
 }
 
 static void axi_chan_start_first_queued(struct axi_dma_chan *chan)
@@ -1195,6 +1203,7 @@ static int dma_chan_terminate_all(struct dma_chan *dchan)
 	spin_unlock_irqrestore(&chan->vc.lock, flags);
 
 	vchan_dma_desc_free_list(&chan->vc, &head);
+	chan->desc = NULL;
 
 	dev_vdbg(dchan2dev(dchan), "terminated: %s\n", axi_chan_name(chan));
 
-- 
2.40.0


  parent reply	other threads:[~2023-05-21 10:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-21 10:12 [PATCH v3 00/11] dmaengine: dw-axi_dmac: bug fix clean up and more features Jisheng Zhang
2023-05-21 10:12 ` [PATCH v3 01/11] dmaengine: dw-axi-dmac: fix reading register when runtime suspended Jisheng Zhang
2023-05-21 10:12 ` [PATCH v3 02/11] dmaengine: dw-axi-dmac: remove unnecessary devm_free_irq() calling Jisheng Zhang
2023-05-21 10:12 ` [PATCH v3 03/11] dmaengine: dw-axi-dmac: remove unnecessary axi_dma_enable() calling Jisheng Zhang
2023-05-21 10:12 ` [PATCH v3 04/11] dmaengine: dw-axi-dmac: remove redundant axi_dma_disable() calling Jisheng Zhang
2023-05-21 10:12 ` [PATCH v3 05/11] dmaengine: dw-axi-dmac: delay irq getting until request_irq Jisheng Zhang
2023-05-21 10:12 ` [PATCH v3 06/11] dmaengine: dw-axi-dmac: move ch irq handling into common routine Jisheng Zhang
2023-05-21 10:12 ` [PATCH v3 07/11] dmaengine: dw-axi-dmac: support per channel irq Jisheng Zhang
2023-05-21 10:12 ` [PATCH v3 08/11] dmaengine: dw-axi-dmac: support dma-channel-mask Jisheng Zhang
2023-05-21 10:12 ` Jisheng Zhang [this message]
2023-05-21 10:12 ` [PATCH v3 10/11] dmaengine: dw-axi-dmac: move dma_chan_tx_status() Jisheng Zhang
2023-05-21 10:12 ` [PATCH v3 11/11] dmaengine: dw-axi-dmac: support polled mode Jisheng Zhang

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=20230521101216.4084-10-jszhang@kernel.org \
    --to=jszhang@kernel.org \
    --cc=Eugeniy.Paltsev@synopsys.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vkoul@kernel.org \
    /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).