mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Edward Srouji <edwards@nvidia.com>
To: Saeed Mahameed <saeedm@nvidia.com>,
	Leon Romanovsky <leon@kernel.org>,
	Tariq Toukan <tariqt@nvidia.com>, Mark Bloch <mbloch@nvidia.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	Yishai Hadas <yishaih@mellanox.com>
Cc: Edward Srouji <edwards@nvidia.com>, <linux-rdma@vger.kernel.org>,
	<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Mark Bloch <markb@mellanox.com>,
	Michael Gur <michaelgur@nvidia.com>,
	Patrisious Haddad <phaddad@nvidia.com>
Subject: [PATCH mlx5-next 3/5] net/mlx5: fs, refactor RDMA transport manager root namespace init/cleanup
Date: Tue, 3 Nov 2026 20:12:51 +0200	[thread overview]
Message-ID: <20261103-rdma-rx-classifier-v1-3-1ad6c8cfe936@nvidia.com> (raw)
In-Reply-To: <20261103-rdma-rx-classifier-v1-0-1ad6c8cfe936@nvidia.com>

From: Michael Gur <michaelgur@nvidia.com>

The rdma transport steering domains init, cleanup and helpers are
near-identical, merge them into single
init_transport_manager_root_ns()/_one() and
cleanup_transport_manager_root_ns() with parameters.

This is preparation for a new domain with the same per-vport root
namespace usage model, which will reuse these functions instead of
duplicating them a third time.
No functional change to RDMA_TRANSPORT_RX/TX.

Signed-off-by: Michael Gur <michaelgur@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Reviewed-by: Patrisious Haddad <phaddad@nvidia.com>
Signed-off-by: Edward Srouji <edwards@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/fs_core.c | 153 +++++++---------------
 drivers/net/ethernet/mellanox/mlx5/core/fs_core.h |  11 +-
 2 files changed, 53 insertions(+), 111 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c b/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
index 70545053f9c42d6f6ccf439852d14f9b9e16419f..033ea5a198ee0d5a7e77ce0770f38bb8ffe97812 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
@@ -2817,20 +2817,20 @@ mlx5_get_flow_vport_namespace(struct mlx5_core_dev *dev,
 		else
 			return NULL;
 	case MLX5_FLOW_NAMESPACE_RDMA_TRANSPORT_RX:
-		if (vport_idx >= steering->rdma_transport_rx_vports)
+		if (vport_idx >= steering->rdma_transport_rx.vports)
 			return NULL;
-		if (steering->rdma_transport_rx_root_ns &&
-		    steering->rdma_transport_rx_root_ns[vport_idx])
-			return &steering->rdma_transport_rx_root_ns[vport_idx]->ns;
+		if (steering->rdma_transport_rx.root_ns &&
+		    steering->rdma_transport_rx.root_ns[vport_idx])
+			return &steering->rdma_transport_rx.root_ns[vport_idx]->ns;
 		else
 			return NULL;
 	case MLX5_FLOW_NAMESPACE_RDMA_TRANSPORT_TX:
-		if (vport_idx >= steering->rdma_transport_tx_vports)
+		if (vport_idx >= steering->rdma_transport_tx.vports)
 			return NULL;
 
-		if (steering->rdma_transport_tx_root_ns &&
-		    steering->rdma_transport_tx_root_ns[vport_idx])
-			return &steering->rdma_transport_tx_root_ns[vport_idx]->ns;
+		if (steering->rdma_transport_tx.root_ns &&
+		    steering->rdma_transport_tx.root_ns[vport_idx])
+			return &steering->rdma_transport_tx.root_ns[vport_idx]->ns;
 		else
 			return NULL;
 	default:
@@ -3244,7 +3244,9 @@ static int init_rdma_tx_root_ns(struct mlx5_flow_steering *steering)
 }
 
 static int
-init_rdma_transport_rx_root_ns_one(struct mlx5_flow_steering *steering,
+init_transport_manager_root_ns_one(struct mlx5_flow_steering *steering,
+				   struct mlx5_flow_root_namespace **root_ns_arr,
+				   enum fs_flow_table_type ft_type,
 				   int vport_idx)
 {
 	struct mlx5_flow_root_namespace *root_ns;
@@ -3252,43 +3254,11 @@ init_rdma_transport_rx_root_ns_one(struct mlx5_flow_steering *steering,
 	int ret;
 	int i;
 
-	steering->rdma_transport_rx_root_ns[vport_idx] =
-		create_root_ns(steering, FS_FT_RDMA_TRANSPORT_RX);
-	if (!steering->rdma_transport_rx_root_ns[vport_idx])
+	root_ns_arr[vport_idx] = create_root_ns(steering, ft_type);
+	if (!root_ns_arr[vport_idx])
 		return -ENOMEM;
 
-	root_ns = steering->rdma_transport_rx_root_ns[vport_idx];
-
-	for (i = 0; i < MLX5_RDMA_TRANSPORT_BYPASS_PRIO; i++) {
-		prio = fs_create_prio(&root_ns->ns, i, 1);
-		if (IS_ERR(prio)) {
-			ret = PTR_ERR(prio);
-			goto err;
-		}
-	}
-	set_prio_attrs(root_ns);
-	return 0;
-
-err:
-	cleanup_root_ns(root_ns);
-	return ret;
-}
-
-static int
-init_rdma_transport_tx_root_ns_one(struct mlx5_flow_steering *steering,
-				   int vport_idx)
-{
-	struct mlx5_flow_root_namespace *root_ns;
-	struct fs_prio *prio;
-	int ret;
-	int i;
-
-	steering->rdma_transport_tx_root_ns[vport_idx] =
-		create_root_ns(steering, FS_FT_RDMA_TRANSPORT_TX);
-	if (!steering->rdma_transport_tx_root_ns[vport_idx])
-		return -ENOMEM;
-
-	root_ns = steering->rdma_transport_tx_root_ns[vport_idx];
+	root_ns = root_ns_arr[vport_idx];
 
 	for (i = 0; i < MLX5_RDMA_TRANSPORT_BYPASS_PRIO; i++) {
 		prio = fs_create_prio(&root_ns->ns, i, 1);
@@ -3327,12 +3297,12 @@ int mlx5_fs_set_root_dev(struct mlx5_core_dev *dev,
 
 	switch (table_type) {
 	case FS_FT_RDMA_TRANSPORT_TX:
-		root = dev->priv.steering->rdma_transport_tx_root_ns;
-		total_vports = dev->priv.steering->rdma_transport_tx_vports;
+		root = dev->priv.steering->rdma_transport_tx.root_ns;
+		total_vports = dev->priv.steering->rdma_transport_tx.vports;
 		break;
 	case FS_FT_RDMA_TRANSPORT_RX:
-		root = dev->priv.steering->rdma_transport_rx_root_ns;
-		total_vports = dev->priv.steering->rdma_transport_rx_vports;
+		root = dev->priv.steering->rdma_transport_rx.root_ns;
+		total_vports = dev->priv.steering->rdma_transport_rx.vports;
 		break;
 	default:
 		WARN_ON_ONCE(true);
@@ -3361,39 +3331,10 @@ int mlx5_fs_set_root_dev(struct mlx5_core_dev *dev,
 }
 EXPORT_SYMBOL(mlx5_fs_set_root_dev);
 
-static int init_rdma_transport_rx_root_ns(struct mlx5_flow_steering *steering)
-{
-	struct mlx5_core_dev *dev = steering->dev;
-	int total_vports;
-	int err;
-	int i;
-
-	/* In case eswitch not supported and working in legacy mode */
-	total_vports = mlx5_eswitch_get_total_vports(dev) ?: 1;
-
-	steering->rdma_transport_rx_root_ns =
-			kzalloc_objs(*steering->rdma_transport_rx_root_ns,
-				     total_vports);
-	if (!steering->rdma_transport_rx_root_ns)
-		return -ENOMEM;
-
-	for (i = 0; i < total_vports; i++) {
-		err = init_rdma_transport_rx_root_ns_one(steering, i);
-		if (err)
-			goto cleanup_root_ns;
-	}
-	steering->rdma_transport_rx_vports = total_vports;
-	return 0;
-
-cleanup_root_ns:
-	while (i--)
-		cleanup_root_ns(steering->rdma_transport_rx_root_ns[i]);
-	kfree(steering->rdma_transport_rx_root_ns);
-	steering->rdma_transport_rx_root_ns = NULL;
-	return err;
-}
-
-static int init_rdma_transport_tx_root_ns(struct mlx5_flow_steering *steering)
+static int
+init_transport_manager_root_ns(struct mlx5_flow_steering *steering,
+			       struct mlx5_transport_manager_ns *tm,
+			       enum fs_flow_table_type ft_type)
 {
 	struct mlx5_core_dev *dev = steering->dev;
 	int total_vports;
@@ -3403,47 +3344,40 @@ static int init_rdma_transport_tx_root_ns(struct mlx5_flow_steering *steering)
 	/* In case eswitch not supported and working in legacy mode */
 	total_vports = mlx5_eswitch_get_total_vports(dev) ?: 1;
 
-	steering->rdma_transport_tx_root_ns =
-			kzalloc_objs(*steering->rdma_transport_tx_root_ns,
-				     total_vports);
-	if (!steering->rdma_transport_tx_root_ns)
+	tm->root_ns = kzalloc_objs(*tm->root_ns, total_vports);
+	if (!tm->root_ns)
 		return -ENOMEM;
 
 	for (i = 0; i < total_vports; i++) {
-		err = init_rdma_transport_tx_root_ns_one(steering, i);
+		err = init_transport_manager_root_ns_one(steering, tm->root_ns,
+							 ft_type, i);
 		if (err)
 			goto cleanup_root_ns;
 	}
-	steering->rdma_transport_tx_vports = total_vports;
+	tm->vports = total_vports;
 	return 0;
 
 cleanup_root_ns:
 	while (i--)
-		cleanup_root_ns(steering->rdma_transport_tx_root_ns[i]);
-	kfree(steering->rdma_transport_tx_root_ns);
-	steering->rdma_transport_tx_root_ns = NULL;
+		cleanup_root_ns(tm->root_ns[i]);
+	kfree(tm->root_ns);
+	tm->root_ns = NULL;
 	return err;
 }
 
-static void cleanup_rdma_transport_roots_ns(struct mlx5_flow_steering *steering)
+static void
+cleanup_transport_manager_root_ns(struct mlx5_transport_manager_ns *tm)
 {
 	int i;
 
-	if (steering->rdma_transport_rx_root_ns) {
-		for (i = 0; i < steering->rdma_transport_rx_vports; i++)
-			cleanup_root_ns(steering->rdma_transport_rx_root_ns[i]);
-
-		kfree(steering->rdma_transport_rx_root_ns);
-		steering->rdma_transport_rx_root_ns = NULL;
-	}
+	if (!tm->root_ns)
+		return;
 
-	if (steering->rdma_transport_tx_root_ns) {
-		for (i = 0; i < steering->rdma_transport_tx_vports; i++)
-			cleanup_root_ns(steering->rdma_transport_tx_root_ns[i]);
+	for (i = 0; i < tm->vports; i++)
+		cleanup_root_ns(tm->root_ns[i]);
 
-		kfree(steering->rdma_transport_tx_root_ns);
-		steering->rdma_transport_tx_root_ns = NULL;
-	}
+	kfree(tm->root_ns);
+	tm->root_ns = NULL;
 }
 
 /* FT and tc chains are stored in the same array so we can re-use the
@@ -3871,7 +3805,8 @@ void mlx5_fs_core_cleanup(struct mlx5_core_dev *dev)
 	cleanup_root_ns(steering->rdma_rx_root_ns);
 	cleanup_root_ns(steering->rdma_tx_root_ns);
 	cleanup_root_ns(steering->egress_root_ns);
-	cleanup_rdma_transport_roots_ns(steering);
+	cleanup_transport_manager_root_ns(&steering->rdma_transport_rx);
+	cleanup_transport_manager_root_ns(&steering->rdma_transport_tx);
 
 	devl_params_unregister(priv_to_devlink(dev), mlx5_fs_params,
 			       ARRAY_SIZE(mlx5_fs_params));
@@ -3942,13 +3877,17 @@ int mlx5_fs_core_init(struct mlx5_core_dev *dev)
 	}
 
 	if (MLX5_CAP_FLOWTABLE_RDMA_TRANSPORT_RX(dev, ft_support)) {
-		err = init_rdma_transport_rx_root_ns(steering);
+		err = init_transport_manager_root_ns(steering,
+						     &steering->rdma_transport_rx,
+						     FS_FT_RDMA_TRANSPORT_RX);
 		if (err)
 			goto err;
 	}
 
 	if (MLX5_CAP_FLOWTABLE_RDMA_TRANSPORT_TX(dev, ft_support)) {
-		err = init_rdma_transport_tx_root_ns(steering);
+		err = init_transport_manager_root_ns(steering,
+						     &steering->rdma_transport_tx,
+						     FS_FT_RDMA_TRANSPORT_TX);
 		if (err)
 			goto err;
 	}
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_core.h b/drivers/net/ethernet/mellanox/mlx5/core/fs_core.h
index 906584345a022d14aadd20d665ea41d2f287d719..e36735bea218c6909a6196305caa5c2aa5a83af6 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fs_core.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_core.h
@@ -125,6 +125,11 @@ enum mlx5_flow_steering_capabilty {
 	MLX5_FLOW_STEERING_CAP_DUPLICATE_MATCH = 1UL << 3,
 };
 
+struct mlx5_transport_manager_ns {
+	struct mlx5_flow_root_namespace **root_ns;
+	int vports;
+};
+
 struct mlx5_flow_steering {
 	struct mlx5_core_dev *dev;
 	enum   mlx5_flow_steering_mode	mode;
@@ -141,10 +146,8 @@ struct mlx5_flow_steering {
 	struct mlx5_flow_root_namespace	*rdma_tx_root_ns;
 	struct mlx5_flow_root_namespace	*egress_root_ns;
 	struct mlx5_flow_root_namespace	*port_sel_root_ns;
-	struct mlx5_flow_root_namespace **rdma_transport_rx_root_ns;
-	struct mlx5_flow_root_namespace **rdma_transport_tx_root_ns;
-	int rdma_transport_rx_vports;
-	int rdma_transport_tx_vports;
+	struct mlx5_transport_manager_ns rdma_transport_rx;
+	struct mlx5_transport_manager_ns rdma_transport_tx;
 };
 
 struct fs_node {

-- 
2.49.0


  parent reply	other threads:[~2026-11-03 18:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 18:12 [PATCH rdma-next 0/5] RDMA/mlx5: Add NIC_RX_CLASS steering domain for RDMA classification Edward Srouji
2026-11-03 18:12 ` [PATCH mlx5-next 1/5] net/mlx5: Add NIC_RX_CLASS IFC bits Edward Srouji
2026-11-03 18:12 ` [PATCH mlx5-next 2/5] net/mlx5: fs, treat ALLOW as a conflicting action upon merge Edward Srouji
2026-11-03 18:12 ` Edward Srouji [this message]
2026-11-03 18:12 ` [PATCH mlx5-next 4/5] net/mlx5: fs, add NIC_RX_CLASS steering domain support Edward Srouji
2026-11-03 18:12 ` [PATCH rdma-next 5/5] RDMA/mlx5: Expose NIC_RX_CLASS flow table type to userspace Edward Srouji

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=20261103-rdma-rx-classifier-v1-3-1ad6c8cfe936@nvidia.com \
    --to=edwards@nvidia.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=markb@mellanox.com \
    --cc=mbloch@nvidia.com \
    --cc=michaelgur@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=phaddad@nvidia.com \
    --cc=saeedm@nvidia.com \
    --cc=tariqt@nvidia.com \
    --cc=yishaih@mellanox.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

all inboxes | Powered by JetHome®