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/20230502083923.34562-1-ilpo.jarvinen@linux.intel.com]
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
This commit is contained in:
Ilpo Järvinen 2023-06-20 14:49:33 -05:00 коммит произвёл Bjorn Helgaas
Родитель f5297a01ee
Коммит 9c7f136433
1 изменённых файлов: 18 добавлений и 12 удалений

Просмотреть файл

@ -193,10 +193,26 @@ static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist)
link->clkpm_disable = blacklist ? 1 : 0; link->clkpm_disable = blacklist ? 1 : 0;
} }
static int pcie_wait_for_retrain(struct pci_dev *pdev)
{
unsigned long end_jiffies;
u16 reg16;
/* Wait for Link Training to be cleared by hardware */
end_jiffies = jiffies + LINK_RETRAIN_TIMEOUT;
do {
pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &reg16);
if (!(reg16 & PCI_EXP_LNKSTA_LT))
return 0;
msleep(1);
} while (time_before(jiffies, end_jiffies));
return -ETIMEDOUT;
}
static int pcie_retrain_link(struct pcie_link_state *link) static int pcie_retrain_link(struct pcie_link_state *link)
{ {
struct pci_dev *parent = link->pdev; struct pci_dev *parent = link->pdev;
unsigned long end_jiffies;
u16 reg16; u16 reg16;
pcie_capability_read_word(parent, PCI_EXP_LNKCTL, &reg16); pcie_capability_read_word(parent, PCI_EXP_LNKCTL, &reg16);
@ -212,17 +228,7 @@ static int pcie_retrain_link(struct pcie_link_state *link)
pcie_capability_write_word(parent, PCI_EXP_LNKCTL, reg16); pcie_capability_write_word(parent, PCI_EXP_LNKCTL, reg16);
} }
/* Wait for link training end. Break out after waiting for timeout */ return pcie_wait_for_retrain(parent);
end_jiffies = jiffies + LINK_RETRAIN_TIMEOUT;
do {
pcie_capability_read_word(parent, PCI_EXP_LNKSTA, &reg16);
if (!(reg16 & PCI_EXP_LNKSTA_LT))
break;
msleep(1);
} while (time_before(jiffies, end_jiffies));
if (reg16 & PCI_EXP_LNKSTA_LT)
return -ETIMEDOUT;
return 0;
} }
/* /*