PCI: rockchip-host: Fix rockchip_pcie_host_init_port() PERST# handling
PATCH v2 1/1 PCI: rockchip-host: Fix rockchip_pcie_host_init_port() PERST# handling
The PCIe specifications (PCI Express Electromechanical Specification rev 2.0, section 2.6.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), for at least 100 msec after the power is stable (Tpvperl).
In addition, the PCI Express Base SPecification Rev 2.0, section 6.6.1 state that the host should wait for at least 100 msec from the end of a conventional reset (PERST# is de-asserted) before accessing the configuration space of the attached device.
Modify rockchip_pcie_host_init_port() by adding two 100ms sleep, one before and after bringing back PESRT signal to high using the ep_gpio GPIO. Comments are also added to clarify this behavior.
---
Changes from v1:
- Add more specification details to the commit message.
- Add missing msleep(100) after PERST# is deasserted.
drivers/pci/controller/pcie-rockchip-host.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/pci/controller/pcie-rockchip-host.c +12 -0
@@ -294,6 +294,7 @@ static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip)int err, i =MAX_LANE_NUM ;u32 status; +/* Assert PERST */ gpiod_set_value_cansleep (rockchip->ep_gpio,0 ); err =rockchip_pcie_init_port (rockchip);
@@ -322,8 +323,19 @@ static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip)rockchip_pcie_write (rockchip,PCIE_CLIENT_LINK_TRAIN_ENABLE ,PCIE_CLIENT_CONFIG ); +/* +* PCIe CME specifications mandate that PERST be asserted for at +* least 100ms after power is stable. +*/ +msleep (100 );gpiod_set_value_cansleep (rockchip->ep_gpio,1 ); +/* +* PCIe base specifications rev 2.0 mandate that the host wait for +* 100ms after completion of a conventional reset. +*/ +msleep (100 ); +/* 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,
Signature · 1 line
2.44.0
Hello Damien,
Please see my comments below.
Quoted 40 lines · Damien Le Moal
The PCIe specifications (PCI Express Electromechanical Specification rev 2.0, section 2.6.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), for at least 100 msec after the power is stable (Tpvperl).
In addition, the PCI Express Base SPecification Rev 2.0, section 6.6.1 state that the host should wait for at least 100 msec from the end of a conventional reset (PERST# is de-asserted) before accessing the configuration space of the attached device.
Modify
rockchip_pcie_host_init_port()by adding two 100ms sleep, one before and after bringing back PESRT signal to high using theep_gpioGPIO. Comments are also added to clarify this behavior.Signed-off-by Damien Le Moal <[email protected]>---
Changes from v1:
- Add more specification details to the commit message.
- Add missing msleep(100) after PERST# is deasserted.drivers/pci/controller/pcie-rockchip-host.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/pci/controller/pcie-rockchip-host.c +1
-0@@ -294,6 +294,7 @@ static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip)int err, i =MAX_LANE_NUM ;u32 status; +/* Assert PERST */ gpiod_set_value_cansleep (rockchip->ep_gpio,0 );drivers/pci/controller/pcie-rockchip-host.c +0
-0err =rockchip_pcie_init_port (rockchip);
drivers/pci/controller/pcie-rockchip-host.c static int rockchip_pcie_host_init_port(struct · line 331
Quoted 9 lines
drivers/pci/controller/pcie-rockchip-host.c +5
-0@@ -322,8 +323,19 @@ static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip)rockchip_pcie_write (rockchip ,PCIE_CLIENT_LINK_TRAIN_ENABLE ,PCIE_CLIENT_CONFIG ); +/* +* PCIe CME specifications mandate that PERST be asserted for at +* least 100ms after power is stable. +*/ +msleep (100 );
Perhaps it would be slightly better to use usleep_range() instead of msleep().
drivers/pci/controller/pcie-rockchip-host.c static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip) · line 337
Quoted 7 lines
drivers/pci/controller/pcie-rockchip-host.c +5
-0gpiod_set_value_cansleep (rockchip->ep_gpio,1 ); +/* +* PCIe base specifications rev 2.0 mandate that the host wait for +* 100ms after completion of a conventional reset. +*/ +msleep (100 );
Obviously, the same comment as above applies here.
Quoted 5 lines
drivers/pci/controller/pcie-rockchip-host.c +1
-0+/* 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,
Quoted 51 lines · Dragan Simic
Hello Damien,
Please see my comments below.
Quoted 46 lines · Damien Le Moal
The PCIe specifications (PCI Express Electromechanical Specification rev
2.0, section 2.6.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), for at least 100 msec
after the power is stable (Tpvperl).In addition, the PCI Express Base SPecification Rev 2.0, section 6.6.1 state that the host should wait for at least 100 msec from the end of a conventional reset (PERST# is de-asserted) before accessing the configuration space of the attached device.
Modify
rockchip_pcie_host_init_port()by adding two 100ms sleep, one before and after bringing back PESRT signal to high using theep_gpioGPIO. Comments are also added to clarify this behavior.Signed-off-by Damien Le Moal <[email protected]>---
Changes from v1:
- Add more specification details to the commit message.
- Add missing msleep(100) after PERST# is deasserted.drivers/pci/controller/pcie-rockchip-host.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/pci/controller/pcie-rockchip-host.c +1
-0@@ -294,6 +294,7 @@ static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip)int err, i =MAX_LANE_NUM ;u32 status; +/* Assert PERST */ gpiod_set_value_cansleep (rockchip->ep_gpio,0 );drivers/pci/controller/pcie-rockchip-host.c +0
-0err =rockchip_pcie_init_port (rockchip);@@ -322,8 +323,19 @@ static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip)rockchip_pcie_write (rockchip ,PCIE_CLIENT_LINK_TRAIN_ENABLE ,PCIE_CLIENT_CONFIG );
Quoted 8 lines
drivers/pci/controller/pcie-rockchip-host.c static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip) · line 330
Quoted 5 lines
drivers/pci/controller/pcie-rockchip-host.c +5
-0+/* +* PCIe CME specifications mandate that PERST be asserted for at +* least 100ms after power is stable. +*/ +msleep (100 );Perhaps it would be slightly better to use
usleep_range()instead ofmsleep().
I can do that, but I fail to see the advantage. Why do you say that it may be better ?
Quoted 16 lines
drivers/pci/controller/pcie-rockchip-host.c static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip) · line 337
Quoted 8 lines
drivers/pci/controller/pcie-rockchip-host.c +5
-0gpiod_set_value_cansleep (rockchip->ep_gpio,1 ); +/* +* PCIe base specifications rev 2.0 mandate that the host wait for +* 100ms after completion of a conventional reset. +*/ +msleep (100 );Obviously, the same comment as above applies here.
Quoted 5 lines
drivers/pci/controller/pcie-rockchip-host.c +1
-0+/* 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,
Signature · 2 lines
Damien Le Moal Western Digital Research
Quoted 59 lines · Damien Le Moal
Quoted 49 lines · Dragan Simic
Please see my comments below.
Quoted 46 lines · Damien Le Moal
The PCIe specifications (PCI Express Electromechanical Specification rev
2.0, section 2.6.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), for at least 100 msec
after the power is stable (Tpvperl).In addition, the PCI Express Base SPecification Rev 2.0, section 6.6.1 state that the host should wait for at least 100 msec from the end of a conventional reset (PERST# is de-asserted) before accessing the configuration space of the attached device.
Modify
rockchip_pcie_host_init_port()by adding two 100ms sleep, one before and after bringing back PESRT signal to high using theep_gpioGPIO. Comments are also added to clarify this behavior.Signed-off-by Damien Le Moal <[email protected]>---
Changes from v1:
- Add more specification details to the commit message.
- Add missing msleep(100) after PERST# is deasserted.drivers/pci/controller/pcie-rockchip-host.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/pci/controller/pcie-rockchip-host.c +1
-0@@ -294,6 +294,7 @@ static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip)int err, i =MAX_LANE_NUM ;u32 status; +/* Assert PERST */ gpiod_set_value_cansleep (rockchip->ep_gpio,0 );drivers/pci/controller/pcie-rockchip-host.c +0
-0err =rockchip_pcie_init_port (rockchip);@@ -322,8 +323,19 @@ static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip)rockchip_pcie_write (rockchip ,PCIE_CLIENT_LINK_TRAIN_ENABLE ,PCIE_CLIENT_CONFIG );Quoted 8 lines
drivers/pci/controller/pcie-rockchip-host.c static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip) · line 330
Quoted 5 lines
drivers/pci/controller/pcie-rockchip-host.c +5
-0+/* +* PCIe CME specifications mandate that PERST be asserted for at +* least 100ms after power is stable. +*/ +msleep (100 );Perhaps it would be slightly better to use
usleep_range()instead ofmsleep().
Quoted 2 lines
I can do that, but I fail to see the advantage. Why do you say that it may be better ?
Actually, I was wrong. When sleeping for 100 msec, msleep() is actually the preferred variant. [1]
[1] https://www.kernel.org/doc/Documentation/timers/timers-howto.txt
Quoted 15 lines
Quoted 15 lines
drivers/pci/controller/pcie-rockchip-host.c static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip) · line 337
Quoted 7 lines
drivers/pci/controller/pcie-rockchip-host.c +5
-0gpiod_set_value_cansleep (rockchip->ep_gpio,1 ); +/* +* PCIe base specifications rev 2.0 mandate that the host wait for +* 100ms after completion of a conventional reset. +*/ +msleep (100 );Obviously, the same comment as above applies here.
Quoted 5 lines
drivers/pci/controller/pcie-rockchip-host.c +1
-0+/* 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,
Quoted 5 lines · Damien Le Moal
The PCIe specifications (PCI Express Electromechanical Specification rev 2.0, section 2.6.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), for at least 100 msec after the power is stable (Tpvperl).
Reference current spec, e.g., "PCIe CEM r5.1, sec 2.9.2" and a note about why you mention two parameters here but the code change only uses one of them.
Quoted 4 lines
In addition, the PCI Express Base SPecification Rev 2.0, section 6.6.1 state that the host should wait for at least 100 msec from the end of a conventional reset (PERST# is de-asserted) before accessing the configuration space of the attached device.
Current spec, e.g., "PCIe r6.0, sec 6.6.1".
Quoted 3 lines
Modify
rockchip_pcie_host_init_port()by adding two 100ms sleep, one before and after bringing back PESRT signal to high using theep_gpioGPIO. Comments are also added to clarify this behavior.
s/PESRT/PERST#/
This is two separate changes that really would be better as separate patches.
Quoted 23 lines
Signed-off-by Damien Le Moal <[email protected]>---
Changes from v1:
- Add more specification details to the commit message.
- Add missing msleep(100) after PERST# is deasserted.drivers/pci/controller/pcie-rockchip-host.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/pci/controller/pcie-rockchip-host.c +1
-0@@ -294,6 +294,7 @@ static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip)int err, i =MAX_LANE_NUM ;u32 status; +/* Assert PERST */ gpiod_set_value_cansleep (rockchip->ep_gpio,0 ); err =rockchip_pcie_init_port (rockchip);
drivers/pci/controller/pcie-rockchip-host.c static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip) · line 329
Quoted 7 lines
drivers/pci/controller/pcie-rockchip-host.c +4
-0@@ -322,8 +323,19 @@ static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip)rockchip_pcie_write (rockchip,PCIE_CLIENT_LINK_TRAIN_ENABLE ,PCIE_CLIENT_CONFIG ); +/* +* PCIe CME specifications mandate that PERST be asserted for at +* least 100ms after power is stable. +*/
Remove comment completely (given use of PCIE_T_PVPERL_MS below).
drivers/pci/controller/pcie-rockchip-host.c static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip) · line 330
Quoted 1 line
drivers/pci/controller/pcie-rockchip-host.c +1
-0+msleep (100 );
s/100/PCIE_T_PVPERL_MS/
drivers/pci/controller/pcie-rockchip-host.c static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip) · line 337
Quoted 7 lines
drivers/pci/controller/pcie-rockchip-host.c +5
-0gpiod_set_value_cansleep (rockchip->ep_gpio,1 ); +/* +* PCIe base specifications rev 2.0 mandate that the host wait for +* 100ms after completion of a conventional reset. +*/ +msleep (100 );
Please add a #define for this since it's generic across all PCIe, not just Rockchip.
I don't think the PCIe spec actually names this parameter. It's similar to T_rhfa (Conventional PCI r3.0, sec 4.3.2), although I think devices must be ready to accept config cycles after T_rhfa.
This delay is a little different because IIUC, a PCIe device doesn't have to be "Configuration Ready"; after 100ms, it only has to be able to respond with a "Request Retry Status" completion if it isn't Configuration Ready yet.
So I think we should add something like
#define PCIE_T_RRS_READY_MS 100
to drivers/pci/pci.h for this case.
Quoted 6 lines
drivers/pci/controller/pcie-rockchip-host.c +0
-0/* 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,Signature · 1 line
2.44.0