* [PATCH v2] PCI: rockchip-host: Retry link bring-up on repeated Recovery
@ 2026-11-16 7:05 Igor Velkov via B4 Relay
2026-11-16 7:11 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Igor Velkov via B4 Relay @ 2026-11-16 7:05 UTC (permalink / raw)
To: Shawn Lin, Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Bjorn Helgaas
Cc: Rob Herring, Heiko Stuebner, Matt Thompson, linux-pci,
linux-rockchip, linux-arm-kernel, linux-kernel, Igor Velkov
From: Igor Velkov <iav@iav.lv>
On Kobol Helios64 (RK3399 with a JMB585 at x2) about 3% of link
bring-ups go bad. The LTSSM reaches L0 and then re-enters Recovery about
every 200 us; the RC sees DLLPs about 300 times as often as on a good
link, with no DLLP or CRC errors. The first config read behind the port
gets no completion and aborts the CPU, or link training times out. The
state survives Recovery, and a new bring-up of the port clears it.
After the link comes up, poll the LTSSM for 5 ms and treat more than two
entries into Recovery as a bad bring-up. The RC runs at 2.5 GT/s only,
so no speed change goes through Recovery, and good bring-ups on the
boards we tested showed no Recovery entries after L0. Bring the port up
again, up to five tries in all with 500 ms between them, for this and
for a training timeout. An empty slot stays in Detect, so a timeout
there fails on the first try. If no try gives a usable link, probe and
resume fail as they do on a training timeout today.
Every link bring-up takes 5 ms longer. A link that stays bad delays the
failure by 3 to 5 s.
Signed-off-by: Igor Velkov <iav@iav.lv>
---
Tested on Helios64 with unbind/bind cycles; every bad bring-up was fixed
by the first retry:
- earlier builds with the same poll and retry loop, 7.3: no abort in 600
cycles (5 in 150 without the patch), 10/10 cold boots, 60/60 s2idle;
- 7.4-rc2 with Matt Thompson's RFC v2 [1]: 4 bad bring-ups in 150
cycles; with the RFC alone the JMB585 was lost in 5 of 150;
- this patch, 7.4-rc2: 5 bad bring-ups in 150 cycles (one of them a
training timeout), no abort; 20/20 s2idle.
An NVMe drive on a ROCK Pi 4A with the patch: 60 cycles, none rejected.
[1] https://lore.kernel.org/r/20261113-rfc-b4-v2-0-d6b14f95c1d6@boondocker.io
---
Changes in v2:
- Drop the hot reset of patch 2: it did not stop the aborts.
- Also retry when the link keeps entering Recovery in the first 5 ms
after link-up; up to five tries, 500 ms apart.
- Do not retry a training timeout in Detect.
- Rebase onto pci/next.
- Link to v1: https://lore.kernel.org/r/20261024-rockchip-pcie-resume-v1-0-58e54a5cf5f1@iav.lv
---
drivers/pci/controller/pcie-rockchip-host.c | 80 +++++++++++++++++++++++++++--
drivers/pci/controller/pcie-rockchip.h | 3 ++
2 files changed, 80 insertions(+), 3 deletions(-)
diff --git a/drivers/pci/controller/pcie-rockchip-host.c b/drivers/pci/controller/pcie-rockchip-host.c
index 1e1556e436b8..7c43e5bcccd3 100644
--- a/drivers/pci/controller/pcie-rockchip-host.c
+++ b/drivers/pci/controller/pcie-rockchip-host.c
@@ -13,12 +13,14 @@
#include <linux/bitfield.h>
#include <linux/bitrev.h>
+#include <linux/delay.h>
#include <linux/gpio/consumer.h>
#include <linux/interrupt.h>
#include <linux/iopoll.h>
#include <linux/irq.h>
#include <linux/irqchip/chained_irq.h>
#include <linux/irqdomain.h>
+#include <linux/ktime.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_pci.h>
@@ -29,6 +31,11 @@
#include "../pci.h"
#include "pcie-rockchip.h"
+#define ROCKCHIP_PCIE_LINK_CHECK_US 5000
+#define ROCKCHIP_PCIE_LINK_CHECK_MAX_RECOVERIES 2
+#define ROCKCHIP_PCIE_LINK_BRING_UP_TRIES 5
+#define ROCKCHIP_PCIE_LINK_RETRY_WAIT_MS 500
+
static void rockchip_pcie_enable_bw_int(struct rockchip_pcie *rockchip)
{
u32 status;
@@ -277,9 +284,40 @@ static void rockchip_pcie_set_power_limit(struct rockchip_pcie *rockchip)
rockchip_pcie_write(rockchip, status, PCIE_RC_CONFIG_CR + PCI_EXP_DEVCAP);
}
+/*
+ * A bad bring-up re-enters Recovery about every 200 us, and config requests
+ * through it get no completion. A good link settles in L0. Each visit to
+ * Recovery lasts about 5 us, so we busy-poll; the limit of two entries leaves
+ * margin for an occasional retrain of a good link.
+ */
+static bool rockchip_pcie_link_is_stable(struct rockchip_pcie *rockchip)
+{
+ ktime_t end = ktime_add_us(ktime_get(), ROCKCHIP_PCIE_LINK_CHECK_US);
+ bool was_recovery = false, is_recovery;
+ int recoveries = 0;
+ u32 state;
+
+ while (ktime_before(ktime_get(), end)) {
+ state = rockchip_pcie_read(rockchip, PCIE_CLIENT_DEBUG_OUT_0);
+ state &= PCIE_CLIENT_DEBUG_LTSSM_MASK;
+ is_recovery = state >= PCIE_CLIENT_DEBUG_LTSSM_RCVR_LOCK &&
+ state <= PCIE_CLIENT_DEBUG_LTSSM_RCVR_IDLE;
+
+ if (is_recovery && !was_recovery)
+ recoveries++;
+ was_recovery = is_recovery;
+ udelay(2);
+ }
+
+ return recoveries <= ROCKCHIP_PCIE_LINK_CHECK_MAX_RECOVERIES;
+}
+
/**
* rockchip_pcie_host_init_port - Initialize hardware
* @rockchip: PCIe port information
+ *
+ * Return: 0 on success, -EAGAIN if another bring-up of the link may help, or
+ * another negative error code
*/
static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip)
{
@@ -325,7 +363,19 @@ static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip)
status, PCIE_LINK_UP(status), 20,
500 * USEC_PER_MSEC);
if (err) {
- dev_err(dev, "PCIe link training gen1 timeout!\n");
+ status = rockchip_pcie_read(rockchip, PCIE_CLIENT_DEBUG_OUT_0) &
+ PCIE_CLIENT_DEBUG_LTSSM_MASK;
+ dev_warn(dev, "PCIe link training gen1 timeout, LTSSM %#x\n",
+ status);
+ /* An empty slot stays in Detect; another try cannot help. */
+ if (status > PCIE_CLIENT_DEBUG_LTSSM_DETECT_ACTIVE)
+ err = -EAGAIN;
+ goto err_power_off_phy;
+ }
+
+ if (!rockchip_pcie_link_is_stable(rockchip)) {
+ dev_warn(dev, "PCIe link up but keeps entering Recovery\n");
+ err = -EAGAIN;
goto err_power_off_phy;
}
@@ -377,6 +427,30 @@ static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip)
return err;
}
+static int rockchip_pcie_bring_up_port(struct rockchip_pcie *rockchip)
+{
+ struct device *dev = rockchip->dev;
+ int i, err;
+
+ for (i = 0; i < ROCKCHIP_PCIE_LINK_BRING_UP_TRIES; i++) {
+ if (i) {
+ dev_info(dev, "retrying the link bring-up (%d/%d)\n", i,
+ ROCKCHIP_PCIE_LINK_BRING_UP_TRIES - 1);
+ msleep(ROCKCHIP_PCIE_LINK_RETRY_WAIT_MS);
+ }
+ err = rockchip_pcie_host_init_port(rockchip);
+ if (err != -EAGAIN)
+ break;
+ }
+
+ if (err == -EAGAIN)
+ err = -ETIMEDOUT;
+ if (err)
+ dev_err(dev, "no usable link: %pe\n", ERR_PTR(err));
+
+ return err;
+}
+
static irqreturn_t rockchip_pcie_subsys_irq_handler(int irq, void *arg)
{
struct rockchip_pcie *rockchip = arg;
@@ -881,7 +955,7 @@ static int rockchip_pcie_resume_noirq(struct device *dev)
if (err)
goto err_disable_0v9;
- err = rockchip_pcie_host_init_port(rockchip);
+ err = rockchip_pcie_bring_up_port(rockchip);
if (err)
goto err_pcie_resume;
@@ -938,7 +1012,7 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
goto err_set_vpcie;
}
- err = rockchip_pcie_host_init_port(rockchip);
+ err = rockchip_pcie_bring_up_port(rockchip);
if (err)
goto err_vpcie;
diff --git a/drivers/pci/controller/pcie-rockchip.h b/drivers/pci/controller/pcie-rockchip.h
index b5da15601b58..fcdc3783b3fd 100644
--- a/drivers/pci/controller/pcie-rockchip.h
+++ b/drivers/pci/controller/pcie-rockchip.h
@@ -51,6 +51,9 @@
#define PCIE_CLIENT_PHY_ST BIT(12)
#define PCIE_CLIENT_DEBUG_OUT_0 (PCIE_CLIENT_BASE + 0x3c)
#define PCIE_CLIENT_DEBUG_LTSSM_MASK GENMASK(5, 0)
+#define PCIE_CLIENT_DEBUG_LTSSM_DETECT_ACTIVE 0x01
+#define PCIE_CLIENT_DEBUG_LTSSM_RCVR_LOCK 0x0b
+#define PCIE_CLIENT_DEBUG_LTSSM_RCVR_IDLE 0x0e
#define PCIE_CLIENT_DEBUG_LTSSM_L1 0x18
#define PCIE_CLIENT_DEBUG_LTSSM_L2 0x19
#define PCIE_CLIENT_BASIC_STATUS0 (PCIE_CLIENT_BASE + 0x44)
---
base-commit: 35f800669ce835aa77364a2ab5b61be19b778d3c
change-id: 20261018-rockchip-pcie-resume-2c4dfe23341e
Best regards,
--
Igor Velkov <iav@iav.lv>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] PCI: rockchip-host: Retry link bring-up on repeated Recovery
2026-11-16 7:05 [PATCH v2] PCI: rockchip-host: Retry link bring-up on repeated Recovery Igor Velkov via B4 Relay
@ 2026-11-16 7:11 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-16 7:11 UTC (permalink / raw)
To: Igor Velkov; +Cc: linux-pci
> From: Igor Velkov <iav@iav.lv>
>
> On Kobol Helios64 (RK3399 with a JMB585 at x2) about 3% of link
> bring-ups go bad. The LTSSM reaches L0 and then re-enters Recovery about
> every 200 us; the RC sees DLLPs about 300 times as often as on a good
> link, with no DLLP or CRC errors. The first config read behind the port
> gets no completion and aborts the CPU, or link training times out. The
> state survives Recovery, and a new bring-up of the port clears it.
>
> After the link comes up, poll the LTSSM for 5 ms and treat more than two
> entries into Recovery as a bad bring-up. The RC runs at 2.5 GT/s only,
> so no speed change goes through Recovery, and good bring-ups on the
> boards we tested showed no Recovery entries after L0. Bring the port up
> again, up to five tries in all with 500 ms between them, for this and
> for a training timeout. An empty slot stays in Detect, so a timeout
> there fails on the first try. If no try gives a usable link, probe and
> resume fail as they do on a training timeout today.
>
> Every link bring-up takes 5 ms longer. A link that stays bad delays the
> failure by 3 to 5 s.
>
> Signed-off-by: Igor Velkov <iav@iav.lv>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-rockchip-pcie-resume-v2-1-a633e279be97@iav.lv?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-16 7:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 7:05 [PATCH v2] PCI: rockchip-host: Retry link bring-up on repeated Recovery Igor Velkov via B4 Relay
2026-11-16 7:11 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox