From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA3012DC794; Fri, 14 Nov 2025 18:59:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146771; cv=none; b=JOUPmJHkv/GsuFjRazOKBwURI7Jff3gvLFpZ7w3zIKHMDOjuhZrw9cX7dajzTFwgh56ekzoJbooYoAmn6rFmSHC4cw3sLMN+87rrcTyt1pEJaAVNX6Q6xzlZZTHEx60QXQeW5f04DVkX64AnQQZJRnUK7MLYF9BjqbNVef9634w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146771; c=relaxed/simple; bh=kb4vVC9exWAZjRCcwIcqHoYZzk1sVFsAZ4sy0TjOZnU=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=QETwBt4EnixI/rcfuef0LwyRiGd5ELIlftOGC4A+yLlyAOqMlJLCwrxlbA36/pbvNRXbDmhEVk8V4ixQJTf8JpcF0l0zZoIaTz/yFgYXsSOTbBlJio6+pn3z5a73y8joJEhmAQkQOnHaVteXPQPy4uXXP03cnKcJOAMoV3Rj8wI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=D7sY7WBe; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="D7sY7WBe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A38BC2BC86; Fri, 14 Nov 2025 18:59:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1763146770; bh=kb4vVC9exWAZjRCcwIcqHoYZzk1sVFsAZ4sy0TjOZnU=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=D7sY7WBeYKhYRE/ZqKAyww/oiMkz2yorlpOCsTSA+VvkPWjr4qNoyWG22jVnny5ZW gs1lnsk0CkM9PLT8NG7WmjnBImZZHVdI8gOxC3VQpxvgPcLkzEdBrtzzqtbFIsQ0QO v32878CMEiOi4xiYQJ1TBCOG/KaHrVdGiSzlX97rOSKcTu5CP4UUQ4g3RtU8sxkNrI DlvTIhLY8Jbdf6Dk7U87xsmeJ84UQ5oukLg/g92pvyDyFFQk7wVrNMfGMTGPwTmAog h0k2wxcVHwtgw0dF6Ye7nsueTLiIYzzq82Md5pqoA3DuqNnN4suN+uYB/KwaQhUd3C qy3j20hjujKbw== Date: Fri, 14 Nov 2025 12:59:28 -0600 From: Bjorn Helgaas To: Christian Bruel Cc: Lorenzo Pieralisi , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , Bjorn Helgaas , Maxime Coquelin , Alexandre Torgue , 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. Message-ID: <20251114185928.GA2335574@bhelgaas> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251114-perst_ep-v1-1-e7976317a890@foss.st.com> 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? > Signed-off-by: Christian Bruel > --- > 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 >