DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Dariusz Sosnowski <dsosnowski@nvidia.com>
To: Viacheslav Ovsiienko <viacheslavo@nvidia.com>,
	Bing Zhao <bingz@nvidia.com>, Ori Kam <orika@nvidia.com>,
	Suanming Mou <suanmingm@nvidia.com>,
	Matan Azrad <matan@nvidia.com>
Cc: <dev@dpdk.org>
Subject: [PATCH 01/13] common/mlx5: rework IB port number query
Date: Mon, 26 Oct 2026 17:26:57 +0100	[thread overview]
Message-ID: <20261026162709.1292958-2-dsosnowski@nvidia.com> (raw)
In-Reply-To: <20261026162709.1292958-1-dsosnowski@nvidia.com>

mlx5_nl_portnum() function currently requires that
IB port to netdev info cache (mlx5_dev_info) is always provided.
Rework this function:

- Allow calling mlx5_nl_portnum() without cache.
- Extract cache fetch/update logic into separate functions.

Signed-off-by: Dariusz Sosnowski <dsosnowski@nvidia.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
---
 drivers/common/mlx5/linux/mlx5_nl.c | 79 ++++++++++++++++++++---------
 1 file changed, 54 insertions(+), 25 deletions(-)

diff --git a/drivers/common/mlx5/linux/mlx5_nl.c b/drivers/common/mlx5/linux/mlx5_nl.c
index 3fabcfaee0..1132e3fa5f 100644
--- a/drivers/common/mlx5/linux/mlx5_nl.c
+++ b/drivers/common/mlx5/linux/mlx5_nl.c
@@ -1275,15 +1275,60 @@ mlx5_nl_port_state(int nl, const char *name, uint32_t pindex, struct mlx5_dev_in
 	return (int)data.state;
 }
 
+static unsigned int
+mlx5_dev_info_get_portnum(const char *ibname, struct mlx5_dev_info *dev_info)
+{
+	if (dev_info == NULL ||
+	    !dev_info->probe_opt ||
+	    dev_info->port_num == 0 ||
+	    strcmp(ibname, dev_info->ibname) != 0)
+		return 0;
+
+	return dev_info->port_num;
+}
+
+static unsigned int
+mlx5_dev_info_set_portnum(const char *ibname,
+			  struct mlx5_dev_info *dev_info,
+			  const struct mlx5_nl_port_info *data)
+{
+	size_t size;
+
+	/* If cache is not available or probe optimization is not enabled, just return portnum. */
+	if (dev_info == NULL || !dev_info->probe_opt)
+		return data->portnum;
+
+	MLX5_ASSERT(data->flags & MLX5_NL_CMD_GET_IB_NAME);
+	MLX5_ASSERT(data->flags & MLX5_NL_CMD_GET_IB_INDEX);
+	MLX5_ASSERT(data->flags & MLX5_NL_CMD_GET_PORT_INDEX);
+	MLX5_ASSERT(strlen(dev_info->ibname) == 0);
+
+	dev_info->port_num = data->portnum;
+	dev_info->ibindex = data->ibindex;
+	snprintf(dev_info->ibname, MLX5_FS_NAME_MAX, "%s", ibname);
+	if (data->portnum > 1) {
+		size = (data->portnum + 1) * sizeof(struct mlx5_port_nl_info);
+		dev_info->port_info = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_RTE, size,
+						  RTE_CACHE_LINE_SIZE,
+						  SOCKET_ID_ANY);
+		if (dev_info->port_info == NULL) {
+			memset(dev_info, 0, sizeof(*dev_info));
+			rte_errno = ENOMEM;
+			return 0;
+		}
+	}
+	return data->portnum;
+}
+
 /**
  * Get the number of physical ports of given IB device.
  *
- * @param nl
+ * @param[in] nl
  *   Netlink socket of the RDMA kind (NETLINK_RDMA).
  * @param[in] name
  *   IB device name.
- * @param[in] dev_info
- *   Cached mlx5 device info.
+ * @param[in,out] dev_info
+ *   Cached mlx5 device info. If NULL, netlink query is done and caching is skipped.
  *
  * @return
  *   A valid (nonzero) number of ports on success, 0 otherwise
@@ -1306,11 +1351,12 @@ mlx5_nl_portnum(int nl, const char *name, struct mlx5_dev_info *dev_info)
 		.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP,
 	};
 	uint32_t sn = MLX5_NL_SN_GENERATE;
-	int ret, size;
+	unsigned int portnum;
+	int ret;
 
-	if (dev_info->probe_opt && dev_info->port_num &&
-	    !strcmp(name, dev_info->ibname))
-		return dev_info->port_num;
+	portnum = mlx5_dev_info_get_portnum(name, dev_info);
+	if (portnum > 0)
+		return portnum;
 
 	ret = mlx5_nl_send(nl, &req, sn);
 	if (ret < 0)
@@ -1328,24 +1374,7 @@ mlx5_nl_portnum(int nl, const char *name, struct mlx5_dev_info *dev_info)
 		rte_errno = EINVAL;
 		return 0;
 	}
-	if (!dev_info->probe_opt)
-		return data.portnum;
-	MLX5_ASSERT(!strlen(dev_info->ibname));
-	dev_info->port_num = data.portnum;
-	dev_info->ibindex = data.ibindex;
-	snprintf(dev_info->ibname, MLX5_FS_NAME_MAX, "%s", name);
-	if (data.portnum > 1) {
-		size = (data.portnum + 1) * sizeof(struct mlx5_port_nl_info);
-		dev_info->port_info = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_RTE, size,
-						  RTE_CACHE_LINE_SIZE,
-						  SOCKET_ID_ANY);
-		if (dev_info->port_info == NULL) {
-			memset(dev_info, 0, sizeof(*dev_info));
-			rte_errno = ENOMEM;
-			return 0;
-		}
-	}
-	return data.portnum;
+	return mlx5_dev_info_set_portnum(name, dev_info, &data);
 }
 
 /**
-- 
2.43.0


  reply	other threads:[~2026-10-26 16:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-26 16:26 [PATCH 00/13] net/mlx5: support nested E-Switch Dariusz Sosnowski
2026-10-26 16:26 ` Dariusz Sosnowski [this message]
2026-10-26 16:26 ` [PATCH 02/13] common/mlx5: allow ifindex query without cache Dariusz Sosnowski
2026-10-26 16:26 ` [PATCH 03/13] common/mlx5: separate netdev info from switch info Dariusz Sosnowski
2026-10-26 16:27 ` [PATCH 04/13] common/mlx5: query parent device over Netlink Dariusz Sosnowski
2026-10-26 16:27 ` [PATCH 05/13] common/mlx5: add check for auxiliary device Dariusz Sosnowski
2026-10-26 16:27 ` [PATCH 06/13] common/mlx5: gather associated devices Dariusz Sosnowski
2026-10-26 16:27 ` [PATCH 07/13] common/mlx5: always use EAL device for probing Dariusz Sosnowski
2026-10-26 16:27 ` [PATCH 08/13] common/mlx5: query devlink port for netdevs Dariusz Sosnowski
2026-10-26 16:27 ` [PATCH 09/13] common/mlx5: get devlink port by port index Dariusz Sosnowski
2026-10-26 16:27 ` [PATCH 10/13] common/mlx5: add check for managed device Dariusz Sosnowski
2026-10-26 16:27 ` [PATCH 11/13] net/mlx5: add sibling device iteration macro Dariusz Sosnowski
2026-10-26 16:27 ` [PATCH 12/13] net/mlx5: allow associated devices Dariusz Sosnowski
2026-10-26 16:27 ` [PATCH 13/13] net/mlx5: allow multiport auxiliary device probe Dariusz Sosnowski

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=20261026162709.1292958-2-dsosnowski@nvidia.com \
    --to=dsosnowski@nvidia.com \
    --cc=bingz@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=matan@nvidia.com \
    --cc=orika@nvidia.com \
    --cc=suanmingm@nvidia.com \
    --cc=viacheslavo@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