Re: [PATCH v5 05/10] dmaengine: dw: calculate residue in the status getter
From: Frank Li
Date: Mon Nov 02 2026 - 17:51:06 EST
On Mon, Nov 02, 2026 at 12:34:17PM -0700, James Hilliard wrote:
> From: Serge Semin <fancer.lancer@xxxxxxxxx>
>
> 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@xxxxxxxxxxxxxxx
> Signed-off-by: Serge Semin <fancer.lancer@xxxxxxxxx>
> [james: retain polled completion and software-LLP progress]
> Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
>
> ---
>
> 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