linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] PCI: Cleanup link activation wait logic
@ 2024-02-02 13:41 Ilpo Järvinen
  2024-02-02 14:22 ` Maciej W. Rozycki
  0 siblings, 1 reply; 9+ messages in thread
From: Ilpo Järvinen @ 2024-02-02 13:41 UTC (permalink / raw)
  To: Maciej W . Rozycki, Bjorn Helgaas, linux-pci, linux-kernel
  Cc: Mika Westerberg, Ilpo Järvinen

The combination of logic in pcie_failed_link_retrain() and
pcie_wait_for_link_delay() is hard to track and does not really make
sense in some cases.

To cleanup the logic mess:

1. Change pcie_failed_link_retrain() to return true only if link was
   retrained successfully due to the Target Speed quirk. If there is no
   LBMS set, return false instead of true because no retraining was
   even attempted. This seems correct considering expectations of both
   callers of pcie_failed_link_retrain().

2. Handle link-was-not-retrained-successfully return (false) from
   pcie_failed_link_retrain() properly in pcie_wait_for_link_delay() by
   directly returning false.

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/pci/pci.c    |  4 +---
 drivers/pci/quirks.c | 25 +++++++++++++------------
 2 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index d8f11a078924..ca4159472a72 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5068,9 +5068,7 @@ static bool pcie_wait_for_link_delay(struct pci_dev *pdev, bool active,
 		msleep(20);
 	rc = pcie_wait_for_link_status(pdev, false, active);
 	if (active) {
-		if (rc)
-			rc = pcie_failed_link_retrain(pdev);
-		if (rc)
+		if (rc < 0 && !pcie_failed_link_retrain(pdev))
 			return false;
 
 		msleep(delay);
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index efb2ddbff115..e729157be95d 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -88,24 +88,25 @@ bool pcie_failed_link_retrain(struct pci_dev *dev)
 	    !pcie_cap_has_lnkctl2(dev) || !dev->link_active_reporting)
 		return false;
 
-	pcie_capability_read_word(dev, PCI_EXP_LNKCTL2, &lnkctl2);
 	pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta);
-	if ((lnksta & (PCI_EXP_LNKSTA_LBMS | PCI_EXP_LNKSTA_DLLLA)) ==
-	    PCI_EXP_LNKSTA_LBMS) {
-		pci_info(dev, "broken device, retraining non-functional downstream link at 2.5GT/s\n");
+	if ((lnksta & (PCI_EXP_LNKSTA_LBMS | PCI_EXP_LNKSTA_DLLLA)) !=
+	    PCI_EXP_LNKSTA_LBMS)
+		return false;
 
-		lnkctl2 &= ~PCI_EXP_LNKCTL2_TLS;
-		lnkctl2 |= PCI_EXP_LNKCTL2_TLS_2_5GT;
-		pcie_capability_write_word(dev, PCI_EXP_LNKCTL2, lnkctl2);
+	pci_info(dev, "broken device, retraining non-functional downstream link at 2.5GT/s\n");
 
-		if (pcie_retrain_link(dev, false)) {
-			pci_info(dev, "retraining failed\n");
-			return false;
-		}
+	pcie_capability_read_word(dev, PCI_EXP_LNKCTL2, &lnkctl2);
+	lnkctl2 &= ~PCI_EXP_LNKCTL2_TLS;
+	lnkctl2 |= PCI_EXP_LNKCTL2_TLS_2_5GT;
+	pcie_capability_write_word(dev, PCI_EXP_LNKCTL2, lnkctl2);
 
-		pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta);
+	if (pcie_retrain_link(dev, false)) {
+		pci_info(dev, "retraining failed\n");
+		return false;
 	}
 
+	pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta);
+
 	if ((lnksta & PCI_EXP_LNKSTA_DLLLA) &&
 	    (lnkctl2 & PCI_EXP_LNKCTL2_TLS) == PCI_EXP_LNKCTL2_TLS_2_5GT &&
 	    pci_match_id(ids, dev)) {
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-02-26 12:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-02 13:41 [PATCH 1/1] PCI: Cleanup link activation wait logic Ilpo Järvinen
2024-02-02 14:22 ` Maciej W. Rozycki
2024-02-02 14:31   ` Ilpo Järvinen
2024-02-10  1:50     ` Maciej W. Rozycki
2024-02-26 12:53       ` Maciej W. Rozycki
2024-02-16 13:28   ` Ilpo Järvinen
2024-02-16 13:58     ` Maciej W. Rozycki
2024-02-16 14:23       ` Ilpo Järvinen
2024-02-26 12:43         ` Maciej W. Rozycki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).