Skip to content

Commit 0a5cfbe

Browse files
hkallweitSeth Forshee
authored andcommitted
PCI/ASPM: Add pcie_aspm_get_link()
BugLink: https://bugs.launchpad.net/bugs/1836030 Factor out getting the link associated with a pci_dev and use this helper where appropriate. In addition this helper will be used in a subsequent patch of this series. Link: https://lore.kernel.org/r/19d33770-29de-a9af-4d85-f2b30269d383@gmail.com Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> (cherry picked from commit 687aaf3) Signed-off-by: AceLan Kao <acelan.kao@canonical.com> Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
1 parent 5eea606 commit 0a5cfbe

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

drivers/pci/pcie/aspm.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,19 +1066,26 @@ void pcie_aspm_powersave_config_link(struct pci_dev *pdev)
10661066
up_read(&pci_bus_sem);
10671067
}
10681068

1069-
static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem)
1069+
static struct pcie_link_state *pcie_aspm_get_link(struct pci_dev *pdev)
10701070
{
1071-
struct pci_dev *parent = pdev->bus->self;
1072-
struct pcie_link_state *link;
1071+
struct pci_dev *bridge;
10731072

10741073
if (!pci_is_pcie(pdev))
1075-
return 0;
1074+
return NULL;
10761075

1077-
if (pcie_downstream_port(pdev))
1078-
parent = pdev;
1079-
if (!parent || !parent->link_state)
1080-
return -EINVAL;
1076+
bridge = pci_upstream_bridge(pdev);
1077+
if (!bridge || !pci_is_pcie(bridge))
1078+
return NULL;
10811079

1080+
return bridge->link_state;
1081+
}
1082+
1083+
static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem)
1084+
{
1085+
struct pcie_link_state *link = pcie_aspm_get_link(pdev);
1086+
1087+
if (!link)
1088+
return -EINVAL;
10821089
/*
10831090
* A driver requested that ASPM be disabled on this device, but
10841091
* if we don't have permission to manage ASPM (e.g., on ACPI
@@ -1095,7 +1102,6 @@ static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem)
10951102
if (sem)
10961103
down_read(&pci_bus_sem);
10971104
mutex_lock(&aspm_lock);
1098-
link = parent->link_state;
10991105
if (state & PCIE_LINK_STATE_L0S)
11001106
link->aspm_disable |= ASPM_STATE_L0S;
11011107
if (state & PCIE_LINK_STATE_L1)
@@ -1193,12 +1199,12 @@ module_param_call(policy, pcie_aspm_set_policy, pcie_aspm_get_policy,
11931199
*/
11941200
bool pcie_aspm_enabled(struct pci_dev *pdev)
11951201
{
1196-
struct pci_dev *bridge = pci_upstream_bridge(pdev);
1202+
struct pcie_link_state *link = pcie_aspm_get_link(pdev);
11971203

1198-
if (!bridge)
1204+
if (!link)
11991205
return false;
12001206

1201-
return bridge->link_state ? !!bridge->link_state->aspm_enabled : false;
1207+
return link->aspm_enabled;
12021208
}
12031209
EXPORT_SYMBOL_GPL(pcie_aspm_enabled);
12041210

0 commit comments

Comments
 (0)