1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018 6WIND S.A.
3 * Copyright 2018 Mellanox Technologies, Ltd
11 /* Verbs headers do not support -pedantic. */
13 #pragma GCC diagnostic ignored "-Wpedantic"
15 #include <infiniband/mlx5dv.h>
16 #include <infiniband/verbs.h>
18 #pragma GCC diagnostic error "-Wpedantic"
21 #include <rte_byteorder.h>
23 #include "mlx5_autoconf.h"
25 #ifndef MLX5_GLUE_VERSION
26 #define MLX5_GLUE_VERSION ""
29 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
30 struct ibv_counter_set;
31 struct ibv_counter_set_data;
32 struct ibv_counter_set_description;
33 struct ibv_counter_set_init_attr;
34 struct ibv_query_counter_set_attr;
37 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
39 struct ibv_counters_init_attr;
40 struct ibv_counter_attach_attr;
43 #ifndef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
44 struct mlx5dv_qp_init_attr;
47 #ifndef HAVE_IBV_DEVICE_STRIDING_RQ_SUPPORT
48 struct mlx5dv_wq_init_attr;
51 #ifndef HAVE_IBV_FLOW_DV_SUPPORT
52 struct mlx5dv_flow_matcher;
53 struct mlx5dv_flow_matcher_attr;
54 struct mlx5dv_flow_action_attr;
55 struct mlx5dv_flow_match_parameters;
56 struct mlx5dv_dr_flow_meter_attr;
57 struct ibv_flow_action;
58 enum mlx5dv_flow_action_packet_reformat_type { packet_reformat_type = 0, };
59 enum mlx5dv_flow_table_type { flow_table_type = 0, };
62 #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
63 #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
66 #ifndef HAVE_IBV_DEVX_OBJ
67 struct mlx5dv_devx_obj;
68 struct mlx5dv_devx_umem { uint32_t umem_id; };
69 struct mlx5dv_devx_uar { void *reg_addr; void *base_addr; uint32_t page_id; };
72 #ifndef HAVE_IBV_DEVX_ASYNC
73 struct mlx5dv_devx_cmd_comp;
74 struct mlx5dv_devx_async_cmd_hdr;
77 #ifndef HAVE_MLX5DV_DR
78 enum mlx5dv_dr_domain_type { unused, };
79 struct mlx5dv_dr_domain;
80 struct mlx5dv_dr_action;
83 #ifndef HAVE_MLX5DV_DR_DEVX_PORT
84 struct mlx5dv_devx_port;
87 #ifndef HAVE_MLX5_DR_CREATE_ACTION_FLOW_METER
88 struct mlx5dv_dr_flow_meter_attr;
91 #ifndef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE
92 struct mlx5dv_dr_flow_sampler_attr {
93 uint32_t sample_ratio;
94 void *default_next_table;
95 size_t num_sample_actions;
96 struct mlx5dv_dr_action **sample_actions;
101 #ifndef HAVE_MLX5_DR_CREATE_ACTION_DEST_ARRAY
102 enum mlx5dv_dr_action_dest_type {
103 MLX5DV_DR_ACTION_DEST,
104 MLX5DV_DR_ACTION_DEST_REFORMAT,
106 struct mlx5dv_dr_action_dest_reformat {
107 struct mlx5dv_dr_action *reformat;
108 struct mlx5dv_dr_action *dest;
110 struct mlx5dv_dr_action_dest_attr {
111 enum mlx5dv_dr_action_dest_type type;
113 struct mlx5dv_dr_action *dest;
114 struct mlx5dv_dr_action_dest_reformat *dest_reformat;
119 #ifndef HAVE_IBV_DEVX_EVENT
120 struct mlx5dv_devx_event_channel { int fd; };
121 struct mlx5dv_devx_async_event_hdr;
122 #define MLX5DV_DEVX_CREATE_EVENT_CHANNEL_FLAGS_OMIT_EV_DATA 1
126 struct mlx5dv_var { uint32_t page_id; uint32_t length; off_t mmap_off;
127 uint64_t comp_mask; };
130 #ifndef HAVE_IBV_RELAXED_ORDERING
131 #define IBV_ACCESS_RELAXED_ORDERING 0
136 int (*fork_init)(void);
137 struct ibv_pd *(*alloc_pd)(struct ibv_context *context);
138 int (*dealloc_pd)(struct ibv_pd *pd);
139 struct ibv_device **(*get_device_list)(int *num_devices);
140 void (*free_device_list)(struct ibv_device **list);
141 struct ibv_context *(*open_device)(struct ibv_device *device);
142 int (*close_device)(struct ibv_context *context);
143 int (*query_device)(struct ibv_context *context,
144 struct ibv_device_attr *device_attr);
145 int (*query_device_ex)(struct ibv_context *context,
146 const struct ibv_query_device_ex_input *input,
147 struct ibv_device_attr_ex *attr);
148 int (*query_rt_values_ex)(struct ibv_context *context,
149 struct ibv_values_ex *values);
150 int (*query_port)(struct ibv_context *context, uint8_t port_num,
151 struct ibv_port_attr *port_attr);
152 struct ibv_comp_channel *(*create_comp_channel)
153 (struct ibv_context *context);
154 int (*destroy_comp_channel)(struct ibv_comp_channel *channel);
155 struct ibv_cq *(*create_cq)(struct ibv_context *context, int cqe,
157 struct ibv_comp_channel *channel,
159 int (*destroy_cq)(struct ibv_cq *cq);
160 int (*get_cq_event)(struct ibv_comp_channel *channel,
161 struct ibv_cq **cq, void **cq_context);
162 void (*ack_cq_events)(struct ibv_cq *cq, unsigned int nevents);
163 struct ibv_rwq_ind_table *(*create_rwq_ind_table)
164 (struct ibv_context *context,
165 struct ibv_rwq_ind_table_init_attr *init_attr);
166 int (*destroy_rwq_ind_table)(struct ibv_rwq_ind_table *rwq_ind_table);
167 struct ibv_wq *(*create_wq)(struct ibv_context *context,
168 struct ibv_wq_init_attr *wq_init_attr);
169 int (*destroy_wq)(struct ibv_wq *wq);
170 int (*modify_wq)(struct ibv_wq *wq, struct ibv_wq_attr *wq_attr);
171 struct ibv_flow *(*create_flow)(struct ibv_qp *qp,
172 struct ibv_flow_attr *flow);
173 int (*destroy_flow)(struct ibv_flow *flow_id);
174 int (*destroy_flow_action)(void *action);
175 struct ibv_qp *(*create_qp)(struct ibv_pd *pd,
176 struct ibv_qp_init_attr *qp_init_attr);
177 struct ibv_qp *(*create_qp_ex)
178 (struct ibv_context *context,
179 struct ibv_qp_init_attr_ex *qp_init_attr_ex);
180 int (*destroy_qp)(struct ibv_qp *qp);
181 int (*modify_qp)(struct ibv_qp *qp, struct ibv_qp_attr *attr,
183 struct ibv_mr *(*reg_mr)(struct ibv_pd *pd, void *addr,
184 size_t length, int access);
185 struct ibv_mr *(*alloc_null_mr)(struct ibv_pd *pd);
186 int (*dereg_mr)(struct ibv_mr *mr);
187 struct ibv_counter_set *(*create_counter_set)
188 (struct ibv_context *context,
189 struct ibv_counter_set_init_attr *init_attr);
190 int (*destroy_counter_set)(struct ibv_counter_set *cs);
191 int (*describe_counter_set)
192 (struct ibv_context *context,
193 uint16_t counter_set_id,
194 struct ibv_counter_set_description *cs_desc);
195 int (*query_counter_set)(struct ibv_query_counter_set_attr *query_attr,
196 struct ibv_counter_set_data *cs_data);
197 struct ibv_counters *(*create_counters)
198 (struct ibv_context *context,
199 struct ibv_counters_init_attr *init_attr);
200 int (*destroy_counters)(struct ibv_counters *counters);
201 int (*attach_counters)(struct ibv_counters *counters,
202 struct ibv_counter_attach_attr *attr,
203 struct ibv_flow *flow);
204 int (*query_counters)(struct ibv_counters *counters,
205 uint64_t *counters_value,
208 void (*ack_async_event)(struct ibv_async_event *event);
209 int (*get_async_event)(struct ibv_context *context,
210 struct ibv_async_event *event);
211 const char *(*port_state_str)(enum ibv_port_state port_state);
212 struct ibv_cq *(*cq_ex_to_cq)(struct ibv_cq_ex *cq);
213 void *(*dr_create_flow_action_dest_flow_tbl)(void *tbl);
214 void *(*dr_create_flow_action_dest_port)(void *domain,
216 void *(*dr_create_flow_action_drop)(void);
217 void *(*dr_create_flow_action_push_vlan)
218 (struct mlx5dv_dr_domain *domain,
219 rte_be32_t vlan_tag);
220 void *(*dr_create_flow_action_pop_vlan)(void);
221 void *(*dr_create_flow_tbl)(void *domain, uint32_t level);
222 int (*dr_destroy_flow_tbl)(void *tbl);
223 void *(*dr_create_domain)(struct ibv_context *ctx,
224 enum mlx5dv_dr_domain_type domain);
225 int (*dr_destroy_domain)(void *domain);
226 int (*dr_sync_domain)(void *domain, uint32_t flags);
227 struct ibv_cq_ex *(*dv_create_cq)
228 (struct ibv_context *context,
229 struct ibv_cq_init_attr_ex *cq_attr,
230 struct mlx5dv_cq_init_attr *mlx5_cq_attr);
231 struct ibv_wq *(*dv_create_wq)
232 (struct ibv_context *context,
233 struct ibv_wq_init_attr *wq_attr,
234 struct mlx5dv_wq_init_attr *mlx5_wq_attr);
235 int (*dv_query_device)(struct ibv_context *ctx_in,
236 struct mlx5dv_context *attrs_out);
237 int (*dv_set_context_attr)(struct ibv_context *ibv_ctx,
238 enum mlx5dv_set_ctx_attr_type type,
240 int (*dv_init_obj)(struct mlx5dv_obj *obj, uint64_t obj_type);
241 struct ibv_qp *(*dv_create_qp)
242 (struct ibv_context *context,
243 struct ibv_qp_init_attr_ex *qp_init_attr_ex,
244 struct mlx5dv_qp_init_attr *dv_qp_init_attr);
245 void *(*dv_create_flow_matcher)
246 (struct ibv_context *context,
247 struct mlx5dv_flow_matcher_attr *matcher_attr,
249 void *(*dv_create_flow)(void *matcher, void *match_value,
250 size_t num_actions, void *actions[]);
251 void *(*dv_create_flow_action_counter)(void *obj, uint32_t offset);
252 void *(*dv_create_flow_action_dest_ibv_qp)(void *qp);
253 void *(*dv_create_flow_action_dest_devx_tir)(void *tir);
254 void *(*dv_create_flow_action_modify_header)
255 (struct ibv_context *ctx, enum mlx5dv_flow_table_type ft_type,
256 void *domain, uint64_t flags, size_t actions_sz,
258 void *(*dv_create_flow_action_packet_reformat)
259 (struct ibv_context *ctx,
260 enum mlx5dv_flow_action_packet_reformat_type reformat_type,
261 enum mlx5dv_flow_table_type ft_type,
262 struct mlx5dv_dr_domain *domain,
263 uint32_t flags, size_t data_sz, void *data);
264 void *(*dv_create_flow_action_tag)(uint32_t tag);
265 void *(*dv_create_flow_action_meter)
266 (struct mlx5dv_dr_flow_meter_attr *attr);
267 int (*dv_modify_flow_action_meter)(void *action,
268 struct mlx5dv_dr_flow_meter_attr *attr, uint64_t modify_bits);
269 void *(*dr_create_flow_action_default_miss)(void);
270 int (*dv_destroy_flow)(void *flow);
271 int (*dv_destroy_flow_matcher)(void *matcher);
272 struct ibv_context *(*dv_open_device)(struct ibv_device *device);
273 struct mlx5dv_var *(*dv_alloc_var)(struct ibv_context *context,
275 void (*dv_free_var)(struct mlx5dv_var *var);
276 struct mlx5dv_devx_uar *(*devx_alloc_uar)(struct ibv_context *context,
278 void (*devx_free_uar)(struct mlx5dv_devx_uar *devx_uar);
279 struct mlx5dv_devx_obj *(*devx_obj_create)
280 (struct ibv_context *ctx,
281 const void *in, size_t inlen,
282 void *out, size_t outlen);
283 int (*devx_obj_destroy)(struct mlx5dv_devx_obj *obj);
284 int (*devx_obj_query)(struct mlx5dv_devx_obj *obj,
285 const void *in, size_t inlen,
286 void *out, size_t outlen);
287 int (*devx_obj_modify)(struct mlx5dv_devx_obj *obj,
288 const void *in, size_t inlen,
289 void *out, size_t outlen);
290 int (*devx_general_cmd)(struct ibv_context *context,
291 const void *in, size_t inlen,
292 void *out, size_t outlen);
293 struct mlx5dv_devx_cmd_comp *(*devx_create_cmd_comp)
294 (struct ibv_context *context);
295 void (*devx_destroy_cmd_comp)(struct mlx5dv_devx_cmd_comp *cmd_comp);
296 int (*devx_obj_query_async)(struct mlx5dv_devx_obj *obj,
297 const void *in, size_t inlen,
298 size_t outlen, uint64_t wr_id,
299 struct mlx5dv_devx_cmd_comp *cmd_comp);
300 int (*devx_get_async_cmd_comp)(struct mlx5dv_devx_cmd_comp *cmd_comp,
301 struct mlx5dv_devx_async_cmd_hdr *resp,
302 size_t cmd_resp_len);
303 struct mlx5dv_devx_umem *(*devx_umem_reg)(struct ibv_context *context,
304 void *addr, size_t size,
306 int (*devx_umem_dereg)(struct mlx5dv_devx_umem *dv_devx_umem);
307 int (*devx_qp_query)(struct ibv_qp *qp,
308 const void *in, size_t inlen,
309 void *out, size_t outlen);
310 int (*devx_wq_query)(struct ibv_wq *wq, const void *in, size_t inlen,
311 void *out, size_t outlen);
312 int (*devx_port_query)(struct ibv_context *ctx,
314 struct mlx5dv_devx_port *mlx5_devx_port);
315 int (*dr_dump_domain)(FILE *file, void *domain);
316 int (*devx_query_eqn)(struct ibv_context *context, uint32_t cpus,
318 struct mlx5dv_devx_event_channel *(*devx_create_event_channel)
319 (struct ibv_context *context, int flags);
320 void (*devx_destroy_event_channel)
321 (struct mlx5dv_devx_event_channel *event_channel);
322 int (*devx_subscribe_devx_event)
323 (struct mlx5dv_devx_event_channel *event_channel,
324 struct mlx5dv_devx_obj *obj,
326 uint16_t events_num[],
328 int (*devx_subscribe_devx_event_fd)
329 (struct mlx5dv_devx_event_channel *event_channel,
331 struct mlx5dv_devx_obj *obj,
333 ssize_t (*devx_get_event)
334 (struct mlx5dv_devx_event_channel *event_channel,
335 struct mlx5dv_devx_async_event_hdr *event_data,
336 size_t event_resp_len);
337 void (*dr_reclaim_domain_memory)(void *domain, uint32_t enable);
338 struct mlx5dv_pp *(*dv_alloc_pp)(struct ibv_context *context,
339 size_t pp_context_sz,
340 const void *pp_context,
342 void (*dv_free_pp)(struct mlx5dv_pp *pp);
343 void *(*dr_create_flow_action_sampler)
344 (struct mlx5dv_dr_flow_sampler_attr *attr);
345 void *(*dr_create_flow_action_dest_array)
348 struct mlx5dv_dr_action_dest_attr *dests[]);
349 void *(*dv_create_flow_action_aso)
350 (struct mlx5dv_dr_domain *domain, void *aso_obj,
351 uint32_t offset, uint32_t flags, uint8_t return_reg_c);
354 extern const struct mlx5_glue *mlx5_glue;
356 #endif /* MLX5_GLUE_H_ */