CAN: add controller hardware name for Softing cards
[linux-2.6.git] / drivers / net / niu.c
index 1f1b815..9fb59d3 100644 (file)
@@ -1,8 +1,10 @@
 /* niu.c: Neptune ethernet driver.
  *
- * Copyright (C) 2007 David S. Miller (davem@davemloft.net)
+ * Copyright (C) 2007, 2008 David S. Miller (davem@davemloft.net)
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/pci.h>
 #include <linux/log2.h>
 #include <linux/jiffies.h>
 #include <linux/crc32.h>
+#include <linux/list.h>
+#include <linux/slab.h>
 
 #include <linux/io.h>
-
-#ifdef CONFIG_SPARC64
 #include <linux/of_device.h>
-#endif
 
 #include "niu.h"
 
 #define DRV_MODULE_NAME                "niu"
-#define PFX DRV_MODULE_NAME    ": "
-#define DRV_MODULE_VERSION     "0.6"
-#define DRV_MODULE_RELDATE     "January 5, 2008"
+#define DRV_MODULE_VERSION     "1.1"
+#define DRV_MODULE_RELDATE     "Apr 22, 2010"
 
 static char version[] __devinitdata =
        DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
@@ -44,15 +44,10 @@ MODULE_DESCRIPTION("NIU ethernet driver");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_MODULE_VERSION);
 
-#ifndef DMA_44BIT_MASK
-#define DMA_44BIT_MASK 0x00000fffffffffffULL
-#endif
-
 #ifndef readq
 static u64 readq(void __iomem *reg)
 {
-       return (((u64)readl(reg + 0x4UL) << 32) |
-               (u64)readl(reg));
+       return ((u64) readl(reg)) | (((u64) readl(reg + 4UL)) << 32);
 }
 
 static void writeq(u64 val, void __iomem *reg)
@@ -62,7 +57,7 @@ static void writeq(u64 val, void __iomem *reg)
 }
 #endif
 
-static struct pci_device_id niu_pci_tbl[] = {
+static DEFINE_PCI_DEVICE_TABLE(niu_pci_tbl) = {
        {PCI_DEVICE(PCI_VENDOR_ID_SUN, 0xabcd)},
        {}
 };
@@ -93,26 +88,13 @@ static int debug = -1;
 module_param(debug, int, 0);
 MODULE_PARM_DESC(debug, "NIU debug level");
 
-#define niudbg(TYPE, f, a...) \
-do {   if ((np)->msg_enable & NETIF_MSG_##TYPE) \
-               printk(KERN_DEBUG PFX f, ## a); \
-} while (0)
-
-#define niuinfo(TYPE, f, a...) \
-do {   if ((np)->msg_enable & NETIF_MSG_##TYPE) \
-               printk(KERN_INFO PFX f, ## a); \
-} while (0)
-
-#define niuwarn(TYPE, f, a...) \
-do {   if ((np)->msg_enable & NETIF_MSG_##TYPE) \
-               printk(KERN_WARNING PFX f, ## a); \
-} while (0)
-
 #define niu_lock_parent(np, flags) \
        spin_lock_irqsave(&np->parent->lock, flags)
 #define niu_unlock_parent(np, flags) \
        spin_unlock_irqrestore(&np->parent->lock, flags)
 
+static int serdes_init_10g_serdes(struct niu *np);
+
 static int __niu_wait_bits_clear_mac(struct niu *np, unsigned long reg,
                                     u64 bits, int limit, int delay)
 {
@@ -137,10 +119,9 @@ static int __niu_set_and_wait_clear_mac(struct niu *np, unsigned long reg,
        nw64_mac(reg, bits);
        err = __niu_wait_bits_clear_mac(np, reg, bits, limit, delay);
        if (err)
-               dev_err(np->device, PFX "%s: bits (%llx) of register %s "
-                       "would not clear, val[%llx]\n",
-                       np->dev->name, (unsigned long long) bits, reg_name,
-                       (unsigned long long) nr64_mac(reg));
+               netdev_err(np->dev, "bits (%llx) of register %s would not clear, val[%llx]\n",
+                          (unsigned long long)bits, reg_name,
+                          (unsigned long long)nr64_mac(reg));
        return err;
 }
 
@@ -177,10 +158,9 @@ static int __niu_set_and_wait_clear_ipp(struct niu *np, unsigned long reg,
 
        err = __niu_wait_bits_clear_ipp(np, reg, bits, limit, delay);
        if (err)
-               dev_err(np->device, PFX "%s: bits (%llx) of register %s "
-                       "would not clear, val[%llx]\n",
-                       np->dev->name, (unsigned long long) bits, reg_name,
-                       (unsigned long long) nr64_ipp(reg));
+               netdev_err(np->dev, "bits (%llx) of register %s would not clear, val[%llx]\n",
+                          (unsigned long long)bits, reg_name,
+                          (unsigned long long)nr64_ipp(reg));
        return err;
 }
 
@@ -218,10 +198,9 @@ static int __niu_set_and_wait_clear(struct niu *np, unsigned long reg,
        nw64(reg, bits);
        err = __niu_wait_bits_clear(np, reg, bits, limit, delay);
        if (err)
-               dev_err(np->device, PFX "%s: bits (%llx) of register %s "
-                       "would not clear, val[%llx]\n",
-                       np->dev->name, (unsigned long long) bits, reg_name,
-                       (unsigned long long) nr64(reg));
+               netdev_err(np->dev, "bits (%llx) of register %s would not clear, val[%llx]\n",
+                          (unsigned long long)bits, reg_name,
+                          (unsigned long long)nr64(reg));
        return err;
 }
 
@@ -304,7 +283,7 @@ static int niu_enable_interrupts(struct niu *np, int on)
 
 static u32 phy_encode(u32 type, int port)
 {
-       return (type << (port * 2));
+       return type << (port * 2);
 }
 
 static u32 phy_decode(u32 val, int port)
@@ -405,7 +384,7 @@ static int esr2_set_rx_cfg(struct niu *np, unsigned long channel, u32 val)
 }
 
 /* Mode is always 10G fiber.  */
-static int serdes_init_niu(struct niu *np)
+static int serdes_init_niu_10g_fiber(struct niu *np)
 {
        struct niu_link_config *lp = &np->link_config;
        u32 tx_cfg, rx_cfg;
@@ -442,6 +421,218 @@ static int serdes_init_niu(struct niu *np)
        return 0;
 }
 
+static int serdes_init_niu_1g_serdes(struct niu *np)
+{
+       struct niu_link_config *lp = &np->link_config;
+       u16 pll_cfg, pll_sts;
+       int max_retry = 100;
+       u64 uninitialized_var(sig), mask, val;
+       u32 tx_cfg, rx_cfg;
+       unsigned long i;
+       int err;
+
+       tx_cfg = (PLL_TX_CFG_ENTX | PLL_TX_CFG_SWING_1375MV |
+                 PLL_TX_CFG_RATE_HALF);
+       rx_cfg = (PLL_RX_CFG_ENRX | PLL_RX_CFG_TERM_0P8VDDT |
+                 PLL_RX_CFG_ALIGN_ENA | PLL_RX_CFG_LOS_LTHRESH |
+                 PLL_RX_CFG_RATE_HALF);
+
+       if (np->port == 0)
+               rx_cfg |= PLL_RX_CFG_EQ_LP_ADAPTIVE;
+
+       if (lp->loopback_mode == LOOPBACK_PHY) {
+               u16 test_cfg = PLL_TEST_CFG_LOOPBACK_CML_DIS;
+
+               mdio_write(np, np->port, NIU_ESR2_DEV_ADDR,
+                          ESR2_TI_PLL_TEST_CFG_L, test_cfg);
+
+               tx_cfg |= PLL_TX_CFG_ENTEST;
+               rx_cfg |= PLL_RX_CFG_ENTEST;
+       }
+
+       /* Initialize PLL for 1G */
+       pll_cfg = (PLL_CFG_ENPLL | PLL_CFG_MPY_8X);
+
+       err = mdio_write(np, np->port, NIU_ESR2_DEV_ADDR,
+                        ESR2_TI_PLL_CFG_L, pll_cfg);
+       if (err) {
+               netdev_err(np->dev, "NIU Port %d %s() mdio write to ESR2_TI_PLL_CFG_L failed\n",
+                          np->port, __func__);
+               return err;
+       }
+
+       pll_sts = PLL_CFG_ENPLL;
+
+       err = mdio_write(np, np->port, NIU_ESR2_DEV_ADDR,
+                        ESR2_TI_PLL_STS_L, pll_sts);
+       if (err) {
+               netdev_err(np->dev, "NIU Port %d %s() mdio write to ESR2_TI_PLL_STS_L failed\n",
+                          np->port, __func__);
+               return err;
+       }
+
+       udelay(200);
+
+       /* Initialize all 4 lanes of the SERDES.  */
+       for (i = 0; i < 4; i++) {
+               err = esr2_set_tx_cfg(np, i, tx_cfg);
+               if (err)
+                       return err;
+       }
+
+       for (i = 0; i < 4; i++) {
+               err = esr2_set_rx_cfg(np, i, rx_cfg);
+               if (err)
+                       return err;
+       }
+
+       switch (np->port) {
+       case 0:
+               val = (ESR_INT_SRDY0_P0 | ESR_INT_DET0_P0);
+               mask = val;
+               break;
+
+       case 1:
+               val = (ESR_INT_SRDY0_P1 | ESR_INT_DET0_P1);
+               mask = val;
+               break;
+
+       default:
+               return -EINVAL;
+       }
+
+       while (max_retry--) {
+               sig = nr64(ESR_INT_SIGNALS);
+               if ((sig & mask) == val)
+                       break;
+
+               mdelay(500);
+       }
+
+       if ((sig & mask) != val) {
+               netdev_err(np->dev, "Port %u signal bits [%08x] are not [%08x]\n",
+                          np->port, (int)(sig & mask), (int)val);
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
+static int serdes_init_niu_10g_serdes(struct niu *np)
+{
+       struct niu_link_config *lp = &np->link_config;
+       u32 tx_cfg, rx_cfg, pll_cfg, pll_sts;
+       int max_retry = 100;
+       u64 uninitialized_var(sig), mask, val;
+       unsigned long i;
+       int err;
+
+       tx_cfg = (PLL_TX_CFG_ENTX | PLL_TX_CFG_SWING_1375MV);
+       rx_cfg = (PLL_RX_CFG_ENRX | PLL_RX_CFG_TERM_0P8VDDT |
+                 PLL_RX_CFG_ALIGN_ENA | PLL_RX_CFG_LOS_LTHRESH |
+                 PLL_RX_CFG_EQ_LP_ADAPTIVE);
+
+       if (lp->loopback_mode == LOOPBACK_PHY) {
+               u16 test_cfg = PLL_TEST_CFG_LOOPBACK_CML_DIS;
+
+               mdio_write(np, np->port, NIU_ESR2_DEV_ADDR,
+                          ESR2_TI_PLL_TEST_CFG_L, test_cfg);
+
+               tx_cfg |= PLL_TX_CFG_ENTEST;
+               rx_cfg |= PLL_RX_CFG_ENTEST;
+       }
+
+       /* Initialize PLL for 10G */
+       pll_cfg = (PLL_CFG_ENPLL | PLL_CFG_MPY_10X);
+
+       err = mdio_write(np, np->port, NIU_ESR2_DEV_ADDR,
+                        ESR2_TI_PLL_CFG_L, pll_cfg & 0xffff);
+       if (err) {
+               netdev_err(np->dev, "NIU Port %d %s() mdio write to ESR2_TI_PLL_CFG_L failed\n",
+                          np->port, __func__);
+               return err;
+       }
+
+       pll_sts = PLL_CFG_ENPLL;
+
+       err = mdio_write(np, np->port, NIU_ESR2_DEV_ADDR,
+                        ESR2_TI_PLL_STS_L, pll_sts & 0xffff);
+       if (err) {
+               netdev_err(np->dev, "NIU Port %d %s() mdio write to ESR2_TI_PLL_STS_L failed\n",
+                          np->port, __func__);
+               return err;
+       }
+
+       udelay(200);
+
+       /* Initialize all 4 lanes of the SERDES.  */
+       for (i = 0; i < 4; i++) {
+               err = esr2_set_tx_cfg(np, i, tx_cfg);
+               if (err)
+                       return err;
+       }
+
+       for (i = 0; i < 4; i++) {
+               err = esr2_set_rx_cfg(np, i, rx_cfg);
+               if (err)
+                       return err;
+       }
+
+       /* check if serdes is ready */
+
+       switch (np->port) {
+       case 0:
+               mask = ESR_INT_SIGNALS_P0_BITS;
+               val = (ESR_INT_SRDY0_P0 |
+                      ESR_INT_DET0_P0 |
+                      ESR_INT_XSRDY_P0 |
+                      ESR_INT_XDP_P0_CH3 |
+                      ESR_INT_XDP_P0_CH2 |
+                      ESR_INT_XDP_P0_CH1 |
+                      ESR_INT_XDP_P0_CH0);
+               break;
+
+       case 1:
+               mask = ESR_INT_SIGNALS_P1_BITS;
+               val = (ESR_INT_SRDY0_P1 |
+                      ESR_INT_DET0_P1 |
+                      ESR_INT_XSRDY_P1 |
+                      ESR_INT_XDP_P1_CH3 |
+                      ESR_INT_XDP_P1_CH2 |
+                      ESR_INT_XDP_P1_CH1 |
+                      ESR_INT_XDP_P1_CH0);
+               break;
+
+       default:
+               return -EINVAL;
+       }
+
+       while (max_retry--) {
+               sig = nr64(ESR_INT_SIGNALS);
+               if ((sig & mask) == val)
+                       break;
+
+               mdelay(500);
+       }
+
+       if ((sig & mask) != val) {
+               pr_info("NIU Port %u signal bits [%08x] are not [%08x] for 10G...trying 1G\n",
+                       np->port, (int)(sig & mask), (int)val);
+
+               /* 10G failed, try initializing at 1G */
+               err = serdes_init_niu_1g_serdes(np);
+               if (!err) {
+                       np->flags &= ~NIU_FLAGS_10G;
+                       np->mac_xcvr = MAC_XCVR_PCS;
+               }  else {
+                       netdev_err(np->dev, "Port %u 10G/1G SERDES Link Failed\n",
+                                  np->port);
+                       return -ENODEV;
+               }
+       }
+       return 0;
+}
+
 static int esr_read_rxtx_ctrl(struct niu *np, unsigned long chan, u32 *val)
 {
        int err;
@@ -520,7 +711,7 @@ static int esr_write_glue0(struct niu *np, unsigned long chan, u32 val)
 
 static int esr_reset(struct niu *np)
 {
-       u32 reset;
+       u32 uninitialized_var(reset);
        int err;
 
        err = mdio_write(np, np->port, NIU_ESR_DEV_ADDR,
@@ -549,9 +740,8 @@ static int esr_reset(struct niu *np)
        if (err)
                return err;
        if (reset != 0) {
-               dev_err(np->device, PFX "Port %u ESR_RESET "
-                       "did not clear [%08x]\n",
-                       np->port, reset);
+               netdev_err(np->dev, "Port %u ESR_RESET did not clear [%08x]\n",
+                          np->port, reset);
                return -ENODEV;
        }
 
@@ -671,11 +861,16 @@ static int serdes_init_10g(struct niu *np)
        }
 
        if ((sig & mask) != val) {
-               dev_err(np->device, PFX "Port %u signal bits [%08x] are not "
-                       "[%08x]\n", np->port, (int) (sig & mask), (int) val);
+               if (np->flags & NIU_FLAGS_HOTPLUG_PHY) {
+                       np->flags &= ~NIU_FLAGS_HOTPLUG_PHY_PRESENT;
+                       return 0;
+               }
+               netdev_err(np->dev, "Port %u signal bits [%08x] are not [%08x]\n",
+                          np->port, (int)(sig & mask), (int)val);
                return -ENODEV;
        }
-
+       if (np->flags & NIU_FLAGS_HOTPLUG_PHY)
+               np->flags |= NIU_FLAGS_HOTPLUG_PHY_PRESENT;
        return 0;
 }
 
@@ -706,13 +901,395 @@ static int serdes_init_1g(struct niu *np)
        return 0;
 }
 
+static int serdes_init_1g_serdes(struct niu *np)
+{
+       struct niu_link_config *lp = &np->link_config;
+       unsigned long ctrl_reg, test_cfg_reg, pll_cfg, i;
+       u64 ctrl_val, test_cfg_val, sig, mask, val;
+       int err;
+       u64 reset_val, val_rd;
+
+       val = ENET_SERDES_PLL_HRATE0 | ENET_SERDES_PLL_HRATE1 |
+               ENET_SERDES_PLL_HRATE2 | ENET_SERDES_PLL_HRATE3 |
+               ENET_SERDES_PLL_FBDIV0;
+       switch (np->port) {
+       case 0:
+               reset_val =  ENET_SERDES_RESET_0;
+               ctrl_reg = ENET_SERDES_0_CTRL_CFG;
+               test_cfg_reg = ENET_SERDES_0_TEST_CFG;
+               pll_cfg = ENET_SERDES_0_PLL_CFG;
+               break;
+       case 1:
+               reset_val =  ENET_SERDES_RESET_1;
+               ctrl_reg = ENET_SERDES_1_CTRL_CFG;
+               test_cfg_reg = ENET_SERDES_1_TEST_CFG;
+               pll_cfg = ENET_SERDES_1_PLL_CFG;
+               break;
+
+       default:
+               return -EINVAL;
+       }
+       ctrl_val = (ENET_SERDES_CTRL_SDET_0 |
+                   ENET_SERDES_CTRL_SDET_1 |
+                   ENET_SERDES_CTRL_SDET_2 |
+                   ENET_SERDES_CTRL_SDET_3 |
+                   (0x5 << ENET_SERDES_CTRL_EMPH_0_SHIFT) |
+                   (0x5 << ENET_SERDES_CTRL_EMPH_1_SHIFT) |
+                   (0x5 << ENET_SERDES_CTRL_EMPH_2_SHIFT) |
+                   (0x5 << ENET_SERDES_CTRL_EMPH_3_SHIFT) |
+                   (0x1 << ENET_SERDES_CTRL_LADJ_0_SHIFT) |
+                   (0x1 << ENET_SERDES_CTRL_LADJ_1_SHIFT) |
+                   (0x1 << ENET_SERDES_CTRL_LADJ_2_SHIFT) |
+                   (0x1 << ENET_SERDES_CTRL_LADJ_3_SHIFT));
+       test_cfg_val = 0;
+
+       if (lp->loopback_mode == LOOPBACK_PHY) {
+               test_cfg_val |= ((ENET_TEST_MD_PAD_LOOPBACK <<
+                                 ENET_SERDES_TEST_MD_0_SHIFT) |
+                                (ENET_TEST_MD_PAD_LOOPBACK <<
+                                 ENET_SERDES_TEST_MD_1_SHIFT) |
+                                (ENET_TEST_MD_PAD_LOOPBACK <<
+                                 ENET_SERDES_TEST_MD_2_SHIFT) |
+                                (ENET_TEST_MD_PAD_LOOPBACK <<
+                                 ENET_SERDES_TEST_MD_3_SHIFT));
+       }
+
+       nw64(ENET_SERDES_RESET, reset_val);
+       mdelay(20);
+       val_rd = nr64(ENET_SERDES_RESET);
+       val_rd &= ~reset_val;
+       nw64(pll_cfg, val);
+       nw64(ctrl_reg, ctrl_val);
+       nw64(test_cfg_reg, test_cfg_val);
+       nw64(ENET_SERDES_RESET, val_rd);
+       mdelay(2000);
+
+       /* Initialize all 4 lanes of the SERDES.  */
+       for (i = 0; i < 4; i++) {
+               u32 rxtx_ctrl, glue0;
+
+               err = esr_read_rxtx_ctrl(np, i, &rxtx_ctrl);
+               if (err)
+                       return err;
+               err = esr_read_glue0(np, i, &glue0);
+               if (err)
+                       return err;
+
+               rxtx_ctrl &= ~(ESR_RXTX_CTRL_VMUXLO);
+               rxtx_ctrl |= (ESR_RXTX_CTRL_ENSTRETCH |
+                             (2 << ESR_RXTX_CTRL_VMUXLO_SHIFT));
+
+               glue0 &= ~(ESR_GLUE_CTRL0_SRATE |
+                          ESR_GLUE_CTRL0_THCNT |
+                          ESR_GLUE_CTRL0_BLTIME);
+               glue0 |= (ESR_GLUE_CTRL0_RXLOSENAB |
+                         (0xf << ESR_GLUE_CTRL0_SRATE_SHIFT) |
+                         (0xff << ESR_GLUE_CTRL0_THCNT_SHIFT) |
+                         (BLTIME_300_CYCLES <<
+                          ESR_GLUE_CTRL0_BLTIME_SHIFT));
+
+               err = esr_write_rxtx_ctrl(np, i, rxtx_ctrl);
+               if (err)
+                       return err;
+               err = esr_write_glue0(np, i, glue0);
+               if (err)
+                       return err;
+       }
+
+
+       sig = nr64(ESR_INT_SIGNALS);
+       switch (np->port) {
+       case 0:
+               val = (ESR_INT_SRDY0_P0 | ESR_INT_DET0_P0);
+               mask = val;
+               break;
+
+       case 1:
+               val = (ESR_INT_SRDY0_P1 | ESR_INT_DET0_P1);
+               mask = val;
+               break;
+
+       default:
+               return -EINVAL;
+       }
+
+       if ((sig & mask) != val) {
+               netdev_err(np->dev, "Port %u signal bits [%08x] are not [%08x]\n",
+                          np->port, (int)(sig & mask), (int)val);
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
+static int link_status_1g_serdes(struct niu *np, int *link_up_p)
+{
+       struct niu_link_config *lp = &np->link_config;
+       int link_up;
+       u64 val;
+       u16 current_speed;
+       unsigned long flags;
+       u8 current_duplex;
+
+       link_up = 0;
+       current_speed = SPEED_INVALID;
+       current_duplex = DUPLEX_INVALID;
+
+       spin_lock_irqsave(&np->lock, flags);
+
+       val = nr64_pcs(PCS_MII_STAT);
+
+       if (val & PCS_MII_STAT_LINK_STATUS) {
+               link_up = 1;
+               current_speed = SPEED_1000;
+               current_duplex = DUPLEX_FULL;
+       }
+
+       lp->active_speed = current_speed;
+       lp->active_duplex = current_duplex;
+       spin_unlock_irqrestore(&np->lock, flags);
+
+       *link_up_p = link_up;
+       return 0;
+}
+
+static int link_status_10g_serdes(struct niu *np, int *link_up_p)
+{
+       unsigned long flags;
+       struct niu_link_config *lp = &np->link_config;
+       int link_up = 0;
+       int link_ok = 1;
+       u64 val, val2;
+       u16 current_speed;
+       u8 current_duplex;
+
+       if (!(np->flags & NIU_FLAGS_10G))
+               return link_status_1g_serdes(np, link_up_p);
+
+       current_speed = SPEED_INVALID;
+       current_duplex = DUPLEX_INVALID;
+       spin_lock_irqsave(&np->lock, flags);
+
+       val = nr64_xpcs(XPCS_STATUS(0));
+       val2 = nr64_mac(XMAC_INTER2);
+       if (val2 & 0x01000000)
+               link_ok = 0;
+
+       if ((val & 0x1000ULL) && link_ok) {
+               link_up = 1;
+               current_speed = SPEED_10000;
+               current_duplex = DUPLEX_FULL;
+       }
+       lp->active_speed = current_speed;
+       lp->active_duplex = current_duplex;
+       spin_unlock_irqrestore(&np->lock, flags);
+       *link_up_p = link_up;
+       return 0;
+}
+
+static int link_status_mii(struct niu *np, int *link_up_p)
+{
+       struct niu_link_config *lp = &np->link_config;
+       int err;
+       int bmsr, advert, ctrl1000, stat1000, lpa, bmcr, estatus;
+       int supported, advertising, active_speed, active_duplex;
+
+       err = mii_read(np, np->phy_addr, MII_BMCR);
+       if (unlikely(err < 0))
+               return err;
+       bmcr = err;
+
+       err = mii_read(np, np->phy_addr, MII_BMSR);
+       if (unlikely(err < 0))
+               return err;
+       bmsr = err;
+
+       err = mii_read(np, np->phy_addr, MII_ADVERTISE);
+       if (unlikely(err < 0))
+               return err;
+       advert = err;
+
+       err = mii_read(np, np->phy_addr, MII_LPA);
+       if (unlikely(err < 0))
+               return err;
+       lpa = err;
+
+       if (likely(bmsr & BMSR_ESTATEN)) {
+               err = mii_read(np, np->phy_addr, MII_ESTATUS);
+               if (unlikely(err < 0))
+                       return err;
+               estatus = err;
+
+               err = mii_read(np, np->phy_addr, MII_CTRL1000);
+               if (unlikely(err < 0))
+                       return err;
+               ctrl1000 = err;
+
+               err = mii_read(np, np->phy_addr, MII_STAT1000);
+               if (unlikely(err < 0))
+                       return err;
+               stat1000 = err;
+       } else
+               estatus = ctrl1000 = stat1000 = 0;
+
+       supported = 0;
+       if (bmsr & BMSR_ANEGCAPABLE)
+               supported |= SUPPORTED_Autoneg;
+       if (bmsr & BMSR_10HALF)
+               supported |= SUPPORTED_10baseT_Half;
+       if (bmsr & BMSR_10FULL)
+               supported |= SUPPORTED_10baseT_Full;
+       if (bmsr & BMSR_100HALF)
+               supported |= SUPPORTED_100baseT_Half;
+       if (bmsr & BMSR_100FULL)
+               supported |= SUPPORTED_100baseT_Full;
+       if (estatus & ESTATUS_1000_THALF)
+               supported |= SUPPORTED_1000baseT_Half;
+       if (estatus & ESTATUS_1000_TFULL)
+               supported |= SUPPORTED_1000baseT_Full;
+       lp->supported = supported;
+
+       advertising = 0;
+       if (advert & ADVERTISE_10HALF)
+               advertising |= ADVERTISED_10baseT_Half;
+       if (advert & ADVERTISE_10FULL)
+               advertising |= ADVERTISED_10baseT_Full;
+       if (advert & ADVERTISE_100HALF)
+               advertising |= ADVERTISED_100baseT_Half;
+       if (advert & ADVERTISE_100FULL)
+               advertising |= ADVERTISED_100baseT_Full;
+       if (ctrl1000 & ADVERTISE_1000HALF)
+               advertising |= ADVERTISED_1000baseT_Half;
+       if (ctrl1000 & ADVERTISE_1000FULL)
+               advertising |= ADVERTISED_1000baseT_Full;
+
+       if (bmcr & BMCR_ANENABLE) {
+               int neg, neg1000;
+
+               lp->active_autoneg = 1;
+               advertising |= ADVERTISED_Autoneg;
+
+               neg = advert & lpa;
+               neg1000 = (ctrl1000 << 2) & stat1000;
+
+               if (neg1000 & (LPA_1000FULL | LPA_1000HALF))
+                       active_speed = SPEED_1000;
+               else if (neg & LPA_100)
+                       active_speed = SPEED_100;
+               else if (neg & (LPA_10HALF | LPA_10FULL))
+                       active_speed = SPEED_10;
+               else
+                       active_speed = SPEED_INVALID;
+
+               if ((neg1000 & LPA_1000FULL) || (neg & LPA_DUPLEX))
+                       active_duplex = DUPLEX_FULL;
+               else if (active_speed != SPEED_INVALID)
+                       active_duplex = DUPLEX_HALF;
+               else
+                       active_duplex = DUPLEX_INVALID;
+       } else {
+               lp->active_autoneg = 0;
+
+               if ((bmcr & BMCR_SPEED1000) && !(bmcr & BMCR_SPEED100))
+                       active_speed = SPEED_1000;
+               else if (bmcr & BMCR_SPEED100)
+                       active_speed = SPEED_100;
+               else
+                       active_speed = SPEED_10;
+
+               if (bmcr & BMCR_FULLDPLX)
+                       active_duplex = DUPLEX_FULL;
+               else
+                       active_duplex = DUPLEX_HALF;
+       }
+
+       lp->active_advertising = advertising;
+       lp->active_speed = active_speed;
+       lp->active_duplex = active_duplex;
+       *link_up_p = !!(bmsr & BMSR_LSTATUS);
+
+       return 0;
+}
+
+static int link_status_1g_rgmii(struct niu *np, int *link_up_p)
+{
+       struct niu_link_config *lp = &np->link_config;
+       u16 current_speed, bmsr;
+       unsigned long flags;
+       u8 current_duplex;
+       int err, link_up;
+
+       link_up = 0;
+       current_speed = SPEED_INVALID;
+       current_duplex = DUPLEX_INVALID;
+
+       spin_lock_irqsave(&np->lock, flags);
+
+       err = -EINVAL;
+
+       err = mii_read(np, np->phy_addr, MII_BMSR);
+       if (err < 0)
+               goto out;
+
+       bmsr = err;
+       if (bmsr & BMSR_LSTATUS) {
+               u16 adv, lpa, common, estat;
+
+               err = mii_read(np, np->phy_addr, MII_ADVERTISE);
+               if (err < 0)
+                       goto out;
+               adv = err;
+
+               err = mii_read(np, np->phy_addr, MII_LPA);
+               if (err < 0)
+                       goto out;
+               lpa = err;
+
+               common = adv & lpa;
+
+               err = mii_read(np, np->phy_addr, MII_ESTATUS);
+               if (err < 0)
+                       goto out;
+               estat = err;
+               link_up = 1;
+               current_speed = SPEED_1000;
+               current_duplex = DUPLEX_FULL;
+
+       }
+       lp->active_speed = current_speed;
+       lp->active_duplex = current_duplex;
+       err = 0;
+
+out:
+       spin_unlock_irqrestore(&np->lock, flags);
+
+       *link_up_p = link_up;
+       return err;
+}
+
+static int link_status_1g(struct niu *np, int *link_up_p)
+{
+       struct niu_link_config *lp = &np->link_config;
+       unsigned long flags;
+       int err;
+
+       spin_lock_irqsave(&np->lock, flags);
+
+       err = link_status_mii(np, link_up_p);
+       lp->supported |= SUPPORTED_TP;
+       lp->active_advertising |= ADVERTISED_TP;
+
+       spin_unlock_irqrestore(&np->lock, flags);
+       return err;
+}
+
 static int bcm8704_reset(struct niu *np)
 {
        int err, limit;
 
        err = mdio_read(np, np->phy_addr,
                        BCM8704_PHYXS_DEV_ADDR, MII_BMCR);
-       if (err < 0)
+       if (err < 0 || err == 0xffff)
                return err;
        err |= BMCR_RESET;
        err = mdio_write(np, np->phy_addr, BCM8704_PHYXS_DEV_ADDR,
@@ -730,8 +1307,8 @@ static int bcm8704_reset(struct niu *np)
                        break;
        }
        if (limit < 0) {
-               dev_err(np->device, PFX "Port %u PHY will not reset "
-                       "(bmcr=%04x)\n", np->port, (err & 0xffff));
+               netdev_err(np->dev, "Port %u PHY will not reset (bmcr=%04x)\n",
+                          np->port, (err & 0xffff));
                return -ENODEV;
        }
        return 0;
@@ -751,6 +1328,28 @@ static int bcm8704_user_dev3_readback(struct niu *np, int reg)
        return 0;
 }
 
+static int bcm8706_init_user_dev3(struct niu *np)
+{
+       int err;
+
+
+       err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR,
+                       BCM8704_USER_OPT_DIGITAL_CTRL);
+       if (err < 0)
+               return err;
+       err &= ~USER_ODIG_CTRL_GPIOS;
+       err |= (0x3 << USER_ODIG_CTRL_GPIOS_SHIFT);
+       err |=  USER_ODIG_CTRL_RESV2;
+       err = mdio_write(np, np->phy_addr, BCM8704_USER_DEV3_ADDR,
+                        BCM8704_USER_OPT_DIGITAL_CTRL, err);
+       if (err)
+               return err;
+
+       mdelay(1000);
+
+       return 0;
+}
+
 static int bcm8704_init_user_dev3(struct niu *np)
 {
        int err;
@@ -880,54 +1479,29 @@ static int xcvr_init_10g_mrvl88x2011(struct niu *np)
                          MRVL88X2011_10G_PMD_TX_DIS, MRVL88X2011_ENA_PMDTX);
 }
 
-static int xcvr_init_10g_bcm8704(struct niu *np)
+
+static int xcvr_diag_bcm870x(struct niu *np)
 {
-       struct niu_link_config *lp = &np->link_config;
        u16 analog_stat0, tx_alarm_status;
-       int err;
-
-       err = bcm8704_reset(np);
-       if (err)
-               return err;
-
-       err = bcm8704_init_user_dev3(np);
-       if (err)
-               return err;
-
-       err = mdio_read(np, np->phy_addr, BCM8704_PCS_DEV_ADDR,
-                       MII_BMCR);
-       if (err < 0)
-               return err;
-       err &= ~BMCR_LOOPBACK;
-
-       if (lp->loopback_mode == LOOPBACK_MAC)
-               err |= BMCR_LOOPBACK;
-
-       err = mdio_write(np, np->phy_addr, BCM8704_PCS_DEV_ADDR,
-                        MII_BMCR, err);
-       if (err)
-               return err;
+       int err = 0;
 
 #if 1
        err = mdio_read(np, np->phy_addr, BCM8704_PMA_PMD_DEV_ADDR,
                        MII_STAT1000);
        if (err < 0)
                return err;
-       pr_info(PFX "Port %u PMA_PMD(MII_STAT1000) [%04x]\n",
-               np->port, err);
+       pr_info("Port %u PMA_PMD(MII_STAT1000) [%04x]\n", np->port, err);
 
        err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, 0x20);
        if (err < 0)
                return err;
-       pr_info(PFX "Port %u USER_DEV3(0x20) [%04x]\n",
-               np->port, err);
+       pr_info("Port %u USER_DEV3(0x20) [%04x]\n", np->port, err);
 
        err = mdio_read(np, np->phy_addr, BCM8704_PHYXS_DEV_ADDR,
                        MII_NWAYTEST);
        if (err < 0)
                return err;
-       pr_info(PFX "Port %u PHYXS(MII_NWAYTEST) [%04x]\n",
-               np->port, err);
+       pr_info("Port %u PHYXS(MII_NWAYTEST) [%04x]\n", np->port, err);
 #endif
 
        /* XXX dig this out it might not be so useful XXX */
@@ -953,17 +1527,100 @@ static int xcvr_init_10g_bcm8704(struct niu *np)
 
        if (analog_stat0 != 0x03fc) {
                if ((analog_stat0 == 0x43bc) && (tx_alarm_status != 0)) {
-                       pr_info(PFX "Port %u cable not connected "
-                               "or bad cable.\n", np->port);
+                       pr_info("Port %u cable not connected or bad cable\n",
+                               np->port);
                } else if (analog_stat0 == 0x639c) {
-                       pr_info(PFX "Port %u optical module is bad "
-                               "or missing.\n", np->port);
+                       pr_info("Port %u optical module is bad or missing\n",
+                               np->port);
                }
        }
 
        return 0;
 }
 
+static int xcvr_10g_set_lb_bcm870x(struct niu *np)
+{
+       struct niu_link_config *lp = &np->link_config;
+       int err;
+
+       err = mdio_read(np, np->phy_addr, BCM8704_PCS_DEV_ADDR,
+                       MII_BMCR);
+       if (err < 0)
+               return err;
+
+       err &= ~BMCR_LOOPBACK;
+
+       if (lp->loopback_mode == LOOPBACK_MAC)
+               err |= BMCR_LOOPBACK;
+
+       err = mdio_write(np, np->phy_addr, BCM8704_PCS_DEV_ADDR,
+                        MII_BMCR, err);
+       if (err)
+               return err;
+
+       return 0;
+}
+
+static int xcvr_init_10g_bcm8706(struct niu *np)
+{
+       int err = 0;
+       u64 val;
+
+       if ((np->flags & NIU_FLAGS_HOTPLUG_PHY) &&
+           (np->flags & NIU_FLAGS_HOTPLUG_PHY_PRESENT) == 0)
+                       return err;
+
+       val = nr64_mac(XMAC_CONFIG);
+       val &= ~XMAC_CONFIG_LED_POLARITY;
+       val |= XMAC_CONFIG_FORCE_LED_ON;
+       nw64_mac(XMAC_CONFIG, val);
+
+       val = nr64(MIF_CONFIG);
+       val |= MIF_CONFIG_INDIRECT_MODE;
+       nw64(MIF_CONFIG, val);
+
+       err = bcm8704_reset(np);
+       if (err)
+               return err;
+
+       err = xcvr_10g_set_lb_bcm870x(np);
+       if (err)
+               return err;
+
+       err = bcm8706_init_user_dev3(np);
+       if (err)
+               return err;
+
+       err = xcvr_diag_bcm870x(np);
+       if (err)
+               return err;
+
+       return 0;
+}
+
+static int xcvr_init_10g_bcm8704(struct niu *np)
+{
+       int err;
+
+       err = bcm8704_reset(np);
+       if (err)
+               return err;
+
+       err = bcm8704_init_user_dev3(np);
+       if (err)
+               return err;
+
+       err = xcvr_10g_set_lb_bcm870x(np);
+       if (err)
+               return err;
+
+       err =  xcvr_diag_bcm870x(np);
+       if (err)
+               return err;
+
+       return 0;
+}
+
 static int xcvr_init_10g(struct niu *np)
 {
        int phy_id, err;
@@ -1014,14 +1671,74 @@ static int mii_reset(struct niu *np)
                        break;
        }
        if (limit < 0) {
-               dev_err(np->device, PFX "Port %u MII would not reset, "
-                       "bmcr[%04x]\n", np->port, err);
+               netdev_err(np->dev, "Port %u MII would not reset, bmcr[%04x]\n",
+                          np->port, err);
                return -ENODEV;
        }
 
        return 0;
 }
 
+static int xcvr_init_1g_rgmii(struct niu *np)
+{
+       int err;
+       u64 val;
+       u16 bmcr, bmsr, estat;
+
+       val = nr64(MIF_CONFIG);
+       val &= ~MIF_CONFIG_INDIRECT_MODE;
+       nw64(MIF_CONFIG, val);
+
+       err = mii_reset(np);
+       if (err)
+               return err;
+
+       err = mii_read(np, np->phy_addr, MII_BMSR);
+       if (err < 0)
+               return err;
+       bmsr = err;
+
+       estat = 0;
+       if (bmsr & BMSR_ESTATEN) {
+               err = mii_read(np, np->phy_addr, MII_ESTATUS);
+               if (err < 0)
+                       return err;
+               estat = err;
+       }
+
+       bmcr = 0;
+       err = mii_write(np, np->phy_addr, MII_BMCR, bmcr);
+       if (err)
+               return err;
+
+       if (bmsr & BMSR_ESTATEN) {
+               u16 ctrl1000 = 0;
+
+               if (estat & ESTATUS_1000_TFULL)
+                       ctrl1000 |= ADVERTISE_1000FULL;
+               err = mii_write(np, np->phy_addr, MII_CTRL1000, ctrl1000);
+               if (err)
+                       return err;
+       }
+
+       bmcr = (BMCR_SPEED1000 | BMCR_FULLDPLX);
+
+       err = mii_write(np, np->phy_addr, MII_BMCR, bmcr);
+       if (err)
+               return err;
+
+       err = mii_read(np, np->phy_addr, MII_BMCR);
+       if (err < 0)
+               return err;
+       bmcr = mii_read(np, np->phy_addr, MII_BMCR);
+
+       err = mii_read(np, np->phy_addr, MII_BMSR);
+       if (err < 0)
+               return err;
+
+       return 0;
+}
+
 static int mii_init_common(struct niu *np)
 {
        struct niu_link_config *lp = &np->link_config;
@@ -1068,40 +1785,89 @@ static int mii_init_common(struct niu *np)
                        return err;
        }
 
-       /* XXX configurable XXX */
-       /* XXX for now don't advertise half-duplex or asym pause... XXX */
-       adv = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP;
-       if (bmsr & BMSR_10FULL)
-               adv |= ADVERTISE_10FULL;
-       if (bmsr & BMSR_100FULL)
-               adv |= ADVERTISE_100FULL;
-       err = mii_write(np, np->phy_addr, MII_ADVERTISE, adv);
-       if (err)
-               return err;
-
-       if (bmsr & BMSR_ESTATEN) {
-               u16 ctrl1000 = 0;
-
-               if (estat & ESTATUS_1000_TFULL)
-                       ctrl1000 |= ADVERTISE_1000FULL;
-               err = mii_write(np, np->phy_addr, MII_CTRL1000, ctrl1000);
+       if (lp->autoneg) {
+               u16 ctrl1000;
+
+               adv = ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP;
+               if ((bmsr & BMSR_10HALF) &&
+                       (lp->advertising & ADVERTISED_10baseT_Half))
+                       adv |= ADVERTISE_10HALF;
+               if ((bmsr & BMSR_10FULL) &&
+                       (lp->advertising & ADVERTISED_10baseT_Full))
+                       adv |= ADVERTISE_10FULL;
+               if ((bmsr & BMSR_100HALF) &&
+                       (lp->advertising & ADVERTISED_100baseT_Half))
+                       adv |= ADVERTISE_100HALF;
+               if ((bmsr & BMSR_100FULL) &&
+                       (lp->advertising & ADVERTISED_100baseT_Full))
+                       adv |= ADVERTISE_100FULL;
+               err = mii_write(np, np->phy_addr, MII_ADVERTISE, adv);
                if (err)
                        return err;
+
+               if (likely(bmsr & BMSR_ESTATEN)) {
+                       ctrl1000 = 0;
+                       if ((estat & ESTATUS_1000_THALF) &&
+                               (lp->advertising & ADVERTISED_1000baseT_Half))
+                               ctrl1000 |= ADVERTISE_1000HALF;
+                       if ((estat & ESTATUS_1000_TFULL) &&
+                               (lp->advertising & ADVERTISED_1000baseT_Full))
+                               ctrl1000 |= ADVERTISE_1000FULL;
+                       err = mii_write(np, np->phy_addr,
+                                       MII_CTRL1000, ctrl1000);
+                       if (err)
+                               return err;
+               }
+
+               bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
+       } else {
+               /* !lp->autoneg */
+               int fulldpx;
+
+               if (lp->duplex == DUPLEX_FULL) {
+                       bmcr |= BMCR_FULLDPLX;
+                       fulldpx = 1;
+               } else if (lp->duplex == DUPLEX_HALF)
+                       fulldpx = 0;
+               else
+                       return -EINVAL;
+
+               if (lp->speed == SPEED_1000) {
+                       /* if X-full requested while not supported, or
+                          X-half requested while not supported... */
+                       if ((fulldpx && !(estat & ESTATUS_1000_TFULL)) ||
+                               (!fulldpx && !(estat & ESTATUS_1000_THALF)))
+                               return -EINVAL;
+                       bmcr |= BMCR_SPEED1000;
+               } else if (lp->speed == SPEED_100) {
+                       if ((fulldpx && !(bmsr & BMSR_100FULL)) ||
+                               (!fulldpx && !(bmsr & BMSR_100HALF)))
+                               return -EINVAL;
+                       bmcr |= BMCR_SPEED100;
+               } else if (lp->speed == SPEED_10) {
+                       if ((fulldpx && !(bmsr & BMSR_10FULL)) ||
+                               (!fulldpx && !(bmsr & BMSR_10HALF)))
+                               return -EINVAL;
+               } else
+                       return -EINVAL;
        }
-       bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
 
        err = mii_write(np, np->phy_addr, MII_BMCR, bmcr);
        if (err)
                return err;
 
+#if 0
        err = mii_read(np, np->phy_addr, MII_BMCR);
        if (err < 0)
                return err;
+       bmcr = err;
+
        err = mii_read(np, np->phy_addr, MII_BMSR);
        if (err < 0)
                return err;
-#if 0
-       pr_info(PFX "Port %u after MII init bmcr[%04x] bmsr[%04x]\n",
+       bmsr = err;
+
+       pr_info("Port %u after MII init bmcr[%04x] bmsr[%04x]\n",
                np->port, bmcr, bmsr);
 #endif
 
@@ -1154,16 +1920,12 @@ static int niu_link_status_common(struct niu *np, int link_up)
        unsigned long flags;
 
        if (!netif_carrier_ok(dev) && link_up) {
-               niuinfo(LINK, "%s: Link is up at %s, %s duplex\n",
-                      dev->name,
-                      (lp->active_speed == SPEED_10000 ?
-                       "10Gb/sec" :
-                       (lp->active_speed == SPEED_1000 ?
-                        "1Gb/sec" :
-                        (lp->active_speed == SPEED_100 ?
-                         "100Mbit/sec" : "10Mbit/sec"))),
-                      (lp->active_duplex == DUPLEX_FULL ?
-                       "full" : "half"));
+               netif_info(np, link, dev, "Link is up at %s, %s duplex\n",
+                          lp->active_speed == SPEED_10000 ? "10Gb/sec" :
+                          lp->active_speed == SPEED_1000 ? "1Gb/sec" :
+                          lp->active_speed == SPEED_100 ? "100Mbit/sec" :
+                          "10Mbit/sec",
+                          lp->active_duplex == DUPLEX_FULL ? "full" : "half");
 
                spin_lock_irqsave(&np->lock, flags);
                niu_init_xif(np);
@@ -1172,7 +1934,7 @@ static int niu_link_status_common(struct niu *np, int link_up)
 
                netif_carrier_on(dev);
        } else if (netif_carrier_ok(dev) && !link_up) {
-               niuwarn(LINK, "%s: Link is down\n", dev->name);
+               netif_warn(np, link, dev, "Link is down\n");
                spin_lock_irqsave(&np->lock, flags);
                niu_handle_led(np, 0);
                spin_unlock_irqrestore(&np->lock, flags);
@@ -1238,6 +2000,57 @@ out:
        return err;
 }
 
+static int link_status_10g_bcm8706(struct niu *np, int *link_up_p)
+{
+       int err, link_up;
+       link_up = 0;
+
+       err = mdio_read(np, np->phy_addr, BCM8704_PMA_PMD_DEV_ADDR,
+                       BCM8704_PMD_RCV_SIGDET);
+       if (err < 0 || err == 0xffff)
+               goto out;
+       if (!(err & PMD_RCV_SIGDET_GLOBAL)) {
+               err = 0;
+               goto out;
+       }
+
+       err = mdio_read(np, np->phy_addr, BCM8704_PCS_DEV_ADDR,
+                       BCM8704_PCS_10G_R_STATUS);
+       if (err < 0)
+               goto out;
+
+       if (!(err & PCS_10G_R_STATUS_BLK_LOCK)) {
+               err = 0;
+               goto out;
+       }
+
+       err = mdio_read(np, np->phy_addr, BCM8704_PHYXS_DEV_ADDR,
+                       BCM8704_PHYXS_XGXS_LANE_STAT);
+       if (err < 0)
+               goto out;
+       if (err != (PHYXS_XGXS_LANE_STAT_ALINGED |
+                   PHYXS_XGXS_LANE_STAT_MAGIC |
+                   PHYXS_XGXS_LANE_STAT_PATTEST |
+                   PHYXS_XGXS_LANE_STAT_LANE3 |
+                   PHYXS_XGXS_LANE_STAT_LANE2 |
+                   PHYXS_XGXS_LANE_STAT_LANE1 |
+                   PHYXS_XGXS_LANE_STAT_LANE0)) {
+               err = 0;
+               np->link_config.active_speed = SPEED_INVALID;
+               np->link_config.active_duplex = DUPLEX_INVALID;
+               goto out;
+       }
+
+       link_up = 1;
+       np->link_config.active_speed = SPEED_10000;
+       np->link_config.active_duplex = DUPLEX_FULL;
+       err = 0;
+
+out:
+       *link_up_p = link_up;
+       return err;
+}
+
 static int link_status_10g_bcom(struct niu *np, int *link_up_p)
 {
        int err, link_up;
@@ -1317,85 +2130,95 @@ static int link_status_10g(struct niu *np, int *link_up_p)
        return err;
 }
 
-static int link_status_1g(struct niu *np, int *link_up_p)
+static int niu_10g_phy_present(struct niu *np)
 {
-       struct niu_link_config *lp = &np->link_config;
-       u16 current_speed, bmsr;
-       unsigned long flags;
-       u8 current_duplex;
-       int err, link_up;
-
-       link_up = 0;
-       current_speed = SPEED_INVALID;
-       current_duplex = DUPLEX_INVALID;
-
-       spin_lock_irqsave(&np->lock, flags);
-
-       err = -EINVAL;
-       if (np->link_config.loopback_mode != LOOPBACK_DISABLED)
-               goto out;
+       u64 sig, mask, val;
 
-       err = mii_read(np, np->phy_addr, MII_BMSR);
-       if (err < 0)
-               goto out;
+       sig = nr64(ESR_INT_SIGNALS);
+       switch (np->port) {
+       case 0:
+               mask = ESR_INT_SIGNALS_P0_BITS;
+               val = (ESR_INT_SRDY0_P0 |
+                      ESR_INT_DET0_P0 |
+                      ESR_INT_XSRDY_P0 |
+                      ESR_INT_XDP_P0_CH3 |
+                      ESR_INT_XDP_P0_CH2 |
+                      ESR_INT_XDP_P0_CH1 |
+                      ESR_INT_XDP_P0_CH0);
+               break;
 
-       bmsr = err;
-       if (bmsr & BMSR_LSTATUS) {
-               u16 adv, lpa, common, estat;
+       case 1:
+               mask = ESR_INT_SIGNALS_P1_BITS;
+               val = (ESR_INT_SRDY0_P1 |
+                      ESR_INT_DET0_P1 |
+                      ESR_INT_XSRDY_P1 |
+                      ESR_INT_XDP_P1_CH3 |
+                      ESR_INT_XDP_P1_CH2 |
+                      ESR_INT_XDP_P1_CH1 |
+                      ESR_INT_XDP_P1_CH0);
+               break;
 
-               err = mii_read(np, np->phy_addr, MII_ADVERTISE);
-               if (err < 0)
-                       goto out;
-               adv = err;
+       default:
+               return 0;
+       }
 
-               err = mii_read(np, np->phy_addr, MII_LPA);
-               if (err < 0)
-                       goto out;
-               lpa = err;
+       if ((sig & mask) != val)
+               return 0;
+       return 1;
+}
 
-               common = adv & lpa;
+static int link_status_10g_hotplug(struct niu *np, int *link_up_p)
+{
+       unsigned long flags;
+       int err = 0;
+       int phy_present;
+       int phy_present_prev;
 
-               err = mii_read(np, np->phy_addr, MII_ESTATUS);
-               if (err < 0)
-                       goto out;
-               estat = err;
+       spin_lock_irqsave(&np->lock, flags);
 
-               link_up = 1;
-               if (estat & (ESTATUS_1000_TFULL | ESTATUS_1000_THALF)) {
-                       current_speed = SPEED_1000;
-                       if (estat & ESTATUS_1000_TFULL)
-                               current_duplex = DUPLEX_FULL;
-                       else
-                               current_duplex = DUPLEX_HALF;
-               } else {
-                       if (common & ADVERTISE_100BASE4) {
-                               current_speed = SPEED_100;
-                               current_duplex = DUPLEX_HALF;
-                       } else if (common & ADVERTISE_100FULL) {
-                               current_speed = SPEED_100;
-                               current_duplex = DUPLEX_FULL;
-                       } else if (common & ADVERTISE_100HALF) {
-                               current_speed = SPEED_100;
-                               current_duplex = DUPLEX_HALF;
-                       } else if (common & ADVERTISE_10FULL) {
-                               current_speed = SPEED_10;
-                               current_duplex = DUPLEX_FULL;
-                       } else if (common & ADVERTISE_10HALF) {
-                               current_speed = SPEED_10;
-                               current_duplex = DUPLEX_HALF;
-                       } else
-                               link_up = 0;
+       if (np->link_config.loopback_mode == LOOPBACK_DISABLED) {
+               phy_present_prev = (np->flags & NIU_FLAGS_HOTPLUG_PHY_PRESENT) ?
+                       1 : 0;
+               phy_present = niu_10g_phy_present(np);
+               if (phy_present != phy_present_prev) {
+                       /* state change */
+                       if (phy_present) {
+                               /* A NEM was just plugged in */
+                               np->flags |= NIU_FLAGS_HOTPLUG_PHY_PRESENT;
+                               if (np->phy_ops->xcvr_init)
+                                       err = np->phy_ops->xcvr_init(np);
+                               if (err) {
+                                       err = mdio_read(np, np->phy_addr,
+                                               BCM8704_PHYXS_DEV_ADDR, MII_BMCR);
+                                       if (err == 0xffff) {
+                                               /* No mdio, back-to-back XAUI */
+                                               goto out;
+                                       }
+                                       /* debounce */
+                                       np->flags &= ~NIU_FLAGS_HOTPLUG_PHY_PRESENT;
+                               }
+                       } else {
+                               np->flags &= ~NIU_FLAGS_HOTPLUG_PHY_PRESENT;
+                               *link_up_p = 0;
+                               netif_warn(np, link, np->dev,
+                                          "Hotplug PHY Removed\n");
+                       }
+               }
+out:
+               if (np->flags & NIU_FLAGS_HOTPLUG_PHY_PRESENT) {
+                       err = link_status_10g_bcm8706(np, link_up_p);
+                       if (err == 0xffff) {
+                               /* No mdio, back-to-back XAUI: it is C10NEM */
+                               *link_up_p = 1;
+                               np->link_config.active_speed = SPEED_10000;
+                               np->link_config.active_duplex = DUPLEX_FULL;
+                       }
                }
        }
-       lp->active_speed = current_speed;
-       lp->active_duplex = current_duplex;
-       err = 0;
 
-out:
        spin_unlock_irqrestore(&np->lock, flags);
 
-       *link_up_p = link_up;
-       return err;
+       return 0;
 }
 
 static int niu_link_status(struct niu *np, int *link_up_p)
@@ -1429,8 +2252,28 @@ static void niu_timer(unsigned long __opaque)
        add_timer(&np->timer);
 }
 
+static const struct niu_phy_ops phy_ops_10g_serdes = {
+       .serdes_init            = serdes_init_10g_serdes,
+       .link_status            = link_status_10g_serdes,
+};
+
+static const struct niu_phy_ops phy_ops_10g_serdes_niu = {
+       .serdes_init            = serdes_init_niu_10g_serdes,
+       .link_status            = link_status_10g_serdes,
+};
+
+static const struct niu_phy_ops phy_ops_1g_serdes_niu = {
+       .serdes_init            = serdes_init_niu_1g_serdes,
+       .link_status            = link_status_1g_serdes,
+};
+
+static const struct niu_phy_ops phy_ops_1g_rgmii = {
+       .xcvr_init              = xcvr_init_1g_rgmii,
+       .link_status            = link_status_1g_rgmii,
+};
+
 static const struct niu_phy_ops phy_ops_10g_fiber_niu = {
-       .serdes_init            = serdes_init_niu,
+       .serdes_init            = serdes_init_niu_10g_fiber,
        .xcvr_init              = xcvr_init_10g,
        .link_status            = link_status_10g,
 };
@@ -1441,6 +2284,18 @@ static const struct niu_phy_ops phy_ops_10g_fiber = {
        .link_status            = link_status_10g,
 };
 
+static const struct niu_phy_ops phy_ops_10g_fiber_hotplug = {
+       .serdes_init            = serdes_init_10g,
+       .xcvr_init              = xcvr_init_10g_bcm8706,
+       .link_status            = link_status_10g_hotplug,
+};
+
+static const struct niu_phy_ops phy_ops_niu_10g_hotplug = {
+       .serdes_init            = serdes_init_niu_10g_fiber,
+       .xcvr_init              = xcvr_init_10g_bcm8706,
+       .link_status            = link_status_10g_hotplug,
+};
+
 static const struct niu_phy_ops phy_ops_10g_copper = {
        .serdes_init            = serdes_init_10g,
        .link_status            = link_status_10g, /* XXX */
@@ -1462,16 +2317,36 @@ struct niu_phy_template {
        u32                             phy_addr_base;
 };
 
-static const struct niu_phy_template phy_template_niu = {
+static const struct niu_phy_template phy_template_niu_10g_fiber = {
        .ops            = &phy_ops_10g_fiber_niu,
        .phy_addr_base  = 16,
 };
 
+static const struct niu_phy_template phy_template_niu_10g_serdes = {
+       .ops            = &phy_ops_10g_serdes_niu,
+       .phy_addr_base  = 0,
+};
+
+static const struct niu_phy_template phy_template_niu_1g_serdes = {
+       .ops            = &phy_ops_1g_serdes_niu,
+       .phy_addr_base  = 0,
+};
+
 static const struct niu_phy_template phy_template_10g_fiber = {
        .ops            = &phy_ops_10g_fiber,
        .phy_addr_base  = 8,
 };
 
+static const struct niu_phy_template phy_template_10g_fiber_hotplug = {
+       .ops            = &phy_ops_10g_fiber_hotplug,
+       .phy_addr_base  = 8,
+};
+
+static const struct niu_phy_template phy_template_niu_10g_hotplug = {
+       .ops            = &phy_ops_niu_10g_hotplug,
+       .phy_addr_base  = 8,
+};
+
 static const struct niu_phy_template phy_template_10g_copper = {
        .ops            = &phy_ops_10g_copper,
        .phy_addr_base  = 10,
@@ -1487,6 +2362,152 @@ static const struct niu_phy_template phy_template_1g_copper = {
        .phy_addr_base  = 0,
 };
 
+static const struct niu_phy_template phy_template_1g_rgmii = {
+       .ops            = &phy_ops_1g_rgmii,
+       .phy_addr_base  = 0,
+};
+
+static const struct niu_phy_template phy_template_10g_serdes = {
+       .ops            = &phy_ops_10g_serdes,
+       .phy_addr_base  = 0,
+};
+
+static int niu_atca_port_num[4] = {
+       0, 0,  11, 10
+};
+
+static int serdes_init_10g_serdes(struct niu *np)
+{
+       struct niu_link_config *lp = &np->link_config;
+       unsigned long ctrl_reg, test_cfg_reg, pll_cfg, i;
+       u64 ctrl_val, test_cfg_val, sig, mask, val;
+       u64 reset_val;
+
+       switch (np->port) {
+       case 0:
+               reset_val =  ENET_SERDES_RESET_0;
+               ctrl_reg = ENET_SERDES_0_CTRL_CFG;
+               test_cfg_reg = ENET_SERDES_0_TEST_CFG;
+               pll_cfg = ENET_SERDES_0_PLL_CFG;
+               break;
+       case 1:
+               reset_val =  ENET_SERDES_RESET_1;
+               ctrl_reg = ENET_SERDES_1_CTRL_CFG;
+               test_cfg_reg = ENET_SERDES_1_TEST_CFG;
+               pll_cfg = ENET_SERDES_1_PLL_CFG;
+               break;
+
+       default:
+               return -EINVAL;
+       }
+       ctrl_val = (ENET_SERDES_CTRL_SDET_0 |
+                   ENET_SERDES_CTRL_SDET_1 |
+                   ENET_SERDES_CTRL_SDET_2 |
+                   ENET_SERDES_CTRL_SDET_3 |
+                   (0x5 << ENET_SERDES_CTRL_EMPH_0_SHIFT) |
+                   (0x5 << ENET_SERDES_CTRL_EMPH_1_SHIFT) |
+                   (0x5 << ENET_SERDES_CTRL_EMPH_2_SHIFT) |
+                   (0x5 << ENET_SERDES_CTRL_EMPH_3_SHIFT) |
+                   (0x1 << ENET_SERDES_CTRL_LADJ_0_SHIFT) |
+                   (0x1 << ENET_SERDES_CTRL_LADJ_1_SHIFT) |
+                   (0x1 << ENET_SERDES_CTRL_LADJ_2_SHIFT) |
+                   (0x1 << ENET_SERDES_CTRL_LADJ_3_SHIFT));
+       test_cfg_val = 0;
+
+       if (lp->loopback_mode == LOOPBACK_PHY) {
+               test_cfg_val |= ((ENET_TEST_MD_PAD_LOOPBACK <<
+                                 ENET_SERDES_TEST_MD_0_SHIFT) |
+                                (ENET_TEST_MD_PAD_LOOPBACK <<
+                                 ENET_SERDES_TEST_MD_1_SHIFT) |
+                                (ENET_TEST_MD_PAD_LOOPBACK <<
+                                 ENET_SERDES_TEST_MD_2_SHIFT) |
+                                (ENET_TEST_MD_PAD_LOOPBACK <<
+                                 ENET_SERDES_TEST_MD_3_SHIFT));
+       }
+
+       esr_reset(np);
+       nw64(pll_cfg, ENET_SERDES_PLL_FBDIV2);
+       nw64(ctrl_reg, ctrl_val);
+       nw64(test_cfg_reg, test_cfg_val);
+
+       /* Initialize all 4 lanes of the SERDES.  */
+       for (i = 0; i < 4; i++) {
+               u32 rxtx_ctrl, glue0;
+               int err;
+
+               err = esr_read_rxtx_ctrl(np, i, &rxtx_ctrl);
+               if (err)
+                       return err;
+               err = esr_read_glue0(np, i, &glue0);
+               if (err)
+                       return err;
+
+               rxtx_ctrl &= ~(ESR_RXTX_CTRL_VMUXLO);
+               rxtx_ctrl |= (ESR_RXTX_CTRL_ENSTRETCH |
+                             (2 << ESR_RXTX_CTRL_VMUXLO_SHIFT));
+
+               glue0 &= ~(ESR_GLUE_CTRL0_SRATE |
+                          ESR_GLUE_CTRL0_THCNT |
+                          ESR_GLUE_CTRL0_BLTIME);
+               glue0 |= (ESR_GLUE_CTRL0_RXLOSENAB |
+                         (0xf << ESR_GLUE_CTRL0_SRATE_SHIFT) |
+                         (0xff << ESR_GLUE_CTRL0_THCNT_SHIFT) |
+                         (BLTIME_300_CYCLES <<
+                          ESR_GLUE_CTRL0_BLTIME_SHIFT));
+
+               err = esr_write_rxtx_ctrl(np, i, rxtx_ctrl);
+               if (err)
+                       return err;
+               err = esr_write_glue0(np, i, glue0);
+               if (err)
+                       return err;
+       }
+
+
+       sig = nr64(ESR_INT_SIGNALS);
+       switch (np->port) {
+       case 0:
+               mask = ESR_INT_SIGNALS_P0_BITS;
+               val = (ESR_INT_SRDY0_P0 |
+                      ESR_INT_DET0_P0 |
+                      ESR_INT_XSRDY_P0 |
+                      ESR_INT_XDP_P0_CH3 |
+                      ESR_INT_XDP_P0_CH2 |
+                      ESR_INT_XDP_P0_CH1 |
+                      ESR_INT_XDP_P0_CH0);
+               break;
+
+       case 1:
+               mask = ESR_INT_SIGNALS_P1_BITS;
+               val = (ESR_INT_SRDY0_P1 |
+                      ESR_INT_DET0_P1 |
+                      ESR_INT_XSRDY_P1 |
+                      ESR_INT_XDP_P1_CH3 |
+                      ESR_INT_XDP_P1_CH2 |
+                      ESR_INT_XDP_P1_CH1 |
+                      ESR_INT_XDP_P1_CH0);
+               break;
+
+       default:
+               return -EINVAL;
+       }
+
+       if ((sig & mask) != val) {
+               int err;
+               err = serdes_init_1g_serdes(np);
+               if (!err) {
+                       np->flags &= ~NIU_FLAGS_10G;
+                       np->mac_xcvr = MAC_XCVR_PCS;
+               }  else {
+                       netdev_err(np->dev, "Port %u 10G/1G SERDES Link Failed\n",
+                                  np->port);
+                       return -ENODEV;
+               }
+       }
+
+       return 0;
+}
+
 static int niu_determine_phy_disposition(struct niu *np)
 {
        struct niu_parent *parent = np->parent;
@@ -1495,10 +2516,38 @@ static int niu_determine_phy_disposition(struct niu *np)
        u32 phy_addr_off = 0;
 
        if (plat_type == PLAT_TYPE_NIU) {
-               tp = &phy_template_niu;
-               phy_addr_off += np->port;
+               switch (np->flags &
+                       (NIU_FLAGS_10G |
+                        NIU_FLAGS_FIBER |
+                        NIU_FLAGS_XCVR_SERDES)) {
+               case NIU_FLAGS_10G | NIU_FLAGS_XCVR_SERDES:
+                       /* 10G Serdes */
+                       tp = &phy_template_niu_10g_serdes;
+                       break;
+               case NIU_FLAGS_XCVR_SERDES:
+                       /* 1G Serdes */
+                       tp = &phy_template_niu_1g_serdes;
+                       break;
+               case NIU_FLAGS_10G | NIU_FLAGS_FIBER:
+                       /* 10G Fiber */
+               default:
+                       if (np->flags & NIU_FLAGS_HOTPLUG_PHY) {
+                               tp = &phy_template_niu_10g_hotplug;
+                               if (np->port == 0)
+                                       phy_addr_off = 8;
+                               if (np->port == 1)
+                                       phy_addr_off = 12;
+                       } else {
+                               tp = &phy_template_niu_10g_fiber;
+                               phy_addr_off += np->port;
+                       }
+                       break;
+               }
        } else {
-               switch (np->flags & (NIU_FLAGS_10G | NIU_FLAGS_FIBER)) {
+               switch (np->flags &
+                       (NIU_FLAGS_10G |
+                        NIU_FLAGS_FIBER |
+                        NIU_FLAGS_XCVR_SERDES)) {
                case 0:
                        /* 1G copper */
                        tp = &phy_template_1g_copper;
@@ -1512,7 +2561,7 @@ static int niu_determine_phy_disposition(struct niu *np)
 
                case NIU_FLAGS_10G:
                        /* 10G copper */
-                       tp = &phy_template_1g_copper;
+                       tp = &phy_template_10g_copper;
                        break;
 
                case NIU_FLAGS_FIBER:
@@ -1527,6 +2576,32 @@ static int niu_determine_phy_disposition(struct niu *np)
                            plat_type == PLAT_TYPE_VF_P1)
                                phy_addr_off = 8;
                        phy_addr_off += np->port;
+                       if (np->flags & NIU_FLAGS_HOTPLUG_PHY) {
+                               tp = &phy_template_10g_fiber_hotplug;
+                               if (np->port == 0)
+                                       phy_addr_off = 8;
+                               if (np->port == 1)
+                                       phy_addr_off = 12;
+                       }
+                       break;
+
+               case NIU_FLAGS_10G | NIU_FLAGS_XCVR_SERDES:
+               case NIU_FLAGS_XCVR_SERDES | NIU_FLAGS_FIBER:
+               case NIU_FLAGS_XCVR_SERDES:
+                       switch(np->port) {
+                       case 0:
+                       case 1:
+                               tp = &phy_template_10g_serdes;
+                               break;
+                       case 2:
+                       case 3:
+                               tp = &phy_template_1g_rgmii;
+                               break;
+                       default:
+                               return -EINVAL;
+                               break;
+                       }
+                       phy_addr_off = niu_atca_port_num[np->port];
                        break;
 
                default:
@@ -1552,11 +2627,11 @@ static int niu_init_link(struct niu *np)
                msleep(200);
        }
        err = niu_serdes_init(np);
-       if (err)
+       if (err && !(np->flags & NIU_FLAGS_HOTPLUG_PHY))
                return err;
        msleep(200);
        err = niu_xcvr_init(np);
-       if (!err)
+       if (!err || (np->flags & NIU_FLAGS_HOTPLUG_PHY))
                niu_link_status(np, &ignore);
        return 0;
 }
@@ -1616,12 +2691,13 @@ static int niu_enable_alt_mac(struct niu *np, int index, int on)
        if (index >= niu_num_alt_addr(np))
                return -EINVAL;
 
-       if (np->flags & NIU_FLAGS_XMAC)
+       if (np->flags & NIU_FLAGS_XMAC) {
                reg = XMAC_ADDR_CMPEN;
-       else
+               mask = 1 << index;
+       } else {
                reg = BMAC_ADDR_CMPEN;
-
-       mask = 1 << index;
+               mask = 1 << (index + 1);
+       }
 
        val = nr64_mac(reg);
        if (on)
@@ -1736,7 +2812,7 @@ static int tcam_wait_bit(struct niu *np, u64 bit)
                        break;
                udelay(1);
        }
-       if (limit < 0)
+       if (limit <= 0)
                return -ENODEV;
 
        return 0;
@@ -1902,7 +2978,6 @@ static int tcam_user_ip_class_enable(struct niu *np, unsigned long class,
        return 0;
 }
 
-#if 0
 static int tcam_user_ip_class_set(struct niu *np, unsigned long class,
                                  int ipv6, u64 protocol_id,
                                  u64 tos_mask, u64 tos_val)
@@ -1930,7 +3005,6 @@ static int tcam_user_ip_class_set(struct niu *np, unsigned long class,
 
        return 0;
 }
-#endif
 
 static int tcam_early_init(struct niu *np)
 {
@@ -1969,8 +3043,7 @@ static int tcam_flush_all(struct niu *np)
 
 static u64 hash_addr_regval(unsigned long index, unsigned long num_entries)
 {
-       return ((u64)index | (num_entries == 1 ?
-                             HASH_TBL_ADDR_AUTOINC : 0));
+       return (u64)index | (num_entries == 1 ? HASH_TBL_ADDR_AUTOINC : 0);
 }
 
 #if 0
@@ -2128,23 +3201,22 @@ static int fflp_early_init(struct niu *np)
        parent = np->parent;
        err = 0;
        if (!(parent->flags & PARENT_FLGS_CLS_HWINIT)) {
-               niudbg(PROBE, "fflp_early_init: Initting hw on port %u\n",
-                      np->port);
                if (np->parent->plat_type != PLAT_TYPE_NIU) {
                        fflp_reset(np);
                        fflp_set_timings(np);
                        err = fflp_disable_all_partitions(np);
                        if (err) {
-                               niudbg(PROBE, "fflp_disable_all_partitions "
-                                      "failed, err=%d\n", err);
+                               netif_printk(np, probe, KERN_DEBUG, np->dev,
+                                            "fflp_disable_all_partitions failed, err=%d\n",
+                                            err);
                                goto out;
                        }
                }
 
                err = tcam_early_init(np);
                if (err) {
-                       niudbg(PROBE, "tcam_early_init failed, err=%d\n",
-                              err);
+                       netif_printk(np, probe, KERN_DEBUG, np->dev,
+                                    "tcam_early_init failed, err=%d\n", err);
                        goto out;
                }
                fflp_llcsnap_enable(np, 1);
@@ -2154,22 +3226,22 @@ static int fflp_early_init(struct niu *np)
 
                err = tcam_flush_all(np);
                if (err) {
-                       niudbg(PROBE, "tcam_flush_all failed, err=%d\n",
-                              err);
+                       netif_printk(np, probe, KERN_DEBUG, np->dev,
+                                    "tcam_flush_all failed, err=%d\n", err);
                        goto out;
                }
                if (np->parent->plat_type != PLAT_TYPE_NIU) {
                        err = fflp_hash_clear(np);
                        if (err) {
-                               niudbg(PROBE, "fflp_hash_clear failed, "
-                                      "err=%d\n", err);
+                               netif_printk(np, probe, KERN_DEBUG, np->dev,
+                                            "fflp_hash_clear failed, err=%d\n",
+                                            err);
                                goto out;
                        }
                }
 
                vlan_tbl_clear(np);
 
-               niudbg(PROBE, "fflp_early_init: Success\n");
                parent->flags |= PARENT_FLGS_CLS_HWINIT;
        }
 out:
@@ -2197,6 +3269,27 @@ static int niu_set_tcam_key(struct niu *np, unsigned long class_code, u64 key)
        return 0;
 }
 
+/* Entries for the ports are interleaved in the TCAM */
+static u16 tcam_get_index(struct niu *np, u16 idx)
+{
+       /* One entry reserved for IP fragment rule */
+       if (idx >= (np->clas.tcam_sz - 1))
+               idx = 0;
+       return np->clas.tcam_top + ((idx+1) * np->parent->num_ports);
+}
+
+static u16 tcam_get_size(struct niu *np)
+{
+       /* One entry reserved for IP fragment rule */
+       return np->clas.tcam_sz - 1;
+}
+
+static u16 tcam_get_valid_entry_cnt(struct niu *np)
+{
+       /* One entry reserved for IP fragment rule */
+       return np->clas.tcam_valid_entries - 1;
+}
+
 static void niu_rx_skb_append(struct sk_buff *skb, struct page *page,
                              u32 offset, u32 size)
 {
@@ -2219,7 +3312,7 @@ static unsigned int niu_hash_rxaddr(struct rx_ring_info *rp, u64 a)
        a >>= PAGE_SHIFT;
        a ^= (a >> ilog2(MAX_RBR_RING_SIZE));
 
-       return (a & (MAX_RBR_RING_SIZE - 1));
+       return a & (MAX_RBR_RING_SIZE - 1);
 }
 
 static struct page *niu_find_rxpage(struct rx_ring_info *rp, u64 addr,
@@ -2233,10 +3326,12 @@ static struct page *niu_find_rxpage(struct rx_ring_info *rp, u64 addr,
        for (; (p = *pp) != NULL; pp = (struct page **) &p->mapping) {
                if (p->index == addr) {
                        *link = pp;
-                       break;
+                       goto found;
                }
        }
+       BUG();
 
+found:
        return p;
 }
 
@@ -2343,9 +3438,11 @@ static int niu_rx_pkt_ignore(struct niu *np, struct rx_ring_info *rp)
        return num_rcr;
 }
 
-static int niu_process_rx_pkt(struct niu *np, struct rx_ring_info *rp)
+static int niu_process_rx_pkt(struct napi_struct *napi, struct niu *np,
+                             struct rx_ring_info *rp)
 {
        unsigned int index = rp->rcr_index;
+       struct rx_pkt_hdr1 *rh;
        struct sk_buff *skb;
        int len, num_rcr;
 
@@ -2379,9 +3476,6 @@ static int niu_process_rx_pkt(struct niu *np, struct rx_ring_info *rp)
                if (num_rcr == 1) {
                        int ptype;
 
-                       off += 2;
-                       append_size -= 2;
-
                        ptype = (val >> RCR_ENTRY_PKT_TYPE_SHIFT);
                        if ((ptype == RCR_PKT_TYPE_TCP ||
                             ptype == RCR_PKT_TYPE_UDP) &&
@@ -2389,9 +3483,8 @@ static int niu_process_rx_pkt(struct niu *np, struct rx_ring_info *rp)
                                     RCR_ENTRY_ERROR)))
                                skb->ip_summed = CHECKSUM_UNNECESSARY;
                        else
-                               skb->ip_summed = CHECKSUM_NONE;
-               }
-               if (!(val & RCR_ENTRY_MULTI))
+                               skb_checksum_none_assert(skb);
+               } else if (!(val & RCR_ENTRY_MULTI))
                        append_size = len - skb->len;
 
                niu_rx_skb_append(skb, page, off, append_size);
@@ -2412,16 +3505,24 @@ static int niu_process_rx_pkt(struct niu *np, struct rx_ring_info *rp)
        }
        rp->rcr_index = index;
 
-       skb_reserve(skb, NET_IP_ALIGN);
-       __pskb_pull_tail(skb, min(len, NIU_RXPULL_MAX));
+       len += sizeof(*rh);
+       len = min_t(int, len, sizeof(*rh) + VLAN_ETH_HLEN);
+       __pskb_pull_tail(skb, len);
+
+       rh = (struct rx_pkt_hdr1 *) skb->data;
+       if (np->dev->features & NETIF_F_RXHASH)
+               skb->rxhash = ((u32)rh->hashval2_0 << 24 |
+                              (u32)rh->hashval2_1 << 16 |
+                              (u32)rh->hashval1_1 << 8 |
+                              (u32)rh->hashval1_2 << 0);
+       skb_pull(skb, sizeof(*rh));
 
        rp->rx_packets++;
        rp->rx_bytes += skb->len;
 
        skb->protocol = eth_type_trans(skb, np->dev);
-       netif_receive_skb(skb);
-
-       np->dev->last_rx = jiffies;
+       skb_record_rx_queue(skb, rp->rx_channel);
+       napi_gro_receive(napi, skb);
 
        return num_rcr;
 }
@@ -2518,10 +3619,14 @@ static int release_tx_packet(struct niu *np, struct tx_ring_info *rp, int idx)
 
 static void niu_tx_work(struct niu *np, struct tx_ring_info *rp)
 {
+       struct netdev_queue *txq;
        u16 pkt_cnt, tmp;
-       int cons;
+       int cons, index;
        u64 cs;
 
+       index = (rp - np->tx_rings);
+       txq = netdev_get_tx_queue(np->dev, index);
+
        cs = rp->tx_cs;
        if (unlikely(!(cs & (TX_CS_MK | TX_CS_MMK))))
                goto out;
@@ -2534,8 +3639,8 @@ static void niu_tx_work(struct niu *np, struct tx_ring_info *rp)
 
        cons = rp->cons;
 
-       niudbg(TX_DONE, "%s: niu_tx_work() pkt_cnt[%u] cons[%d]\n",
-              np->dev->name, pkt_cnt, cons);
+       netif_printk(np, tx_done, KERN_DEBUG, np->dev,
+                    "%s() pkt_cnt[%u] cons[%d]\n", __func__, pkt_cnt, cons);
 
        while (pkt_cnt--)
                cons = release_tx_packet(np, rp, cons);
@@ -2544,17 +3649,70 @@ static void niu_tx_work(struct niu *np, struct tx_ring_info *rp)
        smp_mb();
 
 out:
-       if (unlikely(netif_queue_stopped(np->dev) &&
+       if (unlikely(netif_tx_queue_stopped(txq) &&
                     (niu_tx_avail(rp) > NIU_TX_WAKEUP_THRESH(rp)))) {
-               netif_tx_lock(np->dev);
-               if (netif_queue_stopped(np->dev) &&
+               __netif_tx_lock(txq, smp_processor_id());
+               if (netif_tx_queue_stopped(txq) &&
                    (niu_tx_avail(rp) > NIU_TX_WAKEUP_THRESH(rp)))
-                       netif_wake_queue(np->dev);
-               netif_tx_unlock(np->dev);
+                       netif_tx_wake_queue(txq);
+               __netif_tx_unlock(txq);
+       }
+}
+
+static inline void niu_sync_rx_discard_stats(struct niu *np,
+                                            struct rx_ring_info *rp,
+                                            const int limit)
+{
+       /* This elaborate scheme is needed for reading the RX discard
+        * counters, as they are only 16-bit and can overflow quickly,
+        * and because the overflow indication bit is not usable as
+        * the counter value does not wrap, but remains at max value
+        * 0xFFFF.
+        *
+        * In theory and in practice counters can be lost in between
+        * reading nr64() and clearing the counter nw64().  For this
+        * reason, the number of counter clearings nw64() is
+        * limited/reduced though the limit parameter.
+        */
+       int rx_channel = rp->rx_channel;
+       u32 misc, wred;
+
+       /* RXMISC (Receive Miscellaneous Discard Count), covers the
+        * following discard events: IPP (Input Port Process),
+        * FFLP/TCAM, Full RCR (Receive Completion Ring) RBR (Receive
+        * Block Ring) prefetch buffer is empty.
+        */
+       misc = nr64(RXMISC(rx_channel));
+       if (unlikely((misc & RXMISC_COUNT) > limit)) {
+               nw64(RXMISC(rx_channel), 0);
+               rp->rx_errors += misc & RXMISC_COUNT;
+
+               if (unlikely(misc & RXMISC_OFLOW))
+                       dev_err(np->device, "rx-%d: Counter overflow RXMISC discard\n",
+                               rx_channel);
+
+               netif_printk(np, rx_err, KERN_DEBUG, np->dev,
+                            "rx-%d: MISC drop=%u over=%u\n",
+                            rx_channel, misc, misc-limit);
+       }
+
+       /* WRED (Weighted Random Early Discard) by hardware */
+       wred = nr64(RED_DIS_CNT(rx_channel));
+       if (unlikely((wred & RED_DIS_CNT_COUNT) > limit)) {
+               nw64(RED_DIS_CNT(rx_channel), 0);
+               rp->rx_dropped += wred & RED_DIS_CNT_COUNT;
+
+               if (unlikely(wred & RED_DIS_CNT_OFLOW))
+                       dev_err(np->device, "rx-%d: Counter overflow WRED discard\n", rx_channel);
+
+               netif_printk(np, rx_err, KERN_DEBUG, np->dev,
+                            "rx-%d: WRED drop=%u over=%u\n",
+                            rx_channel, wred, wred-limit);
        }
 }
 
-static int niu_rx_work(struct niu *np, struct rx_ring_info *rp, int budget)
+static int niu_rx_work(struct napi_struct *napi, struct niu *np,
+                      struct rx_ring_info *rp, int budget)
 {
        int qlen, rcr_done = 0, work_done = 0;
        struct rxdma_mailbox *mbox = rp->mbox;
@@ -2570,13 +3728,14 @@ static int niu_rx_work(struct niu *np, struct rx_ring_info *rp, int budget)
        mbox->rx_dma_ctl_stat = 0;
        mbox->rcrstat_a = 0;
 
-       niudbg(RX_STATUS, "%s: niu_rx_work(chan[%d]), stat[%llx] qlen=%d\n",
-              np->dev->name, rp->rx_channel, (unsigned long long) stat, qlen);
+       netif_printk(np, rx_status, KERN_DEBUG, np->dev,
+                    "%s(chan[%d]), stat[%llx] qlen=%d\n",
+                    __func__, rp->rx_channel, (unsigned long long)stat, qlen);
 
        rcr_done = work_done = 0;
        qlen = min(qlen, budget);
        while (work_done < qlen) {
-               rcr_done += niu_process_rx_pkt(np, rp);
+               rcr_done += niu_process_rx_pkt(napi, np, rp);
                work_done++;
        }
 
@@ -2594,6 +3753,10 @@ static int niu_rx_work(struct niu *np, struct rx_ring_info *rp, int budget)
 
        nw64(RX_DMA_CTL_STAT(rp->rx_channel), stat);
 
+       /* Only sync discards stats when qlen indicate potential for drops */
+       if (qlen > 10)
+               niu_sync_rx_discard_stats(np, rp, 0x7FFF);
+
        return work_done;
 }
 
@@ -2604,8 +3767,8 @@ static int niu_poll_core(struct niu *np, struct niu_ldg *lp, int budget)
        u32 rx_vec = (v0 & 0xffffffff);
        int i, work_done = 0;
 
-       niudbg(INTR, "%s: niu_poll_core() v0[%016llx]\n",
-              np->dev->name, (unsigned long long) v0);
+       netif_printk(np, intr, KERN_DEBUG, np->dev,
+                    "%s() v0[%016llx]\n", __func__, (unsigned long long)v0);
 
        for (i = 0; i < np->num_tx_rings; i++) {
                struct tx_ring_info *rp = &np->tx_rings[i];
@@ -2620,7 +3783,7 @@ static int niu_poll_core(struct niu *np, struct niu_ldg *lp, int budget)
                if (rx_vec & (1 << rp->rx_channel)) {
                        int this_work_done;
 
-                       this_work_done = niu_rx_work(np, rp,
+                       this_work_done = niu_rx_work(&lp->napi, np, rp,
                                                     budget);
 
                        budget -= this_work_done;
@@ -2641,7 +3804,7 @@ static int niu_poll(struct napi_struct *napi, int budget)
        work_done = niu_poll_core(np, lp, budget);
 
        if (work_done < budget) {
-               netif_rx_complete(np->dev, napi);
+               napi_complete(napi);
                niu_ldg_rearm(np, lp, 1);
        }
        return work_done;
@@ -2650,39 +3813,38 @@ static int niu_poll(struct napi_struct *napi, int budget)
 static void niu_log_rxchan_errors(struct niu *np, struct rx_ring_info *rp,
                                  u64 stat)
 {
-       dev_err(np->device, PFX "%s: RX channel %u errors ( ",
-               np->dev->name, rp->rx_channel);
+       netdev_err(np->dev, "RX channel %u errors ( ", rp->rx_channel);
 
        if (stat & RX_DMA_CTL_STAT_RBR_TMOUT)
-               printk("RBR_TMOUT ");
+               pr_cont("RBR_TMOUT ");
        if (stat & RX_DMA_CTL_STAT_RSP_CNT_ERR)
-               printk("RSP_CNT ");
+               pr_cont("RSP_CNT ");
        if (stat & RX_DMA_CTL_STAT_BYTE_EN_BUS)
-               printk("BYTE_EN_BUS ");
+               pr_cont("BYTE_EN_BUS ");
        if (stat & RX_DMA_CTL_STAT_RSP_DAT_ERR)
-               printk("RSP_DAT ");
+               pr_cont("RSP_DAT ");
        if (stat & RX_DMA_CTL_STAT_RCR_ACK_ERR)
-               printk("RCR_ACK ");
+               pr_cont("RCR_ACK ");
        if (stat & RX_DMA_CTL_STAT_RCR_SHA_PAR)
-               printk("RCR_SHA_PAR ");
+               pr_cont("RCR_SHA_PAR ");
        if (stat & RX_DMA_CTL_STAT_RBR_PRE_PAR)
-               printk("RBR_PRE_PAR ");
+               pr_cont("RBR_PRE_PAR ");
        if (stat & RX_DMA_CTL_STAT_CONFIG_ERR)
-               printk("CONFIG ");
+               pr_cont("CONFIG ");
        if (stat & RX_DMA_CTL_STAT_RCRINCON)
-               printk("RCRINCON ");
+               pr_cont("RCRINCON ");
        if (stat & RX_DMA_CTL_STAT_RCRFULL)
-               printk("RCRFULL ");
+               pr_cont("RCRFULL ");
        if (stat & RX_DMA_CTL_STAT_RBRFULL)
-               printk("RBRFULL ");
+               pr_cont("RBRFULL ");
        if (stat & RX_DMA_CTL_STAT_RBRLOGPAGE)
-               printk("RBRLOGPAGE ");
+               pr_cont("RBRLOGPAGE ");
        if (stat & RX_DMA_CTL_STAT_CFIGLOGPAGE)
-               printk("CFIGLOGPAGE ");
+               pr_cont("CFIGLOGPAGE ");
        if (stat & RX_DMA_CTL_STAT_DC_FIFO_ERR)
-               printk("DC_FIDO ");
+               pr_cont("DC_FIDO ");
 
-       printk(")\n");
+       pr_cont(")\n");
 }
 
 static int niu_rx_error(struct niu *np, struct rx_ring_info *rp)
@@ -2696,9 +3858,9 @@ static int niu_rx_error(struct niu *np, struct rx_ring_info *rp)
                err = -EINVAL;
 
        if (err) {
-               dev_err(np->device, PFX "%s: RX channel %u error, stat[%llx]\n",
-                       np->dev->name, rp->rx_channel,
-                       (unsigned long long) stat);
+               netdev_err(np->dev, "RX channel %u error, stat[%llx]\n",
+                          rp->rx_channel,
+                          (unsigned long long) stat);
 
                niu_log_rxchan_errors(np, rp, stat);
        }
@@ -2712,27 +3874,26 @@ static int niu_rx_error(struct niu *np, struct rx_ring_info *rp)
 static void niu_log_txchan_errors(struct niu *np, struct tx_ring_info *rp,
                                  u64 cs)
 {
-       dev_err(np->device, PFX "%s: TX channel %u errors ( ",
-               np->dev->name, rp->tx_channel);
+       netdev_err(np->dev, "TX channel %u errors ( ", rp->tx_channel);
 
        if (cs & TX_CS_MBOX_ERR)
-               printk("MBOX ");
+               pr_cont("MBOX ");
        if (cs & TX_CS_PKT_SIZE_ERR)
-               printk("PKT_SIZE ");
+               pr_cont("PKT_SIZE ");
        if (cs & TX_CS_TX_RING_OFLOW)
-               printk("TX_RING_OFLOW ");
+               pr_cont("TX_RING_OFLOW ");
        if (cs & TX_CS_PREF_BUF_PAR_ERR)
-               printk("PREF_BUF_PAR ");
+               pr_cont("PREF_BUF_PAR ");
        if (cs & TX_CS_NACK_PREF)
-               printk("NACK_PREF ");
+               pr_cont("NACK_PREF ");
        if (cs & TX_CS_NACK_PKT_RD)
-               printk("NACK_PKT_RD ");
+               pr_cont("NACK_PKT_RD ");
        if (cs & TX_CS_CONF_PART_ERR)
-               printk("CONF_PART ");
+               pr_cont("CONF_PART ");
        if (cs & TX_CS_PKT_PRT_ERR)
-               printk("PKT_PTR ");
+               pr_cont("PKT_PTR ");
 
-       printk(")\n");
+       pr_cont(")\n");
 }
 
 static int niu_tx_error(struct niu *np, struct tx_ring_info *rp)
@@ -2743,12 +3904,11 @@ static int niu_tx_error(struct niu *np, struct tx_ring_info *rp)
        logh = nr64(TX_RNG_ERR_LOGH(rp->tx_channel));
        logl = nr64(TX_RNG_ERR_LOGL(rp->tx_channel));
 
-       dev_err(np->device, PFX "%s: TX channel %u error, "
-               "cs[%llx] logh[%llx] logl[%llx]\n",
-               np->dev->name, rp->tx_channel,
-               (unsigned long long) cs,
-               (unsigned long long) logh,
-               (unsigned long long) logl);
+       netdev_err(np->dev, "TX channel %u error, cs[%llx] logh[%llx] logl[%llx]\n",
+                  rp->tx_channel,
+                  (unsigned long long)cs,
+                  (unsigned long long)logh,
+                  (unsigned long long)logl);
 
        niu_log_txchan_errors(np, rp, cs);
 
@@ -2767,9 +3927,8 @@ static int niu_mif_interrupt(struct niu *np)
                        phy_mdint = 1;
        }
 
-       dev_err(np->device, PFX "%s: MIF interrupt, "
-               "stat[%llx] phy_mdint(%d)\n",
-               np->dev->name, (unsigned long long) mif_status, phy_mdint);
+       netdev_err(np->dev, "MIF interrupt, stat[%llx] phy_mdint(%d)\n",
+                  (unsigned long long)mif_status, phy_mdint);
 
        return -ENODEV;
 }
@@ -2824,7 +3983,7 @@ static void niu_xmac_interrupt(struct niu *np)
                mp->rx_hist_cnt6 += RXMAC_HIST_CNT6_COUNT;
        if (val & XRXMAC_STATUS_RXHIST7_CNT_EXP)
                mp->rx_hist_cnt7 += RXMAC_HIST_CNT7_COUNT;
-       if (val & XRXMAC_STAT_MSK_RXOCTET_CNT_EXP)
+       if (val & XRXMAC_STATUS_RXOCTET_CNT_EXP)
                mp->rx_octets += RXMAC_BT_CNT_COUNT;
        if (val & XRXMAC_STATUS_CVIOLERR_CNT_EXP)
                mp->rx_code_violations += RXMAC_CD_VIO_CNT_COUNT;
@@ -2894,41 +4053,40 @@ static int niu_mac_interrupt(struct niu *np)
 
 static void niu_log_device_error(struct niu *np, u64 stat)
 {
-       dev_err(np->device, PFX "%s: Core device errors ( ",
-               np->dev->name);
+       netdev_err(np->dev, "Core device errors ( ");
 
        if (stat & SYS_ERR_MASK_META2)
-               printk("META2 ");
+               pr_cont("META2 ");
        if (stat & SYS_ERR_MASK_META1)
-               printk("META1 ");
+               pr_cont("META1 ");
        if (stat & SYS_ERR_MASK_PEU)
-               printk("PEU ");
+               pr_cont("PEU ");
        if (stat & SYS_ERR_MASK_TXC)
-               printk("TXC ");
+               pr_cont("TXC ");
        if (stat & SYS_ERR_MASK_RDMC)
-               printk("RDMC ");
+               pr_cont("RDMC ");
        if (stat & SYS_ERR_MASK_TDMC)
-               printk("TDMC ");
+               pr_cont("TDMC ");
        if (stat & SYS_ERR_MASK_ZCP)
-               printk("ZCP ");
+               pr_cont("ZCP ");
        if (stat & SYS_ERR_MASK_FFLP)
-               printk("FFLP ");
+               pr_cont("FFLP ");
        if (stat & SYS_ERR_MASK_IPP)
-               printk("IPP ");
+               pr_cont("IPP ");
        if (stat & SYS_ERR_MASK_MAC)
-               printk("MAC ");
+               pr_cont("MAC ");
        if (stat & SYS_ERR_MASK_SMX)
-               printk("SMX ");
+               pr_cont("SMX ");
 
-       printk(")\n");
+       pr_cont(")\n");
 }
 
 static int niu_device_error(struct niu *np)
 {
        u64 stat = nr64(SYS_ERR_STAT);
 
-       dev_err(np->device, PFX "%s: Core device error, stat[%llx]\n",
-               np->dev->name, (unsigned long long) stat);
+       netdev_err(np->dev, "Core device error, stat[%llx]\n",
+                  (unsigned long long)stat);
 
        niu_log_device_error(np, stat);
 
@@ -3010,8 +4168,8 @@ static void niu_rxchan_intr(struct niu *np, struct rx_ring_info *rp,
                      RX_DMA_CTL_STAT_RCRTO);
        nw64(RX_DMA_CTL_STAT(rp->rx_channel), stat_write);
 
-       niudbg(INTR, "%s: rxchan_intr stat[%llx]\n",
-              np->dev->name, (unsigned long long) stat);
+       netif_printk(np, intr, KERN_DEBUG, np->dev,
+                    "%s() stat[%llx]\n", __func__, (unsigned long long)stat);
 }
 
 static void niu_txchan_intr(struct niu *np, struct tx_ring_info *rp,
@@ -3019,8 +4177,8 @@ static void niu_txchan_intr(struct niu *np, struct tx_ring_info *rp,
 {
        rp->tx_cs = nr64(TX_CS(rp->tx_channel));
 
-       niudbg(INTR, "%s: txchan_intr cs[%llx]\n",
-              np->dev->name, (unsigned long long) rp->tx_cs);
+       netif_printk(np, intr, KERN_DEBUG, np->dev,
+                    "%s() cs[%llx]\n", __func__, (unsigned long long)rp->tx_cs);
 }
 
 static void __niu_fastpath_interrupt(struct niu *np, int ldg, u64 v0)
@@ -3060,12 +4218,12 @@ static void __niu_fastpath_interrupt(struct niu *np, int ldg, u64 v0)
 static void niu_schedule_napi(struct niu *np, struct niu_ldg *lp,
                              u64 v0, u64 v1, u64 v2)
 {
-       if (likely(netif_rx_schedule_prep(np->dev, &lp->napi))) {
+       if (likely(napi_schedule_prep(&lp->napi))) {
                lp->v0 = v0;
                lp->v1 = v1;
                lp->v2 = v2;
                __niu_fastpath_interrupt(np, lp->ldg_num, v0);
-               __netif_rx_schedule(np->dev, &lp->napi);
+               __napi_schedule(&lp->napi);
        }
 }
 
@@ -3078,8 +4236,8 @@ static irqreturn_t niu_interrupt(int irq, void *dev_id)
        u64 v0, v1, v2;
 
        if (netif_msg_intr(np))
-               printk(KERN_DEBUG PFX "niu_interrupt() ldg[%p](%d) ",
-                      lp, ldg);
+               printk(KERN_DEBUG KBUILD_MODNAME ": " "%s() ldg[%p](%d)",
+                      __func__, lp, ldg);
 
        spin_lock_irqsave(&np->lock, flags);
 
@@ -3088,7 +4246,7 @@ static irqreturn_t niu_interrupt(int irq, void *dev_id)
        v2 = nr64(LDSV2(ldg));
 
        if (netif_msg_intr(np))
-               printk("v0[%llx] v1[%llx] v2[%llx]\n",
+               pr_cont(" v0[%llx] v1[%llx] v2[%llx]\n",
                       (unsigned long long) v0,
                       (unsigned long long) v1,
                       (unsigned long long) v2);
@@ -3213,8 +4371,8 @@ static int niu_alloc_rx_ring_info(struct niu *np,
        if (!rp->mbox)
                return -ENOMEM;
        if ((unsigned long)rp->mbox & (64UL - 1)) {
-               dev_err(np->device, PFX "%s: Coherent alloc gives misaligned "
-                       "RXDMA mailbox %p\n", np->dev->name, rp->mbox);
+               netdev_err(np->dev, "Coherent alloc gives misaligned RXDMA mailbox %p\n",
+                          rp->mbox);
                return -EINVAL;
        }
 
@@ -3224,8 +4382,8 @@ static int niu_alloc_rx_ring_info(struct niu *np,
        if (!rp->rcr)
                return -ENOMEM;
        if ((unsigned long)rp->rcr & (64UL - 1)) {
-               dev_err(np->device, PFX "%s: Coherent alloc gives misaligned "
-                       "RXDMA RCR table %p\n", np->dev->name, rp->rcr);
+               netdev_err(np->dev, "Coherent alloc gives misaligned RXDMA RCR table %p\n",
+                          rp->rcr);
                return -EINVAL;
        }
        rp->rcr_table_size = MAX_RCR_RING_SIZE;
@@ -3237,8 +4395,8 @@ static int niu_alloc_rx_ring_info(struct niu *np,
        if (!rp->rbr)
                return -ENOMEM;
        if ((unsigned long)rp->rbr & (64UL - 1)) {
-               dev_err(np->device, PFX "%s: Coherent alloc gives misaligned "
-                       "RXDMA RBR table %p\n", np->dev->name, rp->rbr);
+               netdev_err(np->dev, "Coherent alloc gives misaligned RXDMA RBR table %p\n",
+                          rp->rbr);
                return -EINVAL;
        }
        rp->rbr_table_size = MAX_RBR_RING_SIZE;
@@ -3271,8 +4429,8 @@ static int niu_alloc_tx_ring_info(struct niu *np,
        if (!rp->mbox)
                return -ENOMEM;
        if ((unsigned long)rp->mbox & (64UL - 1)) {
-               dev_err(np->device, PFX "%s: Coherent alloc gives misaligned "
-                       "TXDMA mailbox %p\n", np->dev->name, rp->mbox);
+               netdev_err(np->dev, "Coherent alloc gives misaligned TXDMA mailbox %p\n",
+                          rp->mbox);
                return -EINVAL;
        }
 
@@ -3282,8 +4440,8 @@ static int niu_alloc_tx_ring_info(struct niu *np,
        if (!rp->descr)
                return -ENOMEM;
        if ((unsigned long)rp->descr & (64UL - 1)) {
-               dev_err(np->device, PFX "%s: Coherent alloc gives misaligned "
-                       "TXDMA descr table %p\n", np->dev->name, rp->descr);
+               netdev_err(np->dev, "Coherent alloc gives misaligned TXDMA descr table %p\n",
+                          rp->descr);
                return -EINVAL;
        }
 
@@ -3331,6 +4489,9 @@ static int niu_alloc_channels(struct niu *np)
 {
        struct niu_parent *parent = np->parent;
        int first_rx_channel, first_tx_channel;
+       int num_rx_rings, num_tx_rings;
+       struct rx_ring_info *rx_rings;
+       struct tx_ring_info *tx_rings;
        int i, port, err;
 
        port = np->port;
@@ -3340,15 +4501,21 @@ static int niu_alloc_channels(struct niu *np)
                first_tx_channel += parent->txchan_per_port[i];
        }
 
-       np->num_rx_rings = parent->rxchan_per_port[port];
-       np->num_tx_rings = parent->txchan_per_port[port];
+       num_rx_rings = parent->rxchan_per_port[port];
+       num_tx_rings = parent->txchan_per_port[port];
 
-       np->rx_rings = kzalloc(np->num_rx_rings * sizeof(struct rx_ring_info),
-                              GFP_KERNEL);
+       rx_rings = kcalloc(num_rx_rings, sizeof(struct rx_ring_info),
+                          GFP_KERNEL);
        err = -ENOMEM;
-       if (!np->rx_rings)
+       if (!rx_rings)
                goto out_err;
 
+       np->num_rx_rings = num_rx_rings;
+       smp_wmb();
+       np->rx_rings = rx_rings;
+
+       netif_set_real_num_rx_queues(np->dev, num_rx_rings);
+
        for (i = 0; i < np->num_rx_rings; i++) {
                struct rx_ring_info *rp = &np->rx_rings[i];
 
@@ -3377,12 +4544,18 @@ static int niu_alloc_channels(struct niu *np)
                        return err;
        }
 
-       np->tx_rings = kzalloc(np->num_tx_rings * sizeof(struct tx_ring_info),
-                              GFP_KERNEL);
+       tx_rings = kcalloc(num_tx_rings, sizeof(struct tx_ring_info),
+                          GFP_KERNEL);
        err = -ENOMEM;
-       if (!np->tx_rings)
+       if (!tx_rings)
                goto out_err;
 
+       np->num_tx_rings = num_tx_rings;
+       smp_wmb();
+       np->tx_rings = tx_rings;
+
+       netif_set_real_num_tx_queues(np->dev, num_tx_rings);
+
        for (i = 0; i < np->num_tx_rings; i++) {
                struct tx_ring_info *rp = &np->tx_rings[i];
 
@@ -3537,10 +4710,8 @@ static int niu_init_one_tx_channel(struct niu *np, struct tx_ring_info *rp)
 
        if (rp->descr_dma & ~(TX_RNG_CFIG_STADDR_BASE |
                              TX_RNG_CFIG_STADDR)) {
-               dev_err(np->device, PFX "%s: TX ring channel %d "
-                       "DMA addr (%llx) is not aligned.\n",
-                       np->dev->name, channel,
-                       (unsigned long long) rp->descr_dma);
+               netdev_err(np->dev, "TX ring channel %d DMA addr (%llx) is not aligned\n",
+                          channel, (unsigned long long)rp->descr_dma);
                return -EINVAL;
        }
 
@@ -3557,10 +4728,8 @@ static int niu_init_one_tx_channel(struct niu *np, struct tx_ring_info *rp)
 
        if (((rp->mbox_dma >> 32) & ~TXDMA_MBH_MBADDR) ||
            ((u32)rp->mbox_dma & ~TXDMA_MBL_MBADDR)) {
-               dev_err(np->device, PFX "%s: TX ring channel %d "
-                       "MBOX addr (%llx) is has illegal bits.\n",
-                       np->dev->name, channel,
-                       (unsigned long long) rp->mbox_dma);
+               netdev_err(np->dev, "TX ring channel %d MBOX addr (%llx) has invalid bits\n",
+                           channel, (unsigned long long)rp->mbox_dma);
                return -EINVAL;
        }
        nw64(TXDMA_MBH(channel), rp->mbox_dma >> 32);
@@ -3674,6 +4843,7 @@ static int niu_compute_rbr_cfig_b(struct rx_ring_info *rp, u64 *ret)
 {
        u64 val = 0;
 
+       *ret = 0;
        switch (rp->rbr_block_size) {
        case 4 * 1024:
                val |= (RBR_BLKSIZE_4K << RBR_CFIG_B_BLKSIZE_SHIFT);
@@ -3793,7 +4963,9 @@ static int niu_init_one_rx_channel(struct niu *np, struct rx_ring_info *rp)
              RX_DMA_CTL_STAT_RCRTO |
              RX_DMA_CTL_STAT_RBR_EMPTY));
        nw64(RXDMA_CFIG1(channel), rp->mbox_dma >> 32);
-       nw64(RXDMA_CFIG2(channel), (rp->mbox_dma & 0x00000000ffffffc0));
+       nw64(RXDMA_CFIG2(channel),
+            ((rp->mbox_dma & RXDMA_CFIG2_MBADDR_L) |
+             RXDMA_CFIG2_FULL_HDR));
        nw64(RBR_CFIG_A(channel),
             ((u64)rp->rbr_table_size << RBR_CFIG_A_LEN_SHIFT) |
             (rp->rbr_dma & (RBR_CFIG_A_STADDR_BASE | RBR_CFIG_A_STADDR)));
@@ -3860,8 +5032,7 @@ static int niu_set_ip_frag_rule(struct niu *np)
        struct niu_tcam_entry *tp;
        int index, err;
 
-       /* XXX fix this allocation scheme XXX */
-       index = cp->tcam_index;
+       index = cp->tcam_top;
        tp = &parent->tcam[index];
 
        /* Note that the noport bit is the same in both ipv4 and
@@ -3878,6 +5049,8 @@ static int niu_set_ip_frag_rule(struct niu *np)
        err = tcam_assoc_write(np, index, tp->assoc_data);
        if (err)
                return err;
+       tp->valid = 1;
+       cp->tcam_valid_entries++;
 
        return 0;
 }
@@ -3955,9 +5128,8 @@ static int niu_zcp_read(struct niu *np, int index, u64 *data)
        err = niu_wait_bits_clear(np, ZCP_RAM_ACC, ZCP_RAM_ACC_BUSY,
                                  1000, 100);
        if (err) {
-               dev_err(np->device, PFX "%s: ZCP read busy won't clear, "
-                       "ZCP_RAM_ACC[%llx]\n", np->dev->name,
-                       (unsigned long long) nr64(ZCP_RAM_ACC));
+               netdev_err(np->dev, "ZCP read busy won't clear, ZCP_RAM_ACC[%llx]\n",
+                          (unsigned long long)nr64(ZCP_RAM_ACC));
                return err;
        }
 
@@ -3969,9 +5141,8 @@ static int niu_zcp_read(struct niu *np, int index, u64 *data)
        err = niu_wait_bits_clear(np, ZCP_RAM_ACC, ZCP_RAM_ACC_BUSY,
                                  1000, 100);
        if (err) {
-               dev_err(np->device, PFX "%s: ZCP read busy2 won't clear, "
-                       "ZCP_RAM_ACC[%llx]\n", np->dev->name,
-                       (unsigned long long) nr64(ZCP_RAM_ACC));
+               netdev_err(np->dev, "ZCP read busy2 won't clear, ZCP_RAM_ACC[%llx]\n",
+                          (unsigned long long)nr64(ZCP_RAM_ACC));
                return err;
        }
 
@@ -4138,6 +5309,12 @@ static void niu_init_xif_xmac(struct niu *np)
        struct niu_link_config *lp = &np->link_config;
        u64 val;
 
+       if (np->flags & NIU_FLAGS_XCVR_SERDES) {
+               val = nr64(MIF_CONFIG);
+               val |= MIF_CONFIG_ATCA_GE;
+               nw64(MIF_CONFIG, val);
+       }
+
        val = nr64_mac(XMAC_CONFIG);
        val &= ~XMAC_CONFIG_SEL_POR_CLK_SRC;
 
@@ -4154,7 +5331,8 @@ static void niu_init_xif_xmac(struct niu *np)
                val &= ~XMAC_CONFIG_LFS_DISABLE;
        } else {
                val |= XMAC_CONFIG_LFS_DISABLE;
-               if (!(np->flags & NIU_FLAGS_FIBER))
+               if (!(np->flags & NIU_FLAGS_FIBER) &&
+                   !(np->flags & NIU_FLAGS_XCVR_SERDES))
                        val |= XMAC_CONFIG_1G_PCS_BYPASS;
                else
                        val &= ~XMAC_CONFIG_1G_PCS_BYPASS;
@@ -4174,10 +5352,10 @@ static void niu_init_xif_xmac(struct niu *np)
        if (np->flags & NIU_FLAGS_10G) {
                val |= XMAC_CONFIG_MODE_XGMII;
        } else {
-               if (lp->active_speed == SPEED_100)
-                       val |= XMAC_CONFIG_MODE_MII;
-               else
+               if (lp->active_speed == SPEED_1000)
                        val |= XMAC_CONFIG_MODE_GMII;
+               else
+                       val |= XMAC_CONFIG_MODE_MII;
        }
 
        nw64_mac(XMAC_CONFIG, val);
@@ -4223,16 +5401,26 @@ static void niu_init_xif(struct niu *np)
 
 static void niu_pcs_mii_reset(struct niu *np)
 {
+       int limit = 1000;
        u64 val = nr64_pcs(PCS_MII_CTL);
        val |= PCS_MII_CTL_RST;
        nw64_pcs(PCS_MII_CTL, val);
+       while ((--limit >= 0) && (val & PCS_MII_CTL_RST)) {
+               udelay(100);
+               val = nr64_pcs(PCS_MII_CTL);
+       }
 }
 
 static void niu_xpcs_reset(struct niu *np)
 {
+       int limit = 1000;
        u64 val = nr64_xpcs(XPCS_CONTROL1);
        val |= XPCS_CONTROL1_RESET;
        nw64_xpcs(XPCS_CONTROL1, val);
+       while ((--limit >= 0) && (val & XPCS_CONTROL1_RESET)) {
+               udelay(100);
+               val = nr64_xpcs(XPCS_CONTROL1);
+       }
 }
 
 static int niu_init_pcs(struct niu *np)
@@ -4240,7 +5428,9 @@ static int niu_init_pcs(struct niu *np)
        struct niu_link_config *lp = &np->link_config;
        u64 val;
 
-       switch (np->flags & (NIU_FLAGS_10G | NIU_FLAGS_FIBER)) {
+       switch (np->flags & (NIU_FLAGS_10G |
+                            NIU_FLAGS_FIBER |
+                            NIU_FLAGS_XCVR_SERDES)) {
        case NIU_FLAGS_FIBER:
                /* 1G fiber */
                nw64_pcs(PCS_CONF, PCS_CONF_MASK | PCS_CONF_ENABLE);
@@ -4250,6 +5440,8 @@ static int niu_init_pcs(struct niu *np)
 
        case NIU_FLAGS_10G:
        case NIU_FLAGS_10G | NIU_FLAGS_FIBER:
+       case NIU_FLAGS_10G | NIU_FLAGS_XCVR_SERDES:
+               /* 10G SERDES */
                if (!(np->flags & NIU_FLAGS_XMAC))
                        return -EINVAL;
 
@@ -4272,8 +5464,18 @@ static int niu_init_pcs(struct niu *np)
                (void) nr64_xpcs(XPCS_SYMERR_CNT23);
                break;
 
+
+       case NIU_FLAGS_XCVR_SERDES:
+               /* 1G SERDES */
+               niu_pcs_mii_reset(np);
+               nw64_pcs(PCS_CONF, PCS_CONF_MASK | PCS_CONF_ENABLE);
+               nw64_pcs(PCS_DPATH_MODE, 0);
+               break;
+
        case 0:
                /* 1G copper */
+       case NIU_FLAGS_XCVR_SERDES | NIU_FLAGS_FIBER:
+               /* 1G RGMII FIBER */
                nw64_pcs(PCS_DPATH_MODE, PCS_DPATH_MODE_MII);
                niu_pcs_mii_reset(np);
                break;
@@ -4305,8 +5507,7 @@ static int niu_reset_tx_bmac(struct niu *np)
                udelay(100);
        }
        if (limit < 0) {
-               dev_err(np->device, PFX "Port %u TX BMAC would not reset, "
-                       "BTXMAC_SW_RST[%llx]\n",
+               dev_err(np->device, "Port %u TX BMAC would not reset, BTXMAC_SW_RST[%llx]\n",
                        np->port,
                        (unsigned long long) nr64_mac(BTXMAC_SW_RST));
                return -ENODEV;
@@ -4389,7 +5590,7 @@ static void niu_init_tx_mac(struct niu *np)
        /* The XMAC_MIN register only accepts values for TX min which
         * have the low 3 bits cleared.
         */
-       BUILD_BUG_ON(min & 0x7);
+       BUG_ON(min & 0x7);
 
        if (np->flags & NIU_FLAGS_XMAC)
                niu_init_tx_xmac(np, min, max);
@@ -4407,12 +5608,11 @@ static int niu_reset_rx_xmac(struct niu *np)
        while (--limit >= 0) {
                if (!(nr64_mac(XRXMAC_SW_RST) & (XRXMAC_SW_RST_REG_RS |
                                                 XRXMAC_SW_RST_SOFT_RST)))
-                   break;
+                       break;
                udelay(100);
        }
        if (limit < 0) {
-               dev_err(np->device, PFX "Port %u RX XMAC would not reset, "
-                       "XRXMAC_SW_RST[%llx]\n",
+               dev_err(np->device, "Port %u RX XMAC would not reset, XRXMAC_SW_RST[%llx]\n",
                        np->port,
                        (unsigned long long) nr64_mac(XRXMAC_SW_RST));
                return -ENODEV;
@@ -4433,8 +5633,7 @@ static int niu_reset_rx_bmac(struct niu *np)
                udelay(100);
        }
        if (limit < 0) {
-               dev_err(np->device, PFX "Port %u RX BMAC would not reset, "
-                       "BRXMAC_SW_RST[%llx]\n",
+               dev_err(np->device, "Port %u RX BMAC would not reset, BRXMAC_SW_RST[%llx]\n",
                        np->port,
                        (unsigned long long) nr64_mac(BRXMAC_SW_RST));
                return -ENODEV;
@@ -4738,11 +5937,9 @@ static void niu_disable_ipp(struct niu *np)
        }
        if (limit < 0 &&
            (rd != 0 && wr != 1)) {
-               dev_err(np->device, PFX "%s: IPP would not quiesce, "
-                       "rd_ptr[%llx] wr_ptr[%llx]\n",
-                       np->dev->name,
-                       (unsigned long long) nr64_ipp(IPP_DFIFO_RD_PTR),
-                       (unsigned long long) nr64_ipp(IPP_DFIFO_WR_PTR));
+               netdev_err(np->dev, "IPP would not quiesce, rd_ptr[%llx] wr_ptr[%llx]\n",
+                          (unsigned long long)nr64_ipp(IPP_DFIFO_RD_PTR),
+                          (unsigned long long)nr64_ipp(IPP_DFIFO_WR_PTR));
        }
 
        val = nr64_ipp(IPP_CFIG);
@@ -4759,12 +5956,12 @@ static int niu_init_hw(struct niu *np)
 {
        int i, err;
 
-       niudbg(IFUP, "%s: Initialize TXC\n", np->dev->name);
+       netif_printk(np, ifup, KERN_DEBUG, np->dev, "Initialize TXC\n");
        niu_txc_enable_port(np, 1);
        niu_txc_port_dma_enable(np, 1);
        niu_txc_set_imask(np, 0);
 
-       niudbg(IFUP, "%s: Initialize TX channels\n", np->dev->name);
+       netif_printk(np, ifup, KERN_DEBUG, np->dev, "Initialize TX channels\n");
        for (i = 0; i < np->num_tx_rings; i++) {
                struct tx_ring_info *rp = &np->tx_rings[i];
 
@@ -4773,27 +5970,27 @@ static int niu_init_hw(struct niu *np)
                        return err;
        }
 
-       niudbg(IFUP, "%s: Initialize RX channels\n", np->dev->name);
+       netif_printk(np, ifup, KERN_DEBUG, np->dev, "Initialize RX channels\n");
        err = niu_init_rx_channels(np);
        if (err)
                goto out_uninit_tx_channels;
 
-       niudbg(IFUP, "%s: Initialize classifier\n", np->dev->name);
+       netif_printk(np, ifup, KERN_DEBUG, np->dev, "Initialize classifier\n");
        err = niu_init_classifier_hw(np);
        if (err)
                goto out_uninit_rx_channels;
 
-       niudbg(IFUP, "%s: Initialize ZCP\n", np->dev->name);
+       netif_printk(np, ifup, KERN_DEBUG, np->dev, "Initialize ZCP\n");
        err = niu_init_zcp(np);
        if (err)
                goto out_uninit_rx_channels;
 
-       niudbg(IFUP, "%s: Initialize IPP\n", np->dev->name);
+       netif_printk(np, ifup, KERN_DEBUG, np->dev, "Initialize IPP\n");
        err = niu_init_ipp(np);
        if (err)
                goto out_uninit_rx_channels;
 
-       niudbg(IFUP, "%s: Initialize MAC\n", np->dev->name);
+       netif_printk(np, ifup, KERN_DEBUG, np->dev, "Initialize MAC\n");
        err = niu_init_mac(np);
        if (err)
                goto out_uninit_ipp;
@@ -4801,16 +5998,16 @@ static int niu_init_hw(struct niu *np)
        return 0;
 
 out_uninit_ipp:
-       niudbg(IFUP, "%s: Uninit IPP\n", np->dev->name);
+       netif_printk(np, ifup, KERN_DEBUG, np->dev, "Uninit IPP\n");
        niu_disable_ipp(np);
 
 out_uninit_rx_channels:
-       niudbg(IFUP, "%s: Uninit RX channels\n", np->dev->name);
+       netif_printk(np, ifup, KERN_DEBUG, np->dev, "Uninit RX channels\n");
        niu_stop_rx_channels(np);
        niu_reset_rx_channels(np);
 
 out_uninit_tx_channels:
-       niudbg(IFUP, "%s: Uninit TX channels\n", np->dev->name);
+       netif_printk(np, ifup, KERN_DEBUG, np->dev, "Uninit TX channels\n");
        niu_stop_tx_channels(np);
        niu_reset_tx_channels(np);
 
@@ -4819,39 +6016,64 @@ out_uninit_tx_channels:
 
 static void niu_stop_hw(struct niu *np)
 {
-       niudbg(IFDOWN, "%s: Disable interrupts\n", np->dev->name);
+       netif_printk(np, ifdown, KERN_DEBUG, np->dev, "Disable interrupts\n");
        niu_enable_interrupts(np, 0);
 
-       niudbg(IFDOWN, "%s: Disable RX MAC\n", np->dev->name);
+       netif_printk(np, ifdown, KERN_DEBUG, np->dev, "Disable RX MAC\n");
        niu_enable_rx_mac(np, 0);
 
-       niudbg(IFDOWN, "%s: Disable IPP\n", np->dev->name);
+       netif_printk(np, ifdown, KERN_DEBUG, np->dev, "Disable IPP\n");
        niu_disable_ipp(np);
 
-       niudbg(IFDOWN, "%s: Stop TX channels\n", np->dev->name);
+       netif_printk(np, ifdown, KERN_DEBUG, np->dev, "Stop TX channels\n");
        niu_stop_tx_channels(np);
 
-       niudbg(IFDOWN, "%s: Stop RX channels\n", np->dev->name);
+       netif_printk(np, ifdown, KERN_DEBUG, np->dev, "Stop RX channels\n");
        niu_stop_rx_channels(np);
 
-       niudbg(IFDOWN, "%s: Reset TX channels\n", np->dev->name);
+       netif_printk(np, ifdown, KERN_DEBUG, np->dev, "Reset TX channels\n");
        niu_reset_tx_channels(np);
 
-       niudbg(IFDOWN, "%s: Reset RX channels\n", np->dev->name);
+       netif_printk(np, ifdown, KERN_DEBUG, np->dev, "Reset RX channels\n");
        niu_reset_rx_channels(np);
 }
 
+static void niu_set_irq_name(struct niu *np)
+{
+       int port = np->port;
+       int i, j = 1;
+
+       sprintf(np->irq_name[0], "%s:MAC", np->dev->name);
+
+       if (port == 0) {
+               sprintf(np->irq_name[1], "%s:MIF", np->dev->name);
+               sprintf(np->irq_name[2], "%s:SYSERR", np->dev->name);
+               j = 3;
+       }
+
+       for (i = 0; i < np->num_ldg - j; i++) {
+               if (i < np->num_rx_rings)
+                       sprintf(np->irq_name[i+j], "%s-rx-%d",
+                               np->dev->name, i);
+               else if (i < np->num_tx_rings + np->num_rx_rings)
+                       sprintf(np->irq_name[i+j], "%s-tx-%d", np->dev->name,
+                               i - np->num_rx_rings);
+       }
+}
+
 static int niu_request_irq(struct niu *np)
 {
        int i, j, err;
 
+       niu_set_irq_name(np);
+
        err = 0;
        for (i = 0; i < np->num_ldg; i++) {
                struct niu_ldg *lp = &np->ldg[i];
 
                err = request_irq(lp->irq, niu_interrupt,
                                  IRQF_SHARED | IRQF_SAMPLE_RANDOM,
-                                 np->dev->name, lp);
+                                 np->irq_name[i], lp);
                if (err)
                        goto out_free_irqs;
 
@@ -4937,7 +6159,7 @@ static int niu_open(struct net_device *dev)
                goto out_free_irq;
        }
 
-       netif_start_queue(dev);
+       netif_tx_start_all_queues(dev);
 
        if (np->link_config.loopback_mode != LOOPBACK_DISABLED)
                netif_carrier_on(dev);
@@ -4961,7 +6183,7 @@ static void niu_full_shutdown(struct niu *np, struct net_device *dev)
        cancel_work_sync(&np->reset_task);
 
        niu_disable_napi(np);
-       netif_stop_queue(dev);
+       netif_tx_stop_all_queues(dev);
 
        del_timer_sync(&np->timer);
 
@@ -5036,49 +6258,68 @@ static void niu_sync_mac_stats(struct niu *np)
 static void niu_get_rx_stats(struct niu *np)
 {
        unsigned long pkts, dropped, errors, bytes;
+       struct rx_ring_info *rx_rings;
        int i;
 
        pkts = dropped = errors = bytes = 0;
+
+       rx_rings = ACCESS_ONCE(np->rx_rings);
+       if (!rx_rings)
+               goto no_rings;
+
        for (i = 0; i < np->num_rx_rings; i++) {
-               struct rx_ring_info *rp = &np->rx_rings[i];
+               struct rx_ring_info *rp = &rx_rings[i];
+
+               niu_sync_rx_discard_stats(np, rp, 0);
 
                pkts += rp->rx_packets;
                bytes += rp->rx_bytes;
                dropped += rp->rx_dropped;
                errors += rp->rx_errors;
        }
-       np->net_stats.rx_packets = pkts;
-       np->net_stats.rx_bytes = bytes;
-       np->net_stats.rx_dropped = dropped;
-       np->net_stats.rx_errors = errors;
+
+no_rings:
+       np->dev->stats.rx_packets = pkts;
+       np->dev->stats.rx_bytes = bytes;
+       np->dev->stats.rx_dropped = dropped;
+       np->dev->stats.rx_errors = errors;
 }
 
 static void niu_get_tx_stats(struct niu *np)
 {
        unsigned long pkts, errors, bytes;
+       struct tx_ring_info *tx_rings;
        int i;
 
        pkts = errors = bytes = 0;
+
+       tx_rings = ACCESS_ONCE(np->tx_rings);
+       if (!tx_rings)
+               goto no_rings;
+
        for (i = 0; i < np->num_tx_rings; i++) {
-               struct tx_ring_info *rp = &np->tx_rings[i];
+               struct tx_ring_info *rp = &tx_rings[i];
 
                pkts += rp->tx_packets;
                bytes += rp->tx_bytes;
                errors += rp->tx_errors;
        }
-       np->net_stats.tx_packets = pkts;
-       np->net_stats.tx_bytes = bytes;
-       np->net_stats.tx_errors = errors;
+
+no_rings:
+       np->dev->stats.tx_packets = pkts;
+       np->dev->stats.tx_bytes = bytes;
+       np->dev->stats.tx_errors = errors;
 }
 
 static struct net_device_stats *niu_get_stats(struct net_device *dev)
 {
        struct niu *np = netdev_priv(dev);
 
-       niu_get_rx_stats(np);
-       niu_get_tx_stats(np);
-
-       return &np->net_stats;
+       if (netif_running(dev)) {
+               niu_get_rx_stats(np);
+               niu_get_tx_stats(np);
+       }
+       return &dev->stats;
 }
 
 static void niu_load_hash_xmac(struct niu *np, u16 *hash)
@@ -5109,7 +6350,7 @@ static void niu_set_rx_mode(struct net_device *dev)
 {
        struct niu *np = netdev_priv(dev);
        int i, alt_cnt, err;
-       struct dev_addr_list *addr;
+       struct netdev_hw_addr *ha;
        unsigned long flags;
        u16 hash[16] = { 0, };
 
@@ -5119,10 +6360,10 @@ static void niu_set_rx_mode(struct net_device *dev)
        np->flags &= ~(NIU_FLAGS_MCAST | NIU_FLAGS_PROMISC);
        if (dev->flags & IFF_PROMISC)
                np->flags |= NIU_FLAGS_PROMISC;
-       if ((dev->flags & IFF_ALLMULTI) || (dev->mc_count > 0))
+       if ((dev->flags & IFF_ALLMULTI) || (!netdev_mc_empty(dev)))
                np->flags |= NIU_FLAGS_MCAST;
 
-       alt_cnt = dev->uc_count;
+       alt_cnt = netdev_uc_count(dev);
        if (alt_cnt > niu_num_alt_addr(np)) {
                alt_cnt = 0;
                np->flags |= NIU_FLAGS_PROMISC;
@@ -5131,18 +6372,15 @@ static void niu_set_rx_mode(struct net_device *dev)
        if (alt_cnt) {
                int index = 0;
 
-               for (addr = dev->uc_list; addr; addr = addr->next) {
-                       err = niu_set_alt_mac(np, index,
-                                             addr->da_addr);
+               netdev_for_each_uc_addr(ha, dev) {
+                       err = niu_set_alt_mac(np, index, ha->addr);
                        if (err)
-                               printk(KERN_WARNING PFX "%s: Error %d "
-                                      "adding alt mac %d\n",
-                                      dev->name, err, index);
+                               netdev_warn(dev, "Error %d adding alt mac %d\n",
+                                           err, index);
                        err = niu_enable_alt_mac(np, index, 1);
                        if (err)
-                               printk(KERN_WARNING PFX "%s: Error %d "
-                                      "enabling alt mac %d\n",
-                                      dev->name, err, index);
+                               netdev_warn(dev, "Error %d enabling alt mac %d\n",
+                                           err, index);
 
                        index++;
                }
@@ -5155,17 +6393,16 @@ static void niu_set_rx_mode(struct net_device *dev)
                for (i = alt_start; i < niu_num_alt_addr(np); i++) {
                        err = niu_enable_alt_mac(np, i, 0);
                        if (err)
-                               printk(KERN_WARNING PFX "%s: Error %d "
-                                      "disabling alt mac %d\n",
-                                      dev->name, err, i);
+                               netdev_warn(dev, "Error %d disabling alt mac %d\n",
+                                           err, i);
                }
        }
        if (dev->flags & IFF_ALLMULTI) {
                for (i = 0; i < 16; i++)
                        hash[i] = 0xffff;
-       } else if (dev->mc_count > 0) {
-               for (addr = dev->mc_list; addr; addr = addr->next) {
-                       u32 crc = ether_crc_le(ETH_ALEN, addr->da_addr);
+       } else if (!netdev_mc_empty(dev)) {
+               netdev_for_each_mc_addr(ha, dev) {
+                       u32 crc = ether_crc_le(ETH_ALEN, ha->addr);
 
                        crc >>= 24;
                        hash[crc >> 4] |= (1 << (15 - (crc & 0xf)));
@@ -5222,13 +6459,63 @@ static void niu_netif_start(struct niu *np)
         * so long as all callers are assured to have free tx slots
         * (such as after niu_init_hw).
         */
-       netif_wake_queue(np->dev);
+       netif_tx_wake_all_queues(np->dev);
 
        niu_enable_napi(np);
 
        niu_enable_interrupts(np, 1);
 }
 
+static void niu_reset_buffers(struct niu *np)
+{
+       int i, j, k, err;
+
+       if (np->rx_rings) {
+               for (i = 0; i < np->num_rx_rings; i++) {
+                       struct rx_ring_info *rp = &np->rx_rings[i];
+
+                       for (j = 0, k = 0; j < MAX_RBR_RING_SIZE; j++) {
+                               struct page *page;
+
+                               page = rp->rxhash[j];
+                               while (page) {
+                                       struct page *next =
+                                               (struct page *) page->mapping;
+                                       u64 base = page->index;
+                                       base = base >> RBR_DESCR_ADDR_SHIFT;
+                                       rp->rbr[k++] = cpu_to_le32(base);
+                                       page = next;
+                               }
+                       }
+                       for (; k < MAX_RBR_RING_SIZE; k++) {
+                               err = niu_rbr_add_page(np, rp, GFP_ATOMIC, k);
+                               if (unlikely(err))
+                                       break;
+                       }
+
+                       rp->rbr_index = rp->rbr_table_size - 1;
+                       rp->rcr_index = 0;
+                       rp->rbr_pending = 0;
+                       rp->rbr_refill_pending = 0;
+               }
+       }
+       if (np->tx_rings) {
+               for (i = 0; i < np->num_tx_rings; i++) {
+                       struct tx_ring_info *rp = &np->tx_rings[i];
+
+                       for (j = 0; j < MAX_TX_RING_SIZE; j++) {
+                               if (rp->tx_buffs[j].skb)
+                                       (void) release_tx_packet(np, rp, j);
+                       }
+
+                       rp->pending = MAX_TX_RING_SIZE;
+                       rp->prod = 0;
+                       rp->cons = 0;
+                       rp->wrap_bit = 0;
+               }
+       }
+}
+
 static void niu_reset_task(struct work_struct *work)
 {
        struct niu *np = container_of(work, struct niu, reset_task);
@@ -5251,6 +6538,12 @@ static void niu_reset_task(struct work_struct *work)
 
        niu_stop_hw(np);
 
+       spin_unlock_irqrestore(&np->lock, flags);
+
+       niu_reset_buffers(np);
+
+       spin_lock_irqsave(&np->lock, flags);
+
        err = niu_init_hw(np);
        if (!err) {
                np->timer.expires = jiffies + HZ;
@@ -5265,7 +6558,7 @@ static void niu_tx_timeout(struct net_device *dev)
 {
        struct niu *np = netdev_priv(dev);
 
-       dev_err(np->device, PFX "%s: Transmit timed out, resetting\n",
+       dev_err(np->device, "%s: Transmit timed out, resetting\n",
                dev->name);
 
        schedule_work(&np->reset_task);
@@ -5302,11 +6595,11 @@ static u64 niu_compute_tx_flags(struct sk_buff *skb, struct ethhdr *ehdr,
 
        ipv6 = ihl = 0;
        switch (skb->protocol) {
-       case __constant_htons(ETH_P_IP):
+       case cpu_to_be16(ETH_P_IP):
                ip_proto = ip_hdr(skb)->protocol;
                ihl = ip_hdr(skb)->ihl;
                break;
-       case __constant_htons(ETH_P_IPV6):
+       case cpu_to_be16(ETH_P_IPV6):
                ip_proto = ipv6_hdr(skb)->nexthdr;
                ihl = (40 >> 2);
                ipv6 = 1;
@@ -5325,7 +6618,7 @@ static u64 niu_compute_tx_flags(struct sk_buff *skb, struct ethhdr *ehdr,
                             (ip_proto == IPPROTO_UDP ?
                              TXHDR_CSUM_UDP : TXHDR_CSUM_SCTP));
 
-               start = skb_transport_offset(skb) -
+               start = skb_checksum_start_offset(skb) -
                        (pad_bytes + sizeof(struct tx_pkt_hdr));
                stuff = start + skb->csum_offset;
 
@@ -5348,15 +6641,12 @@ static u64 niu_compute_tx_flags(struct sk_buff *skb, struct ethhdr *ehdr,
        return ret;
 }
 
-static struct tx_ring_info *tx_ring_select(struct niu *np, struct sk_buff *skb)
-{
-       return &np->tx_rings[0];
-}
-
-static int niu_start_xmit(struct sk_buff *skb, struct net_device *dev)
+static netdev_tx_t niu_start_xmit(struct sk_buff *skb,
+                                 struct net_device *dev)
 {
        struct niu *np = netdev_priv(dev);
        unsigned long align, headroom;
+       struct netdev_queue *txq;
        struct tx_ring_info *rp;
        struct tx_pkt_hdr *tp;
        unsigned int len, nfg;
@@ -5364,12 +6654,13 @@ static int niu_start_xmit(struct sk_buff *skb, struct net_device *dev)
        int prod, i, tlen;
        u64 mapping, mrk;
 
-       rp = tx_ring_select(np, skb);
+       i = skb_get_queue_mapping(skb);
+       rp = &np->tx_rings[i];
+       txq = netdev_get_tx_queue(dev, i);
 
        if (niu_tx_avail(rp) <= (skb_shinfo(skb)->nr_frags + 1)) {
-               netif_stop_queue(dev);
-               dev_err(np->device, PFX "%s: BUG! Tx ring full when "
-                       "queue awake!\n", dev->name);
+               netif_tx_stop_queue(txq);
+               dev_err(np->device, "%s: BUG! Tx ring full when queue awake!\n", dev->name);
                rp->tx_errors++;
                return NETDEV_TX_BUSY;
        }
@@ -5466,13 +6757,11 @@ static int niu_start_xmit(struct sk_buff *skb, struct net_device *dev)
        nw64(TX_RING_KICK(rp->tx_channel), rp->wrap_bit | (prod << 3));
 
        if (unlikely(niu_tx_avail(rp) <= (MAX_SKB_FRAGS + 1))) {
-               netif_stop_queue(dev);
+               netif_tx_stop_queue(txq);
                if (niu_tx_avail(rp) > NIU_TX_WAKEUP_THRESH(rp))
-                       netif_wake_queue(dev);
+                       netif_tx_wake_queue(txq);
        }
 
-       dev->trans_start = jiffies;
-
 out:
        return NETDEV_TX_OK;
 
@@ -5526,7 +6815,7 @@ static int niu_change_mtu(struct net_device *dev, int new_mtu)
        spin_unlock_irq(&np->lock);
 
        if (!err) {
-               netif_start_queue(dev);
+               netif_tx_start_all_queues(dev);
                if (np->link_config.loopback_mode != LOOPBACK_DISABLED)
                        netif_carrier_on(dev);
 
@@ -5560,17 +6849,27 @@ static int niu_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
        memset(cmd, 0, sizeof(*cmd));
        cmd->phy_address = np->phy_addr;
        cmd->supported = lp->supported;
-       cmd->advertising = lp->advertising;
-       cmd->autoneg = lp->autoneg;
+       cmd->advertising = lp->active_advertising;
+       cmd->autoneg = lp->active_autoneg;
        cmd->speed = lp->active_speed;
        cmd->duplex = lp->active_duplex;
+       cmd->port = (np->flags & NIU_FLAGS_FIBER) ? PORT_FIBRE : PORT_TP;
+       cmd->transceiver = (np->flags & NIU_FLAGS_XCVR_SERDES) ?
+               XCVR_EXTERNAL : XCVR_INTERNAL;
 
        return 0;
 }
 
 static int niu_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
 {
-       return -EINVAL;
+       struct niu *np = netdev_priv(dev);
+       struct niu_link_config *lp = &np->link_config;
+
+       lp->advertising = cmd->advertising;
+       lp->speed = cmd->speed;
+       lp->duplex = cmd->duplex;
+       lp->autoneg = cmd->autoneg;
+       return niu_init_link(np);
 }
 
 static u32 niu_get_msglevel(struct net_device *dev)
@@ -5585,6 +6884,16 @@ static void niu_set_msglevel(struct net_device *dev, u32 value)
        np->msg_enable = value;
 }
 
+static int niu_nway_reset(struct net_device *dev)
+{
+       struct niu *np = netdev_priv(dev);
+
+       if (np->link_config.autoneg)
+               return niu_init_link(np);
+
+       return 0;
+}
+
 static int niu_get_eeprom_len(struct net_device *dev)
 {
        struct niu *np = netdev_priv(dev);
@@ -5636,6 +6945,754 @@ static int niu_get_eeprom(struct net_device *dev,
        return 0;
 }
 
+static void niu_ethflow_to_l3proto(int flow_type, u8 *pid)
+{
+       switch (flow_type) {
+       case TCP_V4_FLOW:
+       case TCP_V6_FLOW:
+               *pid = IPPROTO_TCP;
+               break;
+       case UDP_V4_FLOW:
+       case UDP_V6_FLOW:
+               *pid = IPPROTO_UDP;
+               break;
+       case SCTP_V4_FLOW:
+       case SCTP_V6_FLOW:
+               *pid = IPPROTO_SCTP;
+               break;
+       case AH_V4_FLOW:
+       case AH_V6_FLOW:
+               *pid = IPPROTO_AH;
+               break;
+       case ESP_V4_FLOW:
+       case ESP_V6_FLOW:
+               *pid = IPPROTO_ESP;
+               break;
+       default:
+               *pid = 0;
+               break;
+       }
+}
+
+static int niu_class_to_ethflow(u64 class, int *flow_type)
+{
+       switch (class) {
+       case CLASS_CODE_TCP_IPV4:
+               *flow_type = TCP_V4_FLOW;
+               break;
+       case CLASS_CODE_UDP_IPV4:
+               *flow_type = UDP_V4_FLOW;
+               break;
+       case CLASS_CODE_AH_ESP_IPV4:
+               *flow_type = AH_V4_FLOW;
+               break;
+       case CLASS_CODE_SCTP_IPV4:
+               *flow_type = SCTP_V4_FLOW;
+               break;
+       case CLASS_CODE_TCP_IPV6:
+               *flow_type = TCP_V6_FLOW;
+               break;
+       case CLASS_CODE_UDP_IPV6:
+               *flow_type = UDP_V6_FLOW;
+               break;
+       case CLASS_CODE_AH_ESP_IPV6:
+               *flow_type = AH_V6_FLOW;
+               break;
+       case CLASS_CODE_SCTP_IPV6:
+               *flow_type = SCTP_V6_FLOW;
+               break;
+       case CLASS_CODE_USER_PROG1:
+       case CLASS_CODE_USER_PROG2:
+       case CLASS_CODE_USER_PROG3:
+       case CLASS_CODE_USER_PROG4:
+               *flow_type = IP_USER_FLOW;
+               break;
+       default:
+               return 0;
+       }
+
+       return 1;
+}
+
+static int niu_ethflow_to_class(int flow_type, u64 *class)
+{
+       switch (flow_type) {
+       case TCP_V4_FLOW:
+               *class = CLASS_CODE_TCP_IPV4;
+               break;
+       case UDP_V4_FLOW:
+               *class = CLASS_CODE_UDP_IPV4;
+               break;
+       case AH_V4_FLOW:
+       case ESP_V4_FLOW:
+               *class = CLASS_CODE_AH_ESP_IPV4;
+               break;
+       case SCTP_V4_FLOW:
+               *class = CLASS_CODE_SCTP_IPV4;
+               break;
+       case TCP_V6_FLOW:
+               *class = CLASS_CODE_TCP_IPV6;
+               break;
+       case UDP_V6_FLOW:
+               *class = CLASS_CODE_UDP_IPV6;
+               break;
+       case AH_V6_FLOW:
+       case ESP_V6_FLOW:
+               *class = CLASS_CODE_AH_ESP_IPV6;
+               break;
+       case SCTP_V6_FLOW:
+               *class = CLASS_CODE_SCTP_IPV6;
+               break;
+       default:
+               return 0;
+       }
+
+       return 1;
+}
+
+static u64 niu_flowkey_to_ethflow(u64 flow_key)
+{
+       u64 ethflow = 0;
+
+       if (flow_key & FLOW_KEY_L2DA)
+               ethflow |= RXH_L2DA;
+       if (flow_key & FLOW_KEY_VLAN)
+               ethflow |= RXH_VLAN;
+       if (flow_key & FLOW_KEY_IPSA)
+               ethflow |= RXH_IP_SRC;
+       if (flow_key & FLOW_KEY_IPDA)
+               ethflow |= RXH_IP_DST;
+       if (flow_key & FLOW_KEY_PROTO)
+               ethflow |= RXH_L3_PROTO;
+       if (flow_key & (FLOW_KEY_L4_BYTE12 << FLOW_KEY_L4_0_SHIFT))
+               ethflow |= RXH_L4_B_0_1;
+       if (flow_key & (FLOW_KEY_L4_BYTE12 << FLOW_KEY_L4_1_SHIFT))
+               ethflow |= RXH_L4_B_2_3;
+
+       return ethflow;
+
+}
+
+static int niu_ethflow_to_flowkey(u64 ethflow, u64 *flow_key)
+{
+       u64 key = 0;
+
+       if (ethflow & RXH_L2DA)
+               key |= FLOW_KEY_L2DA;
+       if (ethflow & RXH_VLAN)
+               key |= FLOW_KEY_VLAN;
+       if (ethflow & RXH_IP_SRC)
+               key |= FLOW_KEY_IPSA;
+       if (ethflow & RXH_IP_DST)
+               key |= FLOW_KEY_IPDA;
+       if (ethflow & RXH_L3_PROTO)
+               key |= FLOW_KEY_PROTO;
+       if (ethflow & RXH_L4_B_0_1)
+               key |= (FLOW_KEY_L4_BYTE12 << FLOW_KEY_L4_0_SHIFT);
+       if (ethflow & RXH_L4_B_2_3)
+               key |= (FLOW_KEY_L4_BYTE12 << FLOW_KEY_L4_1_SHIFT);
+
+       *flow_key = key;
+
+       return 1;
+
+}
+
+static int niu_get_hash_opts(struct niu *np, struct ethtool_rxnfc *nfc)
+{
+       u64 class;
+
+       nfc->data = 0;
+
+       if (!niu_ethflow_to_class(nfc->flow_type, &class))
+               return -EINVAL;
+
+       if (np->parent->tcam_key[class - CLASS_CODE_USER_PROG1] &
+           TCAM_KEY_DISC)
+               nfc->data = RXH_DISCARD;
+       else
+               nfc->data = niu_flowkey_to_ethflow(np->parent->flow_key[class -
+                                                     CLASS_CODE_USER_PROG1]);
+       return 0;
+}
+
+static void niu_get_ip4fs_from_tcam_key(struct niu_tcam_entry *tp,
+                                       struct ethtool_rx_flow_spec *fsp)
+{
+       u32 tmp;
+       u16 prt;
+
+       tmp = (tp->key[3] & TCAM_V4KEY3_SADDR) >> TCAM_V4KEY3_SADDR_SHIFT;
+       fsp->h_u.tcp_ip4_spec.ip4src = cpu_to_be32(tmp);
+
+       tmp = (tp->key[3] & TCAM_V4KEY3_DADDR) >> TCAM_V4KEY3_DADDR_SHIFT;
+       fsp->h_u.tcp_ip4_spec.ip4dst = cpu_to_be32(tmp);
+
+       tmp = (tp->key_mask[3] & TCAM_V4KEY3_SADDR) >> TCAM_V4KEY3_SADDR_SHIFT;
+       fsp->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(tmp);
+
+       tmp = (tp->key_mask[3] & TCAM_V4KEY3_DADDR) >> TCAM_V4KEY3_DADDR_SHIFT;
+       fsp->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(tmp);
+
+       fsp->h_u.tcp_ip4_spec.tos = (tp->key[2] & TCAM_V4KEY2_TOS) >>
+               TCAM_V4KEY2_TOS_SHIFT;
+       fsp->m_u.tcp_ip4_spec.tos = (tp->key_mask[2] & TCAM_V4KEY2_TOS) >>
+               TCAM_V4KEY2_TOS_SHIFT;
+
+       switch (fsp->flow_type) {
+       case TCP_V4_FLOW:
+       case UDP_V4_FLOW:
+       case SCTP_V4_FLOW:
+               prt = ((tp->key[2] & TCAM_V4KEY2_PORT_SPI) >>
+                       TCAM_V4KEY2_PORT_SPI_SHIFT) >> 16;
+               fsp->h_u.tcp_ip4_spec.psrc = cpu_to_be16(prt);
+
+               prt = ((tp->key[2] & TCAM_V4KEY2_PORT_SPI) >>
+                       TCAM_V4KEY2_PORT_SPI_SHIFT) & 0xffff;
+               fsp->h_u.tcp_ip4_spec.pdst = cpu_to_be16(prt);
+
+               prt = ((tp->key_mask[2] & TCAM_V4KEY2_PORT_SPI) >>
+                       TCAM_V4KEY2_PORT_SPI_SHIFT) >> 16;
+               fsp->m_u.tcp_ip4_spec.psrc = cpu_to_be16(prt);
+
+               prt = ((tp->key_mask[2] & TCAM_V4KEY2_PORT_SPI) >>
+                        TCAM_V4KEY2_PORT_SPI_SHIFT) & 0xffff;
+               fsp->m_u.tcp_ip4_spec.pdst = cpu_to_be16(prt);
+               break;
+       case AH_V4_FLOW:
+       case ESP_V4_FLOW:
+               tmp = (tp->key[2] & TCAM_V4KEY2_PORT_SPI) >>
+                       TCAM_V4KEY2_PORT_SPI_SHIFT;
+               fsp->h_u.ah_ip4_spec.spi = cpu_to_be32(tmp);
+
+               tmp = (tp->key_mask[2] & TCAM_V4KEY2_PORT_SPI) >>
+                       TCAM_V4KEY2_PORT_SPI_SHIFT;
+               fsp->m_u.ah_ip4_spec.spi = cpu_to_be32(tmp);
+               break;
+       case IP_USER_FLOW:
+               tmp = (tp->key[2] & TCAM_V4KEY2_PORT_SPI) >>
+                       TCAM_V4KEY2_PORT_SPI_SHIFT;
+               fsp->h_u.usr_ip4_spec.l4_4_bytes = cpu_to_be32(tmp);
+
+               tmp = (tp->key_mask[2] & TCAM_V4KEY2_PORT_SPI) >>
+                       TCAM_V4KEY2_PORT_SPI_SHIFT;
+               fsp->m_u.usr_ip4_spec.l4_4_bytes = cpu_to_be32(tmp);
+
+               fsp->h_u.usr_ip4_spec.proto =
+                       (tp->key[2] & TCAM_V4KEY2_PROTO) >>
+                       TCAM_V4KEY2_PROTO_SHIFT;
+               fsp->m_u.usr_ip4_spec.proto =
+                       (tp->key_mask[2] & TCAM_V4KEY2_PROTO) >>
+                       TCAM_V4KEY2_PROTO_SHIFT;
+
+               fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
+               break;
+       default:
+               break;
+       }
+}
+
+static int niu_get_ethtool_tcam_entry(struct niu *np,
+                                     struct ethtool_rxnfc *nfc)
+{
+       struct niu_parent *parent = np->parent;
+       struct niu_tcam_entry *tp;
+       struct ethtool_rx_flow_spec *fsp = &nfc->fs;
+       u16 idx;
+       u64 class;
+       int ret = 0;
+
+       idx = tcam_get_index(np, (u16)nfc->fs.location);
+
+       tp = &parent->tcam[idx];
+       if (!tp->valid) {
+               netdev_info(np->dev, "niu%d: entry [%d] invalid for idx[%d]\n",
+                           parent->index, (u16)nfc->fs.location, idx);
+               return -EINVAL;
+       }
+
+       /* fill the flow spec entry */
+       class = (tp->key[0] & TCAM_V4KEY0_CLASS_CODE) >>
+               TCAM_V4KEY0_CLASS_CODE_SHIFT;
+       ret = niu_class_to_ethflow(class, &fsp->flow_type);
+
+       if (ret < 0) {
+               netdev_info(np->dev, "niu%d: niu_class_to_ethflow failed\n",
+                           parent->index);
+               ret = -EINVAL;
+               goto out;
+       }
+
+       if (fsp->flow_type == AH_V4_FLOW || fsp->flow_type == AH_V6_FLOW) {
+               u32 proto = (tp->key[2] & TCAM_V4KEY2_PROTO) >>
+                       TCAM_V4KEY2_PROTO_SHIFT;
+               if (proto == IPPROTO_ESP) {
+                       if (fsp->flow_type == AH_V4_FLOW)
+                               fsp->flow_type = ESP_V4_FLOW;
+                       else
+                               fsp->flow_type = ESP_V6_FLOW;
+               }
+       }
+
+       switch (fsp->flow_type) {
+       case TCP_V4_FLOW:
+       case UDP_V4_FLOW:
+       case SCTP_V4_FLOW:
+       case AH_V4_FLOW:
+       case ESP_V4_FLOW:
+               niu_get_ip4fs_from_tcam_key(tp, fsp);
+               break;
+       case TCP_V6_FLOW:
+       case UDP_V6_FLOW:
+       case SCTP_V6_FLOW:
+       case AH_V6_FLOW:
+       case ESP_V6_FLOW:
+               /* Not yet implemented */
+               ret = -EINVAL;
+               break;
+       case IP_USER_FLOW:
+               niu_get_ip4fs_from_tcam_key(tp, fsp);
+               break;
+       default:
+               ret = -EINVAL;
+               break;
+       }
+
+       if (ret < 0)
+               goto out;
+
+       if (tp->assoc_data & TCAM_ASSOCDATA_DISC)
+               fsp->ring_cookie = RX_CLS_FLOW_DISC;
+       else
+               fsp->ring_cookie = (tp->assoc_data & TCAM_ASSOCDATA_OFFSET) >>
+                       TCAM_ASSOCDATA_OFFSET_SHIFT;
+
+       /* put the tcam size here */
+       nfc->data = tcam_get_size(np);
+out:
+       return ret;
+}
+
+static int niu_get_ethtool_tcam_all(struct niu *np,
+                                   struct ethtool_rxnfc *nfc,
+                                   u32 *rule_locs)
+{
+       struct niu_parent *parent = np->parent;
+       struct niu_tcam_entry *tp;
+       int i, idx, cnt;
+       unsigned long flags;
+       int ret = 0;
+
+       /* put the tcam size here */
+       nfc->data = tcam_get_size(np);
+
+       niu_lock_parent(np, flags);
+       for (cnt = 0, i = 0; i < nfc->data; i++) {
+               idx = tcam_get_index(np, i);
+               tp = &parent->tcam[idx];
+               if (!tp->valid)
+                       continue;
+               if (cnt == nfc->rule_cnt) {
+                       ret = -EMSGSIZE;
+                       break;
+               }
+               rule_locs[cnt] = i;
+               cnt++;
+       }
+       niu_unlock_parent(np, flags);
+
+       return ret;
+}
+
+static int niu_get_nfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
+                      void *rule_locs)
+{
+       struct niu *np = netdev_priv(dev);
+       int ret = 0;
+
+       switch (cmd->cmd) {
+       case ETHTOOL_GRXFH:
+               ret = niu_get_hash_opts(np, cmd);
+               break;
+       case ETHTOOL_GRXRINGS:
+               cmd->data = np->num_rx_rings;
+               break;
+       case ETHTOOL_GRXCLSRLCNT:
+               cmd->rule_cnt = tcam_get_valid_entry_cnt(np);
+               break;
+       case ETHTOOL_GRXCLSRULE:
+               ret = niu_get_ethtool_tcam_entry(np, cmd);
+               break;
+       case ETHTOOL_GRXCLSRLALL:
+               ret = niu_get_ethtool_tcam_all(np, cmd, (u32 *)rule_locs);
+               break;
+       default:
+               ret = -EINVAL;
+               break;
+       }
+
+       return ret;
+}
+
+static int niu_set_hash_opts(struct niu *np, struct ethtool_rxnfc *nfc)
+{
+       u64 class;
+       u64 flow_key = 0;
+       unsigned long flags;
+
+       if (!niu_ethflow_to_class(nfc->flow_type, &class))
+               return -EINVAL;
+
+       if (class < CLASS_CODE_USER_PROG1 ||
+           class > CLASS_CODE_SCTP_IPV6)
+               return -EINVAL;
+
+       if (nfc->data & RXH_DISCARD) {
+               niu_lock_parent(np, flags);
+               flow_key = np->parent->tcam_key[class -
+                                              CLASS_CODE_USER_PROG1];
+               flow_key |= TCAM_KEY_DISC;
+               nw64(TCAM_KEY(class - CLASS_CODE_USER_PROG1), flow_key);
+               np->parent->tcam_key[class - CLASS_CODE_USER_PROG1] = flow_key;
+               niu_unlock_parent(np, flags);
+               return 0;
+       } else {
+               /* Discard was set before, but is not set now */
+               if (np->parent->tcam_key[class - CLASS_CODE_USER_PROG1] &
+                   TCAM_KEY_DISC) {
+                       niu_lock_parent(np, flags);
+                       flow_key = np->parent->tcam_key[class -
+                                              CLASS_CODE_USER_PROG1];
+                       flow_key &= ~TCAM_KEY_DISC;
+                       nw64(TCAM_KEY(class - CLASS_CODE_USER_PROG1),
+                            flow_key);
+                       np->parent->tcam_key[class - CLASS_CODE_USER_PROG1] =
+                               flow_key;
+                       niu_unlock_parent(np, flags);
+               }
+       }
+
+       if (!niu_ethflow_to_flowkey(nfc->data, &flow_key))
+               return -EINVAL;
+
+       niu_lock_parent(np, flags);
+       nw64(FLOW_KEY(class - CLASS_CODE_USER_PROG1), flow_key);
+       np->parent->flow_key[class - CLASS_CODE_USER_PROG1] = flow_key;
+       niu_unlock_parent(np, flags);
+
+       return 0;
+}
+
+static void niu_get_tcamkey_from_ip4fs(struct ethtool_rx_flow_spec *fsp,
+                                      struct niu_tcam_entry *tp,
+                                      int l2_rdc_tab, u64 class)
+{
+       u8 pid = 0;
+       u32 sip, dip, sipm, dipm, spi, spim;
+       u16 sport, dport, spm, dpm;
+
+       sip = be32_to_cpu(fsp->h_u.tcp_ip4_spec.ip4src);
+       sipm = be32_to_cpu(fsp->m_u.tcp_ip4_spec.ip4src);
+       dip = be32_to_cpu(fsp->h_u.tcp_ip4_spec.ip4dst);
+       dipm = be32_to_cpu(fsp->m_u.tcp_ip4_spec.ip4dst);
+
+       tp->key[0] = class << TCAM_V4KEY0_CLASS_CODE_SHIFT;
+       tp->key_mask[0] = TCAM_V4KEY0_CLASS_CODE;
+       tp->key[1] = (u64)l2_rdc_tab << TCAM_V4KEY1_L2RDCNUM_SHIFT;
+       tp->key_mask[1] = TCAM_V4KEY1_L2RDCNUM;
+
+       tp->key[3] = (u64)sip << TCAM_V4KEY3_SADDR_SHIFT;
+       tp->key[3] |= dip;
+
+       tp->key_mask[3] = (u64)sipm << TCAM_V4KEY3_SADDR_SHIFT;
+       tp->key_mask[3] |= dipm;
+
+       tp->key[2] |= ((u64)fsp->h_u.tcp_ip4_spec.tos <<
+                      TCAM_V4KEY2_TOS_SHIFT);
+       tp->key_mask[2] |= ((u64)fsp->m_u.tcp_ip4_spec.tos <<
+                           TCAM_V4KEY2_TOS_SHIFT);
+       switch (fsp->flow_type) {
+       case TCP_V4_FLOW:
+       case UDP_V4_FLOW:
+       case SCTP_V4_FLOW:
+               sport = be16_to_cpu(fsp->h_u.tcp_ip4_spec.psrc);
+               spm = be16_to_cpu(fsp->m_u.tcp_ip4_spec.psrc);
+               dport = be16_to_cpu(fsp->h_u.tcp_ip4_spec.pdst);
+               dpm = be16_to_cpu(fsp->m_u.tcp_ip4_spec.pdst);
+
+               tp->key[2] |= (((u64)sport << 16) | dport);
+               tp->key_mask[2] |= (((u64)spm << 16) | dpm);
+               niu_ethflow_to_l3proto(fsp->flow_type, &pid);
+               break;
+       case AH_V4_FLOW:
+       case ESP_V4_FLOW:
+               spi = be32_to_cpu(fsp->h_u.ah_ip4_spec.spi);
+               spim = be32_to_cpu(fsp->m_u.ah_ip4_spec.spi);
+
+               tp->key[2] |= spi;
+               tp->key_mask[2] |= spim;
+               niu_ethflow_to_l3proto(fsp->flow_type, &pid);
+               break;
+       case IP_USER_FLOW:
+               spi = be32_to_cpu(fsp->h_u.usr_ip4_spec.l4_4_bytes);
+               spim = be32_to_cpu(fsp->m_u.usr_ip4_spec.l4_4_bytes);
+
+               tp->key[2] |= spi;
+               tp->key_mask[2] |= spim;
+               pid = fsp->h_u.usr_ip4_spec.proto;
+               break;
+       default:
+               break;
+       }
+
+       tp->key[2] |= ((u64)pid << TCAM_V4KEY2_PROTO_SHIFT);
+       if (pid) {
+               tp->key_mask[2] |= TCAM_V4KEY2_PROTO;
+       }
+}
+
+static int niu_add_ethtool_tcam_entry(struct niu *np,
+                                     struct ethtool_rxnfc *nfc)
+{
+       struct niu_parent *parent = np->parent;
+       struct niu_tcam_entry *tp;
+       struct ethtool_rx_flow_spec *fsp = &nfc->fs;
+       struct niu_rdc_tables *rdc_table = &parent->rdc_group_cfg[np->port];
+       int l2_rdc_table = rdc_table->first_table_num;
+       u16 idx;
+       u64 class;
+       unsigned long flags;
+       int err, ret;
+
+       ret = 0;
+
+       idx = nfc->fs.location;
+       if (idx >= tcam_get_size(np))
+               return -EINVAL;
+
+       if (fsp->flow_type == IP_USER_FLOW) {
+               int i;
+               int add_usr_cls = 0;
+               struct ethtool_usrip4_spec *uspec = &fsp->h_u.usr_ip4_spec;
+               struct ethtool_usrip4_spec *umask = &fsp->m_u.usr_ip4_spec;
+
+               if (uspec->ip_ver != ETH_RX_NFC_IP4)
+                       return -EINVAL;
+
+               niu_lock_parent(np, flags);
+
+               for (i = 0; i < NIU_L3_PROG_CLS; i++) {
+                       if (parent->l3_cls[i]) {
+                               if (uspec->proto == parent->l3_cls_pid[i]) {
+                                       class = parent->l3_cls[i];
+                                       parent->l3_cls_refcnt[i]++;
+                                       add_usr_cls = 1;
+                                       break;
+                               }
+                       } else {
+                               /* Program new user IP class */
+                               switch (i) {
+                               case 0:
+                                       class = CLASS_CODE_USER_PROG1;
+                                       break;
+                               case 1:
+                                       class = CLASS_CODE_USER_PROG2;
+                                       break;
+                               case 2:
+                                       class = CLASS_CODE_USER_PROG3;
+                                       break;
+                               case 3:
+                                       class = CLASS_CODE_USER_PROG4;
+                                       break;
+                               default:
+                                       break;
+                               }
+                               ret = tcam_user_ip_class_set(np, class, 0,
+                                                            uspec->proto,
+                                                            uspec->tos,
+                                                            umask->tos);
+                               if (ret)
+                                       goto out;
+
+                               ret = tcam_user_ip_class_enable(np, class, 1);
+                               if (ret)
+                                       goto out;
+                               parent->l3_cls[i] = class;
+                               parent->l3_cls_pid[i] = uspec->proto;
+                               parent->l3_cls_refcnt[i]++;
+                               add_usr_cls = 1;
+                               break;
+                       }
+               }
+               if (!add_usr_cls) {
+                       netdev_info(np->dev, "niu%d: %s(): Could not find/insert class for pid %d\n",
+                                   parent->index, __func__, uspec->proto);
+                       ret = -EINVAL;
+                       goto out;
+               }
+               niu_unlock_parent(np, flags);
+       } else {
+               if (!niu_ethflow_to_class(fsp->flow_type, &class)) {
+                       return -EINVAL;
+               }
+       }
+
+       niu_lock_parent(np, flags);
+
+       idx = tcam_get_index(np, idx);
+       tp = &parent->tcam[idx];
+
+       memset(tp, 0, sizeof(*tp));
+
+       /* fill in the tcam key and mask */
+       switch (fsp->flow_type) {
+       case TCP_V4_FLOW:
+       case UDP_V4_FLOW:
+       case SCTP_V4_FLOW:
+       case AH_V4_FLOW:
+       case ESP_V4_FLOW:
+               niu_get_tcamkey_from_ip4fs(fsp, tp, l2_rdc_table, class);
+               break;
+       case TCP_V6_FLOW:
+       case UDP_V6_FLOW:
+       case SCTP_V6_FLOW:
+       case AH_V6_FLOW:
+       case ESP_V6_FLOW:
+               /* Not yet implemented */
+               netdev_info(np->dev, "niu%d: In %s(): flow %d for IPv6 not implemented\n",
+                           parent->index, __func__, fsp->flow_type);
+               ret = -EINVAL;
+               goto out;
+       case IP_USER_FLOW:
+               niu_get_tcamkey_from_ip4fs(fsp, tp, l2_rdc_table, class);
+               break;
+       default:
+               netdev_info(np->dev, "niu%d: In %s(): Unknown flow type %d\n",
+                           parent->index, __func__, fsp->flow_type);
+               ret = -EINVAL;
+               goto out;
+       }
+
+       /* fill in the assoc data */
+       if (fsp->ring_cookie == RX_CLS_FLOW_DISC) {
+               tp->assoc_data = TCAM_ASSOCDATA_DISC;
+       } else {
+               if (fsp->ring_cookie >= np->num_rx_rings) {
+                       netdev_info(np->dev, "niu%d: In %s(): Invalid RX ring %lld\n",
+                                   parent->index, __func__,
+                                   (long long)fsp->ring_cookie);
+                       ret = -EINVAL;
+                       goto out;
+               }
+               tp->assoc_data = (TCAM_ASSOCDATA_TRES_USE_OFFSET |
+                                 (fsp->ring_cookie <<
+                                  TCAM_ASSOCDATA_OFFSET_SHIFT));
+       }
+
+       err = tcam_write(np, idx, tp->key, tp->key_mask);
+       if (err) {
+               ret = -EINVAL;
+               goto out;
+       }
+       err = tcam_assoc_write(np, idx, tp->assoc_data);
+       if (err) {
+               ret = -EINVAL;
+               goto out;
+       }
+
+       /* validate the entry */
+       tp->valid = 1;
+       np->clas.tcam_valid_entries++;
+out:
+       niu_unlock_parent(np, flags);
+
+       return ret;
+}
+
+static int niu_del_ethtool_tcam_entry(struct niu *np, u32 loc)
+{
+       struct niu_parent *parent = np->parent;
+       struct niu_tcam_entry *tp;
+       u16 idx;
+       unsigned long flags;
+       u64 class;
+       int ret = 0;
+
+       if (loc >= tcam_get_size(np))
+               return -EINVAL;
+
+       niu_lock_parent(np, flags);
+
+       idx = tcam_get_index(np, loc);
+       tp = &parent->tcam[idx];
+
+       /* if the entry is of a user defined class, then update*/
+       class = (tp->key[0] & TCAM_V4KEY0_CLASS_CODE) >>
+               TCAM_V4KEY0_CLASS_CODE_SHIFT;
+
+       if (class >= CLASS_CODE_USER_PROG1 && class <= CLASS_CODE_USER_PROG4) {
+               int i;
+               for (i = 0; i < NIU_L3_PROG_CLS; i++) {
+                       if (parent->l3_cls[i] == class) {
+                               parent->l3_cls_refcnt[i]--;
+                               if (!parent->l3_cls_refcnt[i]) {
+                                       /* disable class */
+                                       ret = tcam_user_ip_class_enable(np,
+                                                                       class,
+                                                                       0);
+                                       if (ret)
+                                               goto out;
+                                       parent->l3_cls[i] = 0;
+                                       parent->l3_cls_pid[i] = 0;
+                               }
+                               break;
+                       }
+               }
+               if (i == NIU_L3_PROG_CLS) {
+                       netdev_info(np->dev, "niu%d: In %s(): Usr class 0x%llx not found\n",
+                                   parent->index, __func__,
+                                   (unsigned long long)class);
+                       ret = -EINVAL;
+                       goto out;
+               }
+       }
+
+       ret = tcam_flush(np, idx);
+       if (ret)
+               goto out;
+
+       /* invalidate the entry */
+       tp->valid = 0;
+       np->clas.tcam_valid_entries--;
+out:
+       niu_unlock_parent(np, flags);
+
+       return ret;
+}
+
+static int niu_set_nfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
+{
+       struct niu *np = netdev_priv(dev);
+       int ret = 0;
+
+       switch (cmd->cmd) {
+       case ETHTOOL_SRXFH:
+               ret = niu_set_hash_opts(np, cmd);
+               break;
+       case ETHTOOL_SRXCLSRLINS:
+               ret = niu_add_ethtool_tcam_entry(np, cmd);
+               break;
+       case ETHTOOL_SRXCLSRLDEL:
+               ret = niu_del_ethtool_tcam_entry(np, cmd->fs.location);
+               break;
+       default:
+               ret = -EINVAL;
+               break;
+       }
+
+       return ret;
+}
+
 static const struct {
        const char string[ETH_GSTRING_LEN];
 } niu_xmac_stat_keys[] = {
@@ -5743,15 +7800,18 @@ static void niu_get_strings(struct net_device *dev, u32 stringset, u8 *data)
        }
 }
 
-static int niu_get_stats_count(struct net_device *dev)
+static int niu_get_sset_count(struct net_device *dev, int stringset)
 {
        struct niu *np = netdev_priv(dev);
 
-       return ((np->flags & NIU_FLAGS_XMAC ?
+       if (stringset != ETH_SS_STATS)
+               return -EINVAL;
+
+       return (np->flags & NIU_FLAGS_XMAC ?
                 NUM_XMAC_STAT_KEYS :
                 NUM_BMAC_STAT_KEYS) +
                (np->num_rx_rings * NUM_RXCHAN_STAT_KEYS) +
-               (np->num_tx_rings * NUM_TXCHAN_STAT_KEYS));
+               (np->num_tx_rings * NUM_TXCHAN_STAT_KEYS);
 }
 
 static void niu_get_ethtool_stats(struct net_device *dev,
@@ -5773,6 +7833,8 @@ static void niu_get_ethtool_stats(struct net_device *dev,
        for (i = 0; i < np->num_rx_rings; i++) {
                struct rx_ring_info *rp = &np->rx_rings[i];
 
+               niu_sync_rx_discard_stats(np, rp, 0);
+
                data[0] = rp->rx_channel;
                data[1] = rp->rx_packets;
                data[2] = rp->rx_bytes;
@@ -5853,19 +7915,29 @@ static int niu_phys_id(struct net_device *dev, u32 data)
        return 0;
 }
 
+static int niu_set_flags(struct net_device *dev, u32 data)
+{
+       return ethtool_op_set_flags(dev, data, ETH_FLAG_RXHASH);
+}
+
 static const struct ethtool_ops niu_ethtool_ops = {
        .get_drvinfo            = niu_get_drvinfo,
        .get_link               = ethtool_op_get_link,
        .get_msglevel           = niu_get_msglevel,
        .set_msglevel           = niu_set_msglevel,
+       .nway_reset             = niu_nway_reset,
        .get_eeprom_len         = niu_get_eeprom_len,
        .get_eeprom             = niu_get_eeprom,
        .get_settings           = niu_get_settings,
        .set_settings           = niu_set_settings,
        .get_strings            = niu_get_strings,
-       .get_stats_count        = niu_get_stats_count,
+       .get_sset_count         = niu_get_sset_count,
        .get_ethtool_stats      = niu_get_ethtool_stats,
        .phys_id                = niu_phys_id,
+       .get_rxnfc              = niu_get_nfc,
+       .set_rxnfc              = niu_set_nfc,
+       .set_flags              = niu_set_flags,
+       .get_flags              = ethtool_op_get_flags,
 };
 
 static int niu_ldg_assign_ldn(struct niu *np, struct niu_parent *parent,
@@ -5885,9 +7957,7 @@ static int niu_ldg_assign_ldn(struct niu *np, struct niu_parent *parent,
                 * won't get any interrupts and that's painful to debug.
                 */
                if (nr64(LDG_NUM(ldn)) != ldg) {
-                       dev_err(np->device, PFX "Port %u, mis-matched "
-                               "LDG assignment "
-                               "for ldn %d, should be %d is %llu\n",
+                       dev_err(np->device, "Port %u, mis-matched LDG assignment for ldn %d, should be %d is %llu\n",
                                np->port, ldn, ldg,
                                (unsigned long long) nr64(LDG_NUM(ldn)));
                        return -EINVAL;
@@ -5940,7 +8010,7 @@ static int __devinit niu_pci_eeprom_read(struct niu *np, u32 addr)
                        break;
        } while (limit--);
        if (!(frame & ESPC_PIO_STAT_READ_END)) {
-               dev_err(np->device, PFX "EEPROM read timeout frame[%llx]\n",
+               dev_err(np->device, "EEPROM read timeout frame[%llx]\n",
                        (unsigned long long) frame);
                return -ENODEV;
        }
@@ -5955,7 +8025,7 @@ static int __devinit niu_pci_eeprom_read(struct niu *np, u32 addr)
                        break;
        } while (limit--);
        if (!(frame & ESPC_PIO_STAT_READ_END)) {
-               dev_err(np->device, PFX "EEPROM read timeout frame[%llx]\n",
+               dev_err(np->device, "EEPROM read timeout frame[%llx]\n",
                        (unsigned long long) frame);
                return -ENODEV;
        }
@@ -6027,7 +8097,7 @@ static void __devinit niu_vpd_parse_version(struct niu *np)
        int i;
 
        for (i = 0; i < len - 5; i++) {
-               if (!strncmp(s + i, "FCode ", 5))
+               if (!strncmp(s + i, "FCode ", 6))
                        break;
        }
        if (i >= len - 5)
@@ -6036,8 +8106,9 @@ static void __devinit niu_vpd_parse_version(struct niu *np)
        s += i + 5;
        sscanf(s, "%d.%d", &vpd->fcode_major, &vpd->fcode_minor);
 
-       niudbg(PROBE, "VPD_SCAN: FCODE major(%d) minor(%d)\n",
-              vpd->fcode_major, vpd->fcode_minor);
+       netif_printk(np, probe, KERN_DEBUG, np->dev,
+                    "VPD_SCAN: FCODE major(%d) minor(%d)\n",
+                    vpd->fcode_major, vpd->fcode_minor);
        if (vpd->fcode_major > NIU_VPD_MIN_MAJOR ||
            (vpd->fcode_major == NIU_VPD_MIN_MAJOR &&
             vpd->fcode_minor >= NIU_VPD_MIN_MINOR))
@@ -6057,8 +8128,8 @@ static int __devinit niu_pci_vpd_scan_props(struct niu *np,
 #define FOUND_MASK_PHY         0x00000020
 #define FOUND_MASK_ALL         0x0000003f
 
-       niudbg(PROBE, "VPD_SCAN: start[%x] end[%x]\n",
-              start, end);
+       netif_printk(np, probe, KERN_DEBUG, np->dev,
+                    "VPD_SCAN: start[%x] end[%x]\n", start, end);
        while (start < end) {
                int len, err, instance, type, prop_len;
                char namebuf[64];
@@ -6112,8 +8183,7 @@ static int __devinit niu_pci_vpd_scan_props(struct niu *np,
                }
 
                if (max_len && prop_len > max_len) {
-                       dev_err(np->device, PFX "Property '%s' length (%d) is "
-                               "too long.\n", namebuf, prop_len);
+                       dev_err(np->device, "Property '%s' length (%d) is too long\n", namebuf, prop_len);
                        return -EINVAL;
                }
 
@@ -6121,8 +8191,9 @@ static int __devinit niu_pci_vpd_scan_props(struct niu *np,
                        u32 off = start + 5 + err;
                        int i;
 
-                       niudbg(PROBE, "VPD_SCAN: Reading in property [%s] "
-                              "len[%d]\n", namebuf, prop_len);
+                       netif_printk(np, probe, KERN_DEBUG, np->dev,
+                                    "VPD_SCAN: Reading in property [%s] len[%d]\n",
+                                    namebuf, prop_len);
                        for (i = 0; i < prop_len; i++)
                                *prop_buf++ = niu_pci_eeprom_read(np, off + i);
                }
@@ -6247,12 +8318,38 @@ static int __devinit niu_phy_type_prop_decode(struct niu *np,
                np->flags |= NIU_FLAGS_10G;
                np->flags &= ~NIU_FLAGS_FIBER;
                np->mac_xcvr = MAC_XCVR_XPCS;
+       } else if (!strcmp(phy_prop, "xgsd") || !strcmp(phy_prop, "gsd")) {
+               /* 10G Serdes or 1G Serdes, default to 10G */
+               np->flags |= NIU_FLAGS_10G;
+               np->flags &= ~NIU_FLAGS_FIBER;
+               np->flags |= NIU_FLAGS_XCVR_SERDES;
+               np->mac_xcvr = MAC_XCVR_XPCS;
        } else {
                return -EINVAL;
        }
        return 0;
 }
 
+static int niu_pci_vpd_get_nports(struct niu *np)
+{
+       int ports = 0;
+
+       if ((!strcmp(np->vpd.model, NIU_QGC_LP_MDL_STR)) ||
+           (!strcmp(np->vpd.model, NIU_QGC_PEM_MDL_STR)) ||
+           (!strcmp(np->vpd.model, NIU_MARAMBA_MDL_STR)) ||
+           (!strcmp(np->vpd.model, NIU_KIMI_MDL_STR)) ||
+           (!strcmp(np->vpd.model, NIU_ALONSO_MDL_STR))) {
+               ports = 4;
+       } else if ((!strcmp(np->vpd.model, NIU_2XGF_LP_MDL_STR)) ||
+                  (!strcmp(np->vpd.model, NIU_2XGF_PEM_MDL_STR)) ||
+                  (!strcmp(np->vpd.model, NIU_FOXXY_MDL_STR)) ||
+                  (!strcmp(np->vpd.model, NIU_2XGF_MRVL_MDL_STR))) {
+               ports = 2;
+       }
+
+       return ports;
+}
+
 static void __devinit niu_pci_vpd_validate(struct niu *np)
 {
        struct net_device *dev = np->dev;
@@ -6260,17 +8357,31 @@ static void __devinit niu_pci_vpd_validate(struct niu *np)
        u8 val8;
 
        if (!is_valid_ether_addr(&vpd->local_mac[0])) {
-               dev_err(np->device, PFX "VPD MAC invalid, "
-                       "falling back to SPROM.\n");
+               dev_err(np->device, "VPD MAC invalid, falling back to SPROM\n");
 
                np->flags &= ~NIU_FLAGS_VPD_VALID;
                return;
        }
 
-       if (niu_phy_type_prop_decode(np, np->vpd.phy_type)) {
-               dev_err(np->device, PFX "Illegal phy string [%s].\n",
+       if (!strcmp(np->vpd.model, NIU_ALONSO_MDL_STR) ||
+           !strcmp(np->vpd.model, NIU_KIMI_MDL_STR)) {
+               np->flags |= NIU_FLAGS_10G;
+               np->flags &= ~NIU_FLAGS_FIBER;
+               np->flags |= NIU_FLAGS_XCVR_SERDES;
+               np->mac_xcvr = MAC_XCVR_PCS;
+               if (np->port > 1) {
+                       np->flags |= NIU_FLAGS_FIBER;
+                       np->flags &= ~NIU_FLAGS_10G;
+               }
+               if (np->flags & NIU_FLAGS_10G)
+                       np->mac_xcvr = MAC_XCVR_XPCS;
+       } else if (!strcmp(np->vpd.model, NIU_FOXXY_MDL_STR)) {
+               np->flags |= (NIU_FLAGS_10G | NIU_FLAGS_FIBER |
+                             NIU_FLAGS_HOTPLUG_PHY);
+       } else if (niu_phy_type_prop_decode(np, np->vpd.phy_type)) {
+               dev_err(np->device, "Illegal phy string [%s]\n",
                        np->vpd.phy_type);
-               dev_err(np->device, PFX "Falling back to SPROM.\n");
+               dev_err(np->device, "Falling back to SPROM\n");
                np->flags &= ~NIU_FLAGS_VPD_VALID;
                return;
        }
@@ -6298,7 +8409,8 @@ static int __devinit niu_pci_probe_sprom(struct niu *np)
 
        np->eeprom_len = len;
 
-       niudbg(PROBE, "SPROM: Image size %llu\n", (unsigned long long) val);
+       netif_printk(np, probe, KERN_DEBUG, np->dev,
+                    "SPROM: Image size %llu\n", (unsigned long long)val);
 
        sum = 0;
        for (i = 0; i < len; i++) {
@@ -6308,10 +8420,10 @@ static int __devinit niu_pci_probe_sprom(struct niu *np)
                sum += (val >> 16) & 0xff;
                sum += (val >> 24) & 0xff;
        }
-       niudbg(PROBE, "SPROM: Checksum %x\n", (int)(sum & 0xff));
+       netif_printk(np, probe, KERN_DEBUG, np->dev,
+                    "SPROM: Checksum %x\n", (int)(sum & 0xff));
        if ((sum & 0xff) != 0xab) {
-               dev_err(np->device, PFX "Bad SPROM checksum "
-                       "(%x, should be 0xab)\n", (int) (sum & 0xff));
+               dev_err(np->device, "Bad SPROM checksum (%x, should be 0xab)\n", (int)(sum & 0xff));
                return -EINVAL;
        }
 
@@ -6334,11 +8446,12 @@ static int __devinit niu_pci_probe_sprom(struct niu *np)
                        ESPC_PHY_TYPE_PORT3_SHIFT;
                break;
        default:
-               dev_err(np->device, PFX "Bogus port number %u\n",
+               dev_err(np->device, "Bogus port number %u\n",
                        np->port);
                return -EINVAL;
        }
-       niudbg(PROBE, "SPROM: PHY type %x\n", val8);
+       netif_printk(np, probe, KERN_DEBUG, np->dev,
+                    "SPROM: PHY type %x\n", val8);
 
        switch (val8) {
        case ESPC_PHY_TYPE_1G_COPPER:
@@ -6370,30 +8483,27 @@ static int __devinit niu_pci_probe_sprom(struct niu *np)
                break;
 
        default:
-               dev_err(np->device, PFX "Bogus SPROM phy type %u\n", val8);
+               dev_err(np->device, "Bogus SPROM phy type %u\n", val8);
                return -EINVAL;
        }
 
        val = nr64(ESPC_MAC_ADDR0);
-       niudbg(PROBE, "SPROM: MAC_ADDR0[%08llx]\n",
-              (unsigned long long) val);
+       netif_printk(np, probe, KERN_DEBUG, np->dev,
+                    "SPROM: MAC_ADDR0[%08llx]\n", (unsigned long long)val);
        dev->perm_addr[0] = (val >>  0) & 0xff;
        dev->perm_addr[1] = (val >>  8) & 0xff;
        dev->perm_addr[2] = (val >> 16) & 0xff;
        dev->perm_addr[3] = (val >> 24) & 0xff;
 
        val = nr64(ESPC_MAC_ADDR1);
-       niudbg(PROBE, "SPROM: MAC_ADDR1[%08llx]\n",
-              (unsigned long long) val);
+       netif_printk(np, probe, KERN_DEBUG, np->dev,
+                    "SPROM: MAC_ADDR1[%08llx]\n", (unsigned long long)val);
        dev->perm_addr[4] = (val >>  0) & 0xff;
        dev->perm_addr[5] = (val >>  8) & 0xff;
 
        if (!is_valid_ether_addr(&dev->perm_addr[0])) {
-               dev_err(np->device, PFX "SPROM MAC address invalid\n");
-               dev_err(np->device, PFX "[ \n");
-               for (i = 0; i < 6; i++)
-                       printk("%02x ", dev->perm_addr[i]);
-               printk("]\n");
+               dev_err(np->device, "SPROM MAC address invalid [ %pM ]\n",
+                       dev->perm_addr);
                return -EINVAL;
        }
 
@@ -6405,8 +8515,8 @@ static int __devinit niu_pci_probe_sprom(struct niu *np)
        memcpy(dev->dev_addr, dev->perm_addr, dev->addr_len);
 
        val = nr64(ESPC_MOD_STR_LEN);
-       niudbg(PROBE, "SPROM: MOD_STR_LEN[%llu]\n",
-              (unsigned long long) val);
+       netif_printk(np, probe, KERN_DEBUG, np->dev,
+                    "SPROM: MOD_STR_LEN[%llu]\n", (unsigned long long)val);
        if (val >= 8 * 4)
                return -EINVAL;
 
@@ -6421,8 +8531,8 @@ static int __devinit niu_pci_probe_sprom(struct niu *np)
        np->vpd.model[val] = '\0';
 
        val = nr64(ESPC_BD_MOD_STR_LEN);
-       niudbg(PROBE, "SPROM: BD_MOD_STR_LEN[%llu]\n",
-              (unsigned long long) val);
+       netif_printk(np, probe, KERN_DEBUG, np->dev,
+                    "SPROM: BD_MOD_STR_LEN[%llu]\n", (unsigned long long)val);
        if (val >= 4 * 4)
                return -EINVAL;
 
@@ -6438,8 +8548,8 @@ static int __devinit niu_pci_probe_sprom(struct niu *np)
 
        np->vpd.mac_num =
                nr64(ESPC_NUM_PORTS_MACS) & ESPC_NUM_PORTS_MACS_VAL;
-       niudbg(PROBE, "SPROM: NUM_PORTS_MACS[%d]\n",
-              np->vpd.mac_num);
+       netif_printk(np, probe, KERN_DEBUG, np->dev,
+                    "SPROM: NUM_PORTS_MACS[%d]\n", np->vpd.mac_num);
 
        return 0;
 }
@@ -6455,16 +8565,23 @@ static int __devinit niu_get_and_validate_port(struct niu *np)
                if (parent->plat_type == PLAT_TYPE_NIU) {
                        parent->num_ports = 2;
                } else {
-                       parent->num_ports = nr64(ESPC_NUM_PORTS_MACS) &
-                               ESPC_NUM_PORTS_MACS_VAL;
-
-                       if (!parent->num_ports)
-                               parent->num_ports = 4;
+                       parent->num_ports = niu_pci_vpd_get_nports(np);
+                       if (!parent->num_ports) {
+                               /* Fall back to SPROM as last resort.
+                                * This will fail on most cards.
+                                */
+                               parent->num_ports = nr64(ESPC_NUM_PORTS_MACS) &
+                                       ESPC_NUM_PORTS_MACS_VAL;
+
+                               /* All of the current probing methods fail on
+                                * Maramba on-board parts.
+                                */
+                               if (!parent->num_ports)
+                                       parent->num_ports = 4;
+                       }
                }
        }
 
-       niudbg(PROBE, "niu_get_and_validate_port: port[%d] num_ports[%d]\n",
-              np->port, parent->num_ports);
        if (np->port >= parent->num_ports)
                return -ENODEV;
 
@@ -6483,7 +8600,8 @@ static int __devinit phy_record(struct niu_parent *parent,
                return 0;
        if (type == PHY_TYPE_PMA_PMD || type == PHY_TYPE_PCS) {
                if (((id & NIU_PHY_ID_MASK) != NIU_PHY_ID_BCM8704) &&
-                   ((id & NIU_PHY_ID_MASK) != NIU_PHY_ID_MRVL88X2011))
+                   ((id & NIU_PHY_ID_MASK) != NIU_PHY_ID_MRVL88X2011) &&
+                   ((id & NIU_PHY_ID_MASK) != NIU_PHY_ID_BCM8706))
                        return 0;
        } else {
                if ((id & NIU_PHY_ID_MASK) != NIU_PHY_ID_BCM5464R)
@@ -6492,14 +8610,12 @@ static int __devinit phy_record(struct niu_parent *parent,
 
        pr_info("niu%d: Found PHY %08x type %s at phy_port %u\n",
                parent->index, id,
-               (type == PHY_TYPE_PMA_PMD ?
-                "PMA/PMD" :
-                (type == PHY_TYPE_PCS ?
-                 "PCS" : "MII")),
+               type == PHY_TYPE_PMA_PMD ? "PMA/PMD" :
+               type == PHY_TYPE_PCS ? "PCS" : "MII",
                phy_port);
 
        if (p->cur[type] >= NIU_MAX_PORTS) {
-               printk(KERN_ERR PFX "Too many PHY ports.\n");
+               pr_err("Too many PHY ports\n");
                return -EINVAL;
        }
        idx = p->cur[type];
@@ -6560,8 +8676,7 @@ static void __devinit niu_n2_divide_channels(struct niu_parent *parent)
                parent->rxchan_per_port[i] = (16 / num_ports);
                parent->txchan_per_port[i] = (16 / num_ports);
 
-               pr_info(PFX "niu%d: Port %u [%u RX chans] "
-                       "[%u TX chans]\n",
+               pr_info("niu%d: Port %u [%u RX chans] [%u TX chans]\n",
                        parent->index, i,
                        parent->rxchan_per_port[i],
                        parent->txchan_per_port[i]);
@@ -6604,8 +8719,7 @@ static void __devinit niu_divide_channels(struct niu_parent *parent,
                        parent->rxchan_per_port[i] = rx_chans_per_1g;
                        parent->txchan_per_port[i] = tx_chans_per_1g;
                }
-               pr_info(PFX "niu%d: Port %u [%u RX chans] "
-                       "[%u TX chans]\n",
+               pr_info("niu%d: Port %u [%u RX chans] [%u TX chans]\n",
                        parent->index, i,
                        parent->rxchan_per_port[i],
                        parent->txchan_per_port[i]);
@@ -6614,23 +8728,20 @@ static void __devinit niu_divide_channels(struct niu_parent *parent,
        }
 
        if (tot_rx > NIU_NUM_RXCHAN) {
-               printk(KERN_ERR PFX "niu%d: Too many RX channels (%d), "
-                      "resetting to one per port.\n",
+               pr_err("niu%d: Too many RX channels (%d), resetting to one per port\n",
                       parent->index, tot_rx);
                for (i = 0; i < num_ports; i++)
                        parent->rxchan_per_port[i] = 1;
        }
        if (tot_tx > NIU_NUM_TXCHAN) {
-               printk(KERN_ERR PFX "niu%d: Too many TX channels (%d), "
-                      "resetting to one per port.\n",
+               pr_err("niu%d: Too many TX channels (%d), resetting to one per port\n",
                       parent->index, tot_tx);
                for (i = 0; i < num_ports; i++)
                        parent->txchan_per_port[i] = 1;
        }
        if (tot_rx < NIU_NUM_RXCHAN || tot_tx < NIU_NUM_TXCHAN) {
-               printk(KERN_WARNING PFX "niu%d: Driver bug, wasted channels, "
-                      "RX[%d] TX[%d]\n",
-                      parent->index, tot_rx, tot_tx);
+               pr_warning("niu%d: Driver bug, wasted channels, RX[%d] TX[%d]\n",
+                          parent->index, tot_rx, tot_tx);
        }
 }
 
@@ -6658,18 +8769,18 @@ static void __devinit niu_divide_rdc_groups(struct niu_parent *parent,
                        struct rdc_table *rt = &tp->tables[grp];
                        int slot;
 
-                       pr_info(PFX "niu%d: Port %d RDC tbl(%d) [ ",
+                       pr_info("niu%d: Port %d RDC tbl(%d) [ ",
                                parent->index, i, tp->first_table_num + grp);
                        for (slot = 0; slot < NIU_RDC_TABLE_SLOTS; slot++) {
                                rt->rxdma_channel[slot] =
                                        rdc_channel_base + this_channel_offset;
 
-                               printk("%d ", rt->rxdma_channel[slot]);
+                               pr_cont("%d ", rt->rxdma_channel[slot]);
 
                                if (++this_channel_offset == num_channels)
                                        this_channel_offset = 0;
                        }
-                       printk("]\n");
+                       pr_cont("]\n");
                }
 
                parent->rdc_default[i] = rdc_channel_base;
@@ -6730,80 +8841,109 @@ static int __devinit walk_phys(struct niu *np, struct niu_parent *parent)
        u32 val;
        int err;
 
-       err = fill_phy_probe_info(np, parent, info);
-       if (err)
-               return err;
-
-       num_10g = count_10g_ports(info, &lowest_10g);
-       num_1g = count_1g_ports(info, &lowest_1g);
-
-       switch ((num_10g << 4) | num_1g) {
-       case 0x24:
-               if (lowest_1g == 10)
-                       parent->plat_type = PLAT_TYPE_VF_P0;
-               else if (lowest_1g == 26)
-                       parent->plat_type = PLAT_TYPE_VF_P1;
-               else
-                       goto unknown_vg_1g_port;
+       num_10g = num_1g = 0;
 
-               /* fallthru */
-       case 0x22:
-               val = (phy_encode(PORT_TYPE_10G, 0) |
-                      phy_encode(PORT_TYPE_10G, 1) |
+       if (!strcmp(np->vpd.model, NIU_ALONSO_MDL_STR) ||
+           !strcmp(np->vpd.model, NIU_KIMI_MDL_STR)) {
+               num_10g = 0;
+               num_1g = 2;
+               parent->plat_type = PLAT_TYPE_ATCA_CP3220;
+               parent->num_ports = 4;
+               val = (phy_encode(PORT_TYPE_1G, 0) |
+                      phy_encode(PORT_TYPE_1G, 1) |
                       phy_encode(PORT_TYPE_1G, 2) |
                       phy_encode(PORT_TYPE_1G, 3));
-               break;
-
-       case 0x20:
+       } else if (!strcmp(np->vpd.model, NIU_FOXXY_MDL_STR)) {
+               num_10g = 2;
+               num_1g = 0;
+               parent->num_ports = 2;
                val = (phy_encode(PORT_TYPE_10G, 0) |
                       phy_encode(PORT_TYPE_10G, 1));
-               break;
+       } else if ((np->flags & NIU_FLAGS_XCVR_SERDES) &&
+                  (parent->plat_type == PLAT_TYPE_NIU)) {
+               /* this is the Monza case */
+               if (np->flags & NIU_FLAGS_10G) {
+                       val = (phy_encode(PORT_TYPE_10G, 0) |
+                              phy_encode(PORT_TYPE_10G, 1));
+               } else {
+                       val = (phy_encode(PORT_TYPE_1G, 0) |
+                              phy_encode(PORT_TYPE_1G, 1));
+               }
+       } else {
+               err = fill_phy_probe_info(np, parent, info);
+               if (err)
+                       return err;
 
-       case 0x10:
-               val = phy_encode(PORT_TYPE_10G, np->port);
-               break;
+               num_10g = count_10g_ports(info, &lowest_10g);
+               num_1g = count_1g_ports(info, &lowest_1g);
 
-       case 0x14:
-               if (lowest_1g == 10)
-                       parent->plat_type = PLAT_TYPE_VF_P0;
-               else if (lowest_1g == 26)
-                       parent->plat_type = PLAT_TYPE_VF_P1;
-               else
-                       goto unknown_vg_1g_port;
+               switch ((num_10g << 4) | num_1g) {
+               case 0x24:
+                       if (lowest_1g == 10)
+                               parent->plat_type = PLAT_TYPE_VF_P0;
+                       else if (lowest_1g == 26)
+                               parent->plat_type = PLAT_TYPE_VF_P1;
+                       else
+                               goto unknown_vg_1g_port;
 
-               /* fallthru */
-       case 0x13:
-               if ((lowest_10g & 0x7) == 0)
+                       /* fallthru */
+               case 0x22:
                        val = (phy_encode(PORT_TYPE_10G, 0) |
-                              phy_encode(PORT_TYPE_1G, 1) |
-                              phy_encode(PORT_TYPE_1G, 2) |
-                              phy_encode(PORT_TYPE_1G, 3));
-               else
-                       val = (phy_encode(PORT_TYPE_1G, 0) |
                               phy_encode(PORT_TYPE_10G, 1) |
                               phy_encode(PORT_TYPE_1G, 2) |
                               phy_encode(PORT_TYPE_1G, 3));
-               break;
+                       break;
 
-       case 0x04:
-               if (lowest_1g == 10)
-                       parent->plat_type = PLAT_TYPE_VF_P0;
-               else if (lowest_1g == 26)
-                       parent->plat_type = PLAT_TYPE_VF_P1;
-               else
-                       goto unknown_vg_1g_port;
+               case 0x20:
+                       val = (phy_encode(PORT_TYPE_10G, 0) |
+                              phy_encode(PORT_TYPE_10G, 1));
+                       break;
 
-               val = (phy_encode(PORT_TYPE_1G, 0) |
-                      phy_encode(PORT_TYPE_1G, 1) |
-                      phy_encode(PORT_TYPE_1G, 2) |
-                      phy_encode(PORT_TYPE_1G, 3));
-               break;
+               case 0x10:
+                       val = phy_encode(PORT_TYPE_10G, np->port);
+                       break;
 
-       default:
-               printk(KERN_ERR PFX "Unsupported port config "
-                      "10G[%d] 1G[%d]\n",
-                      num_10g, num_1g);
-               return -EINVAL;
+               case 0x14:
+                       if (lowest_1g == 10)
+                               parent->plat_type = PLAT_TYPE_VF_P0;
+                       else if (lowest_1g == 26)
+                               parent->plat_type = PLAT_TYPE_VF_P1;
+                       else
+                               goto unknown_vg_1g_port;
+
+                       /* fallthru */
+               case 0x13:
+                       if ((lowest_10g & 0x7) == 0)
+                               val = (phy_encode(PORT_TYPE_10G, 0) |
+                                      phy_encode(PORT_TYPE_1G, 1) |
+                                      phy_encode(PORT_TYPE_1G, 2) |
+                                      phy_encode(PORT_TYPE_1G, 3));
+                       else
+                               val = (phy_encode(PORT_TYPE_1G, 0) |
+                                      phy_encode(PORT_TYPE_10G, 1) |
+                                      phy_encode(PORT_TYPE_1G, 2) |
+                                      phy_encode(PORT_TYPE_1G, 3));
+                       break;
+
+               case 0x04:
+                       if (lowest_1g == 10)
+                               parent->plat_type = PLAT_TYPE_VF_P0;
+                       else if (lowest_1g == 26)
+                               parent->plat_type = PLAT_TYPE_VF_P1;
+                       else
+                               goto unknown_vg_1g_port;
+
+                       val = (phy_encode(PORT_TYPE_1G, 0) |
+                              phy_encode(PORT_TYPE_1G, 1) |
+                              phy_encode(PORT_TYPE_1G, 2) |
+                              phy_encode(PORT_TYPE_1G, 3));
+                       break;
+
+               default:
+                       pr_err("Unsupported port config 10G[%d] 1G[%d]\n",
+                              num_10g, num_1g);
+                       return -EINVAL;
+               }
        }
 
        parent->port_phy = val;
@@ -6818,8 +8958,7 @@ static int __devinit walk_phys(struct niu *np, struct niu_parent *parent)
        return 0;
 
 unknown_vg_1g_port:
-       printk(KERN_ERR PFX "Cannot identify platform type, 1gport=%d\n",
-              lowest_1g);
+       pr_err("Cannot identify platform type, 1gport=%d\n", lowest_1g);
        return -EINVAL;
 }
 
@@ -6828,9 +8967,6 @@ static int __devinit niu_probe_ports(struct niu *np)
        struct niu_parent *parent = np->parent;
        int err, i;
 
-       niudbg(PROBE, "niu_probe_ports(): port_phy[%08x]\n",
-              parent->port_phy);
-
        if (parent->port_phy == PORT_PHY_UNKNOWN) {
                err = walk_phys(np, parent);
                if (err)
@@ -6851,10 +8987,8 @@ static int __devinit niu_classifier_swstate_init(struct niu *np)
 {
        struct niu_classifier *cp = &np->clas;
 
-       niudbg(PROBE, "niu_classifier_swstate_init: num_tcam(%d)\n",
-              np->parent->tcam_num_entries);
-
-       cp->tcam_index = (u16) np->port;
+       cp->tcam_top = (u16) np->port;
+       cp->tcam_sz = np->parent->tcam_num_entries / np->parent->num_ports;
        cp->h1_init = 0xffffffff;
        cp->h2_init = 0xffff;
 
@@ -6874,7 +9008,9 @@ static void __devinit niu_link_config_init(struct niu *np)
                           ADVERTISED_10000baseT_Full |
                           ADVERTISED_Autoneg);
        lp->speed = lp->active_speed = SPEED_INVALID;
-       lp->duplex = lp->active_duplex = DUPLEX_INVALID;
+       lp->duplex = DUPLEX_FULL;
+       lp->active_duplex = DUPLEX_INVALID;
+       lp->autoneg = 1;
 #if 0
        lp->loopback_mode = LOOPBACK_MAC;
        lp->active_speed = SPEED_10000;
@@ -6916,8 +9052,7 @@ static int __devinit niu_init_mac_ipp_pcs_base(struct niu *np)
                break;
 
        default:
-               dev_err(np->device, PFX "Port %u is invalid, cannot "
-                       "compute MAC block offset.\n", np->port);
+               dev_err(np->device, "Port %u is invalid, cannot compute MAC block offset\n", np->port);
                return -EINVAL;
        }
 
@@ -6966,20 +9101,20 @@ retry:
 static int __devinit niu_n2_irq_init(struct niu *np, u8 *ldg_num_map)
 {
 #ifdef CONFIG_SPARC64
-       struct of_device *op = np->op;
+       struct platform_device *op = np->op;
        const u32 *int_prop;
        int i;
 
-       int_prop = of_get_property(op->node, "interrupts", NULL);
+       int_prop = of_get_property(op->dev.of_node, "interrupts", NULL);
        if (!int_prop)
                return -ENODEV;
 
-       for (i = 0; i < op->num_irqs; i++) {
+       for (i = 0; i < op->archdata.num_irqs; i++) {
                ldg_num_map[i] = int_prop[i];
-               np->ldg[i].irq = op->irqs[i];
+               np->ldg[i].irq = op->archdata.irqs[i];
        }
 
-       np->num_ldg = op->num_irqs;
+       np->num_ldg = op->archdata.num_irqs;
 
        return 0;
 #else
@@ -7117,18 +9252,18 @@ static int __devinit niu_get_of_props(struct niu *np)
        struct device_node *dp;
        const char *phy_type;
        const u8 *mac_addr;
+       const char *model;
        int prop_len;
 
        if (np->parent->plat_type == PLAT_TYPE_NIU)
-               dp = np->op->node;
+               dp = np->op->dev.of_node;
        else
                dp = pci_device_to_OF_node(np->pdev);
 
        phy_type = of_get_property(dp, "phy-type", &prop_len);
        if (!phy_type) {
-               dev_err(np->device, PFX "%s: OF node lacks "
-                       "phy-type property\n",
-                       dp->full_name);
+               netdev_err(dev, "%s: OF node lacks phy-type property\n",
+                          dp->full_name);
                return -EINVAL;
        }
 
@@ -7138,39 +9273,41 @@ static int __devinit niu_get_of_props(struct niu *np)
        strcpy(np->vpd.phy_type, phy_type);
 
        if (niu_phy_type_prop_decode(np, np->vpd.phy_type)) {
-               dev_err(np->device, PFX "%s: Illegal phy string [%s].\n",
-                       dp->full_name, np->vpd.phy_type);
+               netdev_err(dev, "%s: Illegal phy string [%s]\n",
+                          dp->full_name, np->vpd.phy_type);
                return -EINVAL;
        }
 
        mac_addr = of_get_property(dp, "local-mac-address", &prop_len);
        if (!mac_addr) {
-               dev_err(np->device, PFX "%s: OF node lacks "
-                       "local-mac-address property\n",
-                       dp->full_name);
+               netdev_err(dev, "%s: OF node lacks local-mac-address property\n",
+                          dp->full_name);
                return -EINVAL;
        }
        if (prop_len != dev->addr_len) {
-               dev_err(np->device, PFX "%s: OF MAC address prop len (%d) "
-                       "is wrong.\n",
-                       dp->full_name, prop_len);
+               netdev_err(dev, "%s: OF MAC address prop len (%d) is wrong\n",
+                          dp->full_name, prop_len);
        }
        memcpy(dev->perm_addr, mac_addr, dev->addr_len);
        if (!is_valid_ether_addr(&dev->perm_addr[0])) {
-               int i;
-
-               dev_err(np->device, PFX "%s: OF MAC address is invalid\n",
-                       dp->full_name);
-               dev_err(np->device, PFX "%s: [ \n",
-                       dp->full_name);
-               for (i = 0; i < 6; i++)
-                       printk("%02x ", dev->perm_addr[i]);
-               printk("]\n");
+               netdev_err(dev, "%s: OF MAC address is invalid\n",
+                          dp->full_name);
+               netdev_err(dev, "%s: [ %pM ]\n", dp->full_name, dev->perm_addr);
                return -EINVAL;
        }
 
        memcpy(dev->dev_addr, dev->perm_addr, dev->addr_len);
 
+       model = of_get_property(dp, "model", &prop_len);
+
+       if (model)
+               strcpy(np->vpd.model, model);
+
+       if (of_find_property(dp, "hot-swappable-phy", &prop_len)) {
+               np->flags |= (NIU_FLAGS_10G | NIU_FLAGS_FIBER |
+                       NIU_FLAGS_HOTPLUG_PHY);
+       }
+
        return 0;
 #else
        return -EINVAL;
@@ -7188,30 +9325,38 @@ static int __devinit niu_get_invariants(struct niu *np)
 
        have_props = !err;
 
-       err = niu_get_and_validate_port(np);
-       if (err)
-               return err;
-
        err = niu_init_mac_ipp_pcs_base(np);
        if (err)
                return err;
 
-       if (!have_props) {
+       if (have_props) {
+               err = niu_get_and_validate_port(np);
+               if (err)
+                       return err;
+
+       } else  {
                if (np->parent->plat_type == PLAT_TYPE_NIU)
                        return -EINVAL;
 
                nw64(ESPC_PIO_EN, ESPC_PIO_EN_ENABLE);
                offset = niu_pci_vpd_offset(np);
-               niudbg(PROBE, "niu_get_invariants: VPD offset [%08x]\n",
-                      offset);
+               netif_printk(np, probe, KERN_DEBUG, np->dev,
+                            "%s() VPD offset [%08x]\n", __func__, offset);
                if (offset)
                        niu_pci_vpd_fetch(np, offset);
                nw64(ESPC_PIO_EN, 0);
 
-               if (np->flags & NIU_FLAGS_VPD_VALID)
+               if (np->flags & NIU_FLAGS_VPD_VALID) {
                        niu_pci_vpd_validate(np);
+                       err = niu_get_and_validate_port(np);
+                       if (err)
+                               return err;
+               }
 
                if (!(np->flags & NIU_FLAGS_VPD_VALID)) {
+                       err = niu_get_and_validate_port(np);
+                       if (err)
+                               return err;
                        err = niu_pci_probe_sprom(np);
                        if (err)
                                return err;
@@ -7356,11 +9501,9 @@ static struct niu_parent * __devinit niu_new_parent(struct niu *np,
        struct niu_parent *p;
        int i;
 
-       niudbg(PROBE, "niu_new_parent: Creating new parent.\n");
-
        plat_dev = platform_device_register_simple("niu", niu_parent_index,
                                                   NULL, 0);
-       if (!plat_dev)
+       if (IS_ERR(plat_dev))
                return NULL;
 
        for (i = 0; attr_name(niu_parent_attributes[i]); i++) {
@@ -7422,9 +9565,6 @@ static struct niu_parent * __devinit niu_get_parent(struct niu *np,
        struct niu_parent *p, *tmp;
        int port = np->port;
 
-       niudbg(PROBE, "niu_get_parent: platform_type[%u] port[%u]\n",
-              ptype, port);
-
        mutex_lock(&niu_parent_lock);
        p = NULL;
        list_for_each_entry(tmp, &niu_parent_list, list) {
@@ -7462,7 +9602,8 @@ static void niu_put_parent(struct niu *np)
 
        BUG_ON(!p || p->ports[port] != np);
 
-       niudbg(PROBE, "niu_put_parent: port[%u]\n", port);
+       netif_printk(np, probe, KERN_DEBUG, np->dev,
+                    "%s() port[%u]\n", __func__, port);
 
        sprintf(port_name, "port%d", port);
 
@@ -7509,7 +9650,7 @@ static u64 niu_pci_map_page(struct device *dev, struct page *page,
 static void niu_pci_unmap_page(struct device *dev, u64 dma_address,
                               size_t size, enum dma_data_direction direction)
 {
-       return dma_unmap_page(dev, dma_address, size, direction);
+       dma_unmap_page(dev, dma_address, size, direction);
 }
 
 static u64 niu_pci_map_single(struct device *dev, void *cpu_addr,
@@ -7545,14 +9686,15 @@ static void __devinit niu_driver_version(void)
 
 static struct net_device * __devinit niu_alloc_and_init(
        struct device *gen_dev, struct pci_dev *pdev,
-       struct of_device *op, const struct niu_ops *ops,
+       struct platform_device *op, const struct niu_ops *ops,
        u8 port)
 {
-       struct net_device *dev = alloc_etherdev(sizeof(struct niu));
+       struct net_device *dev;
        struct niu *np;
 
+       dev = alloc_etherdev_mq(sizeof(struct niu), NIU_NUM_TXCHAN);
        if (!dev) {
-               dev_err(gen_dev, PFX "Etherdev alloc failed, aborting.\n");
+               dev_err(gen_dev, "Etherdev alloc failed, aborting\n");
                return NULL;
        }
 
@@ -7575,43 +9717,64 @@ static struct net_device * __devinit niu_alloc_and_init(
        return dev;
 }
 
+static const struct net_device_ops niu_netdev_ops = {
+       .ndo_open               = niu_open,
+       .ndo_stop               = niu_close,
+       .ndo_start_xmit         = niu_start_xmit,
+       .ndo_get_stats          = niu_get_stats,
+       .ndo_set_multicast_list = niu_set_rx_mode,
+       .ndo_validate_addr      = eth_validate_addr,
+       .ndo_set_mac_address    = niu_set_mac_addr,
+       .ndo_do_ioctl           = niu_ioctl,
+       .ndo_tx_timeout         = niu_tx_timeout,
+       .ndo_change_mtu         = niu_change_mtu,
+};
+
 static void __devinit niu_assign_netdev_ops(struct net_device *dev)
 {
-       dev->open = niu_open;
-       dev->stop = niu_close;
-       dev->get_stats = niu_get_stats;
-       dev->set_multicast_list = niu_set_rx_mode;
-       dev->set_mac_address = niu_set_mac_addr;
-       dev->do_ioctl = niu_ioctl;
-       dev->tx_timeout = niu_tx_timeout;
-       dev->hard_start_xmit = niu_start_xmit;
+       dev->netdev_ops = &niu_netdev_ops;
        dev->ethtool_ops = &niu_ethtool_ops;
        dev->watchdog_timeo = NIU_TX_TIMEOUT;
-       dev->change_mtu = niu_change_mtu;
 }
 
 static void __devinit niu_device_announce(struct niu *np)
 {
        struct net_device *dev = np->dev;
-       DECLARE_MAC_BUF(mac);
 
-       pr_info("%s: NIU Ethernet %s\n",
-               dev->name, print_mac(mac, dev->dev_addr));
+       pr_info("%s: NIU Ethernet %pM\n", dev->name, dev->dev_addr);
+
+       if (np->parent->plat_type == PLAT_TYPE_ATCA_CP3220) {
+               pr_info("%s: Port type[%s] mode[%s:%s] XCVR[%s] phy[%s]\n",
+                               dev->name,
+                               (np->flags & NIU_FLAGS_XMAC ? "XMAC" : "BMAC"),
+                               (np->flags & NIU_FLAGS_10G ? "10G" : "1G"),
+                               (np->flags & NIU_FLAGS_FIBER ? "RGMII FIBER" : "SERDES"),
+                               (np->mac_xcvr == MAC_XCVR_MII ? "MII" :
+                                (np->mac_xcvr == MAC_XCVR_PCS ? "PCS" : "XPCS")),
+                               np->vpd.phy_type);
+       } else {
+               pr_info("%s: Port type[%s] mode[%s:%s] XCVR[%s] phy[%s]\n",
+                               dev->name,
+                               (np->flags & NIU_FLAGS_XMAC ? "XMAC" : "BMAC"),
+                               (np->flags & NIU_FLAGS_10G ? "10G" : "1G"),
+                               (np->flags & NIU_FLAGS_FIBER ? "FIBER" :
+                                (np->flags & NIU_FLAGS_XCVR_SERDES ? "SERDES" :
+                                 "COPPER")),
+                               (np->mac_xcvr == MAC_XCVR_MII ? "MII" :
+                                (np->mac_xcvr == MAC_XCVR_PCS ? "PCS" : "XPCS")),
+                               np->vpd.phy_type);
+       }
+}
 
-       pr_info("%s: Port type[%s] mode[%s:%s] XCVR[%s] phy[%s]\n",
-               dev->name,
-               (np->flags & NIU_FLAGS_XMAC ? "XMAC" : "BMAC"),
-               (np->flags & NIU_FLAGS_10G ? "10G" : "1G"),
-               (np->flags & NIU_FLAGS_FIBER ? "FIBER" : "COPPER"),
-               (np->mac_xcvr == MAC_XCVR_MII ? "MII" :
-                (np->mac_xcvr == MAC_XCVR_PCS ? "PCS" : "XPCS")),
-               np->vpd.phy_type);
+static void __devinit niu_set_basic_features(struct net_device *dev)
+{
+       dev->features |= (NETIF_F_SG | NETIF_F_HW_CSUM |
+                         NETIF_F_GRO | NETIF_F_RXHASH);
 }
 
 static int __devinit niu_pci_init_one(struct pci_dev *pdev,
                                      const struct pci_device_id *ent)
 {
-       unsigned long niureg_base, niureg_len;
        union niu_parent_id parent_id;
        struct net_device *dev;
        struct niu *np;
@@ -7623,30 +9786,26 @@ static int __devinit niu_pci_init_one(struct pci_dev *pdev,
 
        err = pci_enable_device(pdev);
        if (err) {
-               dev_err(&pdev->dev, PFX "Cannot enable PCI device, "
-                       "aborting.\n");
+               dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n");
                return err;
        }
 
        if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM) ||
            !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
-               dev_err(&pdev->dev, PFX "Cannot find proper PCI device "
-                       "base addresses, aborting.\n");
+               dev_err(&pdev->dev, "Cannot find proper PCI device base addresses, aborting\n");
                err = -ENODEV;
                goto err_out_disable_pdev;
        }
 
        err = pci_request_regions(pdev, DRV_MODULE_NAME);
        if (err) {
-               dev_err(&pdev->dev, PFX "Cannot obtain PCI resources, "
-                       "aborting.\n");
+               dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n");
                goto err_out_disable_pdev;
        }
 
        pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
        if (pos <= 0) {
-               dev_err(&pdev->dev, PFX "Cannot find PCI Express capability, "
-                       "aborting.\n");
+               dev_err(&pdev->dev, "Cannot find PCI Express capability, aborting\n");
                goto err_out_free_res;
        }
 
@@ -7679,36 +9838,29 @@ static int __devinit niu_pci_init_one(struct pci_dev *pdev,
                  PCI_EXP_DEVCTL_RELAX_EN);
        pci_write_config_word(pdev, pos + PCI_EXP_DEVCTL, val16);
 
-       dma_mask = DMA_44BIT_MASK;
+       dma_mask = DMA_BIT_MASK(44);
        err = pci_set_dma_mask(pdev, dma_mask);
        if (!err) {
                dev->features |= NETIF_F_HIGHDMA;
                err = pci_set_consistent_dma_mask(pdev, dma_mask);
                if (err) {
-                       dev_err(&pdev->dev, PFX "Unable to obtain 44 bit "
-                               "DMA for consistent allocations, "
-                               "aborting.\n");
+                       dev_err(&pdev->dev, "Unable to obtain 44 bit DMA for consistent allocations, aborting\n");
                        goto err_out_release_parent;
                }
        }
-       if (err || dma_mask == DMA_32BIT_MASK) {
-               err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
+       if (err || dma_mask == DMA_BIT_MASK(32)) {
+               err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
                if (err) {
-                       dev_err(&pdev->dev, PFX "No usable DMA configuration, "
-                               "aborting.\n");
+                       dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
                        goto err_out_release_parent;
                }
        }
 
-       dev->features |= (NETIF_F_SG | NETIF_F_HW_CSUM);
+       niu_set_basic_features(dev);
 
-       niureg_base = pci_resource_start(pdev, 0);
-       niureg_len = pci_resource_len(pdev, 0);
-
-       np->regs = ioremap_nocache(niureg_base, niureg_len);
+       np->regs = pci_ioremap_bar(pdev, 0);
        if (!np->regs) {
-               dev_err(&pdev->dev, PFX "Cannot map device registers, "
-                       "aborting.\n");
+               dev_err(&pdev->dev, "Cannot map device registers, aborting\n");
                err = -ENOMEM;
                goto err_out_release_parent;
        }
@@ -7723,15 +9875,13 @@ static int __devinit niu_pci_init_one(struct pci_dev *pdev,
        err = niu_get_invariants(np);
        if (err) {
                if (err != -ENODEV)
-                       dev_err(&pdev->dev, PFX "Problem fetching invariants "
-                               "of chip, aborting.\n");
+                       dev_err(&pdev->dev, "Problem fetching invariants of chip, aborting\n");
                goto err_out_iounmap;
        }
 
        err = register_netdev(dev);
        if (err) {
-               dev_err(&pdev->dev, PFX "Cannot register net device, "
-                       "aborting.\n");
+               dev_err(&pdev->dev, "Cannot register net device, aborting\n");
                goto err_out_iounmap;
        }
 
@@ -7796,7 +9946,7 @@ static int niu_suspend(struct pci_dev *pdev, pm_message_t state)
        if (!netif_running(dev))
                return 0;
 
-       flush_scheduled_work();
+       flush_work_sync(&np->reset_task);
        niu_netif_stop(np);
 
        del_timer_sync(&np->timer);
@@ -7912,12 +10062,7 @@ static const struct niu_ops niu_phys_ops = {
        .unmap_single   = niu_phys_unmap_single,
 };
 
-static unsigned long res_size(struct resource *r)
-{
-       return r->end - r->start + 1UL;
-}
-
-static int __devinit niu_of_probe(struct of_device *op,
+static int __devinit niu_of_probe(struct platform_device *op,
                                  const struct of_device_id *match)
 {
        union niu_parent_id parent_id;
@@ -7928,10 +10073,10 @@ static int __devinit niu_of_probe(struct of_device *op,
 
        niu_driver_version();
 
-       reg = of_get_property(op->node, "reg", NULL);
+       reg = of_get_property(op->dev.of_node, "reg", NULL);
        if (!reg) {
-               dev_err(&op->dev, PFX "%s: No 'reg' property, aborting.\n",
-                       op->node->full_name);
+               dev_err(&op->dev, "%s: No 'reg' property, aborting\n",
+                       op->dev.of_node->full_name);
                return -ENODEV;
        }
 
@@ -7944,7 +10089,7 @@ static int __devinit niu_of_probe(struct of_device *op,
        np = netdev_priv(dev);
 
        memset(&parent_id, 0, sizeof(parent_id));
-       parent_id.of = of_get_parent(op->node);
+       parent_id.of = of_get_parent(op->dev.of_node);
 
        np->parent = niu_get_parent(np, &parent_id,
                                    PLAT_TYPE_NIU);
@@ -7953,34 +10098,31 @@ static int __devinit niu_of_probe(struct of_device *op,
                goto err_out_free_dev;
        }
 
-       dev->features |= (NETIF_F_SG | NETIF_F_HW_CSUM);
+       niu_set_basic_features(dev);
 
        np->regs = of_ioremap(&op->resource[1], 0,
-                             res_size(&op->resource[1]),
+                             resource_size(&op->resource[1]),
                              "niu regs");
        if (!np->regs) {
-               dev_err(&op->dev, PFX "Cannot map device registers, "
-                       "aborting.\n");
+               dev_err(&op->dev, "Cannot map device registers, aborting\n");
                err = -ENOMEM;
                goto err_out_release_parent;
        }
 
        np->vir_regs_1 = of_ioremap(&op->resource[2], 0,
-                                   res_size(&op->resource[2]),
+                                   resource_size(&op->resource[2]),
                                    "niu vregs-1");
        if (!np->vir_regs_1) {
-               dev_err(&op->dev, PFX "Cannot map device vir registers 1, "
-                       "aborting.\n");
+               dev_err(&op->dev, "Cannot map device vir registers 1, aborting\n");
                err = -ENOMEM;
                goto err_out_iounmap;
        }
 
        np->vir_regs_2 = of_ioremap(&op->resource[3], 0,
-                                   res_size(&op->resource[3]),
+                                   resource_size(&op->resource[3]),
                                    "niu vregs-2");
        if (!np->vir_regs_2) {
-               dev_err(&op->dev, PFX "Cannot map device vir registers 2, "
-                       "aborting.\n");
+               dev_err(&op->dev, "Cannot map device vir registers 2, aborting\n");
                err = -ENOMEM;
                goto err_out_iounmap;
        }
@@ -7990,15 +10132,13 @@ static int __devinit niu_of_probe(struct of_device *op,
        err = niu_get_invariants(np);
        if (err) {
                if (err != -ENODEV)
-                       dev_err(&op->dev, PFX "Problem fetching invariants "
-                               "of chip, aborting.\n");
+                       dev_err(&op->dev, "Problem fetching invariants of chip, aborting\n");
                goto err_out_iounmap;
        }
 
        err = register_netdev(dev);
        if (err) {
-               dev_err(&op->dev, PFX "Cannot register net device, "
-                       "aborting.\n");
+               dev_err(&op->dev, "Cannot register net device, aborting\n");
                goto err_out_iounmap;
        }
 
@@ -8011,19 +10151,19 @@ static int __devinit niu_of_probe(struct of_device *op,
 err_out_iounmap:
        if (np->vir_regs_1) {
                of_iounmap(&op->resource[2], np->vir_regs_1,
-                          res_size(&op->resource[2]));
+                          resource_size(&op->resource[2]));
                np->vir_regs_1 = NULL;
        }
 
        if (np->vir_regs_2) {
                of_iounmap(&op->resource[3], np->vir_regs_2,
-                          res_size(&op->resource[3]));
+                          resource_size(&op->resource[3]));
                np->vir_regs_2 = NULL;
        }
 
        if (np->regs) {
                of_iounmap(&op->resource[1], np->regs,
-                          res_size(&op->resource[1]));
+                          resource_size(&op->resource[1]));
                np->regs = NULL;
        }
 
@@ -8037,7 +10177,7 @@ err_out:
        return err;
 }
 
-static int __devexit niu_of_remove(struct of_device *op)
+static int __devexit niu_of_remove(struct platform_device *op)
 {
        struct net_device *dev = dev_get_drvdata(&op->dev);
 
@@ -8048,19 +10188,19 @@ static int __devexit niu_of_remove(struct of_device *op)
 
                if (np->vir_regs_1) {
                        of_iounmap(&op->resource[2], np->vir_regs_1,
-                                  res_size(&op->resource[2]));
+                                  resource_size(&op->resource[2]));
                        np->vir_regs_1 = NULL;
                }
 
                if (np->vir_regs_2) {
                        of_iounmap(&op->resource[3], np->vir_regs_2,
-                                  res_size(&op->resource[3]));
+                                  resource_size(&op->resource[3]));
                        np->vir_regs_2 = NULL;
                }
 
                if (np->regs) {
                        of_iounmap(&op->resource[1], np->regs,
-                                  res_size(&op->resource[1]));
+                                  resource_size(&op->resource[1]));
                        np->regs = NULL;
                }
 
@@ -8074,7 +10214,7 @@ static int __devexit niu_of_remove(struct of_device *op)
        return 0;
 }
 
-static struct of_device_id niu_match[] = {
+static const struct of_device_id niu_match[] = {
        {
                .name = "network",
                .compatible = "SUNW,niusl",
@@ -8084,8 +10224,11 @@ static struct of_device_id niu_match[] = {
 MODULE_DEVICE_TABLE(of, niu_match);
 
 static struct of_platform_driver niu_of_driver = {
-       .name           = "niu",
-       .match_table    = niu_match,
+       .driver = {
+               .name = "niu",
+               .owner = THIS_MODULE,
+               .of_match_table = niu_match,
+       },
        .probe          = niu_of_probe,
        .remove         = __devexit_p(niu_of_remove),
 };
@@ -8101,14 +10244,14 @@ static int __init niu_init(void)
        niu_debug = netif_msg_init(debug, NIU_MSG_DEFAULT);
 
 #ifdef CONFIG_SPARC64
-       err = of_register_driver(&niu_of_driver, &of_bus_type);
+       err = of_register_platform_driver(&niu_of_driver);
 #endif
 
        if (!err) {
                err = pci_register_driver(&niu_pci_driver);
 #ifdef CONFIG_SPARC64
                if (err)
-                       of_unregister_driver(&niu_of_driver);
+                       of_unregister_platform_driver(&niu_of_driver);
 #endif
        }
 
@@ -8119,7 +10262,7 @@ static void __exit niu_exit(void)
 {
        pci_unregister_driver(&niu_pci_driver);
 #ifdef CONFIG_SPARC64
-       of_unregister_driver(&niu_of_driver);
+       of_unregister_platform_driver(&niu_of_driver);
 #endif
 }