New upstream version 18.02
[deb_dpdk.git] / drivers / net / mlx5 / mlx5_glue.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2018 6WIND S.A.
3  * Copyright 2018 Mellanox Technologies, Ltd.
4  */
5
6 #include <errno.h>
7 #include <stddef.h>
8 #include <stdint.h>
9
10 /* Verbs headers do not support -pedantic. */
11 #ifdef PEDANTIC
12 #pragma GCC diagnostic ignored "-Wpedantic"
13 #endif
14 #include <infiniband/mlx5dv.h>
15 #include <infiniband/verbs.h>
16 #ifdef PEDANTIC
17 #pragma GCC diagnostic error "-Wpedantic"
18 #endif
19
20 #include "mlx5_autoconf.h"
21 #include "mlx5_glue.h"
22
23 static int
24 mlx5_glue_fork_init(void)
25 {
26         return ibv_fork_init();
27 }
28
29 static struct ibv_pd *
30 mlx5_glue_alloc_pd(struct ibv_context *context)
31 {
32         return ibv_alloc_pd(context);
33 }
34
35 static int
36 mlx5_glue_dealloc_pd(struct ibv_pd *pd)
37 {
38         return ibv_dealloc_pd(pd);
39 }
40
41 static struct ibv_device **
42 mlx5_glue_get_device_list(int *num_devices)
43 {
44         return ibv_get_device_list(num_devices);
45 }
46
47 static void
48 mlx5_glue_free_device_list(struct ibv_device **list)
49 {
50         ibv_free_device_list(list);
51 }
52
53 static struct ibv_context *
54 mlx5_glue_open_device(struct ibv_device *device)
55 {
56         return ibv_open_device(device);
57 }
58
59 static int
60 mlx5_glue_close_device(struct ibv_context *context)
61 {
62         return ibv_close_device(context);
63 }
64
65 static int
66 mlx5_glue_query_device(struct ibv_context *context,
67                        struct ibv_device_attr *device_attr)
68 {
69         return ibv_query_device(context, device_attr);
70 }
71
72 static int
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)
76 {
77         return ibv_query_device_ex(context, input, attr);
78 }
79
80 static int
81 mlx5_glue_query_port(struct ibv_context *context, uint8_t port_num,
82                      struct ibv_port_attr *port_attr)
83 {
84         return ibv_query_port(context, port_num, port_attr);
85 }
86
87 static struct ibv_comp_channel *
88 mlx5_glue_create_comp_channel(struct ibv_context *context)
89 {
90         return ibv_create_comp_channel(context);
91 }
92
93 static int
94 mlx5_glue_destroy_comp_channel(struct ibv_comp_channel *channel)
95 {
96         return ibv_destroy_comp_channel(channel);
97 }
98
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)
102 {
103         return ibv_create_cq(context, cqe, cq_context, channel, comp_vector);
104 }
105
106 static int
107 mlx5_glue_destroy_cq(struct ibv_cq *cq)
108 {
109         return ibv_destroy_cq(cq);
110 }
111
112 static int
113 mlx5_glue_get_cq_event(struct ibv_comp_channel *channel, struct ibv_cq **cq,
114                        void **cq_context)
115 {
116         return ibv_get_cq_event(channel, cq, cq_context);
117 }
118
119 static void
120 mlx5_glue_ack_cq_events(struct ibv_cq *cq, unsigned int nevents)
121 {
122         ibv_ack_cq_events(cq, nevents);
123 }
124
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)
128 {
129         return ibv_create_rwq_ind_table(context, init_attr);
130 }
131
132 static int
133 mlx5_glue_destroy_rwq_ind_table(struct ibv_rwq_ind_table *rwq_ind_table)
134 {
135         return ibv_destroy_rwq_ind_table(rwq_ind_table);
136 }
137
138 static struct ibv_wq *
139 mlx5_glue_create_wq(struct ibv_context *context,
140                     struct ibv_wq_init_attr *wq_init_attr)
141 {
142         return ibv_create_wq(context, wq_init_attr);
143 }
144
145 static int
146 mlx5_glue_destroy_wq(struct ibv_wq *wq)
147 {
148         return ibv_destroy_wq(wq);
149 }
150 static int
151 mlx5_glue_modify_wq(struct ibv_wq *wq, struct ibv_wq_attr *wq_attr)
152 {
153         return ibv_modify_wq(wq, wq_attr);
154 }
155
156 static struct ibv_flow *
157 mlx5_glue_create_flow(struct ibv_qp *qp, struct ibv_flow_attr *flow)
158 {
159         return ibv_create_flow(qp, flow);
160 }
161
162 static int
163 mlx5_glue_destroy_flow(struct ibv_flow *flow_id)
164 {
165         return ibv_destroy_flow(flow_id);
166 }
167
168 static struct ibv_qp *
169 mlx5_glue_create_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *qp_init_attr)
170 {
171         return ibv_create_qp(pd, qp_init_attr);
172 }
173
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)
177 {
178         return ibv_create_qp_ex(context, qp_init_attr_ex);
179 }
180
181 static int
182 mlx5_glue_destroy_qp(struct ibv_qp *qp)
183 {
184         return ibv_destroy_qp(qp);
185 }
186
187 static int
188 mlx5_glue_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, int attr_mask)
189 {
190         return ibv_modify_qp(qp, attr, attr_mask);
191 }
192
193 static struct ibv_mr *
194 mlx5_glue_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access)
195 {
196         return ibv_reg_mr(pd, addr, length, access);
197 }
198
199 static int
200 mlx5_glue_dereg_mr(struct ibv_mr *mr)
201 {
202         return ibv_dereg_mr(mr);
203 }
204
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)
208 {
209 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT
210         (void)context;
211         (void)init_attr;
212         return NULL;
213 #else
214         return ibv_create_counter_set(context, init_attr);
215 #endif
216 }
217
218 static int
219 mlx5_glue_destroy_counter_set(struct ibv_counter_set *cs)
220 {
221 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT
222         (void)cs;
223         return ENOTSUP;
224 #else
225         return ibv_destroy_counter_set(cs);
226 #endif
227 }
228
229 static int
230 mlx5_glue_describe_counter_set(struct ibv_context *context,
231                                uint16_t counter_set_id,
232                                struct ibv_counter_set_description *cs_desc)
233 {
234 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT
235         (void)context;
236         (void)counter_set_id;
237         (void)cs_desc;
238         return ENOTSUP;
239 #else
240         return ibv_describe_counter_set(context, counter_set_id, cs_desc);
241 #endif
242 }
243
244 static int
245 mlx5_glue_query_counter_set(struct ibv_query_counter_set_attr *query_attr,
246                             struct ibv_counter_set_data *cs_data)
247 {
248 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT
249         (void)query_attr;
250         (void)cs_data;
251         return ENOTSUP;
252 #else
253         return ibv_query_counter_set(query_attr, cs_data);
254 #endif
255 }
256
257 static void
258 mlx5_glue_ack_async_event(struct ibv_async_event *event)
259 {
260         ibv_ack_async_event(event);
261 }
262
263 static int
264 mlx5_glue_get_async_event(struct ibv_context *context,
265                           struct ibv_async_event *event)
266 {
267         return ibv_get_async_event(context, event);
268 }
269
270 static const char *
271 mlx5_glue_port_state_str(enum ibv_port_state port_state)
272 {
273         return ibv_port_state_str(port_state);
274 }
275
276 static struct ibv_cq *
277 mlx5_glue_cq_ex_to_cq(struct ibv_cq_ex *cq)
278 {
279         return ibv_cq_ex_to_cq(cq);
280 }
281
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)
286 {
287         return mlx5dv_create_cq(context, cq_attr, mlx5_cq_attr);
288 }
289
290 static int
291 mlx5_glue_dv_query_device(struct ibv_context *ctx,
292                           struct mlx5dv_context *attrs_out)
293 {
294         return mlx5dv_query_device(ctx, attrs_out);
295 }
296
297 static int
298 mlx5_glue_dv_set_context_attr(struct ibv_context *ibv_ctx,
299                               enum mlx5dv_set_ctx_attr_type type, void *attr)
300 {
301         return mlx5dv_set_context_attr(ibv_ctx, type, attr);
302 }
303
304 static int
305 mlx5_glue_dv_init_obj(struct mlx5dv_obj *obj, uint64_t obj_type)
306 {
307         return mlx5dv_init_obj(obj, obj_type);
308 }
309
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,
353 };