Skip to content

Commit 4ff116d

Browse files
Vidya Sagarbjorn-helgaas
authored andcommitted
PCI/ASPM: Save L1 PM Substates Capability for suspend/resume
Previously the L1 PM Substates Control Registers (CTL1 and CTL2) weren't saved and restored during suspend/resume leading to the L1 PM Substates configuration being lost post-resume. Save the L1 PM Substates Control Registers so that the configuration is retained post-resume. [bhelgaas: drop pci_is_pcie() testing; we can rely on pci_configure_ltr() having already done that] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vidya Sagar <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent 5e85eba commit 4ff116d

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

drivers/pci/pci.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,6 +1663,7 @@ int pci_save_state(struct pci_dev *dev)
16631663
return i;
16641664

16651665
pci_save_ltr_state(dev);
1666+
pci_save_aspm_l1ss_state(dev);
16661667
pci_save_dpc_state(dev);
16671668
pci_save_aer_state(dev);
16681669
pci_save_ptm_state(dev);
@@ -1769,6 +1770,7 @@ void pci_restore_state(struct pci_dev *dev)
17691770
* LTR itself (in the PCIe capability).
17701771
*/
17711772
pci_restore_ltr_state(dev);
1773+
pci_restore_aspm_l1ss_state(dev);
17721774

17731775
pci_restore_pcie_state(dev);
17741776
pci_restore_pasid_state(dev);
@@ -3485,6 +3487,11 @@ void pci_allocate_cap_save_buffers(struct pci_dev *dev)
34853487
if (error)
34863488
pci_err(dev, "unable to allocate suspend buffer for LTR\n");
34873489

3490+
error = pci_add_ext_cap_save_buffer(dev, PCI_EXT_CAP_ID_L1SS,
3491+
2 * sizeof(u32));
3492+
if (error)
3493+
pci_err(dev, "unable to allocate suspend buffer for ASPM-L1SS\n");
3494+
34883495
pci_allocate_vc_save_buffers(dev);
34893496
}
34903497

drivers/pci/pci.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,10 +561,14 @@ bool pcie_wait_for_link(struct pci_dev *pdev, bool active);
561561
void pcie_aspm_init_link_state(struct pci_dev *pdev);
562562
void pcie_aspm_exit_link_state(struct pci_dev *pdev);
563563
void pcie_aspm_powersave_config_link(struct pci_dev *pdev);
564+
void pci_save_aspm_l1ss_state(struct pci_dev *dev);
565+
void pci_restore_aspm_l1ss_state(struct pci_dev *dev);
564566
#else
565567
static inline void pcie_aspm_init_link_state(struct pci_dev *pdev) { }
566568
static inline void pcie_aspm_exit_link_state(struct pci_dev *pdev) { }
567569
static inline void pcie_aspm_powersave_config_link(struct pci_dev *pdev) { }
570+
static inline void pci_save_aspm_l1ss_state(struct pci_dev *dev) { }
571+
static inline void pci_restore_aspm_l1ss_state(struct pci_dev *dev) { }
568572
#endif
569573

570574
#ifdef CONFIG_PCIE_ECRC

drivers/pci/pcie/aspm.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,43 @@ static void pcie_config_aspm_l1ss(struct pcie_link_state *link, u32 state)
732732
PCI_L1SS_CTL1_L1SS_MASK, val);
733733
}
734734

735+
void pci_save_aspm_l1ss_state(struct pci_dev *dev)
736+
{
737+
struct pci_cap_saved_state *save_state;
738+
u16 l1ss = dev->l1ss;
739+
u32 *cap;
740+
741+
if (!l1ss)
742+
return;
743+
744+
save_state = pci_find_saved_ext_cap(dev, PCI_EXT_CAP_ID_L1SS);
745+
if (!save_state)
746+
return;
747+
748+
cap = (u32 *)&save_state->cap.data[0];
749+
pci_read_config_dword(dev, l1ss + PCI_L1SS_CTL2, cap++);
750+
pci_read_config_dword(dev, l1ss + PCI_L1SS_CTL1, cap++);
751+
}
752+
753+
void pci_restore_aspm_l1ss_state(struct pci_dev *dev)
754+
{
755+
struct pci_cap_saved_state *save_state;
756+
u32 *cap, ctl1, ctl2;
757+
u16 l1ss = dev->l1ss;
758+
759+
if (!l1ss)
760+
return;
761+
762+
save_state = pci_find_saved_ext_cap(dev, PCI_EXT_CAP_ID_L1SS);
763+
if (!save_state)
764+
return;
765+
766+
cap = (u32 *)&save_state->cap.data[0];
767+
ctl2 = *cap++;
768+
ctl1 = *cap;
769+
aspm_program_l1ss(dev, ctl1, ctl2);
770+
}
771+
735772
static void pcie_config_aspm_dev(struct pci_dev *pdev, u32 val)
736773
{
737774
pcie_capability_clear_and_set_word(pdev, PCI_EXP_LNKCTL,

0 commit comments

Comments
 (0)