scsi: stex: use generic power management
Subsystems (5)
PATCH 1/1 scsi: stex: use generic power management
Drivers using legacy power management .suspen()/.resume() callbacks have to manage PCI states and device's PM states themselves. They also need to take care of standard configuration registers.
Switch to generic power management framework using a single "struct dev_pm_ops" variable to take the unnecessary load from the driver. This also avoids the need for the driver to directly call most of the PCI helper functions and device power state control functions, as through the generic framework PCI Core takes care of the necessary operations, and drivers are required to do only device-specific jobs.
--- drivers/scsi/stex.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-)
drivers/scsi/stex.c +29 -6
@@ -1972,9 +1972,9 @@ static int stex_choice_sleep_mic(struct st_hba *hba, pm_message_t state) } } -static int stex_suspend (struct pci_dev *pdev,pm_message_t state) +static int stex_suspend_late (struct device *dev,pm_message_t state) { -struct st_hba *hba =pci_get_drvdata (pdev); +struct st_hba *hba =dev_get_drvdata (dev);if ((hba->cardtype == st_yel || hba->cardtype == st_P3) && hba->supports_pm ==1 )
@@ -1984,9 +1984,24 @@ static int stex_suspend(struct pci_dev *pdev, pm_message_t state)return 0 ; } -static int stex_resume (struct pci_dev *pdev) +static int stex_suspend (struct device *dev) { -struct st_hba *hba =pci_get_drvdata (pdev); +return stex_suspend_late (dev,PMSG_SUSPEND ); +} + +static int stex_hibernate (struct device *dev) +{ +return stex_suspend_late (dev,PMSG_HIBERNATE ); +} + +static int stex_freeze (struct device *dev) +{ +return stex_suspend_late (dev,PMSG_FREEZE ); +} + +static int stex_resume (struct device *dev) +{ +struct st_hba *hba =dev_get_drvdata (dev); hba->mu_status =MU_STATE_STARTING ;stex_handshake (hba);
@@ -2000,14 +2015,22 @@ static int stex_halt(struct notifier_block *nb, unsigned long event, void *buf) }MODULE_DEVICE_TABLE (pci, stex_pci_tbl); +static const struct dev_pm_ops stex_pm_ops = { + .suspend = stex_suspend, + .resume = stex_resume, + .freeze = stex_freeze, + .thaw = stex_resume, + .poweroff = stex_hibernate, + .restore = stex_resume, +}; +static struct pci_driver stex_pci_driver = { .name =DRV_NAME , .id_table = stex_pci_tbl, .probe = stex_probe, .remove = stex_remove, .shutdown = stex_shutdown, - .suspend = stex_suspend, - .resume = stex_resume, + .driver.pm = &stex_pm_ops, };static int __init stex_init (void )
Signature · 1 line
2.27.0
cover net: ethernet: use generic power management
Linux Kernel Mentee: Remove Legacy Power Management.
The purpose of this patch series is to upgrade power management in net ethernet drivers. This has been done by upgrading .suspend() and .resume() callbacks.
The upgrade makes sure that the involvement of PCI Core does not change the order of operations executed in a driver. Thus, does not change its behavior.
In general, drivers with legacy PM, .suspend() and .resume() make use of PCI helper functions like pci_enable/disable_device_mem(), pci_set_power_state(), pci_save/restore_state(), pci_enable/disable_device(), etc. to complete their job.
The conversion requires the removal of those function calls, change the callbacks' definition accordingly and make use of dev_pm_ops structure.
All patches are compile-tested only.
Test tools:
- Compiler: gcc (GCC) 10.1.0
- allmodconfig build: make -j$(nproc) W=1 all
Vaibhav Gupta (3):
sc92031: use generic power management
sis900: use generic power management
tlan: use generic power management
drivers/net/ethernet/silan/sc92031.c | 26 ++++++++--------------- drivers/net/ethernet/sis/sis900.c | 23 +++++++-------------- drivers/net/ethernet/ti/tlan.c | 31 ++++++---------------------- 3 files changed, 22 insertions(+), 58 deletions(-)
Signature · 1 line
2.27.0
PATCH 1/3 sc92031: use generic power management
Drivers using legacy power management .suspen()/.resume() callbacks have to manage PCI states and device's PM states themselves. They also need to take care of standard configuration registers.
Switch to generic power management framework using a single "struct dev_pm_ops" variable to take the unnecessary load from the driver. This also avoids the need for the driver to directly call most of the PCI helper functions and device power state control functions, as through the generic framework PCI Core takes care of the necessary operations, and drivers are required to do only device-specific jobs.
--- drivers/net/ethernet/silan/sc92031.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-)
drivers/net/ethernet/silan/sc92031.c +9 -17
@@ -1499,15 +1499,13 @@ static void sc92031_remove(struct pci_dev *pdev)pci_disable_device (pdev); } -static int sc92031_suspend (struct pci_dev *pdev,pm_message_t state) +static int __maybe_unused sc92031_suspend (struct device *dev_d) { -struct net_device *dev =pci_get_drvdata (pdev); +struct net_device *dev =dev_get_drvdata (dev_d);struct sc92031_priv *priv =netdev_priv (dev); -pci_save_state (pdev); -if (!netif_running (dev)) - goto out; +return 0 ;netif_device_detach (dev);
@@ -1521,22 +1519,16 @@ static int sc92031_suspend(struct pci_dev *pdev, pm_message_t state)spin_unlock_bh (&priv->lock); -out: -pci_set_power_state (pdev,pci_choose_state (pdev, state)); -return 0 ; } -static int sc92031_resume (struct pci_dev *pdev) +static int __maybe_unused sc92031_resume (struct device *dev_d) { -struct net_device *dev =pci_get_drvdata (pdev); +struct net_device *dev =dev_get_drvdata (dev_d);struct sc92031_priv *priv =netdev_priv (dev); -pci_restore_state (pdev); -pci_set_power_state (pdev,PCI_D0 ); -if (!netif_running (dev)) - goto out; +return 0 ;/* Interrupts already disabled by sc92031_suspend */ spin_lock_bh (&priv->lock);
@@ -1553,7 +1545,6 @@ static int sc92031_resume(struct pci_dev *pdev)else netif_tx_disable (dev); -out:return 0 ; }
@@ -1565,13 +1556,14 @@ static const struct pci_device_id sc92031_pci_device_id_table[] = { };MODULE_DEVICE_TABLE (pci, sc92031_pci_device_id_table); +static SIMPLE_DEV_PM_OPS(sc92031_pm_ops, sc92031_suspend, sc92031_resume); +static struct pci_driver sc92031_pci_driver = { .name =SC92031_NAME , .id_table = sc92031_pci_device_id_table, .probe = sc92031_probe, .remove = sc92031_remove, - .suspend = sc92031_suspend, - .resume = sc92031_resume, + .driver.pm = &sc92031_pm_ops, };module_pci_driver (sc92031_pci_driver);
Signature · 1 line
2.27.0
PATCH 2/3 sis900: use generic power management
In reply to Vaibhav GuptaDrivers using legacy power management .suspen()/.resume() callbacks have to manage PCI states and device's PM states themselves. They also need to take care of standard configuration registers.
Switch to generic power management framework using a single "struct dev_pm_ops" variable to take the unnecessary load from the driver. This also avoids the need for the driver to directly call most of the PCI helper functions and device power state control functions, as through the generic framework PCI Core takes care of the necessary operations, and drivers are required to do only device-specific jobs.
--- drivers/net/ethernet/sis/sis900.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-)
drivers/net/ethernet/sis/sis900.c +7 -16
@@ -2493,11 +2493,9 @@ static void sis900_remove(struct pci_dev *pci_dev)pci_release_regions (pci_dev); } -#ifdef CONFIG_PM - -static int sis900_suspend (struct pci_dev *pci_dev,pm_message_t state) +static int __maybe_unused sis900_suspend (struct device *dev) { -struct net_device *net_dev =pci_get_drvdata (pci_dev); +struct net_device *net_dev =dev_get_drvdata (dev);struct sis900_private *sis_priv =netdev_priv (net_dev);void __iomem *ioaddr = sis_priv->ioaddr;
@@ -2510,22 +2508,17 @@ static int sis900_suspend(struct pci_dev *pci_dev, pm_message_t state)/* Stop the chip's Tx and Rx Status Machine */ sw32 (cr, RxDIS | TxDIS |sr32 (cr)); -pci_set_power_state (pci_dev, PCI_D3hot); -pci_save_state (pci_dev); -return 0 ; } -static int sis900_resume (struct pci_dev *pci_dev) +static int __maybe_unused sis900_resume (struct device *dev) { -struct net_device *net_dev =pci_get_drvdata (pci_dev); +struct net_device *net_dev =dev_get_drvdata (dev);struct sis900_private *sis_priv =netdev_priv (net_dev);void __iomem *ioaddr = sis_priv->ioaddr;if (!netif_running (net_dev))return 0 ; -pci_restore_state (pci_dev); -pci_set_power_state (pci_dev,PCI_D0 );sis900_init_rxfilter (net_dev);
@@ -2549,17 +2542,15 @@ static int sis900_resume(struct pci_dev *pci_dev)return 0 ; } -#endif /* CONFIG_PM */ + +static SIMPLE_DEV_PM_OPS(sis900_pm_ops, sis900_suspend, sis900_resume);static struct pci_driver sis900_pci_driver = { .name =SIS900_MODULE_NAME , .id_table = sis900_pci_tbl, .probe = sis900_probe, .remove = sis900_remove, -#ifdef CONFIG_PM - .suspend = sis900_suspend, - .resume = sis900_resume, -#endif /* CONFIG_PM */ + .driver.pm = &sis900_pm_ops, };static int __init sis900_init_module (void )
Signature · 1 line
2.27.0
PATCH 3/3 tlan: use generic power management
In reply to Vaibhav GuptaDrivers using legacy power management .suspen()/.resume() callbacks have to manage PCI states and device's PM states themselves. They also need to take care of standard configuration registers.
Switch to generic power management framework using a single "struct dev_pm_ops" variable to take the unnecessary load from the driver. This also avoids the need for the driver to directly call most of the PCI helper functions and device power state control functions, as through the generic framework PCI Core takes care of the necessary operations, and drivers are required to do only device-specific jobs.
--- drivers/net/ethernet/ti/tlan.c | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-)
drivers/net/ethernet/ti/tlan.c +6 -25
@@ -345,33 +345,21 @@ static void tlan_stop(struct net_device *dev) } } -#ifdef CONFIG_PM - -static int tlan_suspend (struct pci_dev *pdev,pm_message_t state) +static int __maybe_unused tlan_suspend (struct device *dev_d) { -struct net_device *dev =pci_get_drvdata (pdev); +struct net_device *dev =dev_get_drvdata (dev_d);if (netif_running (dev))tlan_stop (dev);netif_device_detach (dev); -pci_save_state (pdev); -pci_disable_device (pdev); -pci_wake_from_d3 (pdev, false); -pci_set_power_state (pdev, PCI_D3hot);return 0 ; } -static int tlan_resume (struct pci_dev *pdev) +static int __maybe_unused tlan_resume (struct device *dev_d) { -struct net_device *dev =pci_get_drvdata (pdev); -int rc =pci_enable_device (pdev); - -if (rc) -return rc; -pci_restore_state (pdev); -pci_enable_wake (pdev,PCI_D0 ,0 ); +struct net_device *dev =dev_get_drvdata (dev_d);netif_device_attach (dev);if (netif_running (dev))
@@ -380,21 +368,14 @@ static int tlan_resume(struct pci_dev *pdev)return 0 ; } -#else /* CONFIG_PM */ - -#define tlan_suspend NULL -#define tlan_resume NULL - -#endif /* CONFIG_PM */ - +static SIMPLE_DEV_PM_OPS(tlan_pm_ops, tlan_suspend, tlan_resume);static struct pci_driver tlan_driver = { .name ="tlan" , .id_table = tlan_pci_tbl, .probe = tlan_init_one, .remove = tlan_remove_one, - .suspend = tlan_suspend, - .resume = tlan_resume, + .driver.pm = &tlan_pm_ops, };static int __init tlan_probe (void )
Signature · 1 line
2.27.0