net/mlx5: Generalize enable/disable HCA for any PF vport

Refactor the host-PF-specific mlx5_cmd_host_pf_enable/disable_hca()
into generic mlx5_cmd_pf_enable/disable_hca() that accept a vport
number. The new functions use vhca_id as function_id when supported.

Similarly, refactor the eswitch layer into generic static helpers
mlx5_esw_pf_enable/disable_hca() with thin wrappers for the host PF
case, in preparation for enable_hca on satellite PF vports.

Signed-off-by: Moshe Shemesh <moshe@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260518071356.345723-9-tariqt@nvidia.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
Moshe Shemesh 2026-05-18 10:13:56 +03:00 committed by Paolo Abeni
parent d7ec361003
commit 4a3b5efee2
5 changed files with 42 additions and 20 deletions

View File

@ -18,25 +18,35 @@ static bool mlx5_ecpf_esw_admins_host_pf(const struct mlx5_core_dev *dev)
return mlx5_core_is_ecpf_esw_manager(dev);
}
int mlx5_cmd_host_pf_enable_hca(struct mlx5_core_dev *dev)
int mlx5_cmd_pf_enable_hca(struct mlx5_core_dev *dev, u16 vport_num)
{
u32 out[MLX5_ST_SZ_DW(enable_hca_out)] = {};
u32 in[MLX5_ST_SZ_DW(enable_hca_in)] = {};
u16 vhca_id;
MLX5_SET(enable_hca_in, in, opcode, MLX5_CMD_OP_ENABLE_HCA);
MLX5_SET(enable_hca_in, in, function_id, 0);
MLX5_SET(enable_hca_in, in, embedded_cpu_function, 0);
return mlx5_cmd_exec(dev, &in, sizeof(in), &out, sizeof(out));
if (mlx5_vport_use_vhca_id_as_func_id(dev, vport_num, &vhca_id)) {
MLX5_SET(enable_hca_in, in, function_id, vhca_id);
MLX5_SET(enable_hca_in, in, function_id_type, 1);
} else {
MLX5_SET(enable_hca_in, in, function_id, vport_num);
}
return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
}
int mlx5_cmd_host_pf_disable_hca(struct mlx5_core_dev *dev)
int mlx5_cmd_pf_disable_hca(struct mlx5_core_dev *dev, u16 vport_num)
{
u32 out[MLX5_ST_SZ_DW(disable_hca_out)] = {};
u32 in[MLX5_ST_SZ_DW(disable_hca_in)] = {};
u16 vhca_id;
MLX5_SET(disable_hca_in, in, opcode, MLX5_CMD_OP_DISABLE_HCA);
MLX5_SET(disable_hca_in, in, function_id, 0);
MLX5_SET(disable_hca_in, in, embedded_cpu_function, 0);
if (mlx5_vport_use_vhca_id_as_func_id(dev, vport_num, &vhca_id)) {
MLX5_SET(disable_hca_in, in, function_id, vhca_id);
MLX5_SET(disable_hca_in, in, function_id_type, 1);
} else {
MLX5_SET(disable_hca_in, in, function_id, vport_num);
}
return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
}

View File

@ -17,8 +17,8 @@ bool mlx5_read_embedded_cpu(struct mlx5_core_dev *dev);
int mlx5_ec_init(struct mlx5_core_dev *dev);
void mlx5_ec_cleanup(struct mlx5_core_dev *dev);
int mlx5_cmd_host_pf_enable_hca(struct mlx5_core_dev *dev);
int mlx5_cmd_host_pf_disable_hca(struct mlx5_core_dev *dev);
int mlx5_cmd_pf_enable_hca(struct mlx5_core_dev *dev, u16 vport_num);
int mlx5_cmd_pf_disable_hca(struct mlx5_core_dev *dev, u16 vport_num);
#else /* CONFIG_MLX5_ESWITCH */

View File

@ -1452,7 +1452,7 @@ static int mlx5_eswitch_load_ec_vf_vports(struct mlx5_eswitch *esw, u16 num_ec_v
return err;
}
int mlx5_esw_host_pf_enable_hca(struct mlx5_core_dev *dev)
static int mlx5_esw_pf_enable_hca(struct mlx5_core_dev *dev, u16 vport_num)
{
struct mlx5_eswitch *esw = dev->priv.eswitch;
struct mlx5_vport *vport;
@ -1461,15 +1461,15 @@ int mlx5_esw_host_pf_enable_hca(struct mlx5_core_dev *dev)
if (!mlx5_core_is_ecpf(dev) || !mlx5_esw_allowed(esw))
return 0;
vport = mlx5_eswitch_get_vport(esw, MLX5_VPORT_HOST_PF);
vport = mlx5_eswitch_get_vport(esw, vport_num);
if (IS_ERR(vport))
return PTR_ERR(vport);
/* Once vport and representor are ready, take out the external host PF
* out of initializing state. Enabling HCA clears the iser->initializing
* bit and host PF driver loading can progress.
/* Once vport and representor are ready, take the PF out of
* initializing state. Enabling HCA clears the iser->initializing
* bit and PF driver loading can progress.
*/
err = mlx5_cmd_host_pf_enable_hca(dev);
err = mlx5_cmd_pf_enable_hca(dev, vport_num);
if (err)
return err;
@ -1478,7 +1478,7 @@ int mlx5_esw_host_pf_enable_hca(struct mlx5_core_dev *dev)
return 0;
}
int mlx5_esw_host_pf_disable_hca(struct mlx5_core_dev *dev)
static int mlx5_esw_pf_disable_hca(struct mlx5_core_dev *dev, u16 vport_num)
{
struct mlx5_eswitch *esw = dev->priv.eswitch;
struct mlx5_vport *vport;
@ -1487,11 +1487,11 @@ int mlx5_esw_host_pf_disable_hca(struct mlx5_core_dev *dev)
if (!mlx5_core_is_ecpf(dev) || !mlx5_esw_allowed(esw))
return 0;
vport = mlx5_eswitch_get_vport(esw, MLX5_VPORT_HOST_PF);
vport = mlx5_eswitch_get_vport(esw, vport_num);
if (IS_ERR(vport))
return PTR_ERR(vport);
err = mlx5_cmd_host_pf_disable_hca(dev);
err = mlx5_cmd_pf_disable_hca(dev, vport_num);
if (err)
return err;
@ -1500,6 +1500,16 @@ int mlx5_esw_host_pf_disable_hca(struct mlx5_core_dev *dev)
return 0;
}
int mlx5_esw_host_pf_enable_hca(struct mlx5_core_dev *dev)
{
return mlx5_esw_pf_enable_hca(dev, MLX5_VPORT_HOST_PF);
}
int mlx5_esw_host_pf_disable_hca(struct mlx5_core_dev *dev)
{
return mlx5_esw_pf_disable_hca(dev, MLX5_VPORT_HOST_PF);
}
/* mlx5_eswitch_enable_pf_vf_vports() enables vports of PF, ECPF and VFs
* whichever are present on the eswitch.
*/

View File

@ -452,6 +452,8 @@ void mlx5_unload_one_light(struct mlx5_core_dev *dev);
void mlx5_query_nic_sw_system_image_guid(struct mlx5_core_dev *mdev, u8 *buf,
u8 *len);
bool mlx5_vport_use_vhca_id_as_func_id(struct mlx5_core_dev *dev,
u16 vport_num, u16 *vhca_id);
int mlx5_vport_set_other_func_cap(struct mlx5_core_dev *dev, const void *hca_cap, u16 vport,
u16 opmod);
#define mlx5_vport_get_other_func_general_cap(dev, vport, out) \

View File

@ -1283,8 +1283,8 @@ void mlx5_query_nic_sw_system_image_guid(struct mlx5_core_dev *mdev, u8 *buf,
buf[(*len)++] = MLX5_CAP_GEN_2(mdev, load_balance_id);
}
static bool mlx5_vport_use_vhca_id_as_func_id(struct mlx5_core_dev *dev,
u16 vport_num, u16 *vhca_id)
bool mlx5_vport_use_vhca_id_as_func_id(struct mlx5_core_dev *dev,
u16 vport_num, u16 *vhca_id)
{
if (!MLX5_CAP_GEN_2(dev, function_id_type_vhca_id))
return false;