RE: [PATCH v4 07/17] dmaengine: sh: rz-dmac: Save the start LM descriptor

From: Biju Das

Date: Sat Apr 11 2026 - 08:51:36 EST


Hi Claudiu,

> -----Original Message-----
> From: Claudiu Beznea <claudiu.beznea@xxxxxxxxx>
> Sent: 11 April 2026 13:39
> Subject: Re: [PATCH v4 07/17] dmaengine: sh: rz-dmac: Save the start LM descriptor
>
>
>
> On 4/11/26 15:34, Biju Das wrote:
> > Hi Claudiu,
> >
> >> -----Original Message-----
> >> From: Claudiu <claudiu.beznea@xxxxxxxxx>
> >> Sent: 11 April 2026 12:43
> >> Subject: [PATCH v4 07/17] dmaengine: sh: rz-dmac: Save the start LM
> >> descriptor
> >>
> >> From: Claudiu Beznea <claudiu.beznea.uj@xxxxxxxxxxxxxx>
> >>
> >> Save the start LM descriptor to avoid looping through the entire
> >> channel's LM descriptor list when computing the residue. This avoids unnecessary iterations.
> >>
> >> Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@xxxxxxxxxxxxxx>
> >> ---
> >>
> >> Changes in v4:
> >> - none
> >>
> >> Changes in v3:
> >> - none, this patch is new
> >>
> >> drivers/dma/sh/rz-dmac.c | 11 ++++++++---
> >> 1 file changed, 8 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c
> >> index 6bea7c8c7053..0f871c0a28bd
> >> 100644
> >> --- a/drivers/dma/sh/rz-dmac.c
> >> +++ b/drivers/dma/sh/rz-dmac.c
> >> @@ -58,6 +58,7 @@ struct rz_dmac_desc {
> >> /* For slave sg */
> >> struct scatterlist *sg;
> >> unsigned int sgcount;
> >> + struct rz_lmdesc *start_lmdesc;
> >> };
> >>
> >> #define to_rz_dmac_desc(d) container_of(d, struct rz_dmac_desc, vd)
> >> @@ -343,6 +344,8 @@ static void rz_dmac_prepare_desc_for_memcpy(struct rz_dmac_chan *channel)
> >> struct rz_dmac_desc *d = channel->desc;
> >> u32 chcfg = CHCFG_MEM_COPY;
> >>
> >> + d->start_lmdesc = lmdesc;
> >> +
> >> /* prepare descriptor */
> >> lmdesc->sa = d->src;
> >> lmdesc->da = d->dest;
> >> @@ -377,6 +380,7 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct rz_dmac_chan *channel)
> >> }
> >>
> >> lmdesc = channel->lmdesc.tail;
> >> + d->start_lmdesc = lmdesc;
> >>
> >> for (i = 0, sg = sgl; i < sg_len; i++, sg = sg_next(sg)) {
> >> if (d->direction == DMA_DEV_TO_MEM) { @@ -693,9 +697,10 @@
> >> rz_dmac_get_next_lmdesc(struct rz_lmdesc *base, struct rz_lmdesc *lmdesc)
> >> return next;
> >> }
> >>
> >> -static u32 rz_dmac_calculate_residue_bytes_in_vd(struct rz_dmac_chan
> >> *channel, u32 crla)
> >> +static u32 rz_dmac_calculate_residue_bytes_in_vd(struct rz_dmac_chan *channel,
> >> + struct rz_dmac_desc *desc, u32 crla)
> >
> > U32 normally used with register read/writes hardware related.
> >
> > Here it is just computation which returns number of bytes. Unsigned
> > int will be appropriate instead of u32.
>
> Please check the type of residue as defined by dma_set_residue().

My comment is based on [1]

[1] https://lore.kernel.org/all/87o6kilwd5.ffs@tglx/

Cheers,
Biju