Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[firefly-linux-kernel-4.4.55.git] / drivers / net / ethernet / via / via-rhine.c
index 78ace59efd297531001c171d47351c2fe9bb8ef9..ca98acabf1b43b29b6f27c547fbbb0c5277b2e8a 100644 (file)
@@ -417,6 +417,12 @@ enum chip_cmd_bits {
        Cmd1NoTxPoll=0x08, Cmd1Reset=0x80,
 };
 
+struct rhine_stats {
+       u64             packets;
+       u64             bytes;
+       struct u64_stats_sync syncp;
+};
+
 struct rhine_private {
        /* Bit mask for configured VLAN ids */
        unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
@@ -458,6 +464,8 @@ struct rhine_private {
        unsigned int cur_rx, dirty_rx;  /* Producer/consumer ring indices */
        unsigned int cur_tx, dirty_tx;
        unsigned int rx_buf_sz;         /* Based on MTU+slack. */
+       struct rhine_stats rx_stats;
+       struct rhine_stats tx_stats;
        u8 wolopts;
 
        u8 tx_thresh, rx_thresh;
@@ -495,12 +503,15 @@ static irqreturn_t rhine_interrupt(int irq, void *dev_instance);
 static void rhine_tx(struct net_device *dev);
 static int rhine_rx(struct net_device *dev, int limit);
 static void rhine_set_rx_mode(struct net_device *dev);
-static struct net_device_stats *rhine_get_stats(struct net_device *dev);
+static struct rtnl_link_stats64 *rhine_get_stats64(struct net_device *dev,
+              struct rtnl_link_stats64 *stats);
 static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
 static const struct ethtool_ops netdev_ethtool_ops;
 static int  rhine_close(struct net_device *dev);
-static int rhine_vlan_rx_add_vid(struct net_device *dev, unsigned short vid);
-static int rhine_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid);
+static int rhine_vlan_rx_add_vid(struct net_device *dev,
+                                __be16 proto, u16 vid);
+static int rhine_vlan_rx_kill_vid(struct net_device *dev,
+                                 __be16 proto, u16 vid);
 static void rhine_restart_tx(struct net_device *dev);
 
 static void rhine_wait_bit(struct rhine_private *rp, u8 reg, u8 mask, bool low)
@@ -842,7 +853,7 @@ static const struct net_device_ops rhine_netdev_ops = {
        .ndo_open                = rhine_open,
        .ndo_stop                = rhine_close,
        .ndo_start_xmit          = rhine_start_tx,
-       .ndo_get_stats           = rhine_get_stats,
+       .ndo_get_stats64         = rhine_get_stats64,
        .ndo_set_rx_mode         = rhine_set_rx_mode,
        .ndo_change_mtu          = eth_change_mtu,
        .ndo_validate_addr       = eth_validate_addr,
@@ -990,7 +1001,6 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                netdev_info(dev, "Using random MAC address: %pM\n",
                            dev->dev_addr);
        }
-       memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
 
        /* For Rhine-I/II, phy_id is loaded from EEPROM */
        if (!phy_id)
@@ -1018,8 +1028,9 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                dev->features |= NETIF_F_SG|NETIF_F_HW_CSUM;
 
        if (pdev->revision >= VT6105M)
-               dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
-               NETIF_F_HW_VLAN_FILTER;
+               dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
+                                NETIF_F_HW_VLAN_CTAG_RX |
+                                NETIF_F_HW_VLAN_CTAG_FILTER;
 
        /* dev->name not defined before register_netdev()! */
        rc = register_netdev(dev);
@@ -1406,7 +1417,7 @@ static void rhine_update_vcam(struct net_device *dev)
        rhine_set_vlan_cam_mask(ioaddr, vCAMmask);
 }
 
-static int rhine_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
+static int rhine_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
 {
        struct rhine_private *rp = netdev_priv(dev);
 
@@ -1417,7 +1428,7 @@ static int rhine_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
        return 0;
 }
 
-static int rhine_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
+static int rhine_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
 {
        struct rhine_private *rp = netdev_priv(dev);
 
@@ -1791,8 +1802,11 @@ static void rhine_tx(struct net_device *dev)
                                dev->stats.collisions += txstatus & 0x0F;
                        netif_dbg(rp, tx_done, dev, "collisions: %1.1x:%1.1x\n",
                                  (txstatus >> 3) & 0xF, txstatus & 0xF);
-                       dev->stats.tx_bytes += rp->tx_skbuff[entry]->len;
-                       dev->stats.tx_packets++;
+
+                       u64_stats_update_begin(&rp->tx_stats.syncp);
+                       rp->tx_stats.bytes += rp->tx_skbuff[entry]->len;
+                       rp->tx_stats.packets++;
+                       u64_stats_update_end(&rp->tx_stats.syncp);
                }
                /* Free the original skb. */
                if (rp->tx_skbuff_dma[entry]) {
@@ -1922,10 +1936,13 @@ static int rhine_rx(struct net_device *dev, int limit)
                        skb->protocol = eth_type_trans(skb, dev);
 
                        if (unlikely(desc_length & DescTag))
-                               __vlan_hwaccel_put_tag(skb, vlan_tci);
+                               __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan_tci);
                        netif_receive_skb(skb);
-                       dev->stats.rx_bytes += pkt_len;
-                       dev->stats.rx_packets++;
+
+                       u64_stats_update_begin(&rp->rx_stats.syncp);
+                       rp->rx_stats.bytes += pkt_len;
+                       rp->rx_stats.packets++;
+                       u64_stats_update_end(&rp->rx_stats.syncp);
                }
                entry = (++rp->cur_rx) % RX_RING_SIZE;
                rp->rx_head_desc = &rp->rx_ring[entry];
@@ -2016,15 +2033,31 @@ out_unlock:
        mutex_unlock(&rp->task_lock);
 }
 
-static struct net_device_stats *rhine_get_stats(struct net_device *dev)
+static struct rtnl_link_stats64 *
+rhine_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
 {
        struct rhine_private *rp = netdev_priv(dev);
+       unsigned int start;
 
        spin_lock_bh(&rp->lock);
        rhine_update_rx_crc_and_missed_errord(rp);
        spin_unlock_bh(&rp->lock);
 
-       return &dev->stats;
+       netdev_stats_to_stats64(stats, &dev->stats);
+
+       do {
+               start = u64_stats_fetch_begin_bh(&rp->rx_stats.syncp);
+               stats->rx_packets = rp->rx_stats.packets;
+               stats->rx_bytes = rp->rx_stats.bytes;
+       } while (u64_stats_fetch_retry_bh(&rp->rx_stats.syncp, start));
+
+       do {
+               start = u64_stats_fetch_begin_bh(&rp->tx_stats.syncp);
+               stats->tx_packets = rp->tx_stats.packets;
+               stats->tx_bytes = rp->tx_stats.bytes;
+       } while (u64_stats_fetch_retry_bh(&rp->tx_stats.syncp, start));
+
+       return stats;
 }
 
 static void rhine_set_rx_mode(struct net_device *dev)