vdpa/mlx5: prepare HW queues
[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 #include <rte_spinlock.h>
19 #include <rte_interrupts.h>
20
21 #include <mlx5_glue.h>
22 #include <mlx5_devx_cmds.h>
23 #include <mlx5_prm.h>
24
25
26 #define MLX5_VDPA_INTR_RETRIES 256
27 #define MLX5_VDPA_INTR_RETRIES_USEC 1000
28
29 struct mlx5_vdpa_cq {
30         uint16_t log_desc_n;
31         uint32_t cq_ci:24;
32         uint32_t arm_sn:2;
33         rte_spinlock_t sl;
34         struct mlx5_devx_obj *cq;
35         struct mlx5dv_devx_umem *umem_obj;
36         union {
37                 volatile void *umem_buf;
38                 volatile struct mlx5_cqe *cqes;
39         };
40         volatile uint32_t *db_rec;
41         uint64_t errors;
42 };
43
44 struct mlx5_vdpa_event_qp {
45         struct mlx5_vdpa_cq cq;
46         struct mlx5_devx_obj *fw_qp;
47         struct mlx5_devx_obj *sw_qp;
48         struct mlx5dv_devx_umem *umem_obj;
49         void *umem_buf;
50         volatile uint32_t *db_rec;
51 };
52
53 struct mlx5_vdpa_query_mr {
54         SLIST_ENTRY(mlx5_vdpa_query_mr) next;
55         void *addr;
56         uint64_t length;
57         struct mlx5dv_devx_umem *umem;
58         struct mlx5_devx_obj *mkey;
59         int is_indirect;
60 };
61
62 struct mlx5_vdpa_priv {
63         TAILQ_ENTRY(mlx5_vdpa_priv) next;
64         int id; /* vDPA device id. */
65         int vid; /* vhost device id. */
66         struct ibv_context *ctx; /* Device context. */
67         struct rte_vdpa_dev_addr dev_addr;
68         struct mlx5_hca_vdpa_attr caps;
69         uint32_t pdn; /* Protection Domain number. */
70         struct ibv_pd *pd;
71         uint32_t gpa_mkey_index;
72         struct ibv_mr *null_mr;
73         struct rte_vhost_memory *vmem;
74         uint32_t eqn;
75         struct mlx5dv_devx_event_channel *eventc;
76         struct mlx5dv_devx_uar *uar;
77         struct rte_intr_handle intr_handle;
78         SLIST_HEAD(mr_list, mlx5_vdpa_query_mr) mr_list;
79 };
80
81 /**
82  * Release all the prepared memory regions and all their related resources.
83  *
84  * @param[in] priv
85  *   The vdpa driver private structure.
86  */
87 void mlx5_vdpa_mem_dereg(struct mlx5_vdpa_priv *priv);
88
89 /**
90  * Register all the memory regions of the virtio device to the HW and allocate
91  * all their related resources.
92  *
93  * @param[in] priv
94  *   The vdpa driver private structure.
95  *
96  * @return
97  *   0 on success, a negative errno value otherwise and rte_errno is set.
98  */
99 int mlx5_vdpa_mem_register(struct mlx5_vdpa_priv *priv);
100
101
102 /**
103  * Create an event QP and all its related resources.
104  *
105  * @param[in] priv
106  *   The vdpa driver private structure.
107  * @param[in] desc_n
108  *   Number of descriptors.
109  * @param[in] callfd
110  *   The guest notification file descriptor.
111  * @param[in/out] eqp
112  *   Pointer to the event QP structure.
113  *
114  * @return
115  *   0 on success, -1 otherwise and rte_errno is set.
116  */
117 int mlx5_vdpa_event_qp_create(struct mlx5_vdpa_priv *priv, uint16_t desc_n,
118                               int callfd, struct mlx5_vdpa_event_qp *eqp);
119
120 /**
121  * Destroy an event QP and all its related resources.
122  *
123  * @param[in/out] eqp
124  *   Pointer to the event QP structure.
125  */
126 void mlx5_vdpa_event_qp_destroy(struct mlx5_vdpa_event_qp *eqp);
127
128 /**
129  * Release all the event global resources.
130  *
131  * @param[in] priv
132  *   The vdpa driver private structure.
133  */
134 void mlx5_vdpa_event_qp_global_release(struct mlx5_vdpa_priv *priv);
135
136 /**
137  * Setup CQE event.
138  *
139  * @param[in] priv
140  *   The vdpa driver private structure.
141  *
142  * @return
143  *   0 on success, a negative errno value otherwise and rte_errno is set.
144  */
145 int mlx5_vdpa_cqe_event_setup(struct mlx5_vdpa_priv *priv);
146
147 /**
148  * Unset CQE event .
149  *
150  * @param[in] priv
151  *   The vdpa driver private structure.
152  */
153 void mlx5_vdpa_cqe_event_unset(struct mlx5_vdpa_priv *priv);
154
155 #endif /* RTE_PMD_MLX5_VDPA_H_ */