All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Saheed O. Bolarinwa" <refactormyself@gmail.com>
To: helgaas@kernel.org
Cc: "Bolarinwa O. Saheed" <refactormyself@gmail.com>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH v1 4/4] PCI/ASPM: Remove struct pcie_link_state.clkpm_disable
Date: Wed, 29 Sep 2021 02:44:00 +0200	[thread overview]
Message-ID: <20210929004400.25717-5-refactormyself@gmail.com> (raw)
In-Reply-To: <20210929004400.25717-1-refactormyself@gmail.com>

From: "Bolarinwa O. Saheed" <refactormyself@gmail.com>

The clkpm_disable member of the struct pcie_link_state indicates
if the Clock PM state of the device is disabled. There are two
situations which can cause the Clock PM state disabled.
1. If the device fails sanity check as in pcie_aspm_sanity_check()
2. By calling __pci_disable_link_state()

It is possible to set the Clock PM state of a device ON or OFF by
calling pcie_set_clkpm(). The state can be retieved by calling
pcie_get_clkpm_state().

pcie_link_state.clkpm_disable is only accessed in pcie_set_clkpm()
to ensure that Clock PM state can be reenabled after being disabled.

This patch:
  - add pm_disable to the struct pcie_link_state, to indicate that
    the kernel has marked the device's AS and Clock PM states disabled
  - removes clkpm_disable from the struct pcie_link_state
  - removes all instance where clkpm_disable is set
  - ensure that the Clock PM is always disabled if it is part of the
    states passed into __pci_disable_link_state(), regardless of the
    global policy

Signed-off-by: Bolarinwa O. Saheed <refactormyself@gmail.com>
---
 drivers/pci/pcie/aspm.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index 368828cd427d..e6ae00daa7ae 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -60,8 +60,7 @@ struct pcie_link_state {
 	u32 aspm_default:7;		/* Default ASPM state by BIOS */
 	u32 aspm_disable:7;		/* Disabled ASPM state */
 
-	/* Clock PM state */
-	u32 clkpm_disable:1;		/* Clock PM disabled */
+	u32 pm_disabled:1;		/* Disabled AS and Clock PM ? */
 
 	/* Exit latencies */
 	struct aspm_latency latency_up;	/* Upstream direction exit latency */
@@ -198,7 +197,7 @@ static void pcie_set_clkpm(struct pcie_link_state *link, int enable)
 	 * Don't enable Clock PM if the link is not Clock PM capable
 	 * or Clock PM is disabled
 	 */
-	if (!capable || link->clkpm_disable)
+	if (enable && (!capable || link->pm_disabled))
 		enable = 0;
 	/* Need nothing if the specified equals to current state */
 	if (pcie_get_clkpm_state(link->pdev) == enable)
@@ -206,11 +205,6 @@ static void pcie_set_clkpm(struct pcie_link_state *link, int enable)
 	pcie_set_clkpm_nocheck(link, enable);
 }
 
-static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist)
-{
-	link->clkpm_disable = blacklist ? 1 : 0;
-}
-
 static bool pcie_retrain_link(struct pcie_link_state *link)
 {
 	struct pci_dev *parent = link->pdev;
@@ -952,8 +946,7 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev)
 	 */
 	pcie_aspm_cap_init(link, blacklist);
 
-	/* Setup initial Clock PM state */
-	pcie_clkpm_cap_init(link, blacklist);
+	link->pm_disabled = blacklist;
 
 	/*
 	 * At this stage drivers haven't had an opportunity to change the
@@ -1129,8 +1122,8 @@ static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem)
 	pcie_config_aspm_link(link, policy_to_aspm_state(link));
 
 	if (state & PCIE_LINK_STATE_CLKPM)
-		link->clkpm_disable = 1;
-	pcie_set_clkpm(link, policy_to_clkpm_state(link));
+		pcie_set_clkpm(link, 0);
+
 	mutex_unlock(&aspm_lock);
 	if (sem)
 		up_read(&pci_bus_sem);
@@ -1301,7 +1294,6 @@ static ssize_t clkpm_store(struct device *dev,
 	down_read(&pci_bus_sem);
 	mutex_lock(&aspm_lock);
 
-	link->clkpm_disable = !state_enable;
 	pcie_set_clkpm(link, policy_to_clkpm_state(link));
 
 	mutex_unlock(&aspm_lock);
-- 
2.20.1


  parent reply	other threads:[~2021-09-29  0:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29  0:43 [RFC PATCH v1 0/4] Remove struct pcie_link_state.clkpm_* Saheed O. Bolarinwa
2021-09-29  0:43 ` [RFC PATCH v1 1/4] [PCI/ASPM:] Remove struct pcie_link_state.clkpm_default Saheed O. Bolarinwa
2021-09-30 15:54   ` Bjorn Helgaas
2021-10-11  6:05     ` Saheed Bolarinwa
2021-09-29  0:43 ` [RFC PATCH v1 2/4] PCI/ASPM: Remove struct pcie_link_state.clkpm_capable Saheed O. Bolarinwa
2021-09-30 16:05   ` Bjorn Helgaas
2021-09-29  0:43 ` [RFC PATCH v1 3/4] PCI/ASPM: Remove struct pcie_link_state.clkpm_enabled Saheed O. Bolarinwa
2021-09-30 16:28   ` Bjorn Helgaas
2021-09-29  0:44 ` Saheed O. Bolarinwa [this message]
2021-09-30 20:20   ` [RFC PATCH v1 4/4] PCI/ASPM: Remove struct pcie_link_state.clkpm_disable Bjorn Helgaas
2021-10-11  6:06     ` Saheed Bolarinwa

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=20210929004400.25717-5-refactormyself@gmail.com \
    --to=refactormyself@gmail.com \
    --cc=helgaas@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.