Skip to content

Commit 9e2a031

Browse files
committed
PCI/ASPM: Factor out L1 PM Substates configuration
Move L1 PM Substates configuration from pcie_aspm_cap_init() to a new aspm_l1ss_init() function. No functional change intended. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Kuppuswamy Sathyanarayanan <[email protected]>
1 parent 4ff116d commit 9e2a031

File tree

1 file changed

+55
-48
lines changed

1 file changed

+55
-48
lines changed

drivers/pci/pcie/aspm.c

Lines changed: 55 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -554,13 +554,65 @@ static void aspm_calc_l1ss_info(struct pcie_link_state *link,
554554
aspm_program_l1ss(child, cctl1, ctl2);
555555
}
556556

557+
static void aspm_l1ss_init(struct pcie_link_state *link)
558+
{
559+
struct pci_dev *child = link->downstream, *parent = link->pdev;
560+
u32 parent_l1ss_cap, child_l1ss_cap;
561+
u32 parent_l1ss_ctl1 = 0, child_l1ss_ctl1 = 0;
562+
563+
/* Setup L1 substate */
564+
pci_read_config_dword(parent, parent->l1ss + PCI_L1SS_CAP,
565+
&parent_l1ss_cap);
566+
pci_read_config_dword(child, child->l1ss + PCI_L1SS_CAP,
567+
&child_l1ss_cap);
568+
569+
if (!(parent_l1ss_cap & PCI_L1SS_CAP_L1_PM_SS))
570+
parent_l1ss_cap = 0;
571+
if (!(child_l1ss_cap & PCI_L1SS_CAP_L1_PM_SS))
572+
child_l1ss_cap = 0;
573+
574+
/*
575+
* If we don't have LTR for the entire path from the Root Complex
576+
* to this device, we can't use ASPM L1.2 because it relies on the
577+
* LTR_L1.2_THRESHOLD. See PCIe r4.0, secs 5.5.4, 6.18.
578+
*/
579+
if (!child->ltr_path)
580+
child_l1ss_cap &= ~PCI_L1SS_CAP_ASPM_L1_2;
581+
582+
if (parent_l1ss_cap & child_l1ss_cap & PCI_L1SS_CAP_ASPM_L1_1)
583+
link->aspm_support |= ASPM_STATE_L1_1;
584+
if (parent_l1ss_cap & child_l1ss_cap & PCI_L1SS_CAP_ASPM_L1_2)
585+
link->aspm_support |= ASPM_STATE_L1_2;
586+
if (parent_l1ss_cap & child_l1ss_cap & PCI_L1SS_CAP_PCIPM_L1_1)
587+
link->aspm_support |= ASPM_STATE_L1_1_PCIPM;
588+
if (parent_l1ss_cap & child_l1ss_cap & PCI_L1SS_CAP_PCIPM_L1_2)
589+
link->aspm_support |= ASPM_STATE_L1_2_PCIPM;
590+
591+
if (parent_l1ss_cap)
592+
pci_read_config_dword(parent, parent->l1ss + PCI_L1SS_CTL1,
593+
&parent_l1ss_ctl1);
594+
if (child_l1ss_cap)
595+
pci_read_config_dword(child, child->l1ss + PCI_L1SS_CTL1,
596+
&child_l1ss_ctl1);
597+
598+
if (parent_l1ss_ctl1 & child_l1ss_ctl1 & PCI_L1SS_CTL1_ASPM_L1_1)
599+
link->aspm_enabled |= ASPM_STATE_L1_1;
600+
if (parent_l1ss_ctl1 & child_l1ss_ctl1 & PCI_L1SS_CTL1_ASPM_L1_2)
601+
link->aspm_enabled |= ASPM_STATE_L1_2;
602+
if (parent_l1ss_ctl1 & child_l1ss_ctl1 & PCI_L1SS_CTL1_PCIPM_L1_1)
603+
link->aspm_enabled |= ASPM_STATE_L1_1_PCIPM;
604+
if (parent_l1ss_ctl1 & child_l1ss_ctl1 & PCI_L1SS_CTL1_PCIPM_L1_2)
605+
link->aspm_enabled |= ASPM_STATE_L1_2_PCIPM;
606+
607+
if (link->aspm_support & ASPM_STATE_L1SS)
608+
aspm_calc_l1ss_info(link, parent_l1ss_cap, child_l1ss_cap);
609+
}
610+
557611
static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)
558612
{
559613
struct pci_dev *child = link->downstream, *parent = link->pdev;
560614
u32 parent_lnkcap, child_lnkcap;
561615
u16 parent_lnkctl, child_lnkctl;
562-
u32 parent_l1ss_cap, child_l1ss_cap;
563-
u32 parent_l1ss_ctl1 = 0, child_l1ss_ctl1 = 0;
564616
struct pci_bus *linkbus = parent->subordinate;
565617

566618
if (blacklist) {
@@ -615,52 +667,7 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)
615667
if (parent_lnkctl & child_lnkctl & PCI_EXP_LNKCTL_ASPM_L1)
616668
link->aspm_enabled |= ASPM_STATE_L1;
617669

618-
/* Setup L1 substate */
619-
pci_read_config_dword(parent, parent->l1ss + PCI_L1SS_CAP,
620-
&parent_l1ss_cap);
621-
pci_read_config_dword(child, child->l1ss + PCI_L1SS_CAP,
622-
&child_l1ss_cap);
623-
624-
if (!(parent_l1ss_cap & PCI_L1SS_CAP_L1_PM_SS))
625-
parent_l1ss_cap = 0;
626-
if (!(child_l1ss_cap & PCI_L1SS_CAP_L1_PM_SS))
627-
child_l1ss_cap = 0;
628-
629-
/*
630-
* If we don't have LTR for the entire path from the Root Complex
631-
* to this device, we can't use ASPM L1.2 because it relies on the
632-
* LTR_L1.2_THRESHOLD. See PCIe r4.0, secs 5.5.4, 6.18.
633-
*/
634-
if (!child->ltr_path)
635-
child_l1ss_cap &= ~PCI_L1SS_CAP_ASPM_L1_2;
636-
637-
if (parent_l1ss_cap & child_l1ss_cap & PCI_L1SS_CAP_ASPM_L1_1)
638-
link->aspm_support |= ASPM_STATE_L1_1;
639-
if (parent_l1ss_cap & child_l1ss_cap & PCI_L1SS_CAP_ASPM_L1_2)
640-
link->aspm_support |= ASPM_STATE_L1_2;
641-
if (parent_l1ss_cap & child_l1ss_cap & PCI_L1SS_CAP_PCIPM_L1_1)
642-
link->aspm_support |= ASPM_STATE_L1_1_PCIPM;
643-
if (parent_l1ss_cap & child_l1ss_cap & PCI_L1SS_CAP_PCIPM_L1_2)
644-
link->aspm_support |= ASPM_STATE_L1_2_PCIPM;
645-
646-
if (parent_l1ss_cap)
647-
pci_read_config_dword(parent, parent->l1ss + PCI_L1SS_CTL1,
648-
&parent_l1ss_ctl1);
649-
if (child_l1ss_cap)
650-
pci_read_config_dword(child, child->l1ss + PCI_L1SS_CTL1,
651-
&child_l1ss_ctl1);
652-
653-
if (parent_l1ss_ctl1 & child_l1ss_ctl1 & PCI_L1SS_CTL1_ASPM_L1_1)
654-
link->aspm_enabled |= ASPM_STATE_L1_1;
655-
if (parent_l1ss_ctl1 & child_l1ss_ctl1 & PCI_L1SS_CTL1_ASPM_L1_2)
656-
link->aspm_enabled |= ASPM_STATE_L1_2;
657-
if (parent_l1ss_ctl1 & child_l1ss_ctl1 & PCI_L1SS_CTL1_PCIPM_L1_1)
658-
link->aspm_enabled |= ASPM_STATE_L1_1_PCIPM;
659-
if (parent_l1ss_ctl1 & child_l1ss_ctl1 & PCI_L1SS_CTL1_PCIPM_L1_2)
660-
link->aspm_enabled |= ASPM_STATE_L1_2_PCIPM;
661-
662-
if (link->aspm_support & ASPM_STATE_L1SS)
663-
aspm_calc_l1ss_info(link, parent_l1ss_cap, child_l1ss_cap);
670+
aspm_l1ss_init(link);
664671

665672
/* Save default state */
666673
link->aspm_default = link->aspm_enabled;

0 commit comments

Comments
 (0)