Skip to contentSkip to conversation

PCI: PM: Fix handling of device that can only signal PME from D3cold

PATCH In review Rafael J. Wysocki 3 participants 8 messages Jul 29, 2021 – Jul 30, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover PCI: PM: Fix handling of device that can only signal PME from D3cold

Hi,

This series is a replacement for the following patch:

https://patchwork.kernel.org/project/linux-pm/patch/3149540.aeNJFYEL58@kreacher/

allowing devices that only can signal PME from D3cold to be put into low-power states and signal wakeup from D3cold (if they get into it).

However, the patch above works by adding a special case to pci_pme_capable() which actually is not necessary.

Instead of doing that, it is sufficient to make pci_target_state() handle the case in which the device cannot signal PME from D0 consistently (patch [1/2] in this series) and make __pci_enable_wake() enable PM signaling for devices that can signal PME from D3cold (patch [2/2] in this series).

Please see the patch changelogs for details.

Thanks!

#1 lore raw

PATCH 1/2 PCI: PM: Add special case handling for PCIe device wakeup

From: Rafael J. Wysocki <[email protected]>

It is inconsistent to return PCI_D0 from pci_target_state() instead of the original target state if 'wakeup' is true and the device cannot signal PME from D0.

This only happens when the device cannot signal PME from the original target state and any shallower power states (including D0) and that case is effectively equivalent to the one in which PME signaling is not supported at all. Since the original target state is returned in the latter case, make the function do that in the former one too.

---
 drivers/pci/pci.c |   16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/pci/pci.c +10 -6
Index: linux-pm/drivers/pci/pci.c
===================================================================
@@ -2595,16 +2595,20 @@ static pci_power_t pci_target_state(stru
 	if (dev->current_state == PCI_D3cold)
 		target_state = PCI_D3cold;
 
-	if (wakeup) {
+	if (wakeup && dev->pme_support) {
+		pci_power_t state = target_state;
+
 		/*
 		 * Find the deepest state from which the device can generate
 		 * PME#.
 		 */
-		if (dev->pme_support) {
-			while (target_state
-			      && !(dev->pme_support & (1 << target_state)))
-				target_state--;
-		}
+		while (state && !(dev->pme_support & (1 << state)))
+			state--;
+
+		if (state)
+			return state;
+		else if (dev->pme_support & 1)
+			return PCI_D0;
 	}
 
 	return target_state;
#2 lore raw

Re: [PATCH v1 1/2] PCI: PM: Add special case handling for PCIe device wakeup

Quoted 13 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

It is inconsistent to return PCI_D0 from pci_target_state() instead of the original target state if 'wakeup' is true and the device cannot signal PME from D0.

This only happens when the device cannot signal PME from the original target state and any shallower power states (including D0) and that case is effectively equivalent to the one in which PME signaling is not supported at all. Since the original target state is returned in the latter case, make the function do that in the former one too.

Quoted 6 lines

The subject of this patch should be different, let me resend it.

#3 lore raw

PATCH 1/2 PCI: PM: Avoid forcing PCI_D0 for wakeup reasons inconsistently

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

It is inconsistent to return PCI_D0 from pci_target_state() instead of the original target state if 'wakeup' is true and the device cannot signal PME from D0.

This only happens when the device cannot signal PME from the original target state and any shallower power states (including D0) and that case is effectively equivalent to the one in which PME singaling is not supported at all. Since the original target state is returned in the latter case, make the function do that in the former one too.

---

v1 -> v1.1
* Resend under a suitable subject.

---
 drivers/pci/pci.c |   16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/pci/pci.c +10 -6
Index: linux-pm/drivers/pci/pci.c
===================================================================
@@ -2595,16 +2595,20 @@ static pci_power_t pci_target_state(stru
 	if (dev->current_state == PCI_D3cold)
 		target_state = PCI_D3cold;
 
-	if (wakeup) {
+	if (wakeup && dev->pme_support) {
+		pci_power_t state = target_state;
+
 		/*
 		 * Find the deepest state from which the device can generate
 		 * PME#.
 		 */
-		if (dev->pme_support) {
-			while (target_state
-			      && !(dev->pme_support & (1 << target_state)))
-				target_state--;
-		}
+		while (state && !(dev->pme_support & (1 << state)))
+			state--;
+
+		if (state)
+			return state;
+		else if (dev->pme_support & 1)
+			return PCI_D0;
 	}
 
 	return target_state;
Reviewed-by Tested-by on v1 1/2
#4 lore raw

Re: [PATCH v1.1 1/2] PCI: PM: Avoid forcing PCI_D0 for wakeup reasons inconsistently

Quoted 12 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

It is inconsistent to return PCI_D0 from pci_target_state() instead of the original target state if 'wakeup' is true and the device cannot signal PME from D0.

This only happens when the device cannot signal PME from the original target state and any shallower power states (including D0) and that case is effectively equivalent to the one in which PME singaling is not supported at all. Since the original target state is returned in the latter case, make the function do that in the former one too.

Quoted 3 lines
Fixes 666ff6f83e1d ("PCI/PM: Avoid using device_may_wakeup() for runtime PM")
#5 lore raw

PATCH 2/2 PCI: PM: Enable PME if it can be signaled from D3cold

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

PME signaling is only enabled by __pci_enable_wake() if the target device can signal PME from the given target power state (to avoid pointless reconfiguration of the device), but if the hierarchy above the device goes into D3cold, the device itself will end up in D3cold too, so if it can signal PME from D3cold, it should be enabled to do so in __pci_enable_wake().

[Note that if the device does not end up in D3cold and it cannot
signal PME from the original target power state, it will not signal PME, so in that case the behavior does not change.]

---
 drivers/pci/pci.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/pci/pci.c +8 -1
Index: linux-pm/drivers/pci/pci.c
===================================================================
@@ -2491,7 +2491,14 @@ static int __pci_enable_wake(struct pci_
 	if (enable) {
 		int error;
 
-		if (pci_pme_capable(dev, state))
+		/*
+		 * Enable PME signaling if the device can signal PME from
+		 * D3cold regardless of whether or not it can signal PME from
+		 * the current target state, because that will allow it to
+		 * signal PME when the hierarchy above it goes into D3cold and
+		 * the device itself ends up in D3cold as a result of that.
+		 */
+		if (pci_pme_capable(dev, state) || pci_pme_capable(dev, PCI_D3cold))
 			pci_pme_active(dev, true);
 		else
 			ret = 1;
Reviewed-by Tested-by on v1 2/2
#6 lore raw

Re: [PATCH v1 2/2] PCI: PM: Enable PME if it can be signaled from D3cold

Quoted 9 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

PME signaling is only enabled by __pci_enable_wake() if the target device can signal PME from the given target power state (to avoid pointless reconfiguration of the device), but if the hierarchy above the device goes into D3cold, the device itself will end up in D3cold too, so if it can signal PME from D3cold, it should be enabled to do so in __pci_enable_wake().

Quoted 7 lines

[Note that if the device does not end up in D3cold and it cannot
signal PME from the original target power state, it will not signal PME, so in that case the behavior does not change.]

Fixes 5bcc2fb4e815 ("PCI PM: Simplify PCI wake-up code")

Also this solves the reported issue so,

Thanks!

#7 lore raw

Re: [PATCH v1 2/2] PCI: PM: Enable PME if it can be signaled from D3cold

Quoted 19 lines · Mika Westerberg
Quoted 9 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

PME signaling is only enabled by __pci_enable_wake() if the target device can signal PME from the given target power state (to avoid pointless reconfiguration of the device), but if the hierarchy above the device goes into D3cold, the device itself will end up in D3cold too, so if it can signal PME from D3cold, it should be enabled to do so in __pci_enable_wake().

Quoted 7 lines

[Note that if the device does not end up in D3cold and it cannot
signal PME from the original target power state, it will not signal PME, so in that case the behavior does not change.]

Fixes 5bcc2fb4e815 ("PCI PM: Simplify PCI wake-up code")
Quoted 5 lines

Also this solves the reported issue so,

Thank you!

I'll queue up these two patches for 5.15 barring any objections from Bjorn.