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>
This commit is contained in:
parent
6cf57be0f7
commit
c70b65fb7f
|
@ -167,15 +167,9 @@ static DEVICE_ATTR_RO(max_link_speed);
|
||||||
static ssize_t max_link_width_show(struct device *dev,
|
static ssize_t max_link_width_show(struct device *dev,
|
||||||
struct device_attribute *attr, char *buf)
|
struct device_attribute *attr, char *buf)
|
||||||
{
|
{
|
||||||
struct pci_dev *pci_dev = to_pci_dev(dev);
|
struct pci_dev *pdev = to_pci_dev(dev);
|
||||||
u32 linkcap;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err = pcie_capability_read_dword(pci_dev, PCI_EXP_LNKCAP, &linkcap);
|
return sprintf(buf, "%u\n", pcie_get_width_cap(pdev));
|
||||||
if (err)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
return sprintf(buf, "%u\n", (linkcap & PCI_EXP_LNKCAP_MLW) >> 4);
|
|
||||||
}
|
}
|
||||||
static DEVICE_ATTR_RO(max_link_width);
|
static DEVICE_ATTR_RO(max_link_width);
|
||||||
|
|
||||||
|
|
|
@ -5190,6 +5190,24 @@ enum pci_bus_speed pcie_get_speed_cap(struct pci_dev *dev)
|
||||||
return PCI_SPEED_UNKNOWN;
|
return PCI_SPEED_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pcie_get_width_cap - query for the PCI device's link width capability
|
||||||
|
* @dev: PCI device to query
|
||||||
|
*
|
||||||
|
* Query the PCI device width capability. Return the maximum link width
|
||||||
|
* supported by the device.
|
||||||
|
*/
|
||||||
|
enum pcie_link_width pcie_get_width_cap(struct pci_dev *dev)
|
||||||
|
{
|
||||||
|
u32 lnkcap;
|
||||||
|
|
||||||
|
pcie_capability_read_dword(dev, PCI_EXP_LNKCAP, &lnkcap);
|
||||||
|
if (lnkcap)
|
||||||
|
return (lnkcap & PCI_EXP_LNKCAP_MLW) >> 4;
|
||||||
|
|
||||||
|
return PCIE_LNK_WIDTH_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pci_select_bars - Make BAR mask from the type of resource
|
* pci_select_bars - Make BAR mask from the type of resource
|
||||||
* @dev: the PCI device for which BAR mask is made
|
* @dev: the PCI device for which BAR mask is made
|
||||||
|
|
|
@ -262,6 +262,7 @@ void pci_disable_bridge_window(struct pci_dev *dev);
|
||||||
"Unknown speed")
|
"Unknown speed")
|
||||||
|
|
||||||
enum pci_bus_speed pcie_get_speed_cap(struct pci_dev *dev);
|
enum pci_bus_speed pcie_get_speed_cap(struct pci_dev *dev);
|
||||||
|
enum pcie_link_width pcie_get_width_cap(struct pci_dev *dev);
|
||||||
|
|
||||||
/* Single Root I/O Virtualization */
|
/* Single Root I/O Virtualization */
|
||||||
struct pci_sriov {
|
struct pci_sriov {
|
||||||
|
|
Loading…
Reference in New Issue