[PATCH v8 4/6] dmaengine: dw: extract hardware-LLP residue calculation
From: James Hilliard
Date: Mon Nov 16 2026 - 05:53:30 EST
From: Serge Semin <fancer.lancer@xxxxxxxxx>
Move the hardware-LLP residue calculation into
dwc_get_hard_llp_desc_residue() so it can be reused independently of
completion handling.
Keep the scanner's LLP snapshot, descriptor updates and early returns
unchanged. Only one transaction is active, so the helper updates its
cached residue directly without reporting a completion indication.
Signed-off-by: Serge Semin <fancer.lancer@xxxxxxxxx>
[james: extract the calculation for the single active virt-dma transaction]
Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
---
drivers/dma/dw/core.c | 42 +++++++++++++++++++++++++-----------------
1 file changed, 25 insertions(+), 17 deletions(-)
diff --git a/drivers/dma/dw/core.c b/drivers/dma/dw/core.c
index 982a4b9bd678..504b6ddeccd4 100644
--- a/drivers/dma/dw/core.c
+++ b/drivers/dma/dw/core.c
@@ -214,6 +214,30 @@ static inline u32 dwc_get_sent(struct dw_dma_chan *dwc)
return dw->block2bytes(dwc, ctlhi, ctllo >> 4 & 7);
}
+static void dwc_get_hard_llp_desc_residue(struct dw_dma_chan *dwc,
+ struct dw_desc *desc, dma_addr_t llp)
+{
+ struct dw_desc *child;
+
+ desc->residue = desc->total_len;
+ if (desc->vd.tx.phys == DWC_LLP_LOC(llp))
+ return;
+
+ if (lli_read(desc, llp) == llp) {
+ desc->residue -= dwc_get_sent(dwc);
+ return;
+ }
+
+ desc->residue -= desc->len;
+ list_for_each_entry(child, &desc->tx_list, vd.node) {
+ if (lli_read(child, llp) == llp) {
+ desc->residue -= dwc_get_sent(dwc);
+ return;
+ }
+ desc->residue -= child->len;
+ }
+}
+
static void dwc_scan_descriptors(struct dw_dma *dw, struct dw_dma_chan *dwc)
{
struct dw_desc *desc;
@@ -270,23 +294,7 @@ static void dwc_scan_descriptors(struct dw_dma *dw, struct dw_dma_chan *dwc)
if (!desc || test_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags))
return;
- desc->residue = desc->total_len;
- if (desc->vd.tx.phys == DWC_LLP_LOC(llp))
- return;
-
- if (lli_read(desc, llp) == llp) {
- desc->residue -= dwc_get_sent(dwc);
- return;
- }
-
- desc->residue -= desc->len;
- list_for_each_entry(child, &desc->tx_list, vd.node) {
- if (lli_read(child, llp) == llp) {
- desc->residue -= dwc_get_sent(dwc);
- return;
- }
- desc->residue -= child->len;
- }
+ dwc_get_hard_llp_desc_residue(dwc, desc, llp);
}
static inline void dwc_dump_lli(struct dw_dma_chan *dwc, struct dw_desc *desc)
--
2.53.0