From nobody Fri Dec 19 16:38:15 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 /** From nobody Fri Dec 19 16:38:15 2025 Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 531DB156F5D; Sun, 25 Aug 2024 13:47:35 +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=1724593657; cv=none; b=VkIxFPMcoejQG+2PRwu9j0WVPSkLeh/uUekIvRMFpbyVZdXL3XRoJvJEm3RyifOpZWVSssYnaCm1nwnuQgH4ENy534Vs3OYloUNpcEyL9i8+tP1WcJUBOoYzspGcv0Kp3qoRMYhVc2H/d75GPVgt31Ob9oIsDPlh4j7hqSDM6Xg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724593657; c=relaxed/simple; bh=43V8fSOAt4n23KEKHNBs62n3AClRL2dxS4yXIf/NKUk=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=DKvxv5IHgqOUAWcIDpgWa6RUEElERJTptXnHlvkGqvFxwbsDQwNtc9v8KrvlqdW+Q5rVlzjevgGNspSN5uJLTANNjdA8/s750iqdcyo4lqULP9EqBPMrmOoPzgHTHBvCZaFa7R4+QEaaLy+7N9hDXKsYB1Pl9AgkqXoKJs+nzuM= 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 317FC92009C; Sun, 25 Aug 2024 15:47:34 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 2E05D92009B; Sun, 25 Aug 2024 14:47:34 +0100 (BST) Date: Sun, 25 Aug 2024 14:47:34 +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 2/4] PCI: Revert to the original speed after PCIe failed link retraining 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" When `pcie_failed_link_retrain' has failed to retrain the link by hand=20 it leaves the link speed restricted to 2.5GT/s, which will then affect=20 any device that has been plugged in later on, which may not suffer from=20 the problem that caused the speed restriction to have been attempted. =20 Consequently such a downstream device will suffer from an unnecessary=20 communication throughput limitation and therefore performance loss. Remove the speed restriction then and revert the Link Control 2 register=20 to its original state if link retraining with the speed restriction in=20 place has failed. Retrain the link again afterwards so as to remove any=20 residual state, waiting on LT rather than DLLLA to avoid an excessive=20 delay and ignoring the result as this training is supposed to fail anyway. 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+ Reviewed-by: Ilpo J=C3=A4rvinen --- Changes from v2: - Wait on LT rather than DLLLA with clean-up retraining with the speed=20 restriction lifted, so as to avoid an excessive delay as it's supposed=20 to fail anyway. New change in v2. --- drivers/pci/quirks.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) linux-pcie-failed-link-retrain-fail-unclamp.diff Index: linux-macro/drivers/pci/quirks.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/quirks.c +++ linux-macro/drivers/pci/quirks.c @@ -66,7 +66,7 @@ * apply this erratum workaround to any downstream ports as long as they * support Link Active reporting and have the Link Control 2 register. * Restrict the speed to 2.5GT/s then with the Target Link Speed field, - * request a retrain and wait 200ms for the data link to go up. + * request a retrain and check the result. * * If this turns out successful and we know by the Vendor:Device ID it is * safe to do so, then lift the restriction, letting the devices negotiate @@ -74,6 +74,10 @@ * firmware may have already arranged and lift it with ports that already * report their data link being up. * + * Otherwise revert the speed to the original setting and request a retrain + * again to remove any residual state, ignoring the result as it's supposed + * to fail anyway. + * * Return TRUE if the link has been successfully retrained, otherwise FALS= E. */ bool pcie_failed_link_retrain(struct pci_dev *dev) @@ -92,6 +96,8 @@ bool pcie_failed_link_retrain(struct pci pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta); if ((lnksta & (PCI_EXP_LNKSTA_LBMS | PCI_EXP_LNKSTA_DLLLA)) =3D=3D PCI_EXP_LNKSTA_LBMS) { + u16 oldlnkctl2 =3D lnkctl2; + pci_info(dev, "broken device, retraining non-functional downstream link = at 2.5GT/s\n"); =20 lnkctl2 &=3D ~PCI_EXP_LNKCTL2_TLS; @@ -100,6 +106,9 @@ bool pcie_failed_link_retrain(struct pci =20 if (pcie_retrain_link(dev, false)) { pci_info(dev, "retraining failed\n"); + pcie_capability_write_word(dev, PCI_EXP_LNKCTL2, + oldlnkctl2); + pcie_retrain_link(dev, true); return false; } From nobody Fri Dec 19 16:38:15 2025 Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 55507155C93; Sun, 25 Aug 2024 13:47:41 +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=1724593663; cv=none; b=MnYWTaxzMavp7VyBBo+JO0fQOln8HvQktf536EEindU/3ebQJAHtp6LKLQFJAZg9UZsccaGZAx0hSQsqYxh4mxsCWCDQfXthENYISND2x+pKAEIDcyIVjHU5GKFTCgmQSwVJ1zV0bk99ROEdh4vaHygAkM/LztPeloapJTlEZ2o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724593663; c=relaxed/simple; bh=HXenWO0mvS6SJdnD9Sh0kToK3+6VoC+91twZpxSvFHg=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=YdouFKfSfnJSok5w2vmirg0Qadh80V4n9hD1gOFNsuYab/AWNA6xsQe15CwgIucg7SjU1Hog3aLn7QZGuj4Gv3ooF6qGYejpEBuhEUs9aPyjCsI0D4fzIgriPoZApQCjUj87FhfClirfRlAErjc9LMYB31WO07nolL/MREu97pw= 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 F365192009D; Sun, 25 Aug 2024 15:47:39 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id ED6CB92009B; Sun, 25 Aug 2024 14:47:39 +0100 (BST) Date: Sun, 25 Aug 2024 14:47:39 +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 3/4] PCI: Correct error reporting with PCIe failed link retraining 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Only return successful completion status from `pcie_failed_link_retrain'=20 if retraining has actually been done, preventing excessive delays from=20 being triggered at call sites in a hope that communication will finally=20 be established with the downstream device where in fact nothing has been=20 done about the link in question that would justify such a hope. Fixes: a89c82249c37 ("PCI: Work around PCIe link training failures") Reported-by: Ilpo J=C3=A4rvinen Link: https://lore.kernel.org/r/aa2d1c4e-9961-d54a-00c7-ddf8e858a9b0@linux.= intel.com/ Signed-off-by: Maciej W. Rozycki Reviewed-by: Ilpo J=C3=A4rvinen Cc: stable@vger.kernel.org # v6.5+ --- No changes from v2. Changes from v1 (superseding 1/2): - Regenerate on top of 2/4. - Reword the comment update for clarity. - Go back to returning explicit FALSE rather than `ret' where it is known=20 that we failed. --- drivers/pci/quirks.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) linux-pcie-failed-link-retrain-status-fix.diff Index: linux-macro/drivers/pci/quirks.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/quirks.c +++ linux-macro/drivers/pci/quirks.c @@ -78,7 +78,8 @@ * again to remove any residual state, ignoring the result as it's supposed * to fail anyway. * - * Return TRUE if the link has been successfully retrained, otherwise FALS= E. + * Return TRUE if the link has been successfully retrained. Return FALSE + * if retraining was not needed or we attempted a retrain and it failed. */ bool pcie_failed_link_retrain(struct pci_dev *dev) { @@ -87,6 +88,7 @@ bool pcie_failed_link_retrain(struct pci {} }; u16 lnksta, lnkctl2; + bool ret =3D false; =20 if (!pci_is_pcie(dev) || !pcie_downstream_port(dev) || !pcie_cap_has_lnkctl2(dev) || !dev->link_active_reporting) @@ -104,7 +106,8 @@ bool pcie_failed_link_retrain(struct pci lnkctl2 |=3D PCI_EXP_LNKCTL2_TLS_2_5GT; pcie_capability_write_word(dev, PCI_EXP_LNKCTL2, lnkctl2); =20 - if (pcie_retrain_link(dev, false)) { + ret =3D pcie_retrain_link(dev, false) =3D=3D 0; + if (!ret) { pci_info(dev, "retraining failed\n"); pcie_capability_write_word(dev, PCI_EXP_LNKCTL2, oldlnkctl2); @@ -126,13 +129,14 @@ bool pcie_failed_link_retrain(struct pci lnkctl2 |=3D lnkcap & PCI_EXP_LNKCAP_SLS; pcie_capability_write_word(dev, PCI_EXP_LNKCTL2, lnkctl2); =20 - if (pcie_retrain_link(dev, false)) { + ret =3D pcie_retrain_link(dev, false) =3D=3D 0; + if (!ret) { pci_info(dev, "retraining failed\n"); return false; } } =20 - return true; + return ret; } =20 static ktime_t fixup_debug_start(struct pci_dev *dev, From nobody Fri Dec 19 16:38:15 2025 Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2830E155727; Sun, 25 Aug 2024 13:47:45 +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=1724593667; cv=none; b=bjQzglQ1SzuS/C1GMz0Ivpza94GQ64S9JKXTfvxbOFlmH+cB9FqxnRsvv/NC0mQnwXUIyl0R0A0crYsLvKPCx5xC2t2IWGKwgxiRoOh9NT+AZ+XZ5FENuUtK4aAePraGu/UKZoWkDG+DcHMguasx8f/votazN/XhHtmfK8yW6uY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724593667; c=relaxed/simple; bh=bIzM3uWDDV2Xj7QItaFOLiOTUVZ6W104VSZEtoQ9mkw=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=g49h+BJcMyqlXuveIk1xMS1Ol1pQLemiPiBUObG5U8a9NbC2fgXgD4AX1fZMM1TRBhtOVOPrNa1KmYKIbe4kdAvKFiC2Gw3iKa8hnQjcfW6wdkDEhA/PGtSNKtQJK4lti5sJaMs0K5M5EqnA81pVkoxN2HG/APnEKqK3JhpwNMk= 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 2453892009D; Sun, 25 Aug 2024 15:47:45 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 1F1D792009B; Sun, 25 Aug 2024 14:47:45 +0100 (BST) Date: Sun, 25 Aug 2024 14:47:45 +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 4/4] PCI: Use an error code with PCIe failed link retraining 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Given how the call place in `pcie_wait_for_link_delay' got structured=20 now, and that `pcie_retrain_link' returns a potentially useful error=20 code, convert `pcie_failed_link_retrain' to return an error code rather=20 than a boolean status, fixing handling at the call site mentioned. =20 Update the other call site accordingly. Fixes: 1abb47390350 ("Merge branch 'pci/enumeration'") Reported-by: Ilpo J=C3=A4rvinen Link: https://lore.kernel.org/r/aa2d1c4e-9961-d54a-00c7-ddf8e858a9b0@linux.= intel.com/ Signed-off-by: Maciej W. Rozycki Reviewed-by: Ilpo J=C3=A4rvinen Cc: stable@vger.kernel.org # v6.5+ --- Changes from v2: - Regenerate following changes to 2/4, no functional change. Changes from v1 (superseding 2/2): - Regenerate following changes to 3/4, no functional change. --- drivers/pci/pci.c | 2 +- drivers/pci/pci.h | 6 +++--- drivers/pci/quirks.c | 20 ++++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) linux-pcie-failed-link-retrain-status-int.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 @@ -1324,7 +1324,7 @@ static int pci_dev_wait(struct pci_dev * if (delay > PCI_RESET_WAIT) { if (retrain) { retrain =3D false; - if (pcie_failed_link_retrain(bridge)) { + if (pcie_failed_link_retrain(bridge) =3D=3D 0) { delay =3D 1; continue; } Index: linux-macro/drivers/pci/pci.h =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.h +++ linux-macro/drivers/pci/pci.h @@ -606,7 +606,7 @@ void pci_acs_init(struct pci_dev *dev); int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags); int pci_dev_specific_enable_acs(struct pci_dev *dev); int pci_dev_specific_disable_acs_redir(struct pci_dev *dev); -bool pcie_failed_link_retrain(struct pci_dev *dev); +int pcie_failed_link_retrain(struct pci_dev *dev); #else static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags) @@ -621,9 +621,9 @@ static inline int pci_dev_specific_disab { return -ENOTTY; } -static inline bool pcie_failed_link_retrain(struct pci_dev *dev) +static inline int pcie_failed_link_retrain(struct pci_dev *dev) { - return false; + return -ENOTTY; } #endif =20 Index: linux-macro/drivers/pci/quirks.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/quirks.c +++ linux-macro/drivers/pci/quirks.c @@ -78,21 +78,21 @@ * again to remove any residual state, ignoring the result as it's supposed * to fail anyway. * - * Return TRUE if the link has been successfully retrained. Return FALSE + * Return 0 if the link has been successfully retrained. Return an error * if retraining was not needed or we attempted a retrain and it failed. */ -bool pcie_failed_link_retrain(struct pci_dev *dev) +int pcie_failed_link_retrain(struct pci_dev *dev) { static const struct pci_device_id ids[] =3D { { PCI_VDEVICE(ASMEDIA, 0x2824) }, /* ASMedia ASM2824 */ {} }; u16 lnksta, lnkctl2; - bool ret =3D false; + int ret =3D -ENOTTY; =20 if (!pci_is_pcie(dev) || !pcie_downstream_port(dev) || !pcie_cap_has_lnkctl2(dev) || !dev->link_active_reporting) - return false; + return ret; =20 pcie_capability_read_word(dev, PCI_EXP_LNKCTL2, &lnkctl2); pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta); @@ -106,13 +106,13 @@ bool pcie_failed_link_retrain(struct pci lnkctl2 |=3D PCI_EXP_LNKCTL2_TLS_2_5GT; pcie_capability_write_word(dev, PCI_EXP_LNKCTL2, lnkctl2); =20 - ret =3D pcie_retrain_link(dev, false) =3D=3D 0; - if (!ret) { + ret =3D pcie_retrain_link(dev, false); + if (ret) { pci_info(dev, "retraining failed\n"); pcie_capability_write_word(dev, PCI_EXP_LNKCTL2, oldlnkctl2); pcie_retrain_link(dev, true); - return false; + return ret; } =20 pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta); @@ -129,10 +129,10 @@ bool pcie_failed_link_retrain(struct pci lnkctl2 |=3D lnkcap & PCI_EXP_LNKCAP_SLS; pcie_capability_write_word(dev, PCI_EXP_LNKCTL2, lnkctl2); =20 - ret =3D pcie_retrain_link(dev, false) =3D=3D 0; - if (!ret) { + ret =3D pcie_retrain_link(dev, false); + if (ret) { pci_info(dev, "retraining failed\n"); - return false; + return ret; } } =20