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 <stdalign.h>
8 #include <stddef.h>
9 #include <stdint.h>
10 #include <stdlib.h>
11 /*
12 * Not needed by this file; included to work around the lack of off_t
13 * definition for mlx5dv.h with unpatched rdma-core versions.
14 */
15 #include <sys/types.h>
16
17 #include "mlx5_glue.h"
18
19 static int
mlx5_glue_fork_init(void)20 mlx5_glue_fork_init(void)
21 {
22 return ibv_fork_init();
23 }
24
25 static struct ibv_pd *
mlx5_glue_alloc_pd(struct ibv_context * context)26 mlx5_glue_alloc_pd(struct ibv_context *context)
27 {
28 return ibv_alloc_pd(context);
29 }
30
31 static int
mlx5_glue_dealloc_pd(struct ibv_pd * pd)32 mlx5_glue_dealloc_pd(struct ibv_pd *pd)
33 {
34 return ibv_dealloc_pd(pd);
35 }
36
37 static struct ibv_pd *
mlx5_glue_import_pd(struct ibv_context * context,uint32_t pd_handle)38 mlx5_glue_import_pd(struct ibv_context *context, uint32_t pd_handle)
39 {
40 #ifdef HAVE_MLX5_IBV_IMPORT_CTX_PD_AND_MR
41 return ibv_import_pd(context, pd_handle);
42 #else
43 (void)context;
44 (void)pd_handle;
45 errno = ENOTSUP;
46 return NULL;
47 #endif
48 }
49
50 static int
mlx5_glue_unimport_pd(struct ibv_pd * pd)51 mlx5_glue_unimport_pd(struct ibv_pd *pd)
52 {
53 #ifdef HAVE_MLX5_IBV_IMPORT_CTX_PD_AND_MR
54 ibv_unimport_pd(pd);
55 return 0;
56 #else
57 (void)pd;
58 errno = ENOTSUP;
59 return -errno;
60 #endif
61 }
62
63 static struct ibv_device **
mlx5_glue_get_device_list(int * num_devices)64 mlx5_glue_get_device_list(int *num_devices)
65 {
66 return ibv_get_device_list(num_devices);
67 }
68
69 static void
mlx5_glue_free_device_list(struct ibv_device ** list)70 mlx5_glue_free_device_list(struct ibv_device **list)
71 {
72 ibv_free_device_list(list);
73 }
74
75 static struct ibv_context *
mlx5_glue_open_device(struct ibv_device * device)76 mlx5_glue_open_device(struct ibv_device *device)
77 {
78 return ibv_open_device(device);
79 }
80
81 static struct ibv_context *
mlx5_glue_import_device(int cmd_fd)82 mlx5_glue_import_device(int cmd_fd)
83 {
84 #ifdef HAVE_MLX5_IBV_IMPORT_CTX_PD_AND_MR
85 return ibv_import_device(cmd_fd);
86 #else
87 (void)cmd_fd;
88 errno = ENOTSUP;
89 return NULL;
90 #endif
91 }
92
93 static int
mlx5_glue_close_device(struct ibv_context * context)94 mlx5_glue_close_device(struct ibv_context *context)
95 {
96 return ibv_close_device(context);
97 }
98
99 static int
mlx5_glue_query_device(struct ibv_context * context,struct ibv_device_attr * device_attr)100 mlx5_glue_query_device(struct ibv_context *context,
101 struct ibv_device_attr *device_attr)
102 {
103 return ibv_query_device(context, device_attr);
104 }
105
106 static int
mlx5_glue_query_device_ex(struct ibv_context * context,const struct ibv_query_device_ex_input * input,struct ibv_device_attr_ex * attr)107 mlx5_glue_query_device_ex(struct ibv_context *context,
108 const struct ibv_query_device_ex_input *input,
109 struct ibv_device_attr_ex *attr)
110 {
111 return ibv_query_device_ex(context, input, attr);
112 }
113
114 static int
mlx5_glue_query_rt_values_ex(struct ibv_context * context,struct ibv_values_ex * values)115 mlx5_glue_query_rt_values_ex(struct ibv_context *context,
116 struct ibv_values_ex *values)
117 {
118 return ibv_query_rt_values_ex(context, values);
119 }
120
121 static int
mlx5_glue_query_port(struct ibv_context * context,uint8_t port_num,struct ibv_port_attr * port_attr)122 mlx5_glue_query_port(struct ibv_context *context, uint8_t port_num,
123 struct ibv_port_attr *port_attr)
124 {
125 return ibv_query_port(context, port_num, port_attr);
126 }
127
128 static struct ibv_comp_channel *
mlx5_glue_create_comp_channel(struct ibv_context * context)129 mlx5_glue_create_comp_channel(struct ibv_context *context)
130 {
131 return ibv_create_comp_channel(context);
132 }
133
134 static int
mlx5_glue_destroy_comp_channel(struct ibv_comp_channel * channel)135 mlx5_glue_destroy_comp_channel(struct ibv_comp_channel *channel)
136 {
137 return ibv_destroy_comp_channel(channel);
138 }
139
140 static struct ibv_cq *
mlx5_glue_create_cq(struct ibv_context * context,int cqe,void * cq_context,struct ibv_comp_channel * channel,int comp_vector)141 mlx5_glue_create_cq(struct ibv_context *context, int cqe, void *cq_context,
142 struct ibv_comp_channel *channel, int comp_vector)
143 {
144 return ibv_create_cq(context, cqe, cq_context, channel, comp_vector);
145 }
146
147 static int
mlx5_glue_destroy_cq(struct ibv_cq * cq)148 mlx5_glue_destroy_cq(struct ibv_cq *cq)
149 {
150 return ibv_destroy_cq(cq);
151 }
152
153 static int
mlx5_glue_get_cq_event(struct ibv_comp_channel * channel,struct ibv_cq ** cq,void ** cq_context)154 mlx5_glue_get_cq_event(struct ibv_comp_channel *channel, struct ibv_cq **cq,
155 void **cq_context)
156 {
157 return ibv_get_cq_event(channel, cq, cq_context);
158 }
159
160 static void
mlx5_glue_ack_cq_events(struct ibv_cq * cq,unsigned int nevents)161 mlx5_glue_ack_cq_events(struct ibv_cq *cq, unsigned int nevents)
162 {
163 ibv_ack_cq_events(cq, nevents);
164 }
165
166 static struct ibv_rwq_ind_table *
mlx5_glue_create_rwq_ind_table(struct ibv_context * context,struct ibv_rwq_ind_table_init_attr * init_attr)167 mlx5_glue_create_rwq_ind_table(struct ibv_context *context,
168 struct ibv_rwq_ind_table_init_attr *init_attr)
169 {
170 return ibv_create_rwq_ind_table(context, init_attr);
171 }
172
173 static int
mlx5_glue_destroy_rwq_ind_table(struct ibv_rwq_ind_table * rwq_ind_table)174 mlx5_glue_destroy_rwq_ind_table(struct ibv_rwq_ind_table *rwq_ind_table)
175 {
176 return ibv_destroy_rwq_ind_table(rwq_ind_table);
177 }
178
179 static struct ibv_wq *
mlx5_glue_create_wq(struct ibv_context * context,struct ibv_wq_init_attr * wq_init_attr)180 mlx5_glue_create_wq(struct ibv_context *context,
181 struct ibv_wq_init_attr *wq_init_attr)
182 {
183 return ibv_create_wq(context, wq_init_attr);
184 }
185
186 static int
mlx5_glue_destroy_wq(struct ibv_wq * wq)187 mlx5_glue_destroy_wq(struct ibv_wq *wq)
188 {
189 return ibv_destroy_wq(wq);
190 }
191 static int
mlx5_glue_modify_wq(struct ibv_wq * wq,struct ibv_wq_attr * wq_attr)192 mlx5_glue_modify_wq(struct ibv_wq *wq, struct ibv_wq_attr *wq_attr)
193 {
194 return ibv_modify_wq(wq, wq_attr);
195 }
196
197 static struct ibv_flow *
mlx5_glue_create_flow(struct ibv_qp * qp,struct ibv_flow_attr * flow)198 mlx5_glue_create_flow(struct ibv_qp *qp, struct ibv_flow_attr *flow)
199 {
200 return ibv_create_flow(qp, flow);
201 }
202
203 static int
mlx5_glue_destroy_flow(struct ibv_flow * flow_id)204 mlx5_glue_destroy_flow(struct ibv_flow *flow_id)
205 {
206 return ibv_destroy_flow(flow_id);
207 }
208
209 static int
mlx5_glue_destroy_flow_action(void * action)210 mlx5_glue_destroy_flow_action(void *action)
211 {
212 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
213 #ifdef HAVE_MLX5DV_DR
214 return mlx5dv_dr_action_destroy(action);
215 #else
216 struct mlx5dv_flow_action_attr *attr = action;
217 int res = 0;
218 switch (attr->type) {
219 case MLX5DV_FLOW_ACTION_TAG:
220 break;
221 default:
222 res = ibv_destroy_flow_action(attr->action);
223 break;
224 }
225 free(action);
226 return res;
227 #endif
228 #else
229 (void)action;
230 return -ENOTSUP;
231 #endif
232 }
233
234 static struct ibv_qp *
mlx5_glue_create_qp(struct ibv_pd * pd,struct ibv_qp_init_attr * qp_init_attr)235 mlx5_glue_create_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *qp_init_attr)
236 {
237 return ibv_create_qp(pd, qp_init_attr);
238 }
239
240 static struct ibv_qp *
mlx5_glue_create_qp_ex(struct ibv_context * context,struct ibv_qp_init_attr_ex * qp_init_attr_ex)241 mlx5_glue_create_qp_ex(struct ibv_context *context,
242 struct ibv_qp_init_attr_ex *qp_init_attr_ex)
243 {
244 return ibv_create_qp_ex(context, qp_init_attr_ex);
245 }
246
247 static int
mlx5_glue_destroy_qp(struct ibv_qp * qp)248 mlx5_glue_destroy_qp(struct ibv_qp *qp)
249 {
250 return ibv_destroy_qp(qp);
251 }
252
253 static int
mlx5_glue_modify_qp(struct ibv_qp * qp,struct ibv_qp_attr * attr,int attr_mask)254 mlx5_glue_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, int attr_mask)
255 {
256 return ibv_modify_qp(qp, attr, attr_mask);
257 }
258
259 static struct ibv_mr *
mlx5_glue_reg_mr(struct ibv_pd * pd,void * addr,size_t length,int access)260 mlx5_glue_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access)
261 {
262 return ibv_reg_mr(pd, addr, length, access);
263 }
264
265 static struct ibv_mr *
mlx5_glue_reg_mr_iova(struct ibv_pd * pd,void * addr,size_t length,uint64_t iova,int access)266 mlx5_glue_reg_mr_iova(struct ibv_pd *pd, void *addr, size_t length,
267 uint64_t iova, int access)
268 {
269 #ifdef HAVE_MLX5_IBV_REG_MR_IOVA
270 return ibv_reg_mr_iova(pd, addr, length, iova, access);
271 #else
272 (void)pd;
273 (void)addr;
274 (void)length;
275 (void)iova;
276 (void)access;
277 errno = ENOTSUP;
278 return NULL;
279 #endif
280 }
281
282 static struct ibv_mr *
mlx5_glue_alloc_null_mr(struct ibv_pd * pd)283 mlx5_glue_alloc_null_mr(struct ibv_pd *pd)
284 {
285 #ifdef HAVE_IBV_DEVX_OBJ
286 return ibv_alloc_null_mr(pd);
287 #else
288 (void)pd;
289 errno = ENOTSUP;
290 return NULL;
291 #endif
292 }
293
294 static int
mlx5_glue_dereg_mr(struct ibv_mr * mr)295 mlx5_glue_dereg_mr(struct ibv_mr *mr)
296 {
297 return ibv_dereg_mr(mr);
298 }
299
300 static struct ibv_counter_set *
mlx5_glue_create_counter_set(struct ibv_context * context,struct ibv_counter_set_init_attr * init_attr)301 mlx5_glue_create_counter_set(struct ibv_context *context,
302 struct ibv_counter_set_init_attr *init_attr)
303 {
304 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
305 (void)context;
306 (void)init_attr;
307 return NULL;
308 #else
309 return ibv_create_counter_set(context, init_attr);
310 #endif
311 }
312
313 static int
mlx5_glue_destroy_counter_set(struct ibv_counter_set * cs)314 mlx5_glue_destroy_counter_set(struct ibv_counter_set *cs)
315 {
316 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
317 (void)cs;
318 return -ENOTSUP;
319 #else
320 return ibv_destroy_counter_set(cs);
321 #endif
322 }
323
324 static int
mlx5_glue_describe_counter_set(struct ibv_context * context,uint16_t counter_set_id,struct ibv_counter_set_description * cs_desc)325 mlx5_glue_describe_counter_set(struct ibv_context *context,
326 uint16_t counter_set_id,
327 struct ibv_counter_set_description *cs_desc)
328 {
329 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
330 (void)context;
331 (void)counter_set_id;
332 (void)cs_desc;
333 return -ENOTSUP;
334 #else
335 return ibv_describe_counter_set(context, counter_set_id, cs_desc);
336 #endif
337 }
338
339 static int
mlx5_glue_query_counter_set(struct ibv_query_counter_set_attr * query_attr,struct ibv_counter_set_data * cs_data)340 mlx5_glue_query_counter_set(struct ibv_query_counter_set_attr *query_attr,
341 struct ibv_counter_set_data *cs_data)
342 {
343 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
344 (void)query_attr;
345 (void)cs_data;
346 return -ENOTSUP;
347 #else
348 return ibv_query_counter_set(query_attr, cs_data);
349 #endif
350 }
351
352 static struct ibv_counters *
mlx5_glue_create_counters(struct ibv_context * context,struct ibv_counters_init_attr * init_attr)353 mlx5_glue_create_counters(struct ibv_context *context,
354 struct ibv_counters_init_attr *init_attr)
355 {
356 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
357 (void)context;
358 (void)init_attr;
359 errno = ENOTSUP;
360 return NULL;
361 #else
362 return ibv_create_counters(context, init_attr);
363 #endif
364 }
365
366 static int
mlx5_glue_destroy_counters(struct ibv_counters * counters)367 mlx5_glue_destroy_counters(struct ibv_counters *counters)
368 {
369 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
370 (void)counters;
371 return -ENOTSUP;
372 #else
373 return ibv_destroy_counters(counters);
374 #endif
375 }
376
377 static int
mlx5_glue_attach_counters(struct ibv_counters * counters,struct ibv_counter_attach_attr * attr,struct ibv_flow * flow)378 mlx5_glue_attach_counters(struct ibv_counters *counters,
379 struct ibv_counter_attach_attr *attr,
380 struct ibv_flow *flow)
381 {
382 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
383 (void)counters;
384 (void)attr;
385 (void)flow;
386 return -ENOTSUP;
387 #else
388 return ibv_attach_counters_point_flow(counters, attr, flow);
389 #endif
390 }
391
392 static int
mlx5_glue_query_counters(struct ibv_counters * counters,uint64_t * counters_value,uint32_t ncounters,uint32_t flags)393 mlx5_glue_query_counters(struct ibv_counters *counters,
394 uint64_t *counters_value,
395 uint32_t ncounters,
396 uint32_t flags)
397 {
398 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
399 (void)counters;
400 (void)counters_value;
401 (void)ncounters;
402 (void)flags;
403 return -ENOTSUP;
404 #else
405 return ibv_read_counters(counters, counters_value, ncounters, flags);
406 #endif
407 }
408
409 static void
mlx5_glue_ack_async_event(struct ibv_async_event * event)410 mlx5_glue_ack_async_event(struct ibv_async_event *event)
411 {
412 ibv_ack_async_event(event);
413 }
414
415 static int
mlx5_glue_get_async_event(struct ibv_context * context,struct ibv_async_event * event)416 mlx5_glue_get_async_event(struct ibv_context *context,
417 struct ibv_async_event *event)
418 {
419 return ibv_get_async_event(context, event);
420 }
421
422 static const char *
mlx5_glue_port_state_str(enum ibv_port_state port_state)423 mlx5_glue_port_state_str(enum ibv_port_state port_state)
424 {
425 return ibv_port_state_str(port_state);
426 }
427
428 static struct ibv_cq *
mlx5_glue_cq_ex_to_cq(struct ibv_cq_ex * cq)429 mlx5_glue_cq_ex_to_cq(struct ibv_cq_ex *cq)
430 {
431 return ibv_cq_ex_to_cq(cq);
432 }
433
434 static void *
mlx5_glue_dr_create_flow_action_dest_flow_tbl(void * tbl)435 mlx5_glue_dr_create_flow_action_dest_flow_tbl(void *tbl)
436 {
437 #ifdef HAVE_MLX5DV_DR
438 return mlx5dv_dr_action_create_dest_table(tbl);
439 #else
440 (void)tbl;
441 errno = ENOTSUP;
442 return NULL;
443 #endif
444 }
445
446 static void *
mlx5_glue_dr_create_flow_action_dest_port(void * domain,uint32_t port)447 mlx5_glue_dr_create_flow_action_dest_port(void *domain, uint32_t port)
448 {
449 #ifdef HAVE_MLX5DV_DR_CREATE_DEST_IB_PORT
450 return mlx5dv_dr_action_create_dest_ib_port(domain, port);
451 #else
452 #ifdef HAVE_MLX5DV_DR_ESWITCH
453 return mlx5dv_dr_action_create_dest_vport(domain, port);
454 #else
455 (void)domain;
456 (void)port;
457 errno = ENOTSUP;
458 return NULL;
459 #endif
460 #endif
461 }
462
463 static void *
mlx5_glue_dr_create_flow_action_drop(void)464 mlx5_glue_dr_create_flow_action_drop(void)
465 {
466 #ifdef HAVE_MLX5DV_DR_ESWITCH
467 return mlx5dv_dr_action_create_drop();
468 #else
469 errno = ENOTSUP;
470 return NULL;
471 #endif
472 }
473
474 static void *
mlx5_glue_dr_create_flow_action_push_vlan(struct mlx5dv_dr_domain * domain,rte_be32_t vlan_tag)475 mlx5_glue_dr_create_flow_action_push_vlan(struct mlx5dv_dr_domain *domain,
476 rte_be32_t vlan_tag)
477 {
478 #ifdef HAVE_MLX5DV_DR_VLAN
479 return mlx5dv_dr_action_create_push_vlan(domain, vlan_tag);
480 #else
481 (void)domain;
482 (void)vlan_tag;
483 errno = ENOTSUP;
484 return NULL;
485 #endif
486 }
487
488 static void *
mlx5_glue_dr_create_flow_action_pop_vlan(void)489 mlx5_glue_dr_create_flow_action_pop_vlan(void)
490 {
491 #ifdef HAVE_MLX5DV_DR_VLAN
492 return mlx5dv_dr_action_create_pop_vlan();
493 #else
494 errno = ENOTSUP;
495 return NULL;
496 #endif
497 }
498
499 static void *
mlx5_glue_dr_create_flow_tbl(void * domain,uint32_t level)500 mlx5_glue_dr_create_flow_tbl(void *domain, uint32_t level)
501 {
502 #ifdef HAVE_MLX5DV_DR
503 return mlx5dv_dr_table_create(domain, level);
504 #else
505 (void)domain;
506 (void)level;
507 errno = ENOTSUP;
508 return NULL;
509 #endif
510 }
511
512 static int
mlx5_glue_dr_destroy_flow_tbl(void * tbl)513 mlx5_glue_dr_destroy_flow_tbl(void *tbl)
514 {
515 #ifdef HAVE_MLX5DV_DR
516 return mlx5dv_dr_table_destroy(tbl);
517 #else
518 (void)tbl;
519 errno = ENOTSUP;
520 return errno;
521 #endif
522 }
523
524 static void *
mlx5_glue_dr_create_domain(struct ibv_context * ctx,enum mlx5dv_dr_domain_type domain)525 mlx5_glue_dr_create_domain(struct ibv_context *ctx,
526 enum mlx5dv_dr_domain_type domain)
527 {
528 #ifdef HAVE_MLX5DV_DR
529 return mlx5dv_dr_domain_create(ctx, domain);
530 #else
531 (void)ctx;
532 (void)domain;
533 errno = ENOTSUP;
534 return NULL;
535 #endif
536 }
537
538 static int
mlx5_glue_dr_destroy_domain(void * domain)539 mlx5_glue_dr_destroy_domain(void *domain)
540 {
541 #ifdef HAVE_MLX5DV_DR
542 return mlx5dv_dr_domain_destroy(domain);
543 #else
544 (void)domain;
545 errno = ENOTSUP;
546 return errno;
547 #endif
548 }
549
550 static int
mlx5_glue_dr_sync_domain(void * domain,uint32_t flags)551 mlx5_glue_dr_sync_domain(void *domain, uint32_t flags)
552 {
553 #ifdef HAVE_MLX5DV_DR
554 return mlx5dv_dr_domain_sync(domain, flags);
555 #else
556 (void)domain;
557 (void)flags;
558 errno = ENOTSUP;
559 return errno;
560 #endif
561 }
562
563 static struct ibv_cq_ex *
mlx5_glue_dv_create_cq(struct ibv_context * context,struct ibv_cq_init_attr_ex * cq_attr,struct mlx5dv_cq_init_attr * mlx5_cq_attr)564 mlx5_glue_dv_create_cq(struct ibv_context *context,
565 struct ibv_cq_init_attr_ex *cq_attr,
566 struct mlx5dv_cq_init_attr *mlx5_cq_attr)
567 {
568 return mlx5dv_create_cq(context, cq_attr, mlx5_cq_attr);
569 }
570
571 static struct ibv_wq *
mlx5_glue_dv_create_wq(struct ibv_context * context,struct ibv_wq_init_attr * wq_attr,struct mlx5dv_wq_init_attr * mlx5_wq_attr)572 mlx5_glue_dv_create_wq(struct ibv_context *context,
573 struct ibv_wq_init_attr *wq_attr,
574 struct mlx5dv_wq_init_attr *mlx5_wq_attr)
575 {
576 #ifndef HAVE_IBV_DEVICE_STRIDING_RQ_SUPPORT
577 (void)context;
578 (void)wq_attr;
579 (void)mlx5_wq_attr;
580 errno = ENOTSUP;
581 return NULL;
582 #else
583 return mlx5dv_create_wq(context, wq_attr, mlx5_wq_attr);
584 #endif
585 }
586
587 static int
mlx5_glue_dv_query_device(struct ibv_context * ctx,struct mlx5dv_context * attrs_out)588 mlx5_glue_dv_query_device(struct ibv_context *ctx,
589 struct mlx5dv_context *attrs_out)
590 {
591 return mlx5dv_query_device(ctx, attrs_out);
592 }
593
594 static int
mlx5_glue_dv_set_context_attr(struct ibv_context * ibv_ctx,enum mlx5dv_set_ctx_attr_type type,void * attr)595 mlx5_glue_dv_set_context_attr(struct ibv_context *ibv_ctx,
596 enum mlx5dv_set_ctx_attr_type type, void *attr)
597 {
598 return mlx5dv_set_context_attr(ibv_ctx, type, attr);
599 }
600
601 static int
mlx5_glue_dv_init_obj(struct mlx5dv_obj * obj,uint64_t obj_type)602 mlx5_glue_dv_init_obj(struct mlx5dv_obj *obj, uint64_t obj_type)
603 {
604 return mlx5dv_init_obj(obj, obj_type);
605 }
606
607 static struct ibv_qp *
mlx5_glue_dv_create_qp(struct ibv_context * context,struct ibv_qp_init_attr_ex * qp_init_attr_ex,struct mlx5dv_qp_init_attr * dv_qp_init_attr)608 mlx5_glue_dv_create_qp(struct ibv_context *context,
609 struct ibv_qp_init_attr_ex *qp_init_attr_ex,
610 struct mlx5dv_qp_init_attr *dv_qp_init_attr)
611 {
612 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
613 return mlx5dv_create_qp(context, qp_init_attr_ex, dv_qp_init_attr);
614 #else
615 (void)context;
616 (void)qp_init_attr_ex;
617 (void)dv_qp_init_attr;
618 errno = ENOTSUP;
619 return NULL;
620 #endif
621 }
622
623 static void *
mlx5_glue_dv_create_flow_matcher(struct ibv_context * context,struct mlx5dv_flow_matcher_attr * matcher_attr,void * tbl)624 mlx5_glue_dv_create_flow_matcher(struct ibv_context *context,
625 struct mlx5dv_flow_matcher_attr *matcher_attr,
626 void *tbl)
627 {
628 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
629 #ifdef HAVE_MLX5DV_DR
630 (void)context;
631 return mlx5dv_dr_matcher_create(tbl, matcher_attr->priority,
632 matcher_attr->match_criteria_enable,
633 matcher_attr->match_mask);
634 #else
635 (void)tbl;
636 return mlx5dv_create_flow_matcher(context, matcher_attr);
637 #endif
638 #else
639 (void)context;
640 (void)matcher_attr;
641 (void)tbl;
642 errno = ENOTSUP;
643 return NULL;
644 #endif
645 }
646
647 static void *
mlx5_glue_dv_create_flow(void * matcher,void * match_value,size_t num_actions,void * actions[])648 mlx5_glue_dv_create_flow(void *matcher,
649 void *match_value,
650 size_t num_actions,
651 void *actions[])
652 {
653 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
654 #ifdef HAVE_MLX5DV_DR
655 return mlx5dv_dr_rule_create(matcher, match_value, num_actions,
656 (struct mlx5dv_dr_action **)actions);
657 #else
658 size_t i;
659 struct mlx5dv_flow_action_attr actions_attr[8];
660
661 if (num_actions > 8)
662 return NULL;
663 for (i = 0; i < num_actions; i++)
664 actions_attr[i] =
665 *((struct mlx5dv_flow_action_attr *)(actions[i]));
666 return mlx5dv_create_flow(matcher, match_value,
667 num_actions, actions_attr);
668 #endif
669 #else
670 (void)matcher;
671 (void)match_value;
672 (void)num_actions;
673 (void)actions;
674 return NULL;
675 #endif
676 }
677
678 static void *
mlx5_glue_dv_create_flow_action_counter(void * counter_obj,uint32_t offset)679 mlx5_glue_dv_create_flow_action_counter(void *counter_obj, uint32_t offset)
680 {
681 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
682 #ifdef HAVE_MLX5DV_DR
683 return mlx5dv_dr_action_create_flow_counter(counter_obj, offset);
684 #else
685 struct mlx5dv_flow_action_attr *action;
686
687 (void)offset;
688 action = malloc(sizeof(*action));
689 if (!action)
690 return NULL;
691 action->type = MLX5DV_FLOW_ACTION_COUNTERS_DEVX;
692 action->obj = counter_obj;
693 return action;
694 #endif
695 #else
696 (void)counter_obj;
697 (void)offset;
698 errno = ENOTSUP;
699 return NULL;
700 #endif
701 }
702
703 static void *
mlx5_glue_dv_create_flow_action_dest_ibv_qp(void * qp)704 mlx5_glue_dv_create_flow_action_dest_ibv_qp(void *qp)
705 {
706 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
707 #ifdef HAVE_MLX5DV_DR
708 return mlx5dv_dr_action_create_dest_ibv_qp(qp);
709 #else
710 struct mlx5dv_flow_action_attr *action;
711
712 action = malloc(sizeof(*action));
713 if (!action)
714 return NULL;
715 action->type = MLX5DV_FLOW_ACTION_DEST_IBV_QP;
716 action->obj = qp;
717 return action;
718 #endif
719 #else
720 (void)qp;
721 errno = ENOTSUP;
722 return NULL;
723 #endif
724 }
725
726 static void *
mlx5_glue_dv_create_flow_action_dest_devx_tir(void * tir)727 mlx5_glue_dv_create_flow_action_dest_devx_tir(void *tir)
728 {
729 #ifdef HAVE_MLX5DV_DR_ACTION_DEST_DEVX_TIR
730 return mlx5dv_dr_action_create_dest_devx_tir(tir);
731 #else
732 (void)tir;
733 errno = ENOTSUP;
734 return NULL;
735 #endif
736 }
737
738 static void *
mlx5_glue_dv_create_flow_action_modify_header(struct ibv_context * ctx,enum mlx5dv_flow_table_type ft_type,void * domain,uint64_t flags,size_t actions_sz,uint64_t actions[])739 mlx5_glue_dv_create_flow_action_modify_header
740 (struct ibv_context *ctx,
741 enum mlx5dv_flow_table_type ft_type,
742 void *domain, uint64_t flags,
743 size_t actions_sz,
744 uint64_t actions[])
745 {
746 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
747 #ifdef HAVE_MLX5DV_DR
748 (void)ctx;
749 (void)ft_type;
750 return mlx5dv_dr_action_create_modify_header(domain, flags, actions_sz,
751 (__be64 *)actions);
752 #else
753 struct mlx5dv_flow_action_attr *action;
754
755 (void)domain;
756 (void)flags;
757 action = malloc(sizeof(*action));
758 if (!action)
759 return NULL;
760 action->type = MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION;
761 action->action = mlx5dv_create_flow_action_modify_header
762 (ctx, actions_sz, actions, ft_type);
763 return action;
764 #endif
765 #else
766 (void)ctx;
767 (void)ft_type;
768 (void)domain;
769 (void)flags;
770 (void)actions_sz;
771 (void)actions;
772 errno = ENOTSUP;
773 return NULL;
774 #endif
775 }
776
777 static void *
mlx5_glue_dv_create_flow_action_packet_reformat(struct ibv_context * ctx,enum mlx5dv_flow_action_packet_reformat_type reformat_type,enum mlx5dv_flow_table_type ft_type,struct mlx5dv_dr_domain * domain,uint32_t flags,size_t data_sz,void * data)778 mlx5_glue_dv_create_flow_action_packet_reformat
779 (struct ibv_context *ctx,
780 enum mlx5dv_flow_action_packet_reformat_type reformat_type,
781 enum mlx5dv_flow_table_type ft_type,
782 struct mlx5dv_dr_domain *domain,
783 uint32_t flags, size_t data_sz, void *data)
784 {
785 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
786 #ifdef HAVE_MLX5DV_DR
787 (void)ctx;
788 (void)ft_type;
789 return mlx5dv_dr_action_create_packet_reformat(domain, flags,
790 reformat_type, data_sz,
791 data);
792 #else
793 (void)domain;
794 (void)flags;
795 struct mlx5dv_flow_action_attr *action;
796
797 action = malloc(sizeof(*action));
798 if (!action)
799 return NULL;
800 action->type = MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION;
801 action->action = mlx5dv_create_flow_action_packet_reformat
802 (ctx, data_sz, data, reformat_type, ft_type);
803 return action;
804 #endif
805 #else
806 (void)ctx;
807 (void)reformat_type;
808 (void)ft_type;
809 (void)domain;
810 (void)flags;
811 (void)data_sz;
812 (void)data;
813 errno = ENOTSUP;
814 return NULL;
815 #endif
816 }
817
818 static void *
mlx5_glue_dv_create_flow_action_tag(uint32_t tag)819 mlx5_glue_dv_create_flow_action_tag(uint32_t tag)
820 {
821 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
822 #ifdef HAVE_MLX5DV_DR
823 return mlx5dv_dr_action_create_tag(tag);
824 #else /* HAVE_MLX5DV_DR */
825 struct mlx5dv_flow_action_attr *action;
826
827 action = malloc(sizeof(*action));
828 if (!action)
829 return NULL;
830 action->type = MLX5DV_FLOW_ACTION_TAG;
831 action->tag_value = tag;
832 return action;
833 #endif /* HAVE_MLX5DV_DR */
834 #else /* HAVE_IBV_FLOW_DV_SUPPORT */
835 (void)tag;
836 errno = ENOTSUP;
837 return NULL;
838 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
839 }
840
841 static void *
mlx5_glue_dv_create_flow_action_meter(struct mlx5dv_dr_flow_meter_attr * attr)842 mlx5_glue_dv_create_flow_action_meter(struct mlx5dv_dr_flow_meter_attr *attr)
843 {
844 #if defined(HAVE_MLX5DV_DR) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_METER)
845 return mlx5dv_dr_action_create_flow_meter(attr);
846 #else
847 (void)attr;
848 errno = ENOTSUP;
849 return NULL;
850 #endif
851 }
852
853 static int
mlx5_glue_dv_modify_flow_action_meter(void * action,struct mlx5dv_dr_flow_meter_attr * attr,uint64_t modify_bits)854 mlx5_glue_dv_modify_flow_action_meter(void *action,
855 struct mlx5dv_dr_flow_meter_attr *attr,
856 uint64_t modify_bits)
857 {
858 #if defined(HAVE_MLX5DV_DR) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_METER)
859 return mlx5dv_dr_action_modify_flow_meter(action, attr, modify_bits);
860 #else
861 (void)action;
862 (void)attr;
863 (void)modify_bits;
864 errno = ENOTSUP;
865 return errno;
866 #endif
867 }
868
869 static void *
mlx5_glue_dv_create_flow_action_aso(struct mlx5dv_dr_domain * domain,void * aso_obj,uint32_t offset,uint32_t flags,uint8_t return_reg_c)870 mlx5_glue_dv_create_flow_action_aso(struct mlx5dv_dr_domain *domain,
871 void *aso_obj,
872 uint32_t offset,
873 uint32_t flags,
874 uint8_t return_reg_c)
875 {
876 #if defined(HAVE_MLX5DV_DR) && defined(HAVE_MLX5_DR_CREATE_ACTION_ASO)
877 return mlx5dv_dr_action_create_aso(domain, aso_obj, offset,
878 flags, return_reg_c);
879 #else
880 (void)domain;
881 (void)aso_obj;
882 (void)offset;
883 (void)flags;
884 (void)return_reg_c;
885 errno = ENOTSUP;
886 return NULL;
887 #endif
888 }
889
890 static void *
mlx5_glue_dr_create_flow_action_default_miss(void)891 mlx5_glue_dr_create_flow_action_default_miss(void)
892 {
893 #if defined(HAVE_MLX5DV_DR) && defined(HAVE_MLX5_DR_CREATE_ACTION_DEFAULT_MISS)
894 return mlx5dv_dr_action_create_default_miss();
895 #else
896 errno = ENOTSUP;
897 return NULL;
898 #endif
899 }
900
901 static int
mlx5_glue_dv_destroy_flow(void * flow_id)902 mlx5_glue_dv_destroy_flow(void *flow_id)
903 {
904 #ifdef HAVE_MLX5DV_DR
905 return mlx5dv_dr_rule_destroy(flow_id);
906 #else
907 return ibv_destroy_flow(flow_id);
908 #endif
909 }
910
911 static int
mlx5_glue_dv_destroy_flow_matcher(void * matcher)912 mlx5_glue_dv_destroy_flow_matcher(void *matcher)
913 {
914 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
915 #ifdef HAVE_MLX5DV_DR
916 return mlx5dv_dr_matcher_destroy(matcher);
917 #else
918 return mlx5dv_destroy_flow_matcher(matcher);
919 #endif
920 #else
921 (void)matcher;
922 errno = ENOTSUP;
923 return errno;
924 #endif
925 }
926
927 static struct ibv_context *
mlx5_glue_dv_open_device(struct ibv_device * device)928 mlx5_glue_dv_open_device(struct ibv_device *device)
929 {
930 #ifdef HAVE_IBV_DEVX_OBJ
931 return mlx5dv_open_device(device,
932 &(struct mlx5dv_context_attr){
933 .flags = MLX5DV_CONTEXT_FLAGS_DEVX,
934 });
935 #else
936 (void)device;
937 errno = ENOTSUP;
938 return NULL;
939 #endif
940 }
941
942 static struct mlx5dv_devx_obj *
mlx5_glue_devx_obj_create(struct ibv_context * ctx,const void * in,size_t inlen,void * out,size_t outlen)943 mlx5_glue_devx_obj_create(struct ibv_context *ctx,
944 const void *in, size_t inlen,
945 void *out, size_t outlen)
946 {
947 #ifdef HAVE_IBV_DEVX_OBJ
948 return mlx5dv_devx_obj_create(ctx, in, inlen, out, outlen);
949 #else
950 (void)ctx;
951 (void)in;
952 (void)inlen;
953 (void)out;
954 (void)outlen;
955 errno = ENOTSUP;
956 return NULL;
957 #endif
958 }
959
960 static int
mlx5_glue_devx_obj_destroy(struct mlx5dv_devx_obj * obj)961 mlx5_glue_devx_obj_destroy(struct mlx5dv_devx_obj *obj)
962 {
963 #ifdef HAVE_IBV_DEVX_OBJ
964 return mlx5dv_devx_obj_destroy(obj);
965 #else
966 (void)obj;
967 return -ENOTSUP;
968 #endif
969 }
970
971 static int
mlx5_glue_devx_obj_query(struct mlx5dv_devx_obj * obj,const void * in,size_t inlen,void * out,size_t outlen)972 mlx5_glue_devx_obj_query(struct mlx5dv_devx_obj *obj,
973 const void *in, size_t inlen,
974 void *out, size_t outlen)
975 {
976 #ifdef HAVE_IBV_DEVX_OBJ
977 return mlx5dv_devx_obj_query(obj, in, inlen, out, outlen);
978 #else
979 (void)obj;
980 (void)in;
981 (void)inlen;
982 (void)out;
983 (void)outlen;
984 return -ENOTSUP;
985 #endif
986 }
987
988 static int
mlx5_glue_devx_obj_modify(struct mlx5dv_devx_obj * obj,const void * in,size_t inlen,void * out,size_t outlen)989 mlx5_glue_devx_obj_modify(struct mlx5dv_devx_obj *obj,
990 const void *in, size_t inlen,
991 void *out, size_t outlen)
992 {
993 #ifdef HAVE_IBV_DEVX_OBJ
994 return mlx5dv_devx_obj_modify(obj, in, inlen, out, outlen);
995 #else
996 (void)obj;
997 (void)in;
998 (void)inlen;
999 (void)out;
1000 (void)outlen;
1001 return -ENOTSUP;
1002 #endif
1003 }
1004
1005 static int
mlx5_glue_devx_general_cmd(struct ibv_context * ctx,const void * in,size_t inlen,void * out,size_t outlen)1006 mlx5_glue_devx_general_cmd(struct ibv_context *ctx,
1007 const void *in, size_t inlen,
1008 void *out, size_t outlen)
1009 {
1010 #ifdef HAVE_IBV_DEVX_OBJ
1011 return mlx5dv_devx_general_cmd(ctx, in, inlen, out, outlen);
1012 #else
1013 (void)ctx;
1014 (void)in;
1015 (void)inlen;
1016 (void)out;
1017 (void)outlen;
1018 return -ENOTSUP;
1019 #endif
1020 }
1021
1022 static struct mlx5dv_devx_cmd_comp *
mlx5_glue_devx_create_cmd_comp(struct ibv_context * ctx)1023 mlx5_glue_devx_create_cmd_comp(struct ibv_context *ctx)
1024 {
1025 #ifdef HAVE_IBV_DEVX_ASYNC
1026 return mlx5dv_devx_create_cmd_comp(ctx);
1027 #else
1028 (void)ctx;
1029 errno = -ENOTSUP;
1030 return NULL;
1031 #endif
1032 }
1033
1034 static void
mlx5_glue_devx_destroy_cmd_comp(struct mlx5dv_devx_cmd_comp * cmd_comp)1035 mlx5_glue_devx_destroy_cmd_comp(struct mlx5dv_devx_cmd_comp *cmd_comp)
1036 {
1037 #ifdef HAVE_IBV_DEVX_ASYNC
1038 mlx5dv_devx_destroy_cmd_comp(cmd_comp);
1039 #else
1040 (void)cmd_comp;
1041 errno = -ENOTSUP;
1042 #endif
1043 }
1044
1045 static int
mlx5_glue_devx_obj_query_async(struct mlx5dv_devx_obj * obj,const void * in,size_t inlen,size_t outlen,uint64_t wr_id,struct mlx5dv_devx_cmd_comp * cmd_comp)1046 mlx5_glue_devx_obj_query_async(struct mlx5dv_devx_obj *obj, const void *in,
1047 size_t inlen, size_t outlen, uint64_t wr_id,
1048 struct mlx5dv_devx_cmd_comp *cmd_comp)
1049 {
1050 #ifdef HAVE_IBV_DEVX_ASYNC
1051 return mlx5dv_devx_obj_query_async(obj, in, inlen, outlen, wr_id,
1052 cmd_comp);
1053 #else
1054 (void)obj;
1055 (void)in;
1056 (void)inlen;
1057 (void)outlen;
1058 (void)wr_id;
1059 (void)cmd_comp;
1060 return -ENOTSUP;
1061 #endif
1062 }
1063
1064 static int
mlx5_glue_devx_get_async_cmd_comp(struct mlx5dv_devx_cmd_comp * cmd_comp,struct mlx5dv_devx_async_cmd_hdr * cmd_resp,size_t cmd_resp_len)1065 mlx5_glue_devx_get_async_cmd_comp(struct mlx5dv_devx_cmd_comp *cmd_comp,
1066 struct mlx5dv_devx_async_cmd_hdr *cmd_resp,
1067 size_t cmd_resp_len)
1068 {
1069 #ifdef HAVE_IBV_DEVX_ASYNC
1070 return mlx5dv_devx_get_async_cmd_comp(cmd_comp, cmd_resp,
1071 cmd_resp_len);
1072 #else
1073 (void)cmd_comp;
1074 (void)cmd_resp;
1075 (void)cmd_resp_len;
1076 return -ENOTSUP;
1077 #endif
1078 }
1079
1080 static struct mlx5dv_devx_umem *
mlx5_glue_devx_umem_reg(struct ibv_context * context,void * addr,size_t size,uint32_t access)1081 mlx5_glue_devx_umem_reg(struct ibv_context *context, void *addr, size_t size,
1082 uint32_t access)
1083 {
1084 #ifdef HAVE_IBV_DEVX_OBJ
1085 return mlx5dv_devx_umem_reg(context, addr, size, access);
1086 #else
1087 (void)context;
1088 (void)addr;
1089 (void)size;
1090 (void)access;
1091 errno = -ENOTSUP;
1092 return NULL;
1093 #endif
1094 }
1095
1096 static int
mlx5_glue_devx_umem_dereg(struct mlx5dv_devx_umem * dv_devx_umem)1097 mlx5_glue_devx_umem_dereg(struct mlx5dv_devx_umem *dv_devx_umem)
1098 {
1099 #ifdef HAVE_IBV_DEVX_OBJ
1100 return mlx5dv_devx_umem_dereg(dv_devx_umem);
1101 #else
1102 (void)dv_devx_umem;
1103 return -ENOTSUP;
1104 #endif
1105 }
1106
1107 static int
mlx5_glue_devx_qp_query(struct ibv_qp * qp,const void * in,size_t inlen,void * out,size_t outlen)1108 mlx5_glue_devx_qp_query(struct ibv_qp *qp,
1109 const void *in, size_t inlen,
1110 void *out, size_t outlen)
1111 {
1112 #ifdef HAVE_IBV_DEVX_QP
1113 return mlx5dv_devx_qp_query(qp, in, inlen, out, outlen);
1114 #else
1115 (void)qp;
1116 (void)in;
1117 (void)inlen;
1118 (void)out;
1119 (void)outlen;
1120 errno = ENOTSUP;
1121 return errno;
1122 #endif
1123 }
1124
1125 static int
mlx5_glue_devx_wq_query(struct ibv_wq * wq,const void * in,size_t inlen,void * out,size_t outlen)1126 mlx5_glue_devx_wq_query(struct ibv_wq *wq, const void *in, size_t inlen,
1127 void *out, size_t outlen)
1128 {
1129 #ifdef HAVE_IBV_DEVX_QP
1130 return mlx5dv_devx_wq_query(wq, in, inlen, out, outlen);
1131 #else
1132 (void)wq;
1133 (void)in;
1134 (void)inlen;
1135 (void)out;
1136 (void)outlen;
1137 errno = ENOTSUP;
1138 return errno;
1139 #endif
1140 }
1141
1142 static int
mlx5_glue_devx_port_query(struct ibv_context * ctx,uint32_t port_num,struct mlx5_port_info * info)1143 mlx5_glue_devx_port_query(struct ibv_context *ctx,
1144 uint32_t port_num,
1145 struct mlx5_port_info *info)
1146 {
1147 int err = 0;
1148
1149 info->query_flags = 0;
1150 #ifdef HAVE_MLX5DV_DR_DEVX_PORT_V35
1151 /* The DevX port query API is implemented (rdma-core v35 and above). */
1152 struct mlx5_ib_uapi_query_port devx_port;
1153
1154 memset(&devx_port, 0, sizeof(devx_port));
1155 err = mlx5dv_query_port(ctx, port_num, &devx_port);
1156 if (err)
1157 return err;
1158 if (devx_port.flags & MLX5DV_QUERY_PORT_VPORT_REG_C0) {
1159 info->vport_meta_tag = devx_port.reg_c0.value;
1160 info->vport_meta_mask = devx_port.reg_c0.mask;
1161 info->query_flags |= MLX5_PORT_QUERY_REG_C0;
1162 }
1163 if (devx_port.flags & MLX5DV_QUERY_PORT_VPORT) {
1164 info->vport_id = devx_port.vport;
1165 info->query_flags |= MLX5_PORT_QUERY_VPORT;
1166 }
1167 #else
1168 #ifdef HAVE_MLX5DV_DR_DEVX_PORT
1169 /* The legacy DevX port query API is implemented (prior v35). */
1170 struct mlx5dv_devx_port devx_port = {
1171 .comp_mask = MLX5DV_DEVX_PORT_VPORT |
1172 MLX5DV_DEVX_PORT_MATCH_REG_C_0
1173 };
1174
1175 err = mlx5dv_query_devx_port(ctx, port_num, &devx_port);
1176 if (err)
1177 return err;
1178 if (devx_port.comp_mask & MLX5DV_DEVX_PORT_MATCH_REG_C_0) {
1179 info->vport_meta_tag = devx_port.reg_c_0.value;
1180 info->vport_meta_mask = devx_port.reg_c_0.mask;
1181 info->query_flags |= MLX5_PORT_QUERY_REG_C0;
1182 }
1183 if (devx_port.comp_mask & MLX5DV_DEVX_PORT_VPORT) {
1184 info->vport_id = devx_port.vport_num;
1185 info->query_flags |= MLX5_PORT_QUERY_VPORT;
1186 }
1187 #else
1188 RTE_SET_USED(ctx);
1189 RTE_SET_USED(port_num);
1190 #endif /* HAVE_MLX5DV_DR_DEVX_PORT */
1191 #endif /* HAVE_MLX5DV_DR_DEVX_PORT_V35 */
1192 return err;
1193 }
1194
1195 static int
mlx5_glue_dr_dump_single_rule(FILE * file,void * rule)1196 mlx5_glue_dr_dump_single_rule(FILE *file, void *rule)
1197 {
1198 #ifdef HAVE_MLX5_DR_FLOW_DUMP_RULE
1199 return mlx5dv_dump_dr_rule(file, rule);
1200 #else
1201 RTE_SET_USED(file);
1202 RTE_SET_USED(rule);
1203 return -ENOTSUP;
1204 #endif
1205 }
1206
1207 static int
mlx5_glue_dr_dump_domain(FILE * file,void * domain)1208 mlx5_glue_dr_dump_domain(FILE *file, void *domain)
1209 {
1210 #ifdef HAVE_MLX5_DR_FLOW_DUMP
1211 return mlx5dv_dump_dr_domain(file, domain);
1212 #else
1213 RTE_SET_USED(file);
1214 RTE_SET_USED(domain);
1215 return -ENOTSUP;
1216 #endif
1217 }
1218
1219 static void *
mlx5_glue_dr_create_flow_action_sampler(struct mlx5dv_dr_flow_sampler_attr * attr)1220 mlx5_glue_dr_create_flow_action_sampler
1221 (struct mlx5dv_dr_flow_sampler_attr *attr)
1222 {
1223 #ifdef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE
1224 return mlx5dv_dr_action_create_flow_sampler(attr);
1225 #else
1226 (void)attr;
1227 errno = ENOTSUP;
1228 return NULL;
1229 #endif
1230 }
1231
1232 static void *
mlx5_glue_dr_action_create_dest_array(void * domain,size_t num_dest,struct mlx5dv_dr_action_dest_attr * dests[])1233 mlx5_glue_dr_action_create_dest_array
1234 (void *domain,
1235 size_t num_dest,
1236 struct mlx5dv_dr_action_dest_attr *dests[])
1237 {
1238 #ifdef HAVE_MLX5_DR_CREATE_ACTION_DEST_ARRAY
1239 return mlx5dv_dr_action_create_dest_array
1240 (domain,
1241 num_dest,
1242 dests);
1243 #else
1244 (void)domain;
1245 (void)num_dest;
1246 (void)dests;
1247 errno = ENOTSUP;
1248 return NULL;
1249 #endif
1250 }
1251
1252 static int
mlx5_glue_devx_query_eqn(struct ibv_context * ctx,uint32_t cpus,uint32_t * eqn)1253 mlx5_glue_devx_query_eqn(struct ibv_context *ctx, uint32_t cpus,
1254 uint32_t *eqn)
1255 {
1256 #ifdef HAVE_IBV_DEVX_OBJ
1257 return mlx5dv_devx_query_eqn(ctx, cpus, eqn);
1258 #else
1259 (void)ctx;
1260 (void)cpus;
1261 (void)eqn;
1262 return -ENOTSUP;
1263 #endif
1264 }
1265
1266 static struct mlx5dv_devx_event_channel *
mlx5_glue_devx_create_event_channel(struct ibv_context * ctx,int flags)1267 mlx5_glue_devx_create_event_channel(struct ibv_context *ctx, int flags)
1268 {
1269 #ifdef HAVE_IBV_DEVX_EVENT
1270 return mlx5dv_devx_create_event_channel(ctx, flags);
1271 #else
1272 (void)ctx;
1273 (void)flags;
1274 errno = ENOTSUP;
1275 return NULL;
1276 #endif
1277 }
1278
1279 static void
mlx5_glue_devx_destroy_event_channel(struct mlx5dv_devx_event_channel * eventc)1280 mlx5_glue_devx_destroy_event_channel(struct mlx5dv_devx_event_channel *eventc)
1281 {
1282 #ifdef HAVE_IBV_DEVX_EVENT
1283 mlx5dv_devx_destroy_event_channel(eventc);
1284 #else
1285 (void)eventc;
1286 #endif
1287 }
1288
1289 static int
mlx5_glue_devx_subscribe_devx_event(struct mlx5dv_devx_event_channel * eventc,struct mlx5dv_devx_obj * obj,uint16_t events_sz,uint16_t events_num[],uint64_t cookie)1290 mlx5_glue_devx_subscribe_devx_event(struct mlx5dv_devx_event_channel *eventc,
1291 struct mlx5dv_devx_obj *obj,
1292 uint16_t events_sz, uint16_t events_num[],
1293 uint64_t cookie)
1294 {
1295 #ifdef HAVE_IBV_DEVX_EVENT
1296 return mlx5dv_devx_subscribe_devx_event(eventc, obj, events_sz,
1297 events_num, cookie);
1298 #else
1299 (void)eventc;
1300 (void)obj;
1301 (void)events_sz;
1302 (void)events_num;
1303 (void)cookie;
1304 return -ENOTSUP;
1305 #endif
1306 }
1307
1308 static int
mlx5_glue_devx_subscribe_devx_event_fd(struct mlx5dv_devx_event_channel * eventc,int fd,struct mlx5dv_devx_obj * obj,uint16_t event_num)1309 mlx5_glue_devx_subscribe_devx_event_fd(struct mlx5dv_devx_event_channel *eventc,
1310 int fd, struct mlx5dv_devx_obj *obj,
1311 uint16_t event_num)
1312 {
1313 #ifdef HAVE_IBV_DEVX_EVENT
1314 return mlx5dv_devx_subscribe_devx_event_fd(eventc, fd, obj, event_num);
1315 #else
1316 (void)eventc;
1317 (void)fd;
1318 (void)obj;
1319 (void)event_num;
1320 return -ENOTSUP;
1321 #endif
1322 }
1323
1324 static ssize_t
mlx5_glue_devx_get_event(struct mlx5dv_devx_event_channel * eventc,struct mlx5dv_devx_async_event_hdr * event_data,size_t event_resp_len)1325 mlx5_glue_devx_get_event(struct mlx5dv_devx_event_channel *eventc,
1326 struct mlx5dv_devx_async_event_hdr *event_data,
1327 size_t event_resp_len)
1328 {
1329 #ifdef HAVE_IBV_DEVX_EVENT
1330 return mlx5dv_devx_get_event(eventc, event_data, event_resp_len);
1331 #else
1332 (void)eventc;
1333 (void)event_data;
1334 (void)event_resp_len;
1335 errno = ENOTSUP;
1336 return -1;
1337 #endif
1338 }
1339
1340 static struct mlx5dv_devx_uar *
mlx5_glue_devx_alloc_uar(struct ibv_context * context,uint32_t flags)1341 mlx5_glue_devx_alloc_uar(struct ibv_context *context, uint32_t flags)
1342 {
1343 #ifdef HAVE_IBV_DEVX_OBJ
1344 return mlx5dv_devx_alloc_uar(context, flags);
1345 #else
1346 (void)context;
1347 (void)flags;
1348 errno = ENOTSUP;
1349 return NULL;
1350 #endif
1351 }
1352
1353 static void
mlx5_glue_devx_free_uar(struct mlx5dv_devx_uar * devx_uar)1354 mlx5_glue_devx_free_uar(struct mlx5dv_devx_uar *devx_uar)
1355 {
1356 #ifdef HAVE_IBV_DEVX_OBJ
1357 mlx5dv_devx_free_uar(devx_uar);
1358 #else
1359 (void)devx_uar;
1360 #endif
1361 }
1362
1363 static struct mlx5dv_var *
mlx5_glue_dv_alloc_var(struct ibv_context * context,uint32_t flags)1364 mlx5_glue_dv_alloc_var(struct ibv_context *context, uint32_t flags)
1365 {
1366 #ifdef HAVE_IBV_VAR
1367 return mlx5dv_alloc_var(context, flags);
1368 #else
1369 (void)context;
1370 (void)flags;
1371 errno = ENOTSUP;
1372 return NULL;
1373 #endif
1374 }
1375
1376 static void
mlx5_glue_dv_free_var(struct mlx5dv_var * var)1377 mlx5_glue_dv_free_var(struct mlx5dv_var *var)
1378 {
1379 #ifdef HAVE_IBV_VAR
1380 mlx5dv_free_var(var);
1381 #else
1382 (void)var;
1383 errno = ENOTSUP;
1384 #endif
1385 }
1386
1387 static void
mlx5_glue_dr_reclaim_domain_memory(void * domain,uint32_t enable)1388 mlx5_glue_dr_reclaim_domain_memory(void *domain, uint32_t enable)
1389 {
1390 #ifdef HAVE_MLX5DV_DR_MEM_RECLAIM
1391 mlx5dv_dr_domain_set_reclaim_device_memory(domain, enable);
1392 #else
1393 (void)(enable);
1394 (void)(domain);
1395 #endif
1396 }
1397
1398 static struct mlx5dv_pp *
mlx5_glue_dv_alloc_pp(struct ibv_context * context,size_t pp_context_sz,const void * pp_context,uint32_t flags)1399 mlx5_glue_dv_alloc_pp(struct ibv_context *context,
1400 size_t pp_context_sz,
1401 const void *pp_context,
1402 uint32_t flags)
1403 {
1404 #ifdef HAVE_MLX5DV_PP_ALLOC
1405 return mlx5dv_pp_alloc(context, pp_context_sz, pp_context, flags);
1406 #else
1407 RTE_SET_USED(context);
1408 RTE_SET_USED(pp_context_sz);
1409 RTE_SET_USED(pp_context);
1410 RTE_SET_USED(flags);
1411 errno = ENOTSUP;
1412 return NULL;
1413 #endif
1414 }
1415
1416 static void
mlx5_glue_dr_allow_duplicate_rules(void * domain,uint32_t allow)1417 mlx5_glue_dr_allow_duplicate_rules(void *domain, uint32_t allow)
1418 {
1419 #ifdef HAVE_MLX5_DR_ALLOW_DUPLICATE
1420 mlx5dv_dr_domain_allow_duplicate_rules(domain, allow);
1421 #else
1422 (void)(allow);
1423 (void)(domain);
1424 #endif
1425 }
1426
1427 static void
mlx5_glue_dv_free_pp(struct mlx5dv_pp * pp)1428 mlx5_glue_dv_free_pp(struct mlx5dv_pp *pp)
1429 {
1430 #ifdef HAVE_MLX5DV_PP_ALLOC
1431 mlx5dv_pp_free(pp);
1432 #else
1433 RTE_SET_USED(pp);
1434 #endif
1435 }
1436
1437 __rte_cache_aligned
1438 const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue) {
1439 .version = MLX5_GLUE_VERSION,
1440 .fork_init = mlx5_glue_fork_init,
1441 .alloc_pd = mlx5_glue_alloc_pd,
1442 .dealloc_pd = mlx5_glue_dealloc_pd,
1443 .import_pd = mlx5_glue_import_pd,
1444 .unimport_pd = mlx5_glue_unimport_pd,
1445 .get_device_list = mlx5_glue_get_device_list,
1446 .free_device_list = mlx5_glue_free_device_list,
1447 .open_device = mlx5_glue_open_device,
1448 .import_device = mlx5_glue_import_device,
1449 .close_device = mlx5_glue_close_device,
1450 .query_device = mlx5_glue_query_device,
1451 .query_device_ex = mlx5_glue_query_device_ex,
1452 .query_rt_values_ex = mlx5_glue_query_rt_values_ex,
1453 .query_port = mlx5_glue_query_port,
1454 .create_comp_channel = mlx5_glue_create_comp_channel,
1455 .destroy_comp_channel = mlx5_glue_destroy_comp_channel,
1456 .create_cq = mlx5_glue_create_cq,
1457 .destroy_cq = mlx5_glue_destroy_cq,
1458 .get_cq_event = mlx5_glue_get_cq_event,
1459 .ack_cq_events = mlx5_glue_ack_cq_events,
1460 .create_rwq_ind_table = mlx5_glue_create_rwq_ind_table,
1461 .destroy_rwq_ind_table = mlx5_glue_destroy_rwq_ind_table,
1462 .create_wq = mlx5_glue_create_wq,
1463 .destroy_wq = mlx5_glue_destroy_wq,
1464 .modify_wq = mlx5_glue_modify_wq,
1465 .create_flow = mlx5_glue_create_flow,
1466 .destroy_flow = mlx5_glue_destroy_flow,
1467 .destroy_flow_action = mlx5_glue_destroy_flow_action,
1468 .create_qp = mlx5_glue_create_qp,
1469 .create_qp_ex = mlx5_glue_create_qp_ex,
1470 .destroy_qp = mlx5_glue_destroy_qp,
1471 .modify_qp = mlx5_glue_modify_qp,
1472 .reg_mr = mlx5_glue_reg_mr,
1473 .reg_mr_iova = mlx5_glue_reg_mr_iova,
1474 .alloc_null_mr = mlx5_glue_alloc_null_mr,
1475 .dereg_mr = mlx5_glue_dereg_mr,
1476 .create_counter_set = mlx5_glue_create_counter_set,
1477 .destroy_counter_set = mlx5_glue_destroy_counter_set,
1478 .describe_counter_set = mlx5_glue_describe_counter_set,
1479 .query_counter_set = mlx5_glue_query_counter_set,
1480 .create_counters = mlx5_glue_create_counters,
1481 .destroy_counters = mlx5_glue_destroy_counters,
1482 .attach_counters = mlx5_glue_attach_counters,
1483 .query_counters = mlx5_glue_query_counters,
1484 .ack_async_event = mlx5_glue_ack_async_event,
1485 .get_async_event = mlx5_glue_get_async_event,
1486 .port_state_str = mlx5_glue_port_state_str,
1487 .cq_ex_to_cq = mlx5_glue_cq_ex_to_cq,
1488 .dr_create_flow_action_dest_flow_tbl =
1489 mlx5_glue_dr_create_flow_action_dest_flow_tbl,
1490 .dr_create_flow_action_dest_port =
1491 mlx5_glue_dr_create_flow_action_dest_port,
1492 .dr_create_flow_action_drop =
1493 mlx5_glue_dr_create_flow_action_drop,
1494 .dr_create_flow_action_push_vlan =
1495 mlx5_glue_dr_create_flow_action_push_vlan,
1496 .dr_create_flow_action_pop_vlan =
1497 mlx5_glue_dr_create_flow_action_pop_vlan,
1498 .dr_create_flow_tbl = mlx5_glue_dr_create_flow_tbl,
1499 .dr_destroy_flow_tbl = mlx5_glue_dr_destroy_flow_tbl,
1500 .dr_create_domain = mlx5_glue_dr_create_domain,
1501 .dr_destroy_domain = mlx5_glue_dr_destroy_domain,
1502 .dr_sync_domain = mlx5_glue_dr_sync_domain,
1503 .dv_create_cq = mlx5_glue_dv_create_cq,
1504 .dv_create_wq = mlx5_glue_dv_create_wq,
1505 .dv_query_device = mlx5_glue_dv_query_device,
1506 .dv_set_context_attr = mlx5_glue_dv_set_context_attr,
1507 .dv_init_obj = mlx5_glue_dv_init_obj,
1508 .dv_create_qp = mlx5_glue_dv_create_qp,
1509 .dv_create_flow_matcher = mlx5_glue_dv_create_flow_matcher,
1510 .dv_create_flow = mlx5_glue_dv_create_flow,
1511 .dv_create_flow_action_counter =
1512 mlx5_glue_dv_create_flow_action_counter,
1513 .dv_create_flow_action_dest_ibv_qp =
1514 mlx5_glue_dv_create_flow_action_dest_ibv_qp,
1515 .dv_create_flow_action_dest_devx_tir =
1516 mlx5_glue_dv_create_flow_action_dest_devx_tir,
1517 .dv_create_flow_action_modify_header =
1518 mlx5_glue_dv_create_flow_action_modify_header,
1519 .dv_create_flow_action_packet_reformat =
1520 mlx5_glue_dv_create_flow_action_packet_reformat,
1521 .dv_create_flow_action_tag = mlx5_glue_dv_create_flow_action_tag,
1522 .dv_create_flow_action_meter = mlx5_glue_dv_create_flow_action_meter,
1523 .dv_modify_flow_action_meter = mlx5_glue_dv_modify_flow_action_meter,
1524 .dv_create_flow_action_aso = mlx5_glue_dv_create_flow_action_aso,
1525 .dr_create_flow_action_default_miss =
1526 mlx5_glue_dr_create_flow_action_default_miss,
1527 .dv_destroy_flow = mlx5_glue_dv_destroy_flow,
1528 .dv_destroy_flow_matcher = mlx5_glue_dv_destroy_flow_matcher,
1529 .dv_open_device = mlx5_glue_dv_open_device,
1530 .devx_obj_create = mlx5_glue_devx_obj_create,
1531 .devx_obj_destroy = mlx5_glue_devx_obj_destroy,
1532 .devx_obj_query = mlx5_glue_devx_obj_query,
1533 .devx_obj_modify = mlx5_glue_devx_obj_modify,
1534 .devx_general_cmd = mlx5_glue_devx_general_cmd,
1535 .devx_create_cmd_comp = mlx5_glue_devx_create_cmd_comp,
1536 .devx_destroy_cmd_comp = mlx5_glue_devx_destroy_cmd_comp,
1537 .devx_obj_query_async = mlx5_glue_devx_obj_query_async,
1538 .devx_get_async_cmd_comp = mlx5_glue_devx_get_async_cmd_comp,
1539 .devx_umem_reg = mlx5_glue_devx_umem_reg,
1540 .devx_umem_dereg = mlx5_glue_devx_umem_dereg,
1541 .devx_qp_query = mlx5_glue_devx_qp_query,
1542 .devx_wq_query = mlx5_glue_devx_wq_query,
1543 .devx_port_query = mlx5_glue_devx_port_query,
1544 .dr_dump_domain = mlx5_glue_dr_dump_domain,
1545 .dr_dump_rule = mlx5_glue_dr_dump_single_rule,
1546 .dr_reclaim_domain_memory = mlx5_glue_dr_reclaim_domain_memory,
1547 .dr_create_flow_action_sampler =
1548 mlx5_glue_dr_create_flow_action_sampler,
1549 .dr_create_flow_action_dest_array =
1550 mlx5_glue_dr_action_create_dest_array,
1551 .dr_allow_duplicate_rules = mlx5_glue_dr_allow_duplicate_rules,
1552 .devx_query_eqn = mlx5_glue_devx_query_eqn,
1553 .devx_create_event_channel = mlx5_glue_devx_create_event_channel,
1554 .devx_destroy_event_channel = mlx5_glue_devx_destroy_event_channel,
1555 .devx_subscribe_devx_event = mlx5_glue_devx_subscribe_devx_event,
1556 .devx_subscribe_devx_event_fd = mlx5_glue_devx_subscribe_devx_event_fd,
1557 .devx_get_event = mlx5_glue_devx_get_event,
1558 .devx_alloc_uar = mlx5_glue_devx_alloc_uar,
1559 .devx_free_uar = mlx5_glue_devx_free_uar,
1560 .dv_alloc_var = mlx5_glue_dv_alloc_var,
1561 .dv_free_var = mlx5_glue_dv_free_var,
1562 .dv_alloc_pp = mlx5_glue_dv_alloc_pp,
1563 .dv_free_pp = mlx5_glue_dv_free_pp,
1564 };
1565