Skip to content

Commit c01163d

Browse files
committed
PCI/PM: Always disable PTM for all devices during suspend
We want to disable PTM on Root Ports because that allows some chips, e.g., Intel mobile chips since Coffee Lake, to enter a lower-power PM state. That means we also have to disable PTM on downstream devices. PCIe r6.0, sec 2.2.8, recommends that functions support generation of messages in non-D0 states, so we have to assume Switch Upstream Ports or Endpoints may send PTM Requests while in D1, D2, and D3hot. A PTM message received by a Downstream Port (including a Root Port) with PTM disabled must be treated as an Unsupported Request (sec 6.21.3). PTM was previously disabled only for Root Ports, and it was disabled in pci_prepare_to_sleep(), which is not called at all if a driver supports legacy PM or does its own state saving. Instead, disable PTM early in pci_pm_suspend() and pci_pm_runtime_suspend() so we do it in all cases. Previously PTM was disabled *after* saving device state, so the state restore on resume automatically re-enabled it. Since we now disable PTM *before* saving state, we must explicitly re-enable it in pci_pm_resume() and pci_pm_runtime_resume(). Here's a sample of errors that occur when PTM is disabled only on the Root Port. With this topology: 0000:00:1d.0 Root Port to [bus 08-71] 0000:08:00.0 Switch Upstream Port to [bus 09-71] Kai-Heng reported errors like this: pcieport 0000:00:1d.0: [20] UnsupReq (First) pcieport 0000:00:1d.0: AER: TLP Header: 34000000 08000052 00000000 00000000 Decoding TLP header 0x34...... (0011 0100b) and 0x08000052: Fmt 001b 4 DW header, no data Type 1 0100b Msg (Local - Terminate at Receiver) Requester ID 0x0800 Bus 08 Devfn 00.0 Message Code 0x52 0101 0010b PTM Request The 00:1d.0 Root Port logged an Unsupported Request error when it received a PTM Request with Requester ID 08:00.0. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=215453 Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=216210 Fixes: a697f07 ("PCI: Disable PTM during suspend to save power") Link: https://lore.kernel.org/r/20220909202505.314195-10-helgaas@kernel.org Reported-by: Kai-Heng Feng <kai.heng.feng@canonical.com> Tested-by: Rajvi Jingar <rajvi.jingar@linux.intel.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
1 parent d736d29 commit c01163d

File tree

2 files changed

+13
-26
lines changed

2 files changed

+13
-26
lines changed

drivers/pci/pci-driver.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,12 @@ static int pci_pm_suspend(struct device *dev)
774774

775775
pci_dev->skip_bus_pm = false;
776776

777+
/*
778+
* Disabling PTM allows some systems, e.g., Intel mobile chips
779+
* since Coffee Lake, to enter a lower-power PM state.
780+
*/
781+
pci_suspend_ptm(pci_dev);
782+
777783
if (pci_has_legacy_pm_support(pci_dev))
778784
return pci_legacy_suspend(dev, PMSG_SUSPEND);
779785

@@ -987,6 +993,8 @@ static int pci_pm_resume(struct device *dev)
987993
if (pci_dev->state_saved)
988994
pci_restore_standard_config(pci_dev);
989995

996+
pci_resume_ptm(pci_dev);
997+
990998
if (pci_has_legacy_pm_support(pci_dev))
991999
return pci_legacy_resume(dev);
9921000

@@ -1274,6 +1282,8 @@ static int pci_pm_runtime_suspend(struct device *dev)
12741282
pci_power_t prev = pci_dev->current_state;
12751283
int error;
12761284

1285+
pci_suspend_ptm(pci_dev);
1286+
12771287
/*
12781288
* If pci_dev->driver is not set (unbound), we leave the device in D0,
12791289
* but it may go to D3cold when the bridge above it runtime suspends.
@@ -1335,6 +1345,7 @@ static int pci_pm_runtime_resume(struct device *dev)
13351345
* D3cold when the bridge above it runtime suspended.
13361346
*/
13371347
pci_pm_default_resume_early(pci_dev);
1348+
pci_resume_ptm(pci_dev);
13381349

13391350
if (!pci_dev->driver)
13401351
return 0;

drivers/pci/pci.c

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,24 +2706,12 @@ int pci_prepare_to_sleep(struct pci_dev *dev)
27062706
if (target_state == PCI_POWER_ERROR)
27072707
return -EIO;
27082708

2709-
/*
2710-
* There are systems (for example, Intel mobile chips since Coffee
2711-
* Lake) where the power drawn while suspended can be significantly
2712-
* reduced by disabling PTM on PCIe root ports as this allows the
2713-
* port to enter a lower-power PM state and the SoC to reach a
2714-
* lower-power idle state as a whole.
2715-
*/
2716-
if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT)
2717-
pci_suspend_ptm(dev);
2718-
27192709
pci_enable_wake(dev, target_state, wakeup);
27202710

27212711
error = pci_set_power_state(dev, target_state);
27222712

2723-
if (error) {
2713+
if (error)
27242714
pci_enable_wake(dev, target_state, false);
2725-
pci_restore_ptm_state(dev);
2726-
}
27272715

27282716
return error;
27292717
}
@@ -2764,24 +2752,12 @@ int pci_finish_runtime_suspend(struct pci_dev *dev)
27642752
if (target_state == PCI_POWER_ERROR)
27652753
return -EIO;
27662754

2767-
/*
2768-
* There are systems (for example, Intel mobile chips since Coffee
2769-
* Lake) where the power drawn while suspended can be significantly
2770-
* reduced by disabling PTM on PCIe root ports as this allows the
2771-
* port to enter a lower-power PM state and the SoC to reach a
2772-
* lower-power idle state as a whole.
2773-
*/
2774-
if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT)
2775-
pci_suspend_ptm(dev);
2776-
27772755
__pci_enable_wake(dev, target_state, pci_dev_run_wake(dev));
27782756

27792757
error = pci_set_power_state(dev, target_state);
27802758

2781-
if (error) {
2759+
if (error)
27822760
pci_enable_wake(dev, target_state, false);
2783-
pci_restore_ptm_state(dev);
2784-
}
27852761

27862762
return error;
27872763
}

0 commit comments

Comments
 (0)