Skip to content
/ linux Public
forked from torvalds/linux

Commit

Permalink
PCI: Correct error reporting with PCIe failed link retraining
Browse files Browse the repository at this point in the history
Only return successful completion status from pcie_failed_link_retrain() if
retraining has actually been done, preventing excessive delays from being
triggered at call sites in a hope that communication will finally be
established with the downstream device where in fact nothing has been done
about the link in question that would justify such a hope.

Fixes: a89c822 ("PCI: Work around PCIe link training failures")
Link: https://lore.kernel.org/r/[email protected]
Reported-by: Ilpo Järvinen <[email protected]>
Link: https://lore.kernel.org/r/[email protected]/
Signed-off-by: Maciej W. Rozycki <[email protected]>
Signed-off-by: Bjorn Helgaas <[email protected]>
Signed-off-by: Krzysztof Wilczyński <[email protected]>
Reviewed-by: Ilpo Järvinen <[email protected]>
Cc: <[email protected]> # v6.5+
  • Loading branch information
maciej-w-rozycki authored and kwilczynski committed Sep 9, 2024
1 parent f68dea1 commit 712e49c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions drivers/pci/quirks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 FALSE.
* 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)
{
Expand All @@ -87,6 +88,7 @@ bool pcie_failed_link_retrain(struct pci_dev *dev)
{}
};
u16 lnksta, lnkctl2;
bool ret = false;

if (!pci_is_pcie(dev) || !pcie_downstream_port(dev) ||
!pcie_cap_has_lnkctl2(dev) || !dev->link_active_reporting)
Expand All @@ -104,7 +106,8 @@ bool pcie_failed_link_retrain(struct pci_dev *dev)
lnkctl2 |= PCI_EXP_LNKCTL2_TLS_2_5GT;
pcie_capability_write_word(dev, PCI_EXP_LNKCTL2, lnkctl2);

if (pcie_retrain_link(dev, false)) {
ret = pcie_retrain_link(dev, false) == 0;
if (!ret) {
pci_info(dev, "retraining failed\n");
pcie_capability_write_word(dev, PCI_EXP_LNKCTL2,
oldlnkctl2);
Expand All @@ -126,13 +129,14 @@ bool pcie_failed_link_retrain(struct pci_dev *dev)
lnkctl2 |= lnkcap & PCI_EXP_LNKCAP_SLS;
pcie_capability_write_word(dev, PCI_EXP_LNKCTL2, lnkctl2);

if (pcie_retrain_link(dev, false)) {
ret = pcie_retrain_link(dev, false) == 0;
if (!ret) {
pci_info(dev, "retraining failed\n");
return false;
}
}

return true;
return ret;
}

static ktime_t fixup_debug_start(struct pci_dev *dev,
Expand Down

0 comments on commit 712e49c

Please sign in to comment.