1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2020 Mellanox Technologies, Ltd
13 #include <rte_errno.h>
14 #include <rte_bus_pci.h>
15 #include <rte_bus_auxiliary.h>
17 #include "mlx5_common_utils.h"
18 #include "mlx5_common_log.h"
19 #include "mlx5_common_private.h"
20 #include "mlx5_autoconf.h"
21 #include <mlx5_glue.h>
22 #include <mlx5_common.h>
23 #include <mlx5_common_mr.h>
26 mlx5_os_get_ibv_dev(const struct rte_device *dev)
28 struct ibv_device *ibv;
30 if (mlx5_dev_is_pci(dev))
31 ibv = mlx5_os_get_ibv_device(&RTE_DEV_TO_PCI_CONST(dev)->addr);
33 ibv = mlx5_get_aux_ibv_device(RTE_DEV_TO_AUXILIARY_CONST(dev));
36 DRV_LOG(ERR, "Verbs device not found: %s", dev->name);
42 * Register mr. Given protection domain pointer, pointer to addr and length
43 * register the memory region.
46 * Pointer to protection domain context.
48 * Pointer to memory start address.
50 * Length of the memory to register.
52 * pmd_mr struct set with lkey, address, length and pointer to mr object
55 * 0 on successful registration, -1 otherwise
58 mlx5_common_verbs_reg_mr(void *pd, void *addr, size_t length,
59 struct mlx5_pmd_mr *pmd_mr)
61 struct ibv_mr *ibv_mr;
63 ibv_mr = mlx5_glue->reg_mr(pd, addr, length,
64 IBV_ACCESS_LOCAL_WRITE |
65 (haswell_broadwell_cpu ? 0 :
66 IBV_ACCESS_RELAXED_ORDERING));
70 *pmd_mr = (struct mlx5_pmd_mr){
73 .len = ibv_mr->length,
74 .obj = (void *)ibv_mr,
80 * Deregister mr. Given the mlx5 pmd MR - deregister the MR
83 * pmd_mr struct set with lkey, address, length and pointer to mr object
87 mlx5_common_verbs_dereg_mr(struct mlx5_pmd_mr *pmd_mr)
89 if (pmd_mr && pmd_mr->obj != NULL) {
90 claim_zero(mlx5_glue->dereg_mr(pmd_mr->obj));
91 memset(pmd_mr, 0, sizeof(*pmd_mr));