PCI: dw-rockchip: Clear stale link down interrupt before unmasking it
PATCH 1/1 PCI: dw-rockchip: Clear stale link down interrupt before unmasking it
PCIE_LINK_REQ_RST_NOT_INT is set by smlh_req_rst_not, which according to the RK3568 TRM "is asserted after power-on reset until first link up". The bit is thus already pending when the driver unmasks the interrupt after resetting the controller, both in probe and in .reset_root_port(), so the interrupt fires as soon as it is unmasked, even though the link is up. Since each recovery resets the controller again, this results in an endless loop, as seen on a Quartz64 Model B (RK3566):
pcieport 0000:00:00.0: Recovering Root Port due to Link Down pcieport 0000:00:00.0: Root Port has been reset pcieport 0000:00:00.0: AER: device recovery successful pcieport 0000:00:00.0: Recovering Root Port due to Link Down
Clear the bit before unmasking the interrupt, and in .reset_root_port() only unmask it once the link is back up, like in probe. Also keep the interrupt masked while .reset_root_port() resets the controller, so the link down caused by the reset itself is not reported.
--- drivers/pci/controller/dwc/pcie-dw-rockchip.c | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-)
drivers/pci/controller/dwc/pcie-dw-rockchip.c +17 -7
@@ -686,6 +686,18 @@ static irqreturn_t rockchip_pcie_ep_sys_irq_thread(int irq, void *arg)return IRQ_HANDLED ; } +static void rockchip_pcie_rc_unmask_link_down (struct rockchip_pcie *rockchip) +{ +u32 val; + +rockchip_pcie_writel_apb (rockchip,PCIE_LINK_REQ_RST_NOT_INT , +PCIE_CLIENT_INTR_STATUS_MISC ); + +/* unmask hot reset/link-down reset */ + val =FIELD_PREP_WM16 (PCIE_LINK_REQ_RST_NOT_INT ,0 ); +rockchip_pcie_writel_apb (rockchip, val,PCIE_CLIENT_INTR_MASK_MISC ); +} +static int rockchip_pcie_configure_rc (struct platform_device *pdev,struct rockchip_pcie *rockchip) {
@@ -739,9 +751,7 @@ static int rockchip_pcie_configure_rc(struct platform_device *pdev,return ret; } -/* unmask hot reset/link-down reset */ - val =FIELD_PREP_WM16 (PCIE_LINK_REQ_RST_NOT_INT ,0 ); -rockchip_pcie_writel_apb (rockchip, val,PCIE_CLIENT_INTR_MASK_MISC ); +rockchip_pcie_rc_unmask_link_down (rockchip);return ret; }
@@ -898,6 +908,9 @@ static int rockchip_pcie_rc_reset_root_port(struct pci_host_bridge *bridge,u32 val;int ret; + val =FIELD_PREP_WM16 (PCIE_LINK_REQ_RST_NOT_INT ,1 ); +rockchip_pcie_writel_apb (rockchip, val,PCIE_CLIENT_INTR_MASK_MISC ); +dw_pcie_stop_link (pci);clk_bulk_disable_unprepare (rockchip->clk_cnt, rockchip->clks);rockchip_pcie_phy_deinit (rockchip);
@@ -938,16 +951,13 @@ static int rockchip_pcie_rc_reset_root_port(struct pci_host_bridge *bridge, goto deinit_clk; } -/* unmask hot reset/link-down reset */ - val =FIELD_PREP_WM16 (PCIE_LINK_REQ_RST_NOT_INT ,0 ); -rockchip_pcie_writel_apb (rockchip, val,PCIE_CLIENT_INTR_MASK_MISC ); - ret =dw_pcie_start_link (pci);if (ret) goto deinit_clk;/* Ignore errors, the link may come up later */ dw_pcie_wait_for_link (pci); +rockchip_pcie_rc_unmask_link_down (rockchip);dev_dbg (dev,"Root Port reset completed\n" );return ret;
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
Signature · 1 line
2.56.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [High] PCI: dw-rockchip: resource underflow in…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [High] PCI: dw-rockchip: resource underflow in rockchip_pcie_rc_reset_root_port() [1]
--
commit 923d90cd91ba94b914ca3ad6a3e4e9904ee542db
Author: Niklas Cassel <[email protected]>
PCI: dw-rockchip: Clear stale link down interrupt before unmasking it
This commit clears the pending PCIE_LINK_REQ_RST_NOT_INT status bit before unmasking the link-down interrupt, and keeps it masked during Root Port resets until link training completes.
Quoted 4 lines
drivers/pci/controller/dwc/pcie-dw-rockchip.c +0
-0
[ ... ]
drivers/pci/controller/dwc/pcie-dw-rockchip.c static int rockchip_pcie_rc_reset_root_port(struct pci_host_bridge *bridge, · line 916
Quoted 10 lines
drivers/pci/controller/dwc/pcie-dw-rockchip.c +3
-0@@ -898,6 +908,9 @@ static int rockchip_pcie_rc_reset_root_port(struct pci_host_bridge *bridge,u32 val;int ret; + val =FIELD_PREP_WM16 (PCIE_LINK_REQ_RST_NOT_INT ,1 ); +rockchip_pcie_writel_apb (rockchip, val,PCIE_CLIENT_INTR_MASK_MISC ); +dw_pcie_stop_link (pci);clk_bulk_disable_unprepare (rockchip->clk_cnt, rockchip->clks);rockchip_pcie_phy_deinit (rockchip);
[Severity: High]
This problem wasn't introduced by this patch, but can a failure in rockchip_pcie_rc_reset_root_port() leave rockchip->clks and rockchip->phy disabled and underflow their enable counts [1] on a later reset?
After clk_bulk_disable_unprepare() and rockchip_pcie_phy_deinit() run, an error from reset_control_assert() (or any of the later failure paths that unwind back to deinit_clk / deinit_phy) returns with the clocks and PHY disabled, so the next rockchip_pcie_rc_reset_root_port() call disables them a second time.
[1] https://sashiko.dev/#/bug/linux-8ab80679-6144-4519-a14c-191434f49050
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 13 lines · Niklas Cassel
PCIE_LINK_REQ_RST_NOT_INTis set bysmlh_req_rst_not, which according to the RK3568 TRM "is asserted after power-on reset until first link up". The bit is thus already pending when the driver unmasks the interrupt after resetting the controller, both in probe and in .reset_root_port(), so the interrupt fires as soon as it is unmasked, even though the link is up. Since each recovery resets the controller again, this results in an endless loop, as seen on a Quartz64 Model B (RK3566):pcieport 0000:00:00.0: Recovering Root Port due to Link Down pcieport 0000:00:00.0: Root Port has been reset pcieport 0000:00:00.0: AER: device recovery successful pcieport 0000:00:00.0: Recovering Root Port due to Link Down
Quoted 5 lines
Clear the bit before unmasking the interrupt, and in .reset_root_port() only unmask it once the link is back up, like in probe. Also keep the interrupt masked while .reset_root_port() resets the controller, so the link down caused by the reset itself is not reported.
This looks right to me ,
Quoted 73 lines
Fixes b376b3ff9cb0 ("PCI: dw-rockchip: Implement .reset_root_port() and use for link down")Reported-by James Le Cuirot <[email protected]>Signed-off-by Niklas Cassel <[email protected]>--- drivers/pci/controller/dwc/pcie-dw-rockchip.c | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-)drivers/pci/controller/dwc/pcie-dw-rockchip.c +17
-7@@ -686,6 +686,18 @@ static irqreturn_t rockchip_pcie_ep_sys_irq_thread(int irq, void *arg)return IRQ_HANDLED ; } +static void rockchip_pcie_rc_unmask_link_down (struct rockchip_pcie *rockchip) +{ +u32 val; + +rockchip_pcie_writel_apb (rockchip,PCIE_LINK_REQ_RST_NOT_INT , +PCIE_CLIENT_INTR_STATUS_MISC ); + +/* unmask hot reset/link-down reset */ + val =FIELD_PREP_WM16 (PCIE_LINK_REQ_RST_NOT_INT ,0 ); +rockchip_pcie_writel_apb (rockchip, val,PCIE_CLIENT_INTR_MASK_MISC ); +} +static int rockchip_pcie_configure_rc (struct platform_device *pdev,struct rockchip_pcie *rockchip) {@@ -739,9 +751,7 @@ static int rockchip_pcie_configure_rc(struct platform_device *pdev,return ret; } -/* unmask hot reset/link-down reset */ - val =FIELD_PREP_WM16 (PCIE_LINK_REQ_RST_NOT_INT ,0 ); -rockchip_pcie_writel_apb (rockchip, val,PCIE_CLIENT_INTR_MASK_MISC ); +rockchip_pcie_rc_unmask_link_down (rockchip);return ret; }@@ -898,6 +908,9 @@ static int rockchip_pcie_rc_reset_root_port(struct pci_host_bridge *bridge,u32 val;int ret; + val =FIELD_PREP_WM16 (PCIE_LINK_REQ_RST_NOT_INT ,1 ); +rockchip_pcie_writel_apb (rockchip, val,PCIE_CLIENT_INTR_MASK_MISC ); +dw_pcie_stop_link (pci);clk_bulk_disable_unprepare (rockchip->clk_cnt, rockchip->clks);rockchip_pcie_phy_deinit (rockchip);@@ -938,16 +951,13 @@ static int rockchip_pcie_rc_reset_root_port(struct pci_host_bridge *bridge, goto deinit_clk; } -/* unmask hot reset/link-down reset */ - val =FIELD_PREP_WM16 (PCIE_LINK_REQ_RST_NOT_INT ,0 ); -rockchip_pcie_writel_apb (rockchip, val,PCIE_CLIENT_INTR_MASK_MISC ); - ret =dw_pcie_start_link (pci);if (ret) goto deinit_clk;/* Ignore errors, the link may come up later */ dw_pcie_wait_for_link (pci); +rockchip_pcie_rc_unmask_link_down (rockchip);dev_dbg (dev,"Root Port reset completed\n" );return ret;base-commit:
b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
Quoted 25 lines · Niklas Cassel
PCIE_LINK_REQ_RST_NOT_INTis set bysmlh_req_rst_not, which according to
the RK3568 TRM "is asserted after power-on reset until first link up".
The bit is thus already pending when the driver unmasks the interrupt after resetting the controller, both in probe and in .reset_root_port(),
so the interrupt fires as soon as it is unmasked, even though the link
is up. Since each recovery resets the controller again, this results in
an endless loop, as seen on a Quartz64 Model B (RK3566):pcieport 0000:00:00.0: Recovering Root Port due to Link Down pcieport 0000:00:00.0: Root Port has been reset pcieport 0000:00:00.0: AER: device recovery successful pcieport 0000:00:00.0: Recovering Root Port due to Link Down
Clear the bit before unmasking the interrupt, and in .reset_root_port()
only unmask it once the link is back up, like in probe. Also keep the interrupt masked while .reset_root_port() resets the controller, so the
link down caused by the reset itself is not reported.
Quoted 9 lines
Fixes b376b3ff9cb0 ("PCI: dw-rockchip: Implement .reset_root_port()and use for link down")
Reported-by James Le Cuirot <[email protected]>Closes:
https://lore.kernel.org/linux-pci/[email protected]/Signed-off-by Niklas Cassel <[email protected]>---
Looks good, thanks!