net: remove .ndo_change_proto_down
authorJakub Kicinski <kuba@kernel.org>
Tue, 23 Nov 2021 01:24:47 +0000 (17:24 -0800)
committerDavid S. Miller <davem@davemloft.net>
Tue, 23 Nov 2021 12:18:48 +0000 (12:18 +0000)
.ndo_change_proto_down was added seemingly to enable out-of-tree
implementations. Over 2.5yrs later we still have no real users
upstream. Hardwire the generic implementation for now, we can
revert once real users materialize. (rocker is a test vehicle,
not a user.)

We need to drop the optimization on the sysfs side, because
unlike ndos priv_flags will be changed at runtime, so we'd
need READ_ONCE/WRITE_ONCE everywhere..

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/rocker/rocker_main.c
drivers/net/macvlan.c
drivers/net/vxlan.c
include/linux/netdevice.h
net/8021q/vlanproc.c
net/core/dev.c
net/core/net-sysfs.c
net/core/rtnetlink.c

index ba40628..b620470 100644 (file)
@@ -1995,17 +1995,6 @@ static int rocker_port_get_phys_port_name(struct net_device *dev,
        return err ? -EOPNOTSUPP : 0;
 }
 
-static int rocker_port_change_proto_down(struct net_device *dev,
-                                        bool proto_down)
-{
-       struct rocker_port *rocker_port = netdev_priv(dev);
-
-       if (rocker_port->dev->flags & IFF_UP)
-               rocker_port_set_enable(rocker_port, !proto_down);
-       rocker_port->dev->proto_down = proto_down;
-       return 0;
-}
-
 static void rocker_port_neigh_destroy(struct net_device *dev,
                                      struct neighbour *n)
 {
@@ -2037,7 +2026,6 @@ static const struct net_device_ops rocker_port_netdev_ops = {
        .ndo_set_mac_address            = rocker_port_set_mac_address,
        .ndo_change_mtu                 = rocker_port_change_mtu,
        .ndo_get_phys_port_name         = rocker_port_get_phys_port_name,
-       .ndo_change_proto_down          = rocker_port_change_proto_down,
        .ndo_neigh_destroy              = rocker_port_neigh_destroy,
        .ndo_get_port_parent_id         = rocker_port_get_port_parent_id,
 };
index 75b453a..6ef5f77 100644 (file)
@@ -1171,7 +1171,6 @@ static const struct net_device_ops macvlan_netdev_ops = {
 #endif
        .ndo_get_iflink         = macvlan_dev_get_iflink,
        .ndo_features_check     = passthru_features_check,
-       .ndo_change_proto_down  = dev_change_proto_down_generic,
 };
 
 void macvlan_common_setup(struct net_device *dev)
@@ -1182,7 +1181,7 @@ void macvlan_common_setup(struct net_device *dev)
        dev->max_mtu            = ETH_MAX_MTU;
        dev->priv_flags        &= ~IFF_TX_SKB_SHARING;
        netif_keep_dst(dev);
-       dev->priv_flags        |= IFF_UNICAST_FLT;
+       dev->priv_flags        |= IFF_UNICAST_FLT | IFF_CHANGE_PROTO_DOWN;
        dev->netdev_ops         = &macvlan_netdev_ops;
        dev->needs_free_netdev  = true;
        dev->header_ops         = &macvlan_hard_header_ops;
index 82bd794..fecff0a 100644 (file)
@@ -3234,7 +3234,6 @@ static const struct net_device_ops vxlan_netdev_ether_ops = {
        .ndo_fdb_dump           = vxlan_fdb_dump,
        .ndo_fdb_get            = vxlan_fdb_get,
        .ndo_fill_metadata_dst  = vxlan_fill_metadata_dst,
-       .ndo_change_proto_down  = dev_change_proto_down_generic,
 };
 
 static const struct net_device_ops vxlan_netdev_raw_ops = {
@@ -3305,7 +3304,7 @@ static void vxlan_setup(struct net_device *dev)
        dev->hw_features |= NETIF_F_RXCSUM;
        dev->hw_features |= NETIF_F_GSO_SOFTWARE;
        netif_keep_dst(dev);
-       dev->priv_flags |= IFF_NO_QUEUE;
+       dev->priv_flags |= IFF_NO_QUEUE | IFF_CHANGE_PROTO_DOWN;
 
        /* MTU range: 68 - 65535 */
        dev->min_mtu = ETH_MIN_MTU;
index df04986..db3bff1 100644 (file)
@@ -1297,11 +1297,6 @@ struct netdev_net_notifier {
  *     TX queue.
  * int (*ndo_get_iflink)(const struct net_device *dev);
  *     Called to get the iflink value of this device.
- * void (*ndo_change_proto_down)(struct net_device *dev,
- *                              bool proto_down);
- *     This function is used to pass protocol port error state information
- *     to the switch driver. The switch driver can react to the proto_down
- *      by doing a phys down on the associated switch port.
  * int (*ndo_fill_metadata_dst)(struct net_device *dev, struct sk_buff *skb);
  *     This function is used to get egress tunnel information for given skb.
  *     This is useful for retrieving outer tunnel header parameters while
@@ -1542,8 +1537,6 @@ struct net_device_ops {
                                                      int queue_index,
                                                      u32 maxrate);
        int                     (*ndo_get_iflink)(const struct net_device *dev);
-       int                     (*ndo_change_proto_down)(struct net_device *dev,
-                                                        bool proto_down);
        int                     (*ndo_fill_metadata_dst)(struct net_device *dev,
                                                       struct sk_buff *skb);
        void                    (*ndo_set_rx_headroom)(struct net_device *dev,
@@ -1612,6 +1605,7 @@ struct net_device_ops {
  * @IFF_LIVE_RENAME_OK: rename is allowed while device is up and running
  * @IFF_TX_SKB_NO_LINEAR: device/driver is capable of xmitting frames with
  *     skb_headlen(skb) == 0 (data starts from frag0)
+ * @IFF_CHANGE_PROTO_DOWN: device supports setting carrier via IFLA_PROTO_DOWN
  */
 enum netdev_priv_flags {
        IFF_802_1Q_VLAN                 = 1<<0,
@@ -1646,6 +1640,7 @@ enum netdev_priv_flags {
        IFF_L3MDEV_RX_HANDLER           = 1<<29,
        IFF_LIVE_RENAME_OK              = 1<<30,
        IFF_TX_SKB_NO_LINEAR            = 1<<31,
+       IFF_CHANGE_PROTO_DOWN           = BIT_ULL(32),
 };
 
 #define IFF_802_1Q_VLAN                        IFF_802_1Q_VLAN
@@ -1982,7 +1977,7 @@ struct net_device {
 
        /* Read-mostly cache-line for fast-path access */
        unsigned int            flags;
-       unsigned int            priv_flags;
+       unsigned long long      priv_flags;
        const struct net_device_ops *netdev_ops;
        int                     ifindex;
        unsigned short          gflags;
@@ -3735,7 +3730,6 @@ int dev_get_port_parent_id(struct net_device *dev,
                           struct netdev_phys_item_id *ppid, bool recurse);
 bool netdev_port_same_parent_id(struct net_device *a, struct net_device *b);
 int dev_change_proto_down(struct net_device *dev, bool proto_down);
-int dev_change_proto_down_generic(struct net_device *dev, bool proto_down);
 void dev_change_proto_down_reason(struct net_device *dev, unsigned long mask,
                                  u32 value);
 struct sk_buff *validate_xmit_skb_list(struct sk_buff *skb, struct net_device *dev, bool *again);
index ec87dea..08bf6c8 100644 (file)
@@ -252,7 +252,7 @@ static int vlandev_seq_show(struct seq_file *seq, void *offset)
 
        stats = dev_get_stats(vlandev, &temp);
        seq_printf(seq,
-                  "%s  VID: %d  REORDER_HDR: %i  dev->priv_flags: %hx\n",
+                  "%s  VID: %d  REORDER_HDR: %i  dev->priv_flags: %llx\n",
                   vlandev->name, vlan->vlan_id,
                   (int)(vlan->flags & 1), vlandev->priv_flags);
 
index 9c4fc8c..823917d 100644 (file)
@@ -8558,35 +8558,17 @@ bool netdev_port_same_parent_id(struct net_device *a, struct net_device *b)
 EXPORT_SYMBOL(netdev_port_same_parent_id);
 
 /**
- *     dev_change_proto_down - update protocol port state information
+ *     dev_change_proto_down - set carrier according to proto_down.
+ *
  *     @dev: device
  *     @proto_down: new value
- *
- *     This info can be used by switch drivers to set the phys state of the
- *     port.
  */
 int dev_change_proto_down(struct net_device *dev, bool proto_down)
 {
-       const struct net_device_ops *ops = dev->netdev_ops;
-
-       if (!ops->ndo_change_proto_down)
+       if (!(dev->priv_flags & IFF_CHANGE_PROTO_DOWN))
                return -EOPNOTSUPP;
        if (!netif_device_present(dev))
                return -ENODEV;
-       return ops->ndo_change_proto_down(dev, proto_down);
-}
-EXPORT_SYMBOL(dev_change_proto_down);
-
-/**
- *     dev_change_proto_down_generic - generic implementation for
- *     ndo_change_proto_down that sets carrier according to
- *     proto_down.
- *
- *     @dev: device
- *     @proto_down: new value
- */
-int dev_change_proto_down_generic(struct net_device *dev, bool proto_down)
-{
        if (proto_down)
                netif_carrier_off(dev);
        else
@@ -8594,7 +8576,7 @@ int dev_change_proto_down_generic(struct net_device *dev, bool proto_down)
        dev->proto_down = proto_down;
        return 0;
 }
-EXPORT_SYMBOL(dev_change_proto_down_generic);
+EXPORT_SYMBOL(dev_change_proto_down);
 
 /**
  *     dev_change_proto_down_reason - proto down reason
index 4edd58d..affe34d 100644 (file)
@@ -488,14 +488,6 @@ static ssize_t proto_down_store(struct device *dev,
                                struct device_attribute *attr,
                                const char *buf, size_t len)
 {
-       struct net_device *netdev = to_net_dev(dev);
-
-       /* The check is also done in change_proto_down; this helps returning
-        * early without hitting the trylock/restart in netdev_store.
-        */
-       if (!netdev->netdev_ops->ndo_change_proto_down)
-               return -EOPNOTSUPP;
-
        return netdev_store(dev, attr, buf, len, change_proto_down);
 }
 NETDEVICE_SHOW_RW(proto_down, fmt_dec);
index fd030e0..6f25c0a 100644 (file)
@@ -2539,13 +2539,12 @@ static int do_set_proto_down(struct net_device *dev,
                             struct netlink_ext_ack *extack)
 {
        struct nlattr *pdreason[IFLA_PROTO_DOWN_REASON_MAX + 1];
-       const struct net_device_ops *ops = dev->netdev_ops;
        unsigned long mask = 0;
        u32 value;
        bool proto_down;
        int err;
 
-       if (!ops->ndo_change_proto_down) {
+       if (!(dev->priv_flags & IFF_CHANGE_PROTO_DOWN)) {
                NL_SET_ERR_MSG(extack,  "Protodown not supported by device");
                return -EOPNOTSUPP;
        }