Skip to content

Commit d1f9b39

Browse files
ij-intelbjorn-helgaas
authored andcommitted
PCI: Use FIELD_GET() to extract Link Width
Use FIELD_GET() to extract PCIe Negotiated and Maximum Link Width fields instead of custom masking and shifting. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ilpo Järvinen <[email protected]> [bhelgaas: drop duplicate include of <linux/bitfield.h>] Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]>
1 parent 408599e commit d1f9b39

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

drivers/pci/pci-sysfs.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Modeled after usb's driverfs.c
1313
*/
1414

15-
15+
#include <linux/bitfield.h>
1616
#include <linux/kernel.h>
1717
#include <linux/sched.h>
1818
#include <linux/pci.h>
@@ -230,8 +230,7 @@ static ssize_t current_link_width_show(struct device *dev,
230230
if (err)
231231
return -EINVAL;
232232

233-
return sysfs_emit(buf, "%u\n",
234-
(linkstat & PCI_EXP_LNKSTA_NLW) >> PCI_EXP_LNKSTA_NLW_SHIFT);
233+
return sysfs_emit(buf, "%u\n", FIELD_GET(PCI_EXP_LNKSTA_NLW, linkstat));
235234
}
236235
static DEVICE_ATTR_RO(current_link_width);
237236

drivers/pci/pci.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6257,8 +6257,7 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,
62576257
pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta);
62586258

62596259
next_speed = pcie_link_speed[lnksta & PCI_EXP_LNKSTA_CLS];
6260-
next_width = (lnksta & PCI_EXP_LNKSTA_NLW) >>
6261-
PCI_EXP_LNKSTA_NLW_SHIFT;
6260+
next_width = FIELD_GET(PCI_EXP_LNKSTA_NLW, lnksta);
62626261

62636262
next_bw = next_width * PCIE_SPEED2MBS_ENC(next_speed);
62646263

@@ -6330,7 +6329,7 @@ enum pcie_link_width pcie_get_width_cap(struct pci_dev *dev)
63306329

63316330
pcie_capability_read_dword(dev, PCI_EXP_LNKCAP, &lnkcap);
63326331
if (lnkcap)
6333-
return (lnkcap & PCI_EXP_LNKCAP_MLW) >> 4;
6332+
return FIELD_GET(PCI_EXP_LNKCAP_MLW, lnkcap);
63346333

63356334
return PCIE_LNK_WIDTH_UNKNOWN;
63366335
}

0 commit comments

Comments
 (0)