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_tbl(void *ns, uint32_t level)
375 #ifdef HAVE_MLX5DV_DR
376 return mlx5dv_dr_create_ft(ns, level);
385 mlx5_glue_dr_destroy_flow_tbl(void *tbl)
387 #ifdef HAVE_MLX5DV_DR
388 return mlx5dv_dr_destroy_ft(tbl);
396 mlx5_glue_dr_create_ns(struct ibv_context *ctx,
397 enum mlx5dv_dr_ns_domain domain)
399 #ifdef HAVE_MLX5DV_DR
400 return mlx5dv_dr_create_ns(ctx, domain);
409 mlx5_glue_dr_destroy_ns(void *ns)
411 #ifdef HAVE_MLX5DV_DR
412 return mlx5dv_dr_destroy_ns(ns);
419 static struct ibv_cq_ex *
420 mlx5_glue_dv_create_cq(struct ibv_context *context,
421 struct ibv_cq_init_attr_ex *cq_attr,
422 struct mlx5dv_cq_init_attr *mlx5_cq_attr)
424 return mlx5dv_create_cq(context, cq_attr, mlx5_cq_attr);
427 static struct ibv_wq *
428 mlx5_glue_dv_create_wq(struct ibv_context *context,
429 struct ibv_wq_init_attr *wq_attr,
430 struct mlx5dv_wq_init_attr *mlx5_wq_attr)
432 #ifndef HAVE_IBV_DEVICE_STRIDING_RQ_SUPPORT
438 return mlx5dv_create_wq(context, wq_attr, mlx5_wq_attr);
443 mlx5_glue_dv_query_device(struct ibv_context *ctx,
444 struct mlx5dv_context *attrs_out)
446 return mlx5dv_query_device(ctx, attrs_out);
450 mlx5_glue_dv_set_context_attr(struct ibv_context *ibv_ctx,
451 enum mlx5dv_set_ctx_attr_type type, void *attr)
453 return mlx5dv_set_context_attr(ibv_ctx, type, attr);
457 mlx5_glue_dv_init_obj(struct mlx5dv_obj *obj, uint64_t obj_type)
459 return mlx5dv_init_obj(obj, obj_type);
462 static struct ibv_qp *
463 mlx5_glue_dv_create_qp(struct ibv_context *context,
464 struct ibv_qp_init_attr_ex *qp_init_attr_ex,
465 struct mlx5dv_qp_init_attr *dv_qp_init_attr)
467 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
468 return mlx5dv_create_qp(context, qp_init_attr_ex, dv_qp_init_attr);
471 (void)qp_init_attr_ex;
472 (void)dv_qp_init_attr;
478 mlx5_glue_dv_create_flow_matcher(struct ibv_context *context,
479 struct mlx5dv_flow_matcher_attr *matcher_attr,
482 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
483 #ifdef HAVE_MLX5DV_DR
485 return mlx5dv_dr_create_matcher(tbl, matcher_attr->priority,
486 matcher_attr->match_criteria_enable,
487 matcher_attr->match_mask);
490 return mlx5dv_create_flow_matcher(context, matcher_attr);
501 mlx5_glue_dv_create_flow(void *matcher,
506 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
507 #ifdef HAVE_MLX5DV_DR
508 return mlx5dv_dr_create_rule(matcher, match_value, num_actions,
509 (struct mlx5dv_dr_action **)actions);
511 struct mlx5dv_flow_action_attr actions_attr[8];
515 for (size_t i = 0; i < num_actions; i++)
517 *((struct mlx5dv_flow_action_attr *)(actions[i]));
518 return mlx5dv_create_flow(matcher, match_value,
519 num_actions, actions_attr);
531 mlx5_glue_dv_create_flow_action_counter(void *counter_obj, uint32_t offset)
533 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
534 #ifdef HAVE_MLX5DV_DR
535 return mlx5dv_dr_create_action_devx_counter(counter_obj, offset);
537 struct mlx5dv_flow_action_attr *action;
540 action = malloc(sizeof(*action));
543 action->type = MLX5DV_FLOW_ACTION_COUNTERS_DEVX;
544 action->obj = counter_obj;
555 mlx5_glue_dv_create_flow_action_dest_ibv_qp(void *qp)
557 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
558 #ifdef HAVE_MLX5DV_DR
559 return mlx5dv_dr_create_action_dest_ibv_qp(qp);
561 struct mlx5dv_flow_action_attr *action;
563 action = malloc(sizeof(*action));
566 action->type = MLX5DV_FLOW_ACTION_DEST_IBV_QP;
577 mlx5_glue_dv_create_flow_action_modify_header
578 (struct ibv_context *ctx,
579 enum mlx5dv_flow_table_type ft_type,
580 void *ns, uint64_t flags,
584 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
585 #ifdef HAVE_MLX5DV_DR
588 return mlx5dv_dr_create_action_modify_header(ns, flags, actions_sz,
591 struct mlx5dv_flow_action_attr *action;
595 action = malloc(sizeof(*action));
598 action->type = MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION;
599 action->action = mlx5dv_create_flow_action_modify_header
600 (ctx, actions_sz, actions, ft_type);
615 mlx5_glue_dv_create_flow_action_packet_reformat
616 (struct ibv_context *ctx,
617 enum mlx5dv_flow_action_packet_reformat_type reformat_type,
618 enum mlx5dv_flow_table_type ft_type, struct mlx5dv_dr_ns *ns,
619 uint32_t flags, size_t data_sz, void *data)
621 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
622 #ifdef HAVE_MLX5DV_DR
625 return mlx5dv_dr_create_action_packet_reformat(ns, flags,
626 reformat_type, data_sz,
631 struct mlx5dv_flow_action_attr *action;
633 action = malloc(sizeof(*action));
636 action->type = MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION;
637 action->action = mlx5dv_create_flow_action_packet_reformat
638 (ctx, data_sz, data, reformat_type, ft_type);
654 mlx5_glue_dv_create_flow_action_tag(uint32_t tag)
656 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
657 #ifdef HAVE_MLX5DV_DR
658 return mlx5dv_dr_create_action_tag(tag);
660 struct mlx5dv_flow_action_attr *action;
661 action = malloc(sizeof(*action));
664 action->type = MLX5DV_FLOW_ACTION_TAG;
665 action->tag_value = tag;
674 mlx5_glue_dv_destroy_flow(void *flow_id)
676 #ifdef HAVE_MLX5DV_DR
677 return mlx5dv_dr_destroy_rule(flow_id);
679 return ibv_destroy_flow(flow_id);
684 mlx5_glue_dv_destroy_flow_matcher(void *matcher)
686 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
687 #ifdef HAVE_MLX5DV_DR
688 return mlx5dv_dr_destroy_matcher(matcher);
690 return mlx5dv_destroy_flow_matcher(matcher);
698 static struct ibv_context *
699 mlx5_glue_dv_open_device(struct ibv_device *device)
701 #ifdef HAVE_IBV_DEVX_OBJ
702 return mlx5dv_open_device(device,
703 &(struct mlx5dv_context_attr){
704 .flags = MLX5DV_CONTEXT_FLAGS_DEVX,
712 static struct mlx5dv_devx_obj *
713 mlx5_glue_devx_obj_create(struct ibv_context *ctx,
714 const void *in, size_t inlen,
715 void *out, size_t outlen)
717 #ifdef HAVE_IBV_DEVX_OBJ
718 return mlx5dv_devx_obj_create(ctx, in, inlen, out, outlen);
730 mlx5_glue_devx_obj_destroy(struct mlx5dv_devx_obj *obj)
732 #ifdef HAVE_IBV_DEVX_OBJ
733 return mlx5dv_devx_obj_destroy(obj);
741 mlx5_glue_devx_obj_query(struct mlx5dv_devx_obj *obj,
742 const void *in, size_t inlen,
743 void *out, size_t outlen)
745 #ifdef HAVE_IBV_DEVX_OBJ
746 return mlx5dv_devx_obj_query(obj, in, inlen, out, outlen);
758 mlx5_glue_devx_obj_modify(struct mlx5dv_devx_obj *obj,
759 const void *in, size_t inlen,
760 void *out, size_t outlen)
762 #ifdef HAVE_IBV_DEVX_OBJ
763 return mlx5dv_devx_obj_modify(obj, in, inlen, out, outlen);
775 mlx5_glue_devx_general_cmd(struct ibv_context *ctx,
776 const void *in, size_t inlen,
777 void *out, size_t outlen)
779 #ifdef HAVE_IBV_DEVX_OBJ
780 return mlx5dv_devx_general_cmd(ctx, in, inlen, out, outlen);
791 alignas(RTE_CACHE_LINE_SIZE)
792 const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue){
793 .version = MLX5_GLUE_VERSION,
794 .fork_init = mlx5_glue_fork_init,
795 .alloc_pd = mlx5_glue_alloc_pd,
796 .dealloc_pd = mlx5_glue_dealloc_pd,
797 .get_device_list = mlx5_glue_get_device_list,
798 .free_device_list = mlx5_glue_free_device_list,
799 .open_device = mlx5_glue_open_device,
800 .close_device = mlx5_glue_close_device,
801 .query_device = mlx5_glue_query_device,
802 .query_device_ex = mlx5_glue_query_device_ex,
803 .query_port = mlx5_glue_query_port,
804 .create_comp_channel = mlx5_glue_create_comp_channel,
805 .destroy_comp_channel = mlx5_glue_destroy_comp_channel,
806 .create_cq = mlx5_glue_create_cq,
807 .destroy_cq = mlx5_glue_destroy_cq,
808 .get_cq_event = mlx5_glue_get_cq_event,
809 .ack_cq_events = mlx5_glue_ack_cq_events,
810 .create_rwq_ind_table = mlx5_glue_create_rwq_ind_table,
811 .destroy_rwq_ind_table = mlx5_glue_destroy_rwq_ind_table,
812 .create_wq = mlx5_glue_create_wq,
813 .destroy_wq = mlx5_glue_destroy_wq,
814 .modify_wq = mlx5_glue_modify_wq,
815 .create_flow = mlx5_glue_create_flow,
816 .destroy_flow = mlx5_glue_destroy_flow,
817 .destroy_flow_action = mlx5_glue_destroy_flow_action,
818 .create_qp = mlx5_glue_create_qp,
819 .create_qp_ex = mlx5_glue_create_qp_ex,
820 .destroy_qp = mlx5_glue_destroy_qp,
821 .modify_qp = mlx5_glue_modify_qp,
822 .reg_mr = mlx5_glue_reg_mr,
823 .dereg_mr = mlx5_glue_dereg_mr,
824 .create_counter_set = mlx5_glue_create_counter_set,
825 .destroy_counter_set = mlx5_glue_destroy_counter_set,
826 .describe_counter_set = mlx5_glue_describe_counter_set,
827 .query_counter_set = mlx5_glue_query_counter_set,
828 .create_counters = mlx5_glue_create_counters,
829 .destroy_counters = mlx5_glue_destroy_counters,
830 .attach_counters = mlx5_glue_attach_counters,
831 .query_counters = mlx5_glue_query_counters,
832 .ack_async_event = mlx5_glue_ack_async_event,
833 .get_async_event = mlx5_glue_get_async_event,
834 .port_state_str = mlx5_glue_port_state_str,
835 .cq_ex_to_cq = mlx5_glue_cq_ex_to_cq,
836 .dr_create_flow_tbl = mlx5_glue_dr_create_flow_tbl,
837 .dr_destroy_flow_tbl = mlx5_glue_dr_destroy_flow_tbl,
838 .dr_create_ns = mlx5_glue_dr_create_ns,
839 .dr_destroy_ns = mlx5_glue_dr_destroy_ns,
840 .dv_create_cq = mlx5_glue_dv_create_cq,
841 .dv_create_wq = mlx5_glue_dv_create_wq,
842 .dv_query_device = mlx5_glue_dv_query_device,
843 .dv_set_context_attr = mlx5_glue_dv_set_context_attr,
844 .dv_init_obj = mlx5_glue_dv_init_obj,
845 .dv_create_qp = mlx5_glue_dv_create_qp,
846 .dv_create_flow_matcher = mlx5_glue_dv_create_flow_matcher,
847 .dv_create_flow = mlx5_glue_dv_create_flow,
848 .dv_create_flow_action_counter =
849 mlx5_glue_dv_create_flow_action_counter,
850 .dv_create_flow_action_dest_ibv_qp =
851 mlx5_glue_dv_create_flow_action_dest_ibv_qp,
852 .dv_create_flow_action_modify_header =
853 mlx5_glue_dv_create_flow_action_modify_header,
854 .dv_create_flow_action_packet_reformat =
855 mlx5_glue_dv_create_flow_action_packet_reformat,
856 .dv_create_flow_action_tag = mlx5_glue_dv_create_flow_action_tag,
857 .dv_destroy_flow = mlx5_glue_dv_destroy_flow,
858 .dv_destroy_flow_matcher = mlx5_glue_dv_destroy_flow_matcher,
859 .dv_open_device = mlx5_glue_dv_open_device,
860 .devx_obj_create = mlx5_glue_devx_obj_create,
861 .devx_obj_destroy = mlx5_glue_devx_obj_destroy,
862 .devx_obj_query = mlx5_glue_devx_obj_query,
863 .devx_obj_modify = mlx5_glue_devx_obj_modify,
864 .devx_general_cmd = mlx5_glue_devx_general_cmd,