Skip to content

Commit 861ab44

Browse files
rjwysockidavem330
authored andcommitted
NET/r8169: Rework suspend and resume
The recent changes of the PCI PM core allow us to simplify the suspend and resume handling in a number of device drivers, since they don't need to carry out the general PCI PM operations, such as changing the power state of the device, during suspend and resume any more. Simplify the suspend and resume callbacks of r8169 using the observation that the PCI PM core can take care of some operations carried out by the driver. Additionally, make the shutdown callback of r8169 only put the device into a low power state if the system is going to be powered off (kexec is known to have problems with network adapters that are put into low power states on shutdown). This patch has been tested on MSI Wind U100. Signed-off-by: Rafael J. Wysocki <[email protected]> Tested-by: Bruno Prémont <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0ee904c commit 861ab44

File tree

1 file changed

+39
-22
lines changed

1 file changed

+39
-22
lines changed

drivers/net/r8169.c

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3791,16 +3791,13 @@ static struct net_device_stats *rtl8169_get_stats(struct net_device *dev)
37913791
return &dev->stats;
37923792
}
37933793

3794-
#ifdef CONFIG_PM
3795-
3796-
static int rtl8169_suspend(struct pci_dev *pdev, pm_message_t state)
3794+
static void rtl8169_net_suspend(struct net_device *dev)
37973795
{
3798-
struct net_device *dev = pci_get_drvdata(pdev);
37993796
struct rtl8169_private *tp = netdev_priv(dev);
38003797
void __iomem *ioaddr = tp->mmio_addr;
38013798

38023799
if (!netif_running(dev))
3803-
goto out_pci_suspend;
3800+
return;
38043801

38053802
netif_device_detach(dev);
38063803
netif_stop_queue(dev);
@@ -3812,24 +3809,25 @@ static int rtl8169_suspend(struct pci_dev *pdev, pm_message_t state)
38123809
rtl8169_rx_missed(dev, ioaddr);
38133810

38143811
spin_unlock_irq(&tp->lock);
3812+
}
3813+
3814+
#ifdef CONFIG_PM
3815+
3816+
static int rtl8169_suspend(struct device *device)
3817+
{
3818+
struct pci_dev *pdev = to_pci_dev(device);
3819+
struct net_device *dev = pci_get_drvdata(pdev);
38153820

3816-
out_pci_suspend:
3817-
pci_save_state(pdev);
3818-
pci_enable_wake(pdev, pci_choose_state(pdev, state),
3819-
(tp->features & RTL_FEATURE_WOL) ? 1 : 0);
3820-
pci_set_power_state(pdev, pci_choose_state(pdev, state));
3821+
rtl8169_net_suspend(dev);
38213822

38223823
return 0;
38233824
}
38243825

3825-
static int rtl8169_resume(struct pci_dev *pdev)
3826+
static int rtl8169_resume(struct device *device)
38263827
{
3828+
struct pci_dev *pdev = to_pci_dev(device);
38273829
struct net_device *dev = pci_get_drvdata(pdev);
38283830

3829-
pci_set_power_state(pdev, PCI_D0);
3830-
pci_restore_state(pdev);
3831-
pci_enable_wake(pdev, PCI_D0, 0);
3832-
38333831
if (!netif_running(dev))
38343832
goto out;
38353833

@@ -3840,23 +3838,42 @@ static int rtl8169_resume(struct pci_dev *pdev)
38403838
return 0;
38413839
}
38423840

3841+
static struct dev_pm_ops rtl8169_pm_ops = {
3842+
.suspend = rtl8169_suspend,
3843+
.resume = rtl8169_resume,
3844+
.freeze = rtl8169_suspend,
3845+
.thaw = rtl8169_resume,
3846+
.poweroff = rtl8169_suspend,
3847+
.restore = rtl8169_resume,
3848+
};
3849+
3850+
#define RTL8169_PM_OPS (&rtl8169_pm_ops)
3851+
3852+
#else /* !CONFIG_PM */
3853+
3854+
#define RTL8169_PM_OPS NULL
3855+
3856+
#endif /* !CONFIG_PM */
3857+
38433858
static void rtl_shutdown(struct pci_dev *pdev)
38443859
{
3845-
rtl8169_suspend(pdev, PMSG_SUSPEND);
3846-
}
3860+
struct net_device *dev = pci_get_drvdata(pdev);
3861+
3862+
rtl8169_net_suspend(dev);
38473863

3848-
#endif /* CONFIG_PM */
3864+
if (system_state == SYSTEM_POWER_OFF) {
3865+
pci_wake_from_d3(pdev, true);
3866+
pci_set_power_state(pdev, PCI_D3hot);
3867+
}
3868+
}
38493869

38503870
static struct pci_driver rtl8169_pci_driver = {
38513871
.name = MODULENAME,
38523872
.id_table = rtl8169_pci_tbl,
38533873
.probe = rtl8169_init_one,
38543874
.remove = __devexit_p(rtl8169_remove_one),
3855-
#ifdef CONFIG_PM
3856-
.suspend = rtl8169_suspend,
3857-
.resume = rtl8169_resume,
38583875
.shutdown = rtl_shutdown,
3859-
#endif
3876+
.driver.pm = RTL8169_PM_OPS,
38603877
};
38613878

38623879
static int __init rtl8169_init_module(void)

0 commit comments

Comments
 (0)