Skip to contentSkip to conversation

PCI: Fix runtime PME generation from D3hot

PATCH Superseded Mika Westerberg 4 participants 8 messages Jan 7, 2019 – Jan 21, 2019 PCI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover PCI: Fix runtime PME generation from D3hot

Hi all,

Heiner reported [1] that runtime PME generation of his network card does not work after commit 0e157e528604 ("PCI/PME: Implement runtime PM callbacks") that landed in v4.20. Reverting the commit helps but it has another drawback, which I originally tried to solve with the commit, that the PCIe hierarchy wakes up immediately after being put into D3cold.

This series of two patches tries to fix both issues so that PME wakes up from D3hot and that the hierarchy does not wake up immediately from D3cold.

[1] https://www.spinics.net/lists/linux-pci/msg79051.html

Mika Westerberg (2):
Revert "PCI/PME: Implement runtime PM callbacks"
PCI: pciehp: Disable Data Link Layer State Changed event on suspend

 drivers/pci/hotplug/pciehp_hpc.c | 10 ++++++++--
 drivers/pci/pcie/pme.c           | 27 ---------------------------
 2 files changed, 8 insertions(+), 29 deletions(-)
Signature · 1 line
2.19.2
#1 lore raw

PATCH 1/2 Revert "PCI/PME: Implement runtime PM callbacks"

This reverts commit 0e157e52860441cb26051f131dd0b5ae3187a07b.

Heiner reported that the commit in question prevents his network adapter from triggering PME and waking up when network cable is plugged.

The commit tried to prevent root port waking up from D3cold immediately but looks like disabing root port PME interrupt is not the right way to fix that issue so revert it now. The patch following proposes an alternative solution to that issue.

Fixes 0e157e528604 ("PCI/PME: Implement runtime PM callbacks")
---
 drivers/pci/pcie/pme.c | 27 ---------------------------
 1 file changed, 27 deletions(-)
drivers/pci/pcie/pme.c +0 -27
index 0dbcf429089f..1a8b85051b1b 100644
@@ -432,31 +432,6 @@ static void pcie_pme_remove(struct pcie_device *srv)
 	kfree(get_service_data(srv));
 }
 
-static int pcie_pme_runtime_suspend(struct pcie_device *srv)
-{
-	struct pcie_pme_service_data *data = get_service_data(srv);
-
-	spin_lock_irq(&data->lock);
-	pcie_pme_interrupt_enable(srv->port, false);
-	pcie_clear_root_pme_status(srv->port);
-	data->noirq = true;
-	spin_unlock_irq(&data->lock);
-
-	return 0;
-}
-
-static int pcie_pme_runtime_resume(struct pcie_device *srv)
-{
-	struct pcie_pme_service_data *data = get_service_data(srv);
-
-	spin_lock_irq(&data->lock);
-	pcie_pme_interrupt_enable(srv->port, true);
-	data->noirq = false;
-	spin_unlock_irq(&data->lock);
-
-	return 0;
-}
-
 static struct pcie_port_service_driver pcie_pme_driver = {
 	.name		= "pcie_pme",
 	.port_type	= PCI_EXP_TYPE_ROOT_PORT,
@@ -464,8 +439,6 @@ static struct pcie_port_service_driver pcie_pme_driver = {
 
 	.probe		= pcie_pme_probe,
 	.suspend	= pcie_pme_suspend,
-	.runtime_suspend = pcie_pme_runtime_suspend,
-	.runtime_resume	= pcie_pme_runtime_resume,
 	.resume		= pcie_pme_resume,
 	.remove		= pcie_pme_remove,
 };
Signature · 1 line
2.19.2
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] Revert "PCI/PME: Implement runtime PM callbacks"

Quoted 10 lines · CET Mika Westerberg

This reverts commit 0e157e52860441cb26051f131dd0b5ae3187a07b.

Heiner reported that the commit in question prevents his network adapter from triggering PME and waking up when network cable is plugged.

The commit tried to prevent root port waking up from D3cold immediately but looks like disabing root port PME interrupt is not the right way to fix that issue so revert it now. The patch following proposes an alternative solution to that issue.

Quoted 4 lines
Fixes 0e157e528604 ("PCI/PME: Implement runtime PM callbacks")
Quoted 50 lines
---
 drivers/pci/pcie/pme.c | 27 ---------------------------
 1 file changed, 27 deletions(-)
drivers/pci/pcie/pme.c +0 -27
index 0dbcf429089f..1a8b85051b1b 100644
@@ -432,31 +432,6 @@ static void pcie_pme_remove(struct pcie_device *srv)
 	kfree(get_service_data(srv));
 }
 
-static int pcie_pme_runtime_suspend(struct pcie_device *srv)
-{
-	struct pcie_pme_service_data *data = get_service_data(srv);
-
-	spin_lock_irq(&data->lock);
-	pcie_pme_interrupt_enable(srv->port, false);
-	pcie_clear_root_pme_status(srv->port);
-	data->noirq = true;
-	spin_unlock_irq(&data->lock);
-
-	return 0;
-}
-
-static int pcie_pme_runtime_resume(struct pcie_device *srv)
-{
-	struct pcie_pme_service_data *data = get_service_data(srv);
-
-	spin_lock_irq(&data->lock);
-	pcie_pme_interrupt_enable(srv->port, true);
-	data->noirq = false;
-	spin_unlock_irq(&data->lock);
-
-	return 0;
-}
-
 static struct pcie_port_service_driver pcie_pme_driver = {
 	.name		= "pcie_pme",
 	.port_type	= PCI_EXP_TYPE_ROOT_PORT,
@@ -464,8 +439,6 @@ static struct pcie_port_service_driver pcie_pme_driver = {
 
 	.probe		= pcie_pme_probe,
 	.suspend	= pcie_pme_suspend,
-	.runtime_suspend = pcie_pme_runtime_suspend,
-	.runtime_resume	= pcie_pme_runtime_resume,
 	.resume		= pcie_pme_resume,
 	.remove		= pcie_pme_remove,
 };
#3 lore raw

PATCH 2/2 PCI: pciehp: Disable Data Link Layer State Changed event on suspend

In reply to Mika Westerberg

Commit 0e157e528604 ("PCI/PME: Implement runtime PM callbacks") tried to solve an issue where the hierarchy immediately wakes up when it is transitioned into D3cold. It turns out preventing PME propagation in some PCIe hierarchies not supporting D3cold.

I looked more closely what might cause the immediate wakeup. It happens when the ACPI power resource of the root port is turned off. The AML code associated with the _OFF() method of the ACPI power resource executes PCIe L2/3 ready transition and waits it to complete. Right after the L2/3 ready transition is started the root port receives PME from the downstream port.

The simplest hierarchy where this happens looks like this:

00:1d.0 PCIe Root port

    ^
    |
    v
    05:00.0 PCIe switch #1 upstream port
      06:01.0 PCIe switch #1 downstream hotplug port
        ^
        |
        v
        08:00.0 Pcie switch #2 upstream port

It seems that the PCIe link between the two switches, before PME_Turn_Off/PME_TO_Ack is complete for the whole hierarchy, goes inactive and triggers PME towards the root port bringing it back to D0. Disabling Data Link Layer State Changed event (DLLSCE) prevents the issue and still allows the downstream hotplug port to notice when a device is plugged/unplugged.

Fixes 0e157e528604 ("PCI/PME: Implement runtime PM callbacks")
---
 drivers/pci/hotplug/pciehp_hpc.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/pci/hotplug/pciehp_hpc.c +8 -2
index cd9eae650aa5..6fdaa8d48ebe 100644
@@ -736,12 +736,18 @@ void pcie_clear_hotplug_events(struct controller *ctrl)
 
 void pcie_enable_interrupt(struct controller *ctrl)
 {
-	pcie_write_cmd(ctrl, PCI_EXP_SLTCTL_HPIE, PCI_EXP_SLTCTL_HPIE);
+	u16 mask;
+
+	mask = PCI_EXP_SLTCTL_HPIE | PCI_EXP_SLTCTL_DLLSCE;
+	pcie_write_cmd(ctrl, mask, mask);
 }
 
 void pcie_disable_interrupt(struct controller *ctrl)
 {
-	pcie_write_cmd(ctrl, 0, PCI_EXP_SLTCTL_HPIE);
+	u16 mask;
+
+	mask = PCI_EXP_SLTCTL_HPIE | PCI_EXP_SLTCTL_DLLSCE;
+	pcie_write_cmd(ctrl, 0, mask);
 }
 
 /*
Signature · 1 line
2.19.2
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] PCI: pciehp: Disable Data Link Layer State Changed event on suspend

Quoted 32 lines · CET Mika Westerberg

Commit 0e157e528604 ("PCI/PME: Implement runtime PM callbacks") tried to solve an issue where the hierarchy immediately wakes up when it is transitioned into D3cold. It turns out preventing PME propagation in some PCIe hierarchies not supporting D3cold.

I looked more closely what might cause the immediate wakeup. It happens when the ACPI power resource of the root port is turned off. The AML code associated with the _OFF() method of the ACPI power resource executes PCIe L2/3 ready transition and waits it to complete. Right after the L2/3 ready transition is started the root port receives PME from the downstream port.

The simplest hierarchy where this happens looks like this:

00:1d.0 PCIe Root port

    ^
    |
    v
    05:00.0 PCIe switch #1 upstream port
      06:01.0 PCIe switch #1 downstream hotplug port
        ^
        |
        v
        08:00.0 Pcie switch #2 upstream port

It seems that the PCIe link between the two switches, before PME_Turn_Off/PME_TO_Ack is complete for the whole hierarchy, goes inactive and triggers PME towards the root port bringing it back to D0. Disabling Data Link Layer State Changed event (DLLSCE) prevents the issue and still allows the downstream hotplug port to notice when a device is plugged/unplugged.

Quoted 3 lines
Fixes 0e157e528604 ("PCI/PME: Implement runtime PM callbacks")
Quoted 30 lines
---
 drivers/pci/hotplug/pciehp_hpc.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/pci/hotplug/pciehp_hpc.c +8 -2
index cd9eae650aa5..6fdaa8d48ebe 100644
@@ -736,12 +736,18 @@ void pcie_clear_hotplug_events(struct controller *ctrl)
 
 void pcie_enable_interrupt(struct controller *ctrl)
 {
-	pcie_write_cmd(ctrl, PCI_EXP_SLTCTL_HPIE, PCI_EXP_SLTCTL_HPIE);
+	u16 mask;
+
+	mask = PCI_EXP_SLTCTL_HPIE | PCI_EXP_SLTCTL_DLLSCE;
+	pcie_write_cmd(ctrl, mask, mask);
 }
 
 void pcie_disable_interrupt(struct controller *ctrl)
 {
-	pcie_write_cmd(ctrl, 0, PCI_EXP_SLTCTL_HPIE);
+	u16 mask;
+
+	mask = PCI_EXP_SLTCTL_HPIE | PCI_EXP_SLTCTL_DLLSCE;
+	pcie_write_cmd(ctrl, 0, mask);
 }
 
 /*
#5 lore raw

Re: [PATCH 2/2] PCI: pciehp: Disable Data Link Layer State Changed event on suspend

In reply to Mika Westerberg
Quoted 4 lines · Mika Westerberg

Commit 0e157e528604 ("PCI/PME: Implement runtime PM callbacks") tried to solve an issue where the hierarchy immediately wakes up when it is transitioned into D3cold. It turns out preventing PME propagation in some PCIe hierarchies not supporting D3cold.

I can't quite parse this last sentence. Is it missing a word?

Quoted 4 lines

I looked more closely what might cause the immediate wakeup. It happens when the ACPI power resource of the root port is turned off. The AML code associated with the _OFF() method of the ACPI power resource executes PCIe L2/3 ready transition and waits it to complete.

waits *for* it ...

Quoted 17 lines

Right
after the L2/3 ready transition is started the root port receives PME from the downstream port.

The simplest hierarchy where this happens looks like this:

00:1d.0 PCIe Root port

    ^
    |
    v
    05:00.0 PCIe switch #1 upstream port
      06:01.0 PCIe switch #1 downstream hotplug port
        ^
        |
        v
        08:00.0 Pcie switch #2 upstream port
Quoted 6 lines

It seems that the PCIe link between the two switches, before PME_Turn_Off/PME_TO_Ack is complete for the whole hierarchy, goes inactive and triggers PME towards the root port bringing it back to D0. Disabling Data Link Layer State Changed event (DLLSCE) prevents the issue and still allows the downstream hotplug port to notice when a device is plugged/unplugged.

I don't understand the "link goes inactive and triggers PME" part. Is that prescribed by the spec, or is this implementation-specific behavior, or even a bug?

Are there spec references that would be useful here? PCIe r4.0, sec 5.2 seems like one starting point. 5.3.1.4.2? 5.3.3.2.1 and following sections seem like they should be very relevant, but I haven't studied it in detail.

Quoted 17 lines
Fixes 0e157e528604 ("PCI/PME: Implement runtime PM callbacks")
---
 drivers/pci/hotplug/pciehp_hpc.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/pci/hotplug/pciehp_hpc.c +1 -1
index cd9eae650aa5..6fdaa8d48ebe 100644
@@ -736,12 +736,18 @@ void pcie_clear_hotplug_events(struct controller *ctrl)
 
 void pcie_enable_interrupt(struct controller *ctrl)
 {
-	pcie_write_cmd(ctrl, PCI_EXP_SLTCTL_HPIE, PCI_EXP_SLTCTL_HPIE);
+	u16 mask;

drivers/pci/hotplug/pciehp_hpc.c void pcie_clear_hotplug_events(struct controller *ctrl) · line 748

Quoted 10 lines
drivers/pci/hotplug/pciehp_hpc.c +5 -1
+
+	mask = PCI_EXP_SLTCTL_HPIE | PCI_EXP_SLTCTL_DLLSCE;
+	pcie_write_cmd(ctrl, mask, mask);
 }
 
 void pcie_disable_interrupt(struct controller *ctrl)
 {
-	pcie_write_cmd(ctrl, 0, PCI_EXP_SLTCTL_HPIE);
+	u16 mask;
+

I think some sort of comment here would be useful. It's pretty hard for the casual reader to figure out what things need to be masked.

Quoted 8 lines
drivers/pci/hotplug/pciehp_hpc.c +2 -0
+	mask = PCI_EXP_SLTCTL_HPIE | PCI_EXP_SLTCTL_DLLSCE;
+	pcie_write_cmd(ctrl, 0, mask);
 }
 
 /*
Signature · 1 line
2.19.2
#6 lore raw

Re: [PATCH 2/2] PCI: pciehp: Disable Data Link Layer State Changed event on suspend

Hi Bjorn,

Sorry for the delay - I was on a business trip.

Quoted 7 lines · Bjorn Helgaas
Quoted 4 lines · Mika Westerberg

Commit 0e157e528604 ("PCI/PME: Implement runtime PM callbacks") tried to solve an issue where the hierarchy immediately wakes up when it is transitioned into D3cold. It turns out preventing PME propagation in some PCIe hierarchies not supporting D3cold.

I can't quite parse this last sentence. Is it missing a word?

No, but I'm not native speaker :)

Quoted 6 lines
Quoted 4 lines

I looked more closely what might cause the immediate wakeup. It happens when the ACPI power resource of the root port is turned off. The AML code associated with the _OFF() method of the ACPI power resource executes PCIe L2/3 ready transition and waits it to complete.

waits *for* it ...

OK.

Quoted 24 lines
Quoted 17 lines

Right
after the L2/3 ready transition is started the root port receives PME from the downstream port.

The simplest hierarchy where this happens looks like this:

00:1d.0 PCIe Root port

    ^
    |
    v
    05:00.0 PCIe switch #1 upstream port
      06:01.0 PCIe switch #1 downstream hotplug port
        ^
        |
        v
        08:00.0 Pcie switch #2 upstream port
Quoted 6 lines

It seems that the PCIe link between the two switches, before PME_Turn_Off/PME_TO_Ack is complete for the whole hierarchy, goes inactive and triggers PME towards the root port bringing it back to D0. Disabling Data Link Layer State Changed event (DLLSCE) prevents the issue and still allows the downstream hotplug port to notice when a device is plugged/unplugged.

Quoted 3 lines

I don't understand the "link goes inactive and triggers PME" part. Is that prescribed by the spec, or is this implementation-specific behavior, or even a bug?

It is not directly described in the spec (unfortunately). In general they leave a lot for the reader to interpret instead of explaining how the thing is supposed to be programmed in different situations :(

This is the behavior I see when the hierarchy goes into D3cold. I don't have any equipment that would let me see what exactly happens there. The above is my guess of what happens.

Quoted 4 lines

Are there spec references that would be useful here? PCIe r4.0, sec 5.2 seems like one starting point. 5.3.1.4.2? 5.3.3.2.1 and following sections seem like they should be very relevant, but I haven't studied it in detail.

Sure, I can add those references to the changelog.

Quoted 22 lines
Quoted 22 lines
Fixes 0e157e528604 ("PCI/PME: Implement runtime PM callbacks")
---
 drivers/pci/hotplug/pciehp_hpc.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/pci/hotplug/pciehp_hpc.c +4 -1
index cd9eae650aa5..6fdaa8d48ebe 100644
@@ -736,12 +736,18 @@ void pcie_clear_hotplug_events(struct controller *ctrl)
 
 void pcie_enable_interrupt(struct controller *ctrl)
 {
-	pcie_write_cmd(ctrl, PCI_EXP_SLTCTL_HPIE, PCI_EXP_SLTCTL_HPIE);
+	u16 mask;
+
+	mask = PCI_EXP_SLTCTL_HPIE | PCI_EXP_SLTCTL_DLLSCE;
+	pcie_write_cmd(ctrl, mask, mask);
 }
 
Quoted 8 lines

drivers/pci/hotplug/pciehp_hpc.c void pcie_clear_hotplug_events(struct controller *ctrl) · line 748

Quoted 5 lines
drivers/pci/hotplug/pciehp_hpc.c +2 -1
 void pcie_disable_interrupt(struct controller *ctrl)
 {
-	pcie_write_cmd(ctrl, 0, PCI_EXP_SLTCTL_HPIE);
+	u16 mask;
+

I think some sort of comment here would be useful. It's pretty hard for the casual reader to figure out what things need to be masked.

Sure, I'll add a comment.

Quoted 8 lines
Quoted 8 lines
drivers/pci/hotplug/pciehp_hpc.c +2 -0
+	mask = PCI_EXP_SLTCTL_HPIE | PCI_EXP_SLTCTL_DLLSCE;
+	pcie_write_cmd(ctrl, 0, mask);
 }
 
 /*
Signature · 1 line
2.19.2
Tested-by on the v1 series
#7 lore raw
In reply to Mika Westerberg
Quoted 13 lines · Mika Westerberg

Hi all,

Heiner reported [1] that runtime PME generation of his network card does not work after commit 0e157e528604 ("PCI/PME: Implement runtime PM callbacks") that landed in v4.20. Reverting the commit helps but it has another drawback, which I originally tried to solve with the commit, that the PCIe hierarchy wakes up immediately after being put into D3cold.

This series of two patches tries to fix both issues so that PME wakes up from D3hot and that the hierarchy does not wake up immediately from D3cold.

[1] https://www.spinics.net/lists/linux-pci/msg79051.html

Quoted 8 lines

Mika Westerberg (2):
Revert "PCI/PME: Implement runtime PM callbacks"
PCI: pciehp: Disable Data Link Layer State Changed event on suspend

 drivers/pci/hotplug/pciehp_hpc.c | 10 ++++++++--
 drivers/pci/pcie/pme.c           | 27 ---------------------------
 2 files changed, 8 insertions(+), 29 deletions(-)

Works for me. But that's not a miracle because on my system CONFIG_HOTPLUG_PCI isn't set and therefore effectively just the runtime ops are removed again. And we tested before that this fixes the issue for me. Thanks for the analysis and the fix!

So for the runtime PM PME generation: