From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: "Maciej W. Rozycki" <macro@orcam.me.uk>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
Matthew W Carlis <mattc@purestorage.com>,
ALOK TIWARI <alok.a.tiwari@oracle.com>,
ashishk@purestorage.com, bamstadt@purestorage.com,
msaggi@purestorage.com, sconnor@purestorage.com,
Lukas Wunner <lukas@wunner.de>, Jiwei <jiwei.sun.bj@qq.com>,
guojinhui.liam@bytedance.com, ahuang12@lenovo.com,
sunjw10@lenovo.com, linux-pci@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] PCI: Always lift 2.5GT/s restriction in PCIe failed link retraining
Date: Mon, 1 Dec 2025 11:45:28 +0200 (EET) [thread overview]
Message-ID: <440e7c29-bee1-29f3-afa8-7b5905fd6cf2@linux.intel.com> (raw)
In-Reply-To: <alpine.DEB.2.21.2511290245460.36486@angie.orcam.me.uk>
On Mon, 1 Dec 2025, Maciej W. Rozycki wrote:
> Discard Vendor:Device ID matching in the PCIe failed link retraining
> quirk and ignore the link status for the removal of the 2.5GT/s speed
> clamp, whether applied by the quirk itself or the firmware earlier on.
> Revert to the original target link speed if this final link retraining
> has failed.
>
> This is so that link training noise in hot-plug scenarios does not make
> a link remain clamped to the 2.5GT/s speed where an event race has led
> the quirk to apply the speed clamp for one device, only to leave it in
> place for a subsequent device to be plugged in.
>
> Fixes: a89c82249c37 ("PCI: Work around PCIe link training failures")
> Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk>
> Cc: <stable@vger.kernel.org> # v6.5+
> ---
> drivers/pci/quirks.c | 50 ++++++++++++++++++--------------------------------
> 1 file changed, 18 insertions(+), 32 deletions(-)
>
> linux-pcie-failed-link-retrain-unclamp-always.diff
> Index: linux-macro/drivers/pci/quirks.c
> ===================================================================
> --- linux-macro.orig/drivers/pci/quirks.c
> +++ linux-macro/drivers/pci/quirks.c
> @@ -79,11 +79,10 @@ static bool pcie_lbms_seen(struct pci_de
> * Restrict the speed to 2.5GT/s then with the Target Link Speed field,
> * 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
> - * a higher speed. Also check for a similar 2.5GT/s speed restriction the
> - * firmware may have already arranged and lift it with ports that already
> - * report their data link being up.
> + * If this turns out successful, or where a 2.5GT/s speed restriction has
> + * been previously arranged by the firmware and the port reports its link
> + * already being up, lift the restriction, in a hope it is safe to do so,
> + * letting the devices negotiate a higher speed.
> *
> * 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
> @@ -94,52 +93,39 @@ static bool pcie_lbms_seen(struct pci_de
> */
> int pcie_failed_link_retrain(struct pci_dev *dev)
> {
> - static const struct pci_device_id ids[] = {
> - { PCI_VDEVICE(ASMEDIA, 0x2824) }, /* ASMedia ASM2824 */
> - {}
> - };
> - u16 lnksta, lnkctl2;
> + u16 lnksta, lnkctl2, oldlnkctl2;
> int ret = -ENOTTY;
> + u32 lnkcap;
>
> if (!pci_is_pcie(dev) || !pcie_downstream_port(dev) ||
> !pcie_cap_has_lnkctl2(dev) || !dev->link_active_reporting)
> return ret;
>
> pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta);
> + pcie_capability_read_word(dev, PCI_EXP_LNKCTL2, &oldlnkctl2);
> if (!(lnksta & PCI_EXP_LNKSTA_DLLLA) && pcie_lbms_seen(dev, lnksta)) {
> - u16 oldlnkctl2;
> -
> pci_info(dev, "broken device, retraining non-functional downstream link at 2.5GT/s\n");
>
> - pcie_capability_read_word(dev, PCI_EXP_LNKCTL2, &oldlnkctl2);
> ret = pcie_set_target_speed(dev, PCIE_SPEED_2_5GT, false);
> - if (ret) {
> - pci_info(dev, "retraining failed\n");
> - pcie_set_target_speed(dev, PCIE_LNKCTL2_TLS2SPEED(oldlnkctl2),
> - true);
> - return ret;
> - }
> -
> - pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta);
> + if (ret)
> + goto err;
> }
>
> pcie_capability_read_word(dev, PCI_EXP_LNKCTL2, &lnkctl2);
> -
> - if ((lnksta & PCI_EXP_LNKSTA_DLLLA) &&
> - (lnkctl2 & PCI_EXP_LNKCTL2_TLS) == PCI_EXP_LNKCTL2_TLS_2_5GT &&
> - pci_match_id(ids, dev)) {
> - u32 lnkcap;
> -
> + pcie_capability_read_dword(dev, PCI_EXP_LNKCAP, &lnkcap);
> + if ((lnkctl2 & PCI_EXP_LNKCTL2_TLS) == PCI_EXP_LNKCTL2_TLS_2_5GT &&
> + (lnkcap & PCI_EXP_LNKCAP_SLS) != PCI_EXP_LNKCAP_SLS_2_5GB) {
I'm trying to recall, if there was some particular reason why
->supported_speeds couldn't be used in this function. It would avoid the
need to read LinkCap at all.
> pci_info(dev, "removing 2.5GT/s downstream link speed restriction\n");
> - pcie_capability_read_dword(dev, PCI_EXP_LNKCAP, &lnkcap);
> ret = pcie_set_target_speed(dev, PCIE_LNKCAP_SLS2SPEED(lnkcap), false);
> - if (ret) {
> - pci_info(dev, "retraining failed\n");
> - return ret;
> - }
> + if (ret)
> + goto err;
> }
>
> return ret;
return 0;
> +err:
> + pci_info(dev, "retraining failed\n");
> + pcie_set_target_speed(dev, PCIE_LNKCTL2_TLS2SPEED(oldlnkctl2), true);
> + return ret;
> }
>
> static ktime_t fixup_debug_start(struct pci_dev *dev,
>
--
i.
next prev parent reply other threads:[~2025-12-01 9:45 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-01 3:52 [PATCH] PCI: Always lift 2.5GT/s restriction in PCIe failed link retraining Maciej W. Rozycki
2025-12-01 9:45 ` Ilpo Järvinen [this message]
2025-12-01 13:55 ` Maciej W. Rozycki
2025-12-01 16:48 ` Ilpo Järvinen
2025-12-08 19:24 ` Maciej W. Rozycki
2025-12-02 13:49 ` [External] : " ALOK TIWARI
2025-12-02 16:07 ` Ilpo Järvinen
2025-12-03 19:01 ` Maciej W. Rozycki
2025-12-08 19:25 ` Maciej W. Rozycki
2025-12-04 1:40 ` [PATCH 2/2] PCI: Fix the PCIe bridge decreasing to Gen 1 during hotplug testing Matthew W Carlis
2025-12-04 23:43 ` Maciej W. Rozycki
2025-12-04 18:30 ` [PATCH] PCI: Always lift 2.5GT/s restriction in PCIe failed link retraining Matthew W Carlis
2025-12-08 19:25 ` Maciej W. Rozycki
-- strict thread matches above, loose matches on Subject: below --
2026-02-19 21:26 [PATCH v2 0/3] " Bjorn Helgaas
2026-02-19 22:09 ` [PATCH] " Matthew W Carlis
2026-02-19 22:53 ` Bjorn Helgaas
2026-02-20 12:03 ` Maciej W. Rozycki
2026-02-23 17:36 ` Bjorn Helgaas
2026-02-23 22:49 ` Matthew W Carlis
2026-02-23 23:14 ` Maciej W. Rozycki
2026-02-25 1:41 ` Matthew W Carlis
2026-02-26 22:02 ` Maciej W. Rozycki
2026-03-26 19:52 ` ALOK TIWARI
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=440e7c29-bee1-29f3-afa8-7b5905fd6cf2@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=ahuang12@lenovo.com \
--cc=alok.a.tiwari@oracle.com \
--cc=ashishk@purestorage.com \
--cc=bamstadt@purestorage.com \
--cc=bhelgaas@google.com \
--cc=guojinhui.liam@bytedance.com \
--cc=jiwei.sun.bj@qq.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=macro@orcam.me.uk \
--cc=mattc@purestorage.com \
--cc=msaggi@purestorage.com \
--cc=sconnor@purestorage.com \
--cc=sunjw10@lenovo.com \
/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