From: Tariq Toukan <tariqt@nvidia.com>
To: Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>
Cc: Saeed Mahameed <saeedm@nvidia.com>,
Leon Romanovsky <leon@kernel.org>,
Tariq Toukan <tariqt@nvidia.com>, Mark Bloch <mbloch@nvidia.com>,
"Moshe Shemesh" <moshe@nvidia.com>,
Akiva Goldberger <agoldberger@nvidia.com>,
<netdev@vger.kernel.org>, <linux-rdma@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, Gal Pressman <gal@nvidia.com>,
Dragos Tatulea <dtatulea@nvidia.com>
Subject: [PATCH net-next 1/8] net/mlx5: Use helper to parse host PF info
Date: Sun, 10 May 2026 08:34:41 +0300 [thread overview]
Message-ID: <20260510053448.326823-2-tariqt@nvidia.com> (raw)
In-Reply-To: <20260510053448.326823-1-tariqt@nvidia.com>
From: Moshe Shemesh <moshe@nvidia.com>
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>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../net/ethernet/mellanox/mlx5/core/eswitch.c | 43 ++++++++++++++-----
.../net/ethernet/mellanox/mlx5/core/eswitch.h | 15 +++++++
.../mellanox/mlx5/core/eswitch_offloads.c | 34 ++++++---------
.../net/ethernet/mellanox/mlx5/core/sriov.c | 8 ++--
4 files changed, 62 insertions(+), 38 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
index 43c40353b2d8..861e79ddb489 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
@@ -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;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
index 291271afa96c..cfaae59a6e7c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
@@ -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)
{
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
index d95af87a4f5f..217c2fe6b690 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
@@ -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;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sriov.c b/drivers/net/ethernet/mellanox/mlx5/core/sriov.c
index 6eb6026eadd6..79f76c456d72 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/sriov.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sriov.c
@@ -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;
}
--
2.44.0
next prev parent reply other threads:[~2026-05-10 5:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-10 5:34 [PATCH net-next 0/8] net/mlx5: Prepare eswitch infrastructure for satellite PF support Tariq Toukan
2026-05-10 5:34 ` Tariq Toukan [this message]
2026-05-10 5:34 ` [PATCH net-next 2/8] net/mlx5: Use v1 response layout for query_esw_functions Tariq Toukan
2026-05-10 5:34 ` [PATCH net-next 3/8] net/mlx5: Use mlx5_eswitch_is_vf_vport() for IPsec VF checks Tariq Toukan
2026-05-10 5:34 ` [PATCH net-next 4/8] net/mlx5: Switch vport HCA cap helpers to kvzalloc Tariq Toukan
2026-05-10 5:34 ` [PATCH net-next 5/8] net/mlx5: Add mlx5_vport_set_other_func_general_cap macro Tariq Toukan
2026-05-10 5:34 ` [PATCH net-next 6/8] net/mlx5: Refactor mlx5_set_msix_vec_count() SET_HCA_CAP Tariq Toukan
2026-05-10 5:34 ` [PATCH net-next 7/8] net/mlx5: Use vport helper for IPsec eswitch set caps Tariq Toukan
2026-05-10 5:34 ` [PATCH net-next 8/8] net/mlx5: Generalize enable/disable HCA for any PF vport Tariq Toukan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260510053448.326823-2-tariqt@nvidia.com \
--to=tariqt@nvidia.com \
--cc=agoldberger@nvidia.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=dtatulea@nvidia.com \
--cc=edumazet@google.com \
--cc=gal@nvidia.com \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mbloch@nvidia.com \
--cc=moshe@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=saeedm@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox