vdpa/mlx5: prepare memory regions
[dpdk.git] / drivers / vdpa / mlx5 / mlx5_vdpa.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2019 Mellanox Technologies, Ltd
3  */
4
5 #ifndef RTE_PMD_MLX5_VDPA_H_
6 #define RTE_PMD_MLX5_VDPA_H_
7
8 #include <sys/queue.h>
9
10 #ifdef PEDANTIC
11 #pragma GCC diagnostic ignored "-Wpedantic"
12 #endif
13 #include <rte_vdpa.h>
14 #include <rte_vhost.h>
15 #ifdef PEDANTIC
16 #pragma GCC diagnostic error "-Wpedantic"
17 #endif
18
19 #include <mlx5_glue.h>
20 #include <mlx5_devx_cmds.h>
21
22 struct mlx5_vdpa_query_mr {
23         SLIST_ENTRY(mlx5_vdpa_query_mr) next;
24         void *addr;
25         uint64_t length;
26         struct mlx5dv_devx_umem *umem;
27         struct mlx5_devx_obj *mkey;
28         int is_indirect;
29 };
30
31 struct mlx5_vdpa_priv {
32         TAILQ_ENTRY(mlx5_vdpa_priv) next;
33         int id; /* vDPA device id. */
34         int vid; /* vhost device id. */
35         struct ibv_context *ctx; /* Device context. */
36         struct rte_vdpa_dev_addr dev_addr;
37         struct mlx5_hca_vdpa_attr caps;
38         uint32_t pdn; /* Protection Domain number. */
39         struct ibv_pd *pd;
40         uint32_t gpa_mkey_index;
41         struct ibv_mr *null_mr;
42         struct rte_vhost_memory *vmem;
43         SLIST_HEAD(mr_list, mlx5_vdpa_query_mr) mr_list;
44 };
45
46 /**
47  * Release all the prepared memory regions and all their related resources.
48  *
49  * @param[in] priv
50  *   The vdpa driver private structure.
51  */
52 void mlx5_vdpa_mem_dereg(struct mlx5_vdpa_priv *priv);
53
54 /**
55  * Register all the memory regions of the virtio device to the HW and allocate
56  * all their related resources.
57  *
58  * @param[in] priv
59  *   The vdpa driver private structure.
60  *
61  * @return
62  *   0 on success, a negative errno value otherwise and rte_errno is set.
63  */
64 int mlx5_vdpa_mem_register(struct mlx5_vdpa_priv *priv);
65
66 #endif /* RTE_PMD_MLX5_VDPA_H_ */