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(struct ibv_flow_action *action)
180 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
181 return ibv_destroy_flow_action(action);
188 static struct ibv_qp *
189 mlx5_glue_create_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *qp_init_attr)
191 return ibv_create_qp(pd, qp_init_attr);
194 static struct ibv_qp *
195 mlx5_glue_create_qp_ex(struct ibv_context *context,
196 struct ibv_qp_init_attr_ex *qp_init_attr_ex)
198 return ibv_create_qp_ex(context, qp_init_attr_ex);
202 mlx5_glue_destroy_qp(struct ibv_qp *qp)
204 return ibv_destroy_qp(qp);
208 mlx5_glue_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, int attr_mask)
210 return ibv_modify_qp(qp, attr, attr_mask);
213 static struct ibv_mr *
214 mlx5_glue_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access)
216 return ibv_reg_mr(pd, addr, length, access);
220 mlx5_glue_dereg_mr(struct ibv_mr *mr)
222 return ibv_dereg_mr(mr);
225 static struct ibv_counter_set *
226 mlx5_glue_create_counter_set(struct ibv_context *context,
227 struct ibv_counter_set_init_attr *init_attr)
229 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
234 return ibv_create_counter_set(context, init_attr);
239 mlx5_glue_destroy_counter_set(struct ibv_counter_set *cs)
241 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
245 return ibv_destroy_counter_set(cs);
250 mlx5_glue_describe_counter_set(struct ibv_context *context,
251 uint16_t counter_set_id,
252 struct ibv_counter_set_description *cs_desc)
254 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
256 (void)counter_set_id;
260 return ibv_describe_counter_set(context, counter_set_id, cs_desc);
265 mlx5_glue_query_counter_set(struct ibv_query_counter_set_attr *query_attr,
266 struct ibv_counter_set_data *cs_data)
268 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
273 return ibv_query_counter_set(query_attr, cs_data);
277 static struct ibv_counters *
278 mlx5_glue_create_counters(struct ibv_context *context,
279 struct ibv_counters_init_attr *init_attr)
281 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
286 return ibv_create_counters(context, init_attr);
291 mlx5_glue_destroy_counters(struct ibv_counters *counters)
293 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
297 return ibv_destroy_counters(counters);
302 mlx5_glue_attach_counters(struct ibv_counters *counters,
303 struct ibv_counter_attach_attr *attr,
304 struct ibv_flow *flow)
306 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
312 return ibv_attach_counters_point_flow(counters, attr, flow);
317 mlx5_glue_query_counters(struct ibv_counters *counters,
318 uint64_t *counters_value,
322 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
324 (void)counters_value;
329 return ibv_read_counters(counters, counters_value, ncounters, flags);
334 mlx5_glue_ack_async_event(struct ibv_async_event *event)
336 ibv_ack_async_event(event);
340 mlx5_glue_get_async_event(struct ibv_context *context,
341 struct ibv_async_event *event)
343 return ibv_get_async_event(context, event);
347 mlx5_glue_port_state_str(enum ibv_port_state port_state)
349 return ibv_port_state_str(port_state);
352 static struct ibv_cq *
353 mlx5_glue_cq_ex_to_cq(struct ibv_cq_ex *cq)
355 return ibv_cq_ex_to_cq(cq);
358 static struct ibv_cq_ex *
359 mlx5_glue_dv_create_cq(struct ibv_context *context,
360 struct ibv_cq_init_attr_ex *cq_attr,
361 struct mlx5dv_cq_init_attr *mlx5_cq_attr)
363 return mlx5dv_create_cq(context, cq_attr, mlx5_cq_attr);
366 static struct ibv_wq *
367 mlx5_glue_dv_create_wq(struct ibv_context *context,
368 struct ibv_wq_init_attr *wq_attr,
369 struct mlx5dv_wq_init_attr *mlx5_wq_attr)
371 #ifndef HAVE_IBV_DEVICE_STRIDING_RQ_SUPPORT
377 return mlx5dv_create_wq(context, wq_attr, mlx5_wq_attr);
382 mlx5_glue_dv_query_device(struct ibv_context *ctx,
383 struct mlx5dv_context *attrs_out)
385 return mlx5dv_query_device(ctx, attrs_out);
389 mlx5_glue_dv_set_context_attr(struct ibv_context *ibv_ctx,
390 enum mlx5dv_set_ctx_attr_type type, void *attr)
392 return mlx5dv_set_context_attr(ibv_ctx, type, attr);
396 mlx5_glue_dv_init_obj(struct mlx5dv_obj *obj, uint64_t obj_type)
398 return mlx5dv_init_obj(obj, obj_type);
401 static struct ibv_qp *
402 mlx5_glue_dv_create_qp(struct ibv_context *context,
403 struct ibv_qp_init_attr_ex *qp_init_attr_ex,
404 struct mlx5dv_qp_init_attr *dv_qp_init_attr)
406 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
407 return mlx5dv_create_qp(context, qp_init_attr_ex, dv_qp_init_attr);
410 (void)qp_init_attr_ex;
411 (void)dv_qp_init_attr;
416 static struct mlx5dv_flow_matcher *
417 mlx5_glue_dv_create_flow_matcher(struct ibv_context *context,
418 struct mlx5dv_flow_matcher_attr *matcher_attr)
420 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
421 return mlx5dv_create_flow_matcher(context, matcher_attr);
429 static struct ibv_flow *
430 mlx5_glue_dv_create_flow(struct mlx5dv_flow_matcher *matcher,
431 struct mlx5dv_flow_match_parameters *match_value,
433 struct mlx5dv_flow_action_attr *actions_attr)
435 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
436 return mlx5dv_create_flow(matcher, match_value,
437 num_actions, actions_attr);
448 mlx5_glue_dv_destroy_flow_matcher(struct mlx5dv_flow_matcher *matcher)
450 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
451 return mlx5dv_destroy_flow_matcher(matcher);
458 static struct ibv_flow_action *
459 mlx5_glue_dv_create_flow_action_packet_reformat
460 (struct ibv_context *ctx,
463 enum mlx5dv_flow_action_packet_reformat_type reformat_type,
464 enum mlx5dv_flow_table_type ft_type)
466 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
467 return mlx5dv_create_flow_action_packet_reformat(ctx,
482 alignas(RTE_CACHE_LINE_SIZE)
483 const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue){
484 .version = MLX5_GLUE_VERSION,
485 .fork_init = mlx5_glue_fork_init,
486 .alloc_pd = mlx5_glue_alloc_pd,
487 .dealloc_pd = mlx5_glue_dealloc_pd,
488 .get_device_list = mlx5_glue_get_device_list,
489 .free_device_list = mlx5_glue_free_device_list,
490 .open_device = mlx5_glue_open_device,
491 .close_device = mlx5_glue_close_device,
492 .query_device = mlx5_glue_query_device,
493 .query_device_ex = mlx5_glue_query_device_ex,
494 .query_port = mlx5_glue_query_port,
495 .create_comp_channel = mlx5_glue_create_comp_channel,
496 .destroy_comp_channel = mlx5_glue_destroy_comp_channel,
497 .create_cq = mlx5_glue_create_cq,
498 .destroy_cq = mlx5_glue_destroy_cq,
499 .get_cq_event = mlx5_glue_get_cq_event,
500 .ack_cq_events = mlx5_glue_ack_cq_events,
501 .create_rwq_ind_table = mlx5_glue_create_rwq_ind_table,
502 .destroy_rwq_ind_table = mlx5_glue_destroy_rwq_ind_table,
503 .create_wq = mlx5_glue_create_wq,
504 .destroy_wq = mlx5_glue_destroy_wq,
505 .modify_wq = mlx5_glue_modify_wq,
506 .create_flow = mlx5_glue_create_flow,
507 .destroy_flow = mlx5_glue_destroy_flow,
508 .destroy_flow_action = mlx5_glue_destroy_flow_action,
509 .create_qp = mlx5_glue_create_qp,
510 .create_qp_ex = mlx5_glue_create_qp_ex,
511 .destroy_qp = mlx5_glue_destroy_qp,
512 .modify_qp = mlx5_glue_modify_qp,
513 .reg_mr = mlx5_glue_reg_mr,
514 .dereg_mr = mlx5_glue_dereg_mr,
515 .create_counter_set = mlx5_glue_create_counter_set,
516 .destroy_counter_set = mlx5_glue_destroy_counter_set,
517 .describe_counter_set = mlx5_glue_describe_counter_set,
518 .query_counter_set = mlx5_glue_query_counter_set,
519 .create_counters = mlx5_glue_create_counters,
520 .destroy_counters = mlx5_glue_destroy_counters,
521 .attach_counters = mlx5_glue_attach_counters,
522 .query_counters = mlx5_glue_query_counters,
523 .ack_async_event = mlx5_glue_ack_async_event,
524 .get_async_event = mlx5_glue_get_async_event,
525 .port_state_str = mlx5_glue_port_state_str,
526 .cq_ex_to_cq = mlx5_glue_cq_ex_to_cq,
527 .dv_create_cq = mlx5_glue_dv_create_cq,
528 .dv_create_wq = mlx5_glue_dv_create_wq,
529 .dv_query_device = mlx5_glue_dv_query_device,
530 .dv_set_context_attr = mlx5_glue_dv_set_context_attr,
531 .dv_init_obj = mlx5_glue_dv_init_obj,
532 .dv_create_qp = mlx5_glue_dv_create_qp,
533 .dv_create_flow_matcher = mlx5_glue_dv_create_flow_matcher,
534 .dv_destroy_flow_matcher = mlx5_glue_dv_destroy_flow_matcher,
535 .dv_create_flow = mlx5_glue_dv_create_flow,
536 .dv_create_flow_action_packet_reformat =
537 mlx5_glue_dv_create_flow_action_packet_reformat,