Skip to content

Commit 3c0ec89

Browse files
maciej-w-rozyckibjorn-helgaas
authored andcommitted
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/[email protected] Signed-off-by: Maciej W. Rozycki <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent fd6e6e3 commit 3c0ec89

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

drivers/pci/pcie/aspm.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,32 @@ static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist)
193193
link->clkpm_disable = blacklist ? 1 : 0;
194194
}
195195

196-
static bool pcie_retrain_link(struct pci_dev *pdev)
196+
/**
197+
* pcie_wait_for_link_status - Wait for link training end
198+
* @pdev: Device whose link to wait for.
199+
*
200+
* Return TRUE if successful, or FALSE if training has not completed
201+
* within LINK_RETRAIN_TIMEOUT jiffies.
202+
*/
203+
static bool pcie_wait_for_link_status(struct pci_dev *pdev)
197204
{
198205
unsigned long end_jiffies;
199-
u16 lnkctl;
200206
u16 lnksta;
201207

208+
end_jiffies = jiffies + LINK_RETRAIN_TIMEOUT;
209+
do {
210+
pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnksta);
211+
if (!(lnksta & PCI_EXP_LNKSTA_LT))
212+
break;
213+
msleep(1);
214+
} while (time_before(jiffies, end_jiffies));
215+
return !(lnksta & PCI_EXP_LNKSTA_LT);
216+
}
217+
218+
static bool pcie_retrain_link(struct pci_dev *pdev)
219+
{
220+
u16 lnkctl;
221+
202222
pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &lnkctl);
203223
lnkctl |= PCI_EXP_LNKCTL_RL;
204224
pcie_capability_write_word(pdev, PCI_EXP_LNKCTL, lnkctl);
@@ -212,15 +232,7 @@ static bool pcie_retrain_link(struct pci_dev *pdev)
212232
pcie_capability_write_word(pdev, PCI_EXP_LNKCTL, lnkctl);
213233
}
214234

215-
/* Wait for link training end. Break out after waiting for timeout */
216-
end_jiffies = jiffies + LINK_RETRAIN_TIMEOUT;
217-
do {
218-
pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnksta);
219-
if (!(lnksta & PCI_EXP_LNKSTA_LT))
220-
break;
221-
msleep(1);
222-
} while (time_before(jiffies, end_jiffies));
223-
return !(lnksta & PCI_EXP_LNKSTA_LT);
235+
return pcie_wait_for_link_status(pdev);
224236
}
225237

226238
/*

0 commit comments

Comments
 (0)