Skip to content

Commit

Permalink
Merge branch 'net-ethernet-use-generic-power-management'
Browse files Browse the repository at this point in the history
Vaibhav Gupta says:

====================
net: ethernet: 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 net 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.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Jul 1, 2020
2 parents 4f195d2 + 40c1b1e commit 6d79dc6
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 182 deletions.
53 changes: 32 additions & 21 deletions drivers/net/ethernet/3com/typhoon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1801,9 +1801,8 @@ typhoon_free_rx_rings(struct typhoon *tp)
}

static int
typhoon_sleep(struct typhoon *tp, pci_power_t state, __le16 events)
typhoon_sleep_early(struct typhoon *tp, __le16 events)
{
struct pci_dev *pdev = tp->pdev;
void __iomem *ioaddr = tp->ioaddr;
struct cmd_desc xp_cmd;
int err;
Expand Down Expand Up @@ -1832,20 +1831,29 @@ typhoon_sleep(struct typhoon *tp, pci_power_t state, __le16 events)
*/
netif_carrier_off(tp->dev);

return 0;
}

static int
typhoon_sleep(struct typhoon *tp, pci_power_t state, __le16 events)
{
int err;

err = typhoon_sleep_early(tp, events);

if (err)
return err;

pci_enable_wake(tp->pdev, state, 1);
pci_disable_device(pdev);
return pci_set_power_state(pdev, state);
pci_disable_device(tp->pdev);
return pci_set_power_state(tp->pdev, state);
}

static int
typhoon_wakeup(struct typhoon *tp, int wait_type)
{
struct pci_dev *pdev = tp->pdev;
void __iomem *ioaddr = tp->ioaddr;

pci_set_power_state(pdev, PCI_D0);
pci_restore_state(pdev);

/* Post 2.x.x versions of the Sleep Image require a reset before
* we can download the Runtime Image. But let's not make users of
* the old firmware pay for the reset.
Expand Down Expand Up @@ -2049,6 +2057,9 @@ typhoon_open(struct net_device *dev)
if (err)
goto out;

pci_set_power_state(tp->pdev, PCI_D0);
pci_restore_state(tp->pdev);

err = typhoon_wakeup(tp, WaitSleep);
if (err < 0) {
netdev_err(dev, "unable to wakeup device\n");
Expand Down Expand Up @@ -2114,11 +2125,10 @@ typhoon_close(struct net_device *dev)
return 0;
}

#ifdef CONFIG_PM
static int
typhoon_resume(struct pci_dev *pdev)
static int __maybe_unused
typhoon_resume(struct device *dev_d)
{
struct net_device *dev = pci_get_drvdata(pdev);
struct net_device *dev = dev_get_drvdata(dev_d);
struct typhoon *tp = netdev_priv(dev);

/* If we're down, resume when we are upped.
Expand All @@ -2144,9 +2154,10 @@ typhoon_resume(struct pci_dev *pdev)
return -EBUSY;
}

static int
typhoon_suspend(struct pci_dev *pdev, pm_message_t state)
static int __maybe_unused
typhoon_suspend(struct device *dev_d)
{
struct pci_dev *pdev = to_pci_dev(dev_d);
struct net_device *dev = pci_get_drvdata(pdev);
struct typhoon *tp = netdev_priv(dev);
struct cmd_desc xp_cmd;
Expand Down Expand Up @@ -2190,18 +2201,19 @@ typhoon_suspend(struct pci_dev *pdev, pm_message_t state)
goto need_resume;
}

if (typhoon_sleep(tp, pci_choose_state(pdev, state), tp->wol_events) < 0) {
if (typhoon_sleep_early(tp, tp->wol_events) < 0) {
netdev_err(dev, "unable to put card to sleep\n");
goto need_resume;
}

device_wakeup_enable(dev_d);

return 0;

need_resume:
typhoon_resume(pdev);
typhoon_resume(dev_d);
return -EBUSY;
}
#endif

static int
typhoon_test_mmio(struct pci_dev *pdev)
Expand Down Expand Up @@ -2533,15 +2545,14 @@ typhoon_remove_one(struct pci_dev *pdev)
free_netdev(dev);
}

static SIMPLE_DEV_PM_OPS(typhoon_pm_ops, typhoon_suspend, typhoon_resume);

static struct pci_driver typhoon_driver = {
.name = KBUILD_MODNAME,
.id_table = typhoon_pci_tbl,
.probe = typhoon_init_one,
.remove = typhoon_remove_one,
#ifdef CONFIG_PM
.suspend = typhoon_suspend,
.resume = typhoon_resume,
#endif
.driver.pm = &typhoon_pm_ops,
};

static int __init
Expand Down
29 changes: 6 additions & 23 deletions drivers/net/ethernet/8390/ne2k-pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,50 +699,33 @@ static void ne2k_pci_remove_one(struct pci_dev *pdev)
pci_disable_device(pdev);
}

#ifdef CONFIG_PM
static int ne2k_pci_suspend(struct pci_dev *pdev, pm_message_t state)
static int __maybe_unused ne2k_pci_suspend(struct device *dev_d)
{
struct net_device *dev = pci_get_drvdata(pdev);
struct net_device *dev = dev_get_drvdata(dev_d);

netif_device_detach(dev);
pci_save_state(pdev);
pci_disable_device(pdev);
pci_set_power_state(pdev, pci_choose_state(pdev, state));

return 0;
}

static int ne2k_pci_resume(struct pci_dev *pdev)
static int __maybe_unused ne2k_pci_resume(struct device *dev_d)
{
struct net_device *dev = pci_get_drvdata(pdev);
int rc;

pci_set_power_state(pdev, PCI_D0);
pci_restore_state(pdev);

rc = pci_enable_device(pdev);
if (rc)
return rc;
struct net_device *dev = dev_get_drvdata(dev_d);

NS8390_init(dev, 1);
netif_device_attach(dev);

return 0;
}

#endif /* CONFIG_PM */

static SIMPLE_DEV_PM_OPS(ne2k_pci_pm_ops, ne2k_pci_suspend, ne2k_pci_resume);

static struct pci_driver ne2k_driver = {
.name = DRV_NAME,
.probe = ne2k_pci_init_one,
.remove = ne2k_pci_remove_one,
.id_table = ne2k_pci_tbl,
#ifdef CONFIG_PM
.suspend = ne2k_pci_suspend,
.resume = ne2k_pci_resume,
#endif

.driver.pm = &ne2k_pci_pm_ops,
};


Expand Down
23 changes: 6 additions & 17 deletions drivers/net/ethernet/adaptec/starfire.c
Original file line number Diff line number Diff line change
Expand Up @@ -1984,28 +1984,21 @@ static int netdev_close(struct net_device *dev)
return 0;
}

#ifdef CONFIG_PM
static int starfire_suspend(struct pci_dev *pdev, pm_message_t state)
static int __maybe_unused starfire_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)) {
netif_device_detach(dev);
netdev_close(dev);
}

pci_save_state(pdev);
pci_set_power_state(pdev, pci_choose_state(pdev,state));

return 0;
}

static int starfire_resume(struct pci_dev *pdev)
static int __maybe_unused starfire_resume(struct device *dev_d)
{
struct net_device *dev = pci_get_drvdata(pdev);

pci_set_power_state(pdev, PCI_D0);
pci_restore_state(pdev);
struct net_device *dev = dev_get_drvdata(dev_d);

if (netif_running(dev)) {
netdev_open(dev);
Expand All @@ -2014,8 +2007,6 @@ static int starfire_resume(struct pci_dev *pdev)

return 0;
}
#endif /* CONFIG_PM */


static void starfire_remove_one(struct pci_dev *pdev)
{
Expand All @@ -2040,15 +2031,13 @@ static void starfire_remove_one(struct pci_dev *pdev)
free_netdev(dev); /* Will also free np!! */
}

static SIMPLE_DEV_PM_OPS(starfire_pm_ops, starfire_suspend, starfire_resume);

static struct pci_driver starfire_driver = {
.name = DRV_NAME,
.probe = starfire_init_one,
.remove = starfire_remove_one,
#ifdef CONFIG_PM
.suspend = starfire_suspend,
.resume = starfire_resume,
#endif /* CONFIG_PM */
.driver.pm = &starfire_pm_ops,
.id_table = starfire_pci_tbl,
};

Expand Down
22 changes: 9 additions & 13 deletions drivers/net/ethernet/amazon/ena/ena_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -4420,13 +4420,12 @@ static void ena_shutdown(struct pci_dev *pdev)
__ena_shutoff(pdev, true);
}

#ifdef CONFIG_PM
/* ena_suspend - PM suspend callback
* @pdev: PCI device information struct
* @state:power state
* @dev_d: Device information struct
*/
static int ena_suspend(struct pci_dev *pdev, pm_message_t state)
static int __maybe_unused ena_suspend(struct device *dev_d)
{
struct pci_dev *pdev = to_pci_dev(dev_d);
struct ena_adapter *adapter = pci_get_drvdata(pdev);

u64_stats_update_begin(&adapter->syncp);
Expand All @@ -4445,12 +4444,11 @@ static int ena_suspend(struct pci_dev *pdev, pm_message_t state)
}

/* ena_resume - PM resume callback
* @pdev: PCI device information struct
*
* @dev_d: Device information struct
*/
static int ena_resume(struct pci_dev *pdev)
static int __maybe_unused ena_resume(struct device *dev_d)
{
struct ena_adapter *adapter = pci_get_drvdata(pdev);
struct ena_adapter *adapter = dev_get_drvdata(dev_d);
int rc;

u64_stats_update_begin(&adapter->syncp);
Expand All @@ -4462,18 +4460,16 @@ static int ena_resume(struct pci_dev *pdev)
rtnl_unlock();
return rc;
}
#endif

static SIMPLE_DEV_PM_OPS(ena_pm_ops, ena_suspend, ena_resume);

static struct pci_driver ena_pci_driver = {
.name = DRV_MODULE_NAME,
.id_table = ena_pci_tbl,
.probe = ena_probe,
.remove = ena_remove,
.shutdown = ena_shutdown,
#ifdef CONFIG_PM
.suspend = ena_suspend,
.resume = ena_resume,
#endif
.driver.pm = &ena_pm_ops,
.sriov_configure = pci_sriov_configure_simple,
};

Expand Down
31 changes: 5 additions & 26 deletions drivers/net/ethernet/cavium/liquidio/lio_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,27 +405,8 @@ static void liquidio_pcie_resume(struct pci_dev *pdev __attribute__((unused)))
/* Nothing to be done here. */
}

#ifdef CONFIG_PM
/**
* \brief called when suspending
* @param pdev Pointer to PCI device
* @param state state to suspend to
*/
static int liquidio_suspend(struct pci_dev *pdev __attribute__((unused)),
pm_message_t state __attribute__((unused)))
{
return 0;
}

/**
* \brief called when resuming
* @param pdev Pointer to PCI device
*/
static int liquidio_resume(struct pci_dev *pdev __attribute__((unused)))
{
return 0;
}
#endif
#define liquidio_suspend NULL
#define liquidio_resume NULL

/* For PCI-E Advanced Error Recovery (AER) Interface */
static const struct pci_error_handlers liquidio_err_handler = {
Expand All @@ -451,17 +432,15 @@ static const struct pci_device_id liquidio_pci_tbl[] = {
};
MODULE_DEVICE_TABLE(pci, liquidio_pci_tbl);

static SIMPLE_DEV_PM_OPS(liquidio_pm_ops, liquidio_suspend, liquidio_resume);

static struct pci_driver liquidio_pci_driver = {
.name = "LiquidIO",
.id_table = liquidio_pci_tbl,
.probe = liquidio_probe,
.remove = liquidio_remove,
.err_handler = &liquidio_err_handler, /* For AER */

#ifdef CONFIG_PM
.suspend = liquidio_suspend,
.resume = liquidio_resume,
#endif
.driver.pm = &liquidio_pm_ops,
#ifdef CONFIG_PCI_IOV
.sriov_configure = liquidio_enable_sriov,
#endif
Expand Down
Loading

0 comments on commit 6d79dc6

Please sign in to comment.