Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[firefly-linux-kernel-4.4.55.git] / drivers / net / macvlan.c
index 5b37d3c191e49a6146796e84e744fd4496ca2879..3ad5425b82ddcccd8a58dcef731d5d7451ac0dcb 100644 (file)
@@ -39,8 +39,11 @@ struct macvlan_port {
        struct list_head        vlans;
        struct rcu_head         rcu;
        bool                    passthru;
+       int                     count;
 };
 
+static void macvlan_port_destroy(struct net_device *dev);
+
 #define macvlan_port_get_rcu(dev) \
        ((struct macvlan_port *) rcu_dereference(dev->rx_handler_data))
 #define macvlan_port_get(dev) ((struct macvlan_port *) dev->rx_handler_data)
@@ -412,7 +415,7 @@ static struct lock_class_key macvlan_netdev_addr_lock_key;
 #define MACVLAN_FEATURES \
        (NETIF_F_SG | NETIF_F_ALL_CSUM | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST | \
         NETIF_F_GSO | NETIF_F_TSO | NETIF_F_UFO | NETIF_F_GSO_ROBUST | \
-        NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_GRO)
+        NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_GRO | NETIF_F_RXCSUM)
 
 #define MACVLAN_STATE_MASK \
        ((1<<__LINK_STATE_NOCARRIER) | (1<<__LINK_STATE_DORMANT))
@@ -457,8 +460,13 @@ static int macvlan_init(struct net_device *dev)
 static void macvlan_uninit(struct net_device *dev)
 {
        struct macvlan_dev *vlan = netdev_priv(dev);
+       struct macvlan_port *port = vlan->port;
 
        free_percpu(vlan->pcpu_stats);
+
+       port->count -= 1;
+       if (!port->count)
+               macvlan_port_destroy(port->dev);
 }
 
 static struct rtnl_link_stats64 *macvlan_dev_get_stats64(struct net_device *dev,
@@ -509,12 +517,6 @@ static void macvlan_ethtool_get_drvinfo(struct net_device *dev,
        snprintf(drvinfo->version, 32, "0.1");
 }
 
-static u32 macvlan_ethtool_get_rx_csum(struct net_device *dev)
-{
-       const struct macvlan_dev *vlan = netdev_priv(dev);
-       return dev_ethtool_get_rx_csum(vlan->lowerdev);
-}
-
 static int macvlan_ethtool_get_settings(struct net_device *dev,
                                        struct ethtool_cmd *cmd)
 {
@@ -522,18 +524,10 @@ static int macvlan_ethtool_get_settings(struct net_device *dev,
        return dev_ethtool_get_settings(vlan->lowerdev, cmd);
 }
 
-static u32 macvlan_ethtool_get_flags(struct net_device *dev)
-{
-       const struct macvlan_dev *vlan = netdev_priv(dev);
-       return dev_ethtool_get_flags(vlan->lowerdev);
-}
-
 static const struct ethtool_ops macvlan_ethtool_ops = {
        .get_link               = ethtool_op_get_link,
        .get_settings           = macvlan_ethtool_get_settings,
-       .get_rx_csum            = macvlan_ethtool_get_rx_csum,
        .get_drvinfo            = macvlan_ethtool_get_drvinfo,
-       .get_flags              = macvlan_ethtool_get_flags,
 };
 
 static const struct net_device_ops macvlan_netdev_ops = {
@@ -691,12 +685,13 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
                vlan->mode = nla_get_u32(data[IFLA_MACVLAN_MODE]);
 
        if (vlan->mode == MACVLAN_MODE_PASSTHRU) {
-               if (!list_empty(&port->vlans))
+               if (port->count)
                        return -EINVAL;
                port->passthru = true;
                memcpy(dev->dev_addr, lowerdev->dev_addr, ETH_ALEN);
        }
 
+       port->count += 1;
        err = register_netdevice(dev);
        if (err < 0)
                goto destroy_port;
@@ -707,7 +702,8 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
        return 0;
 
 destroy_port:
-       if (list_empty(&port->vlans))
+       port->count -= 1;
+       if (!port->count)
                macvlan_port_destroy(lowerdev);
 
        return err;
@@ -725,13 +721,9 @@ static int macvlan_newlink(struct net *src_net, struct net_device *dev,
 void macvlan_dellink(struct net_device *dev, struct list_head *head)
 {
        struct macvlan_dev *vlan = netdev_priv(dev);
-       struct macvlan_port *port = vlan->port;
 
        list_del(&vlan->list);
        unregister_netdevice_queue(dev, head);
-
-       if (list_empty(&port->vlans))
-               macvlan_port_destroy(port->dev);
 }
 EXPORT_SYMBOL_GPL(macvlan_dellink);