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}
11901191EXPORT_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+
11921202int 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}
12061233EXPORT_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)
12331260int 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