@@ -1801,9 +1801,8 @@ typhoon_free_rx_rings(struct typhoon *tp)
18011801}
18021802
18031803static 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
18401852static int
18411853typhoon_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
22002213need_resume :
2201- typhoon_resume (pdev );
2214+ typhoon_resume (dev_d );
22022215 return - EBUSY ;
22032216}
2204- #endif
22052217
22062218static int
22072219typhoon_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+
25362550static 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
25472558static int __init
0 commit comments