linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: "Maciej W . Rozycki" <macro@orcam.me.uk>,
	Bjorn Helgaas <bhelgaas@google.com>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Mika Westerberg" <mika.westerberg@linux.intel.com>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Subject: [PATCH 1/1] PCI: Cleanup link activation wait logic
Date: Fri,  2 Feb 2024 15:41:08 +0200	[thread overview]
Message-ID: <20240202134108.4096-1-ilpo.jarvinen@linux.intel.com> (raw)

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


             reply	other threads:[~2024-02-02 13:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-02 13:41 Ilpo Järvinen [this message]
2024-02-02 14:22 ` [PATCH 1/1] PCI: Cleanup link activation wait logic 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

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=20240202134108.4096-1-ilpo.jarvinen@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=bhelgaas@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=macro@orcam.me.uk \
    --cc=mika.westerberg@linux.intel.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;
as well as URLs for NNTP newsgroup(s).