PCI: Add pcie_get_speed_cap() to find max supported link speed
Add pcie_get_speed_cap() to find the max link speed supported by a device. Change max_link_speed_show() to use pcie_get_speed_cap(). Signed-off-by: Tal Gilboa <talgi@mellanox.com> [bhelgaas: return speed directly instead of error and *speed, 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:

committed by
Bjorn Helgaas

parent
1acfb9b7ee
commit
6cf57be0f7
@@ -158,33 +158,9 @@ static DEVICE_ATTR_RO(resource);
|
||||
static ssize_t max_link_speed_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct pci_dev *pci_dev = to_pci_dev(dev);
|
||||
u32 linkcap;
|
||||
int err;
|
||||
const char *speed;
|
||||
struct pci_dev *pdev = to_pci_dev(dev);
|
||||
|
||||
err = pcie_capability_read_dword(pci_dev, PCI_EXP_LNKCAP, &linkcap);
|
||||
if (err)
|
||||
return -EINVAL;
|
||||
|
||||
switch (linkcap & PCI_EXP_LNKCAP_SLS) {
|
||||
case PCI_EXP_LNKCAP_SLS_16_0GB:
|
||||
speed = "16 GT/s";
|
||||
break;
|
||||
case PCI_EXP_LNKCAP_SLS_8_0GB:
|
||||
speed = "8 GT/s";
|
||||
break;
|
||||
case PCI_EXP_LNKCAP_SLS_5_0GB:
|
||||
speed = "5 GT/s";
|
||||
break;
|
||||
case PCI_EXP_LNKCAP_SLS_2_5GB:
|
||||
speed = "2.5 GT/s";
|
||||
break;
|
||||
default:
|
||||
speed = "Unknown speed";
|
||||
}
|
||||
|
||||
return sprintf(buf, "%s\n", speed);
|
||||
return sprintf(buf, "%s\n", PCIE_SPEED2STR(pcie_get_speed_cap(pdev)));
|
||||
}
|
||||
static DEVICE_ATTR_RO(max_link_speed);
|
||||
|
||||
|
Reference in New Issue
Block a user