net/mlx4: move rdma-core calls to separate file
[dpdk.git] / drivers / net / mlx4 / mlx4_glue.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2018 6WIND S.A.
3  * Copyright 2018 Mellanox
4  */
5
6 /* Verbs headers do not support -pedantic. */
7 #ifdef PEDANTIC
8 #pragma GCC diagnostic ignored "-Wpedantic"
9 #endif
10 #include <infiniband/mlx4dv.h>
11 #include <infiniband/verbs.h>
12 #ifdef PEDANTIC
13 #pragma GCC diagnostic error "-Wpedantic"
14 #endif
15
16 #include "mlx4_glue.h"
17
18 static int
19 mlx4_glue_fork_init(void)
20 {
21         return ibv_fork_init();
22 }
23
24 static int
25 mlx4_glue_get_async_event(struct ibv_context *context,
26                           struct ibv_async_event *event)
27 {
28         return ibv_get_async_event(context, event);
29 }
30
31 static void
32 mlx4_glue_ack_async_event(struct ibv_async_event *event)
33 {
34         ibv_ack_async_event(event);
35 }
36
37 static struct ibv_pd *
38 mlx4_glue_alloc_pd(struct ibv_context *context)
39 {
40         return ibv_alloc_pd(context);
41 }
42
43 static int
44 mlx4_glue_dealloc_pd(struct ibv_pd *pd)
45 {
46         return ibv_dealloc_pd(pd);
47 }
48
49 static struct ibv_device **
50 mlx4_glue_get_device_list(int *num_devices)
51 {
52         return ibv_get_device_list(num_devices);
53 }
54
55 static void
56 mlx4_glue_free_device_list(struct ibv_device **list)
57 {
58         ibv_free_device_list(list);
59 }
60
61 static struct ibv_context *
62 mlx4_glue_open_device(struct ibv_device *device)
63 {
64         return ibv_open_device(device);
65 }
66
67 static int
68 mlx4_glue_close_device(struct ibv_context *context)
69 {
70         return ibv_close_device(context);
71 }
72
73 static const char *
74 mlx4_glue_get_device_name(struct ibv_device *device)
75 {
76         return ibv_get_device_name(device);
77 }
78
79 static int
80 mlx4_glue_query_device(struct ibv_context *context,
81                        struct ibv_device_attr *device_attr)
82 {
83         return ibv_query_device(context, device_attr);
84 }
85
86 static int
87 mlx4_glue_query_device_ex(struct ibv_context *context,
88                           const struct ibv_query_device_ex_input *input,
89                           struct ibv_device_attr_ex *attr)
90 {
91         return ibv_query_device_ex(context, input, attr);
92 }
93
94 static int
95 mlx4_glue_query_port(struct ibv_context *context, uint8_t port_num,
96                      struct ibv_port_attr *port_attr)
97 {
98         return ibv_query_port(context, port_num, port_attr);
99 }
100
101 static const char *
102 mlx4_glue_port_state_str(enum ibv_port_state port_state)
103 {
104         return ibv_port_state_str(port_state);
105 }
106
107 static struct ibv_comp_channel *
108 mlx4_glue_create_comp_channel(struct ibv_context *context)
109 {
110         return ibv_create_comp_channel(context);
111 }
112
113 static int
114 mlx4_glue_destroy_comp_channel(struct ibv_comp_channel *channel)
115 {
116         return ibv_destroy_comp_channel(channel);
117 }
118
119 static struct ibv_cq *
120 mlx4_glue_create_cq(struct ibv_context *context, int cqe, void *cq_context,
121                     struct ibv_comp_channel *channel, int comp_vector)
122 {
123         return ibv_create_cq(context, cqe, cq_context, channel, comp_vector);
124 }
125
126 static int
127 mlx4_glue_destroy_cq(struct ibv_cq *cq)
128 {
129         return ibv_destroy_cq(cq);
130 }
131
132 static int
133 mlx4_glue_get_cq_event(struct ibv_comp_channel *channel, struct ibv_cq **cq,
134                        void **cq_context)
135 {
136         return ibv_get_cq_event(channel, cq, cq_context);
137 }
138
139 static void
140 mlx4_glue_ack_cq_events(struct ibv_cq *cq, unsigned int nevents)
141 {
142         ibv_ack_cq_events(cq, nevents);
143 }
144
145 static struct ibv_flow *
146 mlx4_glue_create_flow(struct ibv_qp *qp, struct ibv_flow_attr *flow)
147 {
148         return ibv_create_flow(qp, flow);
149 }
150
151 static int
152 mlx4_glue_destroy_flow(struct ibv_flow *flow_id)
153 {
154         return ibv_destroy_flow(flow_id);
155 }
156
157 static struct ibv_qp *
158 mlx4_glue_create_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *qp_init_attr)
159 {
160         return ibv_create_qp(pd, qp_init_attr);
161 }
162
163 static struct ibv_qp *
164 mlx4_glue_create_qp_ex(struct ibv_context *context,
165                        struct ibv_qp_init_attr_ex *qp_init_attr_ex)
166 {
167         return ibv_create_qp_ex(context, qp_init_attr_ex);
168 }
169
170 static int
171 mlx4_glue_destroy_qp(struct ibv_qp *qp)
172 {
173         return ibv_destroy_qp(qp);
174 }
175
176 static int
177 mlx4_glue_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, int attr_mask)
178 {
179         return ibv_modify_qp(qp, attr, attr_mask);
180 }
181
182 static struct ibv_mr *
183 mlx4_glue_reg_mr(struct ibv_pd *pd, void *addr, size_t length, int access)
184 {
185         return ibv_reg_mr(pd, addr, length, access);
186 }
187
188 static int
189 mlx4_glue_dereg_mr(struct ibv_mr *mr)
190 {
191         return ibv_dereg_mr(mr);
192 }
193
194 static struct ibv_rwq_ind_table *
195 mlx4_glue_create_rwq_ind_table(struct ibv_context *context,
196                                struct ibv_rwq_ind_table_init_attr *init_attr)
197 {
198         return ibv_create_rwq_ind_table(context, init_attr);
199 }
200
201 static int
202 mlx4_glue_destroy_rwq_ind_table(struct ibv_rwq_ind_table *rwq_ind_table)
203 {
204         return ibv_destroy_rwq_ind_table(rwq_ind_table);
205 }
206
207 static struct ibv_wq *
208 mlx4_glue_create_wq(struct ibv_context *context,
209                     struct ibv_wq_init_attr *wq_init_attr)
210 {
211         return ibv_create_wq(context, wq_init_attr);
212 }
213
214 static int
215 mlx4_glue_destroy_wq(struct ibv_wq *wq)
216 {
217         return ibv_destroy_wq(wq);
218 }
219 static int
220 mlx4_glue_modify_wq(struct ibv_wq *wq, struct ibv_wq_attr *wq_attr)
221 {
222         return ibv_modify_wq(wq, wq_attr);
223 }
224
225 static int
226 mlx4_glue_dv_init_obj(struct mlx4dv_obj *obj, uint64_t obj_type)
227 {
228         return mlx4dv_init_obj(obj, obj_type);
229 }
230
231 static int
232 mlx4_glue_dv_set_context_attr(struct ibv_context *context,
233                               enum mlx4dv_set_ctx_attr_type attr_type,
234                               void *attr)
235 {
236         return mlx4dv_set_context_attr(context, attr_type, attr);
237 }
238
239 const struct mlx4_glue *mlx4_glue = &(const struct mlx4_glue){
240         .fork_init = mlx4_glue_fork_init,
241         .get_async_event = mlx4_glue_get_async_event,
242         .ack_async_event = mlx4_glue_ack_async_event,
243         .alloc_pd = mlx4_glue_alloc_pd,
244         .dealloc_pd = mlx4_glue_dealloc_pd,
245         .get_device_list = mlx4_glue_get_device_list,
246         .free_device_list = mlx4_glue_free_device_list,
247         .open_device = mlx4_glue_open_device,
248         .close_device = mlx4_glue_close_device,
249         .get_device_name = mlx4_glue_get_device_name,
250         .query_device = mlx4_glue_query_device,
251         .query_device_ex = mlx4_glue_query_device_ex,
252         .query_port = mlx4_glue_query_port,
253         .port_state_str = mlx4_glue_port_state_str,
254         .create_comp_channel = mlx4_glue_create_comp_channel,
255         .destroy_comp_channel = mlx4_glue_destroy_comp_channel,
256         .create_cq = mlx4_glue_create_cq,
257         .destroy_cq = mlx4_glue_destroy_cq,
258         .get_cq_event = mlx4_glue_get_cq_event,
259         .ack_cq_events = mlx4_glue_ack_cq_events,
260         .create_flow = mlx4_glue_create_flow,
261         .destroy_flow = mlx4_glue_destroy_flow,
262         .create_qp = mlx4_glue_create_qp,
263         .create_qp_ex = mlx4_glue_create_qp_ex,
264         .destroy_qp = mlx4_glue_destroy_qp,
265         .modify_qp = mlx4_glue_modify_qp,
266         .reg_mr = mlx4_glue_reg_mr,
267         .dereg_mr = mlx4_glue_dereg_mr,
268         .create_rwq_ind_table = mlx4_glue_create_rwq_ind_table,
269         .destroy_rwq_ind_table = mlx4_glue_destroy_rwq_ind_table,
270         .create_wq = mlx4_glue_create_wq,
271         .destroy_wq = mlx4_glue_destroy_wq,
272         .modify_wq = mlx4_glue_modify_wq,
273         .dv_init_obj = mlx4_glue_dv_init_obj,
274         .dv_set_context_attr = mlx4_glue_dv_set_context_attr,
275 };