From: Koichiro Den <den@valinux.co.jp>
To: Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
Manivannan Sadhasivam <mani@kernel.org>
Cc: Gustavo Pimentel <Gustavo.Pimentel@synopsys.com>,
Serge Semin <fancer.lancer@gmail.com>,
Cai Huoqing <cai.huoqing@linux.dev>,
Niklas Cassel <cassel@kernel.org>,
Devendra K Verma <devverma@amd.com>,
dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-pci@vger.kernel.org
Subject: [PATCH v8 2/7] dmaengine: dw-edma: Avoid resetting an LL on stale stopped status
Date: Sat, 7 Nov 2026 22:30:22 +0900 [thread overview]
Message-ID: <20261107133027.364237-3-den@valinux.co.jp> (raw)
In-Reply-To: <20261107133027.364237-1-den@valinux.co.jp>
CS can still report STOPPED briefly after a doorbell write, before the
DMA engine starts consuming the published LL entries. Finishing
termination relying solely on that value can reset the ring while a
transfer is about to start, leaving hardware and software ring positions
out of sync and stalling subsequent transfers.
Require LLP to reach the published tail, on top of the standard criteria
(ie. CS=STOPPED and zero transfer size) before
dw_edma_finish_termination(). Non-LL mode behavior is unchanged.
Cc: stable@vger.kernel.org
Fixes: db79c4e264ef ("dmaengine: dw-edma: Make DMA link list work as a circular buffer")
Signed-off-by: Koichiro Den <den@valinux.co.jp>
---
Changes from v7:
- Resample LLP and stop status if stopped to catch progress made after
the first LLP read (follow-up to Sashiko's review).
@Frank: Dropped your R-b due to the change; would appreciate another
look.
drivers/dma/dw-edma/dw-edma-core.c | 45 ++++++++++++++++++++++++++++--
1 file changed, 43 insertions(+), 2 deletions(-)
diff --git a/drivers/dma/dw-edma/dw-edma-core.c b/drivers/dma/dw-edma/dw-edma-core.c
index b08bb31657c9..0c8b9545a5ba 100644
--- a/drivers/dma/dw-edma/dw-edma-core.c
+++ b/drivers/dma/dw-edma/dw-edma-core.c
@@ -146,6 +146,44 @@ static bool dw_edma_ll_pending(struct dw_edma_chan *chan)
return chan->ll_head != chan->ll_done;
}
+static bool dw_edma_ll_stopped(struct dw_edma_chan *chan)
+{
+ return dw_edma_core_ch_status(chan) == DMA_COMPLETE &&
+ !dw_edma_core_ch_transfer_size(chan);
+}
+
+static int dw_edma_ll_read_idx(struct dw_edma_chan *chan, bool *stopped)
+{
+ int idx;
+
+ /* Sample LLP first in case the engine starts between the reads. */
+ idx = dw_edma_core_ll_cur_idx(chan);
+ *stopped = dw_edma_ll_stopped(chan);
+ if (*stopped) {
+ /*
+ * Re-read once to catch the final LLP if the channel remains
+ * stopped. If it restarts, later interrupts will report
+ * further progress.
+ */
+ idx = dw_edma_core_ll_cur_idx(chan);
+ *stopped = dw_edma_ll_stopped(chan);
+ }
+
+ return idx;
+}
+
+static bool dw_edma_ll_drained(struct dw_edma_chan *chan)
+{
+ bool stopped;
+ int idx;
+
+ idx = dw_edma_ll_read_idx(chan, &stopped);
+ if (idx == chan->ll_max)
+ idx = 0;
+
+ return stopped && idx >= 0 && (u32)idx == chan->ll_head;
+}
+
static void dw_edma_core_ll_start(struct dw_edma_desc *desc)
{
struct dw_edma_chan *chan = desc->chan;
@@ -455,7 +493,9 @@ static int dw_edma_device_terminate_all(struct dma_chan *dchan)
dw_edma_finish_termination(chan);
} else if (chan->status == EDMA_ST_IDLE) {
dw_edma_finish_termination(chan);
- } else if (dw_edma_core_ch_status(chan) == DMA_COMPLETE) {
+ } else if (chan->non_ll ?
+ dw_edma_core_ch_status(chan) == DMA_COMPLETE :
+ dw_edma_ll_drained(chan)) {
/*
* The channel is in a false BUSY state, probably didn't
* receive or lost an interrupt
@@ -790,7 +830,8 @@ static void dw_edma_done_interrupt_locked(struct dw_edma_chan *chan)
if (!vd)
break;
- dw_edma_finish_termination(chan);
+ if (chan->non_ll || dw_edma_ll_drained(chan))
+ dw_edma_finish_termination(chan);
break;
default:
--
2.54.0
next prev parent reply other threads:[~2026-11-07 13:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 13:30 [PATCH v8 0/7] dmaengine: dw-edma: Support dynamic LL appends Koichiro Den
2026-11-07 13:30 ` [PATCH v8 1/7] dmaengine: dw-edma: Add a channel transfer size operation Koichiro Den
2026-11-07 13:30 ` Koichiro Den [this message]
2026-11-12 17:47 ` [PATCH v8 2/7] dmaengine: dw-edma: Avoid resetting an LL on stale stopped status Frank Li
2026-11-07 13:30 ` [PATCH v8 3/7] dmaengine: dw-edma: Factor out descriptor completion Koichiro Den
2026-11-07 13:30 ` [PATCH v8 4/7] dmaengine: dw-edma: Reclaim LL entries from hardware progress Koichiro Den
2026-11-12 17:58 ` Frank Li
2026-11-07 13:30 ` [PATCH v8 5/7] dmaengine: dw-edma: Use HDMA watermark interrupts as LL progress Koichiro Den
2026-11-07 13:30 ` [PATCH v8 6/7] dmaengine: dw-edma: Dynamically append requests while running Koichiro Den
2026-11-07 13:30 ` [PATCH v8 7/7] dmaengine: dw-edma: Add trace support Koichiro Den
2026-12-04 7:55 ` [PATCH v8 0/7] dmaengine: dw-edma: Support dynamic LL appends Koichiro Den
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=20261107133027.364237-3-den@valinux.co.jp \
--to=den@valinux.co.jp \
--cc=Frank.Li@kernel.org \
--cc=Gustavo.Pimentel@synopsys.com \
--cc=cai.huoqing@linux.dev \
--cc=cassel@kernel.org \
--cc=devverma@amd.com \
--cc=dmaengine@vger.kernel.org \
--cc=fancer.lancer@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mani@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
all inboxes | Powered by JetHome®