Skip to contentSkip to conversation

orinoco: use generic power management

PATCH In review Vaibhav Gupta 3 participants 4 messages Jun 24, 2020 – Jul 15, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 orinoco: use generic power management

With the support of generic PM callbacks, drivers no longer need to use legacy .suspend() and .resume() in which they had to maintain PCI states changes and device's power state themselves. The required operations are done by PCI core.

PCI drivers are not expected to invoke PCI helper functions like pci_save/restore_state(), pci_enable/disable_device(), pci_set_power_state(), etc. Their tasks are completed by PCI core itself.

Compile-tested only.

---
 .../intersil/orinoco/orinoco_nortel.c         |  3 +-
 .../wireless/intersil/orinoco/orinoco_pci.c   |  3 +-
 .../wireless/intersil/orinoco/orinoco_pci.h   | 32 ++++++-------------
 .../wireless/intersil/orinoco/orinoco_plx.c   |  3 +-
 .../wireless/intersil/orinoco/orinoco_tmd.c   |  3 +-
 5 files changed, 13 insertions(+), 31 deletions(-)
drivers/net/wireless/intersil/orinoco/orinoco_nortel.c +1 -2
index 048693b6c6c2..96a03d10a080 100644
@@ -290,8 +290,7 @@ static struct pci_driver orinoco_nortel_driver = {
 	.id_table	= orinoco_nortel_id_table,
 	.probe		= orinoco_nortel_init_one,
 	.remove		= orinoco_nortel_remove_one,
-	.suspend	= orinoco_pci_suspend,
-	.resume		= orinoco_pci_resume,
+	.driver.pm	= &orinoco_pci_pm_ops,
 };
 
 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
drivers/net/wireless/intersil/orinoco/orinoco_pci.c +1 -2
index 4938a2208a37..f3c86b07b1b9 100644
@@ -230,8 +230,7 @@ static struct pci_driver orinoco_pci_driver = {
 	.id_table	= orinoco_pci_id_table,
 	.probe		= orinoco_pci_init_one,
 	.remove		= orinoco_pci_remove_one,
-	.suspend	= orinoco_pci_suspend,
-	.resume		= orinoco_pci_resume,
+	.driver.pm	= &orinoco_pci_pm_ops,
 };
 
 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
drivers/net/wireless/intersil/orinoco/orinoco_pci.h +9 -23
index 43f5b9f5a0b0..d49d940864b4 100644
@@ -18,51 +18,37 @@ struct orinoco_pci_card {
 	void __iomem *attr_io;
 };
 
-#ifdef CONFIG_PM
-static int orinoco_pci_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused orinoco_pci_suspend(struct device *dev_d)
 {
+	struct pci_dev *pdev = to_pci_dev(dev_d);
 	struct orinoco_private *priv = pci_get_drvdata(pdev);
 
 	orinoco_down(priv);
 	free_irq(pdev->irq, priv);
-	pci_save_state(pdev);
-	pci_disable_device(pdev);
-	pci_set_power_state(pdev, PCI_D3hot);
 
 	return 0;
 }
 
-static int orinoco_pci_resume(struct pci_dev *pdev)
+static int __maybe_unused orinoco_pci_resume(struct device *dev_d)
 {
+	struct pci_dev *pdev = to_pci_dev(dev_d);
 	struct orinoco_private *priv = pci_get_drvdata(pdev);
 	struct net_device *dev = priv->ndev;
 	int err;
 
-	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);
-
 	err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
 			  dev->name, priv);
 	if (err) {
 		printk(KERN_ERR "%s: cannot re-allocate IRQ on resume\n",
 		       dev->name);
-		pci_disable_device(pdev);
 		return -EBUSY;
 	}
 
-	err = orinoco_up(priv);
-
-	return err;
+	return orinoco_up(priv);
 }
-#else
-#define orinoco_pci_suspend NULL
-#define orinoco_pci_resume NULL
-#endif
+
+static SIMPLE_DEV_PM_OPS(orinoco_pci_pm_ops,
+			 orinoco_pci_suspend,
+			 orinoco_pci_resume);
 
 #endif /* _ORINOCO_PCI_H */
drivers/net/wireless/intersil/orinoco/orinoco_plx.c +1 -2
index 221352027779..16dada94c774 100644
@@ -336,8 +336,7 @@ static struct pci_driver orinoco_plx_driver = {
 	.id_table	= orinoco_plx_id_table,
 	.probe		= orinoco_plx_init_one,
 	.remove		= orinoco_plx_remove_one,
-	.suspend	= orinoco_pci_suspend,
-	.resume		= orinoco_pci_resume,
+	.driver.pm	= &orinoco_pci_pm_ops,
 };
 
 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
drivers/net/wireless/intersil/orinoco/orinoco_tmd.c +1 -2
index 20ce569b8a43..9a9d335611ac 100644
@@ -213,8 +213,7 @@ static struct pci_driver orinoco_tmd_driver = {
 	.id_table	= orinoco_tmd_id_table,
 	.probe		= orinoco_tmd_init_one,
 	.remove		= orinoco_tmd_remove_one,
-	.suspend	= orinoco_pci_suspend,
-	.resume		= orinoco_pci_resume,
+	.driver.pm	= &orinoco_pci_pm_ops,
 };
 
 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
Signature · 1 line
2.27.0
#1 lore raw
Quoted 145 lines · Vaibhav Gupta

With the support of generic PM callbacks, drivers no longer need to use legacy .suspend() and .resume() in which they had to maintain PCI states changes and device's power state themselves. The required operations are done by PCI core.

PCI drivers are not expected to invoke PCI helper functions like pci_save/restore_state(), pci_enable/disable_device(), pci_set_power_state(), etc. Their tasks are completed by PCI core itself.

Compile-tested only.

---
 .../intersil/orinoco/orinoco_nortel.c         |  3 +-
 .../wireless/intersil/orinoco/orinoco_pci.c   |  3 +-
 .../wireless/intersil/orinoco/orinoco_pci.h   | 32 ++++++-------------
 .../wireless/intersil/orinoco/orinoco_plx.c   |  3 +-
 .../wireless/intersil/orinoco/orinoco_tmd.c   |  3 +-
 5 files changed, 13 insertions(+), 31 deletions(-)
drivers/net/wireless/intersil/orinoco/orinoco_nortel.c +1 -2
index 048693b6c6c2..96a03d10a080 100644
@@ -290,8 +290,7 @@ static struct pci_driver orinoco_nortel_driver = {
        .id_table       = orinoco_nortel_id_table,
        .probe          = orinoco_nortel_init_one,
        .remove         = orinoco_nortel_remove_one,
-       .suspend        = orinoco_pci_suspend,
-       .resume         = orinoco_pci_resume,
+       .driver.pm      = &orinoco_pci_pm_ops,
 };
 
 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
drivers/net/wireless/intersil/orinoco/orinoco_pci.c +1 -2
index 4938a2208a37..f3c86b07b1b9 100644
@@ -230,8 +230,7 @@ static struct pci_driver orinoco_pci_driver = {
        .id_table       = orinoco_pci_id_table,
        .probe          = orinoco_pci_init_one,
        .remove         = orinoco_pci_remove_one,
-       .suspend        = orinoco_pci_suspend,
-       .resume         = orinoco_pci_resume,
+       .driver.pm      = &orinoco_pci_pm_ops,
 };
 
 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
drivers/net/wireless/intersil/orinoco/orinoco_pci.h +9 -23
index 43f5b9f5a0b0..d49d940864b4 100644
@@ -18,51 +18,37 @@ struct orinoco_pci_card {
        void __iomem *attr_io;
 };
 
-#ifdef CONFIG_PM
-static int orinoco_pci_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused orinoco_pci_suspend(struct device *dev_d)
 {
+       struct pci_dev *pdev = to_pci_dev(dev_d);
        struct orinoco_private *priv = pci_get_drvdata(pdev);
 
        orinoco_down(priv);
        free_irq(pdev->irq, priv);
-       pci_save_state(pdev);
-       pci_disable_device(pdev);
-       pci_set_power_state(pdev, PCI_D3hot);
 
        return 0;
 }
 
-static int orinoco_pci_resume(struct pci_dev *pdev)
+static int __maybe_unused orinoco_pci_resume(struct device *dev_d)
 {
+       struct pci_dev *pdev = to_pci_dev(dev_d);
        struct orinoco_private *priv = pci_get_drvdata(pdev);
        struct net_device *dev = priv->ndev;
        int err;
 
-       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);
-
        err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
                          dev->name, priv);
        if (err) {
                printk(KERN_ERR "%s: cannot re-allocate IRQ on resume\n",
                       dev->name);
-               pci_disable_device(pdev);
                return -EBUSY;
        }
 
-       err = orinoco_up(priv);
-
-       return err;
+       return orinoco_up(priv);
 }
-#else
-#define orinoco_pci_suspend NULL
-#define orinoco_pci_resume NULL
-#endif
+
+static SIMPLE_DEV_PM_OPS(orinoco_pci_pm_ops,
+                        orinoco_pci_suspend,
+                        orinoco_pci_resume);
 
 #endif /* _ORINOCO_PCI_H */
drivers/net/wireless/intersil/orinoco/orinoco_plx.c +1 -2
index 221352027779..16dada94c774 100644
@@ -336,8 +336,7 @@ static struct pci_driver orinoco_plx_driver = {
        .id_table       = orinoco_plx_id_table,
        .probe          = orinoco_plx_init_one,
        .remove         = orinoco_plx_remove_one,
-       .suspend        = orinoco_pci_suspend,
-       .resume         = orinoco_pci_resume,
+       .driver.pm      = &orinoco_pci_pm_ops,
 };
 
 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
drivers/net/wireless/intersil/orinoco/orinoco_tmd.c +1 -3
index 20ce569b8a43..9a9d335611ac 100644
@@ -213,8 +213,7 @@ static struct pci_driver orinoco_tmd_driver = {
        .id_table       = orinoco_tmd_id_table,
        .probe          = orinoco_tmd_init_one,
        .remove         = orinoco_tmd_remove_one,
-       .suspend        = orinoco_pci_suspend,
-       .resume         = orinoco_pci_resume,
+       .driver.pm      = &orinoco_pci_pm_ops,
 };
 
 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
--

2.27.0

#2 lore raw
In reply to Vaibhav Gupta
Quoted 5 lines · Vaibhav Gupta

With the support of generic PM callbacks, drivers no longer need to use legacy .suspend() and .resume() in which they had to maintain PCI states changes and device's power state themselves. The required operations are done by PCI core.

Quoted 7 lines

PCI drivers are not expected to invoke PCI helper functions like pci_save/restore_state(), pci_enable/disable_device(), pci_set_power_state(), etc. Their tasks are completed by PCI core itself.

Compile-tested only.

Patch applied to wireless-drivers-next.git, thanks.

c689a62b6712 orinoco: use generic power management

Signature · 3 lines
https://patchwork.kernel.org/patch/11623867/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#3 lore raw
In reply to Vaibhav Gupta
Quoted 5 lines · Vaibhav Gupta

With the support of generic PM callbacks, drivers no longer need to use legacy .suspend() and .resume() in which they had to maintain PCI states changes and device's power state themselves. The required operations are done by PCI core.

Quoted 7 lines

PCI drivers are not expected to invoke PCI helper functions like pci_save/restore_state(), pci_enable/disable_device(), pci_set_power_state(), etc. Their tasks are completed by PCI core itself.

Compile-tested only.

Patch applied to wireless-drivers-next.git, thanks.

c689a62b6712 orinoco: use generic power management

Signature · 8 lines
https://patchwork.kernel.org/patch/11623867/

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

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees