be684d3787182e88d53a6a4f55844e37df06a01c
[dpdk.git] / drivers / net / mlx5 / mlx5_glue.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2018 6WIND S.A.
3  * Copyright 2018 Mellanox Technologies, Ltd.
4  */
5
6 #include <errno.h>
7 #include <stddef.h>
8 #include <stdint.h>
9
10 /*
11  * Not needed by this file; included to work around the lack of off_t
12  * definition for mlx5dv.h with unpatched rdma-core versions.
13  */
14 #include <sys/types.h>
15
16 /* Verbs headers do not support -pedantic. */
17 #ifdef PEDANTIC
18 #pragma GCC diagnostic ignored "-Wpedantic"
19 #endif
20 #include <infiniband/mlx5dv.h>
21 #include <infiniband/verbs.h>
22 #ifdef PEDANTIC
23 #pragma GCC diagnostic error "-Wpedantic"
24 #endif
25
26 #include "mlx5_autoconf.h"
27 #include "mlx5_glue.h"
28
29 static int
30 mlx5_glue_fork_init(void)
31 {
32         return ibv_fork_init();
33 }
34
35 static struct ibv_pd *
36 mlx5_glue_alloc_pd(struct ibv_context *context)
37 {
38         return ibv_alloc_pd(context);
39 }
40
41 static int
42 mlx5_glue_dealloc_pd(struct ibv_pd *pd)
43 {
44         return ibv_dealloc_pd(pd);
45 }
46
47 static struct ibv_device **
48 mlx5_glue_get_device_list(int *num_devices)
49 {
50         return ibv_get_device_list(num_devices);
51 }
52
53 static void
54 mlx5_glue_free_device_list(struct ibv_device **list)
55 {
56         ibv_free_device_list(list);
57 }
58
59 static struct ibv_context *
60 mlx5_glue_open_device(struct ibv_device *device)
61 {
62         return ibv_open_device(device);
63 }
64
65 static int
66 mlx5_glue_close_device(struct ibv_context *context)
67 {
68         return ibv_close_device(context);
69 }
70
71 static int
72 mlx5_glue_query_device(struct ibv_context *context,
73                        struct ibv_device_attr *device_attr)
74 {
75         return ibv_query_device(context, device_attr);
76 }
77
78 static int
79 mlx5_glue_query_device_ex(struct ibv_context *context,
80                           const struct ibv_query_device_ex_input *input,
81                           struct ibv_device_attr_ex *attr)
82 {
83         return ibv_query_device_ex(context, input, attr);
84 }
85
86 static int
87 mlx5_glue_query_port(struct ibv_context *context, uint8_t port_num,
88                      struct ibv_port_attr *port_attr)
89 {
90         return ibv_query_port(context, port_num, port_attr);
91 }
92
93 static struct ibv_comp_channel *
94 mlx5_glue_create_comp_channel(struct ibv_context *context)
95 {
96         return ibv_create_comp_channel(context);
97 }
98
99 static int
100 mlx5_glue_destroy_comp_channel(struct ibv_comp_channel *channel)
101 {
102         return ibv_destroy_comp_channel(channel);
103 }
104
105 static struct ibv_cq *
106 mlx5_glue_create_cq(struct ibv_context *context, int cqe, void *cq_context,
107                     struct ibv_comp_channel *channel, int comp_vector)
108 {
109         return ibv_create_cq(context, cqe, cq_context, channel, comp_vector);
110 }
111
112 static int
113 mlx5_glue_destroy_cq(struct ibv_cq *cq)
114 {
115         return ibv_destroy_cq(cq);
116 }
117
118 static int
119 mlx5_glue_get_cq_event(struct ibv_comp_channel *channel, struct ibv_cq **cq,
120                        void **cq_context)
121 {
122         return ibv_get_cq_event(channel, cq, cq_context);
123 }
124
125 static void
126 mlx5_glue_ack_cq_events(struct ibv_cq *cq, unsigned int nevents)
127 {
128         ibv_ack_cq_events(cq, nevents);
129 }
130
131 static struct ibv_rwq_ind_table *
132 mlx5_glue_create_rwq_ind_table(struct ibv_context *context,
133                                struct ibv_rwq_ind_table_init_attr *init_attr)
134 {
135         return ibv_create_rwq_ind_table(context, init_attr);
136 }
137
138 static int
139 mlx5_glue_destroy_rwq_ind_table(struct ibv_rwq_ind_table *rwq_ind_table)
140 {
141         return ibv_destroy_rwq_ind_table(rwq_ind_table);
142 }
143
144 static struct ibv_wq *
145 mlx5_glue_create_wq(struct ibv_context *context,
146                     struct ibv_wq_init_attr *wq_init_attr)
147 {
148         return ibv_create_wq(context, wq_init_attr);
149 }
150
151 static int
152 mlx5_glue_destroy_wq(struct ibv_wq *wq)
153 {
154         return ibv_destroy_wq(wq);
155 }
156 static int
157 mlx5_glue_modify_wq(struct ibv_wq *wq, struct ibv_wq_attr *wq_attr)
158 {
159         return ibv_modify_wq(wq, wq_attr);
160 }
161
162 static struct ibv_flow *
163 mlx5_glue_create_flow(struct ibv_qp *qp, struct ibv_flow_attr *flow)
164 {
165         return ibv_create_flow(qp, flow);
166 }
167
168 static int
169 mlx5_glue_destroy_flow(struct ibv_flow *flow_id)
170 {
171         return ibv_destroy_flow(flow_id);
172 }
173
174 static struct ibv_qp *
175 mlx5_glue_create_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *qp_init_attr)
176 {
177         return ibv_create_qp(pd, qp_init_attr);
178 }
179
180 static struct ibv_qp *
181 mlx5_glue_create_qp_ex(struct ibv_context *context,
182                        struct ibv_qp_init_attr_ex *qp_init_attr_ex)
183 {
184         return ibv_create_qp_ex(context, qp_init_attr_ex);
185 }
186
187 static int
188 mlx5_glue_destroy_qp(struct ibv_qp *qp)
189 {
190         return ibv_destroy_qp(qp);
191 }
192
193 static int
194 mlx5_glue_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, int attr_mask)
195 {
196         return ibv_modify_qp(qp, attr, attr_mask);
197 }
198
199 static struct ibv_mr *
200 mlx5_glue_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access)
201 {
202         return ibv_reg_mr(pd, addr, length, access);
203 }
204
205 static int
206 mlx5_glue_dereg_mr(struct ibv_mr *mr)
207 {
208         return ibv_dereg_mr(mr);
209 }
210
211 static struct ibv_counter_set *
212 mlx5_glue_create_counter_set(struct ibv_context *context,
213                              struct ibv_counter_set_init_attr *init_attr)
214 {
215 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT
216         (void)context;
217         (void)init_attr;
218         return NULL;
219 #else
220         return ibv_create_counter_set(context, init_attr);
221 #endif
222 }
223
224 static int
225 mlx5_glue_destroy_counter_set(struct ibv_counter_set *cs)
226 {
227 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT
228         (void)cs;
229         return ENOTSUP;
230 #else
231         return ibv_destroy_counter_set(cs);
232 #endif
233 }
234
235 static int
236 mlx5_glue_describe_counter_set(struct ibv_context *context,
237                                uint16_t counter_set_id,
238                                struct ibv_counter_set_description *cs_desc)
239 {
240 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT
241         (void)context;
242         (void)counter_set_id;
243         (void)cs_desc;
244         return ENOTSUP;
245 #else
246         return ibv_describe_counter_set(context, counter_set_id, cs_desc);
247 #endif
248 }
249
250 static int
251 mlx5_glue_query_counter_set(struct ibv_query_counter_set_attr *query_attr,
252                             struct ibv_counter_set_data *cs_data)
253 {
254 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT
255         (void)query_attr;
256         (void)cs_data;
257         return ENOTSUP;
258 #else
259         return ibv_query_counter_set(query_attr, cs_data);
260 #endif
261 }
262
263 static void
264 mlx5_glue_ack_async_event(struct ibv_async_event *event)
265 {
266         ibv_ack_async_event(event);
267 }
268
269 static int
270 mlx5_glue_get_async_event(struct ibv_context *context,
271                           struct ibv_async_event *event)
272 {
273         return ibv_get_async_event(context, event);
274 }
275
276 static const char *
277 mlx5_glue_port_state_str(enum ibv_port_state port_state)
278 {
279         return ibv_port_state_str(port_state);
280 }
281
282 static struct ibv_cq *
283 mlx5_glue_cq_ex_to_cq(struct ibv_cq_ex *cq)
284 {
285         return ibv_cq_ex_to_cq(cq);
286 }
287
288 static struct ibv_cq_ex *
289 mlx5_glue_dv_create_cq(struct ibv_context *context,
290                        struct ibv_cq_init_attr_ex *cq_attr,
291                        struct mlx5dv_cq_init_attr *mlx5_cq_attr)
292 {
293         return mlx5dv_create_cq(context, cq_attr, mlx5_cq_attr);
294 }
295
296 static int
297 mlx5_glue_dv_query_device(struct ibv_context *ctx,
298                           struct mlx5dv_context *attrs_out)
299 {
300         return mlx5dv_query_device(ctx, attrs_out);
301 }
302
303 static int
304 mlx5_glue_dv_set_context_attr(struct ibv_context *ibv_ctx,
305                               enum mlx5dv_set_ctx_attr_type type, void *attr)
306 {
307         return mlx5dv_set_context_attr(ibv_ctx, type, attr);
308 }
309
310 static int
311 mlx5_glue_dv_init_obj(struct mlx5dv_obj *obj, uint64_t obj_type)
312 {
313         return mlx5dv_init_obj(obj, obj_type);
314 }
315
316 const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue){
317         .version = MLX5_GLUE_VERSION,
318         .fork_init = mlx5_glue_fork_init,
319         .alloc_pd = mlx5_glue_alloc_pd,
320         .dealloc_pd = mlx5_glue_dealloc_pd,
321         .get_device_list = mlx5_glue_get_device_list,
322         .free_device_list = mlx5_glue_free_device_list,
323         .open_device = mlx5_glue_open_device,
324         .close_device = mlx5_glue_close_device,
325         .query_device = mlx5_glue_query_device,
326         .query_device_ex = mlx5_glue_query_device_ex,
327         .query_port = mlx5_glue_query_port,
328         .create_comp_channel = mlx5_glue_create_comp_channel,
329         .destroy_comp_channel = mlx5_glue_destroy_comp_channel,
330         .create_cq = mlx5_glue_create_cq,
331         .destroy_cq = mlx5_glue_destroy_cq,
332         .get_cq_event = mlx5_glue_get_cq_event,
333         .ack_cq_events = mlx5_glue_ack_cq_events,
334         .create_rwq_ind_table = mlx5_glue_create_rwq_ind_table,
335         .destroy_rwq_ind_table = mlx5_glue_destroy_rwq_ind_table,
336         .create_wq = mlx5_glue_create_wq,
337         .destroy_wq = mlx5_glue_destroy_wq,
338         .modify_wq = mlx5_glue_modify_wq,
339         .create_flow = mlx5_glue_create_flow,
340         .destroy_flow = mlx5_glue_destroy_flow,
341         .create_qp = mlx5_glue_create_qp,
342         .create_qp_ex = mlx5_glue_create_qp_ex,
343         .destroy_qp = mlx5_glue_destroy_qp,
344         .modify_qp = mlx5_glue_modify_qp,
345         .reg_mr = mlx5_glue_reg_mr,
346         .dereg_mr = mlx5_glue_dereg_mr,
347         .create_counter_set = mlx5_glue_create_counter_set,
348         .destroy_counter_set = mlx5_glue_destroy_counter_set,
349         .describe_counter_set = mlx5_glue_describe_counter_set,
350         .query_counter_set = mlx5_glue_query_counter_set,
351         .ack_async_event = mlx5_glue_ack_async_event,
352         .get_async_event = mlx5_glue_get_async_event,
353         .port_state_str = mlx5_glue_port_state_str,
354         .cq_ex_to_cq = mlx5_glue_cq_ex_to_cq,
355         .dv_create_cq = mlx5_glue_dv_create_cq,
356         .dv_query_device = mlx5_glue_dv_query_device,
357         .dv_set_context_attr = mlx5_glue_dv_set_context_attr,
358         .dv_init_obj = mlx5_glue_dv_init_obj,
359 };