From: Tal Shnaiderman <talshn@nvidia.com>
To: <dev@dpdk.org>
Cc: <thomas@monjalon.net>, <matan@nvidia.com>, <rasland@nvidia.com>,
<asafp@nvidia.com>, <gakhil@marvell.com>,
<declan.doherty@intel.com>, <viacheslavo@nvidia.com>,
<eilong@nvidia.com>
Subject: [dpdk-dev] [RFC PATCH 02/10] common/mlx5: add an agnostic OS function to open device context
Date: Tue, 14 Sep 2021 08:38:25 +0300 [thread overview]
Message-ID: <20210914053833.7760-3-talshn@nvidia.com> (raw)
In-Reply-To: <20210914053833.7760-1-talshn@nvidia.com>
Add a function to open device context from a rte_device.
Function mlx5_os_open_device_context can be used both on
Windows and Linux OS.
Signed-off-by: Tal Shnaiderman <talshn@nvidia.com>
---
drivers/common/mlx5/linux/mlx5_common_os.c | 28 +++++++
drivers/common/mlx5/mlx5_common.h | 4 +
drivers/common/mlx5/version.map | 2 +
drivers/common/mlx5/windows/mlx5_common_os.c | 118 +++++++++++++++++++++++++++
drivers/common/mlx5/windows/mlx5_common_os.h | 2 +
drivers/net/mlx5/windows/mlx5_os.c | 64 +--------------
6 files changed, 155 insertions(+), 63 deletions(-)
diff --git a/drivers/common/mlx5/linux/mlx5_common_os.c b/drivers/common/mlx5/linux/mlx5_common_os.c
index 9e0c823c97..3ef507944f 100644
--- a/drivers/common/mlx5/linux/mlx5_common_os.c
+++ b/drivers/common/mlx5/linux/mlx5_common_os.c
@@ -428,3 +428,31 @@ mlx5_os_get_ibv_device(const struct rte_pci_addr *addr)
mlx5_glue->free_device_list(ibv_list);
return ibv_match;
}
+
+/**
+ * Open device context from a rte_device.
+ *
+ * @param[in] dev
+ * Pointer to an rte_device struct.
+ * @return
+ * Pointer to device context or NULL in case context cannot be found.
+ */
+void *
+mlx5_os_open_device_context(struct rte_device *dev)
+{
+ struct ibv_device *ibv;
+ void *ctx;
+
+ ibv = mlx5_os_get_ibv_dev(dev);
+ if (ibv == NULL) {
+ DRV_LOG(ERR, "Failed getting ibv_dev");
+ return NULL;
+ }
+ ctx = mlx5_glue->dv_open_device(ibv);
+ if (ctx == NULL) {
+ DRV_LOG(ERR, "Failed to open IB device \"%s\".", ibv->name);
+ rte_errno = ENODEV;
+ return NULL;
+ }
+ return ctx;
+}
diff --git a/drivers/common/mlx5/mlx5_common.h b/drivers/common/mlx5/mlx5_common.h
index a772371200..249804b00c 100644
--- a/drivers/common/mlx5/mlx5_common.h
+++ b/drivers/common/mlx5/mlx5_common.h
@@ -419,4 +419,8 @@ __rte_internal
bool
mlx5_dev_is_pci(const struct rte_device *dev);
+__rte_internal
+void *
+mlx5_os_open_device_context(struct rte_device *dev);
+
#endif /* RTE_PMD_MLX5_COMMON_H_ */
diff --git a/drivers/common/mlx5/version.map b/drivers/common/mlx5/version.map
index e5cb6b7060..6d4258dd25 100644
--- a/drivers/common/mlx5/version.map
+++ b/drivers/common/mlx5/version.map
@@ -141,6 +141,8 @@ INTERNAL {
mlx5_os_alloc_pd;
mlx5_os_dealloc_pd;
mlx5_os_dereg_mr;
+ mlx5_os_match_devx_devices_to_addr;
+ mlx5_os_open_device_context;
mlx5_os_get_ibv_dev; # WINDOWS_NO_EXPORT
mlx5_os_reg_mr;
mlx5_os_umem_dereg;
diff --git a/drivers/common/mlx5/windows/mlx5_common_os.c b/drivers/common/mlx5/windows/mlx5_common_os.c
index 5031bdca26..3b59e57e57 100644
--- a/drivers/common/mlx5/windows/mlx5_common_os.c
+++ b/drivers/common/mlx5/windows/mlx5_common_os.c
@@ -6,6 +6,7 @@
#include <string.h>
#include <stdio.h>
+#include <rte_bus_pci.h>
#include <rte_mempool.h>
#include <rte_malloc.h>
#include <rte_errno.h>
@@ -205,3 +206,120 @@ mlx5_os_dereg_mr(struct mlx5_pmd_mr *pmd_mr)
claim_zero(mlx5_os_umem_dereg(pmd_mr->obj));
memset(pmd_mr, 0, sizeof(*pmd_mr));
}
+
+/**
+ * Detect if a devx_device_bdf object has identical DBDF values to the
+ * rte_pci_addr found in bus/pci probing
+ *
+ * @param[in] devx_bdf
+ * Pointer to the devx_device_bdf structure.
+ * @param[in] addr
+ * Pointer to the rte_pci_addr structure.
+ *
+ * @return
+ * 1 on Device match, 0 on mismatch.
+ */
+static int
+mlx5_os_match_devx_bdf_to_addr(struct devx_device_bdf *devx_bdf,
+ struct rte_pci_addr *addr)
+{
+ if (addr->domain != (devx_bdf->bus_id >> 8) ||
+ addr->bus != (devx_bdf->bus_id & 0xff) ||
+ addr->devid != devx_bdf->dev_id ||
+ addr->function != devx_bdf->fnc_id) {
+ return 0;
+ }
+ return 1;
+}
+
+/**
+ * Detect if a devx_device_bdf object matches the rte_pci_addr
+ * found in bus/pci probing
+ * Compare both the Native/PF BDF and the raw_bdf representing a VF BDF.
+ *
+ * @param[in] devx_bdf
+ * Pointer to the devx_device_bdf structure.
+ * @param[in] addr
+ * Pointer to the rte_pci_addr structure.
+ *
+ * @return
+ * 1 on Device match, 0 on mismatch, rte_errno code on failure.
+ */
+int
+mlx5_os_match_devx_devices_to_addr(struct devx_device_bdf *devx_bdf,
+ struct rte_pci_addr *addr)
+{
+ int err;
+ struct devx_device mlx5_dev;
+
+ if (mlx5_os_match_devx_bdf_to_addr(devx_bdf, addr))
+ return 1;
+ /**
+ * Didn't match on Native/PF BDF, could still
+ * Match a VF BDF, check it next
+ */
+ err = mlx5_glue->query_device(devx_bdf, &mlx5_dev);
+ if (err) {
+ DRV_LOG(ERR, "query_device failed");
+ rte_errno = err;
+ return rte_errno;
+ }
+ if (mlx5_os_match_devx_bdf_to_addr(&mlx5_dev.raw_bdf, addr))
+ return 1;
+ return 0;
+}
+
+/**
+ * Open device context from a rte_device.
+ *
+ * @param[in] dev
+ * Pointer to an rte_device struct.
+ * @return
+ * Pointer to device context or NULL in case context cannot be found.
+ */
+void *
+mlx5_os_open_device_context(struct rte_device *dev)
+{
+ struct devx_device_bdf *devx_bdf_devs, *orig_devx_bdf_devs;
+ struct mlx5_context *devx_ctx_match = NULL;
+ int ret, err;
+ struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev);
+
+ devx_bdf_devs = mlx5_glue->get_device_list(&ret);
+ orig_devx_bdf_devs = devx_bdf_devs;
+ if (!devx_bdf_devs) {
+ rte_errno = errno ? errno : ENOSYS;
+ DRV_LOG(ERR, "cannot list devices, is DevX configured?");
+ return NULL;
+ }
+ while (ret-- > 0) {
+ err = mlx5_os_match_devx_devices_to_addr(devx_bdf_devs,
+ &pci_dev->addr);
+ if (err == 1) {
+ devx_ctx_match = mlx5_glue->open_device(devx_bdf_devs);
+ if (!devx_ctx_match) {
+ DRV_LOG(ERR, "open_device failed");
+ err = errno;
+ goto exit;
+ }
+ err = mlx5_glue->query_device(devx_bdf_devs,
+ &devx_ctx_match->mlx5_dev);
+ if (err) {
+ DRV_LOG(ERR, "query device context failed.");
+ rte_errno = errno ? errno : ENOSYS;
+ claim_zero(mlx5_glue->close_device(
+ devx_ctx_match));
+ goto exit;
+ }
+ }
+ if (err != 0) {
+ DRV_LOG(ERR, "failed to match addr to rte_device");
+ ret = -err;
+ goto exit;
+ }
+ devx_bdf_devs++;
+ }
+exit:
+ mlx5_glue->free_device_list(orig_devx_bdf_devs);
+ return devx_ctx_match;
+}
diff --git a/drivers/common/mlx5/windows/mlx5_common_os.h b/drivers/common/mlx5/windows/mlx5_common_os.h
index 3756e1959b..c3d74d3b67 100644
--- a/drivers/common/mlx5/windows/mlx5_common_os.h
+++ b/drivers/common/mlx5/windows/mlx5_common_os.h
@@ -261,4 +261,6 @@ int mlx5_os_reg_mr(void *pd,
void *addr, size_t length, struct mlx5_pmd_mr *pmd_mr);
__rte_internal
void mlx5_os_dereg_mr(struct mlx5_pmd_mr *pmd_mr);
+int mlx5_os_match_devx_devices_to_addr(struct devx_device_bdf *devx_bdf,
+ struct rte_pci_addr *addr);
#endif /* RTE_PMD_MLX5_COMMON_OS_H_ */
diff --git a/drivers/net/mlx5/windows/mlx5_os.c b/drivers/net/mlx5/windows/mlx5_os.c
index 26fa927039..9dea6d639e 100644
--- a/drivers/net/mlx5/windows/mlx5_os.c
+++ b/drivers/net/mlx5/windows/mlx5_os.c
@@ -901,68 +901,6 @@ mlx5_os_set_allmulti(struct rte_eth_dev *dev, int enable)
return -ENOTSUP;
}
-/**
- * Detect if a devx_device_bdf object has identical DBDF values to the
- * rte_pci_addr found in bus/pci probing
- *
- * @param[in] devx_bdf
- * Pointer to the devx_device_bdf structure.
- * @param[in] addr
- * Pointer to the rte_pci_addr structure.
- *
- * @return
- * 1 on Device match, 0 on mismatch.
- */
-static int
-mlx5_match_devx_bdf_to_addr(struct devx_device_bdf *devx_bdf,
- struct rte_pci_addr *addr)
-{
- if (addr->domain != (devx_bdf->bus_id >> 8) ||
- addr->bus != (devx_bdf->bus_id & 0xff) ||
- addr->devid != devx_bdf->dev_id ||
- addr->function != devx_bdf->fnc_id) {
- return 0;
- }
- return 1;
-}
-
-/**
- * Detect if a devx_device_bdf object matches the rte_pci_addr
- * found in bus/pci probing
- * Compare both the Native/PF BDF and the raw_bdf representing a VF BDF.
- *
- * @param[in] devx_bdf
- * Pointer to the devx_device_bdf structure.
- * @param[in] addr
- * Pointer to the rte_pci_addr structure.
- *
- * @return
- * 1 on Device match, 0 on mismatch, rte_errno code on failure.
- */
-static int
-mlx5_match_devx_devices_to_addr(struct devx_device_bdf *devx_bdf,
- struct rte_pci_addr *addr)
-{
- int err;
- struct devx_device mlx5_dev;
-
- if (mlx5_match_devx_bdf_to_addr(devx_bdf, addr))
- return 1;
- /**
- * Didn't match on Native/PF BDF, could still
- * Match a VF BDF, check it next
- */
- err = mlx5_glue->query_device(devx_bdf, &mlx5_dev);
- if (err) {
- DRV_LOG(ERR, "query_device failed");
- rte_errno = err;
- return rte_errno;
- }
- if (mlx5_match_devx_bdf_to_addr(&mlx5_dev.raw_bdf, addr))
- return 1;
- return 0;
-}
-
/**
* DPDK callback to register a PCI device.
*
@@ -1036,7 +974,7 @@ mlx5_os_net_probe(struct rte_device *dev)
struct devx_device_bdf *devx_bdf_match[ret + 1];
while (ret-- > 0) {
- err = mlx5_match_devx_devices_to_addr(devx_bdf_devs,
+ err = mlx5_os_match_devx_devices_to_addr(devx_bdf_devs,
&pci_dev->addr);
if (!err) {
devx_bdf_devs++;
--
2.16.1.windows.4
next prev parent reply other threads:[~2021-09-14 5:40 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-14 5:38 [dpdk-dev] [RFC PATCH 00/10] Support MLX5 crypto driver on Windows Tal Shnaiderman
2021-09-14 5:38 ` [dpdk-dev] [RFC PATCH 01/10] common/mlx5: add DV enums to Windows defs file Tal Shnaiderman
2021-09-14 5:38 ` Tal Shnaiderman [this message]
2021-09-14 5:38 ` [dpdk-dev] [RFC PATCH 03/10] common/mlx5: move pdn getter to common driver Tal Shnaiderman
2021-09-14 5:38 ` [dpdk-dev] [RFC PATCH 04/10] common/mlx5: add memory region OS agnostic functions for Linux Tal Shnaiderman
2021-09-14 5:38 ` [dpdk-dev] [RFC PATCH 05/10] crypto/mlx5: replace UNIX functions with EAL functions Tal Shnaiderman
2021-09-14 5:38 ` [dpdk-dev] [RFC PATCH 06/10] crypto/mlx5: use OS agnostic functions for UMEM operations Tal Shnaiderman
2021-09-14 5:38 ` [dpdk-dev] [RFC PATCH 07/10] crypto/mlx5: use OS agnostic functions for PD operations Tal Shnaiderman
2021-09-14 5:38 ` [dpdk-dev] [RFC PATCH 08/10] crypto/mlx5: use OS agnostic functions for Verbs operations Tal Shnaiderman
2021-09-14 5:38 ` [dpdk-dev] [RFC PATCH 09/10] crypto/mlx5: fix size of UMR WQE Tal Shnaiderman
2021-09-14 5:38 ` [dpdk-dev] [RFC PATCH 10/10] crypto/mlx5: support on Windows Tal Shnaiderman
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=20210914053833.7760-3-talshn@nvidia.com \
--to=talshn@nvidia.com \
--cc=asafp@nvidia.com \
--cc=declan.doherty@intel.com \
--cc=dev@dpdk.org \
--cc=eilong@nvidia.com \
--cc=gakhil@marvell.com \
--cc=matan@nvidia.com \
--cc=rasland@nvidia.com \
--cc=thomas@monjalon.net \
--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;
as well as URLs for NNTP newsgroup(s).