1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018 6WIND S.A.
3 * Copyright 2018 Mellanox Technologies, Ltd
11 * Not needed by this file; included to work around the lack of off_t
12 * definition for mlx5dv.h with unpatched rdma-core versions.
14 #include <sys/types.h>
16 /* Verbs headers do not support -pedantic. */
18 #pragma GCC diagnostic ignored "-Wpedantic"
20 #include <infiniband/mlx5dv.h>
21 #include <infiniband/verbs.h>
23 #pragma GCC diagnostic error "-Wpedantic"
26 #include "mlx5_autoconf.h"
27 #include "mlx5_glue.h"
30 mlx5_glue_fork_init(void)
32 return ibv_fork_init();
35 static struct ibv_pd *
36 mlx5_glue_alloc_pd(struct ibv_context *context)
38 return ibv_alloc_pd(context);
42 mlx5_glue_dealloc_pd(struct ibv_pd *pd)
44 return ibv_dealloc_pd(pd);
47 static struct ibv_device **
48 mlx5_glue_get_device_list(int *num_devices)
50 return ibv_get_device_list(num_devices);
54 mlx5_glue_free_device_list(struct ibv_device **list)
56 ibv_free_device_list(list);
59 static struct ibv_context *
60 mlx5_glue_open_device(struct ibv_device *device)
62 return ibv_open_device(device);
66 mlx5_glue_close_device(struct ibv_context *context)
68 return ibv_close_device(context);
72 mlx5_glue_query_device(struct ibv_context *context,
73 struct ibv_device_attr *device_attr)
75 return ibv_query_device(context, device_attr);
79 mlx5_glue_query_device_ex(struct ibv_context *context,
80 const struct ibv_query_device_ex_input *input,
81 struct ibv_device_attr_ex *attr)
83 return ibv_query_device_ex(context, input, attr);
87 mlx5_glue_query_port(struct ibv_context *context, uint8_t port_num,
88 struct ibv_port_attr *port_attr)
90 return ibv_query_port(context, port_num, port_attr);
93 static struct ibv_comp_channel *
94 mlx5_glue_create_comp_channel(struct ibv_context *context)
96 return ibv_create_comp_channel(context);
100 mlx5_glue_destroy_comp_channel(struct ibv_comp_channel *channel)
102 return ibv_destroy_comp_channel(channel);
105 static struct ibv_cq *
106 mlx5_glue_create_cq(struct ibv_context *context, int cqe, void *cq_context,
107 struct ibv_comp_channel *channel, int comp_vector)
109 return ibv_create_cq(context, cqe, cq_context, channel, comp_vector);
113 mlx5_glue_destroy_cq(struct ibv_cq *cq)
115 return ibv_destroy_cq(cq);
119 mlx5_glue_get_cq_event(struct ibv_comp_channel *channel, struct ibv_cq **cq,
122 return ibv_get_cq_event(channel, cq, cq_context);
126 mlx5_glue_ack_cq_events(struct ibv_cq *cq, unsigned int nevents)
128 ibv_ack_cq_events(cq, nevents);
131 static struct ibv_rwq_ind_table *
132 mlx5_glue_create_rwq_ind_table(struct ibv_context *context,
133 struct ibv_rwq_ind_table_init_attr *init_attr)
135 return ibv_create_rwq_ind_table(context, init_attr);
139 mlx5_glue_destroy_rwq_ind_table(struct ibv_rwq_ind_table *rwq_ind_table)
141 return ibv_destroy_rwq_ind_table(rwq_ind_table);
144 static struct ibv_wq *
145 mlx5_glue_create_wq(struct ibv_context *context,
146 struct ibv_wq_init_attr *wq_init_attr)
148 return ibv_create_wq(context, wq_init_attr);
152 mlx5_glue_destroy_wq(struct ibv_wq *wq)
154 return ibv_destroy_wq(wq);
157 mlx5_glue_modify_wq(struct ibv_wq *wq, struct ibv_wq_attr *wq_attr)
159 return ibv_modify_wq(wq, wq_attr);
162 static struct ibv_flow *
163 mlx5_glue_create_flow(struct ibv_qp *qp, struct ibv_flow_attr *flow)
165 return ibv_create_flow(qp, flow);
169 mlx5_glue_destroy_flow(struct ibv_flow *flow_id)
171 return ibv_destroy_flow(flow_id);
174 static struct ibv_qp *
175 mlx5_glue_create_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *qp_init_attr)
177 return ibv_create_qp(pd, qp_init_attr);
180 static struct ibv_qp *
181 mlx5_glue_create_qp_ex(struct ibv_context *context,
182 struct ibv_qp_init_attr_ex *qp_init_attr_ex)
184 return ibv_create_qp_ex(context, qp_init_attr_ex);
188 mlx5_glue_destroy_qp(struct ibv_qp *qp)
190 return ibv_destroy_qp(qp);
194 mlx5_glue_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, int attr_mask)
196 return ibv_modify_qp(qp, attr, attr_mask);
199 static struct ibv_mr *
200 mlx5_glue_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access)
202 return ibv_reg_mr(pd, addr, length, access);
206 mlx5_glue_dereg_mr(struct ibv_mr *mr)
208 return ibv_dereg_mr(mr);
211 static struct ibv_counter_set *
212 mlx5_glue_create_counter_set(struct ibv_context *context,
213 struct ibv_counter_set_init_attr *init_attr)
215 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT
220 return ibv_create_counter_set(context, init_attr);
225 mlx5_glue_destroy_counter_set(struct ibv_counter_set *cs)
227 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT
231 return ibv_destroy_counter_set(cs);
236 mlx5_glue_describe_counter_set(struct ibv_context *context,
237 uint16_t counter_set_id,
238 struct ibv_counter_set_description *cs_desc)
240 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT
242 (void)counter_set_id;
246 return ibv_describe_counter_set(context, counter_set_id, cs_desc);
251 mlx5_glue_query_counter_set(struct ibv_query_counter_set_attr *query_attr,
252 struct ibv_counter_set_data *cs_data)
254 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT
259 return ibv_query_counter_set(query_attr, cs_data);
264 mlx5_glue_ack_async_event(struct ibv_async_event *event)
266 ibv_ack_async_event(event);
270 mlx5_glue_get_async_event(struct ibv_context *context,
271 struct ibv_async_event *event)
273 return ibv_get_async_event(context, event);
277 mlx5_glue_port_state_str(enum ibv_port_state port_state)
279 return ibv_port_state_str(port_state);
282 static struct ibv_cq *
283 mlx5_glue_cq_ex_to_cq(struct ibv_cq_ex *cq)
285 return ibv_cq_ex_to_cq(cq);
288 static struct ibv_cq_ex *
289 mlx5_glue_dv_create_cq(struct ibv_context *context,
290 struct ibv_cq_init_attr_ex *cq_attr,
291 struct mlx5dv_cq_init_attr *mlx5_cq_attr)
293 return mlx5dv_create_cq(context, cq_attr, mlx5_cq_attr);
297 mlx5_glue_dv_query_device(struct ibv_context *ctx,
298 struct mlx5dv_context *attrs_out)
300 return mlx5dv_query_device(ctx, attrs_out);
304 mlx5_glue_dv_set_context_attr(struct ibv_context *ibv_ctx,
305 enum mlx5dv_set_ctx_attr_type type, void *attr)
307 return mlx5dv_set_context_attr(ibv_ctx, type, attr);
311 mlx5_glue_dv_init_obj(struct mlx5dv_obj *obj, uint64_t obj_type)
313 return mlx5dv_init_obj(obj, obj_type);
316 const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue){
317 .version = MLX5_GLUE_VERSION,
318 .fork_init = mlx5_glue_fork_init,
319 .alloc_pd = mlx5_glue_alloc_pd,
320 .dealloc_pd = mlx5_glue_dealloc_pd,
321 .get_device_list = mlx5_glue_get_device_list,
322 .free_device_list = mlx5_glue_free_device_list,
323 .open_device = mlx5_glue_open_device,
324 .close_device = mlx5_glue_close_device,
325 .query_device = mlx5_glue_query_device,
326 .query_device_ex = mlx5_glue_query_device_ex,
327 .query_port = mlx5_glue_query_port,
328 .create_comp_channel = mlx5_glue_create_comp_channel,
329 .destroy_comp_channel = mlx5_glue_destroy_comp_channel,
330 .create_cq = mlx5_glue_create_cq,
331 .destroy_cq = mlx5_glue_destroy_cq,
332 .get_cq_event = mlx5_glue_get_cq_event,
333 .ack_cq_events = mlx5_glue_ack_cq_events,
334 .create_rwq_ind_table = mlx5_glue_create_rwq_ind_table,
335 .destroy_rwq_ind_table = mlx5_glue_destroy_rwq_ind_table,
336 .create_wq = mlx5_glue_create_wq,
337 .destroy_wq = mlx5_glue_destroy_wq,
338 .modify_wq = mlx5_glue_modify_wq,
339 .create_flow = mlx5_glue_create_flow,
340 .destroy_flow = mlx5_glue_destroy_flow,
341 .create_qp = mlx5_glue_create_qp,
342 .create_qp_ex = mlx5_glue_create_qp_ex,
343 .destroy_qp = mlx5_glue_destroy_qp,
344 .modify_qp = mlx5_glue_modify_qp,
345 .reg_mr = mlx5_glue_reg_mr,
346 .dereg_mr = mlx5_glue_dereg_mr,
347 .create_counter_set = mlx5_glue_create_counter_set,
348 .destroy_counter_set = mlx5_glue_destroy_counter_set,
349 .describe_counter_set = mlx5_glue_describe_counter_set,
350 .query_counter_set = mlx5_glue_query_counter_set,
351 .ack_async_event = mlx5_glue_ack_async_event,
352 .get_async_event = mlx5_glue_get_async_event,
353 .port_state_str = mlx5_glue_port_state_str,
354 .cq_ex_to_cq = mlx5_glue_cq_ex_to_cq,
355 .dv_create_cq = mlx5_glue_dv_create_cq,
356 .dv_query_device = mlx5_glue_dv_query_device,
357 .dv_set_context_attr = mlx5_glue_dv_set_context_attr,
358 .dv_init_obj = mlx5_glue_dv_init_obj,