return ERR_PTR(err);
}
+static struct mlx5_esw_pf_info
+mlx5_esw_host_pf_from_host_params(const void *entry)
+{
+ return (struct mlx5_esw_pf_info) {
+ .pf_not_exist = MLX5_GET(host_params_context, entry,
+ host_pf_not_exist),
+ .pf_disabled = MLX5_GET(host_params_context, entry,
+ host_pf_disabled),
+ .num_of_vfs = MLX5_GET(host_params_context, entry,
+ host_num_of_vfs),
+ .total_vfs = MLX5_GET(host_params_context, entry,
+ host_total_vfs),
+ .host_number = MLX5_GET(host_params_context, entry,
+ host_number),
+ };
+}
+
+struct mlx5_esw_pf_info mlx5_esw_get_host_pf_info(const u32 *out)
+{
+ const void *entry;
+
+ entry = MLX5_ADDR_OF(query_esw_functions_out, out, net_function_params);
+
+ return mlx5_esw_host_pf_from_host_params(entry);
+}
+
static int mlx5_esw_host_functions_enabled_query(struct mlx5_eswitch *esw)
{
+ struct mlx5_esw_pf_info host_pf_info;
const u32 *query_host_out;
- void *host_params;
if (!mlx5_core_is_ecpf_esw_manager(esw->dev))
return 0;
if (IS_ERR(query_host_out))
return PTR_ERR(query_host_out);
- host_params = MLX5_ADDR_OF(query_esw_functions_out,
- query_host_out, net_function_params);
- esw->esw_funcs.host_funcs_disabled =
- MLX5_GET(host_params_context, host_params,
- host_pf_not_exist);
+ host_pf_info = mlx5_esw_get_host_pf_info(query_host_out);
+ esw->esw_funcs.host_funcs_disabled = host_pf_info.pf_not_exist;
kvfree(query_host_out);
return 0;
static void
mlx5_eswitch_update_num_of_vfs(struct mlx5_eswitch *esw, int num_vfs)
{
- void *host_params;
+ struct mlx5_esw_pf_info host_pf_info;
const u32 *out;
if (num_vfs < 0)
if (IS_ERR(out))
return;
- host_params = MLX5_ADDR_OF(query_esw_functions_out, out,
- net_function_params);
- esw->esw_funcs.num_vfs = MLX5_GET(host_params_context, host_params,
- host_num_of_vfs);
+ host_pf_info = mlx5_esw_get_host_pf_info(out);
+ esw->esw_funcs.num_vfs = host_pf_info.num_of_vfs;
if (mlx5_core_ec_sriov_enabled(esw->dev))
esw->esw_funcs.num_ec_vfs = num_vfs;
};
};
+struct mlx5_esw_pf_info {
+ bool pf_not_exist;
+ bool pf_disabled;
+ u16 num_of_vfs;
+ u16 total_vfs;
+ u16 host_number;
+};
+
#ifdef CONFIG_MLX5_ESWITCH
#define ESW_OFFLOADS_DEFAULT_NUM_GROUPS 15
struct mlx5_core_dev *dev1);
const u32 *mlx5_esw_query_functions(struct mlx5_core_dev *dev);
+struct mlx5_esw_pf_info mlx5_esw_get_host_pf_info(const u32 *out);
int mlx5_esw_host_pf_enable_hca(struct mlx5_core_dev *dev);
int mlx5_esw_host_pf_disable_hca(struct mlx5_core_dev *dev);
return ERR_PTR(-EOPNOTSUPP);
}
+static inline struct mlx5_esw_pf_info
+mlx5_esw_get_host_pf_info(const u32 *out)
+{
+ return (struct mlx5_esw_pf_info) {};
+}
+
static inline struct mlx5_flow_handle *
esw_add_restore_rule(struct mlx5_eswitch *esw, u32 tag)
{
static void esw_vfs_changed_event_handler(struct mlx5_eswitch *esw)
{
- bool host_pf_disabled;
- void *host_params;
+ struct mlx5_esw_pf_info host_pf_info;
u16 new_num_vfs;
const u32 *out;
if (IS_ERR(out))
return;
- host_params = MLX5_ADDR_OF(query_esw_functions_out, out,
- net_function_params);
- new_num_vfs = MLX5_GET(host_params_context, host_params,
- host_num_of_vfs);
- host_pf_disabled = MLX5_GET(host_params_context, host_params,
- host_pf_disabled);
+ host_pf_info = mlx5_esw_get_host_pf_info(out);
+ new_num_vfs = host_pf_info.num_of_vfs;
- if (new_num_vfs == esw->esw_funcs.num_vfs || host_pf_disabled)
+ if (new_num_vfs == esw->esw_funcs.num_vfs || host_pf_info.pf_disabled)
goto free;
mlx5_esw_reps_block(esw);
static int mlx5_esw_host_number_init(struct mlx5_eswitch *esw)
{
+ struct mlx5_esw_pf_info host_pf_info;
const u32 *query_host_out;
- void *host_params;
if (!mlx5_core_is_ecpf_esw_manager(esw->dev))
return 0;
return PTR_ERR(query_host_out);
/* Mark non local controller with non zero controller number. */
- host_params = MLX5_ADDR_OF(query_esw_functions_out,
- query_host_out, net_function_params);
- esw->offloads.host_number = MLX5_GET(host_params_context,
- host_params, host_number);
+ host_pf_info = mlx5_esw_get_host_pf_info(query_host_out);
+ esw->offloads.host_number = host_pf_info.host_number;
kvfree(query_host_out);
return 0;
}
struct netlink_ext_ack *extack)
{
struct mlx5_vport *vport = mlx5_devlink_port_vport_get(port);
+ struct mlx5_esw_pf_info host_pf_info;
const u32 *query_out;
- void *host_params;
- bool pf_disabled;
if (vport->vport != MLX5_VPORT_HOST_PF) {
NL_SET_ERR_MSG_MOD(extack, "State get is not supported for VF");
if (IS_ERR(query_out))
return PTR_ERR(query_out);
- host_params = MLX5_ADDR_OF(query_esw_functions_out, query_out,
- net_function_params);
- pf_disabled = MLX5_GET(host_params_context, host_params,
- host_pf_disabled);
+ host_pf_info = mlx5_esw_get_host_pf_info(query_out);
- *opstate = pf_disabled ? DEVLINK_PORT_FN_OPSTATE_DETACHED :
- DEVLINK_PORT_FN_OPSTATE_ATTACHED;
+ *opstate = host_pf_info.pf_disabled ?
+ DEVLINK_PORT_FN_OPSTATE_DETACHED :
+ DEVLINK_PORT_FN_OPSTATE_ATTACHED;
kvfree(query_out);
return 0;
static u16 mlx5_get_max_vfs(struct mlx5_core_dev *dev)
{
+ struct mlx5_esw_pf_info host_pf_info;
u16 host_total_vfs;
- void *host_params;
const u32 *out;
if (mlx5_core_is_ecpf_esw_manager(dev)) {
*/
if (IS_ERR(out))
goto done;
- host_params = MLX5_ADDR_OF(query_esw_functions_out, out,
- net_function_params);
- host_total_vfs = MLX5_GET(host_params_context, host_params,
- host_total_vfs);
+ host_pf_info = mlx5_esw_get_host_pf_info(out);
+ host_total_vfs = host_pf_info.total_vfs;
kvfree(out);
return host_total_vfs;
}