Skip to content

Commit 5e85eba

Browse files
Vidya Sagarbjorn-helgaas
authored andcommitted
PCI/ASPM: Refactor L1 PM Substates Control Register programming
Refactor the code to extract the common code to program Control Registers 1 and 2 of the L1 PM Substates capability to a new function aspm_program_l1ss() and call it for both parent and child devices. [bhelgaas: squash in update to preserve fields we're not updating from https://lore.kernel.org/r/[email protected]] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vidya Sagar <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent 568035b commit 5e85eba

File tree

1 file changed

+40
-34
lines changed

1 file changed

+40
-34
lines changed

drivers/pci/pcie/aspm.c

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,31 @@ static void pci_clear_and_set_dword(struct pci_dev *pdev, int pos,
455455
pci_write_config_dword(pdev, pos, val);
456456
}
457457

458+
static void aspm_program_l1ss(struct pci_dev *dev, u32 ctl1, u32 ctl2)
459+
{
460+
u16 l1ss = dev->l1ss;
461+
u32 l1_2_enable;
462+
463+
/*
464+
* Per PCIe r6.0, sec 5.5.4, T_POWER_ON in PCI_L1SS_CTL2 must be
465+
* programmed prior to setting the L1.2 enable bits in PCI_L1SS_CTL1.
466+
*/
467+
pci_write_config_dword(dev, l1ss + PCI_L1SS_CTL2, ctl2);
468+
469+
/*
470+
* In addition, Common_Mode_Restore_Time and LTR_L1.2_THRESHOLD in
471+
* PCI_L1SS_CTL1 must be programmed *before* setting the L1.2
472+
* enable bits, even though they're all in PCI_L1SS_CTL1.
473+
*/
474+
l1_2_enable = ctl1 & PCI_L1SS_CTL1_L1_2_MASK;
475+
ctl1 &= ~PCI_L1SS_CTL1_L1_2_MASK;
476+
477+
pci_write_config_dword(dev, l1ss + PCI_L1SS_CTL1, ctl1);
478+
if (l1_2_enable)
479+
pci_write_config_dword(dev, l1ss + PCI_L1SS_CTL1,
480+
ctl1 | l1_2_enable);
481+
}
482+
458483
/* Calculate L1.2 PM substate timing parameters */
459484
static void aspm_calc_l1ss_info(struct pcie_link_state *link,
460485
u32 parent_l1ss_cap, u32 child_l1ss_cap)
@@ -464,7 +489,6 @@ static void aspm_calc_l1ss_info(struct pcie_link_state *link,
464489
u32 t_common_mode, t_power_on, l1_2_threshold, scale, value;
465490
u32 ctl1 = 0, ctl2 = 0;
466491
u32 pctl1, pctl2, cctl1, cctl2;
467-
u32 pl1_2_enables, cl1_2_enables;
468492

469493
if (!(link->aspm_support & ASPM_STATE_L1_2_MASK))
470494
return;
@@ -513,39 +537,21 @@ static void aspm_calc_l1ss_info(struct pcie_link_state *link,
513537
ctl2 == pctl2 && ctl2 == cctl2)
514538
return;
515539

516-
/* Disable L1.2 while updating. See PCIe r5.0, sec 5.5.4, 7.8.3.3 */
517-
pl1_2_enables = pctl1 & PCI_L1SS_CTL1_L1_2_MASK;
518-
cl1_2_enables = cctl1 & PCI_L1SS_CTL1_L1_2_MASK;
519-
520-
if (pl1_2_enables || cl1_2_enables) {
521-
pci_clear_and_set_dword(child, child->l1ss + PCI_L1SS_CTL1,
522-
PCI_L1SS_CTL1_L1_2_MASK, 0);
523-
pci_clear_and_set_dword(parent, parent->l1ss + PCI_L1SS_CTL1,
524-
PCI_L1SS_CTL1_L1_2_MASK, 0);
525-
}
526-
527-
/* Program T_POWER_ON times in both ports */
528-
pci_write_config_dword(parent, parent->l1ss + PCI_L1SS_CTL2, ctl2);
529-
pci_write_config_dword(child, child->l1ss + PCI_L1SS_CTL2, ctl2);
530-
531-
/* Program Common_Mode_Restore_Time in upstream device */
532-
pci_clear_and_set_dword(parent, parent->l1ss + PCI_L1SS_CTL1,
533-
PCI_L1SS_CTL1_CM_RESTORE_TIME, ctl1);
534-
535-
/* Program LTR_L1.2_THRESHOLD time in both ports */
536-
pci_clear_and_set_dword(parent, parent->l1ss + PCI_L1SS_CTL1,
537-
PCI_L1SS_CTL1_LTR_L12_TH_VALUE |
538-
PCI_L1SS_CTL1_LTR_L12_TH_SCALE, ctl1);
539-
pci_clear_and_set_dword(child, child->l1ss + PCI_L1SS_CTL1,
540-
PCI_L1SS_CTL1_LTR_L12_TH_VALUE |
541-
PCI_L1SS_CTL1_LTR_L12_TH_SCALE, ctl1);
542-
543-
if (pl1_2_enables || cl1_2_enables) {
544-
pci_clear_and_set_dword(parent, parent->l1ss + PCI_L1SS_CTL1, 0,
545-
pl1_2_enables);
546-
pci_clear_and_set_dword(child, child->l1ss + PCI_L1SS_CTL1, 0,
547-
cl1_2_enables);
548-
}
540+
pctl1 &= ~(PCI_L1SS_CTL1_CM_RESTORE_TIME |
541+
PCI_L1SS_CTL1_LTR_L12_TH_VALUE |
542+
PCI_L1SS_CTL1_LTR_L12_TH_SCALE);
543+
pctl1 |= (ctl1 & (PCI_L1SS_CTL1_CM_RESTORE_TIME |
544+
PCI_L1SS_CTL1_LTR_L12_TH_VALUE |
545+
PCI_L1SS_CTL1_LTR_L12_TH_SCALE));
546+
aspm_program_l1ss(parent, pctl1, ctl2);
547+
548+
cctl1 &= ~(PCI_L1SS_CTL1_CM_RESTORE_TIME |
549+
PCI_L1SS_CTL1_LTR_L12_TH_VALUE |
550+
PCI_L1SS_CTL1_LTR_L12_TH_SCALE);
551+
cctl1 |= (ctl1 & (PCI_L1SS_CTL1_CM_RESTORE_TIME |
552+
PCI_L1SS_CTL1_LTR_L12_TH_VALUE |
553+
PCI_L1SS_CTL1_LTR_L12_TH_SCALE));
554+
aspm_program_l1ss(child, cctl1, ctl2);
549555
}
550556

551557
static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)

0 commit comments

Comments
 (0)