1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018 6WIND S.A.
3 * Copyright 2018 Mellanox Technologies, Ltd
13 * Not needed by this file; included to work around the lack of off_t
14 * definition for mlx5dv.h with unpatched rdma-core versions.
16 #include <sys/types.h>
18 /* Verbs headers do not support -pedantic. */
20 #pragma GCC diagnostic ignored "-Wpedantic"
22 #include <infiniband/mlx5dv.h>
23 #include <infiniband/verbs.h>
25 #pragma GCC diagnostic error "-Wpedantic"
28 #include <rte_config.h>
30 #include "mlx5_autoconf.h"
31 #include "mlx5_glue.h"
34 mlx5_glue_fork_init(void)
36 return ibv_fork_init();
39 static struct ibv_pd *
40 mlx5_glue_alloc_pd(struct ibv_context *context)
42 return ibv_alloc_pd(context);
46 mlx5_glue_dealloc_pd(struct ibv_pd *pd)
48 return ibv_dealloc_pd(pd);
51 static struct ibv_device **
52 mlx5_glue_get_device_list(int *num_devices)
54 return ibv_get_device_list(num_devices);
58 mlx5_glue_free_device_list(struct ibv_device **list)
60 ibv_free_device_list(list);
63 static struct ibv_context *
64 mlx5_glue_open_device(struct ibv_device *device)
66 return ibv_open_device(device);
70 mlx5_glue_close_device(struct ibv_context *context)
72 return ibv_close_device(context);
76 mlx5_glue_query_device(struct ibv_context *context,
77 struct ibv_device_attr *device_attr)
79 return ibv_query_device(context, device_attr);
83 mlx5_glue_query_device_ex(struct ibv_context *context,
84 const struct ibv_query_device_ex_input *input,
85 struct ibv_device_attr_ex *attr)
87 return ibv_query_device_ex(context, input, attr);
91 mlx5_glue_query_rt_values_ex(struct ibv_context *context,
92 struct ibv_values_ex *values)
94 return ibv_query_rt_values_ex(context, values);
98 mlx5_glue_query_port(struct ibv_context *context, uint8_t port_num,
99 struct ibv_port_attr *port_attr)
101 return ibv_query_port(context, port_num, port_attr);
104 static struct ibv_comp_channel *
105 mlx5_glue_create_comp_channel(struct ibv_context *context)
107 return ibv_create_comp_channel(context);
111 mlx5_glue_destroy_comp_channel(struct ibv_comp_channel *channel)
113 return ibv_destroy_comp_channel(channel);
116 static struct ibv_cq *
117 mlx5_glue_create_cq(struct ibv_context *context, int cqe, void *cq_context,
118 struct ibv_comp_channel *channel, int comp_vector)
120 return ibv_create_cq(context, cqe, cq_context, channel, comp_vector);
124 mlx5_glue_destroy_cq(struct ibv_cq *cq)
126 return ibv_destroy_cq(cq);
130 mlx5_glue_get_cq_event(struct ibv_comp_channel *channel, struct ibv_cq **cq,
133 return ibv_get_cq_event(channel, cq, cq_context);
137 mlx5_glue_ack_cq_events(struct ibv_cq *cq, unsigned int nevents)
139 ibv_ack_cq_events(cq, nevents);
142 static struct ibv_rwq_ind_table *
143 mlx5_glue_create_rwq_ind_table(struct ibv_context *context,
144 struct ibv_rwq_ind_table_init_attr *init_attr)
146 return ibv_create_rwq_ind_table(context, init_attr);
150 mlx5_glue_destroy_rwq_ind_table(struct ibv_rwq_ind_table *rwq_ind_table)
152 return ibv_destroy_rwq_ind_table(rwq_ind_table);
155 static struct ibv_wq *
156 mlx5_glue_create_wq(struct ibv_context *context,
157 struct ibv_wq_init_attr *wq_init_attr)
159 return ibv_create_wq(context, wq_init_attr);
163 mlx5_glue_destroy_wq(struct ibv_wq *wq)
165 return ibv_destroy_wq(wq);
168 mlx5_glue_modify_wq(struct ibv_wq *wq, struct ibv_wq_attr *wq_attr)
170 return ibv_modify_wq(wq, wq_attr);
173 static struct ibv_flow *
174 mlx5_glue_create_flow(struct ibv_qp *qp, struct ibv_flow_attr *flow)
176 return ibv_create_flow(qp, flow);
180 mlx5_glue_destroy_flow(struct ibv_flow *flow_id)
182 return ibv_destroy_flow(flow_id);
186 mlx5_glue_destroy_flow_action(void *action)
188 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
189 #ifdef HAVE_MLX5DV_DR
190 return mlx5dv_dr_action_destroy(action);
192 struct mlx5dv_flow_action_attr *attr = action;
194 switch (attr->type) {
195 case MLX5DV_FLOW_ACTION_TAG:
198 res = ibv_destroy_flow_action(attr->action);
210 static struct ibv_qp *
211 mlx5_glue_create_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *qp_init_attr)
213 return ibv_create_qp(pd, qp_init_attr);
216 static struct ibv_qp *
217 mlx5_glue_create_qp_ex(struct ibv_context *context,
218 struct ibv_qp_init_attr_ex *qp_init_attr_ex)
220 return ibv_create_qp_ex(context, qp_init_attr_ex);
224 mlx5_glue_destroy_qp(struct ibv_qp *qp)
226 return ibv_destroy_qp(qp);
230 mlx5_glue_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, int attr_mask)
232 return ibv_modify_qp(qp, attr, attr_mask);
235 static struct ibv_mr *
236 mlx5_glue_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access)
238 return ibv_reg_mr(pd, addr, length, access);
242 mlx5_glue_dereg_mr(struct ibv_mr *mr)
244 return ibv_dereg_mr(mr);
247 static struct ibv_counter_set *
248 mlx5_glue_create_counter_set(struct ibv_context *context,
249 struct ibv_counter_set_init_attr *init_attr)
251 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
256 return ibv_create_counter_set(context, init_attr);
261 mlx5_glue_destroy_counter_set(struct ibv_counter_set *cs)
263 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
267 return ibv_destroy_counter_set(cs);
272 mlx5_glue_describe_counter_set(struct ibv_context *context,
273 uint16_t counter_set_id,
274 struct ibv_counter_set_description *cs_desc)
276 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
278 (void)counter_set_id;
282 return ibv_describe_counter_set(context, counter_set_id, cs_desc);
287 mlx5_glue_query_counter_set(struct ibv_query_counter_set_attr *query_attr,
288 struct ibv_counter_set_data *cs_data)
290 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
295 return ibv_query_counter_set(query_attr, cs_data);
299 static struct ibv_counters *
300 mlx5_glue_create_counters(struct ibv_context *context,
301 struct ibv_counters_init_attr *init_attr)
303 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
309 return ibv_create_counters(context, init_attr);
314 mlx5_glue_destroy_counters(struct ibv_counters *counters)
316 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
320 return ibv_destroy_counters(counters);
325 mlx5_glue_attach_counters(struct ibv_counters *counters,
326 struct ibv_counter_attach_attr *attr,
327 struct ibv_flow *flow)
329 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
335 return ibv_attach_counters_point_flow(counters, attr, flow);
340 mlx5_glue_query_counters(struct ibv_counters *counters,
341 uint64_t *counters_value,
345 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
347 (void)counters_value;
352 return ibv_read_counters(counters, counters_value, ncounters, flags);
357 mlx5_glue_ack_async_event(struct ibv_async_event *event)
359 ibv_ack_async_event(event);
363 mlx5_glue_get_async_event(struct ibv_context *context,
364 struct ibv_async_event *event)
366 return ibv_get_async_event(context, event);
370 mlx5_glue_port_state_str(enum ibv_port_state port_state)
372 return ibv_port_state_str(port_state);
375 static struct ibv_cq *
376 mlx5_glue_cq_ex_to_cq(struct ibv_cq_ex *cq)
378 return ibv_cq_ex_to_cq(cq);
382 mlx5_glue_dr_create_flow_action_dest_flow_tbl(void *tbl)
384 #ifdef HAVE_MLX5DV_DR
385 return mlx5dv_dr_action_create_dest_table(tbl);
394 mlx5_glue_dr_create_flow_action_dest_vport(void *domain, uint32_t vport)
396 #ifdef HAVE_MLX5DV_DR_ESWITCH
397 return mlx5dv_dr_action_create_dest_vport(domain, vport);
407 mlx5_glue_dr_create_flow_action_drop(void)
409 #ifdef HAVE_MLX5DV_DR_ESWITCH
410 return mlx5dv_dr_action_create_drop();
418 mlx5_glue_dr_create_flow_tbl(void *domain, uint32_t level)
420 #ifdef HAVE_MLX5DV_DR
421 return mlx5dv_dr_table_create(domain, level);
431 mlx5_glue_dr_destroy_flow_tbl(void *tbl)
433 #ifdef HAVE_MLX5DV_DR
434 return mlx5dv_dr_table_destroy(tbl);
443 mlx5_glue_dr_create_domain(struct ibv_context *ctx,
444 enum mlx5dv_dr_domain_type domain)
446 #ifdef HAVE_MLX5DV_DR
447 return mlx5dv_dr_domain_create(ctx, domain);
457 mlx5_glue_dr_destroy_domain(void *domain)
459 #ifdef HAVE_MLX5DV_DR
460 return mlx5dv_dr_domain_destroy(domain);
468 static struct ibv_cq_ex *
469 mlx5_glue_dv_create_cq(struct ibv_context *context,
470 struct ibv_cq_init_attr_ex *cq_attr,
471 struct mlx5dv_cq_init_attr *mlx5_cq_attr)
473 return mlx5dv_create_cq(context, cq_attr, mlx5_cq_attr);
476 static struct ibv_wq *
477 mlx5_glue_dv_create_wq(struct ibv_context *context,
478 struct ibv_wq_init_attr *wq_attr,
479 struct mlx5dv_wq_init_attr *mlx5_wq_attr)
481 #ifndef HAVE_IBV_DEVICE_STRIDING_RQ_SUPPORT
488 return mlx5dv_create_wq(context, wq_attr, mlx5_wq_attr);
493 mlx5_glue_dv_query_device(struct ibv_context *ctx,
494 struct mlx5dv_context *attrs_out)
496 return mlx5dv_query_device(ctx, attrs_out);
500 mlx5_glue_dv_set_context_attr(struct ibv_context *ibv_ctx,
501 enum mlx5dv_set_ctx_attr_type type, void *attr)
503 return mlx5dv_set_context_attr(ibv_ctx, type, attr);
507 mlx5_glue_dv_init_obj(struct mlx5dv_obj *obj, uint64_t obj_type)
509 return mlx5dv_init_obj(obj, obj_type);
512 static struct ibv_qp *
513 mlx5_glue_dv_create_qp(struct ibv_context *context,
514 struct ibv_qp_init_attr_ex *qp_init_attr_ex,
515 struct mlx5dv_qp_init_attr *dv_qp_init_attr)
517 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
518 return mlx5dv_create_qp(context, qp_init_attr_ex, dv_qp_init_attr);
521 (void)qp_init_attr_ex;
522 (void)dv_qp_init_attr;
529 mlx5_glue_dv_create_flow_matcher(struct ibv_context *context,
530 struct mlx5dv_flow_matcher_attr *matcher_attr,
533 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
534 #ifdef HAVE_MLX5DV_DR
536 return mlx5dv_dr_matcher_create(tbl, matcher_attr->priority,
537 matcher_attr->match_criteria_enable,
538 matcher_attr->match_mask);
541 return mlx5dv_create_flow_matcher(context, matcher_attr);
553 mlx5_glue_dv_create_flow(void *matcher,
558 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
559 #ifdef HAVE_MLX5DV_DR
560 return mlx5dv_dr_rule_create(matcher, match_value, num_actions,
561 (struct mlx5dv_dr_action **)actions);
563 struct mlx5dv_flow_action_attr actions_attr[8];
567 for (size_t i = 0; i < num_actions; i++)
569 *((struct mlx5dv_flow_action_attr *)(actions[i]));
570 return mlx5dv_create_flow(matcher, match_value,
571 num_actions, actions_attr);
583 mlx5_glue_dv_create_flow_action_counter(void *counter_obj, uint32_t offset)
585 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
586 #ifdef HAVE_MLX5DV_DR
587 return mlx5dv_dr_action_create_flow_counter(counter_obj, offset);
589 struct mlx5dv_flow_action_attr *action;
592 action = malloc(sizeof(*action));
595 action->type = MLX5DV_FLOW_ACTION_COUNTERS_DEVX;
596 action->obj = counter_obj;
608 mlx5_glue_dv_create_flow_action_dest_ibv_qp(void *qp)
610 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
611 #ifdef HAVE_MLX5DV_DR
612 return mlx5dv_dr_action_create_dest_ibv_qp(qp);
614 struct mlx5dv_flow_action_attr *action;
616 action = malloc(sizeof(*action));
619 action->type = MLX5DV_FLOW_ACTION_DEST_IBV_QP;
631 mlx5_glue_dv_create_flow_action_modify_header
632 (struct ibv_context *ctx,
633 enum mlx5dv_flow_table_type ft_type,
634 void *domain, uint64_t flags,
638 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
639 #ifdef HAVE_MLX5DV_DR
642 return mlx5dv_dr_action_create_modify_header(domain, flags, actions_sz,
645 struct mlx5dv_flow_action_attr *action;
649 action = malloc(sizeof(*action));
652 action->type = MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION;
653 action->action = mlx5dv_create_flow_action_modify_header
654 (ctx, actions_sz, actions, ft_type);
670 mlx5_glue_dv_create_flow_action_packet_reformat
671 (struct ibv_context *ctx,
672 enum mlx5dv_flow_action_packet_reformat_type reformat_type,
673 enum mlx5dv_flow_table_type ft_type,
674 struct mlx5dv_dr_domain *domain,
675 uint32_t flags, size_t data_sz, void *data)
677 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
678 #ifdef HAVE_MLX5DV_DR
681 return mlx5dv_dr_action_create_packet_reformat(domain, flags,
682 reformat_type, data_sz,
687 struct mlx5dv_flow_action_attr *action;
689 action = malloc(sizeof(*action));
692 action->type = MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION;
693 action->action = mlx5dv_create_flow_action_packet_reformat
694 (ctx, data_sz, data, reformat_type, ft_type);
711 mlx5_glue_dv_create_flow_action_tag(uint32_t tag)
713 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
714 #ifdef HAVE_MLX5DV_DR
715 return mlx5dv_dr_action_create_tag(tag);
717 struct mlx5dv_flow_action_attr *action;
718 action = malloc(sizeof(*action));
721 action->type = MLX5DV_FLOW_ACTION_TAG;
722 action->tag_value = tag;
732 mlx5_glue_dv_destroy_flow(void *flow_id)
734 #ifdef HAVE_MLX5DV_DR
735 return mlx5dv_dr_rule_destroy(flow_id);
737 return ibv_destroy_flow(flow_id);
742 mlx5_glue_dv_destroy_flow_matcher(void *matcher)
744 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
745 #ifdef HAVE_MLX5DV_DR
746 return mlx5dv_dr_matcher_destroy(matcher);
748 return mlx5dv_destroy_flow_matcher(matcher);
757 static struct ibv_context *
758 mlx5_glue_dv_open_device(struct ibv_device *device)
760 #ifdef HAVE_IBV_DEVX_OBJ
761 return mlx5dv_open_device(device,
762 &(struct mlx5dv_context_attr){
763 .flags = MLX5DV_CONTEXT_FLAGS_DEVX,
772 static struct mlx5dv_devx_obj *
773 mlx5_glue_devx_obj_create(struct ibv_context *ctx,
774 const void *in, size_t inlen,
775 void *out, size_t outlen)
777 #ifdef HAVE_IBV_DEVX_OBJ
778 return mlx5dv_devx_obj_create(ctx, in, inlen, out, outlen);
791 mlx5_glue_devx_obj_destroy(struct mlx5dv_devx_obj *obj)
793 #ifdef HAVE_IBV_DEVX_OBJ
794 return mlx5dv_devx_obj_destroy(obj);
802 mlx5_glue_devx_obj_query(struct mlx5dv_devx_obj *obj,
803 const void *in, size_t inlen,
804 void *out, size_t outlen)
806 #ifdef HAVE_IBV_DEVX_OBJ
807 return mlx5dv_devx_obj_query(obj, in, inlen, out, outlen);
819 mlx5_glue_devx_obj_modify(struct mlx5dv_devx_obj *obj,
820 const void *in, size_t inlen,
821 void *out, size_t outlen)
823 #ifdef HAVE_IBV_DEVX_OBJ
824 return mlx5dv_devx_obj_modify(obj, in, inlen, out, outlen);
836 mlx5_glue_devx_general_cmd(struct ibv_context *ctx,
837 const void *in, size_t inlen,
838 void *out, size_t outlen)
840 #ifdef HAVE_IBV_DEVX_OBJ
841 return mlx5dv_devx_general_cmd(ctx, in, inlen, out, outlen);
852 alignas(RTE_CACHE_LINE_SIZE)
853 const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue){
854 .version = MLX5_GLUE_VERSION,
855 .fork_init = mlx5_glue_fork_init,
856 .alloc_pd = mlx5_glue_alloc_pd,
857 .dealloc_pd = mlx5_glue_dealloc_pd,
858 .get_device_list = mlx5_glue_get_device_list,
859 .free_device_list = mlx5_glue_free_device_list,
860 .open_device = mlx5_glue_open_device,
861 .close_device = mlx5_glue_close_device,
862 .query_device = mlx5_glue_query_device,
863 .query_device_ex = mlx5_glue_query_device_ex,
864 .query_rt_values_ex = mlx5_glue_query_rt_values_ex,
865 .query_port = mlx5_glue_query_port,
866 .create_comp_channel = mlx5_glue_create_comp_channel,
867 .destroy_comp_channel = mlx5_glue_destroy_comp_channel,
868 .create_cq = mlx5_glue_create_cq,
869 .destroy_cq = mlx5_glue_destroy_cq,
870 .get_cq_event = mlx5_glue_get_cq_event,
871 .ack_cq_events = mlx5_glue_ack_cq_events,
872 .create_rwq_ind_table = mlx5_glue_create_rwq_ind_table,
873 .destroy_rwq_ind_table = mlx5_glue_destroy_rwq_ind_table,
874 .create_wq = mlx5_glue_create_wq,
875 .destroy_wq = mlx5_glue_destroy_wq,
876 .modify_wq = mlx5_glue_modify_wq,
877 .create_flow = mlx5_glue_create_flow,
878 .destroy_flow = mlx5_glue_destroy_flow,
879 .destroy_flow_action = mlx5_glue_destroy_flow_action,
880 .create_qp = mlx5_glue_create_qp,
881 .create_qp_ex = mlx5_glue_create_qp_ex,
882 .destroy_qp = mlx5_glue_destroy_qp,
883 .modify_qp = mlx5_glue_modify_qp,
884 .reg_mr = mlx5_glue_reg_mr,
885 .dereg_mr = mlx5_glue_dereg_mr,
886 .create_counter_set = mlx5_glue_create_counter_set,
887 .destroy_counter_set = mlx5_glue_destroy_counter_set,
888 .describe_counter_set = mlx5_glue_describe_counter_set,
889 .query_counter_set = mlx5_glue_query_counter_set,
890 .create_counters = mlx5_glue_create_counters,
891 .destroy_counters = mlx5_glue_destroy_counters,
892 .attach_counters = mlx5_glue_attach_counters,
893 .query_counters = mlx5_glue_query_counters,
894 .ack_async_event = mlx5_glue_ack_async_event,
895 .get_async_event = mlx5_glue_get_async_event,
896 .port_state_str = mlx5_glue_port_state_str,
897 .cq_ex_to_cq = mlx5_glue_cq_ex_to_cq,
898 .dr_create_flow_action_dest_flow_tbl =
899 mlx5_glue_dr_create_flow_action_dest_flow_tbl,
900 .dr_create_flow_action_dest_vport =
901 mlx5_glue_dr_create_flow_action_dest_vport,
902 .dr_create_flow_action_drop =
903 mlx5_glue_dr_create_flow_action_drop,
904 .dr_create_flow_tbl = mlx5_glue_dr_create_flow_tbl,
905 .dr_destroy_flow_tbl = mlx5_glue_dr_destroy_flow_tbl,
906 .dr_create_domain = mlx5_glue_dr_create_domain,
907 .dr_destroy_domain = mlx5_glue_dr_destroy_domain,
908 .dv_create_cq = mlx5_glue_dv_create_cq,
909 .dv_create_wq = mlx5_glue_dv_create_wq,
910 .dv_query_device = mlx5_glue_dv_query_device,
911 .dv_set_context_attr = mlx5_glue_dv_set_context_attr,
912 .dv_init_obj = mlx5_glue_dv_init_obj,
913 .dv_create_qp = mlx5_glue_dv_create_qp,
914 .dv_create_flow_matcher = mlx5_glue_dv_create_flow_matcher,
915 .dv_create_flow = mlx5_glue_dv_create_flow,
916 .dv_create_flow_action_counter =
917 mlx5_glue_dv_create_flow_action_counter,
918 .dv_create_flow_action_dest_ibv_qp =
919 mlx5_glue_dv_create_flow_action_dest_ibv_qp,
920 .dv_create_flow_action_modify_header =
921 mlx5_glue_dv_create_flow_action_modify_header,
922 .dv_create_flow_action_packet_reformat =
923 mlx5_glue_dv_create_flow_action_packet_reformat,
924 .dv_create_flow_action_tag = mlx5_glue_dv_create_flow_action_tag,
925 .dv_destroy_flow = mlx5_glue_dv_destroy_flow,
926 .dv_destroy_flow_matcher = mlx5_glue_dv_destroy_flow_matcher,
927 .dv_open_device = mlx5_glue_dv_open_device,
928 .devx_obj_create = mlx5_glue_devx_obj_create,
929 .devx_obj_destroy = mlx5_glue_devx_obj_destroy,
930 .devx_obj_query = mlx5_glue_devx_obj_query,
931 .devx_obj_modify = mlx5_glue_devx_obj_modify,
932 .devx_general_cmd = mlx5_glue_devx_general_cmd,