All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v2 0/3] Remove struct pcie_link_state.clkpm_*
@ 2021-11-06 17:55 Saheed O. Bolarinwa
  2021-11-06 17:55 ` [RFC PATCH v2 1/3] PCI/ASPM: Merge pcie_set_clkpm_nocheck() into pcie_set_clkpm() Saheed O. Bolarinwa
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Saheed O. Bolarinwa @ 2021-11-06 17:55 UTC (permalink / raw)
  To: helgaas; +Cc: Saheed O. Bolarinwa, linux-pci, linux-kernel

These series removes the Clock PM members of the
struct pcie_link_state. Another member is introduced to mark
devices that the kernel has disbled.

VERSION CHANGES:
 - v2:
	- clkpm_default and clkpm_disable are now left out.
	- improve pcie_is_clkpm_capable() based on review.
	- replace pcie_get_clkpm_state() with pcie_clkpm_enabled().

MERGE NOTICE:
These series are based on
»       'commit e4e737bb5c17 ("Linux 5.15-rc2")'

Saheed O. Bolarinwa (3):
  PCI/ASPM: Merge pcie_set_clkpm_nocheck() into pcie_set_clkpm()
  PCI/ASPM: Remove struct pcie_link_state.clkpm_capable
  PCI/ASPM: Remove struct pcie_link_state.clkpm_enabled

 drivers/pci/pcie/aspm.c | 82 +++++++++++++++++++++--------------------
 1 file changed, 42 insertions(+), 40 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [RFC PATCH v2 1/3] PCI/ASPM: Merge pcie_set_clkpm_nocheck() into pcie_set_clkpm()
  2021-11-06 17:55 [RFC PATCH v2 0/3] Remove struct pcie_link_state.clkpm_* Saheed O. Bolarinwa
@ 2021-11-06 17:55 ` Saheed O. Bolarinwa
  2021-11-06 17:55 ` [RFC PATCH v2 2/3] PCI/ASPM: Remove struct pcie_link_state.clkpm_capable Saheed O. Bolarinwa
  2021-11-06 17:55 ` [RFC PATCH v2 3/3] PCI/ASPM: Remove struct pcie_link_state.clkpm_enabled Saheed O. Bolarinwa
  2 siblings, 0 replies; 4+ messages in thread
From: Saheed O. Bolarinwa @ 2021-11-06 17:55 UTC (permalink / raw)
  To: helgaas; +Cc: Saheed O. Bolarinwa, linux-pci, linux-kernel

pcie_set_clkpm_nocheck() is only called from pcie_set_clkpm().

Merge the two functions

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

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index 013a47f587ce..e5202cc16ef0 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -139,21 +139,12 @@ static int policy_to_clkpm_state(struct pcie_link_state *link)
 	return 0;
 }
 
-static void pcie_set_clkpm_nocheck(struct pcie_link_state *link, int enable)
+static void pcie_set_clkpm(struct pcie_link_state *link, int enable)
 {
+	u32 val;
 	struct pci_dev *child;
 	struct pci_bus *linkbus = link->pdev->subordinate;
-	u32 val = enable ? PCI_EXP_LNKCTL_CLKREQ_EN : 0;
-
-	list_for_each_entry(child, &linkbus->devices, bus_list)
-		pcie_capability_clear_and_set_word(child, PCI_EXP_LNKCTL,
-						   PCI_EXP_LNKCTL_CLKREQ_EN,
-						   val);
-	link->clkpm_enabled = !!enable;
-}
 
-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
@@ -163,7 +154,14 @@ static void pcie_set_clkpm(struct pcie_link_state *link, int enable)
 	/* Need nothing if the specified equals to current state */
 	if (link->clkpm_enabled == enable)
 		return;
-	pcie_set_clkpm_nocheck(link, enable);
+
+	val = enable ? PCI_EXP_LNKCTL_CLKREQ_EN : 0;
+	list_for_each_entry(child, &linkbus->devices, bus_list)
+		pcie_capability_clear_and_set_word(child, PCI_EXP_LNKCTL,
+						   PCI_EXP_LNKCTL_CLKREQ_EN,
+						   val);
+
+	link->clkpm_enabled = !!enable;
 }
 
 static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist)
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [RFC PATCH v2 2/3] PCI/ASPM: Remove struct pcie_link_state.clkpm_capable
  2021-11-06 17:55 [RFC PATCH v2 0/3] Remove struct pcie_link_state.clkpm_* Saheed O. Bolarinwa
  2021-11-06 17:55 ` [RFC PATCH v2 1/3] PCI/ASPM: Merge pcie_set_clkpm_nocheck() into pcie_set_clkpm() Saheed O. Bolarinwa
@ 2021-11-06 17:55 ` Saheed O. Bolarinwa
  2021-11-06 17:55 ` [RFC PATCH v2 3/3] PCI/ASPM: Remove struct pcie_link_state.clkpm_enabled Saheed O. Bolarinwa
  2 siblings, 0 replies; 4+ messages in thread
From: Saheed O. Bolarinwa @ 2021-11-06 17:55 UTC (permalink / raw)
  To: helgaas; +Cc: Saheed O. Bolarinwa, linux-pci, linux-kernel

The clkpm_capable member of the struct pcie_link_state indicates
if the device is Clock PM capable. This can be calculated when
it is needed, because it comes from Link Capabilities, a read-only
register.

  - remove clkpm_capable from struct pcie_link_state
  - move the calculation of clkpm_capable into
    pcie_is_clkpm_capable()
  - replace references to clkpm_capable with a call to
    pcie_is_clkpm_capable()

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

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index e5202cc16ef0..c1f8f10b7a4c 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -61,7 +61,6 @@ struct pcie_link_state {
 	u32 aspm_disable:7;		/* Disabled ASPM state */
 
 	/* Clock PM state */
-	u32 clkpm_capable:1;		/* Clock PM capable? */
 	u32 clkpm_enabled:1;		/* Current Clock PM state */
 	u32 clkpm_default:1;		/* Default Clock PM state by BIOS */
 	u32 clkpm_disable:1;		/* Clock PM disabled */
@@ -105,6 +104,20 @@ static const char *policy_str[] = {
 
 #define LINK_RETRAIN_TIMEOUT HZ
 
+static int pcie_clkpm_capable(struct pci_dev *pdev)
+{
+	u32 cap;
+	struct pci_dev *child;
+	struct pci_bus *linkbus = pdev->subordinate;
+
+	list_for_each_entry(child, &linkbus->devices, bus_list) {
+		pcie_capability_read_dword(child, PCI_EXP_LNKCAP, &cap);
+		if (!(cap & PCI_EXP_LNKCAP_CLKPM))
+			return 0;
+	}
+	return 1;
+}
+
 static int policy_to_aspm_state(struct pcie_link_state *link)
 {
 	switch (aspm_policy) {
@@ -149,7 +162,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 (!link->clkpm_capable || link->clkpm_disable)
+	if (!pcie_clkpm_capable(link->pdev) || link->clkpm_disable)
 		enable = 0;
 	/* Need nothing if the specified equals to current state */
 	if (link->clkpm_enabled == enable)
@@ -166,7 +179,7 @@ static void pcie_set_clkpm(struct pcie_link_state *link, int enable)
 
 static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist)
 {
-	int capable = 1, enabled = 1;
+	int enabled = 1;
 	u32 reg32;
 	u16 reg16;
 	struct pci_dev *child;
@@ -176,7 +189,6 @@ static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist)
 	list_for_each_entry(child, &linkbus->devices, bus_list) {
 		pcie_capability_read_dword(child, PCI_EXP_LNKCAP, &reg32);
 		if (!(reg32 & PCI_EXP_LNKCAP_CLKPM)) {
-			capable = 0;
 			enabled = 0;
 			break;
 		}
@@ -186,7 +198,6 @@ static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist)
 	}
 	link->clkpm_enabled = enabled;
 	link->clkpm_default = enabled;
-	link->clkpm_capable = capable;
 	link->clkpm_disable = blacklist ? 1 : 0;
 }
 
@@ -1327,7 +1338,7 @@ static umode_t aspm_ctrl_attrs_are_visible(struct kobject *kobj,
 		return 0;
 
 	if (n == 0)
-		return link->clkpm_capable ? a->mode : 0;
+		return pcie_clkpm_capable(link->pdev) ? a->mode : 0;
 
 	return link->aspm_capable & aspm_state_map[n - 1] ? a->mode : 0;
 }
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [RFC PATCH v2 3/3] PCI/ASPM: Remove struct pcie_link_state.clkpm_enabled
  2021-11-06 17:55 [RFC PATCH v2 0/3] Remove struct pcie_link_state.clkpm_* Saheed O. Bolarinwa
  2021-11-06 17:55 ` [RFC PATCH v2 1/3] PCI/ASPM: Merge pcie_set_clkpm_nocheck() into pcie_set_clkpm() Saheed O. Bolarinwa
  2021-11-06 17:55 ` [RFC PATCH v2 2/3] PCI/ASPM: Remove struct pcie_link_state.clkpm_capable Saheed O. Bolarinwa
@ 2021-11-06 17:55 ` Saheed O. Bolarinwa
  2 siblings, 0 replies; 4+ messages in thread
From: Saheed O. Bolarinwa @ 2021-11-06 17:55 UTC (permalink / raw)
  To: helgaas; +Cc: Saheed O. Bolarinwa, linux-pci, linux-kernel

The clkpm_enabled member of the struct pcie_link_state stores the
current Clock PM state for the device. However, when the state changes
it is persisted and thus can be retieved directly.

   - move calculations into pcie_clkpm_enabled()
   - removes clkpm_enabled from the struct pcie_link_state
   - removes all instance where clkpm_enable is set
   - replaces references to clkpm_enabled with a call to
     pcie_get_clkpm_state()

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

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index c1f8f10b7a4c..9425d1e38c51 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -61,7 +61,6 @@ struct pcie_link_state {
 	u32 aspm_disable:7;		/* Disabled ASPM state */
 
 	/* Clock PM state */
-	u32 clkpm_enabled:1;		/* Current Clock PM state */
 	u32 clkpm_default:1;		/* Default Clock PM state by BIOS */
 	u32 clkpm_disable:1;		/* Clock PM disabled */
 
@@ -104,6 +103,21 @@ static const char *policy_str[] = {
 
 #define LINK_RETRAIN_TIMEOUT HZ
 
+static int pcie_clkpm_enabled(struct pci_dev *pdev)
+{
+	struct pci_dev *child;
+	struct pci_bus *linkbus = pdev->subordinate;
+	u16 ctl;
+
+	/* CLKREQ_EN is only applicable for Upstream Ports */
+	list_for_each_entry(child, &linkbus->devices, bus_list) {
+		pcie_capability_read_word(child, PCI_EXP_LNKCTL, &ctl);
+		if (!(ctl & PCI_EXP_LNKCTL_CLKREQ_EN))
+			return 0;
+	}
+	return 1;
+}
+
 static int pcie_clkpm_capable(struct pci_dev *pdev)
 {
 	u32 cap;
@@ -165,7 +179,7 @@ static void pcie_set_clkpm(struct pcie_link_state *link, int enable)
 	if (!pcie_clkpm_capable(link->pdev) || link->clkpm_disable)
 		enable = 0;
 	/* Need nothing if the specified equals to current state */
-	if (link->clkpm_enabled == enable)
+	if (pcie_clkpm_enabled(link->pdev) == enable)
 		return;
 
 	val = enable ? PCI_EXP_LNKCTL_CLKREQ_EN : 0;
@@ -173,31 +187,11 @@ static void pcie_set_clkpm(struct pcie_link_state *link, int enable)
 		pcie_capability_clear_and_set_word(child, PCI_EXP_LNKCTL,
 						   PCI_EXP_LNKCTL_CLKREQ_EN,
 						   val);
-
-	link->clkpm_enabled = !!enable;
 }
 
 static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist)
 {
-	int enabled = 1;
-	u32 reg32;
-	u16 reg16;
-	struct pci_dev *child;
-	struct pci_bus *linkbus = link->pdev->subordinate;
-
-	/* All functions should have the same cap and state, take the worst */
-	list_for_each_entry(child, &linkbus->devices, bus_list) {
-		pcie_capability_read_dword(child, PCI_EXP_LNKCAP, &reg32);
-		if (!(reg32 & PCI_EXP_LNKCAP_CLKPM)) {
-			enabled = 0;
-			break;
-		}
-		pcie_capability_read_word(child, PCI_EXP_LNKCTL, &reg16);
-		if (!(reg16 & PCI_EXP_LNKCTL_CLKREQ_EN))
-			enabled = 0;
-	}
-	link->clkpm_enabled = enabled;
-	link->clkpm_default = enabled;
+	link->clkpm_default = pcie_clkpm_enabled(link->pdev);
 	link->clkpm_disable = blacklist ? 1 : 0;
 }
 
@@ -1272,9 +1266,8 @@ static ssize_t clkpm_show(struct device *dev,
 			  struct device_attribute *attr, char *buf)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
-	struct pcie_link_state *link = pcie_aspm_get_link(pdev);
 
-	return sysfs_emit(buf, "%d\n", link->clkpm_enabled);
+	return sysfs_emit(buf, "%d\n", pcie_clkpm_enabled(pdev));
 }
 
 static ssize_t clkpm_store(struct device *dev,
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-11-06 17:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-06 17:55 [RFC PATCH v2 0/3] Remove struct pcie_link_state.clkpm_* Saheed O. Bolarinwa
2021-11-06 17:55 ` [RFC PATCH v2 1/3] PCI/ASPM: Merge pcie_set_clkpm_nocheck() into pcie_set_clkpm() Saheed O. Bolarinwa
2021-11-06 17:55 ` [RFC PATCH v2 2/3] PCI/ASPM: Remove struct pcie_link_state.clkpm_capable Saheed O. Bolarinwa
2021-11-06 17:55 ` [RFC PATCH v2 3/3] PCI/ASPM: Remove struct pcie_link_state.clkpm_enabled Saheed O. Bolarinwa

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.