Skip to content

Commit 9c7f136

Browse files
ij-intelbjorn-helgaas
authored andcommitted
PCI/ASPM: Factor out pcie_wait_for_retrain()
Factor pcie_wait_for_retrain() out from pcie_retrain_link(). No functional change intended. [bhelgaas: split out from https://lore.kernel.org/r/[email protected]] Signed-off-by: Ilpo Järvinen <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent f5297a0 commit 9c7f136

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

drivers/pci/pcie/aspm.c

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

196+
static int pcie_wait_for_retrain(struct pci_dev *pdev)
197+
{
198+
unsigned long end_jiffies;
199+
u16 reg16;
200+
201+
/* Wait for Link Training to be cleared by hardware */
202+
end_jiffies = jiffies + LINK_RETRAIN_TIMEOUT;
203+
do {
204+
pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &reg16);
205+
if (!(reg16 & PCI_EXP_LNKSTA_LT))
206+
return 0;
207+
msleep(1);
208+
} while (time_before(jiffies, end_jiffies));
209+
210+
return -ETIMEDOUT;
211+
}
212+
196213
static int pcie_retrain_link(struct pcie_link_state *link)
197214
{
198215
struct pci_dev *parent = link->pdev;
199-
unsigned long end_jiffies;
200216
u16 reg16;
201217

202218
pcie_capability_read_word(parent, PCI_EXP_LNKCTL, &reg16);
@@ -212,17 +228,7 @@ static int pcie_retrain_link(struct pcie_link_state *link)
212228
pcie_capability_write_word(parent, PCI_EXP_LNKCTL, reg16);
213229
}
214230

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(parent, PCI_EXP_LNKSTA, &reg16);
219-
if (!(reg16 & PCI_EXP_LNKSTA_LT))
220-
break;
221-
msleep(1);
222-
} while (time_before(jiffies, end_jiffies));
223-
if (reg16 & PCI_EXP_LNKSTA_LT)
224-
return -ETIMEDOUT;
225-
return 0;
231+
return pcie_wait_for_retrain(parent);
226232
}
227233

228234
/*

0 commit comments

Comments
 (0)