mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: James Hilliard <james.hilliard1@gmail.com>
Cc: "Viresh Kumar" <vireshk@kernel.org>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Vinod Koul" <vkoul@kernel.org>, "Frank Li" <Frank.Li@kernel.org>,
	"Dan Williams" <djbw@kernel.org>,
	"Serge Semin" <fancer.lancer@gmail.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Jiri Slaby" <jirislaby@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	dmaengine@vger.kernel.org, linux-serial@vger.kernel.org,
	linux-kernel@vger.kernel.org, Sashiko <sashiko-bot@kernel.org>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	stable@vger.kernel.org
Subject: Re: [PATCH v5 05/10] dmaengine: dw: calculate residue in the status getter
Date: Mon, 2 Nov 2026 15:10:03 -0600	[thread overview]
Message-ID: <auj8K5jwbBOZWIOu@SMW015318> (raw)
In-Reply-To: <20261102-submit-dw-dma-synchronize-v1-v5-5-d3207758fbf9@gmail.com>

On Mon, Nov 02, 2026 at 12:34:17PM -0700, James Hilliard wrote:
> From: Serge Semin <fancer.lancer@gmail.com>
>
> Calculate hardware-LLP residue while looking up the requested cookie under
> the channel lock. The scanner and the status getter currently take that
> lock separately, allowing a descriptor to start between the scanner's
> residue update and the status query.
>
> Have dwc_get_hard_llp_desc_residue() return a local residue value from a
> fresh LLP snapshot. Keep the persistent residue field for software-LLP
> block accounting, subtracting the current block's progress when reporting
> status. The descriptor scanner continues to advance software-LLP blocks
> and complete cookies from RAW.XFER, including for polled transfers.
>
> Fixes: 3bfb1d20b547 ("dmaengine: Driver for the Synopsys DesignWare DMA controller")
> Cc: stable@vger.kernel.org
> Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
> [james: retain polled completion and software-LLP progress]
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
>
> ---
>
> Changelog RFC:
> - Instead of just dropping the dwc_scan_descriptors() method invocation
>   calculate the residue in the Tx-status getter.
> ---
>  drivers/dma/dw/core.c | 88 ++++++++++++++++++---------------------------------
>  1 file changed, 31 insertions(+), 57 deletions(-)
>
> diff --git a/drivers/dma/dw/core.c b/drivers/dma/dw/core.c
> index 5a1caca7ad68..0d6b5bd8ea6b 100644
> --- a/drivers/dma/dw/core.c
> +++ b/drivers/dma/dw/core.c
> @@ -267,41 +267,8 @@ static inline u32 dwc_get_sent(struct dw_dma_chan *dwc)
>  	return dw->block2bytes(dwc, ctlhi, ctllo >> 4 & 7);
>  }
>
> -static bool dwc_get_hard_llp_desc_residue(struct dw_dma_chan *dwc,
> -				       struct dw_desc *desc, dma_addr_t llp)
> -{
> -	struct dw_desc *child;
> -
> -	/* Initial residue value */
> -	desc->residue = desc->total_len;
> -
> -	/* Check first descriptors addr */
> -	if (desc->txd.phys == DWC_LLP_LOC(llp))
> -		return true;
> -
> -	/* Check first descriptors llp */
> -	if (lli_read(desc, llp) == llp) {
> -		/* This one is currently in progress */
> -		desc->residue -= dwc_get_sent(dwc);
> -		return true;
> -	}
> -
> -	desc->residue -= desc->len;
> -	list_for_each_entry(child, &desc->tx_list, desc_node) {
> -		if (lli_read(child, llp) == llp) {
> -			/* Currently in progress */
> -			desc->residue -= dwc_get_sent(dwc);
> -			return true;
> -		}
> -		desc->residue -= child->len;
> -	}
> -
> -	return false;
> -}
> -
>  static void dwc_scan_descriptors(struct dw_dma *dw, struct dw_dma_chan *dwc)
>  {
> -	dma_addr_t llp;
>  	struct dw_desc *desc, *_desc;
>  	struct dw_desc *child;
>  	u32 status_xfer;
> @@ -309,7 +276,6 @@ static void dwc_scan_descriptors(struct dw_dma *dw, struct dw_dma_chan *dwc)
>  	LIST_HEAD(list);
>
>  	spin_lock_irqsave(&dwc->lock, flags);
> -	llp = channel_readl(dwc, LLP);
>  	status_xfer = dma_readl(dw, RAW.XFER);
>
>  	if (status_xfer & dwc->mask) {
> @@ -372,27 +338,6 @@ static void dwc_scan_descriptors(struct dw_dma *dw, struct dw_dma_chan *dwc)
>  		return;
>  	}
>
> -	if (list_empty(&dwc->active_list)) {
> -		spin_unlock_irqrestore(&dwc->lock, flags);
> -		return;
> -	}
> -
> -	if (test_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags)) {
> -		dev_vdbg(dmaengine_chan_dev(&dwc->chan), "%s: soft LLP mode\n", __func__);
> -		spin_unlock_irqrestore(&dwc->lock, flags);
> -		return;
> -	}
> -
> -	dev_vdbg(dmaengine_chan_dev(&dwc->chan), "%s: llp=%pad\n", __func__, &llp);
> -
> -	list_for_each_entry_safe(desc, _desc, &dwc->active_list, desc_node) {
> -		if (dwc_get_hard_llp_desc_residue(dwc, desc, llp)) {
> -			spin_unlock_irqrestore(&dwc->lock, flags);
> -			return;
> -		}
> -	}
> -
> -	/* Residue describes source reads; only RAW.XFER completes a transfer. */
>  	spin_unlock_irqrestore(&dwc->lock, flags);
>  }
>
> @@ -975,6 +920,32 @@ static struct dw_desc *dwc_find_desc(struct dw_dma_chan *dwc, dma_cookie_t c)
>  	return NULL;
>  }
>
> +static u32 dwc_get_hard_llp_desc_residue(struct dw_dma_chan *dwc, struct dw_desc *desc)
> +{

Don't move this function, just change to return value boot to u32 to reduce
changes.


Frank

  reply	other threads:[~2026-11-02 21:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02 19:34 [PATCH v5 00/10] dmaengine: dw: serialize completion and termination James Hilliard
2026-11-02 19:34 ` [PATCH v5 01/10] dmaengine: dw: Fix XFER bit set, but channel not idle error James Hilliard
2026-11-02 19:34 ` [PATCH v5 02/10] dmaengine: dw: serialize error recovery with channel termination James Hilliard
2026-11-02 19:34 ` [PATCH v5 03/10] dmaengine: dw: complete cookies before releasing the channel lock James Hilliard
2026-11-02 19:34 ` [PATCH v5 04/10] dmaengine: dw: extract hardware-LLP residue calculation James Hilliard
2026-11-02 19:34 ` [PATCH v5 05/10] dmaengine: dw: calculate residue in the status getter James Hilliard
2026-11-02 21:10   ` Frank Li [this message]
2026-11-02 19:34 ` [PATCH v5 06/10] dmaengine: dw: simplify transfer-complete handling James Hilliard
2026-11-02 19:34 ` [PATCH v5 07/10] dmaengine: dw: report residue for queued transfers James Hilliard
2026-11-02 19:34 ` [PATCH v5 08/10] dmaengine: dw: drain the tasklet before releasing channel resources James Hilliard
2026-11-02 19:34 ` [PATCH v5 09/10] dmaengine: dw: synchronize completion callbacks James Hilliard
2026-11-02 19:34 ` [PATCH v5 10/10] dmaengine: dw: Prevent tx-status calling DMA-desc callback James Hilliard

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=auj8K5jwbBOZWIOu@SMW015318 \
    --to=frank.li@oss.nxp.com \
    --cc=Frank.Li@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=djbw@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=fancer.lancer@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=james.hilliard1@gmail.com \
    --cc=jirislaby@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=sashiko-bot@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=vireshk@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®