Commit 3c0ec896 authored by Maciej W. Rozycki's avatar Maciej W. Rozycki Committed by Bjorn Helgaas
Browse files

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: default avatarMaciej W. Rozycki <macro@orcam.me.uk>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
parent fd6e6e38
Loading
Loading
Loading
Loading
+23 −11
Original line number Diff line number Diff line
@@ -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);
}

/*