Netdev List
 help / color / mirror / Atom feed
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>,
	"Simon Horman" <horms@kernel.org>,
	Adithya Jayachandran <ajayachandra@nvidia.com>,
	Jiri Pirko <jiri@resnulli.us>, Moshe Shemesh <moshe@nvidia.com>,
	Or Har-Toov <ohartoov@nvidia.com>, Shay Drori <shayd@nvidia.com>,
	Parav Pandit <parav@nvidia.com>,
	Daniel Jurgens <danielj@nvidia.com>, Kees Cook <kees@kernel.org>,
	Cosmin Ratiu <cratiu@nvidia.com>,
	Carolina Jubran <cjubran@nvidia.com>, <netdev@vger.kernel.org>,
	<linux-rdma@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Gal Pressman <gal@nvidia.com>
Subject: [PATCH net-next 05/12] net/mlx5: Support SPF SFs in SF hardware table
Date: Thu, 21 May 2026 14:08:36 +0300	[thread overview]
Message-ID: <20260521110843.367329-6-tariqt@nvidia.com> (raw)
In-Reply-To: <20260521110843.367329-1-tariqt@nvidia.com>

From: Moshe Shemesh <moshe@nvidia.com>

Convert the SF hardware table from a fixed-size hwc array to a
dynamically allocated one, supporting satellite PF (SPF) SFs alongside
local and external host SFs. Initialize hwc entries for each SPF using
its host_number as controller. Rename MLX5_SF_HWC_EXTERNAL to
MLX5_SF_HWC_EXT_HOST and add MLX5_SF_HWC_FIRST_SPF for clarity.

Signed-off-by: Moshe Shemesh <moshe@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 .../ethernet/mellanox/mlx5/core/sf/hw_table.c | 89 ++++++++++++++-----
 1 file changed, 69 insertions(+), 20 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
index 049dfd431618..0bc9146a3598 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
@@ -21,25 +21,33 @@ struct mlx5_sf_hwc_table {
 	struct mlx5_sf_hw *sfs;
 	int max_fn;
 	u16 start_fn_id;
+	u32 controller;
 };
 
-enum mlx5_sf_hwc_index {
+enum {
 	MLX5_SF_HWC_LOCAL,
-	MLX5_SF_HWC_EXTERNAL,
-	MLX5_SF_HWC_MAX,
+	MLX5_SF_HWC_EXT_HOST,
+	MLX5_SF_HWC_FIRST_SPF,
 };
 
 struct mlx5_sf_hw_table {
 	struct mutex table_lock; /* Serializes sf deletion and vhca state change handler. */
-	struct mlx5_sf_hwc_table hwc[MLX5_SF_HWC_MAX];
+	struct mlx5_sf_hwc_table *hwc;
+	int num_hwc;
 };
 
 static struct mlx5_sf_hwc_table *
 mlx5_sf_controller_to_hwc(struct mlx5_core_dev *dev, u32 controller)
 {
-	int idx = !!controller;
+	struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table;
+	int i;
+
+	for (i = MLX5_SF_HWC_FIRST_SPF; i < table->num_hwc; i++) {
+		if (table->hwc[i].controller == controller)
+			return &table->hwc[i];
+	}
 
-	return &dev->priv.sf_hw_table->hwc[idx];
+	return &table->hwc[!!controller];
 }
 
 u16 mlx5_sf_sw_to_hw_id(struct mlx5_core_dev *dev, u32 controller, u16 sw_id)
@@ -60,7 +68,7 @@ mlx5_sf_table_fn_to_hwc(struct mlx5_sf_hw_table *table, u16 fn_id)
 {
 	int i;
 
-	for (i = 0; i < ARRAY_SIZE(table->hwc); i++) {
+	for (i = 0; i < table->num_hwc; i++) {
 		if (table->hwc[i].max_fn &&
 		    fn_id >= table->hwc[i].start_fn_id &&
 		    fn_id < (table->hwc[i].start_fn_id + table->hwc[i].max_fn))
@@ -221,9 +229,10 @@ static void mlx5_sf_hw_table_hwc_dealloc_all(struct mlx5_core_dev *dev,
 static void mlx5_sf_hw_table_dealloc_all(struct mlx5_core_dev *dev,
 					 struct mlx5_sf_hw_table *table)
 {
-	mlx5_sf_hw_table_hwc_dealloc_all(dev,
-					 &table->hwc[MLX5_SF_HWC_EXTERNAL]);
-	mlx5_sf_hw_table_hwc_dealloc_all(dev, &table->hwc[MLX5_SF_HWC_LOCAL]);
+	int i;
+
+	for (i = 0; i < table->num_hwc; i++)
+		mlx5_sf_hw_table_hwc_dealloc_all(dev, &table->hwc[i]);
 }
 
 static int mlx5_sf_hw_table_hwc_init(struct mlx5_sf_hwc_table *hwc, u16 max_fn, u16 base_id)
@@ -277,11 +286,13 @@ static int mlx5_sf_hw_table_res_register(struct mlx5_core_dev *dev, u16 max_fn,
 int mlx5_sf_hw_table_init(struct mlx5_core_dev *dev)
 {
 	struct mlx5_sf_hw_table *table;
+	int num_spfs, num_hwc;
 	u16 max_ext_fn = 0;
 	u16 ext_base_id = 0;
 	u16 base_id;
 	u16 max_fn;
 	int err;
+	int i;
 
 	if (!mlx5_vhca_event_supported(dev))
 		return 0;
@@ -295,7 +306,7 @@ int mlx5_sf_hw_table_init(struct mlx5_core_dev *dev)
 	if (mlx5_sf_hw_table_res_register(dev, max_fn, max_ext_fn))
 		mlx5_core_dbg(dev, "failed to register max SFs resources");
 
-	if (!max_fn && !max_ext_fn)
+	if (!max_fn && !max_ext_fn && !mlx5_esw_has_spf_sfs(dev))
 		return 0;
 
 	table = kzalloc_obj(*table);
@@ -304,26 +315,62 @@ int mlx5_sf_hw_table_init(struct mlx5_core_dev *dev)
 		goto alloc_err;
 	}
 
+	num_spfs = mlx5_esw_get_num_spfs(dev);
+	num_hwc = MLX5_SF_HWC_FIRST_SPF + num_spfs;
+	table->hwc = kcalloc(num_hwc, sizeof(*table->hwc), GFP_KERNEL);
+	if (!table->hwc) {
+		err = -ENOMEM;
+		goto hwc_alloc_err;
+	}
+	table->num_hwc = num_hwc;
+
 	mutex_init(&table->table_lock);
 	dev->priv.sf_hw_table = table;
 
+	table->hwc[MLX5_SF_HWC_LOCAL].controller = 0;
 	base_id = mlx5_sf_start_function_id(dev);
 	err = mlx5_sf_hw_table_hwc_init(&table->hwc[MLX5_SF_HWC_LOCAL], max_fn, base_id);
 	if (err)
-		goto table_err;
+		goto hwc_init_err;
 
-	err = mlx5_sf_hw_table_hwc_init(&table->hwc[MLX5_SF_HWC_EXTERNAL],
+	table->hwc[MLX5_SF_HWC_EXT_HOST].controller =
+		mlx5_esw_get_hpf_host_number(dev) + 1;
+	err = mlx5_sf_hw_table_hwc_init(&table->hwc[MLX5_SF_HWC_EXT_HOST],
 					max_ext_fn, ext_base_id);
 	if (err)
-		goto ext_err;
+		goto hwc_init_err;
+
+	for (i = 0; i < num_spfs; i++) {
+		u16 spf_max_sfs, spf_base_id, host_number;
+		int hwc_idx = MLX5_SF_HWC_FIRST_SPF + i;
+
+		err = mlx5_esw_spf_get_host_number(dev, i, &host_number);
+		if (err)
+			goto hwc_init_err;
+
+		err = mlx5_esw_sf_max_spf_functions(dev, i, &spf_max_sfs,
+						    &spf_base_id);
+		if (err)
+			goto hwc_init_err;
 
-	mlx5_core_dbg(dev, "SF HW table: max sfs = %d, ext sfs = %d\n", max_fn, max_ext_fn);
+		table->hwc[hwc_idx].controller = host_number + 1;
+		err = mlx5_sf_hw_table_hwc_init(&table->hwc[hwc_idx],
+						spf_max_sfs, spf_base_id);
+		if (err)
+			goto hwc_init_err;
+	}
+
+	mlx5_core_dbg(dev, "SF HW table: max sfs = %d, ext sfs = %d, num spfs = %d\n",
+		      max_fn, max_ext_fn, num_spfs);
 	return 0;
 
-ext_err:
-	mlx5_sf_hw_table_hwc_cleanup(&table->hwc[MLX5_SF_HWC_LOCAL]);
-table_err:
+hwc_init_err:
+	dev->priv.sf_hw_table = NULL;
+	for (i = 0; i < num_hwc; i++)
+		mlx5_sf_hw_table_hwc_cleanup(&table->hwc[i]);
 	mutex_destroy(&table->table_lock);
+	kfree(table->hwc);
+hwc_alloc_err:
 	kfree(table);
 alloc_err:
 	mlx5_sf_hw_table_res_unregister(dev);
@@ -333,13 +380,15 @@ int mlx5_sf_hw_table_init(struct mlx5_core_dev *dev)
 void mlx5_sf_hw_table_cleanup(struct mlx5_core_dev *dev)
 {
 	struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table;
+	int i;
 
 	if (!table)
 		goto res_unregister;
 
-	mlx5_sf_hw_table_hwc_cleanup(&table->hwc[MLX5_SF_HWC_EXTERNAL]);
-	mlx5_sf_hw_table_hwc_cleanup(&table->hwc[MLX5_SF_HWC_LOCAL]);
+	for (i = 0; i < table->num_hwc; i++)
+		mlx5_sf_hw_table_hwc_cleanup(&table->hwc[i]);
 	mutex_destroy(&table->table_lock);
+	kfree(table->hwc);
 	kfree(table);
 	dev->priv.sf_hw_table = NULL;
 res_unregister:
-- 
2.44.0


  parent reply	other threads:[~2026-05-21 11:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21 11:08 [PATCH net-next 00/12] net/mlx5: Add satellite PF support Tariq Toukan
2026-05-21 11:08 ` [PATCH net-next 01/12] net/mlx5: Add satellite PF vport support Tariq Toukan
2026-05-21 11:08 ` [PATCH net-next 02/12] net/mlx5: Introduce generic helper for PF SFs info Tariq Toukan
2026-05-21 11:08 ` [PATCH net-next 03/12] net/mlx5: Initialize host PF host number earlier Tariq Toukan
2026-05-21 11:08 ` [PATCH net-next 04/12] net/mlx5: Initialize satellite PF SF vports Tariq Toukan
2026-05-21 11:08 ` Tariq Toukan [this message]
2026-05-21 11:08 ` [PATCH net-next 06/12] net/mlx5: Expose PF number from query_esw_functions Tariq Toukan
2026-05-21 11:08 ` [PATCH net-next 07/12] net/mlx5: Map SF controller to pfnum for satellite PFs Tariq Toukan
2026-05-21 11:08 ` [PATCH net-next 08/12] net/mlx5: Register devlink ports " Tariq Toukan
2026-05-21 11:08 ` [PATCH net-next 09/12] net/mlx5: Register SF resource on satellite PF ports Tariq Toukan
2026-05-21 11:08 ` [PATCH net-next 10/12] net/mlx5: Support state get/set for " Tariq Toukan
2026-05-21 11:08 ` [PATCH net-next 11/12] net/mlx5: Add FDB peer miss rules for satellite PFs Tariq Toukan
2026-05-21 11:08 ` [PATCH net-next 12/12] net/mlx5: Add SPF function type for page management Tariq Toukan
2026-05-25 21:10 ` [PATCH net-next 00/12] net/mlx5: Add satellite PF support patchwork-bot+netdevbpf

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=20260521110843.367329-6-tariqt@nvidia.com \
    --to=tariqt@nvidia.com \
    --cc=ajayachandra@nvidia.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=cjubran@nvidia.com \
    --cc=cratiu@nvidia.com \
    --cc=danielj@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gal@nvidia.com \
    --cc=horms@kernel.org \
    --cc=jiri@resnulli.us \
    --cc=kees@kernel.org \
    --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=ohartoov@nvidia.com \
    --cc=pabeni@redhat.com \
    --cc=parav@nvidia.com \
    --cc=saeedm@nvidia.com \
    --cc=shayd@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