Skip to content

Commit dc69062

Browse files
ij-intelbjorn-helgaas
authored andcommitted
PCI/ASPM: Clean up ASPM disable/enable mask calculation
With only one set of defines remaining, state can be almost used as-is to set ->aspm_disable/default. Only CLKPM and L1 PM substates need special handling. Remove unnecessary if conditions that can use the state variable bits directly. Move ASPM mask calculation into pci_calc_aspm_enable_mask() and pci_calc_aspm_disable_mask() helpers which makes it easier to alter state variable directly. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ilpo Järvinen <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent b478e16 commit dc69062

File tree

1 file changed

+24
-27
lines changed

1 file changed

+24
-27
lines changed

drivers/pci/pcie/aspm.c

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,28 @@ static struct pcie_link_state *pcie_aspm_get_link(struct pci_dev *pdev)
13231323
return bridge->link_state;
13241324
}
13251325

1326+
static u8 pci_calc_aspm_disable_mask(int state)
1327+
{
1328+
state &= ~PCIE_LINK_STATE_CLKPM;
1329+
1330+
/* L1 PM substates require L1 */
1331+
if (state & PCIE_LINK_STATE_L1)
1332+
state |= PCIE_LINK_STATE_L1SS;
1333+
1334+
return state;
1335+
}
1336+
1337+
static u8 pci_calc_aspm_enable_mask(int state)
1338+
{
1339+
state &= ~PCIE_LINK_STATE_CLKPM;
1340+
1341+
/* L1 PM substates require L1 */
1342+
if (state & PCIE_LINK_STATE_L1SS)
1343+
state |= PCIE_LINK_STATE_L1;
1344+
1345+
return state;
1346+
}
1347+
13261348
static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool locked)
13271349
{
13281350
struct pcie_link_state *link = pcie_aspm_get_link(pdev);
@@ -1345,19 +1367,7 @@ static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool locked
13451367
if (!locked)
13461368
down_read(&pci_bus_sem);
13471369
mutex_lock(&aspm_lock);
1348-
if (state & PCIE_LINK_STATE_L0S)
1349-
link->aspm_disable |= PCIE_LINK_STATE_L0S;
1350-
if (state & PCIE_LINK_STATE_L1)
1351-
/* L1 PM substates require L1 */
1352-
link->aspm_disable |= PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_L1SS;
1353-
if (state & PCIE_LINK_STATE_L1_1)
1354-
link->aspm_disable |= PCIE_LINK_STATE_L1_1;
1355-
if (state & PCIE_LINK_STATE_L1_2)
1356-
link->aspm_disable |= PCIE_LINK_STATE_L1_2;
1357-
if (state & PCIE_LINK_STATE_L1_1_PCIPM)
1358-
link->aspm_disable |= PCIE_LINK_STATE_L1_1_PCIPM;
1359-
if (state & PCIE_LINK_STATE_L1_2_PCIPM)
1360-
link->aspm_disable |= PCIE_LINK_STATE_L1_2_PCIPM;
1370+
link->aspm_disable |= pci_calc_aspm_disable_mask(state);
13611371
pcie_config_aspm_link(link, policy_to_aspm_state(link));
13621372

13631373
if (state & PCIE_LINK_STATE_CLKPM)
@@ -1413,20 +1423,7 @@ static int __pci_enable_link_state(struct pci_dev *pdev, int state, bool locked)
14131423
if (!locked)
14141424
down_read(&pci_bus_sem);
14151425
mutex_lock(&aspm_lock);
1416-
link->aspm_default = 0;
1417-
if (state & PCIE_LINK_STATE_L0S)
1418-
link->aspm_default |= PCIE_LINK_STATE_L0S;
1419-
if (state & PCIE_LINK_STATE_L1)
1420-
link->aspm_default |= PCIE_LINK_STATE_L1;
1421-
/* L1 PM substates require L1 */
1422-
if (state & PCIE_LINK_STATE_L1_1)
1423-
link->aspm_default |= PCIE_LINK_STATE_L1_1 | PCIE_LINK_STATE_L1;
1424-
if (state & PCIE_LINK_STATE_L1_2)
1425-
link->aspm_default |= PCIE_LINK_STATE_L1_2 | PCIE_LINK_STATE_L1;
1426-
if (state & PCIE_LINK_STATE_L1_1_PCIPM)
1427-
link->aspm_default |= PCIE_LINK_STATE_L1_1_PCIPM | PCIE_LINK_STATE_L1;
1428-
if (state & PCIE_LINK_STATE_L1_2_PCIPM)
1429-
link->aspm_default |= PCIE_LINK_STATE_L1_2_PCIPM | PCIE_LINK_STATE_L1;
1426+
link->aspm_default = pci_calc_aspm_enable_mask(state);
14301427
pcie_config_aspm_link(link, policy_to_aspm_state(link));
14311428

14321429
link->clkpm_default = (state & PCIE_LINK_STATE_CLKPM) ? 1 : 0;

0 commit comments

Comments
 (0)