[SK_BUFF]: Introduce ip_hdr(), remove skb->nh.iph
[safe/jmp/linux-2.6] / drivers / net / sky2.c
index fb1d2c3..a37bb20 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/ethtool.h>
 #include <linux/pci.h>
 #include <linux/ip.h>
+#include <net/ip.h>
 #include <linux/tcp.h>
 #include <linux/in.h>
 #include <linux/delay.h>
@@ -49,7 +50,7 @@
 #include "sky2.h"
 
 #define DRV_NAME               "sky2"
-#define DRV_VERSION            "1.10"
+#define DRV_VERSION            "1.14"
 #define PFX                    DRV_NAME " "
 
 /*
@@ -105,6 +106,7 @@ static const struct pci_device_id sky2_id_table[] = {
        { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b00) },    /* DGE-560T */
        { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4001) },    /* DGE-550SX */
        { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4B02) },    /* DGE-560SX */
+       { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4B03) },    /* DGE-550T */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4340) }, /* 88E8021 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4341) }, /* 88E8022 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4342) }, /* 88E8061 */
@@ -122,10 +124,16 @@ static const struct pci_device_id sky2_id_table[] = {
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4361) }, /* 88E8050 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4362) }, /* 88E8053 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4363) }, /* 88E8055 */
+#ifdef broken
+       /* This device causes data corruption problems that are not resolved */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4364) }, /* 88E8056 */
+#endif
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4366) }, /* 88EC036 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4367) }, /* 88EC032 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4368) }, /* 88EC034 */
+       { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4369) }, /* 88EC042 */
+       { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436A) }, /* 88E8058 */
+       { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436B) }, /* 88E8071 */
        { 0 }
 };
 
@@ -140,7 +148,7 @@ static const u32 portirq_msk[] = { Y2_IS_PORT_1, Y2_IS_PORT_2 };
 static const char *yukon2_name[] = {
        "XL",           /* 0xb3 */
        "EC Ultra",     /* 0xb4 */
-       "UNKNOWN",      /* 0xb5 */
+       "Extreme",      /* 0xb5 */
        "EC",           /* 0xb6 */
        "FE",           /* 0xb7 */
 };
@@ -192,76 +200,52 @@ static u16 gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg)
        return v;
 }
 
-static void sky2_set_power_state(struct sky2_hw *hw, pci_power_t state)
-{
-       u16 power_control;
-       int vaux;
-
-       pr_debug("sky2_set_power_state %d\n", state);
-       sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
-
-       power_control = sky2_pci_read16(hw, hw->pm_cap + PCI_PM_PMC);
-       vaux = (sky2_read16(hw, B0_CTST) & Y2_VAUX_AVAIL) &&
-               (power_control & PCI_PM_CAP_PME_D3cold);
-
-       power_control = sky2_pci_read16(hw, hw->pm_cap + PCI_PM_CTRL);
-
-       power_control |= PCI_PM_CTRL_PME_STATUS;
-       power_control &= ~(PCI_PM_CTRL_STATE_MASK);
-
-       switch (state) {
-       case PCI_D0:
-               /* switch power to VCC (WA for VAUX problem) */
-               sky2_write8(hw, B0_POWER_CTRL,
-                           PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON);
-
-               /* disable Core Clock Division, */
-               sky2_write32(hw, B2_Y2_CLK_CTRL, Y2_CLK_DIV_DIS);
 
-               if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
-                       /* enable bits are inverted */
-                       sky2_write8(hw, B2_Y2_CLK_GATE,
-                                   Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS |
-                                   Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS |
-                                   Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS);
-               else
-                       sky2_write8(hw, B2_Y2_CLK_GATE, 0);
+static void sky2_power_on(struct sky2_hw *hw)
+{
+       /* switch power to VCC (WA for VAUX problem) */
+       sky2_write8(hw, B0_POWER_CTRL,
+                   PC_VAUX_ENA | PC_VCC_ENA | PC_VAUX_OFF | PC_VCC_ON);
 
-               if (hw->chip_id == CHIP_ID_YUKON_EC_U) {
-                       u32 reg1;
+       /* disable Core Clock Division, */
+       sky2_write32(hw, B2_Y2_CLK_CTRL, Y2_CLK_DIV_DIS);
 
-                       sky2_pci_write32(hw, PCI_DEV_REG3, 0);
-                       reg1 = sky2_pci_read32(hw, PCI_DEV_REG4);
-                       reg1 &= P_ASPM_CONTROL_MSK;
-                       sky2_pci_write32(hw, PCI_DEV_REG4, reg1);
-                       sky2_pci_write32(hw, PCI_DEV_REG5, 0);
-               }
+       if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
+               /* enable bits are inverted */
+               sky2_write8(hw, B2_Y2_CLK_GATE,
+                           Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS |
+                           Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS |
+                           Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS);
+       else
+               sky2_write8(hw, B2_Y2_CLK_GATE, 0);
 
-               break;
+       if (hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_EX) {
+               u32 reg1;
 
-       case PCI_D3hot:
-       case PCI_D3cold:
-               if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
-                       sky2_write8(hw, B2_Y2_CLK_GATE, 0);
-               else
-                       /* enable bits are inverted */
-                       sky2_write8(hw, B2_Y2_CLK_GATE,
-                                   Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS |
-                                   Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS |
-                                   Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS);
-
-               /* switch power to VAUX */
-               if (vaux && state != PCI_D3cold)
-                       sky2_write8(hw, B0_POWER_CTRL,
-                                   (PC_VAUX_ENA | PC_VCC_ENA |
-                                    PC_VAUX_ON | PC_VCC_OFF));
-               break;
-       default:
-               printk(KERN_ERR PFX "Unknown power state %d\n", state);
+               sky2_pci_write32(hw, PCI_DEV_REG3, 0);
+               reg1 = sky2_pci_read32(hw, PCI_DEV_REG4);
+               reg1 &= P_ASPM_CONTROL_MSK;
+               sky2_pci_write32(hw, PCI_DEV_REG4, reg1);
+               sky2_pci_write32(hw, PCI_DEV_REG5, 0);
        }
+}
 
-       sky2_pci_write16(hw, hw->pm_cap + PCI_PM_CTRL, power_control);
-       sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
+static void sky2_power_aux(struct sky2_hw *hw)
+{
+       if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
+               sky2_write8(hw, B2_Y2_CLK_GATE, 0);
+       else
+               /* enable bits are inverted */
+               sky2_write8(hw, B2_Y2_CLK_GATE,
+                           Y2_PCI_CLK_LNK1_DIS | Y2_COR_CLK_LNK1_DIS |
+                           Y2_CLK_GAT_LNK1_DIS | Y2_PCI_CLK_LNK2_DIS |
+                           Y2_COR_CLK_LNK2_DIS | Y2_CLK_GAT_LNK2_DIS);
+
+       /* switch power to VAUX */
+       if (sky2_read16(hw, B0_CTST) & Y2_VAUX_AVAIL)
+               sky2_write8(hw, B0_POWER_CTRL,
+                           (PC_VAUX_ENA | PC_VCC_ENA |
+                            PC_VAUX_ON | PC_VCC_OFF));
 }
 
 static void sky2_gmac_reset(struct sky2_hw *hw, unsigned port)
@@ -313,8 +297,10 @@ static void sky2_phy_init(struct sky2_hw *hw, unsigned port)
        struct sky2_port *sky2 = netdev_priv(hw->dev[port]);
        u16 ctrl, ct1000, adv, pg, ledctrl, ledover, reg;
 
-       if (sky2->autoneg == AUTONEG_ENABLE &&
-           !(hw->chip_id == CHIP_ID_YUKON_XL || hw->chip_id == CHIP_ID_YUKON_EC_U)) {
+       if (sky2->autoneg == AUTONEG_ENABLE
+           && !(hw->chip_id == CHIP_ID_YUKON_XL
+                || hw->chip_id == CHIP_ID_YUKON_EC_U
+                || hw->chip_id == CHIP_ID_YUKON_EX)) {
                u16 ectrl = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL);
 
                ectrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK |
@@ -341,8 +327,10 @@ static void sky2_phy_init(struct sky2_hw *hw, unsigned port)
                        /* enable automatic crossover */
                        ctrl |= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO);
 
-                       if (sky2->autoneg == AUTONEG_ENABLE &&
-                           (hw->chip_id == CHIP_ID_YUKON_XL || hw->chip_id == CHIP_ID_YUKON_EC_U)) {
+                       if (sky2->autoneg == AUTONEG_ENABLE
+                           && (hw->chip_id == CHIP_ID_YUKON_XL
+                               || hw->chip_id == CHIP_ID_YUKON_EC_U
+                               || hw->chip_id == CHIP_ID_YUKON_EX)) {
                                ctrl &= ~PHY_M_PC_DSC_MSK;
                                ctrl |= PHY_M_PC_DSC(2) | PHY_M_PC_DOWN_S_ENA;
                        }
@@ -497,7 +485,9 @@ static void sky2_phy_init(struct sky2_hw *hw, unsigned port)
                /* restore page register */
                gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
                break;
+
        case CHIP_ID_YUKON_EC_U:
+       case CHIP_ID_YUKON_EX:
                pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
 
                /* select page 3 to access LED control register */
@@ -524,9 +514,9 @@ static void sky2_phy_init(struct sky2_hw *hw, unsigned port)
                ledover &= ~PHY_M_LED_MO_RX;
        }
 
-       if (hw->chip_id == CHIP_ID_YUKON_EC_U && hw->chip_rev == CHIP_REV_YU_EC_A1) {
+       if (hw->chip_id == CHIP_ID_YUKON_EC_U &&
+           hw->chip_rev == CHIP_REV_YU_EC_U_A1) {
                /* apply fixes in PHY AFE */
-               pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
                gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 255);
 
                /* increase differential signal amplitude in 10BASE-T */
@@ -538,8 +528,8 @@ static void sky2_phy_init(struct sky2_hw *hw, unsigned port)
                gm_phy_write(hw, port, 0x17, 0x2002);
 
                /* set page register to 0 */
-               gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
-       } else {
+               gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 0);
+       } else if (hw->chip_id != CHIP_ID_YUKON_EX) {
                gm_phy_write(hw, port, PHY_MARV_LED_CTRL, ledctrl);
 
                if (sky2->autoneg == AUTONEG_DISABLE || sky2->speed == SPEED_100) {
@@ -569,8 +559,8 @@ static void sky2_phy_power(struct sky2_hw *hw, unsigned port, int onoff)
        if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
                onoff = !onoff;
 
+       sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
        reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
-
        if (onoff)
                /* Turn off phy power saving */
                reg1 &= ~phy_power[port];
@@ -579,6 +569,7 @@ static void sky2_phy_power(struct sky2_hw *hw, unsigned port, int onoff)
 
        sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
        sky2_pci_read32(hw, PCI_DEV_REG1);
+       sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
        udelay(100);
 }
 
@@ -590,6 +581,73 @@ static void sky2_phy_reinit(struct sky2_port *sky2)
        spin_unlock_bh(&sky2->phy_lock);
 }
 
+/* Put device in state to listen for Wake On Lan */
+static void sky2_wol_init(struct sky2_port *sky2)
+{
+       struct sky2_hw *hw = sky2->hw;
+       unsigned port = sky2->port;
+       enum flow_control save_mode;
+       u16 ctrl;
+       u32 reg1;
+
+       /* Bring hardware out of reset */
+       sky2_write16(hw, B0_CTST, CS_RST_CLR);
+       sky2_write16(hw, SK_REG(port, GMAC_LINK_CTRL), GMLC_RST_CLR);
+
+       sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_CLR);
+       sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_RST_CLR);
+
+       /* Force to 10/100
+        * sky2_reset will re-enable on resume
+        */
+       save_mode = sky2->flow_mode;
+       ctrl = sky2->advertising;
+
+       sky2->advertising &= ~(ADVERTISED_1000baseT_Half|ADVERTISED_1000baseT_Full);
+       sky2->flow_mode = FC_NONE;
+       sky2_phy_power(hw, port, 1);
+       sky2_phy_reinit(sky2);
+
+       sky2->flow_mode = save_mode;
+       sky2->advertising = ctrl;
+
+       /* Set GMAC to no flow control and auto update for speed/duplex */
+       gma_write16(hw, port, GM_GP_CTRL,
+                   GM_GPCR_FC_TX_DIS|GM_GPCR_TX_ENA|GM_GPCR_RX_ENA|
+                   GM_GPCR_DUP_FULL|GM_GPCR_FC_RX_DIS|GM_GPCR_AU_FCT_DIS);
+
+       /* Set WOL address */
+       memcpy_toio(hw->regs + WOL_REGS(port, WOL_MAC_ADDR),
+                   sky2->netdev->dev_addr, ETH_ALEN);
+
+       /* Turn on appropriate WOL control bits */
+       sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), WOL_CTL_CLEAR_RESULT);
+       ctrl = 0;
+       if (sky2->wol & WAKE_PHY)
+               ctrl |= WOL_CTL_ENA_PME_ON_LINK_CHG|WOL_CTL_ENA_LINK_CHG_UNIT;
+       else
+               ctrl |= WOL_CTL_DIS_PME_ON_LINK_CHG|WOL_CTL_DIS_LINK_CHG_UNIT;
+
+       if (sky2->wol & WAKE_MAGIC)
+               ctrl |= WOL_CTL_ENA_PME_ON_MAGIC_PKT|WOL_CTL_ENA_MAGIC_PKT_UNIT;
+       else
+               ctrl |= WOL_CTL_DIS_PME_ON_MAGIC_PKT|WOL_CTL_DIS_MAGIC_PKT_UNIT;;
+
+       ctrl |= WOL_CTL_DIS_PME_ON_PATTERN|WOL_CTL_DIS_PATTERN_UNIT;
+       sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl);
+
+       /* Turn on legacy PCI-Express PME mode */
+       sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
+       reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
+       reg1 |= PCI_Y2_PME_LEGACY;
+       sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
+       sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
+
+       /* block receiver */
+       sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
+
+}
+
 static void sky2_mac_init(struct sky2_hw *hw, unsigned port)
 {
        struct sky2_port *sky2 = netdev_priv(hw->dev[port]);
@@ -683,15 +741,20 @@ static void sky2_mac_init(struct sky2_hw *hw, unsigned port)
        sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_CLR);
        sky2_write16(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_OPER_ON);
 
-       if (hw->chip_id == CHIP_ID_YUKON_EC_U) {
+       if (hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_EX) {
                sky2_write8(hw, SK_REG(port, RX_GMF_LP_THR), 768/8);
                sky2_write8(hw, SK_REG(port, RX_GMF_UP_THR), 1024/8);
-               if (hw->dev[port]->mtu > ETH_DATA_LEN) {
-                       /* set Tx GMAC FIFO Almost Empty Threshold */
-                       sky2_write32(hw, SK_REG(port, TX_GMF_AE_THR), 0x180);
-                       /* Disable Store & Forward mode for TX */
-                       sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_STFW_DIS);
-               }
+
+               /* set Tx GMAC FIFO Almost Empty Threshold */
+               sky2_write32(hw, SK_REG(port, TX_GMF_AE_THR),
+                            (ECU_JUMBO_WM << 16) | ECU_AE_THR);
+
+               if (hw->dev[port]->mtu > ETH_DATA_LEN)
+                       sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T),
+                                    TX_JUMBO_ENA | TX_STFW_DIS);
+               else
+                       sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T),
+                                    TX_JUMBO_DIS | TX_STFW_ENA);
        }
 
 }
@@ -999,8 +1062,7 @@ static void sky2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
 
        sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), RX_VLAN_STRIP_OFF);
        sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T), TX_VLAN_TAG_OFF);
-       if (sky2->vlgrp)
-               sky2->vlgrp->vlan_devices[vid] = NULL;
+       vlan_group_set_device(sky2->vlgrp, vid, NULL);
 
        netif_tx_unlock_bh(dev);
 }
@@ -1225,7 +1287,7 @@ static int sky2_up(struct net_device *dev)
        /* Set almost empty threshold */
        if (hw->chip_id == CHIP_ID_YUKON_EC_U
            && hw->chip_rev == CHIP_REV_YU_EC_U_A0)
-               sky2_write16(hw, Q_ADDR(txqaddr[port], Q_AL), 0x1a0);
+               sky2_write16(hw, Q_ADDR(txqaddr[port], Q_AL), ECU_TXFF_LEV);
 
        sky2_prefetch_init(hw, txqaddr[port], sky2->tx_le_map,
                           TX_RING_SIZE - 1);
@@ -1331,7 +1393,7 @@ static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev)
        mss = skb_shinfo(skb)->gso_size;
        if (mss != 0) {
                mss += ((skb->h.th->doff - 5) * 4);     /* TCP options */
-               mss += (skb->nh.iph->ihl * 4) + sizeof(struct tcphdr);
+               mss += ip_hdrlen(skb) + sizeof(struct tcphdr);
                mss += ETH_HLEN;
 
                if (mss != sky2->tx_last_mss) {
@@ -1366,7 +1428,7 @@ static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev)
                tcpsum |= offset + skb->csum_offset;    /* sum write */
 
                ctrl = CALSUM | WR_SUM | INIT_SUM | LOCK_SUM;
-               if (skb->nh.iph->protocol == IPPROTO_UDP)
+               if (ip_hdr(skb)->protocol == IPPROTO_UDP)
                        ctrl |= UDPTCP;
 
                if (tcpsum != sky2->tx_tcpsum) {
@@ -1466,6 +1528,9 @@ static void sky2_tx_complete(struct sky2_port *sky2, u16 done)
                        if (unlikely(netif_msg_tx_done(sky2)))
                                printk(KERN_DEBUG "%s: tx done %u\n",
                                       dev->name, idx);
+                       sky2->net_stats.tx_packets++;
+                       sky2->net_stats.tx_bytes += re->skb->len;
+
                        dev_kfree_skb_any(re->skb);
                }
 
@@ -1505,12 +1570,20 @@ static int sky2_down(struct net_device *dev)
 
        /* Stop more packets from being queued */
        netif_stop_queue(dev);
+       netif_carrier_off(dev);
 
        /* Disable port IRQ */
        imask = sky2_read32(hw, B0_IMSK);
        imask &= ~portirq_msk[port];
        sky2_write32(hw, B0_IMSK, imask);
 
+       /*
+        * Both ports share the NAPI poll on port 0, so if necessary undo the
+        * the disable that is done in dev_close.
+        */
+       if (sky2->port == 0 && hw->ports > 1)
+               netif_poll_enable(dev);
+
        sky2_gmac_reset(hw, port);
 
        /* Stop transmitter */
@@ -1520,13 +1593,6 @@ static int sky2_down(struct net_device *dev)
        sky2_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL),
                     RB_RST_SET | RB_DIS_OP_MD);
 
-       /* WA for dev. #4.209 */
-       if (hw->chip_id == CHIP_ID_YUKON_EC_U
-           && (hw->chip_rev == CHIP_REV_YU_EC_U_A1 || hw->chip_rev == CHIP_REV_YU_EC_U_B0))
-               sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T),
-                            sky2->speed != SPEED_1000 ?
-                            TX_STFW_ENA : TX_STFW_DIS);
-
        ctrl = gma_read16(hw, port, GM_GP_CTRL);
        ctrl &= ~(GM_GPCR_TX_ENA | GM_GPCR_RX_ENA);
        gma_write16(hw, port, GM_GP_CTRL, ctrl);
@@ -1633,7 +1699,9 @@ static void sky2_link_up(struct sky2_port *sky2)
        sky2_write8(hw, SK_REG(port, LNK_LED_REG),
                    LINKLED_ON | LINKLED_BLINK_OFF | LINKLED_LINKSYNC_OFF);
 
-       if (hw->chip_id == CHIP_ID_YUKON_XL || hw->chip_id == CHIP_ID_YUKON_EC_U) {
+       if (hw->chip_id == CHIP_ID_YUKON_XL
+           || hw->chip_id == CHIP_ID_YUKON_EC_U
+           || hw->chip_id == CHIP_ID_YUKON_EX) {
                u16 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
                u16 led = PHY_M_LEDC_LOS_CTRL(1);       /* link active */
 
@@ -1676,13 +1744,6 @@ static void sky2_link_down(struct sky2_port *sky2)
        reg &= ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA);
        gma_write16(hw, port, GM_GP_CTRL, reg);
 
-       if (sky2->flow_status == FC_RX) {
-               /* restore Asymmetric Pause bit */
-               gm_phy_write(hw, port, PHY_MARV_AUNE_ADV,
-                            gm_phy_read(hw, port, PHY_MARV_AUNE_ADV)
-                            | PHY_M_AN_ASP);
-       }
-
        netif_carrier_off(sky2->netdev);
        netif_stop_queue(sky2->netdev);
 
@@ -1707,10 +1768,10 @@ static int sky2_autoneg_done(struct sky2_port *sky2, u16 aux)
 {
        struct sky2_hw *hw = sky2->hw;
        unsigned port = sky2->port;
-       u16 lpa;
+       u16 advert, lpa;
 
+       advert = gm_phy_read(hw, port, PHY_MARV_AUNE_ADV);
        lpa = gm_phy_read(hw, port, PHY_MARV_AUNE_LP);
-
        if (lpa & PHY_M_AN_RF) {
                printk(KERN_ERR PFX "%s: remote fault", sky2->netdev->name);
                return -1;
@@ -1725,18 +1786,40 @@ static int sky2_autoneg_done(struct sky2_port *sky2, u16 aux)
        sky2->speed = sky2_phy_speed(hw, aux);
        sky2->duplex = (aux & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF;
 
-       /* Pause bits are offset (9..8) */
-       if (hw->chip_id == CHIP_ID_YUKON_XL || hw->chip_id == CHIP_ID_YUKON_EC_U)
-               aux >>= 6;
-
-       sky2->flow_status = sky2_flow(aux & PHY_M_PS_RX_P_EN,
-                                     aux & PHY_M_PS_TX_P_EN);
+       /* Since the pause result bits seem to in different positions on
+        * different chips. look at registers.
+        */
+       if (!sky2_is_copper(hw)) {
+               /* Shift for bits in fiber PHY */
+               advert &= ~(ADVERTISE_PAUSE_CAP|ADVERTISE_PAUSE_ASYM);
+               lpa &= ~(LPA_PAUSE_CAP|LPA_PAUSE_ASYM);
+
+               if (advert & ADVERTISE_1000XPAUSE)
+                       advert |= ADVERTISE_PAUSE_CAP;
+               if (advert & ADVERTISE_1000XPSE_ASYM)
+                       advert |= ADVERTISE_PAUSE_ASYM;
+               if (lpa & LPA_1000XPAUSE)
+                       lpa |= LPA_PAUSE_CAP;
+               if (lpa & LPA_1000XPAUSE_ASYM)
+                       lpa |= LPA_PAUSE_ASYM;
+       }
+
+       sky2->flow_status = FC_NONE;
+       if (advert & ADVERTISE_PAUSE_CAP) {
+               if (lpa & LPA_PAUSE_CAP)
+                       sky2->flow_status = FC_BOTH;
+               else if (advert & ADVERTISE_PAUSE_ASYM)
+                       sky2->flow_status = FC_RX;
+       } else if (advert & ADVERTISE_PAUSE_ASYM) {
+               if ((lpa & LPA_PAUSE_CAP) && (lpa & LPA_PAUSE_ASYM))
+                       sky2->flow_status = FC_TX;
+       }
 
        if (sky2->duplex == DUPLEX_HALF && sky2->speed < SPEED_1000
-           && hw->chip_id != CHIP_ID_YUKON_EC_U)
+           && !(hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_EX))
                sky2->flow_status = FC_NONE;
 
-       if (aux & PHY_M_PS_RX_P_EN)
+       if (sky2->flow_status & FC_TX)
                sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON);
        else
                sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
@@ -1785,55 +1868,31 @@ out:
        spin_unlock(&sky2->phy_lock);
 }
 
-
-/* Transmit timeout is only called if we are running, carries is up
+/* Transmit timeout is only called if we are running, carrier is up
  * and tx queue is full (stopped).
  */
 static void sky2_tx_timeout(struct net_device *dev)
 {
        struct sky2_port *sky2 = netdev_priv(dev);
        struct sky2_hw *hw = sky2->hw;
-       unsigned txq = txqaddr[sky2->port];
-       u16 report, done;
 
        if (netif_msg_timer(sky2))
                printk(KERN_ERR PFX "%s: tx timeout\n", dev->name);
 
-       report = sky2_read16(hw, sky2->port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX);
-       done = sky2_read16(hw, Q_ADDR(txq, Q_DONE));
-
        printk(KERN_DEBUG PFX "%s: transmit ring %u .. %u report=%u done=%u\n",
-              dev->name,
-              sky2->tx_cons, sky2->tx_prod, report, done);
+              dev->name, sky2->tx_cons, sky2->tx_prod,
+              sky2_read16(hw, sky2->port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX),
+              sky2_read16(hw, Q_ADDR(txqaddr[sky2->port], Q_DONE)));
 
-       if (report != done) {
-               printk(KERN_INFO PFX "status burst pending (irq moderation?)\n");
-
-               sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_STOP);
-               sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START);
-       } else if (report != sky2->tx_cons) {
-               printk(KERN_INFO PFX "status report lost?\n");
-
-               netif_tx_lock_bh(dev);
-               sky2_tx_complete(sky2, report);
-               netif_tx_unlock_bh(dev);
-       } else {
-               printk(KERN_INFO PFX "hardware hung? flushing\n");
-
-               sky2_write32(hw, Q_ADDR(txq, Q_CSR), BMU_STOP);
-               sky2_write32(hw, Y2_QADDR(txq, PREF_UNIT_CTRL), PREF_UNIT_RST_SET);
-
-               sky2_tx_clean(dev);
-
-               sky2_qset(hw, txq);
-               sky2_prefetch_init(hw, txq, sky2->tx_le_map, TX_RING_SIZE - 1);
-       }
+       /* can't restart safely under softirq */
+       schedule_work(&hw->restart_work);
 }
 
 static int sky2_change_mtu(struct net_device *dev, int new_mtu)
 {
        struct sky2_port *sky2 = netdev_priv(dev);
        struct sky2_hw *hw = sky2->hw;
+       unsigned port = sky2->port;
        int err;
        u16 ctl, mode;
        u32 imask;
@@ -1841,7 +1900,7 @@ static int sky2_change_mtu(struct net_device *dev, int new_mtu)
        if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU)
                return -EINVAL;
 
-       if (hw->chip_id == CHIP_ID_YUKON_EC_U && new_mtu > ETH_DATA_LEN)
+       if (new_mtu > ETH_DATA_LEN && hw->chip_id == CHIP_ID_YUKON_FE)
                return -EINVAL;
 
        if (!netif_running(dev)) {
@@ -1858,8 +1917,18 @@ static int sky2_change_mtu(struct net_device *dev, int new_mtu)
 
        synchronize_irq(hw->pdev->irq);
 
-       ctl = gma_read16(hw, sky2->port, GM_GP_CTRL);
-       gma_write16(hw, sky2->port, GM_GP_CTRL, ctl & ~GM_GPCR_RX_ENA);
+       if (hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_EX) {
+               if (new_mtu > ETH_DATA_LEN) {
+                       sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T),
+                                    TX_JUMBO_ENA | TX_STFW_DIS);
+                       dev->features &= NETIF_F_TSO | NETIF_F_SG | NETIF_F_IP_CSUM;
+               } else
+                       sky2_write32(hw, SK_REG(port, TX_GMF_CTRL_T),
+                                    TX_JUMBO_DIS | TX_STFW_ENA);
+       }
+
+       ctl = gma_read16(hw, port, GM_GP_CTRL);
+       gma_write16(hw, port, GM_GP_CTRL, ctl & ~GM_GPCR_RX_ENA);
        sky2_rx_stop(sky2);
        sky2_rx_clean(sky2);
 
@@ -1871,9 +1940,9 @@ static int sky2_change_mtu(struct net_device *dev, int new_mtu)
        if (dev->mtu > ETH_DATA_LEN)
                mode |= GM_SMOD_JUMBO_ENA;
 
-       gma_write16(hw, sky2->port, GM_SERIAL_MODE, mode);
+       gma_write16(hw, port, GM_SERIAL_MODE, mode);
 
-       sky2_write8(hw, RB_ADDR(rxqaddr[sky2->port], RB_CTRL), RB_ENA_OP_MD);
+       sky2_write8(hw, RB_ADDR(rxqaddr[port], RB_CTRL), RB_ENA_OP_MD);
 
        err = sky2_rx_start(sky2);
        sky2_write32(hw, B0_IMSK, imask);
@@ -1881,7 +1950,7 @@ static int sky2_change_mtu(struct net_device *dev, int new_mtu)
        if (err)
                dev_close(dev);
        else {
-               gma_write16(hw, sky2->port, GM_GP_CTRL, ctl);
+               gma_write16(hw, port, GM_GP_CTRL, ctl);
 
                netif_poll_enable(hw->dev[0]);
                netif_wake_queue(dev);
@@ -1999,9 +2068,6 @@ static struct sk_buff *sky2_receive(struct net_device *dev,
        if (!(status & GMR_FS_RX_OK))
                goto resubmit;
 
-       if (length > dev->mtu + ETH_HLEN)
-               goto oversize;
-
        if (length < copybreak)
                skb = receive_copy(sky2, re, length);
        else
@@ -2011,14 +2077,10 @@ resubmit:
 
        return skb;
 
-oversize:
-       ++sky2->net_stats.rx_over_errors;
-       goto resubmit;
-
 error:
        ++sky2->net_stats.rx_errors;
        if (status & GMR_FS_RX_FF_OV) {
-               sky2->net_stats.rx_fifo_errors++;
+               sky2->net_stats.rx_over_errors++;
                goto resubmit;
        }
 
@@ -2081,6 +2143,8 @@ static int sky2_status_intr(struct sky2_hw *hw, int to_do)
                                goto force_update;
 
                        skb->protocol = eth_type_trans(skb, dev);
+                       sky2->net_stats.rx_packets++;
+                       sky2->net_stats.rx_bytes += skb->len;
                        dev->last_rx = jiffies;
 
 #ifdef SKY2_VLAN_TAG_USED
@@ -2114,9 +2178,27 @@ force_update:
                        /* fall through */
 #endif
                case OP_RXCHKS:
-                       skb = sky2->rx_ring[sky2->rx_next].skb;
-                       skb->ip_summed = CHECKSUM_COMPLETE;
-                       skb->csum = status & 0xffff;
+                       if (!sky2->rx_csum)
+                               break;
+
+                       /* Both checksum counters are programmed to start at
+                        * the same offset, so unless there is a problem they
+                        * should match. This failure is an early indication that
+                        * hardware receive checksumming won't work.
+                        */
+                       if (likely(status >> 16 == (status & 0xffff))) {
+                               skb = sky2->rx_ring[sky2->rx_next].skb;
+                               skb->ip_summed = CHECKSUM_COMPLETE;
+                               skb->csum = status & 0xffff;
+                       } else {
+                               printk(KERN_NOTICE PFX "%s: hardware receive "
+                                      "checksum problem (status = %#x)\n",
+                                      dev->name, status);
+                               sky2->rx_csum = 0;
+                               sky2_write32(sky2->hw,
+                                            Q_ADDR(rxqaddr[le->link], Q_CSR),
+                                            BMU_DIS_RX_CHKSUM);
+                       }
                        break;
 
                case OP_TXINDEXLE:
@@ -2210,8 +2292,8 @@ static void sky2_hw_intr(struct sky2_hw *hw)
 
                pci_err = sky2_pci_read16(hw, PCI_STATUS);
                if (net_ratelimit())
-                       printk(KERN_ERR PFX "%s: pci hw error (0x%x)\n",
-                              pci_name(hw->pdev), pci_err);
+                       dev_err(&hw->pdev->dev, "PCI hardware error (0x%x)\n",
+                               pci_err);
 
                sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
                sky2_pci_write16(hw, PCI_STATUS,
@@ -2226,8 +2308,8 @@ static void sky2_hw_intr(struct sky2_hw *hw)
                pex_err = sky2_pci_read32(hw, PEX_UNC_ERR_STAT);
 
                if (net_ratelimit())
-                       printk(KERN_ERR PFX "%s: pci express error (0x%x)\n",
-                              pci_name(hw->pdev), pex_err);
+                       dev_err(&hw->pdev->dev, "PCI Express error (0x%x)\n",
+                               pex_err);
 
                /* clear the interrupt */
                sky2_write32(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
@@ -2270,26 +2352,22 @@ static void sky2_mac_intr(struct sky2_hw *hw, unsigned port)
        }
 }
 
-/* This should never happen it is a fatal situation */
-static void sky2_descriptor_error(struct sky2_hw *hw, unsigned port,
-                                 const char *rxtx, u32 mask)
+/* This should never happen it is a bug. */
+static void sky2_le_error(struct sky2_hw *hw, unsigned port,
+                         u16 q, unsigned ring_size)
 {
        struct net_device *dev = hw->dev[port];
        struct sky2_port *sky2 = netdev_priv(dev);
-       u32 imask;
+       unsigned idx;
+       const u64 *le = (q == Q_R1 || q == Q_R2)
+               ? (u64 *) sky2->rx_le : (u64 *) sky2->tx_le;
 
-       printk(KERN_ERR PFX "%s: %s descriptor error (hardware problem)\n",
-              dev ? dev->name : "<not registered>", rxtx);
+       idx = sky2_read16(hw, Y2_QADDR(q, PREF_UNIT_GET_IDX));
+       printk(KERN_ERR PFX "%s: descriptor error q=%#x get=%u [%llx] put=%u\n",
+              dev->name, (unsigned) q, idx, (unsigned long long) le[idx],
+              (unsigned) sky2_read16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX)));
 
-       imask = sky2_read32(hw, B0_IMSK);
-       imask &= ~mask;
-       sky2_write32(hw, B0_IMSK, imask);
-
-       if (dev) {
-               spin_lock(&sky2->phy_lock);
-               sky2_link_down(sky2);
-               spin_unlock(&sky2->phy_lock);
-       }
+       sky2_write32(hw, Q_ADDR(q, Q_CSR), BMU_CLR_IRQ_CHK);
 }
 
 /* If idle then force a fake soft NAPI poll once a second
@@ -2313,23 +2391,15 @@ static void sky2_idle(unsigned long arg)
        mod_timer(&hw->idle_timer, jiffies + msecs_to_jiffies(idle_timeout));
 }
 
-
-static int sky2_poll(struct net_device *dev0, int *budget)
+/* Hardware/software error handling */
+static void sky2_err_intr(struct sky2_hw *hw, u32 status)
 {
-       struct sky2_hw *hw = ((struct sky2_port *) netdev_priv(dev0))->hw;
-       int work_limit = min(dev0->quota, *budget);
-       int work_done = 0;
-       u32 status = sky2_read32(hw, B0_Y2_SP_EISR);
+       if (net_ratelimit())
+               dev_warn(&hw->pdev->dev, "error interrupt status=%#x\n", status);
 
        if (status & Y2_IS_HW_ERR)
                sky2_hw_intr(hw);
 
-       if (status & Y2_IS_IRQ_PHY1)
-               sky2_phy_intr(hw, 0);
-
-       if (status & Y2_IS_IRQ_PHY2)
-               sky2_phy_intr(hw, 1);
-
        if (status & Y2_IS_IRQ_MAC1)
                sky2_mac_intr(hw, 0);
 
@@ -2337,16 +2407,33 @@ static int sky2_poll(struct net_device *dev0, int *budget)
                sky2_mac_intr(hw, 1);
 
        if (status & Y2_IS_CHK_RX1)
-               sky2_descriptor_error(hw, 0, "receive", Y2_IS_CHK_RX1);
+               sky2_le_error(hw, 0, Q_R1, RX_LE_SIZE);
 
        if (status & Y2_IS_CHK_RX2)
-               sky2_descriptor_error(hw, 1, "receive", Y2_IS_CHK_RX2);
+               sky2_le_error(hw, 1, Q_R2, RX_LE_SIZE);
 
        if (status & Y2_IS_CHK_TXA1)
-               sky2_descriptor_error(hw, 0, "transmit", Y2_IS_CHK_TXA1);
+               sky2_le_error(hw, 0, Q_XA1, TX_RING_SIZE);
 
        if (status & Y2_IS_CHK_TXA2)
-               sky2_descriptor_error(hw, 1, "transmit", Y2_IS_CHK_TXA2);
+               sky2_le_error(hw, 1, Q_XA2, TX_RING_SIZE);
+}
+
+static int sky2_poll(struct net_device *dev0, int *budget)
+{
+       struct sky2_hw *hw = ((struct sky2_port *) netdev_priv(dev0))->hw;
+       int work_limit = min(dev0->quota, *budget);
+       int work_done = 0;
+       u32 status = sky2_read32(hw, B0_Y2_SP_EISR);
+
+       if (unlikely(status & Y2_IS_ERROR))
+               sky2_err_intr(hw, status);
+
+       if (status & Y2_IS_IRQ_PHY1)
+               sky2_phy_intr(hw, 0);
+
+       if (status & Y2_IS_IRQ_PHY2)
+               sky2_phy_intr(hw, 1);
 
        work_done = sky2_status_intr(hw, work_limit);
        if (work_done < work_limit) {
@@ -2396,6 +2483,7 @@ static inline u32 sky2_mhz(const struct sky2_hw *hw)
        switch (hw->chip_id) {
        case CHIP_ID_YUKON_EC:
        case CHIP_ID_YUKON_EC_U:
+       case CHIP_ID_YUKON_EX:
                return 125;     /* 125 Mhz */
        case CHIP_ID_YUKON_FE:
                return 100;     /* 100 Mhz */
@@ -2415,36 +2503,62 @@ static inline u32 sky2_clk2us(const struct sky2_hw *hw, u32 clk)
 }
 
 
-static int sky2_reset(struct sky2_hw *hw)
+static int __devinit sky2_init(struct sky2_hw *hw)
 {
-       u16 status;
        u8 t8;
-       int i;
 
        sky2_write8(hw, B0_CTST, CS_RST_CLR);
 
        hw->chip_id = sky2_read8(hw, B2_CHIP_ID);
        if (hw->chip_id < CHIP_ID_YUKON_XL || hw->chip_id > CHIP_ID_YUKON_FE) {
-               printk(KERN_ERR PFX "%s: unsupported chip type 0x%x\n",
-                      pci_name(hw->pdev), hw->chip_id);
+               dev_err(&hw->pdev->dev, "unsupported chip type 0x%x\n",
+                       hw->chip_id);
                return -EOPNOTSUPP;
        }
 
+       if (hw->chip_id == CHIP_ID_YUKON_EX)
+               dev_warn(&hw->pdev->dev, "this driver not yet tested on this chip type\n"
+                        "Please report success or failure to <netdev@vger.kernel.org>\n");
+
+       /* Make sure and enable all clocks */
+       if (hw->chip_id == CHIP_ID_YUKON_EX || hw->chip_id == CHIP_ID_YUKON_EC_U)
+               sky2_pci_write32(hw, PCI_DEV_REG3, 0);
+
        hw->chip_rev = (sky2_read8(hw, B2_MAC_CFG) & CFG_CHIP_R_MSK) >> 4;
 
        /* This rev is really old, and requires untested workarounds */
        if (hw->chip_id == CHIP_ID_YUKON_EC && hw->chip_rev == CHIP_REV_YU_EC_A1) {
-               printk(KERN_ERR PFX "%s: unsupported revision Yukon-%s (0x%x) rev %d\n",
-                      pci_name(hw->pdev), yukon2_name[hw->chip_id - CHIP_ID_YUKON_XL],
-                      hw->chip_id, hw->chip_rev);
+               dev_err(&hw->pdev->dev, "unsupported revision Yukon-%s (0x%x) rev %d\n",
+                       yukon2_name[hw->chip_id - CHIP_ID_YUKON_XL],
+                       hw->chip_id, hw->chip_rev);
                return -EOPNOTSUPP;
        }
 
+       hw->pmd_type = sky2_read8(hw, B2_PMD_TYP);
+       hw->ports = 1;
+       t8 = sky2_read8(hw, B2_Y2_HW_RES);
+       if ((t8 & CFG_DUAL_MAC_MSK) == CFG_DUAL_MAC_MSK) {
+               if (!(sky2_read8(hw, B2_Y2_CLK_GATE) & Y2_STATUS_LNK2_INAC))
+                       ++hw->ports;
+       }
+
+       return 0;
+}
+
+static void sky2_reset(struct sky2_hw *hw)
+{
+       u16 status;
+       int i;
+
        /* disable ASF */
-       if (hw->chip_id <= CHIP_ID_YUKON_EC) {
+       if (hw->chip_id == CHIP_ID_YUKON_EX) {
+               status = sky2_read16(hw, HCU_CCSR);
+               status &= ~(HCU_CCSR_AHB_RST | HCU_CCSR_CPU_RST_MODE |
+                           HCU_CCSR_UC_STATE_MSK);
+               sky2_write16(hw, HCU_CCSR, status);
+       } else
                sky2_write8(hw, B28_Y2_ASF_STAT_CMD, Y2_ASF_RESET);
-               sky2_write16(hw, B0_CTST, Y2_ASF_DISABLE);
-       }
+       sky2_write16(hw, B0_CTST, Y2_ASF_DISABLE);
 
        /* do a SW reset */
        sky2_write8(hw, B0_CTST, CS_RST_SET);
@@ -2464,15 +2578,7 @@ static int sky2_reset(struct sky2_hw *hw)
                sky2_pci_write32(hw, PEX_UNC_ERR_STAT, 0xffffffffUL);
 
 
-       hw->pmd_type = sky2_read8(hw, B2_PMD_TYP);
-       hw->ports = 1;
-       t8 = sky2_read8(hw, B2_Y2_HW_RES);
-       if ((t8 & CFG_DUAL_MAC_MSK) == CFG_DUAL_MAC_MSK) {
-               if (!(sky2_read8(hw, B2_Y2_CLK_GATE) & Y2_STATUS_LNK2_INAC))
-                       ++hw->ports;
-       }
-
-       sky2_set_power_state(hw, PCI_D0);
+       sky2_power_on(hw);
 
        for (i = 0; i < hw->ports; i++) {
                sky2_write8(hw, SK_REG(i, GMAC_LINK_CTRL), GMLC_RST_SET);
@@ -2555,7 +2661,80 @@ static int sky2_reset(struct sky2_hw *hw)
        sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START);
        sky2_write8(hw, STAT_LEV_TIMER_CTRL, TIM_START);
        sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START);
+}
+
+static void sky2_restart(struct work_struct *work)
+{
+       struct sky2_hw *hw = container_of(work, struct sky2_hw, restart_work);
+       struct net_device *dev;
+       int i, err;
+
+       dev_dbg(&hw->pdev->dev, "restarting\n");
+
+       del_timer_sync(&hw->idle_timer);
+
+       rtnl_lock();
+       sky2_write32(hw, B0_IMSK, 0);
+       sky2_read32(hw, B0_IMSK);
+
+       netif_poll_disable(hw->dev[0]);
+
+       for (i = 0; i < hw->ports; i++) {
+               dev = hw->dev[i];
+               if (netif_running(dev))
+                       sky2_down(dev);
+       }
+
+       sky2_reset(hw);
+       sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
+       netif_poll_enable(hw->dev[0]);
+
+       for (i = 0; i < hw->ports; i++) {
+               dev = hw->dev[i];
+               if (netif_running(dev)) {
+                       err = sky2_up(dev);
+                       if (err) {
+                               printk(KERN_INFO PFX "%s: could not restart %d\n",
+                                      dev->name, err);
+                               dev_close(dev);
+                       }
+               }
+       }
+
+       sky2_idle_start(hw);
 
+       rtnl_unlock();
+}
+
+static inline u8 sky2_wol_supported(const struct sky2_hw *hw)
+{
+       return sky2_is_copper(hw) ? (WAKE_PHY | WAKE_MAGIC) : 0;
+}
+
+static void sky2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
+{
+       const struct sky2_port *sky2 = netdev_priv(dev);
+
+       wol->supported = sky2_wol_supported(sky2->hw);
+       wol->wolopts = sky2->wol;
+}
+
+static int sky2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
+{
+       struct sky2_port *sky2 = netdev_priv(dev);
+       struct sky2_hw *hw = sky2->hw;
+
+       if (wol->wolopts & ~sky2_wol_supported(sky2->hw))
+               return -EOPNOTSUPP;
+
+       sky2->wol = wol->wolopts;
+
+       if (hw->chip_id == CHIP_ID_YUKON_EC_U)
+               sky2_write32(hw, B0_CTST, sky2->wol
+                            ? Y2_HW_WOL_ON : Y2_HW_WOL_OFF);
+
+       if (!netif_running(dev))
+               sky2_wol_init(sky2);
        return 0;
 }
 
@@ -2806,25 +2985,9 @@ static void sky2_get_strings(struct net_device *dev, u32 stringset, u8 * data)
        }
 }
 
-/* Use hardware MIB variables for critical path statistics and
- * transmit feedback not reported at interrupt.
- * Other errors are accounted for in interrupt handler.
- */
 static struct net_device_stats *sky2_get_stats(struct net_device *dev)
 {
        struct sky2_port *sky2 = netdev_priv(dev);
-       u64 data[13];
-
-       sky2_phy_stats(sky2, data, ARRAY_SIZE(data));
-
-       sky2->net_stats.tx_bytes = data[0];
-       sky2->net_stats.rx_bytes = data[1];
-       sky2->net_stats.tx_packets = data[2] + data[4] + data[6];
-       sky2->net_stats.rx_packets = data[3] + data[5] + data[7];
-       sky2->net_stats.multicast = data[3] + data[5];
-       sky2->net_stats.collisions = data[10];
-       sky2->net_stats.tx_aborted_errors = data[12];
-
        return &sky2->net_stats;
 }
 
@@ -3180,10 +3343,42 @@ static void sky2_get_regs(struct net_device *dev, struct ethtool_regs *regs,
                      regs->len - B3_RI_WTO_R1);
 }
 
+/* In order to do Jumbo packets on these chips, need to turn off the
+ * transmit store/forward. Therefore checksum offload won't work.
+ */
+static int no_tx_offload(struct net_device *dev)
+{
+       const struct sky2_port *sky2 = netdev_priv(dev);
+       const struct sky2_hw *hw = sky2->hw;
+
+       return dev->mtu > ETH_DATA_LEN &&
+               (hw->chip_id == CHIP_ID_YUKON_EX
+                || hw->chip_id == CHIP_ID_YUKON_EC_U);
+}
+
+static int sky2_set_tx_csum(struct net_device *dev, u32 data)
+{
+       if (data && no_tx_offload(dev))
+               return -EINVAL;
+
+       return ethtool_op_set_tx_csum(dev, data);
+}
+
+
+static int sky2_set_tso(struct net_device *dev, u32 data)
+{
+       if (data && no_tx_offload(dev))
+               return -EINVAL;
+
+       return ethtool_op_set_tso(dev, data);
+}
+
 static const struct ethtool_ops sky2_ethtool_ops = {
        .get_settings = sky2_get_settings,
        .set_settings = sky2_set_settings,
-       .get_drvinfo = sky2_get_drvinfo,
+       .get_drvinfo  = sky2_get_drvinfo,
+       .get_wol      = sky2_get_wol,
+       .set_wol      = sky2_set_wol,
        .get_msglevel = sky2_get_msglevel,
        .set_msglevel = sky2_set_msglevel,
        .nway_reset   = sky2_nway_reset,
@@ -3193,9 +3388,9 @@ static const struct ethtool_ops sky2_ethtool_ops = {
        .get_sg = ethtool_op_get_sg,
        .set_sg = ethtool_op_set_sg,
        .get_tx_csum = ethtool_op_get_tx_csum,
-       .set_tx_csum = ethtool_op_set_tx_csum,
+       .set_tx_csum = sky2_set_tx_csum,
        .get_tso = ethtool_op_get_tso,
-       .set_tso = ethtool_op_set_tso,
+       .set_tso = sky2_set_tso,
        .get_rx_csum = sky2_get_rx_csum,
        .set_rx_csum = sky2_set_rx_csum,
        .get_strings = sky2_get_strings,
@@ -3213,13 +3408,14 @@ static const struct ethtool_ops sky2_ethtool_ops = {
 
 /* Initialize network device */
 static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
-                                                    unsigned port, int highmem)
+                                                    unsigned port,
+                                                    int highmem, int wol)
 {
        struct sky2_port *sky2;
        struct net_device *dev = alloc_etherdev(sizeof(*sky2));
 
        if (!dev) {
-               printk(KERN_ERR "sky2 etherdev alloc failed");
+               dev_err(&hw->pdev->dev, "etherdev alloc failed");
                return NULL;
        }
 
@@ -3261,6 +3457,7 @@ static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
        sky2->speed = -1;
        sky2->advertising = sky2_supported_modes(hw);
        sky2->rx_csum = 1;
+       sky2->wol = wol;
 
        spin_lock_init(&sky2->phy_lock);
        sky2->tx_pending = TX_DEF_PENDING;
@@ -3270,11 +3467,9 @@ static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
 
        sky2->port = port;
 
-       if (hw->chip_id != CHIP_ID_YUKON_EC_U)
-               dev->features |= NETIF_F_TSO;
+       dev->features |= NETIF_F_TSO | NETIF_F_IP_CSUM | NETIF_F_SG;
        if (highmem)
                dev->features |= NETIF_F_HIGHDMA;
-       dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
 
 #ifdef SKY2_VLAN_TAG_USED
        dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
@@ -3335,8 +3530,7 @@ static int __devinit sky2_test_msi(struct sky2_hw *hw)
 
        err = request_irq(pdev->irq, sky2_test_intr, 0, DRV_NAME, hw);
        if (err) {
-               printk(KERN_ERR PFX "%s: cannot assign irq %d\n",
-                      pci_name(pdev), pdev->irq);
+               dev_err(&pdev->dev, "cannot assign irq %d\n", pdev->irq);
                return err;
        }
 
@@ -3347,9 +3541,8 @@ static int __devinit sky2_test_msi(struct sky2_hw *hw)
 
        if (!hw->msi) {
                /* MSI test failed, go back to INTx mode */
-               printk(KERN_INFO PFX "%s: No interrupt generated using MSI, "
-                      "switching to INTx mode.\n",
-                      pci_name(pdev));
+               dev_info(&pdev->dev, "No interrupt generated using MSI, "
+                        "switching to INTx mode.\n");
 
                err = -EOPNOTSUPP;
                sky2_write8(hw, B0_CTST, CS_CL_SW_IRQ);
@@ -3363,62 +3556,62 @@ static int __devinit sky2_test_msi(struct sky2_hw *hw)
        return err;
 }
 
+static int __devinit pci_wake_enabled(struct pci_dev *dev)
+{
+       int pm  = pci_find_capability(dev, PCI_CAP_ID_PM);
+       u16 value;
+
+       if (!pm)
+               return 0;
+       if (pci_read_config_word(dev, pm + PCI_PM_CTRL, &value))
+               return 0;
+       return value & PCI_PM_CTRL_PME_ENABLE;
+}
+
 static int __devinit sky2_probe(struct pci_dev *pdev,
                                const struct pci_device_id *ent)
 {
-       struct net_device *dev, *dev1 = NULL;
+       struct net_device *dev;
        struct sky2_hw *hw;
-       int err, pm_cap, using_dac = 0;
+       int err, using_dac = 0, wol_default;
 
        err = pci_enable_device(pdev);
        if (err) {
-               printk(KERN_ERR PFX "%s cannot enable PCI device\n",
-                      pci_name(pdev));
+               dev_err(&pdev->dev, "cannot enable PCI device\n");
                goto err_out;
        }
 
        err = pci_request_regions(pdev, DRV_NAME);
        if (err) {
-               printk(KERN_ERR PFX "%s cannot obtain PCI resources\n",
-                      pci_name(pdev));
+               dev_err(&pdev->dev, "cannot obtain PCI resources\n");
                goto err_out;
        }
 
        pci_set_master(pdev);
 
-       /* Find power-management capability. */
-       pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
-       if (pm_cap == 0) {
-               printk(KERN_ERR PFX "Cannot find PowerManagement capability, "
-                      "aborting.\n");
-               err = -EIO;
-               goto err_out_free_regions;
-       }
-
        if (sizeof(dma_addr_t) > sizeof(u32) &&
            !(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
                using_dac = 1;
                err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
                if (err < 0) {
-                       printk(KERN_ERR PFX "%s unable to obtain 64 bit DMA "
-                              "for consistent allocations\n", pci_name(pdev));
+                       dev_err(&pdev->dev, "unable to obtain 64 bit DMA "
+                               "for consistent allocations\n");
                        goto err_out_free_regions;
                }
-
        } else {
                err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
                if (err) {
-                       printk(KERN_ERR PFX "%s no usable DMA configuration\n",
-                              pci_name(pdev));
+                       dev_err(&pdev->dev, "no usable DMA configuration\n");
                        goto err_out_free_regions;
                }
        }
 
+       wol_default = pci_wake_enabled(pdev) ? WAKE_MAGIC : 0;
+
        err = -ENOMEM;
        hw = kzalloc(sizeof(*hw), GFP_KERNEL);
        if (!hw) {
-               printk(KERN_ERR PFX "%s: cannot allocate hardware struct\n",
-                      pci_name(pdev));
+               dev_err(&pdev->dev, "cannot allocate hardware struct\n");
                goto err_out_free_regions;
        }
 
@@ -3426,11 +3619,9 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
 
        hw->regs = ioremap_nocache(pci_resource_start(pdev, 0), 0x4000);
        if (!hw->regs) {
-               printk(KERN_ERR PFX "%s: cannot map device registers\n",
-                      pci_name(pdev));
+               dev_err(&pdev->dev, "cannot map device registers\n");
                goto err_out_free_hw;
        }
-       hw->pm_cap = pm_cap;
 
 #ifdef __BIG_ENDIAN
        /* The sk98lin vendor driver uses hardware byte swapping but
@@ -3450,18 +3641,22 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
        if (!hw->st_le)
                goto err_out_iounmap;
 
-       err = sky2_reset(hw);
+       err = sky2_init(hw);
        if (err)
                goto err_out_iounmap;
 
-       printk(KERN_INFO PFX "v%s addr 0x%llx irq %d Yukon-%s (0x%x) rev %d\n",
+       dev_info(&pdev->dev, "v%s addr 0x%llx irq %d Yukon-%s (0x%x) rev %d\n",
               DRV_VERSION, (unsigned long long)pci_resource_start(pdev, 0),
               pdev->irq, yukon2_name[hw->chip_id - CHIP_ID_YUKON_XL],
               hw->chip_id, hw->chip_rev);
 
-       dev = sky2_init_netdev(hw, 0, using_dac);
-       if (!dev)
+       sky2_reset(hw);
+
+       dev = sky2_init_netdev(hw, 0, using_dac, wol_default);
+       if (!dev) {
+               err = -ENOMEM;
                goto err_out_free_pci;
+       }
 
        if (!disable_msi && pci_enable_msi(pdev) == 0) {
                err = sky2_test_msi(hw);
@@ -3473,35 +3668,38 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
 
        err = register_netdev(dev);
        if (err) {
-               printk(KERN_ERR PFX "%s: cannot register net device\n",
-                      pci_name(pdev));
+               dev_err(&pdev->dev, "cannot register net device\n");
                goto err_out_free_netdev;
        }
 
        err = request_irq(pdev->irq,  sky2_intr, hw->msi ? 0 : IRQF_SHARED,
                          dev->name, hw);
        if (err) {
-               printk(KERN_ERR PFX "%s: cannot assign irq %d\n",
-                      pci_name(pdev), pdev->irq);
+               dev_err(&pdev->dev, "cannot assign irq %d\n", pdev->irq);
                goto err_out_unregister;
        }
        sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
 
        sky2_show_addr(dev);
 
-       if (hw->ports > 1 && (dev1 = sky2_init_netdev(hw, 1, using_dac))) {
-               if (register_netdev(dev1) == 0)
-                       sky2_show_addr(dev1);
-               else {
-                       /* Failure to register second port need not be fatal */
-                       printk(KERN_WARNING PFX
-                              "register of second port failed\n");
+       if (hw->ports > 1) {
+               struct net_device *dev1;
+
+               dev1 = sky2_init_netdev(hw, 1, using_dac, wol_default);
+               if (!dev1)
+                       dev_warn(&pdev->dev, "allocation for second device failed\n");
+               else if ((err = register_netdev(dev1))) {
+                       dev_warn(&pdev->dev,
+                                "register of second port failed (%d)\n", err);
                        hw->dev[1] = NULL;
                        free_netdev(dev1);
-               }
+               } else
+                       sky2_show_addr(dev1);
        }
 
        setup_timer(&hw->idle_timer, sky2_idle, (unsigned long) hw);
+       INIT_WORK(&hw->restart_work, sky2_restart);
+
        sky2_idle_start(hw);
 
        pci_set_drvdata(pdev, hw);
@@ -3538,6 +3736,8 @@ static void __devexit sky2_remove(struct pci_dev *pdev)
 
        del_timer_sync(&hw->idle_timer);
 
+       flush_scheduled_work();
+
        sky2_write32(hw, B0_IMSK, 0);
        synchronize_irq(hw->pdev->irq);
 
@@ -3547,7 +3747,8 @@ static void __devexit sky2_remove(struct pci_dev *pdev)
                unregister_netdev(dev1);
        unregister_netdev(dev0);
 
-       sky2_set_power_state(hw, PCI_D3hot);
+       sky2_power_aux(hw);
+
        sky2_write16(hw, B0_Y2LED, LED_STAT_OFF);
        sky2_write8(hw, B0_CTST, CS_RST_SET);
        sky2_read8(hw, B0_CTST);
@@ -3572,27 +3773,31 @@ static void __devexit sky2_remove(struct pci_dev *pdev)
 static int sky2_suspend(struct pci_dev *pdev, pm_message_t state)
 {
        struct sky2_hw *hw = pci_get_drvdata(pdev);
-       int i;
-       pci_power_t pstate = pci_choose_state(pdev, state);
-
-       if (!(pstate == PCI_D3hot || pstate == PCI_D3cold))
-               return -EINVAL;
+       int i, wol = 0;
 
        del_timer_sync(&hw->idle_timer);
        netif_poll_disable(hw->dev[0]);
 
        for (i = 0; i < hw->ports; i++) {
                struct net_device *dev = hw->dev[i];
+               struct sky2_port *sky2 = netdev_priv(dev);
 
-               if (netif_running(dev)) {
+               if (netif_running(dev))
                        sky2_down(dev);
-                       netif_device_detach(dev);
-               }
+
+               if (sky2->wol)
+                       sky2_wol_init(sky2);
+
+               wol |= sky2->wol;
        }
 
        sky2_write32(hw, B0_IMSK, 0);
+       sky2_power_aux(hw);
+
        pci_save_state(pdev);
-       sky2_set_power_state(hw, pstate);
+       pci_enable_wake(pdev, pci_choose_state(pdev, state), wol);
+       pci_set_power_state(pdev, pci_choose_state(pdev, state));
+
        return 0;
 }
 
@@ -3601,21 +3806,27 @@ static int sky2_resume(struct pci_dev *pdev)
        struct sky2_hw *hw = pci_get_drvdata(pdev);
        int i, err;
 
-       pci_restore_state(pdev);
-       pci_enable_wake(pdev, PCI_D0, 0);
-       sky2_set_power_state(hw, PCI_D0);
+       err = pci_set_power_state(pdev, PCI_D0);
+       if (err)
+               goto out;
 
-       err = sky2_reset(hw);
+       err = pci_restore_state(pdev);
        if (err)
                goto out;
 
+       pci_enable_wake(pdev, PCI_D0, 0);
+
+       /* Re-enable all clocks */
+       if (hw->chip_id == CHIP_ID_YUKON_EX || hw->chip_id == CHIP_ID_YUKON_EC_U)
+               sky2_pci_write32(hw, PCI_DEV_REG3, 0);
+
+       sky2_reset(hw);
+
        sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
 
        for (i = 0; i < hw->ports; i++) {
                struct net_device *dev = hw->dev[i];
                if (netif_running(dev)) {
-                       netif_device_attach(dev);
-
                        err = sky2_up(dev);
                        if (err) {
                                printk(KERN_ERR PFX "%s: could not up: %d\n",
@@ -3628,11 +3839,43 @@ static int sky2_resume(struct pci_dev *pdev)
 
        netif_poll_enable(hw->dev[0]);
        sky2_idle_start(hw);
+       return 0;
 out:
+       dev_err(&pdev->dev, "resume failed (%d)\n", err);
+       pci_disable_device(pdev);
        return err;
 }
 #endif
 
+static void sky2_shutdown(struct pci_dev *pdev)
+{
+       struct sky2_hw *hw = pci_get_drvdata(pdev);
+       int i, wol = 0;
+
+       del_timer_sync(&hw->idle_timer);
+       netif_poll_disable(hw->dev[0]);
+
+       for (i = 0; i < hw->ports; i++) {
+               struct net_device *dev = hw->dev[i];
+               struct sky2_port *sky2 = netdev_priv(dev);
+
+               if (sky2->wol) {
+                       wol = 1;
+                       sky2_wol_init(sky2);
+               }
+       }
+
+       if (wol)
+               sky2_power_aux(hw);
+
+       pci_enable_wake(pdev, PCI_D3hot, wol);
+       pci_enable_wake(pdev, PCI_D3cold, wol);
+
+       pci_disable_device(pdev);
+       pci_set_power_state(pdev, PCI_D3hot);
+
+}
+
 static struct pci_driver sky2_driver = {
        .name = DRV_NAME,
        .id_table = sky2_id_table,
@@ -3642,6 +3885,7 @@ static struct pci_driver sky2_driver = {
        .suspend = sky2_suspend,
        .resume = sky2_resume,
 #endif
+       .shutdown = sky2_shutdown,
 };
 
 static int __init sky2_init_module(void)
@@ -3658,6 +3902,6 @@ module_init(sky2_init_module);
 module_exit(sky2_cleanup_module);
 
 MODULE_DESCRIPTION("Marvell Yukon 2 Gigabit Ethernet driver");
-MODULE_AUTHOR("Stephen Hemminger <shemminger@osdl.org>");
+MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_VERSION);