linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Bruel <christian.bruel@foss.st.com>
To: Bjorn Helgaas <helgaas@kernel.org>
Cc: "Lorenzo Pieralisi" <lpieralisi@kernel.org>,
	"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
	"Manivannan Sadhasivam" <mani@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
	"Alexandre Torgue" <alexandre.torgue@foss.st.com>,
	linux-pci@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] PCI: stm32: Fix LTSSM EP race with start link.
Date: Mon, 17 Nov 2025 13:04:47 +0100	[thread overview]
Message-ID: <367c8b88-79e7-4e8d-bf70-9d283696aba2@foss.st.com> (raw)
In-Reply-To: <20251114185928.GA2335574@bhelgaas>



On 11/14/25 19:59, Bjorn Helgaas wrote:
> On Fri, Nov 14, 2025 at 08:45:52AM +0100, Christian Bruel wrote:
>> 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.
> 
> I've seen this kind of thing in other drivers, and I wondered whether
> it was safe because the host asserts and deasserts PERST#
> asynchronously, independent of anything the endpoint is doing.
> 
> I assume it's possible that the host deasserts PERST# before this
> driver has the stm32_pcie_ep_perst_irq_thread() thread set up.  If
> that happens and the driver doesn't see the PERST# interrupt, does
> everything still work correctly?

yes it does. the PERST# interrupt is level-triggered and, if already 
de-asserted, fires only when enabled (it is NOAUTOEN) with start_link.

At that point, the host can enumerate by performing a manual rescan or 
rebind the PCIe driver, restarting the entire probe sequence.

Tested the pcie_epf_test driver with various power-up sequences: full 
power-up the host or device first, and stop or standby PM suspend/resume.


> 
>> Signed-off-by: Christian Bruel <christian.bruel@foss.st.com>
>> ---
>>   drivers/pci/controller/dwc/pcie-stm32-ep.c | 38 ++++++------------------------
>>   1 file changed, 7 insertions(+), 31 deletions(-)
>>
>> diff --git a/drivers/pci/controller/dwc/pcie-stm32-ep.c b/drivers/pci/controller/dwc/pcie-stm32-ep.c
>> index 3400c7cd2d88a279c49ef36a99fc7537c381c384..d0654bb43759bb8d0f0d7badbf7bdae839241fcf 100644
>> --- a/drivers/pci/controller/dwc/pcie-stm32-ep.c
>> +++ b/drivers/pci/controller/dwc/pcie-stm32-ep.c
>> @@ -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,8 @@ 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 +163,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:
>>
>> ---
>> base-commit: 31115ecec74fe5c679a149d7037009f26b3aa8a9
>> change-id: 20251113-perst_ep-0b57b9679cf9
>>
>> Best regards,
>> -- 
>> Christian Bruel <christian.bruel@foss.st.com>
>>


  reply	other threads:[~2025-11-17 12:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-14  7:45 [PATCH] PCI: stm32: Fix LTSSM EP race with start link Christian Bruel
2025-11-14 18:59 ` Bjorn Helgaas
2025-11-17 12:04   ` Christian Bruel [this message]
2025-11-17 20:00     ` Bjorn Helgaas
2025-11-18 18:34       ` Christian Bruel
2025-11-18 21:28         ` Bjorn Helgaas
2025-11-19 15:13           ` Christian Bruel
2025-11-19 15:47             ` Manivannan Sadhasivam
2025-11-17 15:10 ` Manivannan Sadhasivam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=367c8b88-79e7-4e8d-bf70-9d283696aba2@foss.st.com \
    --to=christian.bruel@foss.st.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=bhelgaas@google.com \
    --cc=helgaas@kernel.org \
    --cc=kwilczynski@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=lpieralisi@kernel.org \
    --cc=mani@kernel.org \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).