Defined mlx5_glue_constructor in mlx5_common_os.c to support
run-time dependency on rdma-core

Signed-off-by: Srikanth Kaka <srikant...@oneconvergence.com>
Signed-off-by: Vag Singh <vag.si...@oneconvergence.com>
Signed-off-by: Anand Thulasiram <av...@juniper.net>
---
 drivers/common/mlx5/freebsd/mlx5_common_os.c | 60 ++++++++++++++++++++
 1 file changed, 60 insertions(+)
 create mode 100644 drivers/common/mlx5/freebsd/mlx5_common_os.c

diff --git a/drivers/common/mlx5/freebsd/mlx5_common_os.c 
b/drivers/common/mlx5/freebsd/mlx5_common_os.c
new file mode 100644
index 0000000000..9c3cd1e4e6
--- /dev/null
+++ b/drivers/common/mlx5/freebsd/mlx5_common_os.c
@@ -0,0 +1,60 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2020 Mellanox Technologies, Ltd
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/sysctl.h>
+
+#include <rte_errno.h>
+
+#include "mlx5_common.h"
+#include "mlx5_common_log.h"
+#include "mlx5_glue.h"
+
+/**
+ * Initialization routine for run-time dependency on rdma-core.
+ */
+void
+mlx5_glue_constructor(void)
+{
+       /*
+        * RDMAV_HUGEPAGES_SAFE tells ibv_fork_init() we intend to use
+        * huge pages. Calling ibv_fork_init() during init allows
+        * applications to use fork() safely for purposes other than
+        * using this PMD, which is not supported in forked processes.
+        */
+       setenv("RDMAV_HUGEPAGES_SAFE", "1", 1);
+       /* Match the size of Rx completion entry to the size of a cacheline. */
+       if (RTE_CACHE_LINE_SIZE == 128)
+               setenv("MLX5_CQE_SIZE", "128", 0);
+       /*
+        * MLX5_DEVICE_FATAL_CLEANUP tells ibv_destroy functions to
+        * cleanup all the Verbs resources even when the device was removed.
+        */
+       setenv("MLX5_DEVICE_FATAL_CLEANUP", "1", 1);
+
+#ifdef RTE_LIBRTE_MLX5_DEBUG
+       /* Glue structure must not contain any NULL pointers. */
+       {
+               unsigned int i;
+
+               for (i = 0; i != sizeof(*mlx5_glue) / sizeof(void *); ++i)
+                       MLX5_ASSERT(((const void *const *)mlx5_glue)[i]);
+       }
+#endif
+       if (strcmp(mlx5_glue->version, MLX5_GLUE_VERSION)) {
+               rte_errno = EINVAL;
+               DRV_LOG(ERR, "rdma-core glue \"%s\" mismatch: \"%s\" is "
+                       "required", mlx5_glue->version, MLX5_GLUE_VERSION);
+               goto glue_error;
+       }
+       mlx5_glue->fork_init();
+       return;
+
+glue_error:
+       DRV_LOG(WARNING, "Cannot initialize MLX5 common due to missing"
+               " run-time dependency on rdma-core libraries (libibverbs,"
+               " libmlx5)");
+       mlx5_glue = NULL;
+}
-- 
2.30.2

Reply via email to