2020-06-29 21:23:00

by Vaibhav Gupta

[permalink] [raw]
Subject: [PATCH v2 0/4] drivers/staging: use generic power management

Linux Kernel Mentee: Remove Legacy Power Management.

The purpose of this patch series is to remove legacy power management callbacks
from amd ethernet drivers.

The callbacks performing suspend() and resume() operations are still calling
pci_save_state(), pci_set_power_state(), etc. and handling the power management
themselves, which is not recommended.

The conversion requires the removal of the those function calls and change the
callback definition accordingly and make use of dev_pm_ops structure.

All patches are compile-tested only.

v2: An error was reported by kbuild in v1. pci_set_master() function call in
drivers/staging/qlge/qlge_main.c, inside qlge_resume(), was passing argument
which got deprecated after upgrade to generic PM. The error is fixed in v2.

Vaibhav Gupta (4):
qlge/qlge_main.c: use generic power management
staging/rtl8192e: use generic power management
rts5208/rtsx.c: use generic power management
vt6655/device_main.c: use generic power management

drivers/staging/qlge/qlge_main.c | 38 ++++++--------------
drivers/staging/rtl8192e/rtl8192e/rtl_core.c | 5 +--
drivers/staging/rtl8192e/rtl8192e/rtl_pm.c | 26 ++++----------
drivers/staging/rtl8192e/rtl8192e/rtl_pm.h | 4 +--
drivers/staging/rts5208/rtsx.c | 30 +++++-----------
drivers/staging/vt6655/device_main.c | 25 ++++---------
6 files changed, 37 insertions(+), 91 deletions(-)

--
2.27.0


2020-06-29 21:23:44

by Vaibhav Gupta

[permalink] [raw]
Subject: [PATCH v2 1/4] qlge/qlge_main.c: use generic power management

Drivers should not use legacy power management as they have to manage power
states and related operations, for the device, themselves. This driver was
handling them with the help of PCI helper functions like
pci_save/restore_state(), pci_enable/disable_device(), etc.

With generic PM, all essentials will be handled by the PCI core. Driver
needs to do only device-specific operations.

The driver was also using pci_enable_wake(...,..., 0) to disable wake. Use
device_wakeup_disable() instead.

Compile-tested only.

Signed-off-by: Vaibhav Gupta <[email protected]>
---
drivers/staging/qlge/qlge_main.c | 38 +++++++++-----------------------
1 file changed, 10 insertions(+), 28 deletions(-)

diff --git a/drivers/staging/qlge/qlge_main.c b/drivers/staging/qlge/qlge_main.c
index 402edaeffe12..86d1b53da2c2 100644
--- a/drivers/staging/qlge/qlge_main.c
+++ b/drivers/staging/qlge/qlge_main.c
@@ -4763,9 +4763,9 @@ static const struct pci_error_handlers qlge_err_handler = {
.resume = qlge_io_resume,
};

-static int qlge_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused qlge_suspend(struct device *dev_d)
{
- struct net_device *ndev = pci_get_drvdata(pdev);
+ struct net_device *ndev = dev_get_drvdata(dev_d);
struct ql_adapter *qdev = netdev_priv(ndev);
int err;

@@ -4779,35 +4779,19 @@ static int qlge_suspend(struct pci_dev *pdev, pm_message_t state)
}

ql_wol(qdev);
- err = pci_save_state(pdev);
- if (err)
- return err;
-
- pci_disable_device(pdev);
-
- pci_set_power_state(pdev, pci_choose_state(pdev, state));

return 0;
}

-#ifdef CONFIG_PM
-static int qlge_resume(struct pci_dev *pdev)
+static int __maybe_unused qlge_resume(struct device *dev_d)
{
- struct net_device *ndev = pci_get_drvdata(pdev);
+ struct net_device *ndev = dev_get_drvdata(dev_d);
struct ql_adapter *qdev = netdev_priv(ndev);
int err;

- pci_set_power_state(pdev, PCI_D0);
- pci_restore_state(pdev);
- err = pci_enable_device(pdev);
- if (err) {
- netif_err(qdev, ifup, qdev->ndev, "Cannot enable PCI device from suspend\n");
- return err;
- }
- pci_set_master(pdev);
+ pci_set_master(to_pci_dev(dev_d));

- pci_enable_wake(pdev, PCI_D3hot, 0);
- pci_enable_wake(pdev, PCI_D3cold, 0);
+ device_wakeup_disable(dev_d);

if (netif_running(ndev)) {
err = ql_adapter_up(qdev);
@@ -4820,22 +4804,20 @@ static int qlge_resume(struct pci_dev *pdev)

return 0;
}
-#endif /* CONFIG_PM */

static void qlge_shutdown(struct pci_dev *pdev)
{
- qlge_suspend(pdev, PMSG_SUSPEND);
+ qlge_suspend(&pdev->dev);
}

+static SIMPLE_DEV_PM_OPS(qlge_pm_ops, qlge_suspend, qlge_resume);
+
static struct pci_driver qlge_driver = {
.name = DRV_NAME,
.id_table = qlge_pci_tbl,
.probe = qlge_probe,
.remove = qlge_remove,
-#ifdef CONFIG_PM
- .suspend = qlge_suspend,
- .resume = qlge_resume,
-#endif
+ .driver.pm = &qlge_pm_ops,
.shutdown = qlge_shutdown,
.err_handler = &qlge_err_handler
};
--
2.27.0