net/mlx5: Support state get/set for satellite PF ports

Extend mlx5_devlink_pf_port_fn_state_get() to support satellite PF
vports by querying their vhca_state from the query_esw_functions output
using the vport's vhca_id.

Extend mlx5_devlink_pf_port_fn_state_set() to support satellite PFs by
using the generic mlx5_esw_pf_enable/disable_hca() functions.

Signed-off-by: Moshe Shemesh <moshe@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260521110843.367329-11-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Moshe Shemesh 2026-05-21 14:08:41 +03:00 committed by Jakub Kicinski
parent ac338d8011
commit 425ac0e7a6
3 changed files with 52 additions and 11 deletions

View File

@ -1208,6 +1208,33 @@ mlx5_esw_get_host_pf_info(struct mlx5_core_dev *dev, const u32 *out)
return mlx5_esw_host_pf_from_host_params(entry);
}
bool mlx5_esw_get_spf_disabled(struct mlx5_core_dev *dev, const u32 *out,
u16 vhca_id)
{
int num_entries;
const u8 *entry;
int i;
num_entries = MLX5_GET(query_esw_functions_out, out, net_function_num);
entry = MLX5_ADDR_OF(query_esw_functions_out, out, net_function_params);
for (i = 0; i < num_entries; i++) {
u16 entry_vhca_id = MLX5_GET(network_function_params,
entry, vhca_id);
if (entry_vhca_id == vhca_id) {
int state;
state = MLX5_GET(network_function_params, entry,
vhca_state);
return state != MLX5_VHCA_STATE_IN_USE;
}
entry += MLX5_UN_SZ_BYTES(net_function_params);
}
return true;
}
static int mlx5_esw_host_functions_enabled_query(struct mlx5_eswitch *esw)
{
struct mlx5_esw_pf_info host_pf_info;
@ -1475,7 +1502,7 @@ static int mlx5_eswitch_load_ec_vf_vports(struct mlx5_eswitch *esw, u16 num_ec_v
return err;
}
static int mlx5_esw_pf_enable_hca(struct mlx5_core_dev *dev, u16 vport_num)
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;
@ -1501,7 +1528,7 @@ static int mlx5_esw_pf_enable_hca(struct mlx5_core_dev *dev, u16 vport_num)
return 0;
}
static int mlx5_esw_pf_disable_hca(struct mlx5_core_dev *dev, u16 vport_num)
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;

View File

@ -672,6 +672,10 @@ bool mlx5_esw_multipath_prereq(struct mlx5_core_dev *dev0,
const u32 *mlx5_esw_query_functions(struct mlx5_core_dev *dev);
struct mlx5_esw_pf_info mlx5_esw_get_host_pf_info(struct mlx5_core_dev *dev,
const u32 *out);
bool mlx5_esw_get_spf_disabled(struct mlx5_core_dev *dev, const u32 *out,
u16 vhca_id);
int mlx5_esw_pf_enable_hca(struct mlx5_core_dev *dev, u16 vport_num);
int mlx5_esw_pf_disable_hca(struct mlx5_core_dev *dev, u16 vport_num);
int mlx5_esw_host_pf_enable_hca(struct mlx5_core_dev *dev);
int mlx5_esw_host_pf_disable_hca(struct mlx5_core_dev *dev);

View File

@ -4961,10 +4961,11 @@ int mlx5_devlink_pf_port_fn_state_get(struct devlink_port *port,
struct netlink_ext_ack *extack)
{
struct mlx5_vport *vport = mlx5_devlink_port_vport_get(port);
struct mlx5_esw_pf_info host_pf_info;
struct mlx5_eswitch *esw = vport->dev->priv.eswitch;
const u32 *query_out;
bool pf_disabled;
if (vport->vport != MLX5_VPORT_HOST_PF) {
if (mlx5_eswitch_is_vf_vport(esw, vport->vport)) {
NL_SET_ERR_MSG_MOD(extack, "State get is not supported for VF");
return -EOPNOTSUPP;
}
@ -4976,11 +4977,19 @@ int mlx5_devlink_pf_port_fn_state_get(struct devlink_port *port,
if (IS_ERR(query_out))
return PTR_ERR(query_out);
host_pf_info = mlx5_esw_get_host_pf_info(vport->dev, query_out);
if (vport->vport == MLX5_VPORT_HOST_PF) {
struct mlx5_esw_pf_info host_pf_info;
*opstate = host_pf_info.pf_disabled ?
DEVLINK_PORT_FN_OPSTATE_DETACHED :
DEVLINK_PORT_FN_OPSTATE_ATTACHED;
host_pf_info = mlx5_esw_get_host_pf_info(vport->dev,
query_out);
pf_disabled = host_pf_info.pf_disabled;
} else {
pf_disabled = mlx5_esw_get_spf_disabled(vport->dev, query_out,
vport->vhca_id);
}
*opstate = pf_disabled ? DEVLINK_PORT_FN_OPSTATE_DETACHED :
DEVLINK_PORT_FN_OPSTATE_ATTACHED;
kvfree(query_out);
return 0;
@ -4991,9 +5000,10 @@ int mlx5_devlink_pf_port_fn_state_set(struct devlink_port *port,
struct netlink_ext_ack *extack)
{
struct mlx5_vport *vport = mlx5_devlink_port_vport_get(port);
struct mlx5_eswitch *esw = vport->dev->priv.eswitch;
struct mlx5_core_dev *dev;
if (vport->vport != MLX5_VPORT_HOST_PF) {
if (mlx5_eswitch_is_vf_vport(esw, vport->vport)) {
NL_SET_ERR_MSG_MOD(extack, "State set is not supported for VF");
return -EOPNOTSUPP;
}
@ -5002,9 +5012,9 @@ int mlx5_devlink_pf_port_fn_state_set(struct devlink_port *port,
switch (state) {
case DEVLINK_PORT_FN_STATE_ACTIVE:
return mlx5_esw_host_pf_enable_hca(dev);
return mlx5_esw_pf_enable_hca(dev, vport->vport);
case DEVLINK_PORT_FN_STATE_INACTIVE:
return mlx5_esw_host_pf_disable_hca(dev);
return mlx5_esw_pf_disable_hca(dev, vport->vport);
default:
return -EOPNOTSUPP;
}