Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+31 -21
+4 -2
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
··· 820 820 821 821 hca_caps = MLX5_ADDR_OF(query_hca_cap_out, query_ctx, capability); 822 822 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); 823 824 824 825 if (!MLX5_CAP_GEN_MAX(esw->dev, hca_cap_2)) 825 826 goto out_free; ··· 930 929 931 930 if (!mlx5_esw_is_manager_vport(esw, vport_num) && 932 931 MLX5_CAP_GEN(esw->dev, vhca_resource_manager)) { 933 - ret = mlx5_esw_vport_vhca_id_set(esw, vport_num); 932 + ret = mlx5_esw_vport_vhca_id_map(esw, vport); 934 933 if (ret) 935 934 goto err_vhca_mapping; 936 935 } ··· 974 973 975 974 if (!mlx5_esw_is_manager_vport(esw, vport_num) && 976 975 MLX5_CAP_GEN(esw->dev, vhca_resource_manager)) 977 - mlx5_esw_vport_vhca_id_clear(esw, vport_num); 976 + mlx5_esw_vport_vhca_id_unmap(esw, vport); 978 977 979 978 if (vport->vport != MLX5_VPORT_PF && 980 979 (vport->info.ipsec_crypto_enabled || vport->info.ipsec_packet_enabled)) ··· 1711 1710 vport->vport = vport_num; 1712 1711 vport->index = index; 1713 1712 vport->info.link_state = MLX5_VPORT_ADMIN_STATE_AUTO; 1713 + vport->vhca_id = MLX5_VHCA_ID_INVALID; 1714 1714 INIT_WORK(&vport->vport_change_handler, esw_vport_change_handler); 1715 1715 err = xa_insert(&esw->vports, vport_num, vport, GFP_KERNEL); 1716 1716 if (err)
+10 -2
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
··· 197 197 return mlx5_devlink_port_get(dl_port)->vport; 198 198 } 199 199 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 + 200 205 struct mlx5_vport { 201 206 struct mlx5_core_dev *dev; 202 207 struct hlist_head uc_list[MLX5_L2_ADDR_HASH_SIZE]; ··· 214 209 struct vport_egress egress; 215 210 u32 default_metadata; 216 211 u32 metadata; 212 + int vhca_id; 217 213 218 214 struct mlx5_vport_info info; 219 215 ··· 828 822 829 823 int mlx5_esw_sf_max_hpf_functions(struct mlx5_core_dev *dev, u16 *max_sfs, u16 *sf_base_id); 830 824 831 - int mlx5_esw_vport_vhca_id_set(struct mlx5_eswitch *esw, u16 vport_num); 832 - void mlx5_esw_vport_vhca_id_clear(struct mlx5_eswitch *esw, u16 vport_num); 825 + int mlx5_esw_vport_vhca_id_map(struct mlx5_eswitch *esw, 826 + struct mlx5_vport *vport); 827 + void mlx5_esw_vport_vhca_id_unmap(struct mlx5_eswitch *esw, 828 + struct mlx5_vport *vport); 833 829 int mlx5_eswitch_vhca_id_to_vport(struct mlx5_eswitch *esw, u16 vhca_id, u16 *vport_num); 834 830 835 831 /**
+17 -17
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
··· 4161 4161 } 4162 4162 EXPORT_SYMBOL(mlx5_eswitch_get_vport_metadata_for_match); 4163 4163 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) 4165 4166 { 4166 4167 u16 *old_entry, *vhca_map_entry, vhca_id; 4167 - int err; 4168 4168 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; 4174 4178 } 4175 4179 4180 + vhca_id = vport->vhca_id; 4176 4181 vhca_map_entry = kmalloc(sizeof(*vhca_map_entry), GFP_KERNEL); 4177 4182 if (!vhca_map_entry) 4178 4183 return -ENOMEM; 4179 4184 4180 - *vhca_map_entry = vport_num; 4185 + *vhca_map_entry = vport->vport; 4181 4186 old_entry = xa_store(&esw->offloads.vhca_map, vhca_id, vhca_map_entry, GFP_KERNEL); 4182 4187 if (xa_is_err(old_entry)) { 4183 4188 kfree(vhca_map_entry); ··· 4192 4187 return 0; 4193 4188 } 4194 4189 4195 - void mlx5_esw_vport_vhca_id_clear(struct mlx5_eswitch *esw, u16 vport_num) 4190 + void mlx5_esw_vport_vhca_id_unmap(struct mlx5_eswitch *esw, 4191 + struct mlx5_vport *vport) 4196 4192 { 4197 - u16 *vhca_map_entry, vhca_id; 4198 - int err; 4193 + u16 *vhca_map_entry; 4199 4194 4200 - err = mlx5_vport_get_vhca_id(esw->dev, vport_num, &vhca_id); 4201 - if (err) 4202 - esw_warn(esw->dev, "Getting vhca_id for vport failed (vport=%hu,err=%d)\n", 4203 - vport_num, err); 4204 - 4205 - vhca_map_entry = xa_erase(&esw->offloads.vhca_map, vhca_id); 4195 + vhca_map_entry = xa_erase(&esw->offloads.vhca_map, vport->vhca_id); 4206 4196 kfree(vhca_map_entry); 4207 4197 } 4208 4198