[SKY2]: ethtool register reserved area blackout
[firefly-linux-kernel-4.4.55.git] / drivers / net / sky2.c
index b8c15f881eba51a8020516bcf2691ceda1c34177..4832f64037214b2b8f60808839e0d0c71df4bd76 100644 (file)
@@ -2245,15 +2245,13 @@ static inline void sky2_tx_done(struct net_device *dev, u16 last)
 }
 
 /* Process status response ring */
-static int sky2_status_intr(struct sky2_hw *hw, int to_do)
+static int sky2_status_intr(struct sky2_hw *hw, int to_do, u16 idx)
 {
        int work_done = 0;
        unsigned rx[2] = { 0, 0 };
-       u16 hwidx = sky2_read16(hw, STAT_PUT_IDX);
 
        rmb();
-
-       while (hw->st_idx != hwidx) {
+       do {
                struct sky2_port *sky2;
                struct sky2_status_le *le  = hw->st_le + hw->st_idx;
                unsigned port = le->css & CSS_LINK_BIT;
@@ -2364,7 +2362,7 @@ static int sky2_status_intr(struct sky2_hw *hw, int to_do)
                                printk(KERN_WARNING PFX
                                       "unknown status opcode 0x%x\n", le->opcode);
                }
-       }
+       } while (hw->st_idx != idx);
 
        /* Fully processed status ring so clear irq */
        sky2_write32(hw, STAT_CTRL, SC_STAT_CLR_IRQ);
@@ -2606,7 +2604,8 @@ static int sky2_poll(struct napi_struct *napi, int work_limit)
 {
        struct sky2_hw *hw = container_of(napi, struct sky2_hw, napi);
        u32 status = sky2_read32(hw, B0_Y2_SP_EISR);
-       int work_done;
+       int work_done = 0;
+       u16 idx;
 
        if (unlikely(status & Y2_IS_ERROR))
                sky2_err_intr(hw, status);
@@ -2617,21 +2616,24 @@ static int sky2_poll(struct napi_struct *napi, int work_limit)
        if (status & Y2_IS_IRQ_PHY2)
                sky2_phy_intr(hw, 1);
 
-       work_done = sky2_status_intr(hw, work_limit);
+       while ((idx = sky2_read16(hw, STAT_PUT_IDX)) != hw->st_idx) {
+               work_done += sky2_status_intr(hw, work_limit - work_done, idx);
 
-       /* More work? */
-       if (hw->st_idx == sky2_read16(hw, STAT_PUT_IDX)) {
-               /* Bug/Errata workaround?
-                * Need to kick the TX irq moderation timer.
-                */
-               if (sky2_read8(hw, STAT_TX_TIMER_CTRL) == TIM_START) {
-                       sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_STOP);
-                       sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START);
-               }
+               if (work_done >= work_limit)
+                       goto done;
+       }
 
-               napi_complete(napi);
-               sky2_read32(hw, B0_Y2_SP_LISR);
+       /* Bug/Errata workaround?
+        * Need to kick the TX irq moderation timer.
+        */
+       if (sky2_read8(hw, STAT_TX_TIMER_CTRL) == TIM_START) {
+               sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_STOP);
+               sky2_write8(hw, STAT_TX_TIMER_CTRL, TIM_START);
        }
+       napi_complete(napi);
+       sky2_read32(hw, B0_Y2_SP_LISR);
+done:
+
        return work_done;
 }
 
@@ -3190,9 +3192,14 @@ static void sky2_set_msglevel(struct net_device *netdev, u32 value)
        sky2->msg_enable = value;
 }
 
-static int sky2_get_stats_count(struct net_device *dev)
+static int sky2_get_sset_count(struct net_device *dev, int sset)
 {
-       return ARRAY_SIZE(sky2_stats);
+       switch (sset) {
+       case ETH_SS_STATS:
+               return ARRAY_SIZE(sky2_stats);
+       default:
+               return -EOPNOTSUPP;
+       }
 }
 
 static void sky2_get_ethtool_stats(struct net_device *dev,
@@ -3562,20 +3569,64 @@ static void sky2_get_regs(struct net_device *dev, struct ethtool_regs *regs,
 {
        const struct sky2_port *sky2 = netdev_priv(dev);
        const void __iomem *io = sky2->hw->regs;
+       unsigned int b;
 
        regs->version = 1;
-       memset(p, 0, regs->len);
 
-       memcpy_fromio(p, io, B3_RAM_ADDR);
-
-       /* skip diagnostic ram region */
-       memcpy_fromio(p + B3_RI_WTO_R1, io + B3_RI_WTO_R1, 0x2000 - B3_RI_WTO_R1);
+       for (b = 0; b < 128; b++) {
+               /* This complicated switch statement is to make sure and
+                * only access regions that are unreserved.
+                * Some blocks are only valid on dual port cards.
+                * and block 3 has some special diagnostic registers that
+                * are poison.
+                */
+               switch (b) {
+               case 3:
+                       /* skip diagnostic ram region */
+                       memcpy_fromio(p + 0x10, io + 0x10, 128 - 0x10);
+                       break;
 
-       /* copy GMAC registers */
-       memcpy_fromio(p + BASE_GMAC_1, io + BASE_GMAC_1, 0x1000);
-       if (sky2->hw->ports > 1)
-               memcpy_fromio(p + BASE_GMAC_2, io + BASE_GMAC_2, 0x1000);
+               /* dual port cards only */
+               case 5:         /* Tx Arbiter 2 */
+               case 9:         /* RX2 */
+               case 14 ... 15: /* TX2 */
+               case 17: case 19: /* Ram Buffer 2 */
+               case 22 ... 23: /* Tx Ram Buffer 2 */
+               case 25:        /* Rx MAC Fifo 1 */
+               case 27:        /* Tx MAC Fifo 2 */
+               case 31:        /* GPHY 2 */
+               case 40 ... 47: /* Pattern Ram 2 */
+               case 52: case 54: /* TCP Segmentation 2 */
+               case 112 ... 116: /* GMAC 2 */
+                       if (sky2->hw->ports == 1)
+                               goto reserved;
+                       /* fall through */
+               case 0:         /* Control */
+               case 2:         /* Mac address */
+               case 4:         /* Tx Arbiter 1 */
+               case 7:         /* PCI express reg */
+               case 8:         /* RX1 */
+               case 12 ... 13: /* TX1 */
+               case 16: case 18:/* Rx Ram Buffer 1 */
+               case 20 ... 21: /* Tx Ram Buffer 1 */
+               case 24:        /* Rx MAC Fifo 1 */
+               case 26:        /* Tx MAC Fifo 1 */
+               case 28 ... 29: /* Descriptor and status unit */
+               case 30:        /* GPHY 1*/
+               case 32 ... 39: /* Pattern Ram 1 */
+               case 48: case 50: /* TCP Segmentation 1 */
+               case 56 ... 60: /* PCI space */
+               case 80 ... 84: /* GMAC 1 */
+                       memcpy_fromio(p, io, 128);
+                       break;
+               default:
+reserved:
+                       memset(p, 0, 128);
+               }
 
+               p += 128;
+               io += 128;
+       }
 }
 
 /* In order to do Jumbo packets on these chips, need to turn off the
@@ -3723,7 +3774,7 @@ static const struct ethtool_ops sky2_ethtool_ops = {
        .get_pauseparam = sky2_get_pauseparam,
        .set_pauseparam = sky2_set_pauseparam,
        .phys_id        = sky2_phys_id,
-       .get_stats_count = sky2_get_stats_count,
+       .get_sset_count = sky2_get_sset_count,
        .get_ethtool_stats = sky2_get_ethtool_stats,
 };
 
@@ -3984,12 +4035,11 @@ static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
 static void __devinit sky2_show_addr(struct net_device *dev)
 {
        const struct sky2_port *sky2 = netdev_priv(dev);
+       DECLARE_MAC_BUF(mac);
 
        if (netif_msg_probe(sky2))
-               printk(KERN_INFO PFX "%s: addr %02x:%02x:%02x:%02x:%02x:%02x\n",
-                      dev->name,
-                      dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
-                      dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
+               printk(KERN_INFO PFX "%s: addr %s\n",
+                      dev->name, print_mac(mac, dev->dev_addr));
 }
 
 /* Handle software interrupt used during MSI test */