[PATCH v3 1/3] PCI: Configure root port MPS during host probing
From: Hans Zhang <18255117159@163.com>
Date: 2025-05-06 17:35:49
Also in:
linux-amlogic, linux-pci, linux-rockchip, lkml
Subsystem:
pci subsystem, the rest · Maintainers:
Bjorn Helgaas, Linus Torvalds
Current PCIe initialization logic may leave root ports operating with non-optimal Maximum Payload Size (MPS) settings. While downstream device configuration is handled during bus enumeration, root port MPS values inherited from firmware or hardware defaults might not utilize the full capabilities supported by the controller hardware. This can result is uboptimal data transfer efficiency across the PCIe hierarchy. During host controller probing phase, when PCIe bus tuning is enabled, the implementation now configures root port MPS settings to their hardware-supported maximum values. By iterating through bridge devices under the root bus and identifying PCIe root ports, each port's MPS is set to 128 << pcie_mpss to match the device's maximum supported payload size. Explicit initialization at host probing stage ensures consistent PCIe topology configuration before downstream devices perform their own MPS negotiations. This proactive approach addresses platform-specific requirements where controller drivers depend on properly initialized root port settings, while maintaining backward compatibility through PCIE_BUS_TUNE_OFF conditional checks. Hardware capabilities are fully utilized without altering existing device negotiation behaviors. Suggested-by: Niklas Cassel <cassel@kernel.org> Signed-off-by: Hans Zhang <18255117159@163.com> --- drivers/pci/probe.c | 66 ++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 31 deletions(-)
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 364fa2a514f8..365d9a7dd37f 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c@@ -2149,6 +2149,37 @@ int pci_setup_device(struct pci_dev *dev) return 0; } +static void pcie_write_mps(struct pci_dev *dev, int mps) +{ + int rc; + + if (pcie_bus_config == PCIE_BUS_PERFORMANCE) { + mps = 128 << dev->pcie_mpss; + + if (pci_pcie_type(dev) != PCI_EXP_TYPE_ROOT_PORT && + dev->bus->self) + + /* + * For "Performance", the assumption is made that + * downstream communication will never be larger than + * the MRRS. So, the MPS only needs to be configured + * for the upstream communication. This being the case, + * walk from the top down and set the MPS of the child + * to that of the parent bus. + * + * Configure the device MPS with the smaller of the + * device MPSS or the bridge MPS (which is assumed to be + * properly configured at this point to the largest + * allowable MPS based on its parent bus). + */ + mps = min(mps, pcie_get_mps(dev->bus->self)); + } + + rc = pcie_set_mps(dev, mps); + if (rc) + pci_err(dev, "Failed attempting to set the MPS\n"); +} + static void pci_configure_mps(struct pci_dev *dev) { struct pci_dev *bridge = pci_upstream_bridge(dev);
@@ -2178,6 +2209,10 @@ static void pci_configure_mps(struct pci_dev *dev) return; } + if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT && + pcie_bus_config != PCIE_BUS_TUNE_OFF) + pcie_write_mps(dev, 128 << dev->pcie_mpss); + if (!bridge || !pci_is_pcie(bridge)) return;
@@ -2875,37 +2910,6 @@ static int pcie_find_smpss(struct pci_dev *dev, void *data) return 0; } -static void pcie_write_mps(struct pci_dev *dev, int mps) -{ - int rc; - - if (pcie_bus_config == PCIE_BUS_PERFORMANCE) { - mps = 128 << dev->pcie_mpss; - - if (pci_pcie_type(dev) != PCI_EXP_TYPE_ROOT_PORT && - dev->bus->self) - - /* - * For "Performance", the assumption is made that - * downstream communication will never be larger than - * the MRRS. So, the MPS only needs to be configured - * for the upstream communication. This being the case, - * walk from the top down and set the MPS of the child - * to that of the parent bus. - * - * Configure the device MPS with the smaller of the - * device MPSS or the bridge MPS (which is assumed to be - * properly configured at this point to the largest - * allowable MPS based on its parent bus). - */ - mps = min(mps, pcie_get_mps(dev->bus->self)); - } - - rc = pcie_set_mps(dev, mps); - if (rc) - pci_err(dev, "Failed attempting to set the MPS\n"); -} - static void pcie_write_mrrs(struct pci_dev *dev) { int rc, mrrs;
--
2.25.1