net/mlx5/linux: add memory region callbacks to Verbs
authorOphir Munk <ophirmu@mellanox.com>
Tue, 16 Jun 2020 09:44:46 +0000 (09:44 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Wed, 17 Jun 2020 14:32:01 +0000 (16:32 +0200)
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
drivers/net/mlx5/linux/meson.build
drivers/net/mlx5/linux/mlx5_os.c
drivers/net/mlx5/linux/mlx5_verbs.c [new file with mode: 0644]
drivers/net/mlx5/linux/mlx5_verbs.h [new file with mode: 0644]

index fada6fb..a458402 100644 (file)
@@ -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
index ad908c4..14eed03 100644 (file)
@@ -6,5 +6,6 @@ sources += files(
        'mlx5_socket.c',
        'mlx5_os.c',
        'mlx5_ethdev_os.c',
+       'mlx5_verbs.c',
 )
 
index f498d00..3792371 100644 (file)
@@ -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 (file)
index 0000000..6b59fa1
--- /dev/null
@@ -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 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
+ */
+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 (file)
index 0000000..4f0b637
--- /dev/null
@@ -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_ */