Re: [PATCH v5 09/17] dmaengine: sh: rz-dmac: Use virt-dma APIs for channel descriptor processing

From: Frank Li

Date: Tue May 12 2026 - 17:38:44 EST


On Tue, May 12, 2026 at 03:12:10PM +0300, Claudiu Beznea wrote:
> The driver used a mix of virt-dma APIs and driver specific logic to
> process descriptors. It maintained three internal queues: ld_free,
> ld_queue, and ld_active as follows:
> - ld_free: stores the descriptors pre-allocated at probe time
> - ld_queue: stores descriptors after they are taken from ld_free and
> prepared. At the same time, vchan_tx_prep() queues them to
> vc->desc_allocated. The vc->desc_allocated list is then checked in
> rz_dmac_issue_pending() and rz_dmac_irq_handler_thread() before
> starting a new transfer via rz_dmac_xfer_desc(). In turn,
> rz_dmac_xfer_desc() grabs the next descriptor from vc->desc_issued and
> submits it for transfer
> - ld_active: stores the descriptors currently being transferred
>
> The interrupt handler moved a completed descriptor to ld_free before
> invoking its completion callback. Once returned to ld_free, the
> descriptor can be reused to prepare a new transfer. In theory, this
> means the descriptor could be re-prepared before its completion
> callback is called.
>
> Commit fully back the driver by the virt-dma APIs. With this, only ld_free
> need to be kept to track how many free descriptors are available. This
> is now done as follows:
> - the prepare stage removes the first descriptor from the ld_free and
> prepares it
> - the completion calls for it vc->desc_free() (rz_dmac_virt_desc_free())
> which re-adds the descriptor at the end of ld_free
>
> With this, the critical areas in prepare callbacks were minimized to only
> getting the descriptor from the ld_free list.

Do you plan remove ld_free also?

>
> This change introduces struct rz_dmac_chan::desc to keep track of the

Remove "this change", just Introduce ...

Frank
> currently transferred descriptor. It is cleared in
> rz_dmac_terminate_all(), referenced from rz_dmac_issue_pending() to
> determine whether a new transfer can be started, and from
> rz_dmac_irq_handler_thread() once a descriptor has completed. Finally,
> the rz_dmac_device_synchronize() was updated with vchan_synchronize()
> call to ensure the terminated descriptor is freed and the tasklet is
> killed.
>
> With this, residue computation is also simplified, as it can now be
> handled entirely through the virt-dma APIs.
>
> The spin_lock/unlock operations from rz_dmac_irq_handler_thread() were
> replaced by guard as the final code after rework is simpler this way.
>
> As subsequent commits will set the Link End bit on the last descriptor
> of a transfer, rz_dmac_enable_hw() is also adjusted as part of the full
> conversion to virt-dma APIs. It no longer checks the channel enable
> status itself; instead, its callers verify whether the channel is
> enabled and whether the previous transfer has completed before starting
> a new one.
>
> Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@xxxxxxxxxxxxxx>
> ---
>