Skip to contentSkip to conversation

PCI: dwc: Link Up IRQ fixes

PATCH Superseded Niklas Cassel 1 participant 6 messages May 5, 2025

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover PCI: dwc: Link Up IRQ fixes

Hello there,

Commit 8d3bf19f1b58 ("PCI: dwc: Don't wait for link up if driver can detect Link Up event") added support for DWC to not wait for link up before enumerating the bus. However, we cannot simply enumerate the bus after receiving a Link Up IRQ, we still need to wait PCIE_T_RRS_READY_MS time to allow a device to become ready after deasserting PERST. To avoid bringing back an conditional delay during probe, perform the wait in the threaded IRQ handler instead.

Please review.

Kind regards,
Niklas

Niklas Cassel (4):
PCI: dw-rockchip: Do not enumerate bus before endpoint devices are
ready
PCI: qcom: Do not enumerate bus before endpoint devices are ready
PCI: dw-rockchip: Replace PERST sleep time with proper macro
PCI: qcom: Replace PERST sleep time with proper macro

 drivers/pci/controller/dwc/pcie-dw-rockchip.c | 3 ++-
 drivers/pci/controller/dwc/pcie-qcom.c        | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
Signature · 1 line
2.49.0
#1 lore raw

PATCH 1/4 PCI: dw-rockchip: Do not enumerate bus before endpoint devices are ready

Commit ec9fd499b9c6 ("PCI: dw-rockchip: Don't wait for link since we can detect Link Up") changed so that we no longer call dw_pcie_wait_for_link(), and instead enumerate the bus when receiving a Link Up IRQ.

Laszlo Fiat reported (off-list) that his PLEXTOR PX-256M8PeGN NVMe SSD is no longer functional, and simply reverting commit ec9fd499b9c6 ("PCI:
dw-rockchip: Don't wait for link since we can detect Link Up") makes his SSD functional again.

It seems that we are enumerating the bus before the endpoint is ready. Adding a msleep(PCIE_T_RRS_READY_MS) before enumerating the bus in the threaded IRQ handler makes the SSD functional once again.

What appears to happen is that before ec9fd499b9c6, we called dw_pcie_wait_for_link(), and in the first iteration of the loop, the link will never be up (because the link was just started), dw_pcie_wait_for_link() will then sleep for LINK_WAIT_SLEEP_MS (90 ms), before trying again.

This means that even if a driver was missing a msleep(PCIE_T_RRS_READY_MS) (100 ms), because of the call to dw_pcie_wait_for_link(), enumerating the bus would essentially be delayed by that time anyway (because of the sleep LINK_WAIT_SLEEP_MS (90 ms)).

While we could add the msleep(PCIE_T_RRS_READY_MS) after deasserting PERST, that would essentially bring back an unconditional delay during synchronous probe (the whole reason to use a Link Up IRQ was to avoid an unconditional delay during probe).

Thus, add the msleep(PCIE_T_RRS_READY_MS) before enumerating the bus in the IRQ handler. This way, we will not have an unconditional delay during boot for unpopulated PCIe slots.

Cc Laszlo Fiat <[email protected]>
Fixes ec9fd499b9c6 ("PCI: dw-rockchip: Don't wait for link since we can detect Link Up")

---
Hello Laszlo,

I know you have already tested this, but could you please send your Tested-by tag to this patch?

 drivers/pci/controller/dwc/pcie-dw-rockchip.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/controller/dwc/pcie-dw-rockchip.c +1 -0
index 7a6a95dc877a..ed8e3dfe80e0 100644
@@ -471,6 +471,7 @@ static irqreturn_t rockchip_pcie_rc_sys_irq_thread(int irq, void *arg)
 	if (reg & PCIE_RDLH_LINK_UP_CHGED) {
 		if (rockchip_pcie_link_up(pci)) {
 			dev_dbg(dev, "Received Link up event. Starting enumeration!\n");
+			msleep(PCIE_T_RRS_READY_MS);
 			/* Rescan the bus to enumerate endpoint devices */
 			pci_lock_rescan_remove();
 			pci_rescan_bus(pp->bridge->bus);
Signature · 1 line
2.49.0
#3 lore raw

PATCH 2/4 PCI: qcom: Do not enumerate bus before endpoint devices are ready

In reply to Niklas Cassel

Commit 36971d6c5a9a ("PCI: qcom: Don't wait for link if we can detect Link Up") changed so that we no longer call dw_pcie_wait_for_link(), and instead enumerate the bus when receiving a Link Up IRQ.

Before 36971d6c5a9a, we called dw_pcie_wait_for_link(), and in the first iteration of the loop, the link will never be up (because the link was just started), dw_pcie_wait_for_link() will then sleep for LINK_WAIT_SLEEP_MS (90 ms), before trying again.

This means that even if a driver was missing a msleep(PCIE_T_RRS_READY_MS) (100 ms), because of the call to dw_pcie_wait_for_link(), enumerating the bus would essentially be delayed by that time anyway (because of the sleep LINK_WAIT_SLEEP_MS (90 ms)).

While we could add the msleep(PCIE_T_RRS_READY_MS) after deasserting PERST (qcom already has an unconditional 1 ms sleep after deasserting PERST), that would essentially bring back an unconditional delay during probe (the whole reason to use a Link Up IRQ was to avoid an unconditional delay during probe).

Thus, add the msleep(PCIE_T_RRS_READY_MS) before enumerating the bus in the IRQ handler. This way, for qcom SoCs that has a link up IRQ, we will not have a 100 ms unconditional delay during boot for unpopulated PCIe slots.

Fixes 36971d6c5a9a ("PCI: qcom: Don't wait for link if we can detect Link Up")
---
 drivers/pci/controller/dwc/pcie-qcom.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/controller/dwc/pcie-qcom.c +1 -0
index 6b18a2775e7f..5cef5e92b173 100644
@@ -1646,6 +1646,7 @@ static irqreturn_t qcom_pcie_global_irq_thread(int irq, void *data)
 
 	if (FIELD_GET(PARF_INT_ALL_LINK_UP, status)) {
 		dev_dbg(dev, "Received Link up event. Starting enumeration!\n");
+		msleep(PCIE_T_RRS_READY_MS);
 		/* Rescan the bus to enumerate endpoint devices */
 		pci_lock_rescan_remove();
 		pci_rescan_bus(pp->bridge->bus);
Signature · 1 line
2.49.0
#4 lore raw

PATCH 3/4 PCI: dw-rockchip: Replace PERST sleep time with proper macro

In reply to Niklas Cassel

Replace the PERST sleep time with the proper macro (PCIE_T_PVPERL_MS). No functional change.

---
 drivers/pci/controller/dwc/pcie-dw-rockchip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-dw-rockchip.c +1 -1
index ed8e3dfe80e0..eb2931b39f7a 100644
@@ -231,7 +231,7 @@ static int rockchip_pcie_start_link(struct dw_pcie *pci)
 	 * We need more extra time as before, rather than setting just
 	 * 100us as we don't know how long should the device need to reset.
 	 */
-	msleep(100);
+	msleep(PCIE_T_PVPERL_MS);
 	gpiod_set_value_cansleep(rockchip->rst_gpio, 1);
 
 	return 0;
Signature · 1 line
2.49.0
#5 lore raw

PATCH 4/4 PCI: qcom: Replace PERST sleep time with proper macro

In reply to Niklas Cassel

Replace the PERST sleep time with the proper macro (PCIE_T_PVPERL_MS). No functional change.

---
 drivers/pci/controller/dwc/pcie-qcom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-qcom.c +1 -1
index 5cef5e92b173..b1b89d5cb86a 100644
@@ -301,7 +301,7 @@ static void qcom_ep_reset_assert(struct qcom_pcie *pcie)
 static void qcom_ep_reset_deassert(struct qcom_pcie *pcie)
 {
 	/* Ensure that PERST has been asserted for at least 100 ms */
-	msleep(100);
+	msleep(PCIE_T_PVPERL_MS);
 	gpiod_set_value_cansleep(pcie->reset, 0);
 	usleep_range(PERST_DELAY_US, PERST_DELAY_US + 500);
 }
Signature · 1 line
2.49.0
#2 lore raw

Re: [PATCH 1/4] PCI: dw-rockchip: Do not enumerate bus before endpoint devices are ready

In reply to Niklas Cassel
Quoted 15 lines · Niklas Cassel
drivers/pci/controller/dwc/pcie-dw-rockchip.c +1 -0
index 7a6a95dc877a..ed8e3dfe80e0 100644
@@ -471,6 +471,7 @@ static irqreturn_t rockchip_pcie_rc_sys_irq_thread(int irq, void *arg)
 	if (reg & PCIE_RDLH_LINK_UP_CHGED) {
 		if (rockchip_pcie_link_up(pci)) {
 			dev_dbg(dev, "Received Link up event. Starting enumeration!\n");
+			msleep(PCIE_T_RRS_READY_MS);
 			/* Rescan the bus to enumerate endpoint devices */
 			pci_lock_rescan_remove();
 			pci_rescan_bus(pp->bridge->bus);
Signature · 1 line
2.49.0

Bah.. this patch is missing
+#include "../../pci.h"

missed during rebase.

(pcie-qcom.c already includes this.)

Will send a V2.

Kind regards,
Niklas