static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
 {
        u32 misc_host_ctrl;
+       bool device_should_wake;
 
        /* Make sure register accesses (indirect or otherwise)
         * will function correctly.
        tw32(TG3PCI_MISC_HOST_CTRL,
             misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT);
 
+       device_should_wake = pci_pme_capable(tp->pdev, state) &&
+                            device_may_wakeup(&tp->pdev->dev) &&
+                            (tp->tg3_flags & TG3_FLAG_WOL_ENABLE);
+
        if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) {
                if ((tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED) &&
                    !tp->link_config.phy_is_low_power) {
                                      ADVERTISED_10baseT_Half;
 
                        if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) ||
-                           (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)) {
+                           device_should_wake) {
                                if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB)
                                        advertising |=
                                                ADVERTISED_100baseT_Half |
                                                     WOL_DRV_WOL |
                                                     WOL_SET_MAGIC_PKT);
 
-       if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE) {
+       if (device_should_wake) {
                u32 mac_mode;
 
                if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
                if (!(tp->tg3_flags2 & TG3_FLG2_5750_PLUS))
                        tw32(MAC_LED_CTRL, tp->led_ctrl);
 
-               if (pci_pme_capable(tp->pdev, state) &&
-                    (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)) {
-                       mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE;
-                       if (((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
-                           !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) &&
-                           ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) ||
-                            (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)))
-                               mac_mode |= MAC_MODE_KEEP_FRAME_IN_WOL;
-               }
+               mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE;
+               if (((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
+                   !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) &&
+                   ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) ||
+                    (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)))
+                       mac_mode |= MAC_MODE_KEEP_FRAME_IN_WOL;
 
                if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) {
                        mac_mode |= tp->mac_mode &
                }
        }
 
-       if (!(tp->tg3_flags & TG3_FLAG_WOL_ENABLE) &&
+       if (!(device_should_wake) &&
            !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF) &&
            !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))
                tg3_power_down_phy(tp);
 
        tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN);
 
-       if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)
+       if (device_should_wake)
                pci_enable_wake(tp->pdev, state, true);
 
        /* Finally, set the new power state. */
        else
                wol->supported = 0;
        wol->wolopts = 0;
-       if (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)
+       if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) &&
+           device_can_wakeup(&tp->pdev->dev))
                wol->wolopts = WAKE_MAGIC;
        memset(&wol->sopass, 0, sizeof(wol->sopass));
 }
                    (val & VCPU_CFGSHDW_WOL_MAGPKT) &&
                    device_may_wakeup(&tp->pdev->dev))
                        tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
-               return;
+               goto done;
        }
 
        tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
                        tp->tg3_flags &= ~TG3_FLAG_WOL_CAP;
 
                if ((tp->tg3_flags & TG3_FLAG_WOL_CAP) &&
-                   (nic_cfg & NIC_SRAM_DATA_CFG_WOL_ENABLE) &&
-                   device_may_wakeup(&tp->pdev->dev))
+                   (nic_cfg & NIC_SRAM_DATA_CFG_WOL_ENABLE))
                        tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
 
                if (cfg2 & (1 << 17))
                if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_TX_EN)
                        tp->tg3_flags3 |= TG3_FLG3_RGMII_EXT_IBND_TX_EN;
        }
+done:
+       device_init_wakeup(&tp->pdev->dev, tp->tg3_flags & TG3_FLAG_WOL_CAP);
+       device_set_wakeup_enable(&tp->pdev->dev,
+                                tp->tg3_flags & TG3_FLAG_WOL_ENABLE);
 }
 
 static int __devinit tg3_issue_otp_command(struct tg3 *tp, u32 cmd)