Re: [PATCH 06/10] PCI/DPC: Use FIELD_GET()
From: Ilpo Järvinen
Date: Fri Oct 13 2023 - 07:23:36 EST
On Wed, 11 Oct 2023, Ilpo Järvinen wrote:
> On Tue, 10 Oct 2023, Bjorn Helgaas wrote:
>
> > From: Bjorn Helgaas <bhelgaas@xxxxxxxxxx>
> >
> > Use FIELD_GET() to remove dependences on the field position, i.e., the
> > shift value. No functional change intended.
> >
> > Signed-off-by: Bjorn Helgaas <bhelgaas@xxxxxxxxxx>
> > ---
> > drivers/pci/pcie/dpc.c | 9 +++++----
> > drivers/pci/quirks.c | 2 +-
> > include/uapi/linux/pci_regs.h | 1 +
> > 3 files changed, 7 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/pci/pcie/dpc.c b/drivers/pci/pcie/dpc.c
> > index 3ceed8e3de41..6e551f34ec63 100644
> > --- a/drivers/pci/pcie/dpc.c
> > +++ b/drivers/pci/pcie/dpc.c
> > @@ -8,6 +8,7 @@
> >
> > #define dev_fmt(fmt) "DPC: " fmt
> >
> > +#include <linux/bitfield.h>
> > #include <linux/aer.h>
> > #include <linux/delay.h>
> > #include <linux/interrupt.h>
> > @@ -202,7 +203,7 @@ static void dpc_process_rp_pio_error(struct pci_dev *pdev)
> >
> > /* Get First Error Pointer */
> > pci_read_config_word(pdev, cap + PCI_EXP_DPC_STATUS, &dpc_status);
> > - first_error = (dpc_status & 0x1f00) >> 8;
> > + first_error = FIELD_GET(PCI_EXP_DPC_STATUS_FIRST_ERR, dpc_status);
> >
> > for (i = 0; i < ARRAY_SIZE(rp_pio_error_string); i++) {
> > if ((status & ~mask) & (1 << i))
> > @@ -270,8 +271,8 @@ void dpc_process_error(struct pci_dev *pdev)
> > pci_info(pdev, "containment event, status:%#06x source:%#06x\n",
> > status, source);
> >
> > - reason = (status & PCI_EXP_DPC_STATUS_TRIGGER_RSN) >> 1;
> > - ext_reason = (status & PCI_EXP_DPC_STATUS_TRIGGER_RSN_EXT) >> 5;
> > + reason = FIELD_GET(PCI_EXP_DPC_STATUS_TRIGGER_RSN, status);
> > + ext_reason = FIELD_GET(PCI_EXP_DPC_STATUS_TRIGGER_RSN_EXT, status);
> > pci_warn(pdev, "%s detected\n",
> > (reason == 0) ? "unmasked uncorrectable error" :
> > (reason == 1) ? "ERR_NONFATAL" :
>
> BTW, it seems we're doing overlapping work here with many of these
> patches. It takes some time to think these through one by one, I don't
> just autorun through them with coccinelle so I've not posted my changes
> yet.
>
> I went to a different direction here and named all the reasons too with
> defines and used & to get the reason in order to be able to compare with
> the named reasons.
>
> You also missed convering one 0xfff4 to use define (although I suspect it
> never was your goal to go beyond FIELD_GET() here).
I posted my approach onto the list so you can see what it looks like:
https://lore.kernel.org/linux-pci/20231013112004.4239-1-ilpo.jarvinen@xxxxxxxxxxxxxxx/T/#t
(It will obviously conflict with this patch so both cannot be applied as
is).
--
i.