[SRU,A/B,1/1] PCI / PM: Always check PME wakeup capability for runtime wakeup support

Message ID 20180514070745.31932-2-kai.heng.feng@canonical.com
State New
Headers show
Series
  • Fix an issue that some PCI devices get incorrectly suspended
Related show

Commit Message

Kai-Heng Feng May 14, 2018, 7:07 a.m.
From: Kai Heng Feng <kai.heng.feng@canonical.com>

BugLink: https://bugs.launchpad.net/bugs/1764684

USB controller ASM1042 stops working after commit de3ef1eb1cd0 (PM /
core: Drop run_wake flag from struct dev_pm_info).

The device in question is not power managed by platform firmware,
furthermore, it only supports PME# from D3cold:
Capabilities: [78] Power Management version 3
       Flags: PMEClk- DSI- D1- D2- AuxCurrent=55mA PME(D0-,D1-,D2-,D3hot-,D3cold+)
       Status: D0 NoSoftRst+ PME-Enable- DSel=0 DScale=0 PME-

Before commit de3ef1eb1cd0, the device never gets runtime suspended.
After that commit, the device gets runtime suspended to D3hot, which can
not generate any PME#.

usb_hcd_pci_probe() unconditionally calls device_wakeup_enable(), hence
device_can_wakeup() in pci_dev_run_wake() always returns true.

So pci_dev_run_wake() needs to check PME wakeup capability as its first
condition.

In addition, change wakeup flag passed to pci_target_state() from false
to true, because we want to find the deepest state different from D3cold
that the device can still generate PME#. In this case, it's D0 for the
device in question.

Fixes: de3ef1eb1cd0 (PM / core: Drop run_wake flag from struct dev_pm_info)
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Cc: 4.13+ <stable@vger.kernel.org> # 4.13+
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
(cherry picked from commit 8feaec33b9868582654cd3d5355225dcb79aeca6)
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
 drivers/pci/pci.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Andy Whitcroft May 14, 2018, 9:44 a.m. | #1
On Mon, May 14, 2018 at 03:07:45PM +0800, Kai-Heng Feng wrote:
> From: Kai Heng Feng <kai.heng.feng@canonical.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1764684
> 
> USB controller ASM1042 stops working after commit de3ef1eb1cd0 (PM /
> core: Drop run_wake flag from struct dev_pm_info).
> 
> The device in question is not power managed by platform firmware,
> furthermore, it only supports PME# from D3cold:
> Capabilities: [78] Power Management version 3
>        Flags: PMEClk- DSI- D1- D2- AuxCurrent=55mA PME(D0-,D1-,D2-,D3hot-,D3cold+)
>        Status: D0 NoSoftRst+ PME-Enable- DSel=0 DScale=0 PME-
> 
> Before commit de3ef1eb1cd0, the device never gets runtime suspended.
> After that commit, the device gets runtime suspended to D3hot, which can
> not generate any PME#.
> 
> usb_hcd_pci_probe() unconditionally calls device_wakeup_enable(), hence
> device_can_wakeup() in pci_dev_run_wake() always returns true.
> 
> So pci_dev_run_wake() needs to check PME wakeup capability as its first
> condition.
> 
> In addition, change wakeup flag passed to pci_target_state() from false
> to true, because we want to find the deepest state different from D3cold
> that the device can still generate PME#. In this case, it's D0 for the
> device in question.
> 
> Fixes: de3ef1eb1cd0 (PM / core: Drop run_wake flag from struct dev_pm_info)
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> Cc: 4.13+ <stable@vger.kernel.org> # 4.13+
> Acked-by: Bjorn Helgaas <bhelgaas@google.com>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> (cherry picked from commit 8feaec33b9868582654cd3d5355225dcb79aeca6)
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> ---
>  drivers/pci/pci.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 8eac876b50af..6467af7cd5bd 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -2121,16 +2121,16 @@ bool pci_dev_run_wake(struct pci_dev *dev)
>  {
>  	struct pci_bus *bus = dev->bus;
>  
> -	if (device_can_wakeup(&dev->dev))
> -		return true;
> -
>  	if (!dev->pme_support)
>  		return false;
>  
>  	/* PME-capable in principle, but not from the target power state */
> -	if (!pci_pme_capable(dev, pci_target_state(dev, false)))
> +	if (!pci_pme_capable(dev, pci_target_state(dev, true)))
>  		return false;
>  
> +	if (device_can_wakeup(&dev->dev))
> +		return true;
> +
>  	while (bus->parent) {
>  		struct pci_dev *bridge = bus->self;
>  
> -- 
> 2.17.0
> 
> 
> -- 
> kernel-team mailing list
> kernel-team@lists.ubuntu.com
> https://lists.ubuntu.com/mailman/listinfo/kernel-team

Simple cherry-pick, looks to do what is claimed.

Acked-by: Andy Whitcroft <apw@canonical.com>

-apw

Patch

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 8eac876b50af..6467af7cd5bd 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -2121,16 +2121,16 @@  bool pci_dev_run_wake(struct pci_dev *dev)
 {
 	struct pci_bus *bus = dev->bus;
 
-	if (device_can_wakeup(&dev->dev))
-		return true;
-
 	if (!dev->pme_support)
 		return false;
 
 	/* PME-capable in principle, but not from the target power state */
-	if (!pci_pme_capable(dev, pci_target_state(dev, false)))
+	if (!pci_pme_capable(dev, pci_target_state(dev, true)))
 		return false;
 
+	if (device_can_wakeup(&dev->dev))
+		return true;
+
 	while (bus->parent) {
 		struct pci_dev *bridge = bus->self;