From 4f96d91396790e63d238403d1e61699d53996dbf Mon Sep 17 00:00:00 2001 From: Ophir Munk Date: Tue, 16 Jun 2020 09:44:46 +0000 Subject: [PATCH] net/mlx5/linux: add memory region callbacks to Verbs 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 Acked-by: Matan Azrad --- 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 diff --git a/drivers/net/mlx5/Makefile b/drivers/net/mlx5/Makefile index fada6fb6a2..a458402dcc 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 ad908c4473..14eed03cca 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 f498d00ae3..3792371c30 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 0000000000..6b59fa1712 --- /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 +#include +#include +#include +#include +#include +#include + +/* 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 +#endif +#ifdef HAVE_INFINIBAND_MLX5DV_H +#include +#endif +#ifdef PEDANTIC +#pragma GCC diagnostic error "-Wpedantic" +#endif + +#include +#include +#include +#include + +#include +#include +#include +#include +/** + * 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 index 0000000000..4f0b63754d --- /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_ */ -- 2.20.1