Commit 3ce38d39 authored by David S. Miller's avatar David S. Miller

Merge branch 'net-ethernet-use-generic-power-management'

Vaibhav Gupta says:

====================
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
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents bbf1b94a 04db6465
...@@ -1499,15 +1499,13 @@ static void sc92031_remove(struct pci_dev *pdev) ...@@ -1499,15 +1499,13 @@ static void sc92031_remove(struct pci_dev *pdev)
pci_disable_device(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); struct sc92031_priv *priv = netdev_priv(dev);
pci_save_state(pdev);
if (!netif_running(dev)) if (!netif_running(dev))
goto out; return 0;
netif_device_detach(dev); netif_device_detach(dev);
...@@ -1521,22 +1519,16 @@ static int sc92031_suspend(struct pci_dev *pdev, pm_message_t state) ...@@ -1521,22 +1519,16 @@ static int sc92031_suspend(struct pci_dev *pdev, pm_message_t state)
spin_unlock_bh(&priv->lock); spin_unlock_bh(&priv->lock);
out:
pci_set_power_state(pdev, pci_choose_state(pdev, state));
return 0; 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); struct sc92031_priv *priv = netdev_priv(dev);
pci_restore_state(pdev);
pci_set_power_state(pdev, PCI_D0);
if (!netif_running(dev)) if (!netif_running(dev))
goto out; return 0;
/* Interrupts already disabled by sc92031_suspend */ /* Interrupts already disabled by sc92031_suspend */
spin_lock_bh(&priv->lock); spin_lock_bh(&priv->lock);
...@@ -1553,7 +1545,6 @@ static int sc92031_resume(struct pci_dev *pdev) ...@@ -1553,7 +1545,6 @@ static int sc92031_resume(struct pci_dev *pdev)
else else
netif_tx_disable(dev); netif_tx_disable(dev);
out:
return 0; return 0;
} }
...@@ -1565,13 +1556,14 @@ static const struct pci_device_id sc92031_pci_device_id_table[] = { ...@@ -1565,13 +1556,14 @@ static const struct pci_device_id sc92031_pci_device_id_table[] = {
}; };
MODULE_DEVICE_TABLE(pci, 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 = { static struct pci_driver sc92031_pci_driver = {
.name = SC92031_NAME, .name = SC92031_NAME,
.id_table = sc92031_pci_device_id_table, .id_table = sc92031_pci_device_id_table,
.probe = sc92031_probe, .probe = sc92031_probe,
.remove = sc92031_remove, .remove = sc92031_remove,
.suspend = sc92031_suspend, .driver.pm = &sc92031_pm_ops,
.resume = sc92031_resume,
}; };
module_pci_driver(sc92031_pci_driver); module_pci_driver(sc92031_pci_driver);
......
...@@ -2502,11 +2502,9 @@ static void sis900_remove(struct pci_dev *pci_dev) ...@@ -2502,11 +2502,9 @@ static void sis900_remove(struct pci_dev *pci_dev)
pci_release_regions(pci_dev); pci_release_regions(pci_dev);
} }
#ifdef CONFIG_PM static int __maybe_unused sis900_suspend(struct device *dev)
static int sis900_suspend(struct pci_dev *pci_dev, pm_message_t state)
{ {
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); struct sis900_private *sis_priv = netdev_priv(net_dev);
void __iomem *ioaddr = sis_priv->ioaddr; void __iomem *ioaddr = sis_priv->ioaddr;
...@@ -2519,22 +2517,17 @@ static int sis900_suspend(struct pci_dev *pci_dev, pm_message_t state) ...@@ -2519,22 +2517,17 @@ static int sis900_suspend(struct pci_dev *pci_dev, pm_message_t state)
/* Stop the chip's Tx and Rx Status Machine */ /* Stop the chip's Tx and Rx Status Machine */
sw32(cr, RxDIS | TxDIS | sr32(cr)); sw32(cr, RxDIS | TxDIS | sr32(cr));
pci_set_power_state(pci_dev, PCI_D3hot);
pci_save_state(pci_dev);
return 0; 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); struct sis900_private *sis_priv = netdev_priv(net_dev);
void __iomem *ioaddr = sis_priv->ioaddr; void __iomem *ioaddr = sis_priv->ioaddr;
if(!netif_running(net_dev)) if(!netif_running(net_dev))
return 0; return 0;
pci_restore_state(pci_dev);
pci_set_power_state(pci_dev, PCI_D0);
sis900_init_rxfilter(net_dev); sis900_init_rxfilter(net_dev);
...@@ -2558,17 +2551,15 @@ static int sis900_resume(struct pci_dev *pci_dev) ...@@ -2558,17 +2551,15 @@ static int sis900_resume(struct pci_dev *pci_dev)
return 0; return 0;
} }
#endif /* CONFIG_PM */
static SIMPLE_DEV_PM_OPS(sis900_pm_ops, sis900_suspend, sis900_resume);
static struct pci_driver sis900_pci_driver = { static struct pci_driver sis900_pci_driver = {
.name = SIS900_MODULE_NAME, .name = SIS900_MODULE_NAME,
.id_table = sis900_pci_tbl, .id_table = sis900_pci_tbl,
.probe = sis900_probe, .probe = sis900_probe,
.remove = sis900_remove, .remove = sis900_remove,
#ifdef CONFIG_PM .driver.pm = &sis900_pm_ops,
.suspend = sis900_suspend,
.resume = sis900_resume,
#endif /* CONFIG_PM */
}; };
static int __init sis900_init_module(void) static int __init sis900_init_module(void)
......
...@@ -345,33 +345,21 @@ static void tlan_stop(struct net_device *dev) ...@@ -345,33 +345,21 @@ static void tlan_stop(struct net_device *dev)
} }
} }
#ifdef CONFIG_PM static int __maybe_unused tlan_suspend(struct device *dev_d)
static int tlan_suspend(struct pci_dev *pdev, pm_message_t state)
{ {
struct net_device *dev = pci_get_drvdata(pdev); struct net_device *dev = dev_get_drvdata(dev_d);
if (netif_running(dev)) if (netif_running(dev))
tlan_stop(dev); tlan_stop(dev);
netif_device_detach(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; 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); struct net_device *dev = dev_get_drvdata(dev_d);
int rc = pci_enable_device(pdev);
if (rc)
return rc;
pci_restore_state(pdev);
pci_enable_wake(pdev, PCI_D0, 0);
netif_device_attach(dev); netif_device_attach(dev);
if (netif_running(dev)) if (netif_running(dev))
...@@ -380,21 +368,14 @@ static int tlan_resume(struct pci_dev *pdev) ...@@ -380,21 +368,14 @@ static int tlan_resume(struct pci_dev *pdev)
return 0; return 0;
} }
#else /* CONFIG_PM */ static SIMPLE_DEV_PM_OPS(tlan_pm_ops, tlan_suspend, tlan_resume);
#define tlan_suspend NULL
#define tlan_resume NULL
#endif /* CONFIG_PM */
static struct pci_driver tlan_driver = { static struct pci_driver tlan_driver = {
.name = "tlan", .name = "tlan",
.id_table = tlan_pci_tbl, .id_table = tlan_pci_tbl,
.probe = tlan_init_one, .probe = tlan_init_one,
.remove = tlan_remove_one, .remove = tlan_remove_one,
.suspend = tlan_suspend, .driver.pm = &tlan_pm_ops,
.resume = tlan_resume,
}; };
static int __init tlan_probe(void) static int __init tlan_probe(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment