Skip to content

Commit 1094795

Browse files
paravmellanoxdavem330
authored andcommitted
net/mlx5: Split mac address setting function for using state_lock
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 <[email protected]> Reviewed-by: Roi Dayan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f099fde commit 1094795

File tree

1 file changed

+24
-14
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+24
-14
lines changed

drivers/net/ethernet/mellanox/mlx5/core/eswitch.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,46 +1801,56 @@ void mlx5_eswitch_cleanup(struct mlx5_eswitch *esw)
18011801
}
18021802

18031803
/* Vport Administration */
1804-
int mlx5_eswitch_set_vport_mac(struct mlx5_eswitch *esw,
1805-
u16 vport, const u8 *mac)
1804+
static int
1805+
mlx5_esw_set_vport_mac_locked(struct mlx5_eswitch *esw,
1806+
struct mlx5_vport *evport, const u8 *mac)
18061807
{
1807-
struct mlx5_vport *evport = mlx5_eswitch_get_vport(esw, vport);
1808+
u16 vport_num = evport->vport;
18081809
u64 node_guid;
18091810
int err = 0;
18101811

1811-
if (IS_ERR(evport))
1812-
return PTR_ERR(evport);
18131812
if (is_multicast_ether_addr(mac))
18141813
return -EINVAL;
18151814

1816-
mutex_lock(&esw->state_lock);
1817-
18181815
if (evport->info.spoofchk && !is_valid_ether_addr(mac))
18191816
mlx5_core_warn(esw->dev,
18201817
"Set invalid MAC while spoofchk is on, vport(%d)\n",
1821-
vport);
1818+
vport_num);
18221819

1823-
err = mlx5_modify_nic_vport_mac_address(esw->dev, vport, mac);
1820+
err = mlx5_modify_nic_vport_mac_address(esw->dev, vport_num, mac);
18241821
if (err) {
18251822
mlx5_core_warn(esw->dev,
18261823
"Failed to mlx5_modify_nic_vport_mac vport(%d) err=(%d)\n",
1827-
vport, err);
1828-
goto unlock;
1824+
vport_num, err);
1825+
return err;
18291826
}
18301827

18311828
node_guid_gen_from_mac(&node_guid, mac);
1832-
err = mlx5_modify_nic_vport_node_guid(esw->dev, vport, node_guid);
1829+
err = mlx5_modify_nic_vport_node_guid(esw->dev, vport_num, node_guid);
18331830
if (err)
18341831
mlx5_core_warn(esw->dev,
18351832
"Failed to set vport %d node guid, err = %d. RDMA_CM will not function properly for this VF.\n",
1836-
vport, err);
1833+
vport_num, err);
18371834

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

1843-
unlock:
1840+
return err;
1841+
}
1842+
1843+
int mlx5_eswitch_set_vport_mac(struct mlx5_eswitch *esw,
1844+
u16 vport, const u8 *mac)
1845+
{
1846+
struct mlx5_vport *evport = mlx5_eswitch_get_vport(esw, vport);
1847+
int err = 0;
1848+
1849+
if (IS_ERR(evport))
1850+
return PTR_ERR(evport);
1851+
1852+
mutex_lock(&esw->state_lock);
1853+
err = mlx5_esw_set_vport_mac_locked(esw, evport, mac);
18441854
mutex_unlock(&esw->state_lock);
18451855
return err;
18461856
}

0 commit comments

Comments
 (0)