From: Heiner Kallweit <hkallweit1@gmail.com>
To: Frederick Lawler <fred@fredlawl.com>,
Bjorn Helgaas <bhelgaas@google.com>,
Greg KH <gregkh@linuxfoundation.org>,
Rajat Jain <rajatja@google.com>
Cc: "linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>
Subject: [PATCH v7 3/5] PCI/ASPM: Add and use helper pcie_aspm_get_link
Date: Sat, 5 Oct 2019 14:07:18 +0200 [thread overview]
Message-ID: <19d33770-29de-a9af-4d85-f2b30269d383@gmail.com> (raw)
In-Reply-To: <e1c28e25-df18-16e1-3e9f-933f613ea858@gmail.com>
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.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
v7:
- add as separate patch
---
drivers/pci/pcie/aspm.c | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index 574f822bf..91cfea673 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -1066,19 +1066,28 @@ void pcie_aspm_powersave_config_link(struct pci_dev *pdev)
up_read(&pci_bus_sem);
}
+static struct pcie_link_state *pcie_aspm_get_link(struct pci_dev *pdev)
+{
+ struct pci_dev *upstream;
+
+ if (pcie_downstream_port(pdev))
+ upstream = pdev;
+ else
+ upstream = pci_upstream_bridge(pdev);
+
+ return upstream ? upstream->link_state : NULL;
+}
+
static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem)
{
- struct pci_dev *parent = pdev->bus->self;
struct pcie_link_state *link;
if (!pci_is_pcie(pdev))
return 0;
- if (pcie_downstream_port(pdev))
- parent = pdev;
- if (!parent || !parent->link_state)
+ link = pcie_aspm_get_link(pdev);
+ if (!link)
return -EINVAL;
-
/*
* A driver requested that ASPM be disabled on this device, but
* if we don't have permission to manage ASPM (e.g., on ACPI
@@ -1095,7 +1104,6 @@ static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem)
if (sem)
down_read(&pci_bus_sem);
mutex_lock(&aspm_lock);
- link = parent->link_state;
if (state & PCIE_LINK_STATE_L0S)
link->aspm_disable |= ASPM_STATE_L0S;
if (state & PCIE_LINK_STATE_L1)
@@ -1188,14 +1196,14 @@ module_param_call(policy, pcie_aspm_set_policy, pcie_aspm_get_policy,
*/
bool pcie_aspm_enabled(struct pci_dev *pdev)
{
- struct pci_dev *bridge = pci_upstream_bridge(pdev);
+ struct pcie_link_state *link = pcie_aspm_get_link(pdev);
bool ret;
- if (!bridge)
+ if (!link)
return false;
mutex_lock(&aspm_lock);
- ret = bridge->link_state ? !!bridge->link_state->aspm_enabled : false;
+ ret = link->aspm_enabled;
mutex_unlock(&aspm_lock);
return ret;
--
2.23.0
next prev parent reply other threads:[~2019-10-05 12:09 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-05 12:02 [PATCH v7 0/5] PCI/ASPM: Add sysfs attributes for controlling ASPM Heiner Kallweit
2019-10-05 12:03 ` [PATCH v7 2/5] PCI/ASPM: Allow to re-enable Clock PM Heiner Kallweit
2019-10-05 12:04 ` [PATCH v7 1/5] PCI/ASPM: Add L1 sub-state support to pci_disable_link_state Heiner Kallweit
2019-10-05 12:07 ` Heiner Kallweit [this message]
2019-10-08 1:51 ` [PATCH v7 3/5] PCI/ASPM: Add and use helper pcie_aspm_get_link Bjorn Helgaas
2019-10-05 12:07 ` [PATCH v7 4/5] PCI/ASPM: Add sysfs attributes for controlling ASPM link states Heiner Kallweit
2019-10-08 1:53 ` Bjorn Helgaas
2019-11-21 20:49 ` Bjorn Helgaas
2019-11-21 21:03 ` Rajat Jain
2019-11-21 21:10 ` Greg KH
2019-11-21 23:04 ` Bjorn Helgaas
2019-11-24 17:02 ` Greg KH
2019-10-05 12:08 ` [PATCH v7 5/5] PCI/ASPM: Remove Kconfig option PCIEASPM_DEBUG and related code Heiner Kallweit
2019-10-08 22:10 ` [PATCH v7 0/5] PCI/ASPM: Add sysfs attributes for controlling ASPM Bjorn Helgaas
2019-10-10 13:22 ` Bjorn Helgaas
2019-10-10 20:45 ` Heiner Kallweit
2019-10-15 20:30 ` Bjorn Helgaas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=19d33770-29de-a9af-4d85-f2b30269d383@gmail.com \
--to=hkallweit1@gmail.com \
--cc=bhelgaas@google.com \
--cc=fred@fredlawl.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-pci@vger.kernel.org \
--cc=rajatja@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).