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