diff mbox series

[v2,11/41] common/mlx5: add mr reg/dereg API

Message ID 20211007184350.73858-12-srikanth.k@oneconvergence.com (mailing list archive)
State New
Delegated to: Raslan Darawsheh
Headers show
Series add MLX5 FreeBSD support | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Srikanth Kaka Oct. 7, 2021, 6:43 p.m. UTC
The mlx5_common_verbs_reg_mr() and mlx5_common_verbs_dereg_mr()
APIs are equivalent to their Linux counterparts

Signed-off-by: Srikanth Kaka <srikanth.k@oneconvergence.com>
Signed-off-by: Vag Singh <vag.singh@oneconvergence.com>
Signed-off-by: Anand Thulasiram <avelu@juniper.net>
---
 drivers/common/mlx5/freebsd/meson.build       |  1 +
 .../common/mlx5/freebsd/mlx5_common_verbs.c   | 73 +++++++++++++++++++
 2 files changed, 74 insertions(+)
 create mode 100644 drivers/common/mlx5/freebsd/mlx5_common_verbs.c
diff mbox series

Patch

diff --git a/drivers/common/mlx5/freebsd/meson.build b/drivers/common/mlx5/freebsd/meson.build
index 8e4bb1659e..4112fdb155 100644
--- a/drivers/common/mlx5/freebsd/meson.build
+++ b/drivers/common/mlx5/freebsd/meson.build
@@ -33,6 +33,7 @@  endif
 
 sources += files('mlx5_common_os.c')
 sources += files('mlx5_glue.c')
+sources += files('mlx5_common_verbs.c')
 
 # To maintain the compatibility with the make build system
 # mlx5_autoconf.h file is still generated.
diff --git a/drivers/common/mlx5/freebsd/mlx5_common_verbs.c b/drivers/common/mlx5/freebsd/mlx5_common_verbs.c
new file mode 100644
index 0000000000..efb039c53d
--- /dev/null
+++ b/drivers/common/mlx5/freebsd/mlx5_common_verbs.c
@@ -0,0 +1,73 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2020 Mellanox Technologies, Ltd
+ */
+
+#include <stddef.h>
+#include <errno.h>
+#include <string.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <inttypes.h>
+
+#include "mlx5_common_utils.h"
+#include "mlx5_common_log.h"
+#include "mlx5_common_private.h"
+#include "mlx5_autoconf.h"
+#include <mlx5_glue.h>
+#include <mlx5_common.h>
+#include <mlx5_common_mr.h>
+
+/**
+ * Register mr. Given protection domain pointer, pointer to addr and length
+ * register the memory region.
+ *
+ * @param[in] pd
+ *   Pointer to protection domain context.
+ * @param[in] addr
+ *   Pointer to memory start address.
+ * @param[in] length
+ *   Length of the memory to register.
+ * @param[out] pmd_mr
+ *   pmd_mr struct set with lkey, address, length and pointer to mr object
+ *
+ * @return
+ *   0 on successful registration, -1 otherwise
+ */
+int
+mlx5_common_verbs_reg_mr(void *pd, void *addr, size_t length,
+			 struct mlx5_pmd_mr *pmd_mr)
+{
+	struct ibv_mr *ibv_mr;
+
+	ibv_mr = mlx5_glue->reg_mr(pd, addr, length,
+				   IBV_ACCESS_LOCAL_WRITE |
+				   (haswell_broadwell_cpu ? 0 :
+				   IBV_ACCESS_RELAXED_ORDERING));
+	if (!ibv_mr)
+		return -1;
+
+	*pmd_mr = (struct mlx5_pmd_mr){
+		.lkey = ibv_mr->lkey,
+		.addr = ibv_mr->addr,
+		.len = ibv_mr->length,
+		.obj = (void *)ibv_mr,
+	};
+	return 0;
+}
+
+/**
+ * Deregister mr. Given the mlx5 pmd MR - deregister the MR
+ *
+ * @param[in] pmd_mr
+ *   pmd_mr struct set with lkey, address, length and pointer to mr object
+ *
+ */
+void
+mlx5_common_verbs_dereg_mr(struct mlx5_pmd_mr *pmd_mr)
+{
+	if (pmd_mr && pmd_mr->obj != NULL) {
+		claim_zero(mlx5_glue->dereg_mr(pmd_mr->obj));
+		memset(pmd_mr, 0, sizeof(*pmd_mr));
+	}
+}