Re: [PATCH v3 07/10] PCI/PTM: Add suspend/resume

From: Mika Westerberg
Date: Wed Sep 07 2022 - 01:30:40 EST


On Tue, Sep 06, 2022 at 05:23:48PM -0500, Bjorn Helgaas wrote:
> From: Bjorn Helgaas <bhelgaas@xxxxxxxxxx>
>

I think it is good to explain here why this patch is needed. Even if
just one sentence.

> ---
> drivers/pci/pci.c | 4 ++--
> drivers/pci/pci.h | 4 ++++
> drivers/pci/pcie/ptm.c | 15 +++++++++++++++
> 3 files changed, 21 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 95bc329e74c0..83818f81577d 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -2714,7 +2714,7 @@ int pci_prepare_to_sleep(struct pci_dev *dev)
> * lower-power idle state as a whole.
> */
> if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT)
> - pci_disable_ptm(dev);
> + pci_suspend_ptm(dev);
>
> pci_enable_wake(dev, target_state, wakeup);
>
> @@ -2772,7 +2772,7 @@ int pci_finish_runtime_suspend(struct pci_dev *dev)
> * lower-power idle state as a whole.
> */
> if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT)
> - pci_disable_ptm(dev);
> + pci_suspend_ptm(dev);
>
> __pci_enable_wake(dev, target_state, pci_dev_run_wake(dev));
>
> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> index 91a465460d0f..ce4a277e3f41 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -507,9 +507,13 @@ static inline int pci_iov_bus_range(struct pci_bus *bus)
> #ifdef CONFIG_PCIE_PTM
> void pci_save_ptm_state(struct pci_dev *dev);
> void pci_restore_ptm_state(struct pci_dev *dev);
> +void pci_suspend_ptm(struct pci_dev *dev);
> +void pci_resume_ptm(struct pci_dev *dev);
> #else
> static inline void pci_save_ptm_state(struct pci_dev *dev) { }
> static inline void pci_restore_ptm_state(struct pci_dev *dev) { }
> +static inline void pci_suspend_ptm(struct pci_dev *dev) { }
> +static inline void pci_resume_ptm(struct pci_dev *dev) { }
> #endif
>
> unsigned long pci_cardbus_resource_alignment(struct resource *);
> diff --git a/drivers/pci/pcie/ptm.c b/drivers/pci/pcie/ptm.c
> index 4a9f045126ca..8ac844212436 100644
> --- a/drivers/pci/pcie/ptm.c
> +++ b/drivers/pci/pcie/ptm.c
> @@ -198,6 +198,21 @@ int pci_enable_ptm(struct pci_dev *dev, u8 *granularity)
> }
> EXPORT_SYMBOL(pci_enable_ptm);
>
> +/*
> + * Disable PTM, but leave dev->ptm_enabled so we silently re-enable it on
> + * resume.
> + */

Proper kernel-doc for both.

> +void pci_suspend_ptm(struct pci_dev *dev)
> +{
> + __pci_disable_ptm(dev);
> +}
> +
> +void pci_resume_ptm(struct pci_dev *dev)
> +{
> + if (dev->ptm_enabled)
> + __pci_enable_ptm(dev);
> +}
> +
> bool pcie_ptm_enabled(struct pci_dev *dev)
> {
> if (!dev)
> --
> 2.25.1