[PATCH v1 1/3] PCI: Move to_pcie_link_speed() to probe.c and export it
From: Hans Zhang
Date: Sun Mar 15 2026 - 12:02:10 EST
Move the static helper function to_pcie_link_speed() from pci.c to
probe.c and export it. This function converts a PCIe link status
register value to the corresponding pci_bus_speed enum. Exporting it
allows other parts of the PCI subsystem (e.g., sysfs and inline helpers)
to use this helper instead of directly accessing the pcie_link_speed
array, preparing for better encapsulation.
Signed-off-by: Hans Zhang <18255117159@xxxxxxx>
---
drivers/pci/pci.c | 5 -----
drivers/pci/probe.c | 6 ++++++
include/linux/pci.h | 1 +
3 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 8479c2e1f74f..b93693575573 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5886,11 +5886,6 @@ int pcie_set_mps(struct pci_dev *dev, int mps)
}
EXPORT_SYMBOL(pcie_set_mps);
-static enum pci_bus_speed to_pcie_link_speed(u16 lnksta)
-{
- return pcie_link_speed[FIELD_GET(PCI_EXP_LNKSTA_CLS, lnksta)];
-}
-
int pcie_link_speed_mbps(struct pci_dev *pdev)
{
u16 lnksta;
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index f85da50a3d83..40f2185ac3b5 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -799,6 +799,12 @@ unsigned char pcie_get_link_speed(unsigned int speed)
}
EXPORT_SYMBOL_GPL(pcie_get_link_speed);
+enum pci_bus_speed to_pcie_link_speed(u16 lnksta)
+{
+ return pcie_link_speed[FIELD_GET(PCI_EXP_LNKSTA_CLS, lnksta)];
+}
+EXPORT_SYMBOL_GPL(to_pcie_link_speed);
+
const char *pci_speed_string(enum pci_bus_speed speed)
{
/* Indexed by the pci_bus_speed enum */
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 1c270f1d5123..751a2b2ba04c 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1459,6 +1459,7 @@ int pcie_set_mps(struct pci_dev *dev, int mps);
u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,
enum pci_bus_speed *speed,
enum pcie_link_width *width);
+enum pci_bus_speed to_pcie_link_speed(u16 lnksta);
int pcie_link_speed_mbps(struct pci_dev *pdev);
void pcie_print_link_status(struct pci_dev *dev);
int pcie_reset_flr(struct pci_dev *dev, bool probe);
--
2.34.1