From nobody Fri Dec 19 18:17:04 2025 Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2896C13F458; Sun, 25 Aug 2024 13:47:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=78.133.224.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724593653; cv=none; b=t/L/0aMMMsPlznpiUca8jy9txAfDmtzoTnOZPmMed3/mahzecglI1seHnLH7n9GEM9dv9jM9oo2nHfrSnM4R1Tz0DRqi+l+5x8niBcONfjjpVlWjdrJsSk3pv4YiANTaAfWhG0krIKxlk+VGow/XidLh1e28rmuzrfu3RpCnz7s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724593653; c=relaxed/simple; bh=mYwbke1zdDrcretydAP2RY06U0kSmkFoCcERsWUTMVo=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=ZtuqCrsw60WDujl1VGgx6rCfs8FDkPxBGzFhNzpdl8+gFzzjqGtAX1NiSNTDcyYZB43tZ5z8yhoBy+4yY/j8Ek68xDXuNqNaHxXNEpGRDGwq5nlum0exE2vE7FnerT6Sjmh9K+6dkeDflo//lXksJOeeiFi+UCsybC636bqdD28= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk; spf=none smtp.mailfrom=orcam.me.uk; arc=none smtp.client-ip=78.133.224.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=orcam.me.uk Received: by angie.orcam.me.uk (Postfix, from userid 500) id 667A892009C; Sun, 25 Aug 2024 15:47:29 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 6475D92009B; Sun, 25 Aug 2024 14:47:29 +0100 (BST) Date: Sun, 25 Aug 2024 14:47:29 +0100 (BST) From: "Maciej W. Rozycki" To: =?UTF-8?Q?Ilpo_J=C3=A4rvinen?= , Matthew W Carlis , Bjorn Helgaas cc: Mika Westerberg , Oliver O'Halloran , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/4] PCI: Clear the LBMS bit after a link retrain In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The LBMS bit, where implemented, is set by hardware either in response=20 to the completion of retraining caused by writing 1 to the Retrain Link=20 bit or whenever hardware has changed the link speed or width in attempt=20 to correct unreliable link operation. It is never cleared by hardware=20 other than by software writing 1 to the bit position in the Link Status=20 register and we never do such a write. We currently have two places, namely `apply_bad_link_workaround' and=20 `pcie_failed_link_retrain' in drivers/pci/controller/dwc/pcie-tegra194.c=20 and drivers/pci/quirks.c respectively where we check the state of the=20 LBMS bit and neither is interested in the state of the bit resulting=20 from the completion of retraining, both check for a link fault. And in particular `pcie_failed_link_retrain' causes issues consequently,=20 by trying to retrain a link where there's no downstream device anymore=20 and the state of 1 in the LBMS bit has been retained from when there was=20 a device downstream that has since been removed. Clear the LBMS bit then at the conclusion of `pcie_retrain_link', so=20 that we have a single place that controls it and that our code can track=20 link speed or width changes resulting from unreliable link operation. Fixes: a89c82249c37 ("PCI: Work around PCIe link training failures") Reported-by: Matthew W Carlis Link: https://lore.kernel.org/r/20240806000659.30859-1-mattc@purestorage.co= m/ Link: https://lore.kernel.org/r/20240722193407.23255-1-mattc@purestorage.co= m/ Signed-off-by: Maciej W. Rozycki Cc: stable@vger.kernel.org # v6.5+ --- No change from v2. New change in v2. --- drivers/pci/pci.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) linux-pcie-retrain-link-lbms-clear.diff Index: linux-macro/drivers/pci/pci.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-macro.orig/drivers/pci/pci.c +++ linux-macro/drivers/pci/pci.c @@ -4718,7 +4718,15 @@ int pcie_retrain_link(struct pci_dev *pd pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, PCI_EXP_LNKCTL_RL); } =20 - return pcie_wait_for_link_status(pdev, use_lt, !use_lt); + rc =3D pcie_wait_for_link_status(pdev, use_lt, !use_lt); + + /* + * Clear LBMS after a manual retrain so that the bit can be used + * to track link speed or width changes made by hardware itself + * in attempt to correct unreliable link operation. + */ + pcie_capability_write_word(pdev, PCI_EXP_LNKSTA, PCI_EXP_LNKSTA_LBMS); + return rc; } =20 /**