ba5fd067ed6f037875947d471e5e3b21d10d359a
[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 <stdalign.h>
8 #include <stddef.h>
9 #include <stdint.h>
10 #include <stdlib.h>
11
12 /*
13  * Not needed by this file; included to work around the lack of off_t
14  * definition for mlx5dv.h with unpatched rdma-core versions.
15  */
16 #include <sys/types.h>
17
18 /* Verbs headers do not support -pedantic. */
19 #ifdef PEDANTIC
20 #pragma GCC diagnostic ignored "-Wpedantic"
21 #endif
22 #include <infiniband/mlx5dv.h>
23 #include <infiniband/verbs.h>
24 #ifdef PEDANTIC
25 #pragma GCC diagnostic error "-Wpedantic"
26 #endif
27
28 #include <rte_config.h>
29
30 #include "mlx5_autoconf.h"
31 #include "mlx5_glue.h"
32
33 static int
34 mlx5_glue_fork_init(void)
35 {
36         return ibv_fork_init();
37 }
38
39 static struct ibv_pd *
40 mlx5_glue_alloc_pd(struct ibv_context *context)
41 {
42         return ibv_alloc_pd(context);
43 }
44
45 static int
46 mlx5_glue_dealloc_pd(struct ibv_pd *pd)
47 {
48         return ibv_dealloc_pd(pd);
49 }
50
51 static struct ibv_device **
52 mlx5_glue_get_device_list(int *num_devices)
53 {
54         return ibv_get_device_list(num_devices);
55 }
56
57 static void
58 mlx5_glue_free_device_list(struct ibv_device **list)
59 {
60         ibv_free_device_list(list);
61 }
62
63 static struct ibv_context *
64 mlx5_glue_open_device(struct ibv_device *device)
65 {
66         return ibv_open_device(device);
67 }
68
69 static int
70 mlx5_glue_close_device(struct ibv_context *context)
71 {
72         return ibv_close_device(context);
73 }
74
75 static int
76 mlx5_glue_query_device(struct ibv_context *context,
77                        struct ibv_device_attr *device_attr)
78 {
79         return ibv_query_device(context, device_attr);
80 }
81
82 static int
83 mlx5_glue_query_device_ex(struct ibv_context *context,
84                           const struct ibv_query_device_ex_input *input,
85                           struct ibv_device_attr_ex *attr)
86 {
87         return ibv_query_device_ex(context, input, attr);
88 }
89
90 static int
91 mlx5_glue_query_rt_values_ex(struct ibv_context *context,
92                           struct ibv_values_ex *values)
93 {
94         return ibv_query_rt_values_ex(context, values);
95 }
96
97 static int
98 mlx5_glue_query_port(struct ibv_context *context, uint8_t port_num,
99                      struct ibv_port_attr *port_attr)
100 {
101         return ibv_query_port(context, port_num, port_attr);
102 }
103
104 static struct ibv_comp_channel *
105 mlx5_glue_create_comp_channel(struct ibv_context *context)
106 {
107         return ibv_create_comp_channel(context);
108 }
109
110 static int
111 mlx5_glue_destroy_comp_channel(struct ibv_comp_channel *channel)
112 {
113         return ibv_destroy_comp_channel(channel);
114 }
115
116 static struct ibv_cq *
117 mlx5_glue_create_cq(struct ibv_context *context, int cqe, void *cq_context,
118                     struct ibv_comp_channel *channel, int comp_vector)
119 {
120         return ibv_create_cq(context, cqe, cq_context, channel, comp_vector);
121 }
122
123 static int
124 mlx5_glue_destroy_cq(struct ibv_cq *cq)
125 {
126         return ibv_destroy_cq(cq);
127 }
128
129 static int
130 mlx5_glue_get_cq_event(struct ibv_comp_channel *channel, struct ibv_cq **cq,
131                        void **cq_context)
132 {
133         return ibv_get_cq_event(channel, cq, cq_context);
134 }
135
136 static void
137 mlx5_glue_ack_cq_events(struct ibv_cq *cq, unsigned int nevents)
138 {
139         ibv_ack_cq_events(cq, nevents);
140 }
141
142 static struct ibv_rwq_ind_table *
143 mlx5_glue_create_rwq_ind_table(struct ibv_context *context,
144                                struct ibv_rwq_ind_table_init_attr *init_attr)
145 {
146         return ibv_create_rwq_ind_table(context, init_attr);
147 }
148
149 static int
150 mlx5_glue_destroy_rwq_ind_table(struct ibv_rwq_ind_table *rwq_ind_table)
151 {
152         return ibv_destroy_rwq_ind_table(rwq_ind_table);
153 }
154
155 static struct ibv_wq *
156 mlx5_glue_create_wq(struct ibv_context *context,
157                     struct ibv_wq_init_attr *wq_init_attr)
158 {
159         return ibv_create_wq(context, wq_init_attr);
160 }
161
162 static int
163 mlx5_glue_destroy_wq(struct ibv_wq *wq)
164 {
165         return ibv_destroy_wq(wq);
166 }
167 static int
168 mlx5_glue_modify_wq(struct ibv_wq *wq, struct ibv_wq_attr *wq_attr)
169 {
170         return ibv_modify_wq(wq, wq_attr);
171 }
172
173 static struct ibv_flow *
174 mlx5_glue_create_flow(struct ibv_qp *qp, struct ibv_flow_attr *flow)
175 {
176         return ibv_create_flow(qp, flow);
177 }
178
179 static int
180 mlx5_glue_destroy_flow(struct ibv_flow *flow_id)
181 {
182         return ibv_destroy_flow(flow_id);
183 }
184
185 static int
186 mlx5_glue_destroy_flow_action(void *action)
187 {
188 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
189 #ifdef HAVE_MLX5DV_DR
190         return mlx5dv_dr_action_destroy(action);
191 #else
192         struct mlx5dv_flow_action_attr *attr = action;
193         int res = 0;
194         switch (attr->type) {
195         case MLX5DV_FLOW_ACTION_TAG:
196                 break;
197         default:
198                 res = ibv_destroy_flow_action(attr->action);
199                 break;
200         }
201         free(action);
202         return res;
203 #endif
204 #else
205         (void)action;
206         return ENOTSUP;
207 #endif
208 }
209
210 static struct ibv_qp *
211 mlx5_glue_create_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *qp_init_attr)
212 {
213         return ibv_create_qp(pd, qp_init_attr);
214 }
215
216 static struct ibv_qp *
217 mlx5_glue_create_qp_ex(struct ibv_context *context,
218                        struct ibv_qp_init_attr_ex *qp_init_attr_ex)
219 {
220         return ibv_create_qp_ex(context, qp_init_attr_ex);
221 }
222
223 static int
224 mlx5_glue_destroy_qp(struct ibv_qp *qp)
225 {
226         return ibv_destroy_qp(qp);
227 }
228
229 static int
230 mlx5_glue_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, int attr_mask)
231 {
232         return ibv_modify_qp(qp, attr, attr_mask);
233 }
234
235 static struct ibv_mr *
236 mlx5_glue_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access)
237 {
238         return ibv_reg_mr(pd, addr, length, access);
239 }
240
241 static int
242 mlx5_glue_dereg_mr(struct ibv_mr *mr)
243 {
244         return ibv_dereg_mr(mr);
245 }
246
247 static struct ibv_counter_set *
248 mlx5_glue_create_counter_set(struct ibv_context *context,
249                              struct ibv_counter_set_init_attr *init_attr)
250 {
251 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
252         (void)context;
253         (void)init_attr;
254         return NULL;
255 #else
256         return ibv_create_counter_set(context, init_attr);
257 #endif
258 }
259
260 static int
261 mlx5_glue_destroy_counter_set(struct ibv_counter_set *cs)
262 {
263 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
264         (void)cs;
265         return ENOTSUP;
266 #else
267         return ibv_destroy_counter_set(cs);
268 #endif
269 }
270
271 static int
272 mlx5_glue_describe_counter_set(struct ibv_context *context,
273                                uint16_t counter_set_id,
274                                struct ibv_counter_set_description *cs_desc)
275 {
276 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
277         (void)context;
278         (void)counter_set_id;
279         (void)cs_desc;
280         return ENOTSUP;
281 #else
282         return ibv_describe_counter_set(context, counter_set_id, cs_desc);
283 #endif
284 }
285
286 static int
287 mlx5_glue_query_counter_set(struct ibv_query_counter_set_attr *query_attr,
288                             struct ibv_counter_set_data *cs_data)
289 {
290 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
291         (void)query_attr;
292         (void)cs_data;
293         return ENOTSUP;
294 #else
295         return ibv_query_counter_set(query_attr, cs_data);
296 #endif
297 }
298
299 static struct ibv_counters *
300 mlx5_glue_create_counters(struct ibv_context *context,
301                           struct ibv_counters_init_attr *init_attr)
302 {
303 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
304         (void)context;
305         (void)init_attr;
306         errno = ENOTSUP;
307         return NULL;
308 #else
309         return ibv_create_counters(context, init_attr);
310 #endif
311 }
312
313 static int
314 mlx5_glue_destroy_counters(struct ibv_counters *counters)
315 {
316 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
317         (void)counters;
318         return ENOTSUP;
319 #else
320         return ibv_destroy_counters(counters);
321 #endif
322 }
323
324 static int
325 mlx5_glue_attach_counters(struct ibv_counters *counters,
326                           struct ibv_counter_attach_attr *attr,
327                           struct ibv_flow *flow)
328 {
329 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
330         (void)counters;
331         (void)attr;
332         (void)flow;
333         return ENOTSUP;
334 #else
335         return ibv_attach_counters_point_flow(counters, attr, flow);
336 #endif
337 }
338
339 static int
340 mlx5_glue_query_counters(struct ibv_counters *counters,
341                          uint64_t *counters_value,
342                          uint32_t ncounters,
343                          uint32_t flags)
344 {
345 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
346         (void)counters;
347         (void)counters_value;
348         (void)ncounters;
349         (void)flags;
350         return ENOTSUP;
351 #else
352         return ibv_read_counters(counters, counters_value, ncounters, flags);
353 #endif
354 }
355
356 static void
357 mlx5_glue_ack_async_event(struct ibv_async_event *event)
358 {
359         ibv_ack_async_event(event);
360 }
361
362 static int
363 mlx5_glue_get_async_event(struct ibv_context *context,
364                           struct ibv_async_event *event)
365 {
366         return ibv_get_async_event(context, event);
367 }
368
369 static const char *
370 mlx5_glue_port_state_str(enum ibv_port_state port_state)
371 {
372         return ibv_port_state_str(port_state);
373 }
374
375 static struct ibv_cq *
376 mlx5_glue_cq_ex_to_cq(struct ibv_cq_ex *cq)
377 {
378         return ibv_cq_ex_to_cq(cq);
379 }
380
381 static void *
382 mlx5_glue_dr_create_flow_action_dest_flow_tbl(void *tbl)
383 {
384 #ifdef HAVE_MLX5DV_DR
385         return mlx5dv_dr_action_create_dest_table(tbl);
386 #else
387         (void)tbl;
388         errno = ENOTSUP;
389         return NULL;
390 #endif
391 }
392
393 static void *
394 mlx5_glue_dr_create_flow_action_dest_vport(void *domain, uint32_t vport)
395 {
396 #ifdef HAVE_MLX5DV_DR_ESWITCH
397         return mlx5dv_dr_action_create_dest_vport(domain, vport);
398 #else
399         (void)domain;
400         (void)vport;
401         errno = ENOTSUP;
402         return NULL;
403 #endif
404 }
405
406 static void *
407 mlx5_glue_dr_create_flow_action_drop(void)
408 {
409 #ifdef HAVE_MLX5DV_DR_ESWITCH
410         return mlx5dv_dr_action_create_drop();
411 #else
412         errno = ENOTSUP;
413         return NULL;
414 #endif
415 }
416
417 static void *
418 mlx5_glue_dr_create_flow_tbl(void *domain, uint32_t level)
419 {
420 #ifdef HAVE_MLX5DV_DR
421         return mlx5dv_dr_table_create(domain, level);
422 #else
423         (void)domain;
424         (void)level;
425         errno = ENOTSUP;
426         return NULL;
427 #endif
428 }
429
430 static int
431 mlx5_glue_dr_destroy_flow_tbl(void *tbl)
432 {
433 #ifdef HAVE_MLX5DV_DR
434         return mlx5dv_dr_table_destroy(tbl);
435 #else
436         (void)tbl;
437         errno = ENOTSUP;
438         return errno;
439 #endif
440 }
441
442 static void *
443 mlx5_glue_dr_create_domain(struct ibv_context *ctx,
444                            enum  mlx5dv_dr_domain_type domain)
445 {
446 #ifdef HAVE_MLX5DV_DR
447         return mlx5dv_dr_domain_create(ctx, domain);
448 #else
449         (void)ctx;
450         (void)domain;
451         errno = ENOTSUP;
452         return NULL;
453 #endif
454 }
455
456 static int
457 mlx5_glue_dr_destroy_domain(void *domain)
458 {
459 #ifdef HAVE_MLX5DV_DR
460         return mlx5dv_dr_domain_destroy(domain);
461 #else
462         (void)domain;
463         errno = ENOTSUP;
464         return errno;
465 #endif
466 }
467
468 static struct ibv_cq_ex *
469 mlx5_glue_dv_create_cq(struct ibv_context *context,
470                        struct ibv_cq_init_attr_ex *cq_attr,
471                        struct mlx5dv_cq_init_attr *mlx5_cq_attr)
472 {
473         return mlx5dv_create_cq(context, cq_attr, mlx5_cq_attr);
474 }
475
476 static struct ibv_wq *
477 mlx5_glue_dv_create_wq(struct ibv_context *context,
478                        struct ibv_wq_init_attr *wq_attr,
479                        struct mlx5dv_wq_init_attr *mlx5_wq_attr)
480 {
481 #ifndef HAVE_IBV_DEVICE_STRIDING_RQ_SUPPORT
482         (void)context;
483         (void)wq_attr;
484         (void)mlx5_wq_attr;
485         errno = ENOTSUP;
486         return NULL;
487 #else
488         return mlx5dv_create_wq(context, wq_attr, mlx5_wq_attr);
489 #endif
490 }
491
492 static int
493 mlx5_glue_dv_query_device(struct ibv_context *ctx,
494                           struct mlx5dv_context *attrs_out)
495 {
496         return mlx5dv_query_device(ctx, attrs_out);
497 }
498
499 static int
500 mlx5_glue_dv_set_context_attr(struct ibv_context *ibv_ctx,
501                               enum mlx5dv_set_ctx_attr_type type, void *attr)
502 {
503         return mlx5dv_set_context_attr(ibv_ctx, type, attr);
504 }
505
506 static int
507 mlx5_glue_dv_init_obj(struct mlx5dv_obj *obj, uint64_t obj_type)
508 {
509         return mlx5dv_init_obj(obj, obj_type);
510 }
511
512 static struct ibv_qp *
513 mlx5_glue_dv_create_qp(struct ibv_context *context,
514                        struct ibv_qp_init_attr_ex *qp_init_attr_ex,
515                        struct mlx5dv_qp_init_attr *dv_qp_init_attr)
516 {
517 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
518         return mlx5dv_create_qp(context, qp_init_attr_ex, dv_qp_init_attr);
519 #else
520         (void)context;
521         (void)qp_init_attr_ex;
522         (void)dv_qp_init_attr;
523         errno = ENOTSUP;
524         return NULL;
525 #endif
526 }
527
528 static void *
529 mlx5_glue_dv_create_flow_matcher(struct ibv_context *context,
530                                  struct mlx5dv_flow_matcher_attr *matcher_attr,
531                                  void *tbl)
532 {
533 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
534 #ifdef HAVE_MLX5DV_DR
535         (void)context;
536         return mlx5dv_dr_matcher_create(tbl, matcher_attr->priority,
537                                         matcher_attr->match_criteria_enable,
538                                         matcher_attr->match_mask);
539 #else
540         (void)tbl;
541         return mlx5dv_create_flow_matcher(context, matcher_attr);
542 #endif
543 #else
544         (void)context;
545         (void)matcher_attr;
546         (void)tbl;
547         errno = ENOTSUP;
548         return NULL;
549 #endif
550 }
551
552 static void *
553 mlx5_glue_dv_create_flow(void *matcher,
554                          void *match_value,
555                          size_t num_actions,
556                          void *actions[])
557 {
558 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
559 #ifdef HAVE_MLX5DV_DR
560         return mlx5dv_dr_rule_create(matcher, match_value, num_actions,
561                                      (struct mlx5dv_dr_action **)actions);
562 #else
563         struct mlx5dv_flow_action_attr actions_attr[8];
564
565         if (num_actions > 8)
566                 return NULL;
567         for (size_t i = 0; i < num_actions; i++)
568                 actions_attr[i] =
569                         *((struct mlx5dv_flow_action_attr *)(actions[i]));
570         return mlx5dv_create_flow(matcher, match_value,
571                                   num_actions, actions_attr);
572 #endif
573 #else
574         (void)matcher;
575         (void)match_value;
576         (void)num_actions;
577         (void)actions;
578         return NULL;
579 #endif
580 }
581
582 static void *
583 mlx5_glue_dv_create_flow_action_counter(void *counter_obj, uint32_t offset)
584 {
585 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
586 #ifdef HAVE_MLX5DV_DR
587         return mlx5dv_dr_action_create_flow_counter(counter_obj, offset);
588 #else
589         struct mlx5dv_flow_action_attr *action;
590
591         (void)offset;
592         action = malloc(sizeof(*action));
593         if (!action)
594                 return NULL;
595         action->type = MLX5DV_FLOW_ACTION_COUNTERS_DEVX;
596         action->obj = counter_obj;
597         return action;
598 #endif
599 #else
600         (void)counter_obj;
601         (void)offset;
602         errno = ENOTSUP;
603         return NULL;
604 #endif
605 }
606
607 static void *
608 mlx5_glue_dv_create_flow_action_dest_ibv_qp(void *qp)
609 {
610 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
611 #ifdef HAVE_MLX5DV_DR
612         return mlx5dv_dr_action_create_dest_ibv_qp(qp);
613 #else
614         struct mlx5dv_flow_action_attr *action;
615
616         action = malloc(sizeof(*action));
617         if (!action)
618                 return NULL;
619         action->type = MLX5DV_FLOW_ACTION_DEST_IBV_QP;
620         action->obj = qp;
621         return action;
622 #endif
623 #else
624         (void)qp;
625         errno = ENOTSUP;
626         return NULL;
627 #endif
628 }
629
630 static void *
631 mlx5_glue_dv_create_flow_action_modify_header
632                                         (struct ibv_context *ctx,
633                                          enum mlx5dv_flow_table_type ft_type,
634                                          void *domain, uint64_t flags,
635                                          size_t actions_sz,
636                                          uint64_t actions[])
637 {
638 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
639 #ifdef HAVE_MLX5DV_DR
640         (void)ctx;
641         (void)ft_type;
642         return mlx5dv_dr_action_create_modify_header(domain, flags, actions_sz,
643                                                      (__be64 *)actions);
644 #else
645         struct mlx5dv_flow_action_attr *action;
646
647         (void)domain;
648         (void)flags;
649         action = malloc(sizeof(*action));
650         if (!action)
651                 return NULL;
652         action->type = MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION;
653         action->action = mlx5dv_create_flow_action_modify_header
654                 (ctx, actions_sz, actions, ft_type);
655         return action;
656 #endif
657 #else
658         (void)ctx;
659         (void)ft_type;
660         (void)domain;
661         (void)flags;
662         (void)actions_sz;
663         (void)actions;
664         errno = ENOTSUP;
665         return NULL;
666 #endif
667 }
668
669 static void *
670 mlx5_glue_dv_create_flow_action_packet_reformat
671                 (struct ibv_context *ctx,
672                  enum mlx5dv_flow_action_packet_reformat_type reformat_type,
673                  enum mlx5dv_flow_table_type ft_type,
674                  struct mlx5dv_dr_domain *domain,
675                  uint32_t flags, size_t data_sz, void *data)
676 {
677 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
678 #ifdef HAVE_MLX5DV_DR
679         (void)ctx;
680         (void)ft_type;
681         return mlx5dv_dr_action_create_packet_reformat(domain, flags,
682                                                        reformat_type, data_sz,
683                                                        data);
684 #else
685         (void)domain;
686         (void)flags;
687         struct mlx5dv_flow_action_attr *action;
688
689         action = malloc(sizeof(*action));
690         if (!action)
691                 return NULL;
692         action->type = MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION;
693         action->action = mlx5dv_create_flow_action_packet_reformat
694                 (ctx, data_sz, data, reformat_type, ft_type);
695         return action;
696 #endif
697 #else
698         (void)ctx;
699         (void)reformat_type;
700         (void)ft_type;
701         (void)domain;
702         (void)flags;
703         (void)data_sz;
704         (void)data;
705         errno = ENOTSUP;
706         return NULL;
707 #endif
708 }
709
710 static void *
711 mlx5_glue_dv_create_flow_action_tag(uint32_t tag)
712 {
713 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
714 #ifdef HAVE_MLX5DV_DR
715         return mlx5dv_dr_action_create_tag(tag);
716 #else
717         struct mlx5dv_flow_action_attr *action;
718         action = malloc(sizeof(*action));
719         if (!action)
720                 return NULL;
721         action->type = MLX5DV_FLOW_ACTION_TAG;
722         action->tag_value = tag;
723         return action;
724 #endif
725 #endif
726         (void)tag;
727         errno = ENOTSUP;
728         return NULL;
729 }
730
731 static int
732 mlx5_glue_dv_destroy_flow(void *flow_id)
733 {
734 #ifdef HAVE_MLX5DV_DR
735         return mlx5dv_dr_rule_destroy(flow_id);
736 #else
737         return ibv_destroy_flow(flow_id);
738 #endif
739 }
740
741 static int
742 mlx5_glue_dv_destroy_flow_matcher(void *matcher)
743 {
744 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
745 #ifdef HAVE_MLX5DV_DR
746         return mlx5dv_dr_matcher_destroy(matcher);
747 #else
748         return mlx5dv_destroy_flow_matcher(matcher);
749 #endif
750 #else
751         (void)matcher;
752         errno = ENOTSUP;
753         return errno;
754 #endif
755 }
756
757 static struct ibv_context *
758 mlx5_glue_dv_open_device(struct ibv_device *device)
759 {
760 #ifdef HAVE_IBV_DEVX_OBJ
761         return mlx5dv_open_device(device,
762                                   &(struct mlx5dv_context_attr){
763                                         .flags = MLX5DV_CONTEXT_FLAGS_DEVX,
764                                   });
765 #else
766         (void)device;
767         errno = ENOTSUP;
768         return NULL;
769 #endif
770 }
771
772 static struct mlx5dv_devx_obj *
773 mlx5_glue_devx_obj_create(struct ibv_context *ctx,
774                           const void *in, size_t inlen,
775                           void *out, size_t outlen)
776 {
777 #ifdef HAVE_IBV_DEVX_OBJ
778         return mlx5dv_devx_obj_create(ctx, in, inlen, out, outlen);
779 #else
780         (void)ctx;
781         (void)in;
782         (void)inlen;
783         (void)out;
784         (void)outlen;
785         errno = ENOTSUP;
786         return NULL;
787 #endif
788 }
789
790 static int
791 mlx5_glue_devx_obj_destroy(struct mlx5dv_devx_obj *obj)
792 {
793 #ifdef HAVE_IBV_DEVX_OBJ
794         return mlx5dv_devx_obj_destroy(obj);
795 #else
796         (void)obj;
797         return -ENOTSUP;
798 #endif
799 }
800
801 static int
802 mlx5_glue_devx_obj_query(struct mlx5dv_devx_obj *obj,
803                          const void *in, size_t inlen,
804                          void *out, size_t outlen)
805 {
806 #ifdef HAVE_IBV_DEVX_OBJ
807         return mlx5dv_devx_obj_query(obj, in, inlen, out, outlen);
808 #else
809         (void)obj;
810         (void)in;
811         (void)inlen;
812         (void)out;
813         (void)outlen;
814         return -ENOTSUP;
815 #endif
816 }
817
818 static int
819 mlx5_glue_devx_obj_modify(struct mlx5dv_devx_obj *obj,
820                           const void *in, size_t inlen,
821                           void *out, size_t outlen)
822 {
823 #ifdef HAVE_IBV_DEVX_OBJ
824         return mlx5dv_devx_obj_modify(obj, in, inlen, out, outlen);
825 #else
826         (void)obj;
827         (void)in;
828         (void)inlen;
829         (void)out;
830         (void)outlen;
831         return -ENOTSUP;
832 #endif
833 }
834
835 static int
836 mlx5_glue_devx_general_cmd(struct ibv_context *ctx,
837                            const void *in, size_t inlen,
838                            void *out, size_t outlen)
839 {
840 #ifdef HAVE_IBV_DEVX_OBJ
841         return mlx5dv_devx_general_cmd(ctx, in, inlen, out, outlen);
842 #else
843         (void)ctx;
844         (void)in;
845         (void)inlen;
846         (void)out;
847         (void)outlen;
848         return -ENOTSUP;
849 #endif
850 }
851
852 static struct mlx5dv_devx_umem *
853 mlx5_glue_devx_umem_reg(struct ibv_context *context, void *addr, size_t size,
854                         uint32_t access)
855 {
856 #ifdef HAVE_IBV_DEVX_OBJ
857         return mlx5dv_devx_umem_reg(context, addr, size, access);
858 #else
859         (void)context;
860         (void)addr;
861         (void)size;
862         (void)access;
863         errno = -ENOTSUP;
864         return NULL;
865 #endif
866 }
867
868 static int
869 mlx5_glue_devx_umem_dereg(struct mlx5dv_devx_umem *dv_devx_umem)
870 {
871 #ifdef HAVE_IBV_DEVX_OBJ
872         return mlx5dv_devx_umem_dereg(dv_devx_umem);
873 #else
874         (void)dv_devx_umem;
875         return -ENOTSUP;
876 #endif
877 }
878
879 alignas(RTE_CACHE_LINE_SIZE)
880 const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue){
881         .version = MLX5_GLUE_VERSION,
882         .fork_init = mlx5_glue_fork_init,
883         .alloc_pd = mlx5_glue_alloc_pd,
884         .dealloc_pd = mlx5_glue_dealloc_pd,
885         .get_device_list = mlx5_glue_get_device_list,
886         .free_device_list = mlx5_glue_free_device_list,
887         .open_device = mlx5_glue_open_device,
888         .close_device = mlx5_glue_close_device,
889         .query_device = mlx5_glue_query_device,
890         .query_device_ex = mlx5_glue_query_device_ex,
891         .query_rt_values_ex = mlx5_glue_query_rt_values_ex,
892         .query_port = mlx5_glue_query_port,
893         .create_comp_channel = mlx5_glue_create_comp_channel,
894         .destroy_comp_channel = mlx5_glue_destroy_comp_channel,
895         .create_cq = mlx5_glue_create_cq,
896         .destroy_cq = mlx5_glue_destroy_cq,
897         .get_cq_event = mlx5_glue_get_cq_event,
898         .ack_cq_events = mlx5_glue_ack_cq_events,
899         .create_rwq_ind_table = mlx5_glue_create_rwq_ind_table,
900         .destroy_rwq_ind_table = mlx5_glue_destroy_rwq_ind_table,
901         .create_wq = mlx5_glue_create_wq,
902         .destroy_wq = mlx5_glue_destroy_wq,
903         .modify_wq = mlx5_glue_modify_wq,
904         .create_flow = mlx5_glue_create_flow,
905         .destroy_flow = mlx5_glue_destroy_flow,
906         .destroy_flow_action = mlx5_glue_destroy_flow_action,
907         .create_qp = mlx5_glue_create_qp,
908         .create_qp_ex = mlx5_glue_create_qp_ex,
909         .destroy_qp = mlx5_glue_destroy_qp,
910         .modify_qp = mlx5_glue_modify_qp,
911         .reg_mr = mlx5_glue_reg_mr,
912         .dereg_mr = mlx5_glue_dereg_mr,
913         .create_counter_set = mlx5_glue_create_counter_set,
914         .destroy_counter_set = mlx5_glue_destroy_counter_set,
915         .describe_counter_set = mlx5_glue_describe_counter_set,
916         .query_counter_set = mlx5_glue_query_counter_set,
917         .create_counters = mlx5_glue_create_counters,
918         .destroy_counters = mlx5_glue_destroy_counters,
919         .attach_counters = mlx5_glue_attach_counters,
920         .query_counters = mlx5_glue_query_counters,
921         .ack_async_event = mlx5_glue_ack_async_event,
922         .get_async_event = mlx5_glue_get_async_event,
923         .port_state_str = mlx5_glue_port_state_str,
924         .cq_ex_to_cq = mlx5_glue_cq_ex_to_cq,
925         .dr_create_flow_action_dest_flow_tbl =
926                 mlx5_glue_dr_create_flow_action_dest_flow_tbl,
927         .dr_create_flow_action_dest_vport =
928                 mlx5_glue_dr_create_flow_action_dest_vport,
929         .dr_create_flow_action_drop =
930                 mlx5_glue_dr_create_flow_action_drop,
931         .dr_create_flow_tbl = mlx5_glue_dr_create_flow_tbl,
932         .dr_destroy_flow_tbl = mlx5_glue_dr_destroy_flow_tbl,
933         .dr_create_domain = mlx5_glue_dr_create_domain,
934         .dr_destroy_domain = mlx5_glue_dr_destroy_domain,
935         .dv_create_cq = mlx5_glue_dv_create_cq,
936         .dv_create_wq = mlx5_glue_dv_create_wq,
937         .dv_query_device = mlx5_glue_dv_query_device,
938         .dv_set_context_attr = mlx5_glue_dv_set_context_attr,
939         .dv_init_obj = mlx5_glue_dv_init_obj,
940         .dv_create_qp = mlx5_glue_dv_create_qp,
941         .dv_create_flow_matcher = mlx5_glue_dv_create_flow_matcher,
942         .dv_create_flow = mlx5_glue_dv_create_flow,
943         .dv_create_flow_action_counter =
944                 mlx5_glue_dv_create_flow_action_counter,
945         .dv_create_flow_action_dest_ibv_qp =
946                 mlx5_glue_dv_create_flow_action_dest_ibv_qp,
947         .dv_create_flow_action_modify_header =
948                 mlx5_glue_dv_create_flow_action_modify_header,
949         .dv_create_flow_action_packet_reformat =
950                 mlx5_glue_dv_create_flow_action_packet_reformat,
951         .dv_create_flow_action_tag =  mlx5_glue_dv_create_flow_action_tag,
952         .dv_destroy_flow = mlx5_glue_dv_destroy_flow,
953         .dv_destroy_flow_matcher = mlx5_glue_dv_destroy_flow_matcher,
954         .dv_open_device = mlx5_glue_dv_open_device,
955         .devx_obj_create = mlx5_glue_devx_obj_create,
956         .devx_obj_destroy = mlx5_glue_devx_obj_destroy,
957         .devx_obj_query = mlx5_glue_devx_obj_query,
958         .devx_obj_modify = mlx5_glue_devx_obj_modify,
959         .devx_general_cmd = mlx5_glue_devx_general_cmd,
960         .devx_umem_reg = mlx5_glue_devx_umem_reg,
961         .devx_umem_dereg = mlx5_glue_devx_umem_dereg,
962 };