]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net/mlx5: Use helper to parse host PF info
authorMoshe Shemesh <moshe@nvidia.com>
Mon, 18 May 2026 07:13:49 +0000 (10:13 +0300)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 21 May 2026 10:11:59 +0000 (12:11 +0200)
Add a helper mlx5_esw_get_host_pf_info() to retrieve host PF data from
the query_esw_functions command output, so callers no longer need to
parse the layout to obtain the required information.

Convert all callers of mlx5_esw_query_functions() to use the new helper,
preparing for upcoming support of the new op_mod that returns data in
the network_function_params layout.

Signed-off-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260518071356.345723-2-tariqt@nvidia.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
drivers/net/ethernet/mellanox/mlx5/core/sriov.c

index 43c40353b2d86cb65decd702b7cd6b53b5377b08..861e79ddb48979e1ebae711b32ce21e0428a5120 100644 (file)
@@ -1083,10 +1083,36 @@ const u32 *mlx5_esw_query_functions(struct mlx5_core_dev *dev)
        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;
@@ -1095,11 +1121,8 @@ static int mlx5_esw_host_functions_enabled_query(struct mlx5_eswitch *esw)
        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;
@@ -1523,7 +1546,7 @@ static void mlx5_eswitch_get_devlink_param(struct mlx5_eswitch *esw)
 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)
@@ -1538,10 +1561,8 @@ mlx5_eswitch_update_num_of_vfs(struct mlx5_eswitch *esw, int num_vfs)
        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;
 
index 291271afa96c43b44b46e71198f23a0c69d6af60..cfaae59a6e7cfdca0eb73b34b19de0fbe41202bb 100644 (file)
@@ -71,6 +71,14 @@ struct mlx5_mapped_obj {
        };
 };
 
+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
@@ -649,6 +657,7 @@ bool mlx5_esw_multipath_prereq(struct mlx5_core_dev *dev0,
                               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);
 
@@ -976,6 +985,12 @@ static inline const u32 *mlx5_esw_query_functions(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)
 {
index d95af87a4f5f23ad9f573c9315908becc6825920..217c2fe6b6903cd245a86823c8785a1984e2e4d4 100644 (file)
@@ -3708,8 +3708,7 @@ static void esw_offloads_steering_cleanup(struct mlx5_eswitch *esw)
 
 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;
 
@@ -3717,14 +3716,10 @@ static void esw_vfs_changed_event_handler(struct mlx5_eswitch *esw)
        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);
@@ -3826,8 +3821,8 @@ int mlx5_esw_funcs_changed_handler(struct notifier_block *nb,
 
 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;
@@ -3837,10 +3832,8 @@ static int mlx5_esw_host_number_init(struct mlx5_eswitch *esw)
                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;
 }
@@ -4980,9 +4973,8 @@ 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;
        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");
@@ -4996,13 +4988,11 @@ int mlx5_devlink_pf_port_fn_state_get(struct devlink_port *port,
        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;
index 6eb6026eadd626cd634d6530ecda9533c8cac16e..79f76c456d7257a80fae7d3a8df3f61cc0cedc62 100644 (file)
@@ -273,8 +273,8 @@ void mlx5_sriov_detach(struct mlx5_core_dev *dev)
 
 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)) {
@@ -285,10 +285,8 @@ static u16 mlx5_get_max_vfs(struct mlx5_core_dev *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;
        }