@@ -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;
+}
@@ -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_ */
@@ -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;
@@ -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;
+}
@@ -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_ */
@@ -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++;