2020-06-29 03:34:10

by Vaibhav Gupta

[permalink] [raw]
Subject: [PATCH v1 0/2] ipw2x00: 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.

Vaibhav Gupta (2):
ipw2100: use generic power management
ipw2200: use generic power management

drivers/net/wireless/intel/ipw2x00/ipw2100.c | 31 +++++---------------
drivers/net/wireless/intel/ipw2x00/ipw2200.c | 30 +++++--------------
2 files changed, 14 insertions(+), 47 deletions(-)

--
2.27.0


2020-06-29 03:34:27

by Vaibhav Gupta

[permalink] [raw]
Subject: [PATCH v1 1/2] ipw2100: use generic power management

With legacy PM, drivers themselves were responsible for managing the
device's power states and takes care of register states.

After upgrading to the generic structure, PCI core will take care of
required tasks and drivers should do only device-specific operations.

The driver was invoking PCI helper functions like pci_save/restore_state(),
pci_enable/disable_device() and pci_set_power_state(), which is not
recommended.

Compile-tested only.

Signed-off-by: Vaibhav Gupta <[email protected]>
---
drivers/net/wireless/intel/ipw2x00/ipw2100.c | 31 +++++---------------
1 file changed, 7 insertions(+), 24 deletions(-)

diff --git a/drivers/net/wireless/intel/ipw2x00/ipw2100.c b/drivers/net/wireless/intel/ipw2x00/ipw2100.c
index 624fe721e2b5..57ce55728808 100644
--- a/drivers/net/wireless/intel/ipw2x00/ipw2100.c
+++ b/drivers/net/wireless/intel/ipw2x00/ipw2100.c
@@ -6397,10 +6397,9 @@ static void ipw2100_pci_remove_one(struct pci_dev *pci_dev)
IPW_DEBUG_INFO("exit\n");
}

-#ifdef CONFIG_PM
-static int ipw2100_suspend(struct pci_dev *pci_dev, pm_message_t state)
+static int __maybe_unused ipw2100_suspend(struct device *dev_d)
{
- struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
+ struct ipw2100_priv *priv = dev_get_drvdata(dev_d);
struct net_device *dev = priv->net_dev;

IPW_DEBUG_INFO("%s: Going into suspend...\n", dev->name);
@@ -6414,10 +6413,6 @@ static int ipw2100_suspend(struct pci_dev *pci_dev, pm_message_t state)
/* Remove the PRESENT state of the device */
netif_device_detach(dev);

- pci_save_state(pci_dev);
- pci_disable_device(pci_dev);
- pci_set_power_state(pci_dev, PCI_D3hot);
-
priv->suspend_at = ktime_get_boottime_seconds();

mutex_unlock(&priv->action_mutex);
@@ -6425,11 +6420,11 @@ static int ipw2100_suspend(struct pci_dev *pci_dev, pm_message_t state)
return 0;
}

-static int ipw2100_resume(struct pci_dev *pci_dev)
+static int __maybe_unused ipw2100_resume(struct device *dev_d)
{
+ struct pci_dev *pci_dev = to_pci_dev(dev_d);
struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
struct net_device *dev = priv->net_dev;
- int err;
u32 val;

if (IPW2100_PM_DISABLED)
@@ -6439,16 +6434,6 @@ static int ipw2100_resume(struct pci_dev *pci_dev)

IPW_DEBUG_INFO("%s: Coming out of suspend...\n", dev->name);

- pci_set_power_state(pci_dev, PCI_D0);
- err = pci_enable_device(pci_dev);
- if (err) {
- printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
- dev->name);
- mutex_unlock(&priv->action_mutex);
- return err;
- }
- pci_restore_state(pci_dev);
-
/*
* Suspend/Resume resets the PCI configuration space, so we have to
* re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
@@ -6473,7 +6458,6 @@ static int ipw2100_resume(struct pci_dev *pci_dev)

return 0;
}
-#endif

static void ipw2100_shutdown(struct pci_dev *pci_dev)
{
@@ -6539,15 +6523,14 @@ static const struct pci_device_id ipw2100_pci_id_table[] = {

MODULE_DEVICE_TABLE(pci, ipw2100_pci_id_table);

+static SIMPLE_DEV_PM_OPS(ipw2100_pm_ops, ipw2100_suspend, ipw2100_resume);
+
static struct pci_driver ipw2100_pci_driver = {
.name = DRV_NAME,
.id_table = ipw2100_pci_id_table,
.probe = ipw2100_pci_init_one,
.remove = ipw2100_pci_remove_one,
-#ifdef CONFIG_PM
- .suspend = ipw2100_suspend,
- .resume = ipw2100_resume,
-#endif
+ .driver.pm = &ipw2100_pm_ops,
.shutdown = ipw2100_shutdown,
};

--
2.27.0

2020-06-29 03:37:28

by Vaibhav Gupta

[permalink] [raw]
Subject: [PATCH v1 2/2] ipw2200: use generic power management

With legacy PM, drivers themselves were responsible for managing the
device's power states and takes care of register states.

After upgrading to the generic structure, PCI core will take care of
required tasks and drivers should do only device-specific operations.

The driver was invoking PCI helper functions like pci_save/restore_state(),
pci_enable/disable_device() and pci_set_power_state(), which is not
recommended.

Compile-tested only.

Signed-off-by: Vaibhav Gupta <[email protected]>
---
drivers/net/wireless/intel/ipw2x00/ipw2200.c | 30 +++++---------------
1 file changed, 7 insertions(+), 23 deletions(-)

diff --git a/drivers/net/wireless/intel/ipw2x00/ipw2200.c b/drivers/net/wireless/intel/ipw2x00/ipw2200.c
index 661e63bfc892..39ff3a426092 100644
--- a/drivers/net/wireless/intel/ipw2x00/ipw2200.c
+++ b/drivers/net/wireless/intel/ipw2x00/ipw2200.c
@@ -11838,10 +11838,9 @@ static void ipw_pci_remove(struct pci_dev *pdev)
free_firmware();
}

-#ifdef CONFIG_PM
-static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused ipw_pci_suspend(struct device *dev_d)
{
- struct ipw_priv *priv = pci_get_drvdata(pdev);
+ struct ipw_priv *priv = dev_get_drvdata(dev_d);
struct net_device *dev = priv->net_dev;

printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
@@ -11852,33 +11851,20 @@ static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
/* Remove the PRESENT state of the device */
netif_device_detach(dev);

- pci_save_state(pdev);
- pci_disable_device(pdev);
- pci_set_power_state(pdev, pci_choose_state(pdev, state));
-
priv->suspend_at = ktime_get_boottime_seconds();

return 0;
}

-static int ipw_pci_resume(struct pci_dev *pdev)
+static int __maybe_unused ipw_pci_resume(struct device *dev_d)
{
+ struct pci_dev *pdev = to_pci_dev(dev_d);
struct ipw_priv *priv = pci_get_drvdata(pdev);
struct net_device *dev = priv->net_dev;
- int err;
u32 val;

printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);

- pci_set_power_state(pdev, PCI_D0);
- err = pci_enable_device(pdev);
- if (err) {
- printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
- dev->name);
- return err;
- }
- pci_restore_state(pdev);
-
/*
* Suspend/Resume resets the PCI configuration space, so we have to
* re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
@@ -11900,7 +11886,6 @@ static int ipw_pci_resume(struct pci_dev *pdev)

return 0;
}
-#endif

static void ipw_pci_shutdown(struct pci_dev *pdev)
{
@@ -11912,16 +11897,15 @@ static void ipw_pci_shutdown(struct pci_dev *pdev)
pci_disable_device(pdev);
}

+static SIMPLE_DEV_PM_OPS(ipw_pci_pm_ops, ipw_pci_suspend, ipw_pci_resume);
+
/* driver initialization stuff */
static struct pci_driver ipw_driver = {
.name = DRV_NAME,
.id_table = card_ids,
.probe = ipw_pci_probe,
.remove = ipw_pci_remove,
-#ifdef CONFIG_PM
- .suspend = ipw_pci_suspend,
- .resume = ipw_pci_resume,
-#endif
+ .driver.pm = &ipw_pci_pm_ops,
.shutdown = ipw_pci_shutdown,
};

--
2.27.0

2020-06-29 19:15:26

by Vaibhav Gupta

[permalink] [raw]
Subject: Re: [PATCH v1 0/2] ipw2x00: use generic power management

On Mon, 29 Jun 2020 at 11:20, Kalle Valo <[email protected]> wrote:
>
> Vaibhav Gupta <[email protected]> writes:
>
> > 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.
> >
> > Vaibhav Gupta (2):
> > ipw2100: use generic power management
> > ipw2200: use generic power management
> >
> > drivers/net/wireless/intel/ipw2x00/ipw2100.c | 31 +++++---------------
> > drivers/net/wireless/intel/ipw2x00/ipw2200.c | 30 +++++--------------
> > 2 files changed, 14 insertions(+), 47 deletions(-)
>
> For wireless patches you should CC linux-wireless, otherwise they will
> not be in radar.
Oh yes, sorry! My mistake, I missed CCing them. Sending it again!
> See more from link below.
>
> --
> https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

2020-07-15 11:26:53

by Kalle Valo

[permalink] [raw]
Subject: Re: [PATCH v1 1/2] ipw2100: use generic power management

Vaibhav Gupta <[email protected]> wrote:

> With legacy PM, drivers themselves were responsible for managing the
> device's power states and takes care of register states.
>
> After upgrading to the generic structure, PCI core will take care of
> required tasks and drivers should do only device-specific operations.
>
> The driver was invoking PCI helper functions like pci_save/restore_state(),
> pci_enable/disable_device() and pci_set_power_state(), which is not
> recommended.
>
> Compile-tested only.
>
> Signed-off-by: Vaibhav Gupta <[email protected]>

2 patches applied to wireless-drivers-next.git, thanks.

814db61adb86 ipw2100: use generic power management
77b4ad07699f ipw2200: use generic power management

--
https://patchwork.kernel.org/patch/11632343/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches