Re: [PATCH 08/11] dmaengine: xilinx_dpdma: stop using slave_id field

From: Arnd Bergmann
Date: Mon Nov 15 2021 - 05:21:59 EST


On Mon, Nov 15, 2021 at 10:14 AM Laurent Pinchart
<laurent.pinchart@xxxxxxxxxxxxxxxx> wrote:
> On Mon, Nov 15, 2021 at 09:54:00AM +0100, Arnd Bergmann wrote:
> > @@ -1285,11 +1287,13 @@ static int xilinx_dpdma_config(struct dma_chan *dchan,
> > spin_lock_irqsave(&chan->lock, flags);
> >
> > /*
> > - * Abuse the slave_id to indicate that the channel is part of a video
> > - * group.
> > + * Abuse the peripheral_config to indicate that the channel is part
>
> Is it still an abuse, or is this now the right way to pass custom data
> to the DMA engine driver ?

It doesn't make the driver any more portable, but it's now being
more explicit about it. As far as I can tell, this is the best way
to pass data that cannot be expressed through the regular interfaces
in DT and the dmaengine API.

Ideally there would be a generic way to pass this flag, but I couldn't
figure out what this is actually doing, or whether there is a better
way. Maybe Vinod has an idea.

I'll change s/Abuse/Use/ for the moment until I get a definite answer.

> > + * of a video group.
> > */
> > - if (chan->id <= ZYNQMP_DPDMA_VIDEO2)
> > - chan->video_group = config->slave_id != 0;
> > + pconfig = config->peripheral_config;
>
> This could be moved to the variable declaration above, up to you.

I considered that but since it doesn't fit in a normal 80-column
line, it seemed best to do it here.

> > + if (chan->id <= ZYNQMP_DPDMA_VIDEO2 &&
> > + config->peripheral_size == sizeof(*pconfig))
>
> Silently ignoring a size mismatch isn't nice. Could we validate the size
> at the beginning of the function and return an error ?

Yes, good idea. Since this would mean a bug in another driver,
I'll add a WARN_ON() as well to make it clear which driver caused it.
This is what I have now, let me know if you have any further suggestions:

/*
* Use the peripheral_config to indicate that the channel is part
* of a video group. This requires matching use of the custom
* structure in each driver.
*/
pconfig = config->peripheral_config;
if (WARN_ON(config->peripheral_size != 0 &&
config->peripheral_size != sizeof(*pconfig)))
return -EINVAL;

spin_lock_irqsave(&chan->lock, flags);
if (chan->id <= ZYNQMP_DPDMA_VIDEO2 &&
config->peripheral_size == sizeof(*pconfig))
chan->video_group = pconfig->video_group;
spin_unlock_irqrestore(&chan->lock, flags);

return 0;

> With these issues addressed,
>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@xxxxxxxxxxxxxxxx>

Thanks,

Arnd