SRCS-y += mlx5_common.c
SRCS-y += linux/mlx5_common_os.c
SRCS-y += linux/mlx5_nl.c
+SRCS-y += linux/mlx5_common_verbs.c
SRCS-y += mlx5_common_mp.c
SRCS-y += mlx5_common_mr.c
ifeq ($(CONFIG_RTE_IBVERBS_LINK_DLOPEN),y)
sources += files('mlx5_nl.c')
sources += files('mlx5_common_os.c')
+sources += files('mlx5_common_verbs.c')
if not dlopen_ibverbs
sources += files('mlx5_glue.c')
endif
--- /dev/null
+/* 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 <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;
+
+ memset(pmd_mr, 0, sizeof(*pmd_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));
+ }
+}
+
if (mr == NULL)
return;
DRV_LOG(DEBUG, "freeing MR(%p):", (void *)mr);
- if (mr->pmd_mr.obj != NULL)
- claim_zero(mlx5_glue->dereg_mr(mr->pmd_mr.obj));
+ mlx5_common_verbs_dereg_mr(&mr->pmd_mr);
if (mr->ms_bmp != NULL)
rte_bitmap_free(mr->ms_bmp);
rte_free(mr);
uint32_t ms_n;
uint32_t n;
size_t len;
- struct ibv_mr *ibv_mr;
DRV_LOG(DEBUG, "Creating a MR using address (%p)", (void *)addr);
/*
* mlx5_alloc_buf_extern() which eventually calls rte_malloc_socket()
* through mlx5_alloc_verbs_buf().
*/
- ibv_mr = mlx5_glue->reg_mr(pd, (void *)data.start, len,
- IBV_ACCESS_LOCAL_WRITE |
- (haswell_broadwell_cpu ? 0 :
- IBV_ACCESS_RELAXED_ORDERING));
- if (ibv_mr == NULL) {
+ mlx5_common_verbs_reg_mr(pd, (void *)data.start, len, &mr->pmd_mr);
+ if (mr->pmd_mr.obj == NULL) {
DEBUG("Fail to create an MR for address (%p)",
(void *)addr);
rte_errno = EINVAL;
goto err_mrlock;
}
- mr->pmd_mr.lkey = ibv_mr->lkey;
- mr->pmd_mr.addr = ibv_mr->addr;
- mr->pmd_mr.len = ibv_mr->length;
- mr->pmd_mr.obj = ibv_mr;
MLX5_ASSERT((uintptr_t)mr->pmd_mr.addr == data.start);
MLX5_ASSERT(mr->pmd_mr.len);
LIST_INSERT_HEAD(&share_cache->mr_list, mr, mr);
struct mlx5_mr *
mlx5_create_mr_ext(void *pd, uintptr_t addr, size_t len, int socket_id)
{
- struct ibv_mr *ibv_mr;
struct mlx5_mr *mr = NULL;
mr = rte_zmalloc_socket(NULL,
RTE_CACHE_LINE_SIZE, socket_id);
if (mr == NULL)
return NULL;
- ibv_mr = mlx5_glue->reg_mr(pd, (void *)addr, len,
- IBV_ACCESS_LOCAL_WRITE |
- (haswell_broadwell_cpu ? 0 :
- IBV_ACCESS_RELAXED_ORDERING));
- if (ibv_mr == NULL) {
+ mlx5_common_verbs_reg_mr(pd, (void *)addr, len, &mr->pmd_mr);
+ if (mr->pmd_mr.obj == NULL) {
DRV_LOG(WARNING,
"Fail to create MR for address (%p)",
(void *)addr);
rte_free(mr);
return NULL;
}
- mr->pmd_mr.lkey = ibv_mr->lkey;
- mr->pmd_mr.addr = ibv_mr->addr;
- mr->pmd_mr.len = ibv_mr->length;
- mr->pmd_mr.obj = ibv_mr;
mr->msl = NULL; /* Mark it is external memory. */
mr->ms_bmp = NULL;
mr->ms_n = 1;
struct mlx5_mr_share_cache *share_cache,
struct mr_cache_entry *entry, uintptr_t addr,
unsigned int mr_ext_memseg_en);
-
+__rte_internal
+int
+mlx5_common_verbs_reg_mr(void *pd, void *addr, size_t length,
+ struct mlx5_pmd_mr *pmd_mr);
+__rte_internal
+void
+mlx5_common_verbs_dereg_mr(struct mlx5_pmd_mr *pmd_mr);
#endif /* RTE_PMD_MLX5_COMMON_MR_H_ */
mlx5_class_get;
+ mlx5_common_verbs_reg_mr;
+ mlx5_common_verbs_dereg_mr;
+
mlx5_create_mr_ext;
mlx5_dev_to_pci_addr;