pci/e1000e: return runtime-pm back to work
Subsystems (3)
cover pci/e1000e: return runtime-pm back to work
This patchset contains some fixes for e1000e diver (broken since v2.6.35) and some related fixes for PCI code (more fresh bugs).
Last patch adds simple debug for catching device-enable-cointer underflows.
All together this fixes my regression report for v3.8-rc1:
https://lkml.org/lkml/2013/1/1/25
---
Konstantin Khlebnikov (5):
e1000e: fix resuming from runtime-suspend
e1000e: fix pci device enable counter balance
PCI: revert preparing for wakeup in runtime-suspend finalization
PCI: don't touch enable_cnt in pci_device_shutdown()
PCI: catch enable-counter underflows
drivers/net/ethernet/intel/e1000e/netdev.c | 20 +++++++++++++++----- drivers/pci/pci-driver.c | 7 ++++--- drivers/pci/pci.c | 3 +++ 3 files changed, 22 insertions(+), 8 deletions(-)
Signature · 1 line
Signature
PATCH 1/5 e1000e: fix resuming from runtime-suspend
Bug was introduced in commit 23606cf5d1192c2b17912cb2ef6e62f9b11de133 ("e1000e / PCI / PM: Add basic runtime PM support (rev. 4)") in v2.6.35
--- drivers/net/ethernet/intel/e1000e/netdev.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/e1000e/netdev.c +8 -5
@@ -5691,14 +5691,17 @@ static int e1000_runtime_suspend(struct device *dev)struct pci_dev *pdev =to_pci_dev (dev);struct net_device *netdev =pci_get_drvdata (pdev);struct e1000_adapter *adapter =netdev_priv (netdev); +int retval; +bool wake; -if (e1000e_pm_ready (adapter)) { -bool wake; +if (!e1000e_pm_ready (adapter)) +return 0 ; -__e1000_shutdown (pdev, &wake, true); - } + retval =__e1000_shutdown (pdev, &wake, true); +if (!retval) +e1000_power_off (pdev, true, wake); -return 0 ; +return retval; }static int e1000_idle (struct device *dev)
Bjorn Helgaas
maintainerRe: [PATCH 1/5] e1000e: fix resuming from runtime-suspend
[+cc Rafael, author of patch you cited]
Quoted 44 lines · Konstantin Khlebnikov
Bug was introduced in commit
23606cf5d1192c2b17912cb2ef6e62f9b11de133("e1000e / PCI / PM: Add basic runtime PM support (rev. 4)") in v2.6.35Signed-off-by Konstantin Khlebnikov <[email protected]>Cc Jeff Kirsher <[email protected]>Cc Bruce Allan <[email protected]>--- drivers/net/ethernet/intel/e1000e/netdev.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)drivers/net/ethernet/intel/e1000e/netdev.c +8
-6@@ -5691,14 +5691,17 @@ static int e1000_runtime_suspend(struct device *dev)struct pci_dev *pdev =to_pci_dev (dev);struct net_device *netdev =pci_get_drvdata (pdev);struct e1000_adapter *adapter =netdev_priv (netdev); +int retval; +bool wake; -if (e1000e_pm_ready (adapter)) { -bool wake; +if (!e1000e_pm_ready (adapter)) +return 0 ; -__e1000_shutdown (pdev, &wake, true); - } + retval =__e1000_shutdown (pdev, &wake, true); +if (!retval) +e1000_power_off (pdev, true, wake); -return 0 ; +return retval; }static int e1000_idle (struct device *dev) --To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 1/5] e1000e: fix resuming from runtime-suspend
Quoted 37 lines · Bjorn Helgaas
[+cc Rafael, author of patch you cited]
Quoted 33 lines · Konstantin Khlebnikov
Bug was introduced in commit
23606cf5d1192c2b17912cb2ef6e62f9b11de133("e1000e / PCI / PM: Add basic runtime PM support (rev. 4)") in v2.6.35Signed-off-by Konstantin Khlebnikov <[email protected]>Cc Jeff Kirsher <[email protected]>Cc Bruce Allan <[email protected]>--- drivers/net/ethernet/intel/e1000e/netdev.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)drivers/net/ethernet/intel/e1000e/netdev.c +7
-4@@ -5691,14 +5691,17 @@ static int e1000_runtime_suspend(struct device *dev)struct pci_dev *pdev =to_pci_dev (dev);struct net_device *netdev =pci_get_drvdata (pdev);struct e1000_adapter *adapter =netdev_priv (netdev); +int retval; +bool wake; -if (e1000e_pm_ready (adapter)) { -bool wake; +if (!e1000e_pm_ready (adapter)) +return 0 ; -__e1000_shutdown (pdev, &wake, true); - } + retval =__e1000_shutdown (pdev, &wake, true); +if (!retval) +e1000_power_off (pdev, true, wake);
Quoted 6 lines
drivers/net/ethernet/intel/e1000e/netdev.c static int e1000_runtime_suspend(struct device *dev) · line 5707
Quoted 6 lines
drivers/net/ethernet/intel/e1000e/netdev.c +1
-1-return 0 ; +return retval; }static int e1000_idle (struct device *dev)
I'd like the changelog to say what the bug is and how it is being fixed in general terms.
Thanks,
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Re: [PATCH 1/5] e1000e: fix resuming from runtime-suspend
Quoted 42 lines · Rafael J. Wysocki
Quoted 41 lines · Bjorn Helgaas
[+cc Rafael, author of patch you cited]
Quoted 37 lines · Konstantin Khlebnikov
Bug was introduced in commit
23606cf5d1192c2b17912cb2ef6e62f9b11de133("e1000e / PCI / PM: Add basic runtime PM support (rev. 4)") in v2.6.35Signed-off-by Konstantin Khlebnikov<[email protected]>Cc Jeff Kirsher<[email protected]>Cc Bruce Allan<[email protected]>--- drivers/net/ethernet/intel/e1000e/netdev.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)drivers/net/ethernet/intel/e1000e/netdev.c +8
-5@@ -5691,14 +5691,17 @@ static int e1000_runtime_suspend(struct device *dev)struct pci_dev *pdev =to_pci_dev (dev);struct net_device *netdev =pci_get_drvdata (pdev);struct e1000_adapter *adapter =netdev_priv (netdev); +int retval; +bool wake; -if (e1000e_pm_ready (adapter)) { -bool wake; +if (!e1000e_pm_ready (adapter)) +return 0 ; -__e1000_shutdown (pdev,&wake, true); - } + retval =__e1000_shutdown (pdev,&wake, true); +if (!retval) +e1000_power_off (pdev, true, wake); -return 0 ; +return retval; }
Quoted 5 lines
Quoted 2 lines
drivers/net/ethernet/intel/e1000e/netdev.c static int e1000_runtime_suspend(struct device *dev) · line 5707
Quoted 2 lines
drivers/net/ethernet/intel/e1000e/netdev.c +0
-0static int e1000_idle (struct device *dev)I'd like the changelog to say what the bug is and how it is being fixed in general terms.
Ok, my bad.
Problem: ethernet device does not work (no carrier signal). Right after boot it goes to runtime-suspend and never wake up.
Original code (before your commit) calls pci_prepare_to_sleep() and it calls pci_enable_wake() and switches device to one of D3 state.
It seems redundant, because pci_pm_runtime_suspend() do the same thing after calling ->runtime_suspend callback. Or rather it did it before commit 42eca2302146fed51335b95128e949ee6f54478f ("PCI: Don't touch card regs after runtime suspend D3") and third patch aimed fix this damage.
More over seems like calling pci_enable_wake() from e1000e isn't enough for my case, because my enthernet cannot wakeup from runtime-suspend without third patch. Seems like it's because pci_enable_wake() and pci_finish_runtime_suspend() calls different pratform-pm callbacks -- platform_pci_run_wake() / platform_pci_sleep_wake().
All this looks messy and I don't know how it should work.
If you prefer to minimize changes -- I can test how it would work without first (this) patch. Probably fine.
Quoted 5 lines
Thanks,
Rafael
Re: [PATCH 1/5] e1000e: fix resuming from runtime-suspend
Quoted 68 lines · Konstantin Khlebnikov
Quoted 42 lines · Rafael J. Wysocki
Quoted 41 lines · Bjorn Helgaas
[+cc Rafael, author of patch you cited]
Quoted 37 lines · Konstantin Khlebnikov
Bug was introduced in commit
23606cf5d1192c2b17912cb2ef6e62f9b11de133("e1000e / PCI / PM: Add basic runtime PM support (rev. 4)") in v2.6.35Signed-off-by Konstantin Khlebnikov<[email protected]>Cc Jeff Kirsher<[email protected]>Cc Bruce Allan<[email protected]>--- drivers/net/ethernet/intel/e1000e/netdev.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)drivers/net/ethernet/intel/e1000e/netdev.c +8
-5@@ -5691,14 +5691,17 @@ static int e1000_runtime_suspend(struct device *dev)struct pci_dev *pdev =to_pci_dev (dev);struct net_device *netdev =pci_get_drvdata (pdev);struct e1000_adapter *adapter =netdev_priv (netdev); +int retval; +bool wake; -if (e1000e_pm_ready (adapter)) { -bool wake; +if (!e1000e_pm_ready (adapter)) +return 0 ; -__e1000_shutdown (pdev,&wake, true); - } + retval =__e1000_shutdown (pdev,&wake, true); +if (!retval) +e1000_power_off (pdev, true, wake); -return 0 ; +return retval; }Quoted 5 lines
Quoted 2 lines
drivers/net/ethernet/intel/e1000e/netdev.c static int e1000_runtime_suspend(struct device *dev) · line 5707
Quoted 2 lines
drivers/net/ethernet/intel/e1000e/netdev.c +0
-0static int e1000_idle (struct device *dev)I'd like the changelog to say what the bug is and how it is being fixed in general terms.
Ok, my bad.
Problem: ethernet device does not work (no carrier signal). Right after boot it goes to runtime-suspend and never wake up.
Original code (before your commit) calls
pci_prepare_to_sleep()and it callspci_enable_wake()and switches device to one of D3 state.It seems redundant, because
pci_pm_runtime_suspend()do the same thing after calling ->runtime_suspend callback. Or rather it did it before commit42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3") and third patch aimed fix this damage.More over seems like calling
pci_enable_wake()from e1000e isn't enough for my case, because my enthernet cannot wakeup from runtime-suspend without third patch. Seems like it's becausepci_enable_wake()andpci_finish_runtime_suspend()calls different pratform-pm callbacks --platform_pci_run_wake()/platform_pci_sleep_wake().
Quoted 4 lines
All this looks messy and I don't know how it should work.
If you prefer to minimize changes -- I can test how it would work without first (this) patch. Probably fine.
OK, I need to have a look at that driver, then. Please give me some time, though, I'm working on something different at the moment.
And by the way, by sending patches you declare that you know what you're doing. If you really don't, it's better to just describe the problem. :-)
Thanks,
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Re: [PATCH 1/5] e1000e: fix resuming from runtime-suspend
In reply to Konstantin KhlebnikovQuoted 49 lines · Konstantin Khlebnikov
Quoted 42 lines · Rafael J. Wysocki
Quoted 41 lines · Bjorn Helgaas
[+cc Rafael, author of patch you cited]
Quoted 37 lines · Konstantin Khlebnikov
Bug was introduced in commit
23606cf5d1192c2b17912cb2ef6e62f9b11de133("e1000e / PCI / PM: Add basic runtime PM support (rev. 4)") in v2.6.35Signed-off-by Konstantin Khlebnikov<[email protected]>Cc Jeff Kirsher<[email protected]>Cc Bruce Allan<[email protected]>--- drivers/net/ethernet/intel/e1000e/netdev.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)drivers/net/ethernet/intel/e1000e/netdev.c +8
-5@@ -5691,14 +5691,17 @@ static int e1000_runtime_suspend(struct device *dev)struct pci_dev *pdev =to_pci_dev (dev);struct net_device *netdev =pci_get_drvdata (pdev);struct e1000_adapter *adapter =netdev_priv (netdev); +int retval; +bool wake; -if (e1000e_pm_ready (adapter)) { -bool wake; +if (!e1000e_pm_ready (adapter)) +return 0 ; -__e1000_shutdown (pdev,&wake, true); - } + retval =__e1000_shutdown (pdev,&wake, true); +if (!retval) +e1000_power_off (pdev, true, wake); -return 0 ; +return retval; }Quoted 5 lines
Quoted 2 lines
drivers/net/ethernet/intel/e1000e/netdev.c static int e1000_runtime_suspend(struct device *dev) · line 5707
Quoted 2 lines
drivers/net/ethernet/intel/e1000e/netdev.c +0
-0static int e1000_idle (struct device *dev)I'd like the changelog to say what the bug is and how it is being fixed in general terms.
Quoted 7 lines
Ok, my bad.
Problem: ethernet device does not work (no carrier signal). Right after boot it goes to runtime-suspend and never wake up.
Original code (before your commit) calls
pci_prepare_to_sleep()and it callspci_enable_wake()and switches device to one of D3 state.
The original code in what function?
Quoted 7 lines
It seems redundant, because
pci_pm_runtime_suspend()do the same thing after calling ->runtime_suspend callback. Or rather it did it before commit42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3") and third patch aimed fix this damage.More over seems like calling
pci_enable_wake()from e1000e isn't enough for my case, because my enthernet cannot wakeup from runtime-suspend without third patch.
Which third patch?
Quoted 3 lines
Seems like it's because
pci_enable_wake()andpci_finish_runtime_suspend()calls different pratform-pm callbacks --platform_pci_run_wake()/platform_pci_sleep_wake().
That's correct, for historical reasons. We'll need to merge these things, but for now the are separate (because of the way ACPI handles system suspend and runtime PM).
Thanks,
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Re: [PATCH 1/5] e1000e: fix resuming from runtime-suspend
Quoted 52 lines · Rafael J. Wysocki
Quoted 51 lines · Konstantin Khlebnikov
Quoted 42 lines · Rafael J. Wysocki
Quoted 41 lines · Bjorn Helgaas
[+cc Rafael, author of patch you cited]
Quoted 37 lines · Konstantin Khlebnikov
Bug was introduced in commit
23606cf5d1192c2b17912cb2ef6e62f9b11de133("e1000e / PCI / PM: Add basic runtime PM support (rev. 4)") in v2.6.35Signed-off-by Konstantin Khlebnikov<[email protected]>Cc Jeff Kirsher<[email protected]>Cc Bruce Allan<[email protected]>--- drivers/net/ethernet/intel/e1000e/netdev.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)drivers/net/ethernet/intel/e1000e/netdev.c +8
-5@@ -5691,14 +5691,17 @@ static int e1000_runtime_suspend(struct device *dev)struct pci_dev *pdev =to_pci_dev (dev);struct net_device *netdev =pci_get_drvdata (pdev);struct e1000_adapter *adapter =netdev_priv (netdev); +int retval; +bool wake; -if (e1000e_pm_ready (adapter)) { -bool wake; +if (!e1000e_pm_ready (adapter)) +return 0 ; -__e1000_shutdown (pdev,&wake, true); - } + retval =__e1000_shutdown (pdev,&wake, true); +if (!retval) +e1000_power_off (pdev, true, wake); -return 0 ; +return retval; }Quoted 5 lines
Quoted 2 lines
drivers/net/ethernet/intel/e1000e/netdev.c static int e1000_runtime_suspend(struct device *dev) · line 5707
Quoted 2 lines
drivers/net/ethernet/intel/e1000e/netdev.c +0
-0static int e1000_idle (struct device *dev)I'd like the changelog to say what the bug is and how it is being fixed in general terms.
Ok, my bad.
Quoted 7 lines
Quoted 5 lines
Problem: ethernet device does not work (no carrier signal). Right after boot it goes to runtime-suspend and never wake up.
Original code (before your commit) calls
pci_prepare_to_sleep()and it callspci_enable_wake()and switches device to one of D3 state.The original code in what function?
Oh, I screwed up again. That commit adds support of runtime-pm, so there is no original code. But runtime-pm in 'igb' works in this way:igb_runtime_suspend() -> pci_prepare_to_sleep() -> pci_enable_wake()
Quoted 10 lines
Quoted 8 lines
It seems redundant, because
pci_pm_runtime_suspend()do the same thing after calling ->runtime_suspend callback. Or rather it did it before commit42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3") and third patch aimed fix this damage.More over seems like calling
pci_enable_wake()from e1000e isn't enough for my case, because my enthernet cannot wakeup from runtime-suspend without third patch.Which third patch?
third patch in this patchset:
"[PATCH 3/5] PCI: revert preparing for wakeup in runtime-suspend finalization"
Quoted 8 lines
Quoted 4 lines
Seems like it's because
pci_enable_wake()andpci_finish_runtime_suspend()calls different pratform-pm callbacks --platform_pci_run_wake()/platform_pci_sleep_wake().That's correct, for historical reasons. We'll need to merge these things, but for now the are separate (because of the way ACPI handles system suspend and runtime PM).
Ok, I have not read yet all code and documentation. But it seems runtime-pm engine needs some sort of runtime debug-mode which would warn about strange or ineffective actions in drivers, probably just script for parsing kernel-log and tracking states for all devices and buses.
Quoted 5 lines
Thanks,
Rafael
Re: [PATCH 1/5] e1000e: fix resuming from runtime-suspend
In reply to Konstantin KhlebnikovQuoted 22 lines · Konstantin Khlebnikov
Bug was introduced in commit
23606cf5d1192c2b17912cb2ef6e62f9b11de133("e1000e / PCI / PM: Add basic runtime PM support (rev. 4)") in v2.6.35Signed-off-by Konstantin Khlebnikov <[email protected]>Cc Jeff Kirsher <[email protected]>Cc Bruce Allan <[email protected]>--- drivers/net/ethernet/intel/e1000e/netdev.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)drivers/net/ethernet/intel/e1000e/netdev.c +2
-0@@ -5691,14 +5691,17 @@ static int e1000_runtime_suspend(struct device *dev)struct pci_dev *pdev =to_pci_dev (dev);struct net_device *netdev =pci_get_drvdata (pdev);struct e1000_adapter *adapter =netdev_priv (netdev); +int retval; +bool wake;
drivers/net/ethernet/intel/e1000e/netdev.c static int e1000_runtime_suspend(struct device *dev) · line 5702
Quoted 10 lines
drivers/net/ethernet/intel/e1000e/netdev.c +5
-4-if (e1000e_pm_ready (adapter)) { -bool wake; +if (!e1000e_pm_ready (adapter)) +return 0 ; -__e1000_shutdown (pdev, &wake, true); - } + retval =__e1000_shutdown (pdev, &wake, true); +if (!retval) +e1000_power_off (pdev, true, wake);
That needs to be pci_finish_runtime_suspend() (which needs to be exported for this purpose) or remove the pci_save_state() from __e1000_shutdown().
If the latter works, I'd very much prefer it.
Thanks,
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
PATCH 2/5 e1000e: fix pci device enable counter balance
In reply to Konstantin Khlebnikov__e1000_shutdown() calls pci_disable_device() at the end, thus __e1000_resume() should call pci_enable_device_mem() to keep enable counter in balance.
Bug was introduced in commit 23606cf5d1192c2b17912cb2ef6e62f9b11de133 ("e1000e / PCI / PM: Add basic runtime PM support (rev. 4)") in v2.6.35
--- drivers/net/ethernet/intel/e1000e/netdev.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/net/ethernet/intel/e1000e/netdev.c +7 -0
@@ -5598,6 +5598,13 @@ static int __e1000_resume(struct pci_dev *pdev)pci_restore_state (pdev);pci_save_state (pdev); + err =pci_enable_device_mem (pdev); +if (err) { +dev_err (&pdev->dev, +"Cannot re-enable PCI device after suspend.\n" ); +return err; + } +e1000e_set_interrupt_capability (adapter);if (netif_running (netdev)) { err =e1000_request_irq (adapter);
Re: [PATCH 2/5] e1000e: fix pci device enable counter balance
[+cc Rafael]
Quoted 19 lines · Konstantin Khlebnikov
__e1000_shutdown()callspci_disable_device()at the end, thus__e1000_resume()should callpci_enable_device_mem()to keep enable counter in balance.Bug was introduced in commit
23606cf5d1192c2b17912cb2ef6e62f9b11de133("e1000e / PCI / PM: Add basic runtime PM support (rev. 4)") in v2.6.35Signed-off-by Konstantin Khlebnikov <[email protected]>Cc Jeff Kirsher <[email protected]>Cc Bruce Allan <[email protected]>--- drivers/net/ethernet/intel/e1000e/netdev.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/net/ethernet/intel/e1000e/netdev.c +0
-0
drivers/net/ethernet/intel/e1000e/netdev.c static int __e1000_resume(struct pci_dev *pdev) · line 5606
Quoted 9 lines
drivers/net/ethernet/intel/e1000e/netdev.c +6
-0@@ -5598,6 +5598,13 @@ static int __e1000_resume(struct pci_dev *pdev)pci_restore_state (pdev);pci_save_state (pdev); + err =pci_enable_device_mem (pdev); +if (err) { +dev_err (&pdev->dev, +"Cannot re-enable PCI device after suspend.\n" ); +return err; + }
Seems right to me, and the other users I looked at (igb, azx, virtio_pci) call pci_disable_device() in .suspend() and call pci_enable_device() in .resume() as you propose to do here.
I assume the e1000 folks will handle this patch (and the previous one).
Quoted 9 lines
drivers/net/ethernet/intel/e1000e/netdev.c +1
-1+e1000e_set_interrupt_capability (adapter);if (netif_running (netdev)) { err =e1000_request_irq (adapter); --To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Bjorn Helgaas
maintainerRe: [PATCH 2/5] e1000e: fix pci device enable counter balance
[+cc Rafael @sisk.pl]
Quoted 35 lines · Bjorn Helgaas
[+cc Rafael]
Quoted 19 lines · Konstantin Khlebnikov
__e1000_shutdown()callspci_disable_device()at the end, thus__e1000_resume()should callpci_enable_device_mem()to keep enable counter in balance.Bug was introduced in commit
23606cf5d1192c2b17912cb2ef6e62f9b11de133("e1000e / PCI / PM: Add basic runtime PM support (rev. 4)") in v2.6.35Signed-off-by Konstantin Khlebnikov <[email protected]>Cc Jeff Kirsher <[email protected]>Cc Bruce Allan <[email protected]>--- drivers/net/ethernet/intel/e1000e/netdev.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/net/ethernet/intel/e1000e/netdev.c +0
-0drivers/net/ethernet/intel/e1000e/netdev.c static int __e1000_resume(struct pci_dev *pdev) · line 5606
Quoted 9 lines
drivers/net/ethernet/intel/e1000e/netdev.c +6
-0@@ -5598,6 +5598,13 @@ static int __e1000_resume(struct pci_dev *pdev)pci_restore_state (pdev);pci_save_state (pdev); + err =pci_enable_device_mem (pdev); +if (err) { +dev_err (&pdev->dev, +"Cannot re-enable PCI device after suspend.\n" ); +return err; + }Reviewed-by Bjorn Helgaas <[email protected]>
Quoted 11 lines
Seems right to me, and the other users I looked at (igb, azx,
virtio_pci) callpci_disable_device()in .suspend() and callpci_enable_device()in .resume() as you propose to do here.I assume the e1000 folks will handle this patch (and the previous one).
Quoted 5 lines
drivers/net/ethernet/intel/e1000e/netdev.c +1
-0+e1000e_set_interrupt_capability (adapter);if (netif_running (netdev)) { err =e1000_request_irq (adapter);
I'm still missing something. In your original report
(https://lkml.org/lkml/2013/1/1/25), you noticed that "enable_cnt == 0" immediately after boot, after e1000e had claimed the device:
Quoted 9 lines
Right after boot it looks like this:
root@zurg:/sys/bus/pci/devices# lspci ... 00:19.0 Ethernet controller: Intel Corporation 82579LM Gigabit Network Connection (rev 04) ... root@zurg:/sys/bus/pci/devices# cat 0000\:00\:19.0/enable 0 here must be '1', not '0'
But these patches only change the e1000e suspend/resume path. How could they change the enable_cnt before you've even done a suspend?
Bjorn
Re: [PATCH 2/5] e1000e: fix pci device enable counter balance
Quoted 50 lines · Bjorn Helgaas
[+cc Rafael @sisk.pl]
Quoted 35 lines · Bjorn Helgaas
[+cc Rafael]
Quoted 19 lines · Konstantin Khlebnikov
__e1000_shutdown()callspci_disable_device()at the end, thus__e1000_resume()should callpci_enable_device_mem()to keep enable counter in balance.Bug was introduced in commit
23606cf5d1192c2b17912cb2ef6e62f9b11de133("e1000e / PCI / PM: Add basic runtime PM support (rev. 4)") in v2.6.35Signed-off-by Konstantin Khlebnikov<[email protected]>Cc Jeff Kirsher<[email protected]>Cc Bruce Allan<[email protected]>--- drivers/net/ethernet/intel/e1000e/netdev.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/net/ethernet/intel/e1000e/netdev.c +0
-0drivers/net/ethernet/intel/e1000e/netdev.c static int __e1000_resume(struct pci_dev *pdev) · line 5606
Quoted 9 lines
drivers/net/ethernet/intel/e1000e/netdev.c +6
-0@@ -5598,6 +5598,13 @@ static int __e1000_resume(struct pci_dev *pdev)pci_restore_state (pdev);pci_save_state (pdev); + err =pci_enable_device_mem (pdev); +if (err) { +dev_err (&pdev->dev, +"Cannot re-enable PCI device after suspend.\n" ); +return err; + }Reviewed-by Bjorn Helgaas<[email protected]>Quoted 11 lines
Seems right to me, and the other users I looked at (igb, azx,
virtio_pci) callpci_disable_device()in .suspend() and callpci_enable_device()in .resume() as you propose to do here.I assume the e1000 folks will handle this patch (and the previous one).
Quoted 5 lines
drivers/net/ethernet/intel/e1000e/netdev.c +1
-0+e1000e_set_interrupt_capability (adapter);if (netif_running (netdev)) { err =e1000_request_irq (adapter);
Quoted 3 lines
I'm still missing something. In your original report
(https://lkml.org/lkml/2013/1/1/25), you noticed that "enable_cnt== 0" immediately after boot, after e1000e had claimed the device:
Yep, it rise counter from 0 to 1, and runtime-suspend immediately decrease it back to 0.
Quoted 11 lines
Quoted 10 lines
Right after boot it looks like this:
root@zurg:/sys/bus/pci/devices# lspci ... 00:19.0 Ethernet controller: Intel Corporation 82579LM Gigabit Network Connection (rev 04) ... root@zurg:/sys/bus/pci/devices# cat 0000\:00\:19.0/enable 0 here must be '1', not '0'
Quoted 2 lines
But these patches only change the e1000e suspend/resume path. How could they change the
enable_cntbefore you've even done a suspend?
suspend/resume and runtime_suspend/runtime_resume callbacks calls the one set of functions: __e1000_shutdown() / __e1000_resume()
Any suspend-resume cycle breaks enable_ent balance.
Thus right after boot and first runtime-suspend device cannot wake up due to first sort of bugs and after first s2ram suspend-resume cycle driver breaks it's enable_cnt and device no longer can sleep due to second sort of bugs.
Quoted 2 lines
Bjorn
Rafael J. Wysocki
Acked-byRe: [PATCH 2/5] e1000e: fix pci device enable counter balance
In reply to Bjorn HelgaasQuoted 35 lines · Bjorn Helgaas
[+cc Rafael]
Quoted 19 lines · Konstantin Khlebnikov
__e1000_shutdown()callspci_disable_device()at the end, thus__e1000_resume()should callpci_enable_device_mem()to keep enable counter in balance.Bug was introduced in commit
23606cf5d1192c2b17912cb2ef6e62f9b11de133("e1000e / PCI / PM: Add basic runtime PM support (rev. 4)") in v2.6.35Signed-off-by Konstantin Khlebnikov <[email protected]>Cc Jeff Kirsher <[email protected]>Cc Bruce Allan <[email protected]>--- drivers/net/ethernet/intel/e1000e/netdev.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/net/ethernet/intel/e1000e/netdev.c +0
-0drivers/net/ethernet/intel/e1000e/netdev.c static int __e1000_resume(struct pci_dev *pdev) · line 5606
Quoted 9 lines
drivers/net/ethernet/intel/e1000e/netdev.c +6
-0@@ -5598,6 +5598,13 @@ static int __e1000_resume(struct pci_dev *pdev)pci_restore_state (pdev);pci_save_state (pdev); + err =pci_enable_device_mem (pdev); +if (err) { +dev_err (&pdev->dev, +"Cannot re-enable PCI device after suspend.\n" ); +return err; + }Reviewed-by Bjorn Helgaas <[email protected]>
Quoted 6 lines
Seems right to me, and the other users I looked at (igb, azx,
virtio_pci) callpci_disable_device()in .suspend() and callpci_enable_device()in .resume() as you propose to do here.I assume the e1000 folks will handle this patch (and the previous one).
OK, so this one looks like a genuine fix to me.
Thanks,
Rafael
Quoted 6 lines
Quoted 6 lines
drivers/net/ethernet/intel/e1000e/netdev.c +1
-1+e1000e_set_interrupt_capability (adapter);if (netif_running (netdev)) { err =e1000_request_irq (adapter); --
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
PATCH 3/5 PCI: revert preparing for wakeup in runtime-suspend finalization
In reply to Konstantin KhlebnikovThis patch effectively reverts commit 42eca2302146fed51335b95128e949ee6f54478f ("PCI: Don't touch card regs after runtime suspend D3")
| This patch checks whether the pci state is saved and doesn't attempt to hit | any registers after that point if it is.
This seems completely wrong. Yes, PCI configuration space has been saved by driver, but this doesn't means that all job is done and device has been suspended and ready for waking up in the future.
For example driver e1000e for ethernet in my thinkpad x220 saves pci-state but device cannot wakeup after that, because it needs some ACPI callbacks which usually called from pci_finish_runtime_suspend().
| Optimus (dual-gpu) laptops seem to have their own form of D3cold, but | unfortunately enter it on normal D3 transitions via the ACPI callback.
Hardware which disappears from the bus unexpectedly is exception, so let's handle it as an exception. Its driver should set device state to D3cold and the rest code will handle it properly.
--- drivers/pci/pci-driver.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/pci/pci-driver.c +3 -2
@@ -1005,10 +1005,11 @@ static int pci_pm_runtime_suspend(struct device *dev)return 0 ; } -if (!pci_dev->state_saved) { +if (!pci_dev->state_saved)pci_save_state (pci_dev); + +if (pci_dev->current_state != PCI_D3cold)pci_finish_runtime_suspend (pci_dev); - }return 0 ; }
Bjorn Helgaas
maintainerRe: [PATCH 3/5] PCI: revert preparing for wakeup in runtime-suspend finalization
[+cc Rafael]
Quoted 14 lines · Konstantin Khlebnikov
This patch effectively reverts commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3")| This patch checks whether the pci state is saved and doesn't attempt to hit | any registers after that point if it is.
This seems completely wrong. Yes, PCI configuration space has been saved by driver, but this doesn't means that all job is done and device has been suspended and ready for waking up in the future.
For example driver e1000e for ethernet in my thinkpad x220 saves pci-state but device cannot wakeup after that, because it needs some ACPI callbacks which usually called from
pci_finish_runtime_suspend().
Quoted 6 lines
| Optimus (dual-gpu) laptops seem to have their own form of D3cold, but | unfortunately enter it on normal D3 transitions via the ACPI callback.
Hardware which disappears from the bus unexpectedly is exception, so let's handle it as an exception. Its driver should set device state to D3cold and the rest code will handle it properly.
Functions in D3cold don't have power, so it's completely expected that they would disappear from the bus and not respond to config accesses. Maybe Dave was referring to D3hot, where functions *should* respond to config accesses. I dunno.
Just to be clear, it sounds like 42eca230 caused a regression on your e1000e device? If so, I guess we should revert it unless you and Dave can figure out a better patch that fixes both your e1000e device and the Optimus issue.
Quoted 27 lines
Signed-off-by Konstantin Khlebnikov <[email protected]>Cc Bjorn Helgaas <[email protected]>Cc Dave Airlie <[email protected]>--- drivers/pci/pci-driver.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/pci/pci-driver.c +3
-2@@ -1005,10 +1005,11 @@ static int pci_pm_runtime_suspend(struct device *dev)return 0 ; } -if (!pci_dev->state_saved) { +if (!pci_dev->state_saved)pci_save_state (pci_dev); + +if (pci_dev->current_state != PCI_D3cold)pci_finish_runtime_suspend (pci_dev); - }return 0 ; }
Re: [PATCH 3/5] PCI: revert preparing for wakeup in runtime-suspend finalization
Quoted 30 lines · Bjorn Helgaas
[+cc Rafael]
Quoted 14 lines · Konstantin Khlebnikov
This patch effectively reverts commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3")| This patch checks whether the pci state is saved and doesn't attempt to hit | any registers after that point if it is.
This seems completely wrong. Yes, PCI configuration space has been saved by driver, but this doesn't means that all job is done and device has been suspended and ready for waking up in the future.
For example driver e1000e for ethernet in my thinkpad x220 saves pci-state but device cannot wakeup after that, because it needs some ACPI callbacks which usually called from
pci_finish_runtime_suspend().Quoted 6 lines
| Optimus (dual-gpu) laptops seem to have their own form of D3cold, but | unfortunately enter it on normal D3 transitions via the ACPI callback.
Hardware which disappears from the bus unexpectedly is exception, so let's handle it as an exception. Its driver should set device state to D3cold and the rest code will handle it properly.
Functions in D3cold don't have power, so it's completely expected that they would disappear from the bus and not respond to config accesses. Maybe Dave was referring to D3hot, where functions *should* respond to config accesses. I dunno.
Quoted 4 lines
Just to be clear, it sounds like
42eca230caused a regression on your e1000e device? If so, I guess we should revert it unless you and Dave can figure out a better patch that fixes both your e1000e device and the Optimus issue.
Yes, if there's a regression, let's revert it, but I'd like the regression to be described clearly.
Thanks,
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Re: [PATCH 3/5] PCI: revert preparing for wakeup in runtime-suspend finalization
Quoted 31 lines · Rafael J. Wysocki
Quoted 30 lines · Bjorn Helgaas
[+cc Rafael]
Quoted 14 lines · Konstantin Khlebnikov
This patch effectively reverts commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3")| This patch checks whether the pci state is saved and doesn't attempt to hit | any registers after that point if it is.
This seems completely wrong. Yes, PCI configuration space has been saved by driver, but this doesn't means that all job is done and device has been suspended and ready for waking up in the future.
For example driver e1000e for ethernet in my thinkpad x220 saves pci-state but device cannot wakeup after that, because it needs some ACPI callbacks which usually called from
pci_finish_runtime_suspend().Quoted 6 lines
| Optimus (dual-gpu) laptops seem to have their own form of D3cold, but | unfortunately enter it on normal D3 transitions via the ACPI callback.
Hardware which disappears from the bus unexpectedly is exception, so let's handle it as an exception. Its driver should set device state to D3cold and the rest code will handle it properly.
Functions in D3cold don't have power, so it's completely expected that they would disappear from the bus and not respond to config accesses. Maybe Dave was referring to D3hot, where functions *should* respond to config accesses. I dunno.
Quoted 7 lines
Quoted 4 lines
Just to be clear, it sounds like
42eca230caused a regression on your e1000e device? If so, I guess we should revert it unless you and Dave can figure out a better patch that fixes both your e1000e device and the Optimus issue.Yes, if there's a regression, let's revert it, but I'd like the regression to be described clearly.
Yep, this is regression.
commit 42eca2302146fed51335b95128e949ee6f54478f ("PCI: Don't touch card regs after runtime suspend D3") changes state convention during runtime-suspend transaction too much. If PCI configuration space has been saved by driver that does not means that all job is done and device has been suspended and ready for waking up in the future.
e1000e saves pci-config space itself, but it requires operations which pci_finish_runtime_suspend() does: preparing for wake (calling particular platform pm-callbacks) and switching to proper sleep state.
Quoted 5 lines
Thanks,
Rafael
Re: [PATCH 3/5] PCI: revert preparing for wakeup in runtime-suspend finalization
Quoted 48 lines · Konstantin Khlebnikov
Quoted 31 lines · Rafael J. Wysocki
Quoted 30 lines · Bjorn Helgaas
[+cc Rafael]
Quoted 14 lines · Konstantin Khlebnikov
This patch effectively reverts commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3")| This patch checks whether the pci state is saved and doesn't attempt to hit | any registers after that point if it is.
This seems completely wrong. Yes, PCI configuration space has been saved by driver, but this doesn't means that all job is done and device has been suspended and ready for waking up in the future.
For example driver e1000e for ethernet in my thinkpad x220 saves pci-state but device cannot wakeup after that, because it needs some ACPI callbacks which usually called from
pci_finish_runtime_suspend().Quoted 6 lines
| Optimus (dual-gpu) laptops seem to have their own form of D3cold, but | unfortunately enter it on normal D3 transitions via the ACPI callback.
Hardware which disappears from the bus unexpectedly is exception, so let's handle it as an exception. Its driver should set device state to D3cold and the rest code will handle it properly.
Functions in D3cold don't have power, so it's completely expected that they would disappear from the bus and not respond to config accesses. Maybe Dave was referring to D3hot, where functions *should* respond to config accesses. I dunno.
Quoted 7 lines
Quoted 4 lines
Just to be clear, it sounds like
42eca230caused a regression on your e1000e device? If so, I guess we should revert it unless you and Dave can figure out a better patch that fixes both your e1000e device and the Optimus issue.Yes, if there's a regression, let's revert it, but I'd like the regression to be described clearly.
Yep, this is regression.
commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3") changes state convention during runtime-suspend transaction too much. If PCI configuration space has been saved by driver that does not means that all job is done and device has been suspended and ready for waking up in the future.
Quoted 3 lines
e1000e saves pci-config space itself, but it requires operations which
pci_finish_runtime_suspend()does: preparing for wake (calling particular platform pm-callbacks) and switching to proper sleep state.
Well, I'd argue this is a bug in e1000e. Why does it need to save the PCI config space even though pci_pm_runtime_suspend() will do that anyway?
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Re: [PATCH 3/5] PCI: revert preparing for wakeup in runtime-suspend finalization
Quoted 49 lines · Rafael J. Wysocki
Quoted 48 lines · Konstantin Khlebnikov
Quoted 31 lines · Rafael J. Wysocki
Quoted 30 lines · Bjorn Helgaas
[+cc Rafael]
Quoted 14 lines · Konstantin Khlebnikov
This patch effectively reverts commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3")| This patch checks whether the pci state is saved and doesn't attempt to hit | any registers after that point if it is.
This seems completely wrong. Yes, PCI configuration space has been saved by driver, but this doesn't means that all job is done and device has been suspended and ready for waking up in the future.
For example driver e1000e for ethernet in my thinkpad x220 saves pci-state but device cannot wakeup after that, because it needs some ACPI callbacks which usually called from
pci_finish_runtime_suspend().Quoted 6 lines
| Optimus (dual-gpu) laptops seem to have their own form of D3cold, but | unfortunately enter it on normal D3 transitions via the ACPI callback.
Hardware which disappears from the bus unexpectedly is exception, so let's handle it as an exception. Its driver should set device state to D3cold and the rest code will handle it properly.
Functions in D3cold don't have power, so it's completely expected that they would disappear from the bus and not respond to config accesses. Maybe Dave was referring to D3hot, where functions *should* respond to config accesses. I dunno.
Quoted 7 lines
Quoted 4 lines
Just to be clear, it sounds like
42eca230caused a regression on your e1000e device? If so, I guess we should revert it unless you and Dave can figure out a better patch that fixes both your e1000e device and the Optimus issue.Yes, if there's a regression, let's revert it, but I'd like the regression to be described clearly.
Yep, this is regression.
commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3") changes state convention during runtime-suspend transaction too much. If PCI configuration space has been saved by driver that does not means that all job is done and device has been suspended and ready for waking up in the future.
Quoted 6 lines
Quoted 3 lines
e1000e saves pci-config space itself, but it requires operations which
pci_finish_runtime_suspend()does: preparing for wake (calling particular platform pm-callbacks) and switching to proper sleep state.Well, I'd argue this is a bug in e1000e. Why does it need to save the PCI config space even though
pci_pm_runtime_suspend()will do that anyway?
I honestly don't think we should revert 42eca2302146 because of this.
Yes, there is a requirement that drivers not save the PCI config space by themselves unless they want to do the whole power management by themselves too and e1000e is not following that. So either we need to drop the pci_save_state() from __e1000_shutdown() which I would prefer (I'm not really sure why it is there), or e1000_runtime_suspend() needs to call pci_finish_runtime_suspend() by itself.
Thanks,
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Re: [PATCH 3/5] PCI: revert preparing for wakeup in runtime-suspend finalization
Quoted 57 lines · Rafael J. Wysocki
Quoted 49 lines · Rafael J. Wysocki
Quoted 48 lines · Konstantin Khlebnikov
Quoted 31 lines · Rafael J. Wysocki
Quoted 30 lines · Bjorn Helgaas
[+cc Rafael]
Quoted 14 lines · Konstantin Khlebnikov
This patch effectively reverts commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3")| This patch checks whether the pci state is saved and doesn't attempt to hit | any registers after that point if it is.
This seems completely wrong. Yes, PCI configuration space has been saved by driver, but this doesn't means that all job is done and device has been suspended and ready for waking up in the future.
For example driver e1000e for ethernet in my thinkpad x220 saves pci-state but device cannot wakeup after that, because it needs some ACPI callbacks which usually called from
pci_finish_runtime_suspend().Quoted 6 lines
| Optimus (dual-gpu) laptops seem to have their own form of D3cold, but | unfortunately enter it on normal D3 transitions via the ACPI callback.
Hardware which disappears from the bus unexpectedly is exception, so let's handle it as an exception. Its driver should set device state to D3cold and the rest code will handle it properly.
Functions in D3cold don't have power, so it's completely expected that they would disappear from the bus and not respond to config accesses. Maybe Dave was referring to D3hot, where functions *should* respond to config accesses. I dunno.
Quoted 7 lines
Quoted 4 lines
Just to be clear, it sounds like
42eca230caused a regression on your e1000e device? If so, I guess we should revert it unless you and Dave can figure out a better patch that fixes both your e1000e device and the Optimus issue.Yes, if there's a regression, let's revert it, but I'd like the regression to be described clearly.
Yep, this is regression.
commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3") changes state convention during runtime-suspend transaction too much. If PCI configuration space has been saved by driver that does not means that all job is done and device has been suspended and ready for waking up in the future.Quoted 6 lines
Quoted 3 lines
e1000e saves pci-config space itself, but it requires operations which
pci_finish_runtime_suspend()does: preparing for wake (calling particular platform pm-callbacks) and switching to proper sleep state.Well, I'd argue this is a bug in e1000e. Why does it need to save the PCI config space even though
pci_pm_runtime_suspend()will do that anyway?
Quoted 8 lines
I honestly don't think we should revert
42eca2302146because of this.Yes, there is a requirement that drivers not save the PCI config space by themselves unless they want to do the whole power management by themselves too and e1000e is not following that. So either we need to drop the
pci_save_state()from__e1000_shutdown()which I would prefer (I'm not really sure why it is there), ore1000_runtime_suspend()needs to callpci_finish_runtime_suspend()by itself.
Yet another problem: some drivers calls pci_save_state() from ->probe() callback to use this saved state in pci_error_handlers->slot_reset().
As result pdev->state_saved is true mostly all time.
At least e1000e and drivers/pci/pcie/portdrv_pci.c are doing this.
I think it will be safer to revert 42eca2302146 in v3.8
Re: [PATCH 3/5] PCI: revert preparing for wakeup in runtime-suspend finalization
Quoted 67 lines · Konstantin Khlebnikov
Quoted 57 lines · Rafael J. Wysocki
Quoted 49 lines · Rafael J. Wysocki
Quoted 48 lines · Konstantin Khlebnikov
Quoted 31 lines · Rafael J. Wysocki
Quoted 30 lines · Bjorn Helgaas
[+cc Rafael]
Quoted 14 lines · Konstantin Khlebnikov
This patch effectively reverts commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3")| This patch checks whether the pci state is saved and doesn't attempt to hit | any registers after that point if it is.
This seems completely wrong. Yes, PCI configuration space has been saved by driver, but this doesn't means that all job is done and device has been suspended and ready for waking up in the future.
For example driver e1000e for ethernet in my thinkpad x220 saves pci-state but device cannot wakeup after that, because it needs some ACPI callbacks which usually called from
pci_finish_runtime_suspend().Quoted 6 lines
| Optimus (dual-gpu) laptops seem to have their own form of D3cold, but | unfortunately enter it on normal D3 transitions via the ACPI callback.
Hardware which disappears from the bus unexpectedly is exception, so let's handle it as an exception. Its driver should set device state to D3cold and the rest code will handle it properly.
Functions in D3cold don't have power, so it's completely expected that they would disappear from the bus and not respond to config accesses. Maybe Dave was referring to D3hot, where functions *should* respond to config accesses. I dunno.
Quoted 7 lines
Quoted 4 lines
Just to be clear, it sounds like
42eca230caused a regression on your e1000e device? If so, I guess we should revert it unless you and Dave can figure out a better patch that fixes both your e1000e device and the Optimus issue.Yes, if there's a regression, let's revert it, but I'd like the regression to be described clearly.
Yep, this is regression.
commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3") changes state convention during runtime-suspend transaction too much. If PCI configuration space has been saved by driver that does not means that all job is done and device has been suspended and ready for waking up in the future.Quoted 6 lines
Quoted 3 lines
e1000e saves pci-config space itself, but it requires operations which
pci_finish_runtime_suspend()does: preparing for wake (calling particular platform pm-callbacks) and switching to proper sleep state.Well, I'd argue this is a bug in e1000e. Why does it need to save the PCI config space even though
pci_pm_runtime_suspend()will do that anyway?Quoted 8 lines
I honestly don't think we should revert
42eca2302146because of this.Yes, there is a requirement that drivers not save the PCI config space by themselves unless they want to do the whole power management by themselves too and e1000e is not following that. So either we need to drop the
pci_save_state()from__e1000_shutdown()which I would prefer (I'm not really sure why it is there), ore1000_runtime_suspend()needs to callpci_finish_runtime_suspend()by itself.
Quoted 6 lines
Yet another problem: some drivers calls
pci_save_state()from ->probe() callback to use this saved state inpci_error_handlers->slot_reset().
As resultpdev->state_savedis true mostly all time.
At least e1000e anddrivers/pci/pcie/portdrv_pci.care doing this.I think it will be safer to revert
42eca2302146in v3.8
Well, I wonder if we can just do something like the appended patch instead and address the e1000e runtime suspend by calling pci_finish_runtime_suspend() directly from e1000_runtime_suspend().
While we can revert commit 42eca2302146, that hardly would be progress, because then the issue it was supposed to address would still need to be addressed somehow.
Thanks,
Rafael
--- drivers/pci/pci-driver.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/pci/pci-driver.c +4 -0
@@ -628,6 +628,7 @@ static int pci_pm_suspend(struct device goto Fixup; } + pci_dev->state_saved = false;if (pm->suspend) {pci_power_t prev = pci_dev->current_state;int error;
@@ -774,6 +775,7 @@ static int pci_pm_freeze(struct device *return 0 ; } + pci_dev->state_saved = false;if (pm->freeze) {int error;
@@ -862,6 +864,7 @@ static int pci_pm_poweroff(struct device goto Fixup; } + pci_dev->state_saved = false;if (pm->poweroff) {int error;
@@ -987,6 +990,7 @@ static int pci_pm_runtime_suspend(structif (!pm || !pm->runtime_suspend)return -ENOSYS ; + pci_dev->state_saved = false; pci_dev->no_d3cold = false; error = pm->runtime_suspend (dev);suspend_report_result (pm->runtime_suspend, error);
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Re: [PATCH 3/5] PCI: revert preparing for wakeup in runtime-suspend finalization
Quoted 116 lines · Rafael J. Wysocki
Quoted 67 lines · Konstantin Khlebnikov
Quoted 57 lines · Rafael J. Wysocki
Quoted 49 lines · Rafael J. Wysocki
Quoted 48 lines · Konstantin Khlebnikov
Quoted 31 lines · Rafael J. Wysocki
Quoted 30 lines · Bjorn Helgaas
[+cc Rafael]
Quoted 14 lines · Konstantin Khlebnikov
This patch effectively reverts commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3")| This patch checks whether the pci state is saved and doesn't attempt to hit | any registers after that point if it is.
This seems completely wrong. Yes, PCI configuration space has been saved by driver, but this doesn't means that all job is done and device has been suspended and ready for waking up in the future.
For example driver e1000e for ethernet in my thinkpad x220 saves pci-state but device cannot wakeup after that, because it needs some ACPI callbacks which usually called from
pci_finish_runtime_suspend().Quoted 6 lines
| Optimus (dual-gpu) laptops seem to have their own form of D3cold, but | unfortunately enter it on normal D3 transitions via the ACPI callback.
Hardware which disappears from the bus unexpectedly is exception, so let's handle it as an exception. Its driver should set device state to D3cold and the rest code will handle it properly.
Functions in D3cold don't have power, so it's completely expected that they would disappear from the bus and not respond to config accesses. Maybe Dave was referring to D3hot, where functions *should* respond to config accesses. I dunno.
Quoted 7 lines
Quoted 4 lines
Just to be clear, it sounds like
42eca230caused a regression on your e1000e device? If so, I guess we should revert it unless you and Dave can figure out a better patch that fixes both your e1000e device and the Optimus issue.Yes, if there's a regression, let's revert it, but I'd like the regression to be described clearly.
Yep, this is regression.
commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3") changes state convention during runtime-suspend transaction too much. If PCI configuration space has been saved by driver that does not means that all job is done and device has been suspended and ready for waking up in the future.Quoted 6 lines
Quoted 3 lines
e1000e saves pci-config space itself, but it requires operations which
pci_finish_runtime_suspend()does: preparing for wake (calling particular platform pm-callbacks) and switching to proper sleep state.Well, I'd argue this is a bug in e1000e. Why does it need to save the PCI config space even though
pci_pm_runtime_suspend()will do that anyway?Quoted 8 lines
I honestly don't think we should revert
42eca2302146because of this.Yes, there is a requirement that drivers not save the PCI config space by themselves unless they want to do the whole power management by themselves too and e1000e is not following that. So either we need to drop the
pci_save_state()from__e1000_shutdown()which I would prefer (I'm not really sure why it is there), ore1000_runtime_suspend()needs to callpci_finish_runtime_suspend()by itself.Quoted 6 lines
Yet another problem: some drivers calls
pci_save_state()from ->probe() callback to use this saved state inpci_error_handlers->slot_reset().
As resultpdev->state_savedis true mostly all time.
At least e1000e anddrivers/pci/pcie/portdrv_pci.care doing this.I think it will be safer to revert
42eca2302146in v3.8Well, I wonder if we can just do something like the appended patch instead and address the e1000e runtime suspend by calling
pci_finish_runtime_suspend()directly frome1000_runtime_suspend().While we can revert commit
42eca2302146, that hardly would be progress, because then the issue it was supposed to address would still need to be addressed somehow.--- drivers/pci/pci-driver.c | 4 ++++ 1 file changed, 4 insertions(+)Index:
linux-pm/drivers/pci/pci-driver.c
===================================================================drivers/pci/pci-driver.c +3
-0@@ -628,6 +628,7 @@ static int pci_pm_suspend(struct device goto Fixup; } + pci_dev->state_saved = false;if (pm->suspend) {pci_power_t prev = pci_dev->current_state;int error;@@ -774,6 +775,7 @@ static int pci_pm_freeze(struct device *return 0 ; } + pci_dev->state_saved = false;if (pm->freeze) {int error;@@ -862,6 +864,7 @@ static int pci_pm_poweroff(struct device goto Fixup; } + pci_dev->state_saved = false;if (pm->poweroff) {int error;
drivers/pci/pci-driver.c static int pci_pm_runtime_suspend(struct · line 996
Quoted 7 lines
drivers/pci/pci-driver.c +1
-0@@ -987,6 +990,7 @@ static int pci_pm_runtime_suspend(structif (!pm || !pm->runtime_suspend)return -ENOSYS ; + pci_dev->state_saved = false; pci_dev->no_d3cold = false; error = pm->runtime_suspend (dev);suspend_report_result (pm->runtime_suspend, error);
For completness, on top of the above one.
--- drivers/net/ethernet/intel/e1000e/netdev.c | 1 + drivers/pci/pci.c | 1 + drivers/pci/pci.h | 1 - include/linux/pci.h | 1 + 4 files changed, 3 insertions(+), 1 deletion(-)
drivers/pci/pci.c +1 -0
@@ -1840,6 +1840,7 @@ int pci_finish_runtime_suspend(struct pcreturn error; } +EXPORT_SYMBOL_GPL (pci_finish_runtime_suspend);/** * pci_dev_run_wake - Check if device can generate run-time wake-up events.
drivers/pci/pci.h +0 -1
@@ -64,7 +64,6 @@ extern int pci_set_platform_pm(struct pcextern void pci_update_current_state (struct pci_dev *dev,pci_power_t state);extern void pci_power_up (struct pci_dev *dev);extern void pci_disable_enabled_device (struct pci_dev *dev); -extern int pci_finish_runtime_suspend (struct pci_dev *dev);extern int __pci_pme_wakeup (struct pci_dev *dev,void *ign);extern void pci_wakeup_bus (struct pci_bus *bus);extern void pci_config_pm_runtime_get (struct pci_dev *dev);
include/linux/pci.h +1 -0
@@ -936,6 +936,7 @@ int pci_back_from_sleep(struct pci_dev *bool pci_dev_run_wake (struct pci_dev *dev);bool pci_check_pme_status (struct pci_dev *dev);void pci_pme_wakeup_bus (struct pci_bus *bus); +int pci_finish_runtime_suspend (struct pci_dev *dev);static inline int pci_enable_wake (struct pci_dev *dev,pci_power_t state,bool enable)
drivers/net/ethernet/intel/e1000e/netdev.c +1 -0
@@ -5696,6 +5696,7 @@ static int e1000_runtime_suspend(structbool wake;__e1000_shutdown (pdev, &wake, true); +pci_finish_runtime_suspend (pdev); }return 0 ;
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Re: [PATCH 3/5] PCI: revert preparing for wakeup in runtime-suspend finalization
Quoted 120 lines · Rafael J. Wysocki
Quoted 119 lines · Rafael J. Wysocki
Quoted 67 lines · Konstantin Khlebnikov
Quoted 57 lines · Rafael J. Wysocki
Quoted 49 lines · Rafael J. Wysocki
Quoted 48 lines · Konstantin Khlebnikov
Quoted 31 lines · Rafael J. Wysocki
Quoted 30 lines · Bjorn Helgaas
[+cc Rafael]
Quoted 14 lines · Konstantin Khlebnikov
This patch effectively reverts commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3")| This patch checks whether the pci state is saved and doesn't attempt to hit | any registers after that point if it is.
This seems completely wrong. Yes, PCI configuration space has been saved by driver, but this doesn't means that all job is done and device has been suspended and ready for waking up in the future.
For example driver e1000e for ethernet in my thinkpad x220 saves pci-state but device cannot wakeup after that, because it needs some ACPI callbacks which usually called from
pci_finish_runtime_suspend().Quoted 6 lines
| Optimus (dual-gpu) laptops seem to have their own form of D3cold, but | unfortunately enter it on normal D3 transitions via the ACPI callback.
Hardware which disappears from the bus unexpectedly is exception, so let's handle it as an exception. Its driver should set device state to D3cold and the rest code will handle it properly.
Functions in D3cold don't have power, so it's completely expected that they would disappear from the bus and not respond to config accesses. Maybe Dave was referring to D3hot, where functions *should* respond to config accesses. I dunno.
Quoted 7 lines
Quoted 4 lines
Just to be clear, it sounds like
42eca230caused a regression on your e1000e device? If so, I guess we should revert it unless you and Dave can figure out a better patch that fixes both your e1000e device and the Optimus issue.Yes, if there's a regression, let's revert it, but I'd like the regression to be described clearly.
Yep, this is regression.
commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3") changes state convention during runtime-suspend transaction too much. If PCI configuration space has been saved by driver that does not means that all job is done and device has been suspended and ready for waking up in the future.Quoted 6 lines
Quoted 3 lines
e1000e saves pci-config space itself, but it requires operations which
pci_finish_runtime_suspend()does: preparing for wake (calling particular platform pm-callbacks) and switching to proper sleep state.Well, I'd argue this is a bug in e1000e. Why does it need to save the PCI config space even though
pci_pm_runtime_suspend()will do that anyway?Quoted 8 lines
I honestly don't think we should revert
42eca2302146because of this.Yes, there is a requirement that drivers not save the PCI config space by themselves unless they want to do the whole power management by themselves too and e1000e is not following that. So either we need to drop the
pci_save_state()from__e1000_shutdown()which I would prefer (I'm not really sure why it is there), ore1000_runtime_suspend()needs to callpci_finish_runtime_suspend()by itself.Quoted 6 lines
Yet another problem: some drivers calls
pci_save_state()from ->probe() callback to use this saved state inpci_error_handlers->slot_reset().
As resultpdev->state_savedis true mostly all time.
At least e1000e anddrivers/pci/pcie/portdrv_pci.care doing this.I think it will be safer to revert
42eca2302146in v3.8Well, I wonder if we can just do something like the appended patch instead and address the e1000e runtime suspend by calling
pci_finish_runtime_suspend()directly frome1000_runtime_suspend().While we can revert commit
42eca2302146, that hardly would be progress, because then the issue it was supposed to address would still need to be addressed somehow.--- drivers/pci/pci-driver.c | 4 ++++ 1 file changed, 4 insertions(+)Index:
linux-pm/drivers/pci/pci-driver.c
===================================================================drivers/pci/pci-driver.c +3
-0@@ -628,6 +628,7 @@ static int pci_pm_suspend(struct device goto Fixup; } + pci_dev->state_saved = false;if (pm->suspend) {pci_power_t prev = pci_dev->current_state;int error;@@ -774,6 +775,7 @@ static int pci_pm_freeze(struct device *return 0 ; } + pci_dev->state_saved = false;if (pm->freeze) {int error;@@ -862,6 +864,7 @@ static int pci_pm_poweroff(struct device goto Fixup; } + pci_dev->state_saved = false;if (pm->poweroff) {int error;@@ -987,6 +990,7 @@ static int pci_pm_runtime_suspend(structif (!pm || !pm->runtime_suspend)return -ENOSYS ;
Quoted 6 lines
drivers/pci/pci-driver.c static int pci_pm_runtime_suspend(struct · line 996
Quoted 4 lines
drivers/pci/pci-driver.c +1
-0+ pci_dev->state_saved = false; pci_dev->no_d3cold = false; error = pm->runtime_suspend (dev);suspend_report_result (pm->runtime_suspend, error);For completness, on top of the above one.
I would prefer to remove pci_save_state() from e1000e_runtime_suspend().
drivers/net/ethernet/intel/e1000e/netdev.c +5 -3
@@ -5429,9 +5429,11 @@ static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake, }e1000e_reset_interrupt_capability (adapter); - retval =pci_save_state (pdev); -if (retval) -return retval; +if (!runtime) { + retval =pci_save_state (pdev); +if (retval) +return retval; + } status =er32 (STATUS );if (status &E1000_STATUS_LU )
I found another problem in e1000e: it does not calls pci_enable_master() in 'resume' functions, but it disables 'bus-mastering' on suspending. Thus if pci_save_state() is called after clearing that bit whole device wouldn't work after resuming.
drivers/net/ethernet/intel/e1000e/netdev.c +1 -0
@@ -5598,6 +5598,7 @@ static int __e1000_resume(struct pci_dev *pdev)pci_set_power_state (pdev,PCI_D0 );pci_restore_state (pdev); +pci_set_master (pdev);pci_save_state (pdev); err =pci_enable_device_mem (pdev);
Quoted 59 lines
--- drivers/net/ethernet/intel/e1000e/netdev.c | 1 + drivers/pci/pci.c | 1 + drivers/pci/pci.h | 1 - include/linux/pci.h | 1 + 4 files changed, 3 insertions(+), 1 deletion(-)Index:
linux-pm/drivers/pci/pci.c
===================================================================drivers/pci/pci.c +1
-0@@ -1840,6 +1840,7 @@ int pci_finish_runtime_suspend(struct pcreturn error; } +EXPORT_SYMBOL_GPL (pci_finish_runtime_suspend);/** * pci_dev_run_wake - Check if device can generate run-time wake-up events. Index:
linux-pm/drivers/pci/pci.h
===================================================================drivers/pci/pci.h +0
-1@@ -64,7 +64,6 @@ extern int pci_set_platform_pm(struct pcextern void pci_update_current_state (struct pci_dev *dev,pci_power_t state);extern void pci_power_up (struct pci_dev *dev);extern void pci_disable_enabled_device (struct pci_dev *dev); -extern int pci_finish_runtime_suspend (struct pci_dev *dev);extern int __pci_pme_wakeup (struct pci_dev *dev,void *ign);extern void pci_wakeup_bus (struct pci_bus *bus);extern void pci_config_pm_runtime_get (struct pci_dev *dev);Index:
linux-pm/include/linux/pci.h
===================================================================include/linux/pci.h +1
-0@@ -936,6 +936,7 @@ int pci_back_from_sleep(struct pci_dev *bool pci_dev_run_wake (struct pci_dev *dev);bool pci_check_pme_status (struct pci_dev *dev);void pci_pme_wakeup_bus (struct pci_bus *bus); +int pci_finish_runtime_suspend (struct pci_dev *dev);static inline int pci_enable_wake (struct pci_dev *dev,pci_power_t state,bool enable)Index:
linux-pm/drivers/net/ethernet/intel/e1000e/netdev.c
===================================================================drivers/net/ethernet/intel/e1000e/netdev.c +1
-0@@ -5696,6 +5696,7 @@ static int e1000_runtime_suspend(structbool wake;__e1000_shutdown (pdev,&wake, true); +pci_finish_runtime_suspend (pdev); }return 0 ;
Re: [PATCH 3/5] PCI: revert preparing for wakeup in runtime-suspend finalization
Quoted 137 lines · Konstantin Khlebnikov
Quoted 120 lines · Rafael J. Wysocki
Quoted 119 lines · Rafael J. Wysocki
Quoted 67 lines · Konstantin Khlebnikov
Quoted 57 lines · Rafael J. Wysocki
Quoted 49 lines · Rafael J. Wysocki
Quoted 48 lines · Konstantin Khlebnikov
Quoted 31 lines · Rafael J. Wysocki
Quoted 30 lines · Bjorn Helgaas
[+cc Rafael]
Quoted 14 lines · Konstantin Khlebnikov
This patch effectively reverts commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3")| This patch checks whether the pci state is saved and doesn't attempt to hit | any registers after that point if it is.
This seems completely wrong. Yes, PCI configuration space has been saved by driver, but this doesn't means that all job is done and device has been suspended and ready for waking up in the future.
For example driver e1000e for ethernet in my thinkpad x220 saves pci-state but device cannot wakeup after that, because it needs some ACPI callbacks which usually called from
pci_finish_runtime_suspend().Quoted 6 lines
| Optimus (dual-gpu) laptops seem to have their own form of D3cold, but | unfortunately enter it on normal D3 transitions via the ACPI callback.
Hardware which disappears from the bus unexpectedly is exception, so let's handle it as an exception. Its driver should set device state to D3cold and the rest code will handle it properly.
Functions in D3cold don't have power, so it's completely expected that they would disappear from the bus and not respond to config accesses. Maybe Dave was referring to D3hot, where functions *should* respond to config accesses. I dunno.
Quoted 7 lines
Quoted 4 lines
Just to be clear, it sounds like
42eca230caused a regression on your e1000e device? If so, I guess we should revert it unless you and Dave can figure out a better patch that fixes both your e1000e device and the Optimus issue.Yes, if there's a regression, let's revert it, but I'd like the regression to be described clearly.
Yep, this is regression.
commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3") changes state convention during runtime-suspend transaction too much. If PCI configuration space has been saved by driver that does not means that all job is done and device has been suspended and ready for waking up in the future.Quoted 6 lines
Quoted 3 lines
e1000e saves pci-config space itself, but it requires operations which
pci_finish_runtime_suspend()does: preparing for wake (calling particular platform pm-callbacks) and switching to proper sleep state.Well, I'd argue this is a bug in e1000e. Why does it need to save the PCI config space even though
pci_pm_runtime_suspend()will do that anyway?Quoted 8 lines
I honestly don't think we should revert
42eca2302146because of this.Yes, there is a requirement that drivers not save the PCI config space by themselves unless they want to do the whole power management by themselves too and e1000e is not following that. So either we need to drop the
pci_save_state()from__e1000_shutdown()which I would prefer (I'm not really sure why it is there), ore1000_runtime_suspend()needs to callpci_finish_runtime_suspend()by itself.Quoted 6 lines
Yet another problem: some drivers calls
pci_save_state()from ->probe() callback to use this saved state inpci_error_handlers->slot_reset().
As resultpdev->state_savedis true mostly all time.
At least e1000e anddrivers/pci/pcie/portdrv_pci.care doing this.I think it will be safer to revert
42eca2302146in v3.8Well, I wonder if we can just do something like the appended patch instead and address the e1000e runtime suspend by calling
pci_finish_runtime_suspend()directly frome1000_runtime_suspend().While we can revert commit
42eca2302146, that hardly would be progress, because then the issue it was supposed to address would still need to be addressed somehow.--- drivers/pci/pci-driver.c | 4 ++++ 1 file changed, 4 insertions(+)Index:
linux-pm/drivers/pci/pci-driver.c
===================================================================drivers/pci/pci-driver.c +3
-0@@ -628,6 +628,7 @@ static int pci_pm_suspend(struct device goto Fixup; } + pci_dev->state_saved = false;if (pm->suspend) {pci_power_t prev = pci_dev->current_state;int error;@@ -774,6 +775,7 @@ static int pci_pm_freeze(struct device *return 0 ; } + pci_dev->state_saved = false;if (pm->freeze) {int error;@@ -862,6 +864,7 @@ static int pci_pm_poweroff(struct device goto Fixup; } + pci_dev->state_saved = false;if (pm->poweroff) {int error;@@ -987,6 +990,7 @@ static int pci_pm_runtime_suspend(structif (!pm || !pm->runtime_suspend)return -ENOSYS ;Quoted 6 lines
drivers/pci/pci-driver.c static int pci_pm_runtime_suspend(struct · line 996
Quoted 4 lines
drivers/pci/pci-driver.c +1
-0+ pci_dev->state_saved = false; pci_dev->no_d3cold = false; error = pm->runtime_suspend (dev);suspend_report_result (pm->runtime_suspend, error);For completness, on top of the above one.
I would prefer to remove
pci_save_state()frome1000e_runtime_suspend().drivers/net/ethernet/intel/e1000e/netdev.c +0
-1@@ -5429,9 +5429,11 @@ static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake, }e1000e_reset_interrupt_capability (adapter); - retval =pci_save_state (pdev);
drivers/net/ethernet/intel/e1000e/netdev.c static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake, · line 5439
Quoted 10 lines
drivers/net/ethernet/intel/e1000e/netdev.c +5
-2-if (retval) -return retval; +if (!runtime) { + retval =pci_save_state (pdev); +if (retval) +return retval; + } status =er32 (STATUS );if (status &E1000_STATUS_LU )
Well, I'm not sure if it's necessary to do the pci_save_state() for !runtime here (i.e. why don't we remove it entirely?), but I'm fine with this change. :-)
Quoted 9 lines
I found another problem in e1000e: it does not calls
pci_enable_master()in 'resume' functions, but it disables 'bus-mastering' on suspending. Thus ifpci_save_state()is called after clearing that bit whole device wouldn't work after resuming.
drivers/net/ethernet/intel/e1000e/netdev.c static int __e1000_resume(struct pci_dev *pdev) · line 5604
Quoted 7 lines
drivers/net/ethernet/intel/e1000e/netdev.c +1
-0@@ -5598,6 +5598,7 @@ static int __e1000_resume(struct pci_dev *pdev)pci_set_power_state (pdev,PCI_D0 );pci_restore_state (pdev); +pci_set_master (pdev);pci_save_state (pdev); err =pci_enable_device_mem (pdev);
Yeah. Perhaps you can fold this change into your [2/5]?
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Re: [PATCH 3/5] PCI: revert preparing for wakeup in runtime-suspend finalization
In reply to Konstantin KhlebnikovQuoted 42 lines
Quoted 40 lines · Rafael J. Wysocki
Quoted 39 lines · Rafael J. Wysocki
Quoted 37 lines · Konstantin Khlebnikov
Quoted 36 lines · Rafael J. Wysocki
Quoted 35 lines · Bjorn Helgaas
[+cc Rafael]
Quoted 30 lines · Konstantin Khlebnikov
This patch effectively reverts commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3")| This patch checks whether the pci state is saved and doesn't | attempt to hit | any registers after that point if it is.This seems completely wrong. Yes, PCI configuration space has been saved by
driver, but this doesn't means that all job is done and device has been
suspended and ready for waking up in the future.For example driver e1000e for ethernet in my thinkpad x220 saves pci-state
but device cannot wakeup after that, because it needs some ACPI callbacks
which usually called frompci_finish_runtime_suspend().| Optimus (dual-gpu) laptops seem to have their own form of | D3cold, but | unfortunately enter it on normal D3 transitions via the ACPI | callback.Hardware which disappears from the bus unexpectedly is exception, so let's
handle it as an exception. Its driver should set device state to D3cold and
the rest code will handle it properly.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Functions in D3cold don't have power, so it's completely expected that
they would disappear from the bus and not respond to config accesses.
Maybe Dave was referring to D3hot, where functions *should* respond to
config accesses. I dunno.
Just to clarify what is going on with optimus laptops:
D3cold didn't exist as a real thing, so when you call the ACPI method to enter D3, it actually powers off the card completely, I've actually in my future work fixed it so that the driver then reports it being in D3cold when that happens.
The problem here was originally that the kernel didn't care if we hit D3hot or D3cold, it wanted to finish the dynamic suspend, however in this case there was no way it could.
So I'm happy with any solution that means cards reporting being in D3cold, won't get touched again after they return.
Dave.
Re: [PATCH 3/5] PCI: revert preparing for wakeup in runtime-suspend finalization
In reply to Konstantin Khlebnikov----- Original Message -----
Quoted 103 lines
From: "Konstantin Khlebnikov" <[email protected]>
To: "Rafael J. Wysocki" <[email protected]>
Cc: "Bjorn Helgaas" <[email protected]>, [email protected], [email protected], [email protected], "Dave Airlie" <[email protected]>, "Rafael J. Wysocki" <[email protected]>
Sent: Saturday, 2 February, 2013 10:12:03 PM
Subject: Re: [PATCH 3/5] PCI: revert preparing for wakeup in runtime-suspend finalizationQuoted 85 lines · Rafael J. Wysocki
Quoted 76 lines · Rafael J. Wysocki
Quoted 68 lines · Konstantin Khlebnikov
Quoted 52 lines · Rafael J. Wysocki
Quoted 43 lines · Bjorn Helgaas
[+cc Rafael]
Quoted 25 lines · Konstantin Khlebnikov
This patch effectively reverts commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3")| This patch checks whether the pci state is saved and doesn't | attempt to hit | any registers after that point if it is.This seems completely wrong. Yes, PCI configuration space has been saved by
driver, but this doesn't means that all job is done and device has been
suspended and ready for waking up in the future.For example driver e1000e for ethernet in my thinkpad x220 saves pci-state
but device cannot wakeup after that, because it needs some ACPI callbacks
which usually called frompci_finish_runtime_suspend().| Optimus (dual-gpu) laptops seem to have their own form of | D3cold, but | unfortunately enter it on normal D3 transitions via the ACPI | callback.Quoted 5 lines
Hardware which disappears from the bus unexpectedly is exception, so let's
handle it as an exception. Its driver should set device state to D3cold and
the rest code will handle it properly.Functions in D3cold don't have power, so it's completely expected that
they would disappear from the bus and not respond to config accesses.
Maybe Dave was referring to D3hot, where functions *should* respond to
config accesses. I dunno.Quoted 7 lines
Just to be clear, it sounds like
42eca230caused a regression on your
e1000e device? If so, I guess we should revert it unless you and Dave
can figure out a better patch that fixes both your e1000e device and
the Optimus issue.Quoted 3 lines
Yes, if there's a regression, let's revert it, but I'd like the regression
to be described clearly.Yep, this is regression.
commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch
card regs after runtime suspend D3") changes state convention during
runtime-suspend transaction too much. If PCI configuration space has been saved by driver that does not means that all job is done and device has been suspended and ready for waking up in the future.Quoted 5 lines
e1000e saves pci-config space itself, but it requires operations which
pci_finish_runtime_suspend()does: preparing for wake (calling particular
platform pm-callbacks) and switching to proper sleep state.Quoted 4 lines
Well, I'd argue this is a bug in e1000e. Why does it need to save the PCI
config space even thoughpci_pm_runtime_suspend()will do that anyway?I honestly don't think we should revert
42eca2302146because of this.Quoted 9 lines
Yes, there is a requirement that drivers not save the PCI config space by
themselves unless they want to do the whole power management by themselves too
and e1000e is not following that. So either we need to drop thepci_save_state()from__e1000_shutdown()which I would prefer (I'm not really
sure why it is there), ore1000_runtime_suspend()needs to callpci_finish_runtime_suspend()by itself.
Quoted 8 lines
Yet another problem: some drivers calls
pci_save_state()from ->probe() callback
to use this saved state inpci_error_handlers->slot_reset(). As resultpdev->state_savedis true mostly all time.
At least e1000e anddrivers/pci/pcie/portdrv_pci.care doing this.I think it will be safer to revert
42eca2302146in v3.8
btw I've no problem reverting this for 3.8, though I'd like to get a fix in for 3.9 then, the code relying on this change is still not completed, so a revert shouldn't break anything.
but definitely if a card goes into D3cold, we need to not poke any registers on it after it returns.
Dave.
Dave.
Re: [PATCH 3/5] PCI: revert preparing for wakeup in runtime-suspend finalization
Quoted 111 lines · David Airlie
----- Original Message -----
Quoted 109 lines
From: "Konstantin Khlebnikov" <[email protected]>
To: "Rafael J. Wysocki" <[email protected]>
Cc: "Bjorn Helgaas" <[email protected]>, [email protected], [email protected], [email protected], "Dave Airlie" <[email protected]>, "Rafael J. Wysocki" <[email protected]>
Sent: Saturday, 2 February, 2013 10:12:03 PM
Subject: Re: [PATCH 3/5] PCI: revert preparing for wakeup in runtime-suspend finalizationQuoted 85 lines · Rafael J. Wysocki
Quoted 76 lines · Rafael J. Wysocki
Quoted 68 lines · Konstantin Khlebnikov
Quoted 52 lines · Rafael J. Wysocki
Quoted 43 lines · Bjorn Helgaas
[+cc Rafael]
Quoted 25 lines · Konstantin Khlebnikov
This patch effectively reverts commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch card regs after runtime suspend D3")| This patch checks whether the pci state is saved and doesn't | attempt to hit | any registers after that point if it is.This seems completely wrong. Yes, PCI configuration space has been saved by
driver, but this doesn't means that all job is done and device has been
suspended and ready for waking up in the future.For example driver e1000e for ethernet in my thinkpad x220 saves pci-state
but device cannot wakeup after that, because it needs some ACPI callbacks
which usually called frompci_finish_runtime_suspend().| Optimus (dual-gpu) laptops seem to have their own form of | D3cold, but | unfortunately enter it on normal D3 transitions via the ACPI | callback.Quoted 5 lines
Hardware which disappears from the bus unexpectedly is exception, so let's
handle it as an exception. Its driver should set device state to D3cold and
the rest code will handle it properly.Functions in D3cold don't have power, so it's completely expected that
they would disappear from the bus and not respond to config accesses.
Maybe Dave was referring to D3hot, where functions *should* respond to
config accesses. I dunno.Quoted 7 lines
Just to be clear, it sounds like
42eca230caused a regression on your
e1000e device? If so, I guess we should revert it unless you and Dave
can figure out a better patch that fixes both your e1000e device and
the Optimus issue.Quoted 3 lines
Yes, if there's a regression, let's revert it, but I'd like the regression
to be described clearly.Yep, this is regression.
commit
42eca2302146fed51335b95128e949ee6f54478f("PCI: Don't touch
card regs after runtime suspend D3") changes state convention during
runtime-suspend transaction too much. If PCI configuration space has been saved by driver that does not means that all job is done and device has been suspended and ready for waking up in the future.Quoted 5 lines
e1000e saves pci-config space itself, but it requires operations which
pci_finish_runtime_suspend()does: preparing for wake (calling particular
platform pm-callbacks) and switching to proper sleep state.Quoted 4 lines
Well, I'd argue this is a bug in e1000e. Why does it need to save the PCI
config space even thoughpci_pm_runtime_suspend()will do that anyway?I honestly don't think we should revert
42eca2302146because of this.Quoted 9 lines
Yes, there is a requirement that drivers not save the PCI config space by
themselves unless they want to do the whole power management by themselves too
and e1000e is not following that. So either we need to drop thepci_save_state()from__e1000_shutdown()which I would prefer (I'm not really
sure why it is there), ore1000_runtime_suspend()needs to callpci_finish_runtime_suspend()by itself.Yet another problem: some drivers calls
pci_save_state()from ->probe() callback
to use this saved state inpci_error_handlers->slot_reset(). As resultpdev->state_savedis true mostly all time.
At least e1000e anddrivers/pci/pcie/portdrv_pci.care doing this.
Quoted 8 lines
Quoted 2 lines
I think it will be safer to revert
42eca2302146in v3.8btw I've no problem reverting this for 3.8, though I'd like to get a fix in for 3.9 then, the code relying on this change is still not completed, so a revert shouldn't break anything.
but definitely if a card goes into D3cold, we need to not poke any registers on it after it returns.
Sure.
As I said, I don't think it is necessary to revert 42eca2302146 and I've got a confirmation from Boris that the approach proposed so far works, so now it only is a matter of cutting final patches and testing them.
I'm not quite sure what Konstantin's plans in that respect are, though. Konstantin, care to tell us?
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
PATCH 4/5 PCI: don't touch enable_cnt in pci_device_shutdown()
In reply to Konstantin Khlebnikovcomment in commit b566a22c23327f18ce941ffad0ca907e50a53d41 ("PCI: disable Bus Master on PCI device shutdown") says:
| Disable Bus Master bit on the device in pci_device_shutdown() to ensure PCI | devices do not continue to DMA data after shutdown. This can cause memory | corruption in case of a kexec where the current kernel shuts down and | transfers control to a new kernel while a PCI device continues to DMA to | memory that does not belong to it any more in the new kernel.
Seems like pci_clear_master() must be used here instead of pci_disable_device(), because it disables Bus Muster unconditionally and doesn't changes enable_cnt.
--- drivers/pci/pci-driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci-driver.c +1 -1
@@ -392,7 +392,7 @@ static void pci_device_shutdown(struct device *dev)* Turn off Bus Master bit on the device to tell it to not * continue to do DMA */ -pci_disable_device (pci_dev); +pci_clear_master (pci_dev); }#ifdef CONFIG_PM
Re: [PATCH 4/5] PCI: don't touch enable_cnt in pci_device_shutdown()
Quoted 9 lines · Konstantin Khlebnikov
comment in commit
b566a22c23327f18ce941ffad0ca907e50a53d41("PCI: disable Bus Master on PCI device shutdown") says:| Disable Bus Master bit on the device in pci_device_shutdown() to ensure PCI | devices do not continue to DMA data after shutdown. This can cause memory | corruption in case of a kexec where the current kernel shuts down and | transfers control to a new kernel while a PCI device continues to DMA to | memory that does not belong to it any more in the new kernel.
Quoted 7 lines
Seems like
pci_clear_master()must be used here instead ofpci_disable_device(), because it disables Bus Muster unconditionally and doesn't changesenable_cnt.Signed-off-by Konstantin Khlebnikov<[email protected]>Cc Bjorn Helgaas<[email protected]>Cc Khalid Aziz<[email protected]>
Hmmm.... wondering if this was the problem why kexec folks said that device_shutdown() didn't work on all systems (when trying to stop DMA, esp. on IOMMU-enabled systems...).
Bjorn: do you have a list &/or contact in kexec space to try this patch vs the "reset every PCI bus" strategy that is currently being pushed for kexec's method to halt DMA from a PCI device ?
Quoted 22 lines
--- drivers/pci/pci-driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pci/pci-driver.c +1
-2@@ -392,7 +392,7 @@ static void pci_device_shutdown(struct device *dev)* Turn off Bus Master bit on the device to tell it to not * continue to do DMA */ -pci_disable_device (pci_dev); +pci_clear_master (pci_dev); }#ifdef CONFIG_PM --To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Bjorn Helgaas
maintainerRe: [PATCH 4/5] PCI: don't touch enable_cnt in pci_device_shutdown()
In reply to Konstantin KhlebnikovQuoted 25 lines · Konstantin Khlebnikov
comment in commit
b566a22c23327f18ce941ffad0ca907e50a53d41("PCI: disable Bus Master on PCI device shutdown") says:| Disable Bus Master bit on the device in pci_device_shutdown() to ensure PCI | devices do not continue to DMA data after shutdown. This can cause memory | corruption in case of a kexec where the current kernel shuts down and | transfers control to a new kernel while a PCI device continues to DMA to | memory that does not belong to it any more in the new kernel.Seems like
pci_clear_master()must be used here instead ofpci_disable_device(), because it disables Bus Muster unconditionally and doesn't changesenable_cnt.Signed-off-by Konstantin Khlebnikov <[email protected]>Cc Bjorn Helgaas <[email protected]>Cc Khalid Aziz <[email protected]>--- drivers/pci/pci-driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pci/pci-driver.c +0
-0
drivers/pci/pci-driver.c static void pci_device_shutdown(struct device *dev) · line 395
Quoted 5 lines
drivers/pci/pci-driver.c +1
-1@@ -392,7 +392,7 @@ static void pci_device_shutdown(struct device *dev)* Turn off Bus Master bit on the device to tell it to not * continue to do DMA */ -pci_disable_device (pci_dev); +pci_clear_master (pci_dev);
We currently only call pci_enable_device() and pci_disable_device() from drivers, and I think that's a nice division that's worth keeping.
It keeps the core's mitts off device operation and helps preserve theenable_cnt integrity. So I like this change from that perspective.
Any objections to this, Khalid?
Quoted 4 lines
drivers/pci/pci-driver.c +0
-0}#ifdef CONFIG_PM
Bjorn Helgaas
maintainerRe: [PATCH 4/5] PCI: don't touch enable_cnt in pci_device_shutdown()
[+cc Khalid new email addr]
Quoted 44 lines · Bjorn Helgaas
Quoted 25 lines · Konstantin Khlebnikov
comment in commit
b566a22c23327f18ce941ffad0ca907e50a53d41("PCI: disable Bus Master on PCI device shutdown") says:| Disable Bus Master bit on the device in pci_device_shutdown() to ensure PCI | devices do not continue to DMA data after shutdown. This can cause memory | corruption in case of a kexec where the current kernel shuts down and | transfers control to a new kernel while a PCI device continues to DMA to | memory that does not belong to it any more in the new kernel.Seems like
pci_clear_master()must be used here instead ofpci_disable_device(), because it disables Bus Muster unconditionally and doesn't changesenable_cnt.Signed-off-by Konstantin Khlebnikov <[email protected]>Cc Bjorn Helgaas <[email protected]>Cc Khalid Aziz <[email protected]>--- drivers/pci/pci-driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pci/pci-driver.c +0
-0drivers/pci/pci-driver.c static void pci_device_shutdown(struct device *dev) · line 395
Quoted 5 lines
drivers/pci/pci-driver.c +1
-1@@ -392,7 +392,7 @@ static void pci_device_shutdown(struct device *dev)* Turn off Bus Master bit on the device to tell it to not * continue to do DMA */ -pci_disable_device (pci_dev); +pci_clear_master (pci_dev);We currently only call
pci_enable_device()andpci_disable_device()from drivers, and I think that's a nice division that's worth keeping.
It keeps the core's mitts off device operation and helps preserve theenable_cntintegrity. So I like this change from that perspective.Any objections to this, Khalid?
Quoted 4 lines
drivers/pci/pci-driver.c +0
-0}#ifdef CONFIG_PM
Re: [PATCH 4/5] PCI: don't touch enable_cnt in pci_device_shutdown()
[Sorry about the resend. gmail sent my original reply in html by default which didn't go through to all mailing lists]
Quoted 43 lines · Bjorn Helgaas
[+cc Khalid new email addr]
Quoted 39 lines · Bjorn Helgaas
Quoted 25 lines · Konstantin Khlebnikov
comment in commit
b566a22c23327f18ce941ffad0ca907e50a53d41("PCI: disable Bus Master on PCI device shutdown") says:| Disable Bus Master bit on the device in pci_device_shutdown() to ensure PCI | devices do not continue to DMA data after shutdown. This can cause memory | corruption in case of a kexec where the current kernel shuts down and | transfers control to a new kernel while a PCI device continues to DMA to | memory that does not belong to it any more in the new kernel.Seems like
pci_clear_master()must be used here instead ofpci_disable_device(), because it disables Bus Muster unconditionally and doesn't changesenable_cnt.Signed-off-by Konstantin Khlebnikov <[email protected]>Cc Bjorn Helgaas <[email protected]>Cc Khalid Aziz <[email protected]>--- drivers/pci/pci-driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pci/pci-driver.c +0
-0drivers/pci/pci-driver.c static void pci_device_shutdown(struct device *dev) · line 395
Quoted 5 lines
drivers/pci/pci-driver.c +1
-1@@ -392,7 +392,7 @@ static void pci_device_shutdown(struct device *dev)* Turn off Bus Master bit on the device to tell it to not * continue to do DMA */ -pci_disable_device (pci_dev); +pci_clear_master (pci_dev);We currently only call
pci_enable_device()andpci_disable_device()from drivers, and I think that's a nice division that's worth keeping.
It keeps the core's mitts off device operation and helps preserve theenable_cntintegrity. So I like this change from that perspective.Any objections to this, Khalid?
Just turning the Bus Master bit off on a device does worry me. For well behaved PCI devices this should not be an issue at all, but it has been brought up before that there are misbehaved PCI devices that do not respond well when Bus Master bit is cleared on them while they are active. Turning interrupts off as well on them seems to help with being able to re-initialize them in the new kernel. As a result, I wanted to make sure we at least call pcibios_disable_irq() to turn off their interrupt and hence I chose to call pci_disable_device() instead of pci_clear_master(). I understand the concern around messing up enable_cnt. Would it be better to replace pci_disable_device() with these two instead:
pci_clear_master(pci_dev);pcibios_disable_device(pci_dev);
--
Khalid
PATCH 5/5 PCI: catch enable-counter underflows
In reply to Konstantin KhlebnikovThis patch adds single WARN_ONCE() check for catching 'enable_cnt' imbalances.
--- drivers/pci/pci.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/pci/pci.c +3 -0
@@ -1401,6 +1401,9 @@ pci_disable_device(struct pci_dev *dev)if (dr) dr->enabled =0 ; +dev_WARN_ONCE (&dev->dev,atomic_read (&dev->enable_cnt) <=0 , +"enable counter underflow" ); +if (atomic_sub_return (1 , &dev->enable_cnt) !=0 )return ;