Skip to content

Commit e7e3975

Browse files
ij-intelbjorn-helgaas
authored andcommitted
PCI/ASPM: Avoid link retraining race
PCIe r6.0.1, sec 7.5.3.7, recommends setting the link control parameters, then waiting for the Link Training bit to be clear before setting the Retrain Link bit. This avoids a race where the LTSSM may not use the updated parameters if it is already in the midst of link training because of other normal link activity. Wait for the Link Training bit to be clear before toggling the Retrain Link bit to ensure that the LTSSM uses the updated link control parameters. [bhelgaas: commit log, return 0 (success)/-ETIMEDOUT instead of bool for both pcie_wait_for_retrain() and the existing pcie_retrain_link()] Suggested-by: Lukas Wunner <[email protected]> Fixes: 7d715a6 ("PCI: add PCI Express ASPM support") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ilpo Järvinen <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Lukas Wunner <[email protected]> Cc: [email protected]
1 parent 9c7f136 commit e7e3975

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

drivers/pci/pcie/aspm.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,19 @@ static int pcie_wait_for_retrain(struct pci_dev *pdev)
213213
static int pcie_retrain_link(struct pcie_link_state *link)
214214
{
215215
struct pci_dev *parent = link->pdev;
216+
int rc;
216217
u16 reg16;
217218

219+
/*
220+
* Ensure the updated LNKCTL parameters are used during link
221+
* training by checking that there is no ongoing link training to
222+
* avoid LTSSM race as recommended in Implementation Note at the
223+
* end of PCIe r6.0.1 sec 7.5.3.7.
224+
*/
225+
rc = pcie_wait_for_retrain(parent);
226+
if (rc)
227+
return rc;
228+
218229
pcie_capability_read_word(parent, PCI_EXP_LNKCTL, &reg16);
219230
reg16 |= PCI_EXP_LNKCTL_RL;
220231
pcie_capability_write_word(parent, PCI_EXP_LNKCTL, reg16);

0 commit comments

Comments
 (0)