Skip to content

Commit 1baf304

Browse files
author
Saeed Mahameed
committed
net/mlx5: E-Switch, Set/Query hca cap via vhca id
Dynamically created vports require vhca id as input to set/query other vport hca cap, when FW is capable and the vhca id of a vport is valid use it instead of the local function id. Signed-off-by: Saeed Mahameed <saeedm@nvidia.com> Signed-off-by: Adithya Jayachandran <ajayachandra@nvidia.com> Reviewed-by: Parav Pandit <parav@nvidia.com> Reviewed-by: Feng Liu <feliu@nvidia.com> Reviewed-by: William Tu <witu@nvidia.com> Reviewed-by: Mark Bloch <mbloch@nvidia.com>
1 parent 864c05b commit 1baf304

3 files changed

Lines changed: 68 additions & 5 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,18 @@ static int mlx5_esw_vport_caps_get(struct mlx5_eswitch *esw, struct mlx5_vport *
840840
return err;
841841
}
842842

843+
bool mlx5_esw_vport_vhca_id(struct mlx5_eswitch *esw, u16 vportn, u16 *vhca_id)
844+
{
845+
struct mlx5_vport *vport;
846+
847+
vport = mlx5_eswitch_get_vport(esw, vportn);
848+
if (IS_ERR(vport) || MLX5_VPORT_INVAL_VHCA_ID(vport))
849+
return false;
850+
851+
*vhca_id = vport->vhca_id;
852+
return true;
853+
}
854+
843855
static int esw_vport_setup(struct mlx5_eswitch *esw, struct mlx5_vport *vport)
844856
{
845857
bool vst_mode_steering = esw_vst_mode_is_steering(esw);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ int mlx5_esw_vport_vhca_id_map(struct mlx5_eswitch *esw,
833833
void mlx5_esw_vport_vhca_id_unmap(struct mlx5_eswitch *esw,
834834
struct mlx5_vport *vport);
835835
int mlx5_eswitch_vhca_id_to_vport(struct mlx5_eswitch *esw, u16 vhca_id, u16 *vport_num);
836+
bool mlx5_esw_vport_vhca_id(struct mlx5_eswitch *esw, u16 vportn, u16 *vhca_id);
836837

837838
/**
838839
* struct mlx5_esw_event_info - Indicates eswitch mode changed/changing.
@@ -973,6 +974,13 @@ static inline bool mlx5_eswitch_block_ipsec(struct mlx5_core_dev *dev)
973974
}
974975

975976
static inline void mlx5_eswitch_unblock_ipsec(struct mlx5_core_dev *dev) {}
977+
978+
static inline bool
979+
mlx5_esw_vport_vhca_id(struct mlx5_eswitch *esw, u16 vportn, u16 *vhca_id)
980+
{
981+
return -EOPNOTSUPP;
982+
}
983+
976984
#endif /* CONFIG_MLX5_ESWITCH */
977985

978986
#endif /* __MLX5_ESWITCH_H__ */

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

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <linux/mlx5/vport.h>
3737
#include <linux/mlx5/eswitch.h>
3838
#include "mlx5_core.h"
39+
#include "eswitch.h"
3940
#include "sf/sf.h"
4041

4142
/* Mutex to hold while enabling or disabling RoCE */
@@ -1189,18 +1190,44 @@ u64 mlx5_query_nic_system_image_guid(struct mlx5_core_dev *mdev)
11891190
}
11901191
EXPORT_SYMBOL_GPL(mlx5_query_nic_system_image_guid);
11911192

1193+
static bool mlx5_vport_use_vhca_id_as_func_id(struct mlx5_core_dev *dev,
1194+
u16 vport_num, u16 *vhca_id)
1195+
{
1196+
if (!MLX5_CAP_GEN_2(dev, function_id_type_vhca_id))
1197+
return false;
1198+
1199+
return mlx5_esw_vport_vhca_id(dev->priv.eswitch, vport_num, vhca_id);
1200+
}
1201+
11921202
int mlx5_vport_get_other_func_cap(struct mlx5_core_dev *dev, u16 vport, void *out,
11931203
u16 opmod)
11941204
{
1195-
bool ec_vf_func = mlx5_core_is_ec_vf_vport(dev, vport);
11961205
u8 in[MLX5_ST_SZ_BYTES(query_hca_cap_in)] = {};
1206+
u16 vhca_id = 0, function_id = 0;
1207+
bool ec_vf_func = false;
1208+
1209+
/* if this vport is referring to a vport on the ec PF (embedded cpu )
1210+
* let the FW know which domain we are querying since vport numbers or
1211+
* function_ids are not unique across the different PF domains,
1212+
* unless we use vhca_id as the function_id below.
1213+
*/
1214+
ec_vf_func = mlx5_core_is_ec_vf_vport(dev, vport);
1215+
function_id = mlx5_vport_to_func_id(dev, vport, ec_vf_func);
1216+
1217+
if (mlx5_vport_use_vhca_id_as_func_id(dev, vport, &vhca_id)) {
1218+
MLX5_SET(query_hca_cap_in, in, function_id_type, 1);
1219+
function_id = vhca_id;
1220+
ec_vf_func = false;
1221+
mlx5_core_dbg(dev, "%s using vhca_id as function_id for vport %d vhca_id 0x%x\n",
1222+
__func__, vport, vhca_id);
1223+
}
11971224

11981225
opmod = (opmod << 1) | (HCA_CAP_OPMOD_GET_MAX & 0x01);
11991226
MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP);
12001227
MLX5_SET(query_hca_cap_in, in, op_mod, opmod);
1201-
MLX5_SET(query_hca_cap_in, in, function_id, mlx5_vport_to_func_id(dev, vport, ec_vf_func));
12021228
MLX5_SET(query_hca_cap_in, in, other_function, true);
12031229
MLX5_SET(query_hca_cap_in, in, ec_vf_function, ec_vf_func);
1230+
MLX5_SET(query_hca_cap_in, in, function_id, function_id);
12041231
return mlx5_cmd_exec_inout(dev, query_hca_cap, in, out);
12051232
}
12061233
EXPORT_SYMBOL_GPL(mlx5_vport_get_other_func_cap);
@@ -1233,8 +1260,9 @@ int mlx5_vport_get_vhca_id(struct mlx5_core_dev *dev, u16 vport, u16 *vhca_id)
12331260
int mlx5_vport_set_other_func_cap(struct mlx5_core_dev *dev, const void *hca_cap,
12341261
u16 vport, u16 opmod)
12351262
{
1236-
bool ec_vf_func = mlx5_core_is_ec_vf_vport(dev, vport);
12371263
int set_sz = MLX5_ST_SZ_BYTES(set_hca_cap_in);
1264+
u16 vhca_id = 0, function_id = 0;
1265+
bool ec_vf_func = false;
12381266
void *set_hca_cap;
12391267
void *set_ctx;
12401268
int ret;
@@ -1243,14 +1271,29 @@ int mlx5_vport_set_other_func_cap(struct mlx5_core_dev *dev, const void *hca_cap
12431271
if (!set_ctx)
12441272
return -ENOMEM;
12451273

1274+
/* if this vport is referring to a vport on the ec PF (embedded cpu )
1275+
* let the FW know which domain we are querying since vport numbers or
1276+
* function_ids are not unique across the different PF domains,
1277+
* unless we use vhca_id as the function_id below.
1278+
*/
1279+
ec_vf_func = mlx5_core_is_ec_vf_vport(dev, vport);
1280+
function_id = mlx5_vport_to_func_id(dev, vport, ec_vf_func);
1281+
1282+
if (mlx5_vport_use_vhca_id_as_func_id(dev, vport, &vhca_id)) {
1283+
MLX5_SET(set_hca_cap_in, set_ctx, function_id_type, 1);
1284+
function_id = vhca_id;
1285+
ec_vf_func = false;
1286+
mlx5_core_dbg(dev, "%s using vhca_id as function_id for vport %d vhca_id 0x%x\n",
1287+
__func__, vport, vhca_id);
1288+
}
1289+
12461290
MLX5_SET(set_hca_cap_in, set_ctx, opcode, MLX5_CMD_OP_SET_HCA_CAP);
12471291
MLX5_SET(set_hca_cap_in, set_ctx, op_mod, opmod << 1);
12481292
set_hca_cap = MLX5_ADDR_OF(set_hca_cap_in, set_ctx, capability);
12491293
memcpy(set_hca_cap, hca_cap, MLX5_ST_SZ_BYTES(cmd_hca_cap));
1250-
MLX5_SET(set_hca_cap_in, set_ctx, function_id,
1251-
mlx5_vport_to_func_id(dev, vport, ec_vf_func));
12521294
MLX5_SET(set_hca_cap_in, set_ctx, other_function, true);
12531295
MLX5_SET(set_hca_cap_in, set_ctx, ec_vf_function, ec_vf_func);
1296+
MLX5_SET(set_hca_cap_in, set_ctx, function_id, function_id);
12541297
ret = mlx5_cmd_exec_in(dev, set_hca_cap, set_ctx);
12551298

12561299
kfree(set_ctx);

0 commit comments

Comments
 (0)