Skip to content

Commit

Permalink
net/mlx5: Split mac address setting function for using state_lock
Browse files Browse the repository at this point in the history
Refactor mac address setting function to let caller hold the necessary
state_lock mutex, so that subsequent patch and use this helper routine.

Signed-off-by: Parav Pandit <parav@mellanox.com>
Reviewed-by: Roi Dayan <roid@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
paravmellanox authored and davem330 committed Jun 22, 2020
1 parent f099fde commit 1094795
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1801,46 +1801,56 @@ void mlx5_eswitch_cleanup(struct mlx5_eswitch *esw)
}

/* Vport Administration */
int mlx5_eswitch_set_vport_mac(struct mlx5_eswitch *esw,
u16 vport, const u8 *mac)
static int
mlx5_esw_set_vport_mac_locked(struct mlx5_eswitch *esw,
struct mlx5_vport *evport, const u8 *mac)
{
struct mlx5_vport *evport = mlx5_eswitch_get_vport(esw, vport);
u16 vport_num = evport->vport;
u64 node_guid;
int err = 0;

if (IS_ERR(evport))
return PTR_ERR(evport);
if (is_multicast_ether_addr(mac))
return -EINVAL;

mutex_lock(&esw->state_lock);

if (evport->info.spoofchk && !is_valid_ether_addr(mac))
mlx5_core_warn(esw->dev,
"Set invalid MAC while spoofchk is on, vport(%d)\n",
vport);
vport_num);

err = mlx5_modify_nic_vport_mac_address(esw->dev, vport, mac);
err = mlx5_modify_nic_vport_mac_address(esw->dev, vport_num, mac);
if (err) {
mlx5_core_warn(esw->dev,
"Failed to mlx5_modify_nic_vport_mac vport(%d) err=(%d)\n",
vport, err);
goto unlock;
vport_num, err);
return err;
}

node_guid_gen_from_mac(&node_guid, mac);
err = mlx5_modify_nic_vport_node_guid(esw->dev, vport, node_guid);
err = mlx5_modify_nic_vport_node_guid(esw->dev, vport_num, node_guid);
if (err)
mlx5_core_warn(esw->dev,
"Failed to set vport %d node guid, err = %d. RDMA_CM will not function properly for this VF.\n",
vport, err);
vport_num, err);

ether_addr_copy(evport->info.mac, mac);
evport->info.node_guid = node_guid;
if (evport->enabled && esw->mode == MLX5_ESWITCH_LEGACY)
err = esw_acl_ingress_lgcy_setup(esw, evport);

unlock:
return err;
}

int mlx5_eswitch_set_vport_mac(struct mlx5_eswitch *esw,
u16 vport, const u8 *mac)
{
struct mlx5_vport *evport = mlx5_eswitch_get_vport(esw, vport);
int err = 0;

if (IS_ERR(evport))
return PTR_ERR(evport);

mutex_lock(&esw->state_lock);
err = mlx5_esw_set_vport_mac_locked(esw, evport, mac);
mutex_unlock(&esw->state_lock);
return err;
}
Expand Down

0 comments on commit 1094795

Please sign in to comment.