net/mlx4: Add VF link state support
authorRony Efraim <ronye@mellanox.com>
Thu, 13 Jun 2013 10:19:11 +0000 (13:19 +0300)
committerDavid S. Miller <davem@davemloft.net>
Fri, 14 Jun 2013 00:51:04 +0000 (17:51 -0700)
Add support to change the link state of VF (vPort)

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>
drivers/net/ethernet/mellanox/mlx4/cmd.c
drivers/net/ethernet/mellanox/mlx4/en_netdev.c
drivers/net/ethernet/mellanox/mlx4/eq.c
drivers/net/ethernet/mellanox/mlx4/fw.c
drivers/net/ethernet/mellanox/mlx4/mlx4.h
include/linux/mlx4/cmd.h

index 0e572a527154acc13e29e01293bacf9688cfca66..ea1e038963538418f375a367e0d5a6d36d040e3e 100644 (file)
@@ -39,6 +39,7 @@
 #include <linux/errno.h>
 
 #include <linux/mlx4/cmd.h>
+#include <linux/mlx4/device.h>
 #include <linux/semaphore.h>
 #include <rdma/ib_smi.h>
 
@@ -2178,7 +2179,54 @@ int mlx4_get_vf_config(struct mlx4_dev *dev, int port, int vf, struct ifla_vf_in
        ivf->qos        = s_info->default_qos;
        ivf->tx_rate    = s_info->tx_rate;
        ivf->spoofchk   = s_info->spoofchk;
+       ivf->linkstate  = s_info->link_state;
 
        return 0;
 }
 EXPORT_SYMBOL_GPL(mlx4_get_vf_config);
+
+int mlx4_set_vf_link_state(struct mlx4_dev *dev, int port, int vf, int link_state)
+{
+       struct mlx4_priv *priv = mlx4_priv(dev);
+       struct mlx4_vport_state *s_info;
+       struct mlx4_vport_oper_state *vp_oper;
+       int slave;
+       u8 link_stat_event;
+
+       slave = mlx4_get_slave_indx(dev, vf);
+       if (slave < 0)
+               return -EINVAL;
+
+       switch (link_state) {
+       case IFLA_VF_LINK_STATE_AUTO:
+               /* get current link state */
+               if (!priv->sense.do_sense_port[port])
+                       link_stat_event = MLX4_PORT_CHANGE_SUBTYPE_ACTIVE;
+               else
+                       link_stat_event = MLX4_PORT_CHANGE_SUBTYPE_DOWN;
+           break;
+
+       case IFLA_VF_LINK_STATE_ENABLE:
+               link_stat_event = MLX4_PORT_CHANGE_SUBTYPE_ACTIVE;
+           break;
+
+       case IFLA_VF_LINK_STATE_DISABLE:
+               link_stat_event = MLX4_PORT_CHANGE_SUBTYPE_DOWN;
+           break;
+
+       default:
+               mlx4_warn(dev, "unknown value for link_state %02x on slave %d port %d\n",
+                         link_state, slave, port);
+               return -EINVAL;
+       };
+       /* update the admin & oper state on the link state */
+       s_info = &priv->mfunc.master.vf_admin[slave].vport[port];
+       vp_oper = &priv->mfunc.master.vf_oper[slave].vport[port];
+       s_info->link_state = link_state;
+       vp_oper->state.link_state = link_state;
+
+       /* send event */
+       mlx4_gen_port_state_change_eqe(dev, slave, port, link_stat_event);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(mlx4_set_vf_link_state);
index 89c47ea84b503ea9e1be08606d6e4937b6d6b178..ade276cca0e6bd9900636d10778445ee43fd838f 100644 (file)
@@ -2061,6 +2061,13 @@ static int mlx4_en_get_vf_config(struct net_device *dev, int vf, struct ifla_vf_
        return mlx4_get_vf_config(mdev->dev, en_priv->port, vf, ivf);
 }
 
+static int mlx4_en_set_vf_link_state(struct net_device *dev, int vf, int link_state)
+{
+       struct mlx4_en_priv *en_priv = netdev_priv(dev);
+       struct mlx4_en_dev *mdev = en_priv->mdev;
+
+       return mlx4_set_vf_link_state(mdev->dev, en_priv->port, vf, link_state);
+}
 static const struct net_device_ops mlx4_netdev_ops = {
        .ndo_open               = mlx4_en_open,
        .ndo_stop               = mlx4_en_close,
@@ -2101,6 +2108,7 @@ static const struct net_device_ops mlx4_netdev_ops_master = {
        .ndo_set_vf_mac         = mlx4_en_set_vf_mac,
        .ndo_set_vf_vlan        = mlx4_en_set_vf_vlan,
        .ndo_set_vf_spoofchk    = mlx4_en_set_vf_spoofchk,
+       .ndo_set_vf_link_state  = mlx4_en_set_vf_link_state,
        .ndo_get_vf_config      = mlx4_en_get_vf_config,
 #ifdef CONFIG_NET_POLL_CONTROLLER
        .ndo_poll_controller    = mlx4_en_netpoll,
index 6000342f9725db0f29e8bac3a249765e53c90173..7e042869ef0cd2d9c5884147edd7b1c7d582b868 100644 (file)
@@ -448,6 +448,7 @@ static int mlx4_eq_int(struct mlx4_dev *dev, struct mlx4_eq *eq)
        int i;
        enum slave_port_gen_event gen_event;
        unsigned long flags;
+       struct mlx4_vport_state *s_info;
 
        while ((eqe = next_eqe_sw(eq, dev->caps.eqe_factor))) {
                /*
@@ -556,7 +557,9 @@ static int mlx4_eq_int(struct mlx4_dev *dev, struct mlx4_eq *eq)
                                                mlx4_dbg(dev, "%s: Sending MLX4_PORT_CHANGE_SUBTYPE_DOWN"
                                                         " to slave: %d, port:%d\n",
                                                         __func__, i, port);
-                                               mlx4_slave_event(dev, i, eqe);
+                                               s_info = &priv->mfunc.master.vf_oper[slave].vport[port].state;
+                                               if (IFLA_VF_LINK_STATE_AUTO == s_info->link_state)
+                                                       mlx4_slave_event(dev, i, eqe);
                                        } else {  /* IB port */
                                                set_and_calc_slave_port_state(dev, i, port,
                                                                              MLX4_PORT_STATE_DEV_EVENT_PORT_DOWN,
@@ -580,7 +583,9 @@ static int mlx4_eq_int(struct mlx4_dev *dev, struct mlx4_eq *eq)
                                        for (i = 0; i < dev->num_slaves; i++) {
                                                if (i == mlx4_master_func_num(dev))
                                                        continue;
-                                               mlx4_slave_event(dev, i, eqe);
+                                               s_info = &priv->mfunc.master.vf_oper[slave].vport[port].state;
+                                               if (IFLA_VF_LINK_STATE_AUTO == s_info->link_state)
+                                                       mlx4_slave_event(dev, i, eqe);
                                        }
                                else /* IB port */
                                        /* port-up event will be sent to a slave when the
index 2c97901c6a6d2ff79231e294c5fd1d5622255263..569bbe3e7403596b918d2c011d2c3c5448c5f6bb 100644 (file)
@@ -830,8 +830,10 @@ int mlx4_QUERY_PORT_wrapper(struct mlx4_dev *dev, int slave,
        u8 port_type;
        u16 short_field;
        int err;
+       int admin_link_state;
 
 #define MLX4_VF_PORT_NO_LINK_SENSE_MASK        0xE0
+#define MLX4_PORT_LINK_UP_MASK         0x80
 #define QUERY_PORT_CUR_MAX_PKEY_OFFSET 0x0c
 #define QUERY_PORT_CUR_MAX_GID_OFFSET  0x0e
 
@@ -861,6 +863,12 @@ int mlx4_QUERY_PORT_wrapper(struct mlx4_dev *dev, int slave,
                /* set port type to currently operating port type */
                port_type |= (dev->caps.port_type[vhcr->in_modifier] & 0x3);
 
+               admin_link_state = priv->mfunc.master.vf_oper[slave].vport[vhcr->in_modifier].state.link_state;
+               if (IFLA_VF_LINK_STATE_ENABLE == admin_link_state)
+                       port_type |= MLX4_PORT_LINK_UP_MASK;
+               else if (IFLA_VF_LINK_STATE_DISABLE == admin_link_state)
+                       port_type &= ~MLX4_PORT_LINK_UP_MASK;
+
                MLX4_PUT(outbox->buf, port_type,
                         QUERY_PORT_SUPPORTED_TYPE_OFFSET);
 
index df15bb6631cc7d6f68b70191e891321f505fe00b..75272935a3f74e42c31bdd774e6aab5f0bcf1854 100644 (file)
@@ -482,6 +482,7 @@ struct mlx4_vport_state {
        u8  default_qos;
        u32 tx_rate;
        bool spoofchk;
+       u32 link_state;
 };
 
 struct mlx4_vf_admin_state {
index adf6e0648f20cb209413a2137f0b688862a7e559..8074a9711cf1c1f3957088c8a73efe838eb6bd38 100644 (file)
@@ -237,7 +237,7 @@ int mlx4_set_vf_mac(struct mlx4_dev *dev, int port, int vf, u64 mac);
 int mlx4_set_vf_vlan(struct mlx4_dev *dev, int port, int vf, u16 vlan, u8 qos);
 int mlx4_set_vf_spoofchk(struct mlx4_dev *dev, int port, int vf, bool setting);
 int mlx4_get_vf_config(struct mlx4_dev *dev, int port, int vf, struct ifla_vf_info *ivf);
-
+int mlx4_set_vf_link_state(struct mlx4_dev *dev, int port, int vf, int link_state);
 
 #define MLX4_COMM_GET_IF_REV(cmd_chan_ver) (u8)((cmd_chan_ver) >> 8)