Skip to content

Commit 64dbb2d

Browse files
committed
PCI/ASPM: Disable L1 before configuring L1 Substates
Per PCIe r6.1, sec 5.5.4, L1 must be disabled while setting ASPM L1 PM Substates enable bits. Previously this was enforced by clearing PCI_EXP_LNKCTL_ASPMC before calling pci_restore_aspm_l1ss_state(). Move the L1 (and L0s, although that doesn't seem required) disable into pci_restore_aspm_l1ss_state() itself so it's closer to the code that depends on it. Link: https://lore.kernel.org/r/20240223213733.GA115410@bhelgaas Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent c198faf commit 64dbb2d

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

drivers/pci/pci.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,13 +1633,14 @@ static void pci_restore_pcie_state(struct pci_dev *dev)
16331633
{
16341634
int i = 0;
16351635
struct pci_cap_saved_state *save_state;
1636-
u16 *cap, lnkctl;
1636+
u16 *cap;
16371637

16381638
/*
16391639
* Restore max latencies (in the LTR capability) before enabling
16401640
* LTR itself in PCI_EXP_DEVCTL2.
16411641
*/
16421642
pci_restore_ltr_state(dev);
1643+
pci_restore_aspm_l1ss_state(dev);
16431644

16441645
save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
16451646
if (!save_state)
@@ -1654,23 +1655,12 @@ static void pci_restore_pcie_state(struct pci_dev *dev)
16541655

16551656
cap = (u16 *)&save_state->cap.data[0];
16561657
pcie_capability_write_word(dev, PCI_EXP_DEVCTL, cap[i++]);
1657-
1658-
/* Restore LNKCTL register with ASPM control field clear */
1659-
lnkctl = cap[i++];
1660-
pcie_capability_write_word(dev, PCI_EXP_LNKCTL,
1661-
lnkctl & ~PCI_EXP_LNKCTL_ASPMC);
1662-
1658+
pcie_capability_write_word(dev, PCI_EXP_LNKCTL, cap[i++]);
16631659
pcie_capability_write_word(dev, PCI_EXP_SLTCTL, cap[i++]);
16641660
pcie_capability_write_word(dev, PCI_EXP_RTCTL, cap[i++]);
16651661
pcie_capability_write_word(dev, PCI_EXP_DEVCTL2, cap[i++]);
16661662
pcie_capability_write_word(dev, PCI_EXP_LNKCTL2, cap[i++]);
16671663
pcie_capability_write_word(dev, PCI_EXP_SLTCTL2, cap[i++]);
1668-
1669-
pci_restore_aspm_l1ss_state(dev);
1670-
1671-
/* Restore ASPM control after restoring L1SS state */
1672-
pcie_capability_set_word(dev, PCI_EXP_LNKCTL,
1673-
lnkctl & PCI_EXP_LNKCTL_ASPMC);
16741664
}
16751665

16761666
static int pci_save_pcix_state(struct pci_dev *dev)

drivers/pci/pcie/aspm.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ void pci_restore_aspm_l1ss_state(struct pci_dev *pdev)
105105
struct pci_dev *parent = pdev->bus->self;
106106
u32 *cap, pl_ctl1, pl_ctl2, pl_l1_2_enable;
107107
u32 cl_ctl1, cl_ctl2, cl_l1_2_enable;
108+
u16 clnkctl, plnkctl;
108109

109110
/*
110111
* In case BIOS enabled L1.2 when resuming, we need to disable it first
@@ -129,6 +130,17 @@ void pci_restore_aspm_l1ss_state(struct pci_dev *pdev)
129130
pl_ctl2 = *cap++;
130131
pl_ctl1 = *cap;
131132

133+
/* Make sure L0s/L1 are disabled before updating L1SS config */
134+
pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &clnkctl);
135+
pcie_capability_read_word(parent, PCI_EXP_LNKCTL, &plnkctl);
136+
if (FIELD_GET(PCI_EXP_LNKCTL_ASPMC, clnkctl) ||
137+
FIELD_GET(PCI_EXP_LNKCTL_ASPMC, plnkctl)) {
138+
pcie_capability_write_word(pdev, PCI_EXP_LNKCTL,
139+
clnkctl & ~PCI_EXP_LNKCTL_ASPMC);
140+
pcie_capability_write_word(parent, PCI_EXP_LNKCTL,
141+
plnkctl & ~PCI_EXP_LNKCTL_ASPMC);
142+
}
143+
132144
/*
133145
* Disable L1.2 on this downstream endpoint device first, followed
134146
* by the upstream
@@ -161,6 +173,13 @@ void pci_restore_aspm_l1ss_state(struct pci_dev *pdev)
161173
pci_write_config_dword(pdev, pdev->l1ss + PCI_L1SS_CTL1,
162174
cl_ctl1 | cl_l1_2_enable);
163175
}
176+
177+
/* Restore L0s/L1 if they were enabled */
178+
if (FIELD_GET(PCI_EXP_LNKCTL_ASPMC, clnkctl) ||
179+
FIELD_GET(PCI_EXP_LNKCTL_ASPMC, plnkctl)) {
180+
pcie_capability_write_word(parent, PCI_EXP_LNKCTL, clnkctl);
181+
pcie_capability_write_word(pdev, PCI_EXP_LNKCTL, plnkctl);
182+
}
164183
}
165184

166185
#ifdef CONFIG_PCIEASPM

0 commit comments

Comments
 (0)