[v1,4/4] mlx5/linux: add MR callbacks to verbs operations struct

Message ID 20200616094446.7152-5-ophirmu@mellanox.com (mailing list archive)
State Accepted, archived
Delegated to: Raslan Darawsheh
Headers
Series mlx5 MR refactor |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Ophir Munk June 16, 2020, 9:44 a.m. UTC
  Create a set of verbs callbacks in 'struct mlx5_verbs_ops'
and add MR operations to it (file net/mlx5/linux/mlx5_verbs.c).

Signed-off-by: Ophir Munk <ophirmu@mellanox.com>
Acked-by: Matan Azrad <matan@mellanox.com>
---
 drivers/net/mlx5/Makefile           |  1 +
 drivers/net/mlx5/linux/meson.build  |  1 +
 drivers/net/mlx5/linux/mlx5_os.c    |  5 ++-
 drivers/net/mlx5/linux/mlx5_verbs.c | 78 +++++++++++++++++++++++++++++++++++++
 drivers/net/mlx5/linux/mlx5_verbs.h | 15 +++++++
 5 files changed, 98 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/mlx5/linux/mlx5_verbs.c
 create mode 100644 drivers/net/mlx5/linux/mlx5_verbs.h
  

Patch

diff --git a/drivers/net/mlx5/Makefile b/drivers/net/mlx5/Makefile
index fada6fb..a458402 100644
--- a/drivers/net/mlx5/Makefile
+++ b/drivers/net/mlx5/Makefile
@@ -34,6 +34,7 @@  SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_utils.c
 SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += linux/mlx5_socket.c
 SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += linux/mlx5_os.c
 SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += linux/mlx5_ethdev_os.c
+SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += linux/mlx5_verbs.c
 
 # Basic CFLAGS.
 CFLAGS += -O3
diff --git a/drivers/net/mlx5/linux/meson.build b/drivers/net/mlx5/linux/meson.build
index ad908c4..14eed03 100644
--- a/drivers/net/mlx5/linux/meson.build
+++ b/drivers/net/mlx5/linux/meson.build
@@ -6,5 +6,6 @@  sources += files(
 	'mlx5_socket.c',
 	'mlx5_os.c',
 	'mlx5_ethdev_os.c',
+	'mlx5_verbs.c',
 )
 
diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c
index f498d00..3792371 100644
--- a/drivers/net/mlx5/linux/mlx5_os.c
+++ b/drivers/net/mlx5/linux/mlx5_os.c
@@ -52,6 +52,7 @@ 
 #include "mlx5_mr.h"
 #include "mlx5_flow.h"
 #include "rte_pmd_mlx5.h"
+#include "mlx5_verbs.h"
 
 #define MLX5_TAGS_HLIST_ARRAY_SIZE 8192
 
@@ -2335,8 +2336,8 @@  void
 mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb,
 		      mlx5_dereg_mr_t *dereg_mr_cb)
 {
-	*reg_mr_cb = mlx5_common_verbs_reg_mr;
-	*dereg_mr_cb = mlx5_common_verbs_dereg_mr;
+	*reg_mr_cb = mlx5_verbs_ops.reg_mr;
+	*dereg_mr_cb = mlx5_verbs_ops.dereg_mr;
 }
 
 const struct eth_dev_ops mlx5_os_dev_ops = {
diff --git a/drivers/net/mlx5/linux/mlx5_verbs.c b/drivers/net/mlx5/linux/mlx5_verbs.c
new file mode 100644
index 0000000..8e42ec8
--- /dev/null
+++ b/drivers/net/mlx5/linux/mlx5_verbs.c
@@ -0,0 +1,78 @@ 
+/* 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>
+
+/* Verbs header. */
+/* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
+#include "mlx5_autoconf.h"
+#ifdef PEDANTIC
+#pragma GCC diagnostic ignored "-Wpedantic"
+#endif
+#ifdef HAVE_INFINIBAND_VERBS_H
+#include <infiniband/verbs.h>
+#endif
+#ifdef HAVE_INFINIBAND_MLX5DV_H
+#include <infiniband/mlx5dv.h>
+#endif
+#ifdef PEDANTIC
+#pragma GCC diagnostic error "-Wpedantic"
+#endif
+
+#include <rte_mbuf.h>
+#include <rte_malloc.h>
+#include <rte_ethdev_driver.h>
+#include <rte_common.h>
+
+#include <mlx5_glue.h>
+#include <mlx5_common.h>
+#include <mlx5_common_mr.h>
+#include <mlx5_verbs.h>
+/**
+ * Register mr. Given protection doamin 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] lentgh
+ *   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
+ */
+static int
+mlx5_reg_mr(void *pd, void *addr, size_t length,
+		 struct mlx5_pmd_mr *pmd_mr)
+{
+	return mlx5_common_verbs_reg_mr(pd, addr, length, pmd_mr);
+}
+
+/**
+ * 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
+ *
+ */
+static void
+mlx5_dereg_mr(struct mlx5_pmd_mr *pmd_mr)
+{
+	mlx5_common_verbs_dereg_mr(pmd_mr);
+}
+
+/* verbs operations. */
+const struct mlx5_verbs_ops mlx5_verbs_ops = {
+	.reg_mr = mlx5_reg_mr,
+	.dereg_mr = mlx5_dereg_mr,
+};
diff --git a/drivers/net/mlx5/linux/mlx5_verbs.h b/drivers/net/mlx5/linux/mlx5_verbs.h
new file mode 100644
index 0000000..4f0b637
--- /dev/null
+++ b/drivers/net/mlx5/linux/mlx5_verbs.h
@@ -0,0 +1,15 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2020 Mellanox Technologies, Ltd
+ */
+
+#ifndef RTE_PMD_MLX5_VERBS_H_
+#define RTE_PMD_MLX5_VERBS_H_
+
+struct mlx5_verbs_ops {
+	mlx5_reg_mr_t reg_mr;
+	mlx5_dereg_mr_t dereg_mr;
+};
+
+/* Verbs ops struct */
+extern const struct mlx5_verbs_ops mlx5_verbs_ops;
+#endif /* RTE_PMD_MLX5_VERBS_H_ */