Skip to contentSkip to conversation

rockchip rk3399 port initialization fixes

PATCH Applied Damien Le Moal 4 participants 7 messages Apr 13, 2024 – May 17, 2024

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v4 cover rockchip rk3399 port initialization fixes

A couple of patches to have the rockchip rk3399 host controller port initialization follow the PCI specifications around PERST# signal timing handling.

Changes from v3:
- Fixed commit messages as suggested by Bjorn.

Changes from v2:
- Use PCIE_T_PVPERL_MS macro in patch 1 (and remove useless comments).
- Split second msleep() addition into patch 2 as suggested by Bjorn.

Changes from v1:
- Add more specification details to the commit message.
- Add missing msleep(100) after PERST# is deasserted.

Damien Le Moal (2):
PCI: rockchip-host: Fix rockchip_pcie_host_init_port() PERST# handling
PCI: rockchip-host: Wait 100ms after reset before starting configuration

 drivers/pci/controller/pcie-rockchip-host.c | 3 +++
 drivers/pci/pci.h                           | 7 +++++++
 2 files changed, 10 insertions(+)
Signature · 1 line
2.44.0
#1 lore raw

PATCH v4 1/2 PCI: rockchip-host: Fix rockchip_pcie_host_init_port() PERST# handling

The PCIe specifications (PCIe CEM r5.1, sec 2.9.2) mandate that the PERST# signal must remain asserted for at least 100 usec (Tperst-clk) after the PCIe reference clock becomes stable (if a reference clock is supplied), and for at least 100 msec after the power is stable (Tpvperl, defined by the macro PCIE_T_PVPERL_MS).

Modify rockchip_pcie_host_init_port() to satisfy these constraints by adding a sleep period before deasserting PERST# using the ep_gpio GPIO. Since Tperst-clk is the shorter wait time, add an msleep() call for the longer PCIE_T_PVPERL_MS milliseconds to handle both timing requirements.

---
 drivers/pci/controller/pcie-rockchip-host.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/controller/pcie-rockchip-host.c +1 -0
index 300b9dc85ecc..fc868251e570 100644
@@ -322,6 +322,7 @@ static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip)
 	rockchip_pcie_write(rockchip, PCIE_CLIENT_LINK_TRAIN_ENABLE,
 			    PCIE_CLIENT_CONFIG);
 
+	msleep(PCIE_T_PVPERL_MS);
 	gpiod_set_value_cansleep(rockchip->ep_gpio, 1);
 
 	/* 500ms timeout value should be enough for Gen1/2 training */
Signature · 1 line
2.44.0
Reviewed-by on v4 1/2
#2 lore raw

Re: [PATCH v4 1/2] PCI: rockchip-host: Fix rockchip_pcie_host_init_port() PERST# handling

Quoted 6 lines · Damien Le Moal

The PCIe specifications (PCIe CEM r5.1, sec 2.9.2) mandate that the PERST# signal must remain asserted for at least 100 usec (Tperst-clk) after the PCIe reference clock becomes stable (if a reference clock is supplied), and for at least 100 msec after the power is stable (Tpvperl, defined by the macro PCIE_T_PVPERL_MS).

Quoted 6 lines

Modify rockchip_pcie_host_init_port() to satisfy these constraints by adding a sleep period before deasserting PERST# using the ep_gpio GPIO. Since Tperst-clk is the shorter wait time, add an msleep() call for the longer PCIE_T_PVPERL_MS milliseconds to handle both timing requirements.

- Mani

Quoted 20 lines
---
 drivers/pci/controller/pcie-rockchip-host.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/controller/pcie-rockchip-host.c +1 -0
index 300b9dc85ecc..fc868251e570 100644
@@ -322,6 +322,7 @@ static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip)
 	rockchip_pcie_write(rockchip, PCIE_CLIENT_LINK_TRAIN_ENABLE,
 			    PCIE_CLIENT_CONFIG);
 
+	msleep(PCIE_T_PVPERL_MS);
 	gpiod_set_value_cansleep(rockchip->ep_gpio, 1);
 
 	/* 500ms timeout value should be enough for Gen1/2 training */
Signature · 1 line
2.44.0
Signature · 1 line
மணிவண்ணன் சதாசிவம்
#3 lore raw

PATCH v4 2/2 PCI: rockchip-host: Wait 100ms after reset before starting configuration

In reply to Damien Le Moal

The PCI Express Base Specification r6.0, section 6.6.1, states that the host should wait for at least 100 msec from the end of a conventional reset (PERST# is de-asserted) before sending a configuration request to ensure that the device is able to respond with a "Request Retry Status" completion.

Add the PCIE_T_RRS_READY_MS macro to define this wait time and modify rockchip_pcie_host_init_port() to add this 100ms sleep after deasserting PERST# using the ep_gpio GPIO.

---
 drivers/pci/controller/pcie-rockchip-host.c | 2 ++
 drivers/pci/pci.h                           | 7 +++++++
 2 files changed, 9 insertions(+)
drivers/pci/controller/pcie-rockchip-host.c +2 -0
index fc868251e570..cbec71114825 100644
@@ -325,6 +325,8 @@ static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip)
 	msleep(PCIE_T_PVPERL_MS);
 	gpiod_set_value_cansleep(rockchip->ep_gpio, 1);
 
+	msleep(PCIE_T_RRS_READY_MS);
+
 	/* 500ms timeout value should be enough for Gen1/2 training */
 	err = readl_poll_timeout(rockchip->apb_base + PCIE_CLIENT_BASIC_STATUS1,
 				 status, PCIE_LINK_UP(status), 20,
drivers/pci/pci.h +7 -0
index 17fed1846847..c93ffc5e6e1f 100644
@@ -16,6 +16,13 @@
 /* Power stable to PERST# inactive from PCIe card Electromechanical Spec */
 #define PCIE_T_PVPERL_MS		100
 
+/*
+ * End of conventional reset (PERST# de-asserted) to first configuration
+ * request (device able to respond with a "Request Retry Status" completion),
+ * from PCI Express Base Specification r6.0, section 6.6.1.
+ */
+#define PCIE_T_RRS_READY_MS	100
+
 /*
  * PCIe r6.0, sec 5.3.3.2.1 <PME Synchronization>
  * Recommends 1ms to 10ms timeout to check L2 ready.
Signature · 1 line
2.44.0
Reviewed-by on v4 2/2
#4 lore raw

Re: [PATCH v4 2/2] PCI: rockchip-host: Wait 100ms after reset before starting configuration

Quoted 6 lines · Damien Le Moal

The PCI Express Base Specification r6.0, section 6.6.1, states that the host should wait for at least 100 msec from the end of a conventional reset (PERST# is de-asserted) before sending a configuration request to ensure that the device is able to respond with a "Request Retry Status" completion.

Quoted 6 lines

Add the PCIE_T_RRS_READY_MS macro to define this wait time and modify rockchip_pcie_host_init_port() to add this 100ms sleep after deasserting PERST# using the ep_gpio GPIO.

- Mani

Quoted 40 lines
---
 drivers/pci/controller/pcie-rockchip-host.c | 2 ++
 drivers/pci/pci.h                           | 7 +++++++
 2 files changed, 9 insertions(+)
drivers/pci/controller/pcie-rockchip-host.c +2 -0
index fc868251e570..cbec71114825 100644
@@ -325,6 +325,8 @@ static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip)
 	msleep(PCIE_T_PVPERL_MS);
 	gpiod_set_value_cansleep(rockchip->ep_gpio, 1);
 
+	msleep(PCIE_T_RRS_READY_MS);
+
 	/* 500ms timeout value should be enough for Gen1/2 training */
 	err = readl_poll_timeout(rockchip->apb_base + PCIE_CLIENT_BASIC_STATUS1,
 				 status, PCIE_LINK_UP(status), 20,
drivers/pci/pci.h +7 -0
index 17fed1846847..c93ffc5e6e1f 100644
@@ -16,6 +16,13 @@
 /* Power stable to PERST# inactive from PCIe card Electromechanical Spec */
 #define PCIE_T_PVPERL_MS		100
 
+/*
+ * End of conventional reset (PERST# de-asserted) to first configuration
+ * request (device able to respond with a "Request Retry Status" completion),
+ * from PCI Express Base Specification r6.0, section 6.6.1.
+ */
+#define PCIE_T_RRS_READY_MS	100
+
 /*
  * PCIe r6.0, sec 5.3.3.2.1 <PME Synchronization>
  * Recommends 1ms to 10ms timeout to check L2 ready.
Signature · 1 line
2.44.0
Signature · 1 line
மணிவண்ணன் சதாசிவம்
#5 lore raw
In reply to Damien Le Moal
Quoted 15 lines · Damien Le Moal

A couple of patches to have the rockchip rk3399 host controller port initialization follow the PCI specifications around PERST# signal timing handling.

Changes from v3:
- Fixed commit messages as suggested by Bjorn.

Changes from v2:
- Use PCIE_T_PVPERL_MS macro in patch 1 (and remove useless comments).
- Split second msleep() addition into patch 2 as suggested by Bjorn.

Changes from v1:
- Add more specification details to the commit message.
- Add missing msleep(100) after PERST# is deasserted.

Quoted 7 lines

Damien Le Moal (2):
PCI: rockchip-host: Fix rockchip_pcie_host_init_port() PERST# handling
PCI: rockchip-host: Wait 100ms after reset before starting configuration

 drivers/pci/controller/pcie-rockchip-host.c | 3 +++
 drivers/pci/pci.h                           | 7 +++++++
 2 files changed, 10 insertions(+)

Both applied by Krzysztof with Mani's Reviewed-by to pci/controller/rockchip, but his outgoing mail queue got stuck. It's really too late, but trying to squeeze this into v6.10.

#6 lore raw
In reply to Damien Le Moal
Quoted 3 lines

A couple of patches to have the rockchip rk3399 host controller port initialization follow the PCI specifications around PERST# signal timing handling.

Applied to controller/rockchip, thank you!

[01/02] PCI: rockchip-host: Fix rockchip_pcie_host_init_port() PERST# handling

        https://git.kernel.org/pci/pci/c/3392b74f3065
[02/02] PCI: rockchip-host: Wait 100ms after reset before starting configuration
        https://git.kernel.org/pci/pci/c/46a610678fef

	Krzysztof