Re: [PATCH v4 1/1] dmaengine: switchtec-dma: Introduce Switchtec DMA engine PCI driver

From: Kelvin.Cao
Date: Mon May 15 2023 - 14:20:05 EST


On Mon, 2023-05-15 at 08:13 -0700, Christoph Hellwig wrote:
>
> > > > +     union {
> > > > +             __le32 saddr_lo;
> > > > +             __le32 widata_lo;
> > > > +     };
> > > > +     union {
> > > > +             __le32 saddr_hi;
> > > > +             __le32 widata_hi;
> > > > +     };
> > >
> > > What is the point for unions of identical data types?
> >
> > The same offset could hold either source address or write immediate
> > data in different transactions. Unions used here is to give
> > different
> > names for the same offset. I guess it improves readability when
> > referring to them with proper names.
>
> I find this rather confusing, especially as some code literally
> switches on the op to fill in either set.

It's a hardware interface, and not possible to change it at the point.
I guess I can make it look slightly better by grouping the related
names together:

union {
struct {
__le32 saddr_lo;
__le32 saddr_hi;
};
struct {
__le32 widata_lo;
__le32 widata_hi;
};
};
>
>
> > > > +#define SWITCHTEC_DMA_DEVICE(device_id) \
> > > > +     { \
> > > > +             .vendor     = PCI_VENDOR_ID_MICROSEMI, \
> > > > +             .device     = device_id, \
> > > > +             .subvendor  = PCI_ANY_ID, \
> > > > +             .subdevice  = PCI_ANY_ID, \
> > > > +             .class      = PCI_CLASS_SYSTEM_OTHER << 8, \
> > > > +             .class_mask = 0xFFFFFFFF, \
> > > > +     }
> > > > +
> > > > +static const struct pci_device_id switchtec_dma_pci_tbl[] = {
> > > > +     SWITCHTEC_DMA_DEVICE(0x4000), /* PFX 100XG4 */
> > >
> > > This should use the common PCI_DEVICE() macro instead, i.e.
> > >
> > >         PCI_DEVICE(PCI_VENDOR_ID_MICROSEMI, 0x4000), /* PFX
> > > 100XG4 */
> > >         ...
> >
> > We also need to distinguish the .class as we have devices of other
> > .class with the same vendor/device ID.
>
> Ok, that's roetty weird and probably worth a little comment.

Will add some comment on this.