jme: Cleanup PM operations after using new PM API
[jme.git] / jme.c
diff --git a/jme.c b/jme.c
index 490bc0f..6b2a5e7 100644 (file)
--- a/jme.c
+++ b/jme.c
@@ -161,6 +161,67 @@ jme_setup_wakeup_frame(struct jme_adapter *jme,
 }
 
 static inline void
+jme_mac_rxclk_off(struct jme_adapter *jme)
+{
+       jme->reg_gpreg1 |= GPREG1_RXCLKOFF;
+       jwrite32f(jme, JME_GPREG1, jme->reg_gpreg1);
+}
+
+static inline void
+jme_mac_rxclk_on(struct jme_adapter *jme)
+{
+       jme->reg_gpreg1 &= ~GPREG1_RXCLKOFF;
+       jwrite32f(jme, JME_GPREG1, jme->reg_gpreg1);
+}
+
+static inline void
+jme_mac_txclk_off(struct jme_adapter *jme)
+{
+       jme->reg_ghc &= ~(GHC_TO_CLK_SRC | GHC_TXMAC_CLK_SRC);
+       jwrite32f(jme, JME_GHC, jme->reg_ghc);
+}
+
+static inline void
+jme_mac_txclk_on(struct jme_adapter *jme)
+{
+       u32 speed = jme->reg_ghc & GHC_SPEED;
+       if (speed == GHC_SPEED_1000M)
+               jme->reg_ghc |= GHC_TO_CLK_GPHY | GHC_TXMAC_CLK_GPHY;
+       else
+               jme->reg_ghc |= GHC_TO_CLK_PCIE | GHC_TXMAC_CLK_PCIE;
+       jwrite32f(jme, JME_GHC, jme->reg_ghc);
+}
+
+static inline void
+jme_reset_ghc_speed(struct jme_adapter *jme)
+{
+       jme->reg_ghc &= ~(GHC_SPEED | GHC_DPX);
+       jwrite32f(jme, JME_GHC, jme->reg_ghc);
+}
+
+static inline void
+jme_reset_250A2_workaround(struct jme_adapter *jme)
+{
+       jme->reg_gpreg1 &= ~(GPREG1_HALFMODEPATCH |
+                            GPREG1_RSSPATCH);
+       jwrite32(jme, JME_GPREG1, jme->reg_gpreg1);
+}
+
+static inline void
+jme_assert_ghc_reset(struct jme_adapter *jme)
+{
+       jme->reg_ghc |= GHC_SWRST;
+       jwrite32f(jme, JME_GHC, jme->reg_ghc);
+}
+
+static inline void
+jme_clear_ghc_reset(struct jme_adapter *jme)
+{
+       jme->reg_ghc &= ~GHC_SWRST;
+       jwrite32f(jme, JME_GHC, jme->reg_ghc);
+}
+
+static inline void
 jme_reset_mac_processor(struct jme_adapter *jme)
 {
        static const u32 mask[WAKEUP_FRAME_MASK_DWNR] = {0, 0, 0, 0};
@@ -168,9 +229,24 @@ jme_reset_mac_processor(struct jme_adapter *jme)
        u32 gpreg0;
        int i;
 
-       jwrite32(jme, JME_GHC, jme->reg_ghc | GHC_SWRST);
-       udelay(2);
-       jwrite32(jme, JME_GHC, jme->reg_ghc);
+       jme_reset_ghc_speed(jme);
+       jme_reset_250A2_workaround(jme);
+
+       jme_mac_rxclk_on(jme);
+       jme_mac_txclk_on(jme);
+       udelay(1);
+       jme_assert_ghc_reset(jme);
+       udelay(1);
+       jme_mac_rxclk_off(jme);
+       jme_mac_txclk_off(jme);
+       udelay(1);
+       jme_clear_ghc_reset(jme);
+       udelay(1);
+       jme_mac_rxclk_on(jme);
+       jme_mac_txclk_on(jme);
+       udelay(1);
+       jme_mac_rxclk_off(jme);
+       jme_mac_txclk_off(jme);
 
        jwrite32(jme, JME_RXDBA_LO, 0x00000000);
        jwrite32(jme, JME_RXDBA_HI, 0x00000000);
@@ -190,22 +266,12 @@ jme_reset_mac_processor(struct jme_adapter *jme)
        else
                gpreg0 = GPREG0_DEFAULT;
        jwrite32(jme, JME_GPREG0, gpreg0);
-       jwrite32(jme, JME_GPREG1, GPREG1_DEFAULT);
-}
-
-static inline void
-jme_reset_ghc_speed(struct jme_adapter *jme)
-{
-       jme->reg_ghc &= ~(GHC_SPEED_1000M | GHC_DPX);
-       jwrite32(jme, JME_GHC, jme->reg_ghc);
 }
 
 static inline void
 jme_clear_pm(struct jme_adapter *jme)
 {
-       jwrite32(jme, JME_PMCS, 0xFFFF0000 | jme->reg_pmcs);
-       pci_set_power_state(jme->pdev, PCI_D0);
-       pci_enable_wake(jme->pdev, PCI_D0, false);
+       jwrite32(jme, JME_PMCS, PMCS_STMASK | jme->reg_pmcs);
 }
 
 static int
@@ -351,7 +417,7 @@ static int
 jme_check_link(struct net_device *netdev, int testonly)
 {
        struct jme_adapter *jme = netdev_priv(netdev);
-       u32 phylink, ghc, cnt = JME_SPDRSV_TIMEOUT, bmcr, gpreg1;
+       u32 phylink, cnt = JME_SPDRSV_TIMEOUT, bmcr;
        char linkmsg[64];
        int rc = 0;
 
@@ -414,23 +480,21 @@ jme_check_link(struct net_device *netdev, int testonly)
 
                jme->phylink = phylink;
 
-               ghc = jme->reg_ghc & ~(GHC_SPEED | GHC_DPX |
-                               GHC_TO_CLK_PCIE | GHC_TXMAC_CLK_PCIE |
-                               GHC_TO_CLK_GPHY | GHC_TXMAC_CLK_GPHY);
+               /*
+                * The speed/duplex setting of jme->reg_ghc already cleared
+                * by jme_reset_mac_processor()
+                */
                switch (phylink & PHY_LINK_SPEED_MASK) {
                case PHY_LINK_SPEED_10M:
-                       ghc |= GHC_SPEED_10M |
-                               GHC_TO_CLK_PCIE | GHC_TXMAC_CLK_PCIE;
+                       jme->reg_ghc |= GHC_SPEED_10M;
                        strcat(linkmsg, "10 Mbps, ");
                        break;
                case PHY_LINK_SPEED_100M:
-                       ghc |= GHC_SPEED_100M |
-                               GHC_TO_CLK_PCIE | GHC_TXMAC_CLK_PCIE;
+                       jme->reg_ghc |= GHC_SPEED_100M;
                        strcat(linkmsg, "100 Mbps, ");
                        break;
                case PHY_LINK_SPEED_1000M:
-                       ghc |= GHC_SPEED_1000M |
-                               GHC_TO_CLK_GPHY | GHC_TXMAC_CLK_GPHY;
+                       jme->reg_ghc |= GHC_SPEED_1000M;
                        strcat(linkmsg, "1000 Mbps, ");
                        break;
                default:
@@ -439,30 +503,31 @@ jme_check_link(struct net_device *netdev, int testonly)
 
                if (phylink & PHY_LINK_DUPLEX) {
                        jwrite32(jme, JME_TXMCS, TXMCS_DEFAULT);
-                       ghc |= GHC_DPX;
+                       jwrite32(jme, JME_TXTRHD, TXTRHD_FULLDUPLEX);
+                       jme->reg_ghc |= GHC_DPX;
                } else {
                        jwrite32(jme, JME_TXMCS, TXMCS_DEFAULT |
                                                TXMCS_BACKOFF |
                                                TXMCS_CARRIERSENSE |
                                                TXMCS_COLLISION);
-                       jwrite32(jme, JME_TXTRHD, TXTRHD_TXPEN |
-                               ((0x2000 << TXTRHD_TXP_SHIFT) & TXTRHD_TXP) |
-                               TXTRHD_TXREN |
-                               ((8 << TXTRHD_TXRL_SHIFT) & TXTRHD_TXRL));
+                       jwrite32(jme, JME_TXTRHD, TXTRHD_HALFDUPLEX);
                }
 
-               gpreg1 = GPREG1_DEFAULT;
+               jwrite32(jme, JME_GHC, jme->reg_ghc);
+
                if (is_buggy250(jme->pdev->device, jme->chiprev)) {
+                       jme->reg_gpreg1 &= ~(GPREG1_HALFMODEPATCH |
+                                            GPREG1_RSSPATCH);
                        if (!(phylink & PHY_LINK_DUPLEX))
-                               gpreg1 |= GPREG1_HALFMODEPATCH;
+                               jme->reg_gpreg1 |= GPREG1_HALFMODEPATCH;
                        switch (phylink & PHY_LINK_SPEED_MASK) {
                        case PHY_LINK_SPEED_10M:
                                jme_set_phyfifo_8level(jme);
-                               gpreg1 |= GPREG1_RSSPATCH;
+                               jme->reg_gpreg1 |= GPREG1_RSSPATCH;
                                break;
                        case PHY_LINK_SPEED_100M:
                                jme_set_phyfifo_5level(jme);
-                               gpreg1 |= GPREG1_RSSPATCH;
+                               jme->reg_gpreg1 |= GPREG1_RSSPATCH;
                                break;
                        case PHY_LINK_SPEED_1000M:
                                jme_set_phyfifo_8level(jme);
@@ -471,10 +536,7 @@ jme_check_link(struct net_device *netdev, int testonly)
                                break;
                        }
                }
-
-               jwrite32(jme, JME_GPREG1, gpreg1);
-               jwrite32(jme, JME_GHC, ghc);
-               jme->reg_ghc = ghc;
+               jwrite32(jme, JME_GPREG1, jme->reg_gpreg1);
 
                strcat(linkmsg, (phylink & PHY_LINK_DUPLEX) ?
                                        "Full-Duplex, " :
@@ -613,10 +675,14 @@ jme_enable_tx_engine(struct jme_adapter *jme)
         * Enable TX Engine
         */
        wmb();
-       jwrite32(jme, JME_TXCS, jme->reg_txcs |
+       jwrite32f(jme, JME_TXCS, jme->reg_txcs |
                                TXCS_SELECT_QUEUE0 |
                                TXCS_ENABLE);
 
+       /*
+        * Start clock for TX MAC Processor
+        */
+       jme_mac_txclk_on(jme);
 }
 
 static inline void
@@ -651,6 +717,11 @@ jme_disable_tx_engine(struct jme_adapter *jme)
 
        if (!i)
                pr_err("Disable TX engine timeout\n");
+
+       /*
+        * Stop clock for TX MAC Processor
+        */
+       jme_mac_txclk_off(jme);
 }
 
 static void
@@ -825,16 +896,22 @@ jme_enable_rx_engine(struct jme_adapter *jme)
        /*
         * Setup Unicast Filter
         */
+       jme_set_unicastaddr(jme->dev);
        jme_set_multi(jme->dev);
 
        /*
         * Enable RX Engine
         */
        wmb();
-       jwrite32(jme, JME_RXCS, jme->reg_rxcs |
+       jwrite32f(jme, JME_RXCS, jme->reg_rxcs |
                                RXCS_QUEUESEL_Q0 |
                                RXCS_ENABLE |
                                RXCS_QST);
+
+       /*
+        * Start clock for RX MAC Processor
+        */
+       jme_mac_rxclk_on(jme);
 }
 
 static inline void
@@ -871,10 +948,40 @@ jme_disable_rx_engine(struct jme_adapter *jme)
        if (!i)
                pr_err("Disable RX engine timeout\n");
 
+       /*
+        * Stop clock for RX MAC Processor
+        */
+       jme_mac_rxclk_off(jme);
+}
+
+static u16
+jme_udpsum(struct sk_buff *skb)
+{
+       u16 csum = 0xFFFFu;
+
+       if (skb->len < (ETH_HLEN + sizeof(struct iphdr)))
+               return csum;
+       if (skb->protocol != htons(ETH_P_IP))
+               return csum;
+       skb_set_network_header(skb, ETH_HLEN);
+       if ((ip_hdr(skb)->protocol != IPPROTO_UDP) ||
+           (skb->len < (ETH_HLEN +
+                       (ip_hdr(skb)->ihl << 2) +
+                       sizeof(struct udphdr)))) {
+               skb_reset_network_header(skb);
+               return csum;
+       }
+       skb_set_transport_header(skb,
+                       ETH_HLEN + (ip_hdr(skb)->ihl << 2));
+       csum = udp_hdr(skb)->check;
+       skb_reset_transport_header(skb);
+       skb_reset_network_header(skb);
+
+       return csum;
 }
 
 static int
-jme_rxsum_ok(struct jme_adapter *jme, u16 flags)
+jme_rxsum_ok(struct jme_adapter *jme, u16 flags, struct sk_buff *skb)
 {
        if (!(flags & (RXWBFLAG_TCPON | RXWBFLAG_UDPON | RXWBFLAG_IPV4)))
                return false;
@@ -887,7 +994,7 @@ jme_rxsum_ok(struct jme_adapter *jme, u16 flags)
        }
 
        if (unlikely((flags & (RXWBFLAG_MF | RXWBFLAG_UDPON | RXWBFLAG_UDPCS))
-                       == RXWBFLAG_UDPON)) {
+                       == RXWBFLAG_UDPON) && jme_udpsum(skb)) {
                if (flags & RXWBFLAG_IPV4)
                        netif_err(jme, rx_err, jme->dev, "UDP Checksum error\n");
                return false;
@@ -935,7 +1042,7 @@ jme_alloc_and_feed_skb(struct jme_adapter *jme, int idx)
                skb_put(skb, framesize);
                skb->protocol = eth_type_trans(skb, jme->dev);
 
-               if (jme_rxsum_ok(jme, le16_to_cpu(rxdesc->descwb.flags)))
+               if (jme_rxsum_ok(jme, le16_to_cpu(rxdesc->descwb.flags), skb))
                        skb->ip_summed = CHECKSUM_UNNECESSARY;
                else
                        skb_checksum_none_assert(skb);
@@ -1207,7 +1314,6 @@ jme_link_change_tasklet(unsigned long arg)
        tasklet_disable(&jme->rxempty_task);
 
        if (netif_carrier_ok(netdev)) {
-               jme_reset_ghc_speed(jme);
                jme_disable_rx_engine(jme);
                jme_disable_tx_engine(jme);
                jme_reset_mac_processor(jme);
@@ -1709,11 +1815,9 @@ jme_powersave_phy(struct jme_adapter *jme)
 {
        if (jme->reg_pmcs) {
                jme_set_100m_half(jme);
-
                if (jme->reg_pmcs & (PMCS_LFEN | PMCS_LREN))
                        jme_wait_link(jme);
-
-               jwrite32(jme, JME_PMCS, jme->reg_pmcs);
+               jme_clear_pm(jme);
        } else {
                jme_phy_off(jme);
        }
@@ -1737,7 +1841,6 @@ jme_close(struct net_device *netdev)
        tasklet_disable(&jme->rxclean_task);
        tasklet_disable(&jme->rxempty_task);
 
-       jme_reset_ghc_speed(jme);
        jme_disable_rx_engine(jme);
        jme_disable_tx_engine(jme);
        jme_reset_mac_processor(jme);
@@ -2034,27 +2137,34 @@ jme_start_xmit(struct sk_buff *skb, struct net_device *netdev)
        return NETDEV_TX_OK;
 }
 
+static void
+jme_set_unicastaddr(struct net_device *netdev)
+{
+       struct jme_adapter *jme = netdev_priv(netdev);
+       u32 val;
+
+       val = (netdev->dev_addr[3] & 0xff) << 24 |
+             (netdev->dev_addr[2] & 0xff) << 16 |
+             (netdev->dev_addr[1] & 0xff) <<  8 |
+             (netdev->dev_addr[0] & 0xff);
+       jwrite32(jme, JME_RXUMA_LO, val);
+       val = (netdev->dev_addr[5] & 0xff) << 8 |
+             (netdev->dev_addr[4] & 0xff);
+       jwrite32(jme, JME_RXUMA_HI, val);
+}
+
 static int
 jme_set_macaddr(struct net_device *netdev, void *p)
 {
        struct jme_adapter *jme = netdev_priv(netdev);
        struct sockaddr *addr = p;
-       u32 val;
 
        if (netif_running(netdev))
                return -EBUSY;
 
        spin_lock_bh(&jme->macaddr_lock);
        memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
-
-       val = (addr->sa_data[3] & 0xff) << 24 |
-             (addr->sa_data[2] & 0xff) << 16 |
-             (addr->sa_data[1] & 0xff) <<  8 |
-             (addr->sa_data[0] & 0xff);
-       jwrite32(jme, JME_RXUMA_LO, val);
-       val = (addr->sa_data[5] & 0xff) << 8 |
-             (addr->sa_data[4] & 0xff);
-       jwrite32(jme, JME_RXUMA_HI, val);
+       jme_set_unicastaddr(netdev);
        spin_unlock_bh(&jme->macaddr_lock);
 
        return 0;
@@ -2116,17 +2226,9 @@ jme_change_mtu(struct net_device *netdev, int new_mtu)
                jme_restart_rx_engine(jme);
        }
 
-       if (new_mtu > 1900) {
-               netdev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
-                               NETIF_F_TSO | NETIF_F_TSO6);
-       } else {
-               if (test_bit(JME_FLAG_TXCSUM, &jme->flags))
-                       netdev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
-               if (test_bit(JME_FLAG_TSO, &jme->flags))
-                       netdev->features |= NETIF_F_TSO | NETIF_F_TSO6;
-       }
-
        netdev->mtu = new_mtu;
+       netdev_update_features(netdev);
+
        jme_reset_link(jme);
 
        return 0;
@@ -2423,6 +2525,7 @@ jme_set_wol(struct net_device *netdev,
                jme->reg_pmcs |= PMCS_MFEN;
 
        jwrite32(jme, JME_PMCS, jme->reg_pmcs);
+       device_set_wakeup_enable(&jme->pdev->dev, !!(jme->reg_pmcs));
 
        return 0;
 }
@@ -2447,7 +2550,8 @@ jme_set_settings(struct net_device *netdev,
        struct jme_adapter *jme = netdev_priv(netdev);
        int rc, fdc = 0;
 
-       if (ecmd->speed == SPEED_1000 && ecmd->autoneg != AUTONEG_ENABLE)
+       if (ethtool_cmd_speed(ecmd) == SPEED_1000
+           && ecmd->autoneg != AUTONEG_ENABLE)
                return -EINVAL;
 
        /*
@@ -2524,19 +2628,20 @@ jme_set_msglevel(struct net_device *netdev, u32 value)
 }
 
 static u32
-jme_get_rx_csum(struct net_device *netdev)
+jme_fix_features(struct net_device *netdev, u32 features)
 {
-       struct jme_adapter *jme = netdev_priv(netdev);
-       return jme->reg_rxmcs & RXMCS_CHECKSUM;
+       if (netdev->mtu > 1900)
+               features &= ~(NETIF_F_ALL_TSO | NETIF_F_ALL_CSUM);
+       return features;
 }
 
 static int
-jme_set_rx_csum(struct net_device *netdev, u32 on)
+jme_set_features(struct net_device *netdev, u32 features)
 {
        struct jme_adapter *jme = netdev_priv(netdev);
 
        spin_lock_bh(&jme->rxmcs_lock);
-       if (on)
+       if (features & NETIF_F_RXCSUM)
                jme->reg_rxmcs |= RXMCS_CHECKSUM;
        else
                jme->reg_rxmcs &= ~RXMCS_CHECKSUM;
@@ -2547,42 +2652,6 @@ jme_set_rx_csum(struct net_device *netdev, u32 on)
 }
 
 static int
-jme_set_tx_csum(struct net_device *netdev, u32 on)
-{
-       struct jme_adapter *jme = netdev_priv(netdev);
-
-       if (on) {
-               set_bit(JME_FLAG_TXCSUM, &jme->flags);
-               if (netdev->mtu <= 1900)
-                       netdev->features |=
-                               NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
-       } else {
-               clear_bit(JME_FLAG_TXCSUM, &jme->flags);
-               netdev->features &=
-                               ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
-       }
-
-       return 0;
-}
-
-static int
-jme_set_tso(struct net_device *netdev, u32 on)
-{
-       struct jme_adapter *jme = netdev_priv(netdev);
-
-       if (on) {
-               set_bit(JME_FLAG_TSO, &jme->flags);
-               if (netdev->mtu <= 1900)
-                       netdev->features |= NETIF_F_TSO | NETIF_F_TSO6;
-       } else {
-               clear_bit(JME_FLAG_TSO, &jme->flags);
-               netdev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
-       }
-
-       return 0;
-}
-
-static int
 jme_nway_reset(struct net_device *netdev)
 {
        struct jme_adapter *jme = netdev_priv(netdev);
@@ -2723,11 +2792,6 @@ static const struct ethtool_ops jme_ethtool_ops = {
        .get_link               = jme_get_link,
        .get_msglevel           = jme_get_msglevel,
        .set_msglevel           = jme_set_msglevel,
-       .get_rx_csum            = jme_get_rx_csum,
-       .set_rx_csum            = jme_set_rx_csum,
-       .set_tx_csum            = jme_set_tx_csum,
-       .set_tso                = jme_set_tso,
-       .set_sg                 = ethtool_op_set_sg,
        .nway_reset             = jme_nway_reset,
        .get_eeprom_len         = jme_get_eeprom_len,
        .get_eeprom             = jme_get_eeprom,
@@ -2787,6 +2851,8 @@ static const struct net_device_ops jme_netdev_ops = {
        .ndo_change_mtu         = jme_change_mtu,
        .ndo_tx_timeout         = jme_tx_timeout,
        .ndo_vlan_rx_register   = jme_vlan_rx_register,
+       .ndo_fix_features       = jme_fix_features,
+       .ndo_set_features       = jme_set_features,
 };
 
 static int __devinit
@@ -2841,6 +2907,12 @@ jme_init_one(struct pci_dev *pdev,
        netdev->netdev_ops = &jme_netdev_ops;
        netdev->ethtool_ops             = &jme_ethtool_ops;
        netdev->watchdog_timeo          = TX_TIMEOUT;
+       netdev->hw_features             =       NETIF_F_IP_CSUM |
+                                               NETIF_F_IPV6_CSUM |
+                                               NETIF_F_SG |
+                                               NETIF_F_TSO |
+                                               NETIF_F_TSO6 |
+                                               NETIF_F_RXCSUM;
        netdev->features                =       NETIF_F_IP_CSUM |
                                                NETIF_F_IPV6_CSUM |
                                                NETIF_F_SG |
@@ -2923,8 +2995,10 @@ jme_init_one(struct pci_dev *pdev,
        jme->reg_rxmcs = RXMCS_DEFAULT;
        jme->reg_txpfc = 0;
        jme->reg_pmcs = PMCS_MFEN;
-       set_bit(JME_FLAG_TXCSUM, &jme->flags);
-       set_bit(JME_FLAG_TSO, &jme->flags);
+       jme->reg_gpreg1 = GPREG1_DEFAULT;
+
+       if (jme->reg_rxmcs & RXMCS_CHECKSUM)
+               netdev->features |= NETIF_F_RXCSUM;
 
        /*
         * Get Max Read Req Size from PCI Config Space
@@ -2979,8 +3053,11 @@ jme_init_one(struct pci_dev *pdev,
        jme->mii_if.mdio_write = jme_mdio_write;
 
        jme_clear_pm(jme);
+       pci_set_power_state(jme->pdev, PCI_D0);
+       device_set_wakeup_enable(&pdev->dev, true);
+
        jme_set_phyfifo_5level(jme);
-       pci_read_config_byte(pdev, PCI_REVISION_ID, &jme->pcirev);
+       jme->pcirev = pdev->revision;
        if (!jme->fpgaver)
                jme_phy_init(jme);
        jme_phy_off(jme);
@@ -3056,10 +3133,11 @@ jme_shutdown(struct pci_dev *pdev)
        pci_pme_active(pdev, true);
 }
 
-#ifdef CONFIG_PM
+#ifdef CONFIG_PM_SLEEP
 static int
-jme_suspend(struct pci_dev *pdev, pm_message_t state)
+jme_suspend(struct device *dev)
 {
+       struct pci_dev *pdev = to_pci_dev(dev);
        struct net_device *netdev = pci_get_drvdata(pdev);
        struct jme_adapter *jme = netdev_priv(netdev);
 
@@ -3078,7 +3156,6 @@ jme_suspend(struct pci_dev *pdev, pm_message_t state)
                        jme_polling_mode(jme);
 
                jme_stop_pcc_timer(jme);
-               jme_reset_ghc_speed(jme);
                jme_disable_rx_engine(jme);
                jme_disable_tx_engine(jme);
                jme_reset_mac_processor(jme);
@@ -3092,23 +3169,19 @@ jme_suspend(struct pci_dev *pdev, pm_message_t state)
        tasklet_hi_enable(&jme->rxclean_task);
        tasklet_hi_enable(&jme->rxempty_task);
 
-       pci_save_state(pdev);
        jme_powersave_phy(jme);
-       pci_enable_wake(jme->pdev, PCI_D3hot, true);
-       pci_set_power_state(pdev, PCI_D3hot);
 
        return 0;
 }
 
 static int
-jme_resume(struct pci_dev *pdev)
+jme_resume(struct device *dev)
 {
+       struct pci_dev *pdev = to_pci_dev(dev);
        struct net_device *netdev = pci_get_drvdata(pdev);
        struct jme_adapter *jme = netdev_priv(netdev);
 
        jme_clear_pm(jme);
-       pci_restore_state(pdev);
-
        jme_phy_on(jme);
        if (test_bit(JME_FLAG_SSET, &jme->flags))
                jme_set_settings(netdev, &jme->old_ecmd);
@@ -3124,6 +3197,13 @@ jme_resume(struct pci_dev *pdev)
 
        return 0;
 }
+
+static SIMPLE_DEV_PM_OPS(jme_pm_ops, jme_suspend, jme_resume);
+#define JME_PM_OPS (&jme_pm_ops)
+
+#else
+
+#define JME_PM_OPS NULL
 #endif
 
 static DEFINE_PCI_DEVICE_TABLE(jme_pci_tbl) = {
@@ -3137,11 +3217,8 @@ static struct pci_driver jme_driver = {
        .id_table       = jme_pci_tbl,
        .probe          = jme_init_one,
        .remove         = __devexit_p(jme_remove_one),
-#ifdef CONFIG_PM
-       .suspend        = jme_suspend,
-       .resume         = jme_resume,
-#endif /* CONFIG_PM */
        .shutdown       = jme_shutdown,
+       .driver.pm      = JME_PM_OPS,
 };
 
 static int __init