sky2: revert to access PCI config via device space
[powerpc.git] / drivers / net / sky2.c
index 1b9e5f4..65071e4 100644 (file)
@@ -52,7 +52,7 @@
 #include "sky2.h"
 
 #define DRV_NAME               "sky2"
-#define DRV_VERSION            "1.18"
+#define DRV_VERSION            "1.20"
 #define PFX                    DRV_NAME " "
 
 /*
@@ -121,6 +121,7 @@ static const struct pci_device_id sky2_id_table[] = {
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4353) }, /* 88E8039 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4354) }, /* 88E8040 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4356) }, /* 88EC033 */
+       { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4357) }, /* 88E8042 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x435A) }, /* 88E8048 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4360) }, /* 88E8052 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4361) }, /* 88E8050 */
@@ -134,6 +135,7 @@ static const struct pci_device_id sky2_id_table[] = {
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4369) }, /* 88EC042 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436A) }, /* 88E8058 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436B) }, /* 88E8071 */
+       { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436C) }, /* 88E8072 */
        { 0 }
 };
 
@@ -156,7 +158,7 @@ static const char *yukon2_name[] = {
 
 static void sky2_set_multicast(struct net_device *dev);
 
-/* Access to external PHY */
+/* Access to PHY via serial interconnect */
 static int gm_phy_write(struct sky2_hw *hw, unsigned port, u16 reg, u16 val)
 {
        int i;
@@ -166,13 +168,22 @@ static int gm_phy_write(struct sky2_hw *hw, unsigned port, u16 reg, u16 val)
                    GM_SMI_CT_PHY_AD(PHY_ADDR_MARV) | GM_SMI_CT_REG_AD(reg));
 
        for (i = 0; i < PHY_RETRIES; i++) {
-               if (!(gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_BUSY))
+               u16 ctrl = gma_read16(hw, port, GM_SMI_CTRL);
+               if (ctrl == 0xffff)
+                       goto io_error;
+
+               if (!(ctrl & GM_SMI_CT_BUSY))
                        return 0;
-               udelay(1);
+
+               udelay(10);
        }
 
-       printk(KERN_WARNING PFX "%s: phy write timeout\n", hw->dev[port]->name);
+       dev_warn(&hw->pdev->dev,"%s: phy write timeout\n", hw->dev[port]->name);
        return -ETIMEDOUT;
+
+io_error:
+       dev_err(&hw->pdev->dev, "%s: phy I/O error\n", hw->dev[port]->name);
+       return -EIO;
 }
 
 static int __gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg, u16 *val)
@@ -183,23 +194,29 @@ static int __gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg, u16 *val)
                    | GM_SMI_CT_REG_AD(reg) | GM_SMI_CT_OP_RD);
 
        for (i = 0; i < PHY_RETRIES; i++) {
-               if (gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_RD_VAL) {
+               u16 ctrl = gma_read16(hw, port, GM_SMI_CTRL);
+               if (ctrl == 0xffff)
+                       goto io_error;
+
+               if (ctrl & GM_SMI_CT_RD_VAL) {
                        *val = gma_read16(hw, port, GM_SMI_DATA);
                        return 0;
                }
 
-               udelay(1);
+               udelay(10);
        }
 
+       dev_warn(&hw->pdev->dev, "%s: phy read timeout\n", hw->dev[port]->name);
        return -ETIMEDOUT;
+io_error:
+       dev_err(&hw->pdev->dev, "%s: phy I/O error\n", hw->dev[port]->name);
+       return -EIO;
 }
 
-static u16 gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg)
+static inline u16 gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg)
 {
        u16 v;
-
-       if (__gm_phy_read(hw, port, reg, &v) != 0)
-               printk(KERN_WARNING PFX "%s: phy read timeout\n", hw->dev[port]->name);
+       __gm_phy_read(hw, port, reg, &v);
        return v;
 }
 
@@ -223,22 +240,21 @@ static void sky2_power_on(struct sky2_hw *hw)
                sky2_write8(hw, B2_Y2_CLK_GATE, 0);
 
        if (hw->flags & SKY2_HW_ADV_POWER_CTL) {
-               struct pci_dev *pdev = hw->pdev;
                u32 reg;
 
-               pci_write_config_dword(pdev, PCI_DEV_REG3, 0);
+               sky2_pci_write32(hw, PCI_DEV_REG3, 0);
 
-               pci_read_config_dword(pdev, PCI_DEV_REG4, &reg);
+               reg = sky2_pci_read32(hw, PCI_DEV_REG4);
                /* set all bits to 0 except bits 15..12 and 8 */
                reg &= P_ASPM_CONTROL_MSK;
-               pci_write_config_dword(pdev, PCI_DEV_REG4, reg);
+               sky2_pci_write32(hw, PCI_DEV_REG4, reg);
 
-               pci_read_config_dword(pdev, PCI_DEV_REG5, &reg);
+               reg = sky2_pci_read32(hw, PCI_DEV_REG5);
                /* set all bits to 0 except bits 28 & 27 */
                reg &= P_CTL_TIM_VMAIN_AV_MSK;
-               pci_write_config_dword(pdev, PCI_DEV_REG5, reg);
+               sky2_pci_write32(hw, PCI_DEV_REG5, reg);
 
-               pci_write_config_dword(pdev, PCI_CFG_REG_1, 0);
+               sky2_pci_write32(hw, PCI_CFG_REG_1, 0);
 
                /* Enable workaround for dev 4.107 on Yukon-Ultra & Extreme */
                reg = sky2_read32(hw, B2_GP_IO);
@@ -273,8 +289,6 @@ static void sky2_gmac_reset(struct sky2_hw *hw, unsigned port)
 
        /* disable all GMAC IRQ's */
        sky2_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0);
-       /* disable PHY IRQs */
-       gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);
 
        gma_write16(hw, port, GM_MC_ADDR_H1, 0);        /* clear MC hash */
        gma_write16(hw, port, GM_MC_ADDR_H2, 0);
@@ -296,10 +310,10 @@ static const u16 copper_fc_adv[] = {
 
 /* flow control to advertise bits when using 1000BaseX */
 static const u16 fiber_fc_adv[] = {
-       [FC_BOTH] = PHY_M_P_BOTH_MD_X,
+       [FC_NONE] = PHY_M_P_NO_PAUSE_X,
        [FC_TX]   = PHY_M_P_ASYM_MD_X,
        [FC_RX]   = PHY_M_P_SYM_MD_X,
-       [FC_NONE] = PHY_M_P_NO_PAUSE_X,
+       [FC_BOTH] = PHY_M_P_BOTH_MD_X,
 };
 
 /* flow control to GMA disable bits */
@@ -604,24 +618,22 @@ static void sky2_phy_init(struct sky2_hw *hw, unsigned port)
 
 static void sky2_phy_power(struct sky2_hw *hw, unsigned port, int onoff)
 {
-       struct pci_dev *pdev = hw->pdev;
        u32 reg1;
-       static const u32 phy_power[]
-               = { PCI_Y2_PHY1_POWD, PCI_Y2_PHY2_POWD };
+       static const u32 phy_power[] = { PCI_Y2_PHY1_POWD, PCI_Y2_PHY2_POWD };
+       static const u32 coma_mode[] = { PCI_Y2_PHY1_COMA, PCI_Y2_PHY2_COMA };
 
-       /* looks like this XL is back asswards .. */
-       if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
-               onoff = !onoff;
-
-       pci_read_config_dword(pdev, PCI_DEV_REG1, &reg1);
+       reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
+       /* Turn on/off phy power saving */
        if (onoff)
-               /* Turn off phy power saving */
                reg1 &= ~phy_power[port];
        else
                reg1 |= phy_power[port];
 
-       pci_write_config_dword(pdev, PCI_DEV_REG1, reg1);
-       pci_read_config_dword(pdev, PCI_DEV_REG1, &reg1);
+       if (onoff && hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
+               reg1 |= coma_mode[port];
+
+       sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
+       reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
 
        udelay(100);
 }
@@ -690,9 +702,9 @@ static void sky2_wol_init(struct sky2_port *sky2)
        sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl);
 
        /* Turn on legacy PCI-Express PME mode */
-       pci_read_config_dword(hw->pdev, PCI_DEV_REG1, &reg1);
+       reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
        reg1 |= PCI_Y2_PME_LEGACY;
-       pci_write_config_dword(hw->pdev, PCI_DEV_REG1, reg1);
+       sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
 
        /* block receiver */
        sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
@@ -1306,15 +1318,12 @@ static int sky2_up(struct net_device *dev)
         */
        if (otherdev && netif_running(otherdev) &&
            (cap = pci_find_capability(hw->pdev, PCI_CAP_ID_PCIX))) {
-               struct sky2_port *osky2 = netdev_priv(otherdev);
                u16 cmd;
 
-               pci_read_config_word(hw->pdev, cap + PCI_X_CMD, &cmd);
+               cmd = sky2_pci_read16(hw, cap + PCI_X_CMD);
                cmd &= ~PCI_X_CMD_MAX_SPLIT;
-               pci_write_config_word(hw->pdev, cap + PCI_X_CMD, cmd);
+               sky2_pci_write16(hw, cap + PCI_X_CMD, cmd);
 
-               sky2->rx_csum = 0;
-               osky2->rx_csum = 0;
        }
 
        if (netif_msg_ifup(sky2))
@@ -1385,13 +1394,9 @@ static int sky2_up(struct net_device *dev)
        sky2_prefetch_init(hw, txqaddr[port], sky2->tx_le_map,
                           TX_RING_SIZE - 1);
 
-       napi_enable(&hw->napi);
-
        err = sky2_rx_start(sky2);
-       if (err) {
-               napi_disable(&hw->napi);
+       if (err)
                goto err_out;
-       }
 
        /* Enable interrupts from phy/mac for port */
        imask = sky2_read32(hw, B0_IMSK);
@@ -1636,8 +1641,8 @@ static void sky2_tx_complete(struct sky2_port *sky2, u16 done)
                                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->stats.tx_packets++;
+                       dev->stats.tx_bytes += re->skb->len;
 
                        dev_kfree_skb_any(re->skb);
                        sky2->tx_next = RING_NEXT(idx, TX_RING_SIZE);
@@ -1680,13 +1685,13 @@ static int sky2_down(struct net_device *dev)
        /* Stop more packets from being queued */
        netif_stop_queue(dev);
 
-       napi_disable(&hw->napi);
-
        /* Disable port IRQ */
        imask = sky2_read32(hw, B0_IMSK);
        imask &= ~portirq_msk[port];
        sky2_write32(hw, B0_IMSK, imask);
 
+       synchronize_irq(hw->pdev->irq);
+
        sky2_gmac_reset(hw, port);
 
        /* Stop transmitter */
@@ -1700,6 +1705,9 @@ static int sky2_down(struct net_device *dev)
        ctrl &= ~(GM_GPCR_TX_ENA | GM_GPCR_RX_ENA);
        gma_write16(hw, port, GM_GP_CTRL, ctrl);
 
+       /* Make sure no packets are pending */
+       napi_synchronize(&hw->napi);
+
        sky2_write8(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
 
        /* Workaround shared GMAC reset */
@@ -1737,8 +1745,6 @@ static int sky2_down(struct net_device *dev)
        /* turn off LED's */
        sky2_write16(hw, B0_Y2LED, LED_STAT_OFF);
 
-       synchronize_irq(hw->pdev->irq);
-
        sky2_tx_clean(dev);
        sky2_rx_clean(sky2);
 
@@ -1809,29 +1815,6 @@ 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->flags & SKY2_HW_NEWER_PHY) {
-               u16 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
-               u16 led = PHY_M_LEDC_LOS_CTRL(1);       /* link active */
-
-               switch(sky2->speed) {
-               case SPEED_10:
-                       led |= PHY_M_LEDC_INIT_CTRL(7);
-                       break;
-
-               case SPEED_100:
-                       led |= PHY_M_LEDC_STA1_CTRL(7);
-                       break;
-
-               case SPEED_1000:
-                       led |= PHY_M_LEDC_STA0_CTRL(7);
-                       break;
-               }
-
-               gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3);
-               gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, led);
-               gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
-       }
-
        if (netif_msg_link(sky2))
                printk(KERN_INFO PFX
                       "%s: Link is up at %d Mbps, %s duplex, flow control %s\n",
@@ -2049,9 +2032,6 @@ static int sky2_change_mtu(struct net_device *dev, int new_mtu)
        err = sky2_rx_start(sky2);
        sky2_write32(hw, B0_IMSK, imask);
 
-       /* Unconditionally re-enable NAPI because even if we
-        * call dev_close() that will do a napi_disable().
-        */
        napi_enable(&hw->napi);
 
        if (err)
@@ -2205,16 +2185,16 @@ resubmit:
 len_error:
        /* Truncation of overlength packets
           causes PHY length to not match MAC length */
-       ++sky2->net_stats.rx_length_errors;
+       ++dev->stats.rx_length_errors;
        if (netif_msg_rx_err(sky2) && net_ratelimit())
                pr_info(PFX "%s: rx length error: status %#x length %d\n",
                        dev->name, status, length);
        goto resubmit;
 
 error:
-       ++sky2->net_stats.rx_errors;
+       ++dev->stats.rx_errors;
        if (status & GMR_FS_RX_FF_OV) {
-               sky2->net_stats.rx_over_errors++;
+               dev->stats.rx_over_errors++;
                goto resubmit;
        }
 
@@ -2223,11 +2203,11 @@ error:
                       dev->name, status, length);
 
        if (status & (GMR_FS_LONG_ERR | GMR_FS_UN_SIZE))
-               sky2->net_stats.rx_length_errors++;
+               dev->stats.rx_length_errors++;
        if (status & GMR_FS_FRAGMENT)
-               sky2->net_stats.rx_frame_errors++;
+               dev->stats.rx_frame_errors++;
        if (status & GMR_FS_CRC_ERR)
-               sky2->net_stats.rx_crc_errors++;
+               dev->stats.rx_crc_errors++;
 
        goto resubmit;
 }
@@ -2245,36 +2225,40 @@ static inline void sky2_tx_done(struct net_device *dev, u16 last)
 }
 
 /* Process status response ring */
-static int sky2_status_intr(struct sky2_hw *hw, int to_do)
+static int sky2_status_intr(struct sky2_hw *hw, int to_do, u16 idx)
 {
        int work_done = 0;
        unsigned rx[2] = { 0, 0 };
-       u16 hwidx = sky2_read16(hw, STAT_PUT_IDX);
 
        rmb();
-
-       while (hw->st_idx != hwidx) {
+       do {
                struct sky2_port *sky2;
                struct sky2_status_le *le  = hw->st_le + hw->st_idx;
-               unsigned port = le->css & CSS_LINK_BIT;
+               unsigned port;
                struct net_device *dev;
                struct sk_buff *skb;
                u32 status;
                u16 length;
+               u8 opcode = le->opcode;
+
+               if (!(opcode & HW_OWNER))
+                       break;
 
                hw->st_idx = RING_NEXT(hw->st_idx, STATUS_RING_SIZE);
 
+               port = le->css & CSS_LINK_BIT;
                dev = hw->dev[port];
                sky2 = netdev_priv(dev);
                length = le16_to_cpu(le->length);
                status = le32_to_cpu(le->status);
 
-               switch (le->opcode & ~HW_OWNER) {
+               le->opcode = 0;
+               switch (opcode & ~HW_OWNER) {
                case OP_RXSTAT:
                        ++rx[port];
                        skb = sky2_receive(dev, length, status);
                        if (unlikely(!skb)) {
-                               sky2->net_stats.rx_dropped++;
+                               dev->stats.rx_dropped++;
                                break;
                        }
 
@@ -2289,8 +2273,8 @@ static int sky2_status_intr(struct sky2_hw *hw, int to_do)
                        }
 
                        skb->protocol = eth_type_trans(skb, dev);
-                       sky2->net_stats.rx_packets++;
-                       sky2->net_stats.rx_bytes += skb->len;
+                       dev->stats.rx_packets++;
+                       dev->stats.rx_bytes += skb->len;
                        dev->last_rx = jiffies;
 
 #ifdef SKY2_VLAN_TAG_USED
@@ -2362,9 +2346,9 @@ static int sky2_status_intr(struct sky2_hw *hw, int to_do)
                default:
                        if (net_ratelimit())
                                printk(KERN_WARNING PFX
-                                      "unknown status opcode 0x%x\n", le->opcode);
+                                      "unknown status opcode 0x%x\n", opcode);
                }
-       }
+       } while (hw->st_idx != idx);
 
        /* Fully processed status ring so clear irq */
        sky2_write32(hw, STAT_CTRL, SC_STAT_CLR_IRQ);
@@ -2437,24 +2421,37 @@ static void sky2_hw_intr(struct sky2_hw *hw)
        if (status & (Y2_IS_MST_ERR | Y2_IS_IRQ_STAT)) {
                u16 pci_err;
 
-               pci_read_config_word(pdev, PCI_STATUS, &pci_err);
+               pci_err = sky2_pci_read16(hw, PCI_STATUS);
                if (net_ratelimit())
                        dev_err(&pdev->dev, "PCI hardware error (0x%x)\n",
                                pci_err);
 
-               pci_write_config_word(pdev, PCI_STATUS,
+               sky2_pci_write16(hw, PCI_STATUS,
                                      pci_err | PCI_STATUS_ERROR_BITS);
        }
 
        if (status & Y2_IS_PCI_EXP) {
                /* PCI-Express uncorrectable Error occurred */
-               int pos = pci_find_aer_capability(hw->pdev);
+               int aer = pci_find_aer_capability(hw->pdev);
                u32 err;
 
-               pci_read_config_dword(pdev, pos + PCI_ERR_UNCOR_STATUS, &err);
+               if (aer) {
+                       pci_read_config_dword(pdev, aer + PCI_ERR_UNCOR_STATUS,
+                                             &err);
+                       pci_cleanup_aer_uncorrect_error_status(pdev);
+               } else {
+                       /* Either AER not configured, or not working
+                        * because of bad MMCONFIG, so just do recover
+                        * manually.
+                        */
+                       err = sky2_read32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS);
+                       sky2_write32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS,
+                                    0xfffffffful);
+               }
+
                if (net_ratelimit())
                        dev_err(&pdev->dev, "PCI Express error (0x%x)\n", err);
-               pci_cleanup_aer_uncorrect_error_status(pdev);
+
        }
 
        if (status & Y2_HWE_L1_MASK)
@@ -2481,12 +2478,12 @@ static void sky2_mac_intr(struct sky2_hw *hw, unsigned port)
                gma_read16(hw, port, GM_TX_IRQ_SRC);
 
        if (status & GM_IS_RX_FF_OR) {
-               ++sky2->net_stats.rx_fifo_errors;
+               ++dev->stats.rx_fifo_errors;
                sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_CLI_RX_FO);
        }
 
        if (status & GM_IS_TX_FF_UR) {
-               ++sky2->net_stats.tx_fifo_errors;
+               ++dev->stats.tx_fifo_errors;
                sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_FU);
        }
 }
@@ -2606,7 +2603,8 @@ static int sky2_poll(struct napi_struct *napi, int work_limit)
 {
        struct sky2_hw *hw = container_of(napi, struct sky2_hw, napi);
        u32 status = sky2_read32(hw, B0_Y2_SP_EISR);
-       int work_done;
+       int work_done = 0;
+       u16 idx;
 
        if (unlikely(status & Y2_IS_ERROR))
                sky2_err_intr(hw, status);
@@ -2617,21 +2615,24 @@ static int sky2_poll(struct napi_struct *napi, int work_limit)
        if (status & Y2_IS_IRQ_PHY2)
                sky2_phy_intr(hw, 1);
 
-       work_done = sky2_status_intr(hw, work_limit);
+       while ((idx = sky2_read16(hw, STAT_PUT_IDX)) != hw->st_idx) {
+               work_done += sky2_status_intr(hw, work_limit - work_done, idx);
 
-       /* More work? */
-       if (hw->st_idx == sky2_read16(hw, STAT_PUT_IDX)) {
-               /* Bug/Errata workaround?
-                * Need to kick the TX irq moderation timer.
-                */
-               if (sky2_read8(hw, STAT_TX_TIMER_CTRL) == TIM_START) {
-                       sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_STOP);
-                       sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START);
-               }
+               if (work_done >= work_limit)
+                       goto done;
+       }
 
-               napi_complete(napi);
-               sky2_read32(hw, B0_Y2_SP_LISR);
+       /* Bug/Errata workaround?
+        * Need to kick the TX irq moderation timer.
+        */
+       if (sky2_read8(hw, STAT_TX_TIMER_CTRL) == TIM_START) {
+               sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_STOP);
+               sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START);
        }
+       napi_complete(napi);
+       sky2_read32(hw, B0_Y2_SP_LISR);
+done:
+
        return work_done;
 }
 
@@ -2697,13 +2698,10 @@ static inline u32 sky2_clk2us(const struct sky2_hw *hw, u32 clk)
 
 static int __devinit sky2_init(struct sky2_hw *hw)
 {
-       int rc;
        u8 t8;
 
        /* Enable all clocks and check for bad PCI access */
-       rc = pci_write_config_dword(hw->pdev, PCI_DEV_REG3, 0);
-       if (rc)
-               return rc;
+       sky2_pci_write32(hw, PCI_DEV_REG3, 0);
 
        sky2_write8(hw, B0_CTST, CS_RST_CLR);
 
@@ -2796,18 +2794,30 @@ static void sky2_reset(struct sky2_hw *hw)
        sky2_write8(hw, B0_CTST, CS_RST_SET);
        sky2_write8(hw, B0_CTST, CS_RST_CLR);
 
+       /* allow writes to PCI config */
+       sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
+
        /* clear PCI errors, if any */
-       pci_read_config_word(pdev, PCI_STATUS, &status);
+       status = sky2_pci_read16(hw, PCI_STATUS);
        status |= PCI_STATUS_ERROR_BITS;
-       pci_write_config_word(pdev, PCI_STATUS, status);
+       sky2_pci_write16(hw, PCI_STATUS, status);
 
        sky2_write8(hw, B0_CTST, CS_MRST_CLR);
 
        cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
        if (cap) {
-               /* Check for advanced error reporting */
-               pci_cleanup_aer_uncorrect_error_status(pdev);
-               pci_cleanup_aer_correct_error_status(pdev);
+               if (pci_find_aer_capability(pdev)) {
+                       /* Check for advanced error reporting */
+                       pci_cleanup_aer_uncorrect_error_status(pdev);
+                       pci_cleanup_aer_correct_error_status(pdev);
+               } else {
+                       dev_warn(&pdev->dev,
+                               "PCI Express Advanced Error Reporting"
+                               " not configured or MMCONFIG problem?\n");
+
+                       sky2_write32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS,
+                                    0xfffffffful);
+               }
 
                /* If error bit is stuck on ignore it */
                if (sky2_read32(hw, B0_HWE_ISRC) & Y2_IS_PCI_EXP)
@@ -2914,6 +2924,7 @@ static void sky2_restart(struct work_struct *work)
        rtnl_lock();
        sky2_write32(hw, B0_IMSK, 0);
        sky2_read32(hw, B0_IMSK);
+       napi_disable(&hw->napi);
 
        for (i = 0; i < hw->ports; i++) {
                dev = hw->dev[i];
@@ -2923,6 +2934,7 @@ static void sky2_restart(struct work_struct *work)
 
        sky2_reset(hw);
        sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
+       napi_enable(&hw->napi);
 
        for (i = 0; i < hw->ports; i++) {
                dev = hw->dev[i];
@@ -3190,9 +3202,14 @@ static void sky2_set_msglevel(struct net_device *netdev, u32 value)
        sky2->msg_enable = value;
 }
 
-static int sky2_get_stats_count(struct net_device *dev)
+static int sky2_get_sset_count(struct net_device *dev, int sset)
 {
-       return ARRAY_SIZE(sky2_stats);
+       switch (sset) {
+       case ETH_SS_STATS:
+               return ARRAY_SIZE(sky2_stats);
+       default:
+               return -EOPNOTSUPP;
+       }
 }
 
 static void sky2_get_ethtool_stats(struct net_device *dev,
@@ -3216,12 +3233,6 @@ static void sky2_get_strings(struct net_device *dev, u32 stringset, u8 * data)
        }
 }
 
-static struct net_device_stats *sky2_get_stats(struct net_device *dev)
-{
-       struct sky2_port *sky2 = netdev_priv(dev);
-       return &sky2->net_stats;
-}
-
 static int sky2_set_mac_address(struct net_device *dev, void *p)
 {
        struct sky2_port *sky2 = netdev_priv(dev);
@@ -3562,20 +3573,64 @@ static void sky2_get_regs(struct net_device *dev, struct ethtool_regs *regs,
 {
        const struct sky2_port *sky2 = netdev_priv(dev);
        const void __iomem *io = sky2->hw->regs;
+       unsigned int b;
 
        regs->version = 1;
-       memset(p, 0, regs->len);
-
-       memcpy_fromio(p, io, B3_RAM_ADDR);
 
-       /* skip diagnostic ram region */
-       memcpy_fromio(p + B3_RI_WTO_R1, io + B3_RI_WTO_R1, 0x2000 - B3_RI_WTO_R1);
+       for (b = 0; b < 128; b++) {
+               /* This complicated switch statement is to make sure and
+                * only access regions that are unreserved.
+                * Some blocks are only valid on dual port cards.
+                * and block 3 has some special diagnostic registers that
+                * are poison.
+                */
+               switch (b) {
+               case 3:
+                       /* skip diagnostic ram region */
+                       memcpy_fromio(p + 0x10, io + 0x10, 128 - 0x10);
+                       break;
 
-       /* copy GMAC registers */
-       memcpy_fromio(p + BASE_GMAC_1, io + BASE_GMAC_1, 0x1000);
-       if (sky2->hw->ports > 1)
-               memcpy_fromio(p + BASE_GMAC_2, io + BASE_GMAC_2, 0x1000);
+               /* dual port cards only */
+               case 5:         /* Tx Arbiter 2 */
+               case 9:         /* RX2 */
+               case 14 ... 15: /* TX2 */
+               case 17: case 19: /* Ram Buffer 2 */
+               case 22 ... 23: /* Tx Ram Buffer 2 */
+               case 25:        /* Rx MAC Fifo 1 */
+               case 27:        /* Tx MAC Fifo 2 */
+               case 31:        /* GPHY 2 */
+               case 40 ... 47: /* Pattern Ram 2 */
+               case 52: case 54: /* TCP Segmentation 2 */
+               case 112 ... 116: /* GMAC 2 */
+                       if (sky2->hw->ports == 1)
+                               goto reserved;
+                       /* fall through */
+               case 0:         /* Control */
+               case 2:         /* Mac address */
+               case 4:         /* Tx Arbiter 1 */
+               case 7:         /* PCI express reg */
+               case 8:         /* RX1 */
+               case 12 ... 13: /* TX1 */
+               case 16: case 18:/* Rx Ram Buffer 1 */
+               case 20 ... 21: /* Tx Ram Buffer 1 */
+               case 24:        /* Rx MAC Fifo 1 */
+               case 26:        /* Tx MAC Fifo 1 */
+               case 28 ... 29: /* Descriptor and status unit */
+               case 30:        /* GPHY 1*/
+               case 32 ... 39: /* Pattern Ram 1 */
+               case 48: case 50: /* TCP Segmentation 1 */
+               case 56 ... 60: /* PCI space */
+               case 80 ... 84: /* GMAC 1 */
+                       memcpy_fromio(p, io, 128);
+                       break;
+               default:
+reserved:
+                       memset(p, 0, 128);
+               }
 
+               p += 128;
+               io += 128;
+       }
 }
 
 /* In order to do Jumbo packets on these chips, need to turn off the
@@ -3609,32 +3664,33 @@ static int sky2_set_tso(struct net_device *dev, u32 data)
 static int sky2_get_eeprom_len(struct net_device *dev)
 {
        struct sky2_port *sky2 = netdev_priv(dev);
+       struct sky2_hw *hw = sky2->hw;
        u16 reg2;
 
-       pci_read_config_word(sky2->hw->pdev, PCI_DEV_REG2, &reg2);
+       reg2 = sky2_pci_read16(hw, PCI_DEV_REG2);
        return 1 << ( ((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8);
 }
 
-static u32 sky2_vpd_read(struct pci_dev *pdev, int cap, u16 offset)
+static u32 sky2_vpd_read(struct sky2_hw *hw, int cap, u16 offset)
 {
        u32 val;
 
-       pci_write_config_word(pdev, cap + PCI_VPD_ADDR, offset);
+       sky2_pci_write16(hw, cap + PCI_VPD_ADDR, offset);
 
        do {
-               pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &offset);
+               offset = sky2_pci_read16(hw, cap + PCI_VPD_ADDR);
        } while (!(offset & PCI_VPD_ADDR_F));
 
-       pci_read_config_dword(pdev, cap + PCI_VPD_DATA, &val);
+       val = sky2_pci_read32(hw, cap + PCI_VPD_DATA);
        return val;
 }
 
-static void sky2_vpd_write(struct pci_dev *pdev, int cap, u16 offset, u32 val)
+static void sky2_vpd_write(struct sky2_hw *hw, int cap, u16 offset, u32 val)
 {
-       pci_write_config_word(pdev, cap + PCI_VPD_DATA, val);
-       pci_write_config_dword(pdev, cap + PCI_VPD_ADDR, offset | PCI_VPD_ADDR_F);
+       sky2_pci_write16(hw, cap + PCI_VPD_DATA, val);
+       sky2_pci_write32(hw, cap + PCI_VPD_ADDR, offset | PCI_VPD_ADDR_F);
        do {
-               pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &offset);
+               offset = sky2_pci_read16(hw, cap + PCI_VPD_ADDR);
        } while (offset & PCI_VPD_ADDR_F);
 }
 
@@ -3652,7 +3708,7 @@ static int sky2_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom
        eeprom->magic = SKY2_EEPROM_MAGIC;
 
        while (length > 0) {
-               u32 val = sky2_vpd_read(sky2->hw->pdev, cap, offset);
+               u32 val = sky2_vpd_read(sky2->hw, cap, offset);
                int n = min_t(int, length, sizeof(val));
 
                memcpy(data, &val, n);
@@ -3682,10 +3738,10 @@ static int sky2_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom
                int n = min_t(int, length, sizeof(val));
 
                if (n < sizeof(val))
-                       val = sky2_vpd_read(sky2->hw->pdev, cap, offset);
+                       val = sky2_vpd_read(sky2->hw, cap, offset);
                memcpy(&val, data, n);
 
-               sky2_vpd_write(sky2->hw->pdev, cap, offset, val);
+               sky2_vpd_write(sky2->hw, cap, offset, val);
 
                length -= n;
                data += n;
@@ -3710,11 +3766,8 @@ static const struct ethtool_ops sky2_ethtool_ops = {
        .get_eeprom_len = sky2_get_eeprom_len,
        .get_eeprom     = sky2_get_eeprom,
        .set_eeprom     = sky2_set_eeprom,
-       .get_sg         = ethtool_op_get_sg,
        .set_sg         = ethtool_op_set_sg,
-       .get_tx_csum    = ethtool_op_get_tx_csum,
        .set_tx_csum    = sky2_set_tx_csum,
-       .get_tso        = ethtool_op_get_tso,
        .set_tso        = sky2_set_tso,
        .get_rx_csum    = sky2_get_rx_csum,
        .set_rx_csum    = sky2_set_rx_csum,
@@ -3726,7 +3779,7 @@ static const struct ethtool_ops sky2_ethtool_ops = {
        .get_pauseparam = sky2_get_pauseparam,
        .set_pauseparam = sky2_set_pauseparam,
        .phys_id        = sky2_phys_id,
-       .get_stats_count = sky2_get_stats_count,
+       .get_sset_count = sky2_get_sset_count,
        .get_ethtool_stats = sky2_get_ethtool_stats,
 };
 
@@ -3920,7 +3973,7 @@ static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
        struct net_device *dev = alloc_etherdev(sizeof(*sky2));
 
        if (!dev) {
-               dev_err(&hw->pdev->dev, "etherdev alloc failed");
+               dev_err(&hw->pdev->dev, "etherdev alloc failed\n");
                return NULL;
        }
 
@@ -3930,7 +3983,6 @@ static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
        dev->stop = sky2_down;
        dev->do_ioctl = sky2_ioctl;
        dev->hard_start_xmit = sky2_xmit_frame;
-       dev->get_stats = sky2_get_stats;
        dev->set_multicast_list = sky2_set_multicast;
        dev->set_mac_address = sky2_set_mac_address;
        dev->change_mtu = sky2_change_mtu;
@@ -3938,7 +3990,8 @@ static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
        dev->tx_timeout = sky2_tx_timeout;
        dev->watchdog_timeo = TX_WATCHDOG;
 #ifdef CONFIG_NET_POLL_CONTROLLER
-       dev->poll_controller = sky2_netpoll;
+       if (port == 0)
+               dev->poll_controller = sky2_netpoll;
 #endif
 
        sky2 = netdev_priv(dev);
@@ -3953,7 +4006,7 @@ static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
        sky2->duplex = -1;
        sky2->speed = -1;
        sky2->advertising = sky2_supported_modes(hw);
-       sky2->rx_csum = 1;
+       sky2->rx_csum = (hw->chip_id != CHIP_ID_YUKON_XL);
        sky2->wol = wol;
 
        spin_lock_init(&sky2->phy_lock);
@@ -3987,12 +4040,11 @@ static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
 static void __devinit sky2_show_addr(struct net_device *dev)
 {
        const struct sky2_port *sky2 = netdev_priv(dev);
+       DECLARE_MAC_BUF(mac);
 
        if (netif_msg_probe(sky2))
-               printk(KERN_INFO PFX "%s: addr %02x:%02x:%02x:%02x:%02x:%02x\n",
-                      dev->name,
-                      dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
-                      dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
+               printk(KERN_INFO PFX "%s: addr %s\n",
+                      dev->name, print_mac(mac, dev->dev_addr));
 }
 
 /* Handle software interrupt used during MSI test */
@@ -4125,9 +4177,9 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
         */
        {
                u32 reg;
-               pci_read_config_dword(pdev,PCI_DEV_REG2, &reg);
+               reg = sky2_pci_read32(hw, PCI_DEV_REG2);
                reg &= ~PCI_REV_DESC;
-               pci_write_config_dword(pdev, PCI_DEV_REG2, reg);
+               sky2_pci_write32(hw, PCI_DEV_REG2, reg);
        }
 #endif
 
@@ -4152,7 +4204,6 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
                err = -ENOMEM;
                goto err_out_free_pci;
        }
-       netif_napi_add(dev, &hw->napi, sky2_poll, NAPI_WEIGHT);
 
        if (!disable_msi && pci_enable_msi(pdev) == 0) {
                err = sky2_test_msi(hw);
@@ -4168,6 +4219,8 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
                goto err_out_free_netdev;
        }
 
+       netif_napi_add(dev, &hw->napi, sky2_poll, NAPI_WEIGHT);
+
        err = request_irq(pdev->irq, sky2_intr,
                          (hw->flags & SKY2_HW_USE_MSI) ? 0 : IRQF_SHARED,
                          dev->name, hw);
@@ -4176,6 +4229,7 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
                goto err_out_unregister;
        }
        sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
+       napi_enable(&hw->napi);
 
        sky2_show_addr(dev);
 
@@ -4226,23 +4280,18 @@ err_out:
 static void __devexit sky2_remove(struct pci_dev *pdev)
 {
        struct sky2_hw *hw = pci_get_drvdata(pdev);
-       struct net_device *dev0, *dev1;
+       int i;
 
        if (!hw)
                return;
 
        del_timer_sync(&hw->watchdog_timer);
+       cancel_work_sync(&hw->restart_work);
 
-       flush_scheduled_work();
+       for (i = hw->ports-1; i >= 0; --i)
+               unregister_netdev(hw->dev[i]);
 
        sky2_write32(hw, B0_IMSK, 0);
-       synchronize_irq(hw->pdev->irq);
-
-       dev0 = hw->dev[0];
-       dev1 = hw->dev[1];
-       if (dev1)
-               unregister_netdev(dev1);
-       unregister_netdev(dev0);
 
        sky2_power_aux(hw);
 
@@ -4257,9 +4306,9 @@ static void __devexit sky2_remove(struct pci_dev *pdev)
        pci_release_regions(pdev);
        pci_disable_device(pdev);
 
-       if (dev1)
-               free_netdev(dev1);
-       free_netdev(dev0);
+       for (i = hw->ports-1; i >= 0; --i)
+               free_netdev(hw->dev[i]);
+
        iounmap(hw->regs);
        kfree(hw);
 
@@ -4289,6 +4338,7 @@ static int sky2_suspend(struct pci_dev *pdev, pm_message_t state)
        }
 
        sky2_write32(hw, B0_IMSK, 0);
+       napi_disable(&hw->napi);
        sky2_power_aux(hw);
 
        pci_save_state(pdev);
@@ -4320,11 +4370,11 @@ static int sky2_resume(struct pci_dev *pdev)
        if (hw->chip_id == CHIP_ID_YUKON_EX ||
            hw->chip_id == CHIP_ID_YUKON_EC_U ||
            hw->chip_id == CHIP_ID_YUKON_FE_P)
-               pci_write_config_dword(pdev, PCI_DEV_REG3, 0);
+               sky2_pci_write32(hw, PCI_DEV_REG3, 0);
 
        sky2_reset(hw);
-
        sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
+       napi_enable(&hw->napi);
 
        for (i = 0; i < hw->ports; i++) {
                struct net_device *dev = hw->dev[i];
@@ -4357,7 +4407,7 @@ static void sky2_shutdown(struct pci_dev *pdev)
        if (!hw)
                return;
 
-       napi_disable(&hw->napi);
+       del_timer_sync(&hw->watchdog_timer);
 
        for (i = 0; i < hw->ports; i++) {
                struct net_device *dev = hw->dev[i];