Skip to content

Commit 6d79dc6

Browse files
committed
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 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 <[email protected]>
2 parents 4f195d2 + 40c1b1e commit 6d79dc6

File tree

11 files changed

+101
-182
lines changed

11 files changed

+101
-182
lines changed

drivers/net/ethernet/3com/typhoon.c

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,9 +1801,8 @@ typhoon_free_rx_rings(struct typhoon *tp)
18011801
}
18021802

18031803
static int
1804-
typhoon_sleep(struct typhoon *tp, pci_power_t state, __le16 events)
1804+
typhoon_sleep_early(struct typhoon *tp, __le16 events)
18051805
{
1806-
struct pci_dev *pdev = tp->pdev;
18071806
void __iomem *ioaddr = tp->ioaddr;
18081807
struct cmd_desc xp_cmd;
18091808
int err;
@@ -1832,20 +1831,29 @@ typhoon_sleep(struct typhoon *tp, pci_power_t state, __le16 events)
18321831
*/
18331832
netif_carrier_off(tp->dev);
18341833

1834+
return 0;
1835+
}
1836+
1837+
static int
1838+
typhoon_sleep(struct typhoon *tp, pci_power_t state, __le16 events)
1839+
{
1840+
int err;
1841+
1842+
err = typhoon_sleep_early(tp, events);
1843+
1844+
if (err)
1845+
return err;
1846+
18351847
pci_enable_wake(tp->pdev, state, 1);
1836-
pci_disable_device(pdev);
1837-
return pci_set_power_state(pdev, state);
1848+
pci_disable_device(tp->pdev);
1849+
return pci_set_power_state(tp->pdev, state);
18381850
}
18391851

18401852
static int
18411853
typhoon_wakeup(struct typhoon *tp, int wait_type)
18421854
{
1843-
struct pci_dev *pdev = tp->pdev;
18441855
void __iomem *ioaddr = tp->ioaddr;
18451856

1846-
pci_set_power_state(pdev, PCI_D0);
1847-
pci_restore_state(pdev);
1848-
18491857
/* Post 2.x.x versions of the Sleep Image require a reset before
18501858
* we can download the Runtime Image. But let's not make users of
18511859
* the old firmware pay for the reset.
@@ -2049,6 +2057,9 @@ typhoon_open(struct net_device *dev)
20492057
if (err)
20502058
goto out;
20512059

2060+
pci_set_power_state(tp->pdev, PCI_D0);
2061+
pci_restore_state(tp->pdev);
2062+
20522063
err = typhoon_wakeup(tp, WaitSleep);
20532064
if (err < 0) {
20542065
netdev_err(dev, "unable to wakeup device\n");
@@ -2114,11 +2125,10 @@ typhoon_close(struct net_device *dev)
21142125
return 0;
21152126
}
21162127

2117-
#ifdef CONFIG_PM
2118-
static int
2119-
typhoon_resume(struct pci_dev *pdev)
2128+
static int __maybe_unused
2129+
typhoon_resume(struct device *dev_d)
21202130
{
2121-
struct net_device *dev = pci_get_drvdata(pdev);
2131+
struct net_device *dev = dev_get_drvdata(dev_d);
21222132
struct typhoon *tp = netdev_priv(dev);
21232133

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

2147-
static int
2148-
typhoon_suspend(struct pci_dev *pdev, pm_message_t state)
2157+
static int __maybe_unused
2158+
typhoon_suspend(struct device *dev_d)
21492159
{
2160+
struct pci_dev *pdev = to_pci_dev(dev_d);
21502161
struct net_device *dev = pci_get_drvdata(pdev);
21512162
struct typhoon *tp = netdev_priv(dev);
21522163
struct cmd_desc xp_cmd;
@@ -2190,18 +2201,19 @@ typhoon_suspend(struct pci_dev *pdev, pm_message_t state)
21902201
goto need_resume;
21912202
}
21922203

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

2209+
device_wakeup_enable(dev_d);
2210+
21982211
return 0;
21992212

22002213
need_resume:
2201-
typhoon_resume(pdev);
2214+
typhoon_resume(dev_d);
22022215
return -EBUSY;
22032216
}
2204-
#endif
22052217

22062218
static int
22072219
typhoon_test_mmio(struct pci_dev *pdev)
@@ -2533,15 +2545,14 @@ typhoon_remove_one(struct pci_dev *pdev)
25332545
free_netdev(dev);
25342546
}
25352547

2548+
static SIMPLE_DEV_PM_OPS(typhoon_pm_ops, typhoon_suspend, typhoon_resume);
2549+
25362550
static struct pci_driver typhoon_driver = {
25372551
.name = KBUILD_MODNAME,
25382552
.id_table = typhoon_pci_tbl,
25392553
.probe = typhoon_init_one,
25402554
.remove = typhoon_remove_one,
2541-
#ifdef CONFIG_PM
2542-
.suspend = typhoon_suspend,
2543-
.resume = typhoon_resume,
2544-
#endif
2555+
.driver.pm = &typhoon_pm_ops,
25452556
};
25462557

25472558
static int __init

drivers/net/ethernet/8390/ne2k-pci.c

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -699,50 +699,33 @@ static void ne2k_pci_remove_one(struct pci_dev *pdev)
699699
pci_disable_device(pdev);
700700
}
701701

702-
#ifdef CONFIG_PM
703-
static int ne2k_pci_suspend(struct pci_dev *pdev, pm_message_t state)
702+
static int __maybe_unused ne2k_pci_suspend(struct device *dev_d)
704703
{
705-
struct net_device *dev = pci_get_drvdata(pdev);
704+
struct net_device *dev = dev_get_drvdata(dev_d);
706705

707706
netif_device_detach(dev);
708-
pci_save_state(pdev);
709-
pci_disable_device(pdev);
710-
pci_set_power_state(pdev, pci_choose_state(pdev, state));
711707

712708
return 0;
713709
}
714710

715-
static int ne2k_pci_resume(struct pci_dev *pdev)
711+
static int __maybe_unused ne2k_pci_resume(struct device *dev_d)
716712
{
717-
struct net_device *dev = pci_get_drvdata(pdev);
718-
int rc;
719-
720-
pci_set_power_state(pdev, PCI_D0);
721-
pci_restore_state(pdev);
722-
723-
rc = pci_enable_device(pdev);
724-
if (rc)
725-
return rc;
713+
struct net_device *dev = dev_get_drvdata(dev_d);
726714

727715
NS8390_init(dev, 1);
728716
netif_device_attach(dev);
729717

730718
return 0;
731719
}
732720

733-
#endif /* CONFIG_PM */
734-
721+
static SIMPLE_DEV_PM_OPS(ne2k_pci_pm_ops, ne2k_pci_suspend, ne2k_pci_resume);
735722

736723
static struct pci_driver ne2k_driver = {
737724
.name = DRV_NAME,
738725
.probe = ne2k_pci_init_one,
739726
.remove = ne2k_pci_remove_one,
740727
.id_table = ne2k_pci_tbl,
741-
#ifdef CONFIG_PM
742-
.suspend = ne2k_pci_suspend,
743-
.resume = ne2k_pci_resume,
744-
#endif
745-
728+
.driver.pm = &ne2k_pci_pm_ops,
746729
};
747730

748731

drivers/net/ethernet/adaptec/starfire.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,28 +1984,21 @@ static int netdev_close(struct net_device *dev)
19841984
return 0;
19851985
}
19861986

1987-
#ifdef CONFIG_PM
1988-
static int starfire_suspend(struct pci_dev *pdev, pm_message_t state)
1987+
static int __maybe_unused starfire_suspend(struct device *dev_d)
19891988
{
1990-
struct net_device *dev = pci_get_drvdata(pdev);
1989+
struct net_device *dev = dev_get_drvdata(dev_d);
19911990

19921991
if (netif_running(dev)) {
19931992
netif_device_detach(dev);
19941993
netdev_close(dev);
19951994
}
19961995

1997-
pci_save_state(pdev);
1998-
pci_set_power_state(pdev, pci_choose_state(pdev,state));
1999-
20001996
return 0;
20011997
}
20021998

2003-
static int starfire_resume(struct pci_dev *pdev)
1999+
static int __maybe_unused starfire_resume(struct device *dev_d)
20042000
{
2005-
struct net_device *dev = pci_get_drvdata(pdev);
2006-
2007-
pci_set_power_state(pdev, PCI_D0);
2008-
pci_restore_state(pdev);
2001+
struct net_device *dev = dev_get_drvdata(dev_d);
20092002

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

20152008
return 0;
20162009
}
2017-
#endif /* CONFIG_PM */
2018-
20192010

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

2034+
static SIMPLE_DEV_PM_OPS(starfire_pm_ops, starfire_suspend, starfire_resume);
20432035

20442036
static struct pci_driver starfire_driver = {
20452037
.name = DRV_NAME,
20462038
.probe = starfire_init_one,
20472039
.remove = starfire_remove_one,
2048-
#ifdef CONFIG_PM
2049-
.suspend = starfire_suspend,
2050-
.resume = starfire_resume,
2051-
#endif /* CONFIG_PM */
2040+
.driver.pm = &starfire_pm_ops,
20522041
.id_table = starfire_pci_tbl,
20532042
};
20542043

drivers/net/ethernet/amazon/ena/ena_netdev.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4420,13 +4420,12 @@ static void ena_shutdown(struct pci_dev *pdev)
44204420
__ena_shutoff(pdev, true);
44214421
}
44224422

4423-
#ifdef CONFIG_PM
44244423
/* ena_suspend - PM suspend callback
4425-
* @pdev: PCI device information struct
4426-
* @state:power state
4424+
* @dev_d: Device information struct
44274425
*/
4428-
static int ena_suspend(struct pci_dev *pdev, pm_message_t state)
4426+
static int __maybe_unused ena_suspend(struct device *dev_d)
44294427
{
4428+
struct pci_dev *pdev = to_pci_dev(dev_d);
44304429
struct ena_adapter *adapter = pci_get_drvdata(pdev);
44314430

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

44474446
/* ena_resume - PM resume callback
4448-
* @pdev: PCI device information struct
4449-
*
4447+
* @dev_d: Device information struct
44504448
*/
4451-
static int ena_resume(struct pci_dev *pdev)
4449+
static int __maybe_unused ena_resume(struct device *dev_d)
44524450
{
4453-
struct ena_adapter *adapter = pci_get_drvdata(pdev);
4451+
struct ena_adapter *adapter = dev_get_drvdata(dev_d);
44544452
int rc;
44554453

44564454
u64_stats_update_begin(&adapter->syncp);
@@ -4462,18 +4460,16 @@ static int ena_resume(struct pci_dev *pdev)
44624460
rtnl_unlock();
44634461
return rc;
44644462
}
4465-
#endif
4463+
4464+
static SIMPLE_DEV_PM_OPS(ena_pm_ops, ena_suspend, ena_resume);
44664465

44674466
static struct pci_driver ena_pci_driver = {
44684467
.name = DRV_MODULE_NAME,
44694468
.id_table = ena_pci_tbl,
44704469
.probe = ena_probe,
44714470
.remove = ena_remove,
44724471
.shutdown = ena_shutdown,
4473-
#ifdef CONFIG_PM
4474-
.suspend = ena_suspend,
4475-
.resume = ena_resume,
4476-
#endif
4472+
.driver.pm = &ena_pm_ops,
44774473
.sriov_configure = pci_sriov_configure_simple,
44784474
};
44794475

drivers/net/ethernet/cavium/liquidio/lio_main.c

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -405,27 +405,8 @@ static void liquidio_pcie_resume(struct pci_dev *pdev __attribute__((unused)))
405405
/* Nothing to be done here. */
406406
}
407407

408-
#ifdef CONFIG_PM
409-
/**
410-
* \brief called when suspending
411-
* @param pdev Pointer to PCI device
412-
* @param state state to suspend to
413-
*/
414-
static int liquidio_suspend(struct pci_dev *pdev __attribute__((unused)),
415-
pm_message_t state __attribute__((unused)))
416-
{
417-
return 0;
418-
}
419-
420-
/**
421-
* \brief called when resuming
422-
* @param pdev Pointer to PCI device
423-
*/
424-
static int liquidio_resume(struct pci_dev *pdev __attribute__((unused)))
425-
{
426-
return 0;
427-
}
428-
#endif
408+
#define liquidio_suspend NULL
409+
#define liquidio_resume NULL
429410

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

435+
static SIMPLE_DEV_PM_OPS(liquidio_pm_ops, liquidio_suspend, liquidio_resume);
436+
454437
static struct pci_driver liquidio_pci_driver = {
455438
.name = "LiquidIO",
456439
.id_table = liquidio_pci_tbl,
457440
.probe = liquidio_probe,
458441
.remove = liquidio_remove,
459442
.err_handler = &liquidio_err_handler, /* For AER */
460-
461-
#ifdef CONFIG_PM
462-
.suspend = liquidio_suspend,
463-
.resume = liquidio_resume,
464-
#endif
443+
.driver.pm = &liquidio_pm_ops,
465444
#ifdef CONFIG_PCI_IOV
466445
.sriov_configure = liquidio_enable_sriov,
467446
#endif

0 commit comments

Comments
 (0)