aboutsummaryrefslogtreecommitdiff
path: root/drivers/pci/pcie
diff options
context:
space:
mode:
authorMaciej W. Rozycki <macro@orcam.me.uk>2023-06-11 18:19:49 +0100
committerBjorn Helgaas <bhelgaas@google.com>2023-06-20 10:58:53 -0500
commit3c0ec896a4b42bc4751c71cac5996d23d3b648ae (patch)
treecc21839e71c988e194a8629cbdda021eeed69fd4 /drivers/pci/pcie
parentfd6e6e38ebe5db99b8eeab0abef8cc930301a677 (diff)
PCI/ASPM: Factor out waiting for link training to complete
Move code polling for the Link Training bit to clear into a function of its own. [bhelgaas: reorder to clean up before exposing to PCI core] Link: https://lore.kernel.org/r/alpine.DEB.2.21.2306111605060.64925@angie.orcam.me.uk Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Diffstat (limited to 'drivers/pci/pcie')
-rw-r--r--drivers/pci/pcie/aspm.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index e2cfff3a0a2e..eaaacf24e16c 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -193,12 +193,32 @@ static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist)
link->clkpm_disable = blacklist ? 1 : 0;
}
-static bool pcie_retrain_link(struct pci_dev *pdev)
+/**
+ * pcie_wait_for_link_status - Wait for link training end
+ * @pdev: Device whose link to wait for.
+ *
+ * Return TRUE if successful, or FALSE if training has not completed
+ * within LINK_RETRAIN_TIMEOUT jiffies.
+ */
+static bool pcie_wait_for_link_status(struct pci_dev *pdev)
{
unsigned long end_jiffies;
- u16 lnkctl;
u16 lnksta;
+ end_jiffies = jiffies + LINK_RETRAIN_TIMEOUT;
+ do {
+ pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnksta);
+ if (!(lnksta & PCI_EXP_LNKSTA_LT))
+ break;
+ msleep(1);
+ } while (time_before(jiffies, end_jiffies));
+ return !(lnksta & PCI_EXP_LNKSTA_LT);
+}
+
+static bool pcie_retrain_link(struct pci_dev *pdev)
+{
+ u16 lnkctl;
+
pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &lnkctl);
lnkctl |= PCI_EXP_LNKCTL_RL;
pcie_capability_write_word(pdev, PCI_EXP_LNKCTL, lnkctl);
@@ -212,15 +232,7 @@ static bool pcie_retrain_link(struct pci_dev *pdev)
pcie_capability_write_word(pdev, PCI_EXP_LNKCTL, lnkctl);
}
- /* Wait for link training end. Break out after waiting for timeout */
- end_jiffies = jiffies + LINK_RETRAIN_TIMEOUT;
- do {
- pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnksta);
- if (!(lnksta & PCI_EXP_LNKSTA_LT))
- break;
- msleep(1);
- } while (time_before(jiffies, end_jiffies));
- return !(lnksta & PCI_EXP_LNKSTA_LT);
+ return pcie_wait_for_link_status(pdev);
}
/*