@@ -2551,39 +2551,35 @@ static void __tg3_set_mac_addr(struct tg3 *tp, int skip_mac_1)
25512551 tw32 (MAC_TX_BACKOFF_SEED , addr_high );
25522552}
25532553
2554- static int tg3_set_power_state (struct tg3 * tp , pci_power_t state )
2554+ static void tg3_enable_register_access (struct tg3 * tp )
25552555{
2556- u32 misc_host_ctrl ;
2557- bool device_should_wake , do_low_power ;
2558-
2559- /* Make sure register accesses (indirect or otherwise)
2560- * will function correctly.
2556+ /*
2557+ * Make sure register accesses (indirect or otherwise) will function
2558+ * correctly.
25612559 */
25622560 pci_write_config_dword (tp -> pdev ,
2563- TG3PCI_MISC_HOST_CTRL ,
2564- tp -> misc_host_ctrl );
2561+ TG3PCI_MISC_HOST_CTRL , tp -> misc_host_ctrl );
2562+ }
25652563
2566- switch (state ) {
2567- case PCI_D0 :
2568- pci_enable_wake (tp -> pdev , state , false);
2569- pci_set_power_state (tp -> pdev , PCI_D0 );
2564+ static int tg3_power_up (struct tg3 * tp )
2565+ {
2566+ tg3_enable_register_access (tp );
25702567
2571- /* Switch out of Vaux if it is a NIC */
2572- if (tp -> tg3_flags2 & TG3_FLG2_IS_NIC )
2573- tw32_wait_f (GRC_LOCAL_CTRL , tp -> grc_local_ctrl , 100 );
2568+ pci_set_power_state (tp -> pdev , PCI_D0 );
25742569
2575- return 0 ;
2570+ /* Switch out of Vaux if it is a NIC */
2571+ if (tp -> tg3_flags2 & TG3_FLG2_IS_NIC )
2572+ tw32_wait_f (GRC_LOCAL_CTRL , tp -> grc_local_ctrl , 100 );
25762573
2577- case PCI_D1 :
2578- case PCI_D2 :
2579- case PCI_D3hot :
2580- break ;
2574+ return 0 ;
2575+ }
25812576
2582- default :
2583- netdev_err (tp -> dev , "Invalid power state (D%d) requested\n" ,
2584- state );
2585- return - EINVAL ;
2586- }
2577+ static int tg3_power_down_prepare (struct tg3 * tp )
2578+ {
2579+ u32 misc_host_ctrl ;
2580+ bool device_should_wake , do_low_power ;
2581+
2582+ tg3_enable_register_access (tp );
25872583
25882584 /* Restore the CLKREQ setting. */
25892585 if (tp -> tg3_flags3 & TG3_FLG3_CLKREQ_BUG ) {
@@ -2602,8 +2598,7 @@ static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
26022598 tw32 (TG3PCI_MISC_HOST_CTRL ,
26032599 misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT );
26042600
2605- device_should_wake = pci_pme_capable (tp -> pdev , state ) &&
2606- device_may_wakeup (& tp -> pdev -> dev ) &&
2601+ device_should_wake = device_may_wakeup (& tp -> pdev -> dev ) &&
26072602 (tp -> tg3_flags & TG3_FLAG_WOL_ENABLE );
26082603
26092604 if (tp -> tg3_flags3 & TG3_FLG3_USE_PHYLIB ) {
@@ -2823,13 +2818,15 @@ static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
28232818
28242819 tg3_write_sig_post_reset (tp , RESET_KIND_SHUTDOWN );
28252820
2826- if ( device_should_wake )
2827- pci_enable_wake ( tp -> pdev , state , true);
2821+ return 0 ;
2822+ }
28282823
2829- /* Finally, set the new power state. */
2830- pci_set_power_state (tp -> pdev , state );
2824+ static void tg3_power_down (struct tg3 * tp )
2825+ {
2826+ tg3_power_down_prepare (tp );
28312827
2832- return 0 ;
2828+ pci_wake_from_d3 (tp -> pdev , tp -> tg3_flags & TG3_FLAG_WOL_ENABLE );
2829+ pci_set_power_state (tp -> pdev , PCI_D3hot );
28332830}
28342831
28352832static void tg3_aux_stat_to_speed_duplex (struct tg3 * tp , u32 val , u16 * speed , u8 * duplex )
@@ -9137,7 +9134,7 @@ static int tg3_open(struct net_device *dev)
91379134
91389135 netif_carrier_off (tp -> dev );
91399136
9140- err = tg3_set_power_state (tp , PCI_D0 );
9137+ err = tg3_power_up (tp );
91419138 if (err )
91429139 return err ;
91439140
@@ -9302,7 +9299,7 @@ static int tg3_close(struct net_device *dev)
93029299
93039300 tg3_free_consistent (tp );
93049301
9305- tg3_set_power_state (tp , PCI_D3hot );
9302+ tg3_power_down (tp );
93069303
93079304 netif_carrier_off (tp -> dev );
93089305
@@ -11104,7 +11101,7 @@ static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
1110411101 struct tg3 * tp = netdev_priv (dev );
1110511102
1110611103 if (tp -> phy_flags & TG3_PHYFLG_IS_LOW_POWER )
11107- tg3_set_power_state (tp , PCI_D0 );
11104+ tg3_power_up (tp );
1110811105
1110911106 memset (data , 0 , sizeof (u64 ) * TG3_NUM_TEST );
1111011107
@@ -11172,7 +11169,7 @@ static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
1117211169 tg3_phy_start (tp );
1117311170 }
1117411171 if (tp -> phy_flags & TG3_PHYFLG_IS_LOW_POWER )
11175- tg3_set_power_state (tp , PCI_D3hot );
11172+ tg3_power_down (tp );
1117611173
1117711174}
1117811175
@@ -13621,7 +13618,7 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
1362113618 (tp -> tg3_flags3 & TG3_FLG3_5717_PLUS ))
1362213619 tp -> tg3_flags |= TG3_FLAG_CPMU_PRESENT ;
1362313620
13624- /* Set up tp->grc_local_ctrl before calling tg3_set_power_state ().
13621+ /* Set up tp->grc_local_ctrl before calling tg_power_up ().
1362513622 * GPIO1 driven high will bring 5700's external PHY out of reset.
1362613623 * It is also used as eeprom write protect on LOMs.
1362713624 */
@@ -13652,7 +13649,7 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
1365213649 }
1365313650
1365413651 /* Force the chip into D0. */
13655- err = tg3_set_power_state (tp , PCI_D0 );
13652+ err = tg3_power_up (tp );
1365613653 if (err ) {
1365713654 dev_err (& tp -> pdev -> dev , "Transition to D0 failed\n" );
1365813655 return err ;
@@ -15055,19 +15052,13 @@ static void __devexit tg3_remove_one(struct pci_dev *pdev)
1505515052 }
1505615053}
1505715054
15058- static int tg3_suspend (struct pci_dev * pdev , pm_message_t state )
15055+ static int tg3_suspend (struct device * device )
1505915056{
15057+ struct pci_dev * pdev = to_pci_dev (device );
1506015058 struct net_device * dev = pci_get_drvdata (pdev );
1506115059 struct tg3 * tp = netdev_priv (dev );
15062- pci_power_t target_state ;
1506315060 int err ;
1506415061
15065- /* PCI register 4 needs to be saved whether netif_running() or not.
15066- * MSI address and data need to be saved if using MSI and
15067- * netif_running().
15068- */
15069- pci_save_state (pdev );
15070-
1507115062 if (!netif_running (dev ))
1507215063 return 0 ;
1507315064
@@ -15088,9 +15079,7 @@ static int tg3_suspend(struct pci_dev *pdev, pm_message_t state)
1508815079 tp -> tg3_flags &= ~TG3_FLAG_INIT_COMPLETE ;
1508915080 tg3_full_unlock (tp );
1509015081
15091- target_state = pdev -> pm_cap ? pci_target_state (pdev ) : PCI_D3hot ;
15092-
15093- err = tg3_set_power_state (tp , target_state );
15082+ err = tg3_power_down_prepare (tp );
1509415083 if (err ) {
1509515084 int err2 ;
1509615085
@@ -15117,21 +15106,16 @@ static int tg3_suspend(struct pci_dev *pdev, pm_message_t state)
1511715106 return err ;
1511815107}
1511915108
15120- static int tg3_resume (struct pci_dev * pdev )
15109+ static int tg3_resume (struct device * device )
1512115110{
15111+ struct pci_dev * pdev = to_pci_dev (device );
1512215112 struct net_device * dev = pci_get_drvdata (pdev );
1512315113 struct tg3 * tp = netdev_priv (dev );
1512415114 int err ;
1512515115
15126- pci_restore_state (tp -> pdev );
15127-
1512815116 if (!netif_running (dev ))
1512915117 return 0 ;
1513015118
15131- err = tg3_set_power_state (tp , PCI_D0 );
15132- if (err )
15133- return err ;
15134-
1513515119 netif_device_attach (dev );
1513615120
1513715121 tg3_full_lock (tp , 0 );
@@ -15155,13 +15139,14 @@ static int tg3_resume(struct pci_dev *pdev)
1515515139 return err ;
1515615140}
1515715141
15142+ static SIMPLE_DEV_PM_OPS (tg3_pm_ops , tg3_suspend , tg3_resume ) ;
15143+
1515815144static struct pci_driver tg3_driver = {
1515915145 .name = DRV_MODULE_NAME ,
1516015146 .id_table = tg3_pci_tbl ,
1516115147 .probe = tg3_init_one ,
1516215148 .remove = __devexit_p (tg3_remove_one ),
15163- .suspend = tg3_suspend ,
15164- .resume = tg3_resume
15149+ .driver .pm = & tg3_pm_ops ,
1516515150};
1516615151
1516715152static int __init tg3_init (void )
0 commit comments