GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — PCI: Store all PCIe Supported Link Speeds · liom/BPI-Router-Linux@47ecb8f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • drivers/pci
    • pci.c
    • pci.h
    • probe.c
  • include
    • linux
      • pci.h
    • uapi/linux
      • pci_regs.h
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎drivers/pci/pci.c‎

Copy file name to clipboardExpand all lines: drivers/pci/pci.c
+42-16Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6199,38 +6199,64 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,
61996199
EXPORT_SYMBOL(pcie_bandwidth_available);
62006200

62016201
/**
6202-
* pcie_get_speed_cap - query for the PCI device's link speed capability
6202+
* pcie_get_supported_speeds - query Supported Link Speed Vector
62036203
* @dev: PCI device to query
62046204
*
6205-
* Query the PCI device speed capability. Return the maximum link speed
6206-
* supported by the device.
6205+
* Query @dev supported link speeds.
6206+
*
6207+
* Implementation Note in PCIe r6.0 sec 7.5.3.18 recommends determining
6208+
* supported link speeds using the Supported Link Speeds Vector in the Link
6209+
* Capabilities 2 Register (when available).
6210+
*
6211+
* Link Capabilities 2 was added in PCIe r3.0, sec 7.8.18.
6212+
*
6213+
* Without Link Capabilities 2, i.e., prior to PCIe r3.0, Supported Link
6214+
* Speeds field in Link Capabilities is used and only 2.5 GT/s and 5.0 GT/s
6215+
* speeds were defined.
6216+
*
6217+
* For @dev without Supported Link Speed Vector, the field is synthesized
6218+
* from the Max Link Speed field in the Link Capabilities Register.
6219+
*
6220+
* Return: Supported Link Speeds Vector (+ reserved 0 at LSB).
62076221
*/
6208-
enum pci_bus_speed pcie_get_speed_cap(struct pci_dev *dev)
6222+
u8 pcie_get_supported_speeds(struct pci_dev *dev)
62096223
{
62106224
u32 lnkcap2, lnkcap;
6225+
u8 speeds;
62116226

62126227
/*
6213-
* Link Capabilities 2 was added in PCIe r3.0, sec 7.8.18. The
6214-
* implementation note there recommends using the Supported Link
6215-
* Speeds Vector in Link Capabilities 2 when supported.
6216-
*
6217-
* Without Link Capabilities 2, i.e., prior to PCIe r3.0, software
6218-
* should use the Supported Link Speeds field in Link Capabilities,
6219-
* where only 2.5 GT/s and 5.0 GT/s speeds were defined.
6228+
* Speeds retain the reserved 0 at LSB before PCIe Supported Link
6229+
* Speeds Vector to allow using SLS Vector bit defines directly.
62206230
*/
62216231
pcie_capability_read_dword(dev, PCI_EXP_LNKCAP2, &lnkcap2);
6232+
speeds = lnkcap2 & PCI_EXP_LNKCAP2_SLS;
62226233

62236234
/* PCIe r3.0-compliant */
6224-
if (lnkcap2)
6225-
return PCIE_LNKCAP2_SLS2SPEED(lnkcap2);
6235+
if (speeds)
6236+
return speeds;
62266237

62276238
pcie_capability_read_dword(dev, PCI_EXP_LNKCAP, &lnkcap);
6239+
6240+
/* Synthesize from the Max Link Speed field */
62286241
if ((lnkcap & PCI_EXP_LNKCAP_SLS) == PCI_EXP_LNKCAP_SLS_5_0GB)
6229-
return PCIE_SPEED_5_0GT;
6242+
speeds = PCI_EXP_LNKCAP2_SLS_5_0GB | PCI_EXP_LNKCAP2_SLS_2_5GB;
62306243
else if ((lnkcap & PCI_EXP_LNKCAP_SLS) == PCI_EXP_LNKCAP_SLS_2_5GB)
6231-
return PCIE_SPEED_2_5GT;
6244+
speeds = PCI_EXP_LNKCAP2_SLS_2_5GB;
62326245

6233-
return PCI_SPEED_UNKNOWN;
6246+
return speeds;
6247+
}
6248+
6249+
/**
6250+
* pcie_get_speed_cap - query for the PCI device's link speed capability
6251+
* @dev: PCI device to query
6252+
*
6253+
* Query the PCI device speed capability.
6254+
*
6255+
* Return: the maximum link speed supported by the device.
6256+
*/
6257+
enum pci_bus_speed pcie_get_speed_cap(struct pci_dev *dev)
6258+
{
6259+
return PCIE_LNKCAP2_SLS2SPEED(dev->supported_speeds);
62346260
}
62356261
EXPORT_SYMBOL(pcie_get_speed_cap);
62366262

Collapse file

‎drivers/pci/pci.h‎

Copy file name to clipboardExpand all lines: drivers/pci/pci.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ static inline int pcie_dev_speed_mbps(enum pci_bus_speed speed)
390390
return -EINVAL;
391391
}
392392

393+
u8 pcie_get_supported_speeds(struct pci_dev *dev);
393394
const char *pci_speed_string(enum pci_bus_speed speed);
394395
enum pci_bus_speed pcie_get_speed_cap(struct pci_dev *dev);
395396
enum pcie_link_width pcie_get_width_cap(struct pci_dev *dev);
Collapse file

‎drivers/pci/probe.c‎

Copy file name to clipboardExpand all lines: drivers/pci/probe.c
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,6 +1972,9 @@ int pci_setup_device(struct pci_dev *dev)
19721972

19731973
set_pcie_untrusted(dev);
19741974

1975+
if (pci_is_pcie(dev))
1976+
dev->supported_speeds = pcie_get_supported_speeds(dev);
1977+
19751978
/* "Unknown power state" */
19761979
dev->current_state = PCI_UNKNOWN;
19771980

Collapse file

‎include/linux/pci.h‎

Copy file name to clipboardExpand all lines: include/linux/pci.h
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,14 @@ struct pci_sriov;
320320
struct pci_p2pdma;
321321
struct rcec_ea;
322322

323-
/* The pci_dev structure describes PCI devices */
323+
/* struct pci_dev - describes a PCI device
324+
*
325+
* @supported_speeds: PCIe Supported Link Speeds Vector (+ reserved 0 at
326+
* LSB). 0 when the supported speeds cannot be
327+
* determined (e.g., for Root Complex Integrated
328+
* Endpoints without the relevant Capability
329+
* Registers).
330+
*/
324331
struct pci_dev {
325332
struct list_head bus_list; /* Node in per-bus list */
326333
struct pci_bus *bus; /* Bus this device is on */
@@ -524,6 +531,7 @@ struct pci_dev {
524531
struct npem *npem; /* Native PCIe Enclosure Management */
525532
#endif
526533
u16 acs_cap; /* ACS Capability offset */
534+
u8 supported_speeds; /* Supported Link Speeds Vector */
527535
phys_addr_t rom; /* Physical address if not from BAR */
528536
size_t romlen; /* Length if not from BAR */
529537
/*
Collapse file

‎include/uapi/linux/pci_regs.h‎

Copy file name to clipboardExpand all lines: include/uapi/linux/pci_regs.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@
678678
#define PCI_EXP_DEVSTA2 0x2a /* Device Status 2 */
679679
#define PCI_CAP_EXP_RC_ENDPOINT_SIZEOF_V2 0x2c /* end of v2 EPs w/o link */
680680
#define PCI_EXP_LNKCAP2 0x2c /* Link Capabilities 2 */
681+
#define PCI_EXP_LNKCAP2_SLS 0x000000fe /* Supported Link Speeds Vector */
681682
#define PCI_EXP_LNKCAP2_SLS_2_5GB 0x00000002 /* Supported Speed 2.5GT/s */
682683
#define PCI_EXP_LNKCAP2_SLS_5_0GB 0x00000004 /* Supported Speed 5GT/s */
683684
#define PCI_EXP_LNKCAP2_SLS_8_0GB 0x00000008 /* Supported Speed 8GT/s */

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.