PCI: keep enable status consistent for device without driver
PATCH 1/1 PCI: keep enable status consistent for device without driver
Wilmer reported continuous suspend/resume does not work after commit 928bea964827 ("PCI: Delay enabling bridges until they're needed").
For pci bridge without driver, FW enable it already. In pci_pm_resume/pci_pm_reenable_device after first resume will not reenable the device, aka the status is not the same as that before first suspend.
Try to update enable status according to register value before calling pci_reenable_device, so we will not miss those pm operation calling for next suspend/resume.
--- drivers/pci/pci-driver.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/pci/pci-driver.c +9 -0
@@ -519,8 +519,17 @@ static void pci_pm_set_unknown_state(str*/ static int pci_pm_reenable_device (struct pci_dev *pci_dev) { +u16 cmd;int retval; +/* update enable_cnt according to cmd register */ +pci_read_config_word (pci_dev,PCI_COMMAND , &cmd); +if (!pci_dev->is_busmaster && (cmd &PCI_COMMAND_MASTER )) + pci_dev->is_busmaster = true; +if (!pci_is_enabled (pci_dev) && + (cmd & (PCI_COMMAND_IO |PCI_COMMAND_MEMORY ))) +atomic_inc (&pci_dev->enable_cnt); +/* if the device was enabled before suspend, reenable */ retval =pci_reenable_device (pci_dev);/*
Bjorn Helgaas
maintainer[+cc Rafael, Pavel, linux-pm]
Quoted 12 lines · Yinghai Lu
Wilmer reported continuous suspend/resume does not work after commit
928bea964827("PCI: Delay enabling bridges until they're needed").For pci bridge without driver, FW enable it already. In pci_pm_resume/pci_pm_reenable_device after first resume will not reenable the device, aka the status is not the same as that before first suspend.
Try to update enable status according to register value before calling
pci_reenable_device, so we will not miss those pm operation calling for next suspend/resume.
Quoted 8 lines
Fixes 928bea964827 ("PCI: Delay enabling bridges until they're needed")Reported-by Wilmer van der Gaast <[email protected]>Bisected-by Wilmer van der Gaast <[email protected]>Tested-by Wilmer van der Gaast <[email protected]>Signed-off-by Yinghai Lu <[email protected]>Cc Zhang Rui <[email protected]>CC [email protected] # v3.10+
928bea964827 appeared in v3.12. Did you mean v3.12+ instead of v3.10+?
I'd really like to get Rafael and Pavel to take a look at this.
Quoted 14 lines
--- drivers/pci/pci-driver.c | 9 +++++++++ 1 file changed, 9 insertions(+)Index:
linux-2.6/drivers/pci/pci-driver.c
===================================================================drivers/pci/pci-driver.c +1
-0@@ -519,8 +519,17 @@ static void pci_pm_set_unknown_state(str*/ static int pci_pm_reenable_device (struct pci_dev *pci_dev) { +u16 cmd;int retval;
drivers/pci/pci-driver.c static void pci_pm_set_unknown_state(str · line 533
Quoted 10 lines
drivers/pci/pci-driver.c +7
-0+/* update enable_cnt according to cmd register */ +pci_read_config_word (pci_dev,PCI_COMMAND , &cmd); +if (!pci_dev->is_busmaster && (cmd &PCI_COMMAND_MASTER )) + pci_dev->is_busmaster = true; +if (!pci_is_enabled (pci_dev) && + (cmd & (PCI_COMMAND_IO |PCI_COMMAND_MEMORY ))) +atomic_inc (&pci_dev->enable_cnt);
This doesn't feel right because we're handling enable_cnt differently here than we do on initial boot.
On initial boot, I don't think we set enable_cnt based on whether firmware left the IO or MEMORY bits set in the command register. Why should we modify enable_cnt based on the command register during resume?
I could certainly believe we should do something during initial boot, too. It just seems like we should look at the command register in both places or neither place.
I have the same question about is_busmaster above.
Quoted 4 lines
drivers/pci/pci-driver.c +1
-0+/* if the device was enabled before suspend, reenable */ drivers/pci/pci-driver.c +0
-0retval =pci_reenable_device (pci_dev);/*
Quoted 60 lines · Bjorn Helgaas
[+cc Rafael, Pavel, linux-pm]
Quoted 12 lines · Yinghai Lu
Wilmer reported continuous suspend/resume does not work after commit
928bea964827("PCI: Delay enabling bridges until they're needed").For pci bridge without driver, FW enable it already. In pci_pm_resume/pci_pm_reenable_device after first resume will not reenable the device, aka the status is not the same as that before first suspend.
Try to update enable status according to register value before calling
pci_reenable_device, so we will not miss those pm operation calling for next suspend/resume.Quoted 8 lines
Fixes 928bea964827 ("PCI: Delay enabling bridges until they're needed")Reported-by Wilmer van der Gaast <[email protected]>Bisected-by Wilmer van der Gaast <[email protected]>Tested-by Wilmer van der Gaast <[email protected]>Signed-off-by Yinghai Lu <[email protected]>Cc Zhang Rui <[email protected]>CC [email protected] # v3.10+
928bea964827appeared in v3.12. Did you mean v3.12+ instead of v3.10+?I'd really like to get Rafael and Pavel to take a look at this.
Quoted 14 lines
--- drivers/pci/pci-driver.c | 9 +++++++++ 1 file changed, 9 insertions(+)Index:
linux-2.6/drivers/pci/pci-driver.c
===================================================================drivers/pci/pci-driver.c +1
-0@@ -519,8 +519,17 @@ static void pci_pm_set_unknown_state(str*/ static int pci_pm_reenable_device (struct pci_dev *pci_dev) { +u16 cmd;int retval;drivers/pci/pci-driver.c static void pci_pm_set_unknown_state(str · line 533
Quoted 10 lines
drivers/pci/pci-driver.c +7
-0+/* update enable_cnt according to cmd register */ +pci_read_config_word (pci_dev,PCI_COMMAND , &cmd); +if (!pci_dev->is_busmaster && (cmd &PCI_COMMAND_MASTER )) + pci_dev->is_busmaster = true; +if (!pci_is_enabled (pci_dev) && + (cmd & (PCI_COMMAND_IO |PCI_COMMAND_MEMORY ))) +atomic_inc (&pci_dev->enable_cnt);This doesn't feel right because we're handling
enable_cntdifferently here than we do on initial boot.On initial boot, I don't think we set
enable_cntbased on whether firmware left the IO or MEMORY bits set in the command register. Why should we modifyenable_cntbased on the command register during resume?
Quoted 5 lines
I could certainly believe we should do something during initial boot, too. It just seems like we should look at the command register in both places or neither place.
I have the same question about
is_busmasterabove.
Yep, that sounds like strange thing to do.
Adding more cc's.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 24 lines · Bjorn Helgaas
[+cc Rafael, Pavel, linux-pm]
Quoted 12 lines · Yinghai Lu
Wilmer reported continuous suspend/resume does not work after commit
928bea964827("PCI: Delay enabling bridges until they're needed").For pci bridge without driver, FW enable it already. In pci_pm_resume/pci_pm_reenable_device after first resume will not reenable the device, aka the status is not the same as that before first suspend.
Try to update enable status according to register value before calling
pci_reenable_device, so we will not miss those pm operation calling for next suspend/resume.Quoted 8 lines
Fixes 928bea964827 ("PCI: Delay enabling bridges until they're needed")Reported-by Wilmer van der Gaast <[email protected]>Bisected-by Wilmer van der Gaast <[email protected]>Tested-by Wilmer van der Gaast <[email protected]>Signed-off-by Yinghai Lu <[email protected]>Cc Zhang Rui <[email protected]>CC [email protected] # v3.10+
Quoted 1 line
928bea964827appeared in v3.12. Did you mean v3.12+ instead of v3.10+?
Yes.
get confused that Wilmer can not use 3.10 stable kernel.
Quoted 31 lines
I'd really like to get Rafael and Pavel to take a look at this.
Quoted 14 lines
--- drivers/pci/pci-driver.c | 9 +++++++++ 1 file changed, 9 insertions(+)Index:
linux-2.6/drivers/pci/pci-driver.c
===================================================================drivers/pci/pci-driver.c +1
-0@@ -519,8 +519,17 @@ static void pci_pm_set_unknown_state(str*/ static int pci_pm_reenable_device (struct pci_dev *pci_dev) { +u16 cmd;int retval;drivers/pci/pci-driver.c static void pci_pm_set_unknown_state(str · line 533
Quoted 10 lines
drivers/pci/pci-driver.c +7
-0+/* update enable_cnt according to cmd register */ +pci_read_config_word (pci_dev,PCI_COMMAND , &cmd); +if (!pci_dev->is_busmaster && (cmd &PCI_COMMAND_MASTER )) + pci_dev->is_busmaster = true; +if (!pci_is_enabled (pci_dev) && + (cmd & (PCI_COMMAND_IO |PCI_COMMAND_MEMORY ))) +atomic_inc (&pci_dev->enable_cnt);This doesn't feel right because we're handling
enable_cntdifferently here than we do on initial boot.
Quoted 8 lines
On initial boot, I don't think we set
enable_cntbased on whether firmware left the IO or MEMORY bits set in the command register. Why should we modifyenable_cntbased on the command register during resume?I could certainly believe we should do something during initial boot, too. It just seems like we should look at the command register in both places or neither place.
BIOS set power state correctly, so first suspend/resume will work.
late because setting power state will rely on the enable-cnt, first resume would not set the power state related correctly, then second suspend/resume will not work anymore.
will check if we can change to:
check hw status, and then enable the pci device on boot path instead.
Thanks
Yinghai