[PATCH RFC v3 5/6] PCI: rockchip-host: Defer retraining during initial link training
From: Matt Thompson via B4 Relay
Date: Mon Nov 16 2026 - 04:36:17 EST
From: Matt Thompson <matt@xxxxxxxxxxxxx>
Clearing Link Disable starts initial training. A retrain request can
arrive while the PHY is still in Detect, when it cannot recover a data
link that later stalls in initialization. On RockPro64 the link could
reach L0 while the data link remained unable to pass configuration
traffic.
Remember an early request and give initialization 50 ms to finish.
If a later downstream access finds the PHY ready with data link
initialization still pending, issue the saved request once and leave
configuration access blocked until the data link becomes ready.
Signed-off-by: Matt Thompson <matt@xxxxxxxxxxxxx>
---
drivers/pci/controller/pcie-rockchip-host.c | 45 +++++++++++++++++++++++++++--
drivers/pci/controller/pcie-rockchip.h | 3 ++
2 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/controller/pcie-rockchip-host.c b/drivers/pci/controller/pcie-rockchip-host.c
index 64ac6f4..d6c494f 100644
--- a/drivers/pci/controller/pcie-rockchip-host.c
+++ b/drivers/pci/controller/pcie-rockchip-host.c
@@ -19,6 +19,7 @@
#include <linux/irq.h>
#include <linux/irqchip/chained_irq.h>
#include <linux/irqdomain.h>
+#include <linux/jiffies.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_pci.h>
@@ -123,11 +124,28 @@ static int rockchip_pcie_wr_own_conf(struct rockchip_pcie *rockchip,
int where, int size, u32 val)
{
u32 mask, tmp, offset;
+ bool link_control = where == 0xc0 + PCI_EXP_LNKCTL;
void __iomem *addr;
offset = where & ~0x3;
addr = rockchip->apb_base + PCIE_RC_CONFIG_NORMAL_BASE + offset;
+ /*
+ * Let the PHY finish initial training after Link Disable is cleared.
+ * Retain a request made during this phase in case the data link does
+ * not finish initializing on its own.
+ */
+ if (link_control && (val & PCI_EXP_LNKCTL_LD)) {
+ rockchip->retrain_pending = false;
+ } else if (link_control && (val & PCI_EXP_LNKCTL_RL)) {
+ rockchip->retrain_pending = false;
+ if (!PCIE_LINK_TRAINING_DONE(rockchip_pcie_read(rockchip, PCIE_CORE_CTRL))) {
+ rockchip->retrain_pending = true;
+ rockchip->retrain_after = jiffies + msecs_to_jiffies(50);
+ val &= ~PCI_EXP_LNKCTL_RL;
+ }
+ }
+
if (size == 4) {
writel(val, addr);
return PCIBIOS_SUCCESSFUL;
@@ -149,8 +167,29 @@ static int rockchip_pcie_wr_own_conf(struct rockchip_pcie *rockchip,
static bool rockchip_pcie_downstream_ready(struct rockchip_pcie *rockchip)
{
- return PCIE_LINK_UP(rockchip_pcie_read(rockchip, PCIE_CLIENT_BASIC_STATUS1)) &&
- PCIE_LINK_TRAINING_DONE(rockchip_pcie_read(rockchip, PCIE_CORE_CTRL));
+ u32 status = rockchip_pcie_read(rockchip, PCIE_CLIENT_BASIC_STATUS1);
+ u32 core = rockchip_pcie_read(rockchip, PCIE_CORE_CTRL);
+ u32 control;
+
+ if (!PCIE_LINK_TRAINING_DONE(core))
+ return false;
+ if (PCIE_LINK_UP(status)) {
+ rockchip->retrain_pending = false;
+ return true;
+ }
+
+ if (rockchip->retrain_pending &&
+ time_after_eq(jiffies, rockchip->retrain_after) &&
+ (status & PCIE_CLIENT_LINK_STATUS_MASK) == PCIE_CLIENT_LINK_STATUS_DL_INIT) {
+ rockchip->retrain_pending = false;
+ rockchip_pcie_rd_own_conf(rockchip, 0xc0 + PCI_EXP_LNKCTL, 2, &control);
+ if (!(control & PCI_EXP_LNKCTL_LD)) {
+ rockchip_pcie_wr_own_conf(rockchip, 0xc0 + PCI_EXP_LNKCTL, 2,
+ control | PCI_EXP_LNKCTL_RL);
+ }
+ }
+
+ return false;
}
#ifdef CONFIG_ARM64
@@ -914,6 +953,8 @@ static int rockchip_pcie_suspend_noirq(struct device *dev)
struct rockchip_pcie *rockchip = dev_get_drvdata(dev);
int ret;
+ rockchip->retrain_pending = false;
+
/* disable core and cli int since we don't need to ack PME_ACK */
rockchip_pcie_write(rockchip, (PCIE_CLIENT_INT_CLI << 16) |
PCIE_CLIENT_INT_CLI, PCIE_CLIENT_INT_MASK);
diff --git a/drivers/pci/controller/pcie-rockchip.h b/drivers/pci/controller/pcie-rockchip.h
index 1cc3621..5fdd06b 100644
--- a/drivers/pci/controller/pcie-rockchip.h
+++ b/drivers/pci/controller/pcie-rockchip.h
@@ -58,6 +58,7 @@
#define PCIE_CLIENT_NEG_LINK_WIDTH_SHIFT 6
#define PCIE_CLIENT_NEG_LINK_SPEED BIT(5)
#define PCIE_CLIENT_BASIC_STATUS1 (PCIE_CLIENT_BASE + 0x48)
+#define PCIE_CLIENT_LINK_STATUS_DL_INIT 0x00200000
#define PCIE_CLIENT_LINK_STATUS_UP 0x00300000
#define PCIE_CLIENT_LINK_STATUS_MASK 0x00300000
#define PCIE_CLIENT_INT_MASK (PCIE_CLIENT_BASE + 0x4c)
@@ -325,6 +326,8 @@ struct rockchip_pcie {
void __iomem *msg_region;
phys_addr_t msg_bus_addr;
bool is_rc;
+ bool retrain_pending;
+ unsigned long retrain_after;
struct resource *mem_res;
};
--
Git-155)