[PATCH v1] PCI: Make PCIe link wait timeout configurable via pcie_link_timeout=

From: Hongtao Zhang

Date: Sat Nov 21 2026 - 05:51:05 EST


PCIE_LINK_RETRAIN_TIMEOUT_MS fixes the timeout for waiting on PCIe
link training and link state transitions at 1000 ms, matching the
PCIe spec's minimum recommendation for declaring a non-responsive
device broken.

As hardware evolves, some combinations of newer devices and newer
boards may need more than 1 sec to bring the link up. Rather than
changing the compiled-in constant for each such case, make the
timeout runtime-configurable: keep 1000 ms as the default and allow
raising it at boot via "pcie_link_timeout=<ms>", range [1000, 10000].
This gives platform and device bring-up a flexible knob to
accommodate slower link training without any code change, while
out-of-range values fall back to the spec default. The ceiling keeps
failure detection, bus/slot lock hold times, and the blind-sleep path
on ports without Link Active Reporting well below upper-layer error
handling thresholds.

Accordingly, adjust the two DPC log messages that hardcoded "1000
msec" to print the actually configured timeout.

Signed-off-by: Hongtao Zhang <zhanghongtao35@xxxxxxxxxx>
---
.../admin-guide/kernel-parameters.txt | 14 +++++
drivers/pci/pci.c | 61 +++++++++++++++++--
drivers/pci/pci.h | 10 +++
drivers/pci/pcie/dpc.c | 6 +-
4 files changed, 84 insertions(+), 7 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 0b3c140babd94..cde4faa5e3187 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -5304,6 +5304,20 @@ Kernel parameters
force Enable ASPM even on devices that claim not to support it.
WARNING: Forcing ASPM on may cause system lockups.

+ pcie_link_timeout=
+ [PCIE] Timeout in milliseconds to wait for PCIe link
+ training and link state (up/down) transitions, e.g.
+ during hot-plug power-on, error recovery resets and
+ runtime resume.
+ Some devices, or specific device/board combinations,
+ may need more than the PCIe spec's 1 sec to train the
+ link; use this to raise the wait, e.g.
+ pcie_link_timeout=3000
+ Range: [1000, 10000] ms. Values out of range are
+ ignored with a warning and the 1000 ms default is
+ used. Only affects failure detection latency; healthy
+ links return as soon as training completes.
+
pcie_ports= [PCIE] PCIe port services handling:
native Use native PCIe services (PME, AER, DPC, PCIe hotplug)
even if the platform doesn't give the OS permission to
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 7c6f2aba81443..a5996beeaebbd 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -159,6 +159,25 @@ static bool pci_bridge_d3_disable;
/* Force bridge_d3 for all PCIe ports */
static bool pci_bridge_d3_force;

+/*
+ * Effective timeout (ms) for waiting on PCIe link training / state changes.
+ * Defaults to the spec-mandated 1 sec floor. Devices or device/board
+ * combinations that legitimately need longer than 1 sec to train the link
+ * can raise this at boot via "pcie_link_timeout=<ms>".
+ */
+unsigned int pcie_link_retrain_timeout_ms = PCIE_LINK_RETRAIN_TIMEOUT_MS;
+EXPORT_SYMBOL_GPL(pcie_link_retrain_timeout_ms);
+
+/*
+ * Upper bound for pcie_link_timeout=. Generous headroom for slower link
+ * training, yet far below the ~30 sec abort threshold used by block/NVMe
+ * error handling so a single link wait cannot cascade into abort/reset
+ * loops above us. On ports without Link Active Reporting the wait is a
+ * blind sleep that runs even for healthy devices, so the ceiling must
+ * bound that cost as well.
+ */
+#define PCIE_LINK_RETRAIN_TIMEOUT_MAX_MS 10000
+
static int __init pcie_port_pm_setup(char *str)
{
if (!strcmp(str, "off"))
@@ -169,6 +188,37 @@ static int __init pcie_port_pm_setup(char *str)
}
__setup("pcie_port_pm=", pcie_port_pm_setup);

+static int __init pcie_link_timeout_setup(char *str)
+{
+ unsigned int timeout;
+
+ if (kstrtouint(str, 10, &timeout)) {
+ pr_warn("PCIe: invalid pcie_link_timeout=%s, using default %u ms\n",
+ str, PCIE_LINK_RETRAIN_TIMEOUT_MS);
+ return 1;
+ }
+
+ /*
+ * Floor: PCIe spec requires at least 1 sec before declaring a device
+ * that has not responded as broken. Ceiling: keep a single link wait
+ * well below upper-layer timeouts so failure detection stays bounded
+ * (see PCIE_LINK_RETRAIN_TIMEOUT_MAX_MS).
+ */
+ if (timeout < PCIE_LINK_RETRAIN_TIMEOUT_MS ||
+ timeout > PCIE_LINK_RETRAIN_TIMEOUT_MAX_MS) {
+ pr_warn("PCIe: pcie_link_timeout=%u out of range [%u, %u] ms, using default %u ms\n",
+ timeout, (unsigned int)PCIE_LINK_RETRAIN_TIMEOUT_MS,
+ (unsigned int)PCIE_LINK_RETRAIN_TIMEOUT_MAX_MS,
+ PCIE_LINK_RETRAIN_TIMEOUT_MS);
+ return 1;
+ }
+
+ pcie_link_retrain_timeout_ms = timeout;
+ pr_info("PCIe: link wait timeout set to %u ms\n", timeout);
+ return 1;
+}
+__setup("pcie_link_timeout=", pcie_link_timeout_setup);
+
/**
* pci_bus_max_busnr - returns maximum PCI bus number of given bus' children
* @bus: pointer to PCI bus structure to search
@@ -4612,7 +4662,7 @@ static int pci_pm_reset(struct pci_dev *dev, bool probe)
* @active: Waiting for active or inactive?
*
* Return 0 if successful, or -ETIMEDOUT if status has not changed within
- * PCIE_LINK_RETRAIN_TIMEOUT_MS milliseconds.
+ * pcie_link_retrain_timeout_ms milliseconds.
*/
static int pcie_wait_for_link_status(struct pci_dev *pdev,
bool use_lt, bool active)
@@ -4624,7 +4674,7 @@ static int pcie_wait_for_link_status(struct pci_dev *pdev,
lnksta_mask = use_lt ? PCI_EXP_LNKSTA_LT : PCI_EXP_LNKSTA_DLLLA;
lnksta_match = active ? lnksta_mask : 0;

- end_jiffies = jiffies + msecs_to_jiffies(PCIE_LINK_RETRAIN_TIMEOUT_MS);
+ end_jiffies = jiffies + msecs_to_jiffies(pcie_link_retrain_timeout_ms);
do {
pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnksta);
if ((lnksta & lnksta_mask) == lnksta_match)
@@ -4650,7 +4700,7 @@ static int pcie_wait_for_link_status(struct pci_dev *pdev,
* bit is valid.
*
* Return 0 if successful, or -ETIMEDOUT if training has not completed
- * within PCIE_LINK_RETRAIN_TIMEOUT_MS milliseconds.
+ * within pcie_link_retrain_timeout_ms milliseconds.
*/
int pcie_retrain_link(struct pci_dev *pdev, bool use_lt)
{
@@ -4715,10 +4765,11 @@ static bool pcie_wait_for_link_delay(struct pci_dev *pdev, bool active,

/*
* Some controllers might not implement link active reporting. In this
- * case, we wait for 1000 ms + any delay requested by the caller.
+ * case, we wait for pcie_link_retrain_timeout_ms + any delay requested
+ * by the caller.
*/
if (!pdev->link_active_reporting) {
- msleep(PCIE_LINK_RETRAIN_TIMEOUT_MS + delay);
+ msleep(pcie_link_retrain_timeout_ms + delay);
return true;
}

diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 77efa4c5c960e..e060e129f02a0 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -20,8 +20,18 @@ struct pcie_tlp_log;

#define PCI_VSEC_ID_INTEL_TBT 0x1234 /* Thunderbolt */

+/*
+ * Default timeout for link retraining / link state transitions. PCIe spec
+ * says software must allow at least 1 sec before declaring a device that
+ * has not responded as broken; keep that as the floor. The effective value
+ * can be raised at boot via the "pcie_link_timeout=" parameter for devices
+ * that need longer to bring the link up.
+ */
#define PCIE_LINK_RETRAIN_TIMEOUT_MS 1000

+/* Effective, boot-configurable link wait timeout in milliseconds. */
+extern unsigned int pcie_link_retrain_timeout_ms;
+
/*
* Power stable to PERST# inactive.
*
diff --git a/drivers/pci/pcie/dpc.c b/drivers/pci/pcie/dpc.c
index 2b779bd1d861b..ef04532d9c8ab 100644
--- a/drivers/pci/pcie/dpc.c
+++ b/drivers/pci/pcie/dpc.c
@@ -163,7 +163,8 @@ pci_ers_result_t dpc_reset_link(struct pci_dev *pdev)
* to allow the Port to leave DPC.
*/
if (!pcie_wait_for_link(pdev, false))
- pci_info(pdev, "Data Link Layer Link Active not cleared in 1000 msec\n");
+ pci_info(pdev, "Data Link Layer Link Active not cleared in %u msec\n",
+ pcie_link_retrain_timeout_ms);

if (pdev->dpc_rp_extensions && dpc_wait_rp_inactive(pdev)) {
clear_bit(PCI_DPC_RECOVERED, &pdev->priv_flags);
@@ -328,7 +329,8 @@ static void pci_clear_surpdn_errors(struct pci_dev *pdev)
static void dpc_handle_surprise_removal(struct pci_dev *pdev)
{
if (!pcie_wait_for_link(pdev, false)) {
- pci_info(pdev, "Data Link Layer Link Active not cleared in 1000 msec\n");
+ pci_info(pdev, "Data Link Layer Link Active not cleared in %u msec\n",
+ pcie_link_retrain_timeout_ms);
goto out;
}

--
2.43.0