Skip to content

Commit 948e306

Browse files
Rony Efraimdavem330
authored andcommitted
net/mlx4: Add VF link state support
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>
1 parent 1d8faf4 commit 948e306

6 files changed

Lines changed: 73 additions & 3 deletions

File tree

‎drivers/net/ethernet/mellanox/mlx4/cmd.c‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <linux/errno.h>
4040

4141
#include <linux/mlx4/cmd.h>
42+
#include <linux/mlx4/device.h>
4243
#include <linux/semaphore.h>
4344
#include <rdma/ib_smi.h>
4445

@@ -2178,7 +2179,54 @@ int mlx4_get_vf_config(struct mlx4_dev *dev, int port, int vf, struct ifla_vf_in
21782179
ivf->qos = s_info->default_qos;
21792180
ivf->tx_rate = s_info->tx_rate;
21802181
ivf->spoofchk = s_info->spoofchk;
2182+
ivf->linkstate = s_info->link_state;
21812183

21822184
return 0;
21832185
}
21842186
EXPORT_SYMBOL_GPL(mlx4_get_vf_config);
2187+
2188+
int mlx4_set_vf_link_state(struct mlx4_dev *dev, int port, int vf, int link_state)
2189+
{
2190+
struct mlx4_priv *priv = mlx4_priv(dev);
2191+
struct mlx4_vport_state *s_info;
2192+
struct mlx4_vport_oper_state *vp_oper;
2193+
int slave;
2194+
u8 link_stat_event;
2195+
2196+
slave = mlx4_get_slave_indx(dev, vf);
2197+
if (slave < 0)
2198+
return -EINVAL;
2199+
2200+
switch (link_state) {
2201+
case IFLA_VF_LINK_STATE_AUTO:
2202+
/* get current link state */
2203+
if (!priv->sense.do_sense_port[port])
2204+
link_stat_event = MLX4_PORT_CHANGE_SUBTYPE_ACTIVE;
2205+
else
2206+
link_stat_event = MLX4_PORT_CHANGE_SUBTYPE_DOWN;
2207+
break;
2208+
2209+
case IFLA_VF_LINK_STATE_ENABLE:
2210+
link_stat_event = MLX4_PORT_CHANGE_SUBTYPE_ACTIVE;
2211+
break;
2212+
2213+
case IFLA_VF_LINK_STATE_DISABLE:
2214+
link_stat_event = MLX4_PORT_CHANGE_SUBTYPE_DOWN;
2215+
break;
2216+
2217+
default:
2218+
mlx4_warn(dev, "unknown value for link_state %02x on slave %d port %d\n",
2219+
link_state, slave, port);
2220+
return -EINVAL;
2221+
};
2222+
/* update the admin & oper state on the link state */
2223+
s_info = &priv->mfunc.master.vf_admin[slave].vport[port];
2224+
vp_oper = &priv->mfunc.master.vf_oper[slave].vport[port];
2225+
s_info->link_state = link_state;
2226+
vp_oper->state.link_state = link_state;
2227+
2228+
/* send event */
2229+
mlx4_gen_port_state_change_eqe(dev, slave, port, link_stat_event);
2230+
return 0;
2231+
}
2232+
EXPORT_SYMBOL_GPL(mlx4_set_vf_link_state);

‎drivers/net/ethernet/mellanox/mlx4/en_netdev.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,13 @@ static int mlx4_en_get_vf_config(struct net_device *dev, int vf, struct ifla_vf_
20612061
return mlx4_get_vf_config(mdev->dev, en_priv->port, vf, ivf);
20622062
}
20632063

2064+
static int mlx4_en_set_vf_link_state(struct net_device *dev, int vf, int link_state)
2065+
{
2066+
struct mlx4_en_priv *en_priv = netdev_priv(dev);
2067+
struct mlx4_en_dev *mdev = en_priv->mdev;
2068+
2069+
return mlx4_set_vf_link_state(mdev->dev, en_priv->port, vf, link_state);
2070+
}
20642071
static const struct net_device_ops mlx4_netdev_ops = {
20652072
.ndo_open = mlx4_en_open,
20662073
.ndo_stop = mlx4_en_close,
@@ -2101,6 +2108,7 @@ static const struct net_device_ops mlx4_netdev_ops_master = {
21012108
.ndo_set_vf_mac = mlx4_en_set_vf_mac,
21022109
.ndo_set_vf_vlan = mlx4_en_set_vf_vlan,
21032110
.ndo_set_vf_spoofchk = mlx4_en_set_vf_spoofchk,
2111+
.ndo_set_vf_link_state = mlx4_en_set_vf_link_state,
21042112
.ndo_get_vf_config = mlx4_en_get_vf_config,
21052113
#ifdef CONFIG_NET_POLL_CONTROLLER
21062114
.ndo_poll_controller = mlx4_en_netpoll,

‎drivers/net/ethernet/mellanox/mlx4/eq.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ static int mlx4_eq_int(struct mlx4_dev *dev, struct mlx4_eq *eq)
448448
int i;
449449
enum slave_port_gen_event gen_event;
450450
unsigned long flags;
451+
struct mlx4_vport_state *s_info;
451452

452453
while ((eqe = next_eqe_sw(eq, dev->caps.eqe_factor))) {
453454
/*
@@ -556,7 +557,9 @@ static int mlx4_eq_int(struct mlx4_dev *dev, struct mlx4_eq *eq)
556557
mlx4_dbg(dev, "%s: Sending MLX4_PORT_CHANGE_SUBTYPE_DOWN"
557558
" to slave: %d, port:%d\n",
558559
__func__, i, port);
559-
mlx4_slave_event(dev, i, eqe);
560+
s_info = &priv->mfunc.master.vf_oper[slave].vport[port].state;
561+
if (IFLA_VF_LINK_STATE_AUTO == s_info->link_state)
562+
mlx4_slave_event(dev, i, eqe);
560563
} else { /* IB port */
561564
set_and_calc_slave_port_state(dev, i, port,
562565
MLX4_PORT_STATE_DEV_EVENT_PORT_DOWN,
@@ -580,7 +583,9 @@ static int mlx4_eq_int(struct mlx4_dev *dev, struct mlx4_eq *eq)
580583
for (i = 0; i < dev->num_slaves; i++) {
581584
if (i == mlx4_master_func_num(dev))
582585
continue;
583-
mlx4_slave_event(dev, i, eqe);
586+
s_info = &priv->mfunc.master.vf_oper[slave].vport[port].state;
587+
if (IFLA_VF_LINK_STATE_AUTO == s_info->link_state)
588+
mlx4_slave_event(dev, i, eqe);
584589
}
585590
else /* IB port */
586591
/* port-up event will be sent to a slave when the

‎drivers/net/ethernet/mellanox/mlx4/fw.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,8 +830,10 @@ int mlx4_QUERY_PORT_wrapper(struct mlx4_dev *dev, int slave,
830830
u8 port_type;
831831
u16 short_field;
832832
int err;
833+
int admin_link_state;
833834

834835
#define MLX4_VF_PORT_NO_LINK_SENSE_MASK 0xE0
836+
#define MLX4_PORT_LINK_UP_MASK 0x80
835837
#define QUERY_PORT_CUR_MAX_PKEY_OFFSET 0x0c
836838
#define QUERY_PORT_CUR_MAX_GID_OFFSET 0x0e
837839

@@ -861,6 +863,12 @@ int mlx4_QUERY_PORT_wrapper(struct mlx4_dev *dev, int slave,
861863
/* set port type to currently operating port type */
862864
port_type |= (dev->caps.port_type[vhcr->in_modifier] & 0x3);
863865

866+
admin_link_state = priv->mfunc.master.vf_oper[slave].vport[vhcr->in_modifier].state.link_state;
867+
if (IFLA_VF_LINK_STATE_ENABLE == admin_link_state)
868+
port_type |= MLX4_PORT_LINK_UP_MASK;
869+
else if (IFLA_VF_LINK_STATE_DISABLE == admin_link_state)
870+
port_type &= ~MLX4_PORT_LINK_UP_MASK;
871+
864872
MLX4_PUT(outbox->buf, port_type,
865873
QUERY_PORT_SUPPORTED_TYPE_OFFSET);
866874

‎drivers/net/ethernet/mellanox/mlx4/mlx4.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ struct mlx4_vport_state {
482482
u8 default_qos;
483483
u32 tx_rate;
484484
bool spoofchk;
485+
u32 link_state;
485486
};
486487

487488
struct mlx4_vf_admin_state {

‎include/linux/mlx4/cmd.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ int mlx4_set_vf_mac(struct mlx4_dev *dev, int port, int vf, u64 mac);
237237
int mlx4_set_vf_vlan(struct mlx4_dev *dev, int port, int vf, u16 vlan, u8 qos);
238238
int mlx4_set_vf_spoofchk(struct mlx4_dev *dev, int port, int vf, bool setting);
239239
int mlx4_get_vf_config(struct mlx4_dev *dev, int port, int vf, struct ifla_vf_info *ivf);
240-
240+
int mlx4_set_vf_link_state(struct mlx4_dev *dev, int port, int vf, int link_state);
241241

242242
#define MLX4_COMM_GET_IF_REV(cmd_chan_ver) (u8)((cmd_chan_ver) >> 8)
243243

0 commit comments

Comments
 (0)