Skip to content

Commit c70b65f

Browse files
talgimellanoxbjorn-helgaas
authored andcommitted
PCI: Add pcie_get_width_cap() to find max supported link width
Add pcie_get_width_cap() to find the max link width supported by a device. Change max_link_width_show() to use pcie_get_width_cap(). Signed-off-by: Tal Gilboa <talgi@mellanox.com> [bhelgaas: return width directly instead of error and *width, don't export outside drivers/pci] Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Tariq Toukan <tariqt@mellanox.com>
1 parent 6cf57be commit c70b65f

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

drivers/pci/pci-sysfs.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,9 @@ static DEVICE_ATTR_RO(max_link_speed);
167167
static ssize_t max_link_width_show(struct device *dev,
168168
struct device_attribute *attr, char *buf)
169169
{
170-
struct pci_dev *pci_dev = to_pci_dev(dev);
171-
u32 linkcap;
172-
int err;
173-
174-
err = pcie_capability_read_dword(pci_dev, PCI_EXP_LNKCAP, &linkcap);
175-
if (err)
176-
return -EINVAL;
170+
struct pci_dev *pdev = to_pci_dev(dev);
177171

178-
return sprintf(buf, "%u\n", (linkcap & PCI_EXP_LNKCAP_MLW) >> 4);
172+
return sprintf(buf, "%u\n", pcie_get_width_cap(pdev));
179173
}
180174
static DEVICE_ATTR_RO(max_link_width);
181175

drivers/pci/pci.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5190,6 +5190,24 @@ enum pci_bus_speed pcie_get_speed_cap(struct pci_dev *dev)
51905190
return PCI_SPEED_UNKNOWN;
51915191
}
51925192

5193+
/**
5194+
* pcie_get_width_cap - query for the PCI device's link width capability
5195+
* @dev: PCI device to query
5196+
*
5197+
* Query the PCI device width capability. Return the maximum link width
5198+
* supported by the device.
5199+
*/
5200+
enum pcie_link_width pcie_get_width_cap(struct pci_dev *dev)
5201+
{
5202+
u32 lnkcap;
5203+
5204+
pcie_capability_read_dword(dev, PCI_EXP_LNKCAP, &lnkcap);
5205+
if (lnkcap)
5206+
return (lnkcap & PCI_EXP_LNKCAP_MLW) >> 4;
5207+
5208+
return PCIE_LNK_WIDTH_UNKNOWN;
5209+
}
5210+
51935211
/**
51945212
* pci_select_bars - Make BAR mask from the type of resource
51955213
* @dev: the PCI device for which BAR mask is made

drivers/pci/pci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ void pci_disable_bridge_window(struct pci_dev *dev);
262262
"Unknown speed")
263263

264264
enum pci_bus_speed pcie_get_speed_cap(struct pci_dev *dev);
265+
enum pcie_link_width pcie_get_width_cap(struct pci_dev *dev);
265266

266267
/* Single Root I/O Virtualization */
267268
struct pci_sriov {

0 commit comments

Comments
 (0)