Re: [PATCH] ahci: add 43-bit DMA address quirk for ASMedia ASM106x controllers

Niklas Cassel
2024-01-25T14:06:13Z

On Thu, Jan 25, 2024 at 03:43:06PM +0200, Lennert Buytenhek wrote:
> On Thu, Jan 25, 2024 at 02:30:14PM +0100, Niklas Cassel wrote:

(snip)

> > > @@ -943,11 +951,19 @@ static int ahci_pci_device_resume(struct device *dev)
> > >
> > > #endif /* CONFIG_PM */
> > >
> > > -static int ahci_configure_dma_masks(struct pci_dev *pdev, int using_dac)
> > > +static int ahci_configure_dma_masks(struct pci_dev *pdev,
> > > + struct ahci_host_priv *hpriv)
> > > {
> > > - const int dma_bits = using_dac ? 64 : 32;
> > > + int dma_bits;
> > > int rc;
> > >
> > > + if (!(hpriv->cap & HOST_CAP_64))
> > > + dma_bits = 32;
> > > + else if (hpriv->flags & AHCI_HFLAG_43BIT_ONLY)
> > > + dma_bits = 43;
> > > + else
> > > + dma_bits = 64;
> > > +
> >
> > I would prefer if you write this as:
> >
> > if (hpriv->cap & HOST_CAP_64) {
> > dma_bits = 64;
> > if (hpriv->flags & AHCI_HFLAG_43BIT_ONLY)
> > dma_bits = 43;
> > } else {
> > dma_bits = 32;
> > }
> >
> > Such that we still require the device to advertize 64 bit support,
> > and the quirk.
> > If the device does not advertize 64, we don't want it to be possible
> > to use a mask >32, even if the quirk flag is set.
>
> Isn't that logic exactly the same as in my version? I.e. in both
> versions, HOST_CAP_64 has to be set and AHCI_HFLAG_43BIT_ONLY has
> to be set for dma_bits to become 43.
>
> (I don't mind doing it your way, I just don't see a functional
> difference between the versions. :-) )

Yes, you are right.

But please change it to not use an inverted check for the flag anyway,
as such pattern has apparently proven to be too complicated for my brain
to interpret correctly already :)

Kind regards,
Niklas