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