Skip to content

Commit 0eb62b9

Browse files
Rony Efraimdavem330
authored andcommitted
net/mlx4: Add structures to keep VF Ethernet ports information
This patch add struct mlx4_vport_state where all the parameters related to management of VFs port (virtual ports of the NIC eswitch) are kept. The driver keeps an administrative and operational copy of the settings. The current administrative copy becomes operational on the event of probing a VF either on a VM or on the host. 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 6ce71ac commit 0eb62b9

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,16 @@ static int mlx4_master_process_vhcr(struct mlx4_dev *dev, int slave,
14901490
return ret;
14911491
}
14921492

1493+
static int mlx4_master_activate_admin_state(struct mlx4_priv *priv, int slave)
1494+
{
1495+
int port;
1496+
for (port = 1; port <= MLX4_MAX_PORTS; port++) {
1497+
priv->mfunc.master.vf_oper[slave].vport[port].state =
1498+
priv->mfunc.master.vf_admin[slave].vport[port];
1499+
}
1500+
return 0;
1501+
}
1502+
14931503
static void mlx4_master_do_cmd(struct mlx4_dev *dev, int slave, u8 cmd,
14941504
u16 param, u8 toggle)
14951505
{
@@ -1556,6 +1566,7 @@ static void mlx4_master_do_cmd(struct mlx4_dev *dev, int slave, u8 cmd,
15561566
if (slave_state[slave].last_cmd != MLX4_COMM_CMD_VHCR2)
15571567
goto reset_slave;
15581568
slave_state[slave].vhcr_dma |= param;
1569+
mlx4_master_activate_admin_state(priv, slave);
15591570
slave_state[slave].active = true;
15601571
mlx4_dispatch_event(dev, MLX4_DEV_EVENT_SLAVE_INIT, slave);
15611572
break;
@@ -1732,6 +1743,18 @@ int mlx4_multi_func_init(struct mlx4_dev *dev)
17321743
if (!priv->mfunc.master.slave_state)
17331744
goto err_comm;
17341745

1746+
priv->mfunc.master.vf_admin =
1747+
kzalloc(dev->num_slaves *
1748+
sizeof(struct mlx4_vf_admin_state), GFP_KERNEL);
1749+
if (!priv->mfunc.master.vf_admin)
1750+
goto err_comm_admin;
1751+
1752+
priv->mfunc.master.vf_oper =
1753+
kzalloc(dev->num_slaves *
1754+
sizeof(struct mlx4_vf_oper_state), GFP_KERNEL);
1755+
if (!priv->mfunc.master.vf_oper)
1756+
goto err_comm_oper;
1757+
17351758
for (i = 0; i < dev->num_slaves; ++i) {
17361759
s_state = &priv->mfunc.master.slave_state[i];
17371760
s_state->last_cmd = MLX4_COMM_CMD_RESET;
@@ -1752,6 +1775,9 @@ int mlx4_multi_func_init(struct mlx4_dev *dev)
17521775
goto err_slaves;
17531776
}
17541777
INIT_LIST_HEAD(&s_state->mcast_filters[port]);
1778+
priv->mfunc.master.vf_admin[i].vport[port].default_vlan = MLX4_VGT;
1779+
priv->mfunc.master.vf_oper[i].vport[port].vlan_idx = NO_INDX;
1780+
priv->mfunc.master.vf_oper[i].vport[port].mac_idx = NO_INDX;
17551781
}
17561782
spin_lock_init(&s_state->lock);
17571783
}
@@ -1800,6 +1826,10 @@ int mlx4_multi_func_init(struct mlx4_dev *dev)
18001826
for (port = 1; port <= MLX4_MAX_PORTS; port++)
18011827
kfree(priv->mfunc.master.slave_state[i].vlan_filter[port]);
18021828
}
1829+
kfree(priv->mfunc.master.vf_oper);
1830+
err_comm_oper:
1831+
kfree(priv->mfunc.master.vf_admin);
1832+
err_comm_admin:
18031833
kfree(priv->mfunc.master.slave_state);
18041834
err_comm:
18051835
iounmap(priv->mfunc.comm);
@@ -1874,6 +1904,8 @@ void mlx4_multi_func_cleanup(struct mlx4_dev *dev)
18741904
kfree(priv->mfunc.master.slave_state[i].vlan_filter[port]);
18751905
}
18761906
kfree(priv->mfunc.master.slave_state);
1907+
kfree(priv->mfunc.master.vf_admin);
1908+
kfree(priv->mfunc.master.vf_oper);
18771909
}
18781910

18791911
iounmap(priv->mfunc.comm);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,7 @@ int mlx4_QUERY_PORT_wrapper(struct mlx4_dev *dev, int slave,
816816
struct mlx4_cmd_mailbox *outbox,
817817
struct mlx4_cmd_info *cmd)
818818
{
819+
struct mlx4_priv *priv = mlx4_priv(dev);
819820
u64 def_mac;
820821
u8 port_type;
821822
u16 short_field;
@@ -833,6 +834,9 @@ int mlx4_QUERY_PORT_wrapper(struct mlx4_dev *dev, int slave,
833834
/* set slave default_mac address */
834835
MLX4_GET(def_mac, outbox->buf, QUERY_PORT_MAC_OFFSET);
835836
def_mac += slave << 8;
837+
/* if config MAC in DB use it */
838+
if (priv->mfunc.master.vf_oper[slave].vport[vhcr->in_modifier].state.mac)
839+
def_mac = priv->mfunc.master.vf_oper[slave].vport[vhcr->in_modifier].state.mac;
836840
MLX4_PUT(outbox->buf, def_mac, QUERY_PORT_MAC_OFFSET);
837841

838842
/* get port type - currently only eth is enabled */

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,30 @@ struct mlx4_slave_state {
473473
enum slave_port_state port_state[MLX4_MAX_PORTS + 1];
474474
};
475475

476+
#define MLX4_VGT 4095
477+
#define NO_INDX (-1)
478+
479+
struct mlx4_vport_state {
480+
u64 mac;
481+
u16 default_vlan;
482+
u8 default_qos;
483+
u32 tx_rate;
484+
bool spoofchk;
485+
};
486+
487+
struct mlx4_vf_admin_state {
488+
struct mlx4_vport_state vport[MLX4_MAX_PORTS + 1];
489+
};
490+
491+
struct mlx4_vport_oper_state {
492+
struct mlx4_vport_state state;
493+
int mac_idx;
494+
int vlan_idx;
495+
};
496+
struct mlx4_vf_oper_state {
497+
struct mlx4_vport_oper_state vport[MLX4_MAX_PORTS + 1];
498+
};
499+
476500
struct slave_list {
477501
struct mutex mutex;
478502
struct list_head res_list[MLX4_NUM_OF_RESOURCE_TYPE];
@@ -503,6 +527,8 @@ struct mlx4_master_qp0_state {
503527

504528
struct mlx4_mfunc_master_ctx {
505529
struct mlx4_slave_state *slave_state;
530+
struct mlx4_vf_admin_state *vf_admin;
531+
struct mlx4_vf_oper_state *vf_oper;
506532
struct mlx4_master_qp0_state qp0_state[MLX4_MAX_PORTS + 1];
507533
int init_port_ref[MLX4_MAX_PORTS + 1];
508534
u16 max_mtu[MLX4_MAX_PORTS + 1];

0 commit comments

Comments
 (0)