Re: [PATCH v3 2/2] dmaengine: fsl-edma: Support dynamic scatter/gather chaining
From: Benoît Monin
Date: Tue May 12 2026 - 11:58:00 EST
On Monday, 11 May 2026 at 21:20:15 CEST, Frank Li wrote:
> On Mon, May 11, 2026 at 03:57:20PM +0200, Benoît Monin wrote:
> > Implement dynamic linking of scatter/gather transfers to enable
> > chaining multiple DMA descriptors without stopping the channel.
> > This avoids waiting for the channel to go idle if there is another
> > transaction already issued.
> >
> > Add fsl_edma_link_sg() to dynamically link the last TCD of a previously
> > submitted descriptor to the first TCD of a new descriptor by setting
> > the scatter/gather address and the E_SG flag, and keeping the channel
> > active by clearing the DREQ bit.
> >
> > Linking is done when the transaction is submitted by fsl_edma_tx_submit().
> > To do so, the .tx_submit() callback is overridden for non-cyclic
> > transactions prepared by fsl_edma_prep_peripheral_dma_vec() and
> > fsl_edma_prep_slave_sg(). This ensures that transactions are linked
> > in the order they are submitted.
> >
> > Update fsl_edma_xfer_desc() to avoid re-initializing the hardware when a
> > transfer is already in progress, allowing seamless chaining of descriptors.
> >
> > Modify the transfer completion handler to check the DONE flag in the
> > channel CSR before marking the transfer complete. Since this flag is
> > only available on SoC with the split registers layout, we only link
> > transactions for DMA controllers flagged with FSL_EDMA_DRV_SPLIT_REG.
> >
> > Add trace event for scatter/gather linking operations.
> >
> > Signed-off-by: Benoît Monin <benoit.monin@xxxxxxxxxxx>
> > ---
> > drivers/dma/fsl-edma-common.c | 90 +++++++++++++++++++++++++++++++++++++++----
> > drivers/dma/fsl-edma-trace.h | 5 +++
> > 2 files changed, 88 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/dma/fsl-edma-common.c b/drivers/dma/fsl-edma-common.c
> > index c10190164926..b83d1b91dca2 100644
> > --- a/drivers/dma/fsl-edma-common.c
> > +++ b/drivers/dma/fsl-edma-common.c
> > @@ -58,7 +58,10 @@ void fsl_edma_tx_chan_handler(struct fsl_edma_chan *fsl_chan)
> > list_del(&fsl_chan->edesc->vdesc.node);
> > vchan_cookie_complete(&fsl_chan->edesc->vdesc);
> > fsl_chan->edesc = NULL;
> > - fsl_chan->status = DMA_COMPLETE;
> > + if (!(fsl_edma_drvflags(fsl_chan) & FSL_EDMA_DRV_SPLIT_REG) ||
> > + (edma_readl_chreg(fsl_chan, ch_csr) & EDMA_V3_CH_CSR_DONE)) {
> > + fsl_chan->status = DMA_COMPLETE;
>
> Does fsl_edma_desc_residue() needs to update?
>
I don't think so. Computing the residue of one vdesc is not modified by the
fact that is it linked to another transaction.
> > + }
> > } else {
> > vchan_cyclic_callback(&fsl_chan->edesc->vdesc);
> > }
> > @@ -673,6 +676,68 @@ struct dma_async_tx_descriptor *fsl_edma_prep_dma_cyclic(
> > return vchan_tx_prep(&fsl_chan->vchan, &fsl_desc->vdesc, flags);
> > }
> >
> > +static void fsl_edma_link_sg(struct fsl_edma_chan *fsl_chan, struct fsl_edma_desc *fsl_desc)
> > +{
> > + u32 flags = fsl_edma_drvflags(fsl_chan);
> > + struct fsl_edma_hw_tcd *last_tcd;
> > + struct fsl_edma_desc *prev_desc;
> > + struct virt_dma_desc *vdesc;
> > + u16 csr;
> > +
> > + lockdep_assert_held(&fsl_chan->vchan.lock);
> > +
> > + if (!(flags & FSL_EDMA_DRV_SPLIT_REG))
> > + return;
> > +
> > + vdesc = list_last_entry_or_null(&fsl_chan->vchan.desc_issued,
> > + struct virt_dma_desc, node);
> > + if (!vdesc)
> > + vdesc = list_last_entry_or_null(&fsl_chan->vchan.desc_submitted,
> > + struct virt_dma_desc, node);
> > + if (!vdesc)
> > + return;
>
> Suppose you only check submit queue,
>
> issue transfer will move submit queue to issue queue.
>
Right, It's the other way around. I should first look for the last submitted
entry, then check the issued list. Will fix.
Best regards,
--
Benoît Monin, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com