PCI: Refactor pcie_update_link_speed()
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Fri, 18 Oct 2024 14:47:50 +0000 (17:47 +0300)
committerBjorn Helgaas <bhelgaas@google.com>
Mon, 11 Nov 2024 20:20:04 +0000 (14:20 -0600)
pcie_update_link_speed() is passed the Link Status register but not all
callers have that value at hand nor need the value.

Refactor pcie_update_link_speed() to include reading the Link Status
register and create __pcie_update_link_speed() which can be used by the
hotplug code that has the register value at hand beforehand (and needs the
value for other purposes).

Link: https://lore.kernel.org/r/20241018144755.7875-5-ilpo.jarvinen@linux.intel.com
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/pci/hotplug/pciehp_hpc.c
drivers/pci/pci.h
drivers/pci/probe.c

index 736ad8b..bb5a8d9 100644 (file)
@@ -319,7 +319,7 @@ int pciehp_check_link_status(struct controller *ctrl)
                return -1;
        }
 
-       pcie_update_link_speed(ctrl->pcie->port->subordinate, lnk_status);
+       __pcie_update_link_speed(ctrl->pcie->port->subordinate, lnk_status);
 
        if (!found) {
                ctrl_info(ctrl, "Slot(%s): No device found\n",
index d0a46ec..8137ad2 100644 (file)
@@ -379,7 +379,12 @@ enum pci_bus_speed pcie_get_speed_cap(struct pci_dev *dev);
 enum pcie_link_width pcie_get_width_cap(struct pci_dev *dev);
 void __pcie_print_link_status(struct pci_dev *dev, bool verbose);
 void pcie_report_downtraining(struct pci_dev *dev);
-void pcie_update_link_speed(struct pci_bus *bus, u16 link_status);
+
+static inline void __pcie_update_link_speed(struct pci_bus *bus, u16 linksta)
+{
+       bus->cur_bus_speed = pcie_link_speed[linksta & PCI_EXP_LNKSTA_CLS];
+}
+void pcie_update_link_speed(struct pci_bus *bus);
 
 /* Single Root I/O Virtualization */
 struct pci_sriov {
index af153a8..c138daf 100644 (file)
@@ -742,9 +742,13 @@ const char *pci_speed_string(enum pci_bus_speed speed)
 }
 EXPORT_SYMBOL_GPL(pci_speed_string);
 
-void pcie_update_link_speed(struct pci_bus *bus, u16 linksta)
+void pcie_update_link_speed(struct pci_bus *bus)
 {
-       bus->cur_bus_speed = pcie_link_speed[linksta & PCI_EXP_LNKSTA_CLS];
+       struct pci_dev *bridge = bus->self;
+       u16 linksta;
+
+       pcie_capability_read_word(bridge, PCI_EXP_LNKSTA, &linksta);
+       __pcie_update_link_speed(bus, linksta);
 }
 EXPORT_SYMBOL_GPL(pcie_update_link_speed);
 
@@ -827,13 +831,11 @@ static void pci_set_bus_speed(struct pci_bus *bus)
 
        if (pci_is_pcie(bridge)) {
                u32 linkcap;
-               u16 linksta;
 
                pcie_capability_read_dword(bridge, PCI_EXP_LNKCAP, &linkcap);
                bus->max_bus_speed = pcie_link_speed[linkcap & PCI_EXP_LNKCAP_SLS];
 
-               pcie_capability_read_word(bridge, PCI_EXP_LNKSTA, &linksta);
-               pcie_update_link_speed(bus, linksta);
+               pcie_update_link_speed(bus);
        }
 }