linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5] PCI: dwc: Wait for link up only if link is started
@ 2024-01-12  9:30 Ajay Agarwal
  2024-01-18 18:15 ` Ajay Agarwal
                   ` (2 more replies)
  0 siblings, 3 replies; 40+ messages in thread
From: Ajay Agarwal @ 2024-01-12  9:30 UTC (permalink / raw)
  To: Jingoo Han, Johan Hovold, Manivannan Sadhasivam, Jon Hunter,
	Lorenzo Pieralisi, Krzysztof Wilczyński, Rob Herring,
	Bjorn Helgaas, Manu Gautam, Doug Zobel, William McVicker,
	Serge Semin, Robin Murphy
  Cc: linux-pci, Ajay Agarwal

In dw_pcie_host_init() regardless of whether the link has been
started or not, the code waits for the link to come up. Even in
cases where start_link() is not defined the code ends up spinning
in a loop for 1 second. Since in some systems dw_pcie_host_init()
gets called during probe, this one second loop for each pcie
interface instance ends up extending the boot time.

Wait for the link up in only if the start_link() is defined.

Signed-off-by: Ajay Agarwal <ajayagarwal@google.com>
---
v4 was applied, but then reverted. The reason being v4 added a
regression on some products which expect the link to not come up as a
part of the probe. Since v4 returned error from dw_pcie_wait_for_link
check, the probe function of these products started to fail.

Changelog since v4:
 - Do not return error from dw_pcie_wait_for_link check

 .../pci/controller/dwc/pcie-designware-host.c | 12 +++++++----
 drivers/pci/controller/dwc/pcie-designware.c  | 20 ++++++++++++-------
 drivers/pci/controller/dwc/pcie-designware.h  |  1 +
 3 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index 7991f0e179b2..e53132663d1d 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -487,14 +487,18 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp)
 	if (ret)
 		goto err_remove_edma;
 
-	if (!dw_pcie_link_up(pci)) {
+	if (dw_pcie_link_up(pci)) {
+		dw_pcie_print_link_status(pci);
+	} else {
 		ret = dw_pcie_start_link(pci);
 		if (ret)
 			goto err_remove_edma;
-	}
 
-	/* Ignore errors, the link may come up later */
-	dw_pcie_wait_for_link(pci);
+		if (pci->ops && pci->ops->start_link) {
+			/* Ignore errors, the link may come up later */
+			dw_pcie_wait_for_link(pci);
+		}
+	}
 
 	bridge->sysdata = pp;
 
diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c
index 250cf7f40b85..c067d2e960cf 100644
--- a/drivers/pci/controller/dwc/pcie-designware.c
+++ b/drivers/pci/controller/dwc/pcie-designware.c
@@ -645,9 +645,20 @@ void dw_pcie_disable_atu(struct dw_pcie *pci, u32 dir, int index)
 	dw_pcie_writel_atu(pci, dir, index, PCIE_ATU_REGION_CTRL2, 0);
 }
 
-int dw_pcie_wait_for_link(struct dw_pcie *pci)
+void dw_pcie_print_link_status(struct dw_pcie *pci)
 {
 	u32 offset, val;
+
+	offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP);
+	val = dw_pcie_readw_dbi(pci, offset + PCI_EXP_LNKSTA);
+
+	dev_info(pci->dev, "PCIe Gen.%u x%u link up\n",
+		 FIELD_GET(PCI_EXP_LNKSTA_CLS, val),
+		 FIELD_GET(PCI_EXP_LNKSTA_NLW, val));
+}
+
+int dw_pcie_wait_for_link(struct dw_pcie *pci)
+{
 	int retries;
 
 	/* Check if the link is up or not */
@@ -663,12 +674,7 @@ int dw_pcie_wait_for_link(struct dw_pcie *pci)
 		return -ETIMEDOUT;
 	}
 
-	offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP);
-	val = dw_pcie_readw_dbi(pci, offset + PCI_EXP_LNKSTA);
-
-	dev_info(pci->dev, "PCIe Gen.%u x%u link up\n",
-		 FIELD_GET(PCI_EXP_LNKSTA_CLS, val),
-		 FIELD_GET(PCI_EXP_LNKSTA_NLW, val));
+	dw_pcie_print_link_status(pci);
 
 	return 0;
 }
diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h
index 55ff76e3d384..164214a7219a 100644
--- a/drivers/pci/controller/dwc/pcie-designware.h
+++ b/drivers/pci/controller/dwc/pcie-designware.h
@@ -447,6 +447,7 @@ void dw_pcie_setup(struct dw_pcie *pci);
 void dw_pcie_iatu_detect(struct dw_pcie *pci);
 int dw_pcie_edma_detect(struct dw_pcie *pci);
 void dw_pcie_edma_remove(struct dw_pcie *pci);
+void dw_pcie_print_link_status(struct dw_pcie *pci);
 
 int dw_pcie_suspend_noirq(struct dw_pcie *pci);
 int dw_pcie_resume_noirq(struct dw_pcie *pci);
-- 
2.43.0.381.gb435a96ce8-goog


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

end of thread, other threads:[~2025-02-19 17:47 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-12  9:30 [PATCH v5] PCI: dwc: Wait for link up only if link is started Ajay Agarwal
2024-01-18 18:15 ` Ajay Agarwal
2024-01-19  7:52 ` Manivannan Sadhasivam
2024-01-19 17:59   ` Ajay Agarwal
2024-01-20 14:34     ` Manivannan Sadhasivam
2024-01-29  6:51       ` Ajay Agarwal
2024-01-29  7:10         ` Manivannan Sadhasivam
2024-01-29  8:04           ` Ajay Agarwal
2024-01-29  8:12             ` Manivannan Sadhasivam
2024-01-29 13:26               ` Ajay Agarwal
2024-01-30  6:45                 ` Manivannan Sadhasivam
2024-01-30  9:00                   ` Ajay Agarwal
2024-01-30 12:29                     ` Manivannan Sadhasivam
2024-01-30 17:18                       ` Ajay Agarwal
2024-01-30 18:36                         ` Manivannan Sadhasivam
2024-02-05 11:00                           ` Ajay Agarwal
2024-02-06 17:10                             ` Manivannan Sadhasivam
2024-02-14 22:02                               ` Bjorn Helgaas
2024-02-15 14:09                                 ` Manivannan Sadhasivam
2024-02-17  0:07                                   ` Bjorn Helgaas
2024-02-19 14:13                                     ` Manivannan Sadhasivam
2024-02-22  4:30                                   ` Ajay Agarwal
2024-02-28  2:55                                     ` Ajay Agarwal
2024-02-20 17:34                               ` Ajay Agarwal
2024-02-28 17:29                                 ` Manivannan Sadhasivam
2024-03-06 12:00                                   ` Ajay Agarwal
2024-03-10 13:51                                     ` Manivannan Sadhasivam
2025-02-14  9:15                                       ` Ajay Agarwal
2025-02-14  9:18                                         ` Johan Hovold
2025-02-14  9:42                                           ` Manivannan Sadhasivam
2025-02-14 10:02                                             ` Ajay Agarwal
2025-02-14 13:39                                               ` Manivannan Sadhasivam
2025-02-14 18:38                                                 ` William McVicker
2025-02-19 17:46                                                   ` Manivannan Sadhasivam
2024-01-31 23:48   ` Bjorn Helgaas
2024-02-01  3:14     ` Bjorn Helgaas
2024-02-01  7:32       ` Manivannan Sadhasivam
2024-02-01  8:37         ` Lei Chuan Hua
2024-01-19 20:42 ` Bjorn Helgaas
2024-01-24  9:24   ` Ajay Agarwal

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).