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