1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018 6WIND S.A.
3 * Copyright 2018 Mellanox Technologies, Ltd
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.
15 #include <sys/types.h>
17 /* Verbs headers do not support -pedantic. */
19 #pragma GCC diagnostic ignored "-Wpedantic"
21 #include <infiniband/mlx5dv.h>
22 #include <infiniband/verbs.h>
24 #pragma GCC diagnostic error "-Wpedantic"
27 #include <rte_config.h>
29 #include "mlx5_autoconf.h"
30 #include "mlx5_glue.h"
33 mlx5_glue_fork_init(void)
35 return ibv_fork_init();
38 static struct ibv_pd *
39 mlx5_glue_alloc_pd(struct ibv_context *context)
41 return ibv_alloc_pd(context);
45 mlx5_glue_dealloc_pd(struct ibv_pd *pd)
47 return ibv_dealloc_pd(pd);
50 static struct ibv_device **
51 mlx5_glue_get_device_list(int *num_devices)
53 return ibv_get_device_list(num_devices);
57 mlx5_glue_free_device_list(struct ibv_device **list)
59 ibv_free_device_list(list);
62 static struct ibv_context *
63 mlx5_glue_open_device(struct ibv_device *device)
65 return ibv_open_device(device);
69 mlx5_glue_close_device(struct ibv_context *context)
71 return ibv_close_device(context);
75 mlx5_glue_query_device(struct ibv_context *context,
76 struct ibv_device_attr *device_attr)
78 return ibv_query_device(context, device_attr);
82 mlx5_glue_query_device_ex(struct ibv_context *context,
83 const struct ibv_query_device_ex_input *input,
84 struct ibv_device_attr_ex *attr)
86 return ibv_query_device_ex(context, input, attr);
90 mlx5_glue_query_port(struct ibv_context *context, uint8_t port_num,
91 struct ibv_port_attr *port_attr)
93 return ibv_query_port(context, port_num, port_attr);
96 static struct ibv_comp_channel *
97 mlx5_glue_create_comp_channel(struct ibv_context *context)
99 return ibv_create_comp_channel(context);
103 mlx5_glue_destroy_comp_channel(struct ibv_comp_channel *channel)
105 return ibv_destroy_comp_channel(channel);
108 static struct ibv_cq *
109 mlx5_glue_create_cq(struct ibv_context *context, int cqe, void *cq_context,
110 struct ibv_comp_channel *channel, int comp_vector)
112 return ibv_create_cq(context, cqe, cq_context, channel, comp_vector);
116 mlx5_glue_destroy_cq(struct ibv_cq *cq)
118 return ibv_destroy_cq(cq);
122 mlx5_glue_get_cq_event(struct ibv_comp_channel *channel, struct ibv_cq **cq,
125 return ibv_get_cq_event(channel, cq, cq_context);
129 mlx5_glue_ack_cq_events(struct ibv_cq *cq, unsigned int nevents)
131 ibv_ack_cq_events(cq, nevents);
134 static struct ibv_rwq_ind_table *
135 mlx5_glue_create_rwq_ind_table(struct ibv_context *context,
136 struct ibv_rwq_ind_table_init_attr *init_attr)
138 return ibv_create_rwq_ind_table(context, init_attr);
142 mlx5_glue_destroy_rwq_ind_table(struct ibv_rwq_ind_table *rwq_ind_table)
144 return ibv_destroy_rwq_ind_table(rwq_ind_table);
147 static struct ibv_wq *
148 mlx5_glue_create_wq(struct ibv_context *context,
149 struct ibv_wq_init_attr *wq_init_attr)
151 return ibv_create_wq(context, wq_init_attr);
155 mlx5_glue_destroy_wq(struct ibv_wq *wq)
157 return ibv_destroy_wq(wq);
160 mlx5_glue_modify_wq(struct ibv_wq *wq, struct ibv_wq_attr *wq_attr)
162 return ibv_modify_wq(wq, wq_attr);
165 static struct ibv_flow *
166 mlx5_glue_create_flow(struct ibv_qp *qp, struct ibv_flow_attr *flow)
168 return ibv_create_flow(qp, flow);
172 mlx5_glue_destroy_flow(struct ibv_flow *flow_id)
174 return ibv_destroy_flow(flow_id);
178 mlx5_glue_destroy_flow_action(void *action)
180 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
181 #ifdef HAVE_MLX5DV_DR
182 return mlx5dv_dr_destroy_action(action);
184 struct mlx5dv_flow_action_attr *attr = action;
186 switch (attr->type) {
187 case MLX5DV_FLOW_ACTION_TAG:
190 res = ibv_destroy_flow_action(attr->action);
202 static struct ibv_qp *
203 mlx5_glue_create_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *qp_init_attr)
205 return ibv_create_qp(pd, qp_init_attr);
208 static struct ibv_qp *
209 mlx5_glue_create_qp_ex(struct ibv_context *context,
210 struct ibv_qp_init_attr_ex *qp_init_attr_ex)
212 return ibv_create_qp_ex(context, qp_init_attr_ex);
216 mlx5_glue_destroy_qp(struct ibv_qp *qp)
218 return ibv_destroy_qp(qp);
222 mlx5_glue_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, int attr_mask)
224 return ibv_modify_qp(qp, attr, attr_mask);
227 static struct ibv_mr *
228 mlx5_glue_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access)
230 return ibv_reg_mr(pd, addr, length, access);
234 mlx5_glue_dereg_mr(struct ibv_mr *mr)
236 return ibv_dereg_mr(mr);
239 static struct ibv_counter_set *
240 mlx5_glue_create_counter_set(struct ibv_context *context,
241 struct ibv_counter_set_init_attr *init_attr)
243 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
248 return ibv_create_counter_set(context, init_attr);
253 mlx5_glue_destroy_counter_set(struct ibv_counter_set *cs)
255 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
259 return ibv_destroy_counter_set(cs);
264 mlx5_glue_describe_counter_set(struct ibv_context *context,
265 uint16_t counter_set_id,
266 struct ibv_counter_set_description *cs_desc)
268 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
270 (void)counter_set_id;
274 return ibv_describe_counter_set(context, counter_set_id, cs_desc);
279 mlx5_glue_query_counter_set(struct ibv_query_counter_set_attr *query_attr,
280 struct ibv_counter_set_data *cs_data)
282 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
287 return ibv_query_counter_set(query_attr, cs_data);
291 static struct ibv_counters *
292 mlx5_glue_create_counters(struct ibv_context *context,
293 struct ibv_counters_init_attr *init_attr)
295 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
300 return ibv_create_counters(context, init_attr);
305 mlx5_glue_destroy_counters(struct ibv_counters *counters)
307 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
311 return ibv_destroy_counters(counters);
316 mlx5_glue_attach_counters(struct ibv_counters *counters,
317 struct ibv_counter_attach_attr *attr,
318 struct ibv_flow *flow)
320 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
326 return ibv_attach_counters_point_flow(counters, attr, flow);
331 mlx5_glue_query_counters(struct ibv_counters *counters,
332 uint64_t *counters_value,
336 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
338 (void)counters_value;
343 return ibv_read_counters(counters, counters_value, ncounters, flags);
348 mlx5_glue_ack_async_event(struct ibv_async_event *event)
350 ibv_ack_async_event(event);
354 mlx5_glue_get_async_event(struct ibv_context *context,
355 struct ibv_async_event *event)
357 return ibv_get_async_event(context, event);
361 mlx5_glue_port_state_str(enum ibv_port_state port_state)
363 return ibv_port_state_str(port_state);
366 static struct ibv_cq *
367 mlx5_glue_cq_ex_to_cq(struct ibv_cq_ex *cq)
369 return ibv_cq_ex_to_cq(cq);
373 mlx5_glue_dr_create_flow_action_dest_flow_tbl(void *tbl)
375 #ifdef HAVE_MLX5DV_DR
376 return mlx5dv_dr_create_action_dest_flow_table(tbl);
384 mlx5_glue_dr_create_flow_tbl(void *ns, uint32_t level)
386 #ifdef HAVE_MLX5DV_DR
387 return mlx5dv_dr_create_ft(ns, level);
396 mlx5_glue_dr_destroy_flow_tbl(void *tbl)
398 #ifdef HAVE_MLX5DV_DR
399 return mlx5dv_dr_destroy_ft(tbl);
407 mlx5_glue_dr_create_ns(struct ibv_context *ctx,
408 enum mlx5dv_dr_ns_domain domain)
410 #ifdef HAVE_MLX5DV_DR
411 return mlx5dv_dr_create_ns(ctx, domain);
420 mlx5_glue_dr_destroy_ns(void *ns)
422 #ifdef HAVE_MLX5DV_DR
423 return mlx5dv_dr_destroy_ns(ns);
430 static struct ibv_cq_ex *
431 mlx5_glue_dv_create_cq(struct ibv_context *context,
432 struct ibv_cq_init_attr_ex *cq_attr,
433 struct mlx5dv_cq_init_attr *mlx5_cq_attr)
435 return mlx5dv_create_cq(context, cq_attr, mlx5_cq_attr);
438 static struct ibv_wq *
439 mlx5_glue_dv_create_wq(struct ibv_context *context,
440 struct ibv_wq_init_attr *wq_attr,
441 struct mlx5dv_wq_init_attr *mlx5_wq_attr)
443 #ifndef HAVE_IBV_DEVICE_STRIDING_RQ_SUPPORT
449 return mlx5dv_create_wq(context, wq_attr, mlx5_wq_attr);
454 mlx5_glue_dv_query_device(struct ibv_context *ctx,
455 struct mlx5dv_context *attrs_out)
457 return mlx5dv_query_device(ctx, attrs_out);
461 mlx5_glue_dv_set_context_attr(struct ibv_context *ibv_ctx,
462 enum mlx5dv_set_ctx_attr_type type, void *attr)
464 return mlx5dv_set_context_attr(ibv_ctx, type, attr);
468 mlx5_glue_dv_init_obj(struct mlx5dv_obj *obj, uint64_t obj_type)
470 return mlx5dv_init_obj(obj, obj_type);
473 static struct ibv_qp *
474 mlx5_glue_dv_create_qp(struct ibv_context *context,
475 struct ibv_qp_init_attr_ex *qp_init_attr_ex,
476 struct mlx5dv_qp_init_attr *dv_qp_init_attr)
478 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
479 return mlx5dv_create_qp(context, qp_init_attr_ex, dv_qp_init_attr);
482 (void)qp_init_attr_ex;
483 (void)dv_qp_init_attr;
489 mlx5_glue_dv_create_flow_matcher(struct ibv_context *context,
490 struct mlx5dv_flow_matcher_attr *matcher_attr,
493 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
494 #ifdef HAVE_MLX5DV_DR
496 return mlx5dv_dr_create_matcher(tbl, matcher_attr->priority,
497 matcher_attr->match_criteria_enable,
498 matcher_attr->match_mask);
501 return mlx5dv_create_flow_matcher(context, matcher_attr);
512 mlx5_glue_dv_create_flow(void *matcher,
517 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
518 #ifdef HAVE_MLX5DV_DR
519 return mlx5dv_dr_create_rule(matcher, match_value, num_actions,
520 (struct mlx5dv_dr_action **)actions);
522 struct mlx5dv_flow_action_attr actions_attr[8];
526 for (size_t i = 0; i < num_actions; i++)
528 *((struct mlx5dv_flow_action_attr *)(actions[i]));
529 return mlx5dv_create_flow(matcher, match_value,
530 num_actions, actions_attr);
542 mlx5_glue_dv_create_flow_action_counter(void *counter_obj, uint32_t offset)
544 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
545 #ifdef HAVE_MLX5DV_DR
546 return mlx5dv_dr_create_action_devx_counter(counter_obj, offset);
548 struct mlx5dv_flow_action_attr *action;
551 action = malloc(sizeof(*action));
554 action->type = MLX5DV_FLOW_ACTION_COUNTERS_DEVX;
555 action->obj = counter_obj;
566 mlx5_glue_dv_create_flow_action_dest_ibv_qp(void *qp)
568 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
569 #ifdef HAVE_MLX5DV_DR
570 return mlx5dv_dr_create_action_dest_ibv_qp(qp);
572 struct mlx5dv_flow_action_attr *action;
574 action = malloc(sizeof(*action));
577 action->type = MLX5DV_FLOW_ACTION_DEST_IBV_QP;
588 mlx5_glue_dv_create_flow_action_modify_header
589 (struct ibv_context *ctx,
590 enum mlx5dv_flow_table_type ft_type,
591 void *ns, uint64_t flags,
595 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
596 #ifdef HAVE_MLX5DV_DR
599 return mlx5dv_dr_create_action_modify_header(ns, flags, actions_sz,
602 struct mlx5dv_flow_action_attr *action;
606 action = malloc(sizeof(*action));
609 action->type = MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION;
610 action->action = mlx5dv_create_flow_action_modify_header
611 (ctx, actions_sz, actions, ft_type);
626 mlx5_glue_dv_create_flow_action_packet_reformat
627 (struct ibv_context *ctx,
628 enum mlx5dv_flow_action_packet_reformat_type reformat_type,
629 enum mlx5dv_flow_table_type ft_type, struct mlx5dv_dr_ns *ns,
630 uint32_t flags, size_t data_sz, void *data)
632 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
633 #ifdef HAVE_MLX5DV_DR
636 return mlx5dv_dr_create_action_packet_reformat(ns, flags,
637 reformat_type, data_sz,
642 struct mlx5dv_flow_action_attr *action;
644 action = malloc(sizeof(*action));
647 action->type = MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION;
648 action->action = mlx5dv_create_flow_action_packet_reformat
649 (ctx, data_sz, data, reformat_type, ft_type);
665 mlx5_glue_dv_create_flow_action_tag(uint32_t tag)
667 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
668 #ifdef HAVE_MLX5DV_DR
669 return mlx5dv_dr_create_action_tag(tag);
671 struct mlx5dv_flow_action_attr *action;
672 action = malloc(sizeof(*action));
675 action->type = MLX5DV_FLOW_ACTION_TAG;
676 action->tag_value = tag;
685 mlx5_glue_dv_destroy_flow(void *flow_id)
687 #ifdef HAVE_MLX5DV_DR
688 return mlx5dv_dr_destroy_rule(flow_id);
690 return ibv_destroy_flow(flow_id);
695 mlx5_glue_dv_destroy_flow_matcher(void *matcher)
697 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
698 #ifdef HAVE_MLX5DV_DR
699 return mlx5dv_dr_destroy_matcher(matcher);
701 return mlx5dv_destroy_flow_matcher(matcher);
709 static struct ibv_context *
710 mlx5_glue_dv_open_device(struct ibv_device *device)
712 #ifdef HAVE_IBV_DEVX_OBJ
713 return mlx5dv_open_device(device,
714 &(struct mlx5dv_context_attr){
715 .flags = MLX5DV_CONTEXT_FLAGS_DEVX,
723 static struct mlx5dv_devx_obj *
724 mlx5_glue_devx_obj_create(struct ibv_context *ctx,
725 const void *in, size_t inlen,
726 void *out, size_t outlen)
728 #ifdef HAVE_IBV_DEVX_OBJ
729 return mlx5dv_devx_obj_create(ctx, in, inlen, out, outlen);
741 mlx5_glue_devx_obj_destroy(struct mlx5dv_devx_obj *obj)
743 #ifdef HAVE_IBV_DEVX_OBJ
744 return mlx5dv_devx_obj_destroy(obj);
752 mlx5_glue_devx_obj_query(struct mlx5dv_devx_obj *obj,
753 const void *in, size_t inlen,
754 void *out, size_t outlen)
756 #ifdef HAVE_IBV_DEVX_OBJ
757 return mlx5dv_devx_obj_query(obj, in, inlen, out, outlen);
769 mlx5_glue_devx_obj_modify(struct mlx5dv_devx_obj *obj,
770 const void *in, size_t inlen,
771 void *out, size_t outlen)
773 #ifdef HAVE_IBV_DEVX_OBJ
774 return mlx5dv_devx_obj_modify(obj, in, inlen, out, outlen);
786 mlx5_glue_devx_general_cmd(struct ibv_context *ctx,
787 const void *in, size_t inlen,
788 void *out, size_t outlen)
790 #ifdef HAVE_IBV_DEVX_OBJ
791 return mlx5dv_devx_general_cmd(ctx, in, inlen, out, outlen);
802 alignas(RTE_CACHE_LINE_SIZE)
803 const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue){
804 .version = MLX5_GLUE_VERSION,
805 .fork_init = mlx5_glue_fork_init,
806 .alloc_pd = mlx5_glue_alloc_pd,
807 .dealloc_pd = mlx5_glue_dealloc_pd,
808 .get_device_list = mlx5_glue_get_device_list,
809 .free_device_list = mlx5_glue_free_device_list,
810 .open_device = mlx5_glue_open_device,
811 .close_device = mlx5_glue_close_device,
812 .query_device = mlx5_glue_query_device,
813 .query_device_ex = mlx5_glue_query_device_ex,
814 .query_port = mlx5_glue_query_port,
815 .create_comp_channel = mlx5_glue_create_comp_channel,
816 .destroy_comp_channel = mlx5_glue_destroy_comp_channel,
817 .create_cq = mlx5_glue_create_cq,
818 .destroy_cq = mlx5_glue_destroy_cq,
819 .get_cq_event = mlx5_glue_get_cq_event,
820 .ack_cq_events = mlx5_glue_ack_cq_events,
821 .create_rwq_ind_table = mlx5_glue_create_rwq_ind_table,
822 .destroy_rwq_ind_table = mlx5_glue_destroy_rwq_ind_table,
823 .create_wq = mlx5_glue_create_wq,
824 .destroy_wq = mlx5_glue_destroy_wq,
825 .modify_wq = mlx5_glue_modify_wq,
826 .create_flow = mlx5_glue_create_flow,
827 .destroy_flow = mlx5_glue_destroy_flow,
828 .destroy_flow_action = mlx5_glue_destroy_flow_action,
829 .create_qp = mlx5_glue_create_qp,
830 .create_qp_ex = mlx5_glue_create_qp_ex,
831 .destroy_qp = mlx5_glue_destroy_qp,
832 .modify_qp = mlx5_glue_modify_qp,
833 .reg_mr = mlx5_glue_reg_mr,
834 .dereg_mr = mlx5_glue_dereg_mr,
835 .create_counter_set = mlx5_glue_create_counter_set,
836 .destroy_counter_set = mlx5_glue_destroy_counter_set,
837 .describe_counter_set = mlx5_glue_describe_counter_set,
838 .query_counter_set = mlx5_glue_query_counter_set,
839 .create_counters = mlx5_glue_create_counters,
840 .destroy_counters = mlx5_glue_destroy_counters,
841 .attach_counters = mlx5_glue_attach_counters,
842 .query_counters = mlx5_glue_query_counters,
843 .ack_async_event = mlx5_glue_ack_async_event,
844 .get_async_event = mlx5_glue_get_async_event,
845 .port_state_str = mlx5_glue_port_state_str,
846 .cq_ex_to_cq = mlx5_glue_cq_ex_to_cq,
847 .dr_create_flow_action_dest_flow_tbl =
848 mlx5_glue_dr_create_flow_action_dest_flow_tbl,
849 .dr_create_flow_tbl = mlx5_glue_dr_create_flow_tbl,
850 .dr_destroy_flow_tbl = mlx5_glue_dr_destroy_flow_tbl,
851 .dr_create_ns = mlx5_glue_dr_create_ns,
852 .dr_destroy_ns = mlx5_glue_dr_destroy_ns,
853 .dv_create_cq = mlx5_glue_dv_create_cq,
854 .dv_create_wq = mlx5_glue_dv_create_wq,
855 .dv_query_device = mlx5_glue_dv_query_device,
856 .dv_set_context_attr = mlx5_glue_dv_set_context_attr,
857 .dv_init_obj = mlx5_glue_dv_init_obj,
858 .dv_create_qp = mlx5_glue_dv_create_qp,
859 .dv_create_flow_matcher = mlx5_glue_dv_create_flow_matcher,
860 .dv_create_flow = mlx5_glue_dv_create_flow,
861 .dv_create_flow_action_counter =
862 mlx5_glue_dv_create_flow_action_counter,
863 .dv_create_flow_action_dest_ibv_qp =
864 mlx5_glue_dv_create_flow_action_dest_ibv_qp,
865 .dv_create_flow_action_modify_header =
866 mlx5_glue_dv_create_flow_action_modify_header,
867 .dv_create_flow_action_packet_reformat =
868 mlx5_glue_dv_create_flow_action_packet_reformat,
869 .dv_create_flow_action_tag = mlx5_glue_dv_create_flow_action_tag,
870 .dv_destroy_flow = mlx5_glue_dv_destroy_flow,
871 .dv_destroy_flow_matcher = mlx5_glue_dv_destroy_flow_matcher,
872 .dv_open_device = mlx5_glue_dv_open_device,
873 .devx_obj_create = mlx5_glue_devx_obj_create,
874 .devx_obj_destroy = mlx5_glue_devx_obj_destroy,
875 .devx_obj_query = mlx5_glue_devx_obj_query,
876 .devx_obj_modify = mlx5_glue_devx_obj_modify,
877 .devx_general_cmd = mlx5_glue_devx_general_cmd,