]> git.itanic.dy.fi Git - linux-stable/commitdiff
PCI: Use FIELD_GET() to extract Link Width
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Tue, 19 Sep 2023 12:56:46 +0000 (15:56 +0300)
committerBjorn Helgaas <bhelgaas@google.com>
Wed, 18 Oct 2023 01:10:31 +0000 (20:10 -0500)
Use FIELD_GET() to extract PCIe Negotiated and Maximum Link Width fields
instead of custom masking and shifting.

Link: https://lore.kernel.org/r/20230919125648.1920-7-ilpo.jarvinen@linux.intel.com
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
[bhelgaas: drop duplicate include of <linux/bitfield.h>]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/pci/pci-sysfs.c
drivers/pci/pci.c

index d9eede2dbc0e130a18e56dd17acee674d86921ae..5a6241044c3c8a9abbdf589ef54386ed9e444eed 100644 (file)
@@ -12,7 +12,7 @@
  * Modeled after usb's driverfs.c
  */
 
-
+#include <linux/bitfield.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/pci.h>
@@ -230,8 +230,7 @@ static ssize_t current_link_width_show(struct device *dev,
        if (err)
                return -EINVAL;
 
-       return sysfs_emit(buf, "%u\n",
-               (linkstat & PCI_EXP_LNKSTA_NLW) >> PCI_EXP_LNKSTA_NLW_SHIFT);
+       return sysfs_emit(buf, "%u\n", FIELD_GET(PCI_EXP_LNKSTA_NLW, linkstat));
 }
 static DEVICE_ATTR_RO(current_link_width);
 
index 59c01d68c6d5ed16ed07622694f321ca8092e40f..0a584d19486ec6d13aa5b4070408ee5ab1410bb5 100644 (file)
@@ -6257,8 +6257,7 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,
                pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta);
 
                next_speed = pcie_link_speed[lnksta & PCI_EXP_LNKSTA_CLS];
-               next_width = (lnksta & PCI_EXP_LNKSTA_NLW) >>
-                       PCI_EXP_LNKSTA_NLW_SHIFT;
+               next_width = FIELD_GET(PCI_EXP_LNKSTA_NLW, lnksta);
 
                next_bw = next_width * PCIE_SPEED2MBS_ENC(next_speed);
 
@@ -6330,7 +6329,7 @@ enum pcie_link_width pcie_get_width_cap(struct pci_dev *dev)
 
        pcie_capability_read_dword(dev, PCI_EXP_LNKCAP, &lnkcap);
        if (lnkcap)
-               return (lnkcap & PCI_EXP_LNKCAP_MLW) >> 4;
+               return FIELD_GET(PCI_EXP_LNKCAP_MLW, lnkcap);
 
        return PCIE_LNK_WIDTH_UNKNOWN;
 }