Skip to content

Commit 864c05b

Browse files
author
Saeed Mahameed
committed
net/mlx5: E-Switch, Cache vport vhca id on first cap query
We need vhca_id to set up the vhca_id to vport mapping for every vport, for that we query the firmware in mlx5_esw_vport_vhca_id_set, and it is redundant since in esw_vport_setup, we already query hca caps which has the vhca_id, cache it there and save 2 extra fw queries per vport. Signed-off-by: Saeed Mahameed <saeedm@nvidia.com> Reviewed-by: Mark Bloch <mbloch@nvidia.com> Reviewed-by: Parav Pandit <parav@nvidia.com> Signed-off-by: Alexei Lazar <alazar@nvidia.com> Reviewed-by: Feng Liu <feliu@nvidia.com>
1 parent 2335b3f commit 864c05b

3 files changed

Lines changed: 31 additions & 21 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,7 @@ static int mlx5_esw_vport_caps_get(struct mlx5_eswitch *esw, struct mlx5_vport *
820820

821821
hca_caps = MLX5_ADDR_OF(query_hca_cap_out, query_ctx, capability);
822822
vport->info.roce_enabled = MLX5_GET(cmd_hca_cap, hca_caps, roce);
823+
vport->vhca_id = MLX5_GET(cmd_hca_cap, hca_caps, vhca_id);
823824

824825
if (!MLX5_CAP_GEN_MAX(esw->dev, hca_cap_2))
825826
goto out_free;
@@ -929,7 +930,7 @@ int mlx5_esw_vport_enable(struct mlx5_eswitch *esw, struct mlx5_vport *vport,
929930

930931
if (!mlx5_esw_is_manager_vport(esw, vport_num) &&
931932
MLX5_CAP_GEN(esw->dev, vhca_resource_manager)) {
932-
ret = mlx5_esw_vport_vhca_id_set(esw, vport_num);
933+
ret = mlx5_esw_vport_vhca_id_map(esw, vport);
933934
if (ret)
934935
goto err_vhca_mapping;
935936
}
@@ -973,7 +974,7 @@ void mlx5_esw_vport_disable(struct mlx5_eswitch *esw, struct mlx5_vport *vport)
973974

974975
if (!mlx5_esw_is_manager_vport(esw, vport_num) &&
975976
MLX5_CAP_GEN(esw->dev, vhca_resource_manager))
976-
mlx5_esw_vport_vhca_id_clear(esw, vport_num);
977+
mlx5_esw_vport_vhca_id_unmap(esw, vport);
977978

978979
if (vport->vport != MLX5_VPORT_PF &&
979980
(vport->info.ipsec_crypto_enabled || vport->info.ipsec_packet_enabled))
@@ -1710,6 +1711,7 @@ static int mlx5_esw_vport_alloc(struct mlx5_eswitch *esw,
17101711
vport->vport = vport_num;
17111712
vport->index = index;
17121713
vport->info.link_state = MLX5_VPORT_ADMIN_STATE_AUTO;
1714+
vport->vhca_id = MLX5_VHCA_ID_INVALID;
17131715
INIT_WORK(&vport->vport_change_handler, esw_vport_change_handler);
17141716
err = xa_insert(&esw->vports, vport_num, vport, GFP_KERNEL);
17151717
if (err)

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ static inline struct mlx5_vport *mlx5_devlink_port_vport_get(struct devlink_port
197197
return mlx5_devlink_port_get(dl_port)->vport;
198198
}
199199

200+
#define MLX5_VHCA_ID_INVALID (-1)
201+
202+
#define MLX5_VPORT_INVAL_VHCA_ID(vport) \
203+
((vport)->vhca_id == MLX5_VHCA_ID_INVALID)
204+
200205
struct mlx5_vport {
201206
struct mlx5_core_dev *dev;
202207
struct hlist_head uc_list[MLX5_L2_ADDR_HASH_SIZE];
@@ -209,6 +214,7 @@ struct mlx5_vport {
209214
struct vport_egress egress;
210215
u32 default_metadata;
211216
u32 metadata;
217+
int vhca_id;
212218

213219
struct mlx5_vport_info info;
214220

@@ -822,8 +828,10 @@ struct devlink_port *mlx5_esw_offloads_devlink_port(struct mlx5_eswitch *esw, u1
822828

823829
int mlx5_esw_sf_max_hpf_functions(struct mlx5_core_dev *dev, u16 *max_sfs, u16 *sf_base_id);
824830

825-
int mlx5_esw_vport_vhca_id_set(struct mlx5_eswitch *esw, u16 vport_num);
826-
void mlx5_esw_vport_vhca_id_clear(struct mlx5_eswitch *esw, u16 vport_num);
831+
int mlx5_esw_vport_vhca_id_map(struct mlx5_eswitch *esw,
832+
struct mlx5_vport *vport);
833+
void mlx5_esw_vport_vhca_id_unmap(struct mlx5_eswitch *esw,
834+
struct mlx5_vport *vport);
827835
int mlx5_eswitch_vhca_id_to_vport(struct mlx5_eswitch *esw, u16 vhca_id, u16 *vport_num);
828836

829837
/**

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4161,23 +4161,28 @@ u32 mlx5_eswitch_get_vport_metadata_for_match(struct mlx5_eswitch *esw,
41614161
}
41624162
EXPORT_SYMBOL(mlx5_eswitch_get_vport_metadata_for_match);
41634163

4164-
int mlx5_esw_vport_vhca_id_set(struct mlx5_eswitch *esw, u16 vport_num)
4164+
int mlx5_esw_vport_vhca_id_map(struct mlx5_eswitch *esw,
4165+
struct mlx5_vport *vport)
41654166
{
41664167
u16 *old_entry, *vhca_map_entry, vhca_id;
4167-
int err;
41684168

4169-
err = mlx5_vport_get_vhca_id(esw->dev, vport_num, &vhca_id);
4170-
if (err) {
4171-
esw_warn(esw->dev, "Getting vhca_id for vport failed (vport=%u,err=%d)\n",
4172-
vport_num, err);
4173-
return err;
4169+
if (WARN_ONCE(MLX5_VPORT_INVAL_VHCA_ID(vport),
4170+
"vport %d vhca_id is not set", vport->vport)) {
4171+
int err;
4172+
4173+
err = mlx5_vport_get_vhca_id(vport->dev, vport->vport,
4174+
&vhca_id);
4175+
if (err)
4176+
return err;
4177+
vport->vhca_id = vhca_id;
41744178
}
41754179

4180+
vhca_id = vport->vhca_id;
41764181
vhca_map_entry = kmalloc(sizeof(*vhca_map_entry), GFP_KERNEL);
41774182
if (!vhca_map_entry)
41784183
return -ENOMEM;
41794184

4180-
*vhca_map_entry = vport_num;
4185+
*vhca_map_entry = vport->vport;
41814186
old_entry = xa_store(&esw->offloads.vhca_map, vhca_id, vhca_map_entry, GFP_KERNEL);
41824187
if (xa_is_err(old_entry)) {
41834188
kfree(vhca_map_entry);
@@ -4187,17 +4192,12 @@ int mlx5_esw_vport_vhca_id_set(struct mlx5_eswitch *esw, u16 vport_num)
41874192
return 0;
41884193
}
41894194

4190-
void mlx5_esw_vport_vhca_id_clear(struct mlx5_eswitch *esw, u16 vport_num)
4195+
void mlx5_esw_vport_vhca_id_unmap(struct mlx5_eswitch *esw,
4196+
struct mlx5_vport *vport)
41914197
{
4192-
u16 *vhca_map_entry, vhca_id;
4193-
int err;
4194-
4195-
err = mlx5_vport_get_vhca_id(esw->dev, vport_num, &vhca_id);
4196-
if (err)
4197-
esw_warn(esw->dev, "Getting vhca_id for vport failed (vport=%hu,err=%d)\n",
4198-
vport_num, err);
4198+
u16 *vhca_map_entry;
41994199

4200-
vhca_map_entry = xa_erase(&esw->offloads.vhca_map, vhca_id);
4200+
vhca_map_entry = xa_erase(&esw->offloads.vhca_map, vport->vhca_id);
42014201
kfree(vhca_map_entry);
42024202
}
42034203

0 commit comments

Comments
 (0)