Commit 1d8faf48c74b8329a0322dc4b2a2030ae5003c86

Authored by Rony Efraim
Committed by David S. Miller
1 parent 3dc6475c0c

net/core: Add VF link state control

Add netlink directives and ndo entry to allow for controling
VF link, which can be in one of three states:

Auto - VF link state reflects the PF link state (default)

Up - VF link state is up, traffic from VF to VF works even if
the actual PF link is down

Down - VF link state is down, no traffic from/to this VF, can be of
use while configuring the VF

Signed-off-by: Rony Efraim <ronye@mellanox.com>
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 4 changed files with 37 additions and 2 deletions Side-by-side Diff

include/linux/if_link.h
... ... @@ -12,6 +12,7 @@
12 12 __u32 qos;
13 13 __u32 tx_rate;
14 14 __u32 spoofchk;
  15 + __u32 linkstate;
15 16 };
16 17 #endif /* _LINUX_IF_LINK_H */
include/linux/netdevice.h
... ... @@ -829,6 +829,7 @@
829 829 * int (*ndo_set_vf_spoofchk)(struct net_device *dev, int vf, bool setting);
830 830 * int (*ndo_get_vf_config)(struct net_device *dev,
831 831 * int vf, struct ifla_vf_info *ivf);
  832 + * int (*ndo_set_vf_link_state)(struct net_device *dev, int vf, int link_state);
832 833 * int (*ndo_set_vf_port)(struct net_device *dev, int vf,
833 834 * struct nlattr *port[]);
834 835 * int (*ndo_get_vf_port)(struct net_device *dev, int vf, struct sk_buff *skb);
... ... @@ -986,6 +987,8 @@
986 987 int (*ndo_get_vf_config)(struct net_device *dev,
987 988 int vf,
988 989 struct ifla_vf_info *ivf);
  990 + int (*ndo_set_vf_link_state)(struct net_device *dev,
  991 + int vf, int link_state);
989 992 int (*ndo_set_vf_port)(struct net_device *dev,
990 993 int vf,
991 994 struct nlattr *port[]);
include/uapi/linux/if_link.h
... ... @@ -338,6 +338,7 @@
338 338 IFLA_VF_VLAN,
339 339 IFLA_VF_TX_RATE, /* TX Bandwidth Allocation */
340 340 IFLA_VF_SPOOFCHK, /* Spoof Checking on/off switch */
  341 + IFLA_VF_LINK_STATE, /* link state enable/disable/auto switch */
341 342 __IFLA_VF_MAX,
342 343 };
343 344  
... ... @@ -362,6 +363,18 @@
362 363 struct ifla_vf_spoofchk {
363 364 __u32 vf;
364 365 __u32 setting;
  366 +};
  367 +
  368 +enum {
  369 + IFLA_VF_LINK_STATE_AUTO, /* link state of the uplink */
  370 + IFLA_VF_LINK_STATE_ENABLE, /* link always up */
  371 + IFLA_VF_LINK_STATE_DISABLE, /* link always down */
  372 + __IFLA_VF_LINK_STATE_MAX,
  373 +};
  374 +
  375 +struct ifla_vf_link_state {
  376 + __u32 vf;
  377 + __u32 link_state;
365 378 };
366 379  
367 380 /* VF ports management section
net/core/rtnetlink.c
... ... @@ -947,6 +947,7 @@
947 947 struct ifla_vf_vlan vf_vlan;
948 948 struct ifla_vf_tx_rate vf_tx_rate;
949 949 struct ifla_vf_spoofchk vf_spoofchk;
  950 + struct ifla_vf_link_state vf_linkstate;
950 951  
951 952 /*
952 953 * Not all SR-IOV capable drivers support the
953 954  
954 955  
... ... @@ -956,18 +957,24 @@
956 957 */
957 958 ivi.spoofchk = -1;
958 959 memset(ivi.mac, 0, sizeof(ivi.mac));
  960 + /* The default value for VF link state is "auto"
  961 + * IFLA_VF_LINK_STATE_AUTO which equals zero
  962 + */
  963 + ivi.linkstate = 0;
959 964 if (dev->netdev_ops->ndo_get_vf_config(dev, i, &ivi))
960 965 break;
961 966 vf_mac.vf =
962 967 vf_vlan.vf =
963 968 vf_tx_rate.vf =
964   - vf_spoofchk.vf = ivi.vf;
  969 + vf_spoofchk.vf =
  970 + vf_linkstate.vf = ivi.vf;
965 971  
966 972 memcpy(vf_mac.mac, ivi.mac, sizeof(ivi.mac));
967 973 vf_vlan.vlan = ivi.vlan;
968 974 vf_vlan.qos = ivi.qos;
969 975 vf_tx_rate.rate = ivi.tx_rate;
970 976 vf_spoofchk.setting = ivi.spoofchk;
  977 + vf_linkstate.link_state = ivi.linkstate;
971 978 vf = nla_nest_start(skb, IFLA_VF_INFO);
972 979 if (!vf) {
973 980 nla_nest_cancel(skb, vfinfo);
... ... @@ -978,7 +985,9 @@
978 985 nla_put(skb, IFLA_VF_TX_RATE, sizeof(vf_tx_rate),
979 986 &vf_tx_rate) ||
980 987 nla_put(skb, IFLA_VF_SPOOFCHK, sizeof(vf_spoofchk),
981   - &vf_spoofchk))
  988 + &vf_spoofchk) ||
  989 + nla_put(skb, IFLA_VF_LINK_STATE, sizeof(vf_linkstate),
  990 + &vf_linkstate))
982 991 goto nla_put_failure;
983 992 nla_nest_end(skb, vf);
984 993 }
... ... @@ -1236,6 +1245,15 @@
1236 1245 if (ops->ndo_set_vf_spoofchk)
1237 1246 err = ops->ndo_set_vf_spoofchk(dev, ivs->vf,
1238 1247 ivs->setting);
  1248 + break;
  1249 + }
  1250 + case IFLA_VF_LINK_STATE: {
  1251 + struct ifla_vf_link_state *ivl;
  1252 + ivl = nla_data(vf);
  1253 + err = -EOPNOTSUPP;
  1254 + if (ops->ndo_set_vf_link_state)
  1255 + err = ops->ndo_set_vf_link_state(dev, ivl->vf,
  1256 + ivl->link_state);
1239 1257 break;
1240 1258 }
1241 1259 default: