]> Gentwo Git Trees - linux/.git/commitdiff
PCI: stm32: Fix LTSSM EP race with start link
authorChristian Bruel <christian.bruel@foss.st.com>
Fri, 14 Nov 2025 07:45:52 +0000 (08:45 +0100)
committerBjorn Helgaas <bhelgaas@google.com>
Mon, 17 Nov 2025 20:32:51 +0000 (14:32 -0600)
If the host has deasserted PERST# and started link training before the link
is started on EP side, enabling LTSSM before the endpoint registers are
initialized in the perst_irq handler results in probing incorrect values.

Thus, wait for the PERST# level-triggered interrupt to start link training
at the end of initialization and cleanup the stm32_pcie_[start stop]_link
functions.

Fixes: 151f3d29baf4 ("PCI: stm32-ep: Add PCIe Endpoint support for STM32MP25")
Signed-off-by: Christian Bruel <christian.bruel@foss.st.com>
[mani: added fixes tag]
Signed-off-by: Manivannan Sadhasivam <mani@kernel.org>
[bhelgaas: wrap line]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Link: https://patch.msgid.link/20251114-perst_ep-v1-1-e7976317a890@foss.st.com
drivers/pci/controller/dwc/pcie-stm32-ep.c

index 3400c7cd2d88a279c49ef36a99fc7537c381c384..faa6433a784f37afc799bba58c345d6c66562492 100644 (file)
@@ -37,36 +37,9 @@ static void stm32_pcie_ep_init(struct dw_pcie_ep *ep)
                dw_pcie_ep_reset_bar(pci, bar);
 }
 
-static int stm32_pcie_enable_link(struct dw_pcie *pci)
-{
-       struct stm32_pcie *stm32_pcie = to_stm32_pcie(pci);
-
-       regmap_update_bits(stm32_pcie->regmap, SYSCFG_PCIECR,
-                          STM32MP25_PCIECR_LTSSM_EN,
-                          STM32MP25_PCIECR_LTSSM_EN);
-
-       return dw_pcie_wait_for_link(pci);
-}
-
-static void stm32_pcie_disable_link(struct dw_pcie *pci)
-{
-       struct stm32_pcie *stm32_pcie = to_stm32_pcie(pci);
-
-       regmap_update_bits(stm32_pcie->regmap, SYSCFG_PCIECR, STM32MP25_PCIECR_LTSSM_EN, 0);
-}
-
 static int stm32_pcie_start_link(struct dw_pcie *pci)
 {
        struct stm32_pcie *stm32_pcie = to_stm32_pcie(pci);
-       int ret;
-
-       dev_dbg(pci->dev, "Enable link\n");
-
-       ret = stm32_pcie_enable_link(pci);
-       if (ret) {
-               dev_err(pci->dev, "PCIe cannot establish link: %d\n", ret);
-               return ret;
-       }
 
        enable_irq(stm32_pcie->perst_irq);
 
@@ -77,11 +50,7 @@ static void stm32_pcie_stop_link(struct dw_pcie *pci)
 {
        struct stm32_pcie *stm32_pcie = to_stm32_pcie(pci);
 
-       dev_dbg(pci->dev, "Disable link\n");
-
        disable_irq(stm32_pcie->perst_irq);
-
-       stm32_pcie_disable_link(pci);
 }
 
 static int stm32_pcie_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
@@ -152,6 +121,9 @@ static void stm32_pcie_perst_assert(struct dw_pcie *pci)
 
        dev_dbg(dev, "PERST asserted by host\n");
 
+       regmap_update_bits(stm32_pcie->regmap, SYSCFG_PCIECR,
+                          STM32MP25_PCIECR_LTSSM_EN, 0);
+
        pci_epc_deinit_notify(ep->epc);
 
        stm32_pcie_disable_resources(stm32_pcie);
@@ -192,6 +164,11 @@ static void stm32_pcie_perst_deassert(struct dw_pcie *pci)
 
        pci_epc_init_notify(ep->epc);
 
+       /* Enable link training */
+       regmap_update_bits(stm32_pcie->regmap, SYSCFG_PCIECR,
+                          STM32MP25_PCIECR_LTSSM_EN,
+                          STM32MP25_PCIECR_LTSSM_EN);
+
        return;
 
 err_disable_resources: