1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018 6WIND S.A.
3 * Copyright 2018 Mellanox Technologies, Ltd.
10 /* Verbs headers do not support -pedantic. */
12 #pragma GCC diagnostic ignored "-Wpedantic"
14 #include <infiniband/mlx5dv.h>
15 #include <infiniband/verbs.h>
17 #pragma GCC diagnostic error "-Wpedantic"
20 #include "mlx5_autoconf.h"
21 #include "mlx5_glue.h"
24 mlx5_glue_fork_init(void)
26 return ibv_fork_init();
29 static struct ibv_pd *
30 mlx5_glue_alloc_pd(struct ibv_context *context)
32 return ibv_alloc_pd(context);
36 mlx5_glue_dealloc_pd(struct ibv_pd *pd)
38 return ibv_dealloc_pd(pd);
41 static struct ibv_device **
42 mlx5_glue_get_device_list(int *num_devices)
44 return ibv_get_device_list(num_devices);
48 mlx5_glue_free_device_list(struct ibv_device **list)
50 ibv_free_device_list(list);
53 static struct ibv_context *
54 mlx5_glue_open_device(struct ibv_device *device)
56 return ibv_open_device(device);
60 mlx5_glue_close_device(struct ibv_context *context)
62 return ibv_close_device(context);
66 mlx5_glue_query_device(struct ibv_context *context,
67 struct ibv_device_attr *device_attr)
69 return ibv_query_device(context, device_attr);
73 mlx5_glue_query_device_ex(struct ibv_context *context,
74 const struct ibv_query_device_ex_input *input,
75 struct ibv_device_attr_ex *attr)
77 return ibv_query_device_ex(context, input, attr);
81 mlx5_glue_query_port(struct ibv_context *context, uint8_t port_num,
82 struct ibv_port_attr *port_attr)
84 return ibv_query_port(context, port_num, port_attr);
87 static struct ibv_comp_channel *
88 mlx5_glue_create_comp_channel(struct ibv_context *context)
90 return ibv_create_comp_channel(context);
94 mlx5_glue_destroy_comp_channel(struct ibv_comp_channel *channel)
96 return ibv_destroy_comp_channel(channel);
99 static struct ibv_cq *
100 mlx5_glue_create_cq(struct ibv_context *context, int cqe, void *cq_context,
101 struct ibv_comp_channel *channel, int comp_vector)
103 return ibv_create_cq(context, cqe, cq_context, channel, comp_vector);
107 mlx5_glue_destroy_cq(struct ibv_cq *cq)
109 return ibv_destroy_cq(cq);
113 mlx5_glue_get_cq_event(struct ibv_comp_channel *channel, struct ibv_cq **cq,
116 return ibv_get_cq_event(channel, cq, cq_context);
120 mlx5_glue_ack_cq_events(struct ibv_cq *cq, unsigned int nevents)
122 ibv_ack_cq_events(cq, nevents);
125 static struct ibv_rwq_ind_table *
126 mlx5_glue_create_rwq_ind_table(struct ibv_context *context,
127 struct ibv_rwq_ind_table_init_attr *init_attr)
129 return ibv_create_rwq_ind_table(context, init_attr);
133 mlx5_glue_destroy_rwq_ind_table(struct ibv_rwq_ind_table *rwq_ind_table)
135 return ibv_destroy_rwq_ind_table(rwq_ind_table);
138 static struct ibv_wq *
139 mlx5_glue_create_wq(struct ibv_context *context,
140 struct ibv_wq_init_attr *wq_init_attr)
142 return ibv_create_wq(context, wq_init_attr);
146 mlx5_glue_destroy_wq(struct ibv_wq *wq)
148 return ibv_destroy_wq(wq);
151 mlx5_glue_modify_wq(struct ibv_wq *wq, struct ibv_wq_attr *wq_attr)
153 return ibv_modify_wq(wq, wq_attr);
156 static struct ibv_flow *
157 mlx5_glue_create_flow(struct ibv_qp *qp, struct ibv_flow_attr *flow)
159 return ibv_create_flow(qp, flow);
163 mlx5_glue_destroy_flow(struct ibv_flow *flow_id)
165 return ibv_destroy_flow(flow_id);
168 static struct ibv_qp *
169 mlx5_glue_create_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *qp_init_attr)
171 return ibv_create_qp(pd, qp_init_attr);
174 static struct ibv_qp *
175 mlx5_glue_create_qp_ex(struct ibv_context *context,
176 struct ibv_qp_init_attr_ex *qp_init_attr_ex)
178 return ibv_create_qp_ex(context, qp_init_attr_ex);
182 mlx5_glue_destroy_qp(struct ibv_qp *qp)
184 return ibv_destroy_qp(qp);
188 mlx5_glue_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, int attr_mask)
190 return ibv_modify_qp(qp, attr, attr_mask);
193 static struct ibv_mr *
194 mlx5_glue_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access)
196 return ibv_reg_mr(pd, addr, length, access);
200 mlx5_glue_dereg_mr(struct ibv_mr *mr)
202 return ibv_dereg_mr(mr);
205 static struct ibv_counter_set *
206 mlx5_glue_create_counter_set(struct ibv_context *context,
207 struct ibv_counter_set_init_attr *init_attr)
209 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT
214 return ibv_create_counter_set(context, init_attr);
219 mlx5_glue_destroy_counter_set(struct ibv_counter_set *cs)
221 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT
225 return ibv_destroy_counter_set(cs);
230 mlx5_glue_describe_counter_set(struct ibv_context *context,
231 uint16_t counter_set_id,
232 struct ibv_counter_set_description *cs_desc)
234 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT
236 (void)counter_set_id;
240 return ibv_describe_counter_set(context, counter_set_id, cs_desc);
245 mlx5_glue_query_counter_set(struct ibv_query_counter_set_attr *query_attr,
246 struct ibv_counter_set_data *cs_data)
248 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT
253 return ibv_query_counter_set(query_attr, cs_data);
258 mlx5_glue_ack_async_event(struct ibv_async_event *event)
260 ibv_ack_async_event(event);
264 mlx5_glue_get_async_event(struct ibv_context *context,
265 struct ibv_async_event *event)
267 return ibv_get_async_event(context, event);
271 mlx5_glue_port_state_str(enum ibv_port_state port_state)
273 return ibv_port_state_str(port_state);
276 static struct ibv_cq *
277 mlx5_glue_cq_ex_to_cq(struct ibv_cq_ex *cq)
279 return ibv_cq_ex_to_cq(cq);
282 static struct ibv_cq_ex *
283 mlx5_glue_dv_create_cq(struct ibv_context *context,
284 struct ibv_cq_init_attr_ex *cq_attr,
285 struct mlx5dv_cq_init_attr *mlx5_cq_attr)
287 return mlx5dv_create_cq(context, cq_attr, mlx5_cq_attr);
291 mlx5_glue_dv_query_device(struct ibv_context *ctx,
292 struct mlx5dv_context *attrs_out)
294 return mlx5dv_query_device(ctx, attrs_out);
298 mlx5_glue_dv_set_context_attr(struct ibv_context *ibv_ctx,
299 enum mlx5dv_set_ctx_attr_type type, void *attr)
301 return mlx5dv_set_context_attr(ibv_ctx, type, attr);
305 mlx5_glue_dv_init_obj(struct mlx5dv_obj *obj, uint64_t obj_type)
307 return mlx5dv_init_obj(obj, obj_type);
310 const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue){
311 .version = MLX5_GLUE_VERSION,
312 .fork_init = mlx5_glue_fork_init,
313 .alloc_pd = mlx5_glue_alloc_pd,
314 .dealloc_pd = mlx5_glue_dealloc_pd,
315 .get_device_list = mlx5_glue_get_device_list,
316 .free_device_list = mlx5_glue_free_device_list,
317 .open_device = mlx5_glue_open_device,
318 .close_device = mlx5_glue_close_device,
319 .query_device = mlx5_glue_query_device,
320 .query_device_ex = mlx5_glue_query_device_ex,
321 .query_port = mlx5_glue_query_port,
322 .create_comp_channel = mlx5_glue_create_comp_channel,
323 .destroy_comp_channel = mlx5_glue_destroy_comp_channel,
324 .create_cq = mlx5_glue_create_cq,
325 .destroy_cq = mlx5_glue_destroy_cq,
326 .get_cq_event = mlx5_glue_get_cq_event,
327 .ack_cq_events = mlx5_glue_ack_cq_events,
328 .create_rwq_ind_table = mlx5_glue_create_rwq_ind_table,
329 .destroy_rwq_ind_table = mlx5_glue_destroy_rwq_ind_table,
330 .create_wq = mlx5_glue_create_wq,
331 .destroy_wq = mlx5_glue_destroy_wq,
332 .modify_wq = mlx5_glue_modify_wq,
333 .create_flow = mlx5_glue_create_flow,
334 .destroy_flow = mlx5_glue_destroy_flow,
335 .create_qp = mlx5_glue_create_qp,
336 .create_qp_ex = mlx5_glue_create_qp_ex,
337 .destroy_qp = mlx5_glue_destroy_qp,
338 .modify_qp = mlx5_glue_modify_qp,
339 .reg_mr = mlx5_glue_reg_mr,
340 .dereg_mr = mlx5_glue_dereg_mr,
341 .create_counter_set = mlx5_glue_create_counter_set,
342 .destroy_counter_set = mlx5_glue_destroy_counter_set,
343 .describe_counter_set = mlx5_glue_describe_counter_set,
344 .query_counter_set = mlx5_glue_query_counter_set,
345 .ack_async_event = mlx5_glue_ack_async_event,
346 .get_async_event = mlx5_glue_get_async_event,
347 .port_state_str = mlx5_glue_port_state_str,
348 .cq_ex_to_cq = mlx5_glue_cq_ex_to_cq,
349 .dv_create_cq = mlx5_glue_dv_create_cq,
350 .dv_query_device = mlx5_glue_dv_query_device,
351 .dv_set_context_attr = mlx5_glue_dv_set_context_attr,
352 .dv_init_obj = mlx5_glue_dv_init_obj,