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
134 /* LIB_GLUE_VERSION must be updated every time this structure is modified. */
137 int (*fork_init)(void);
138 struct ibv_pd *(*alloc_pd)(struct ibv_context *context);
139 int (*dealloc_pd)(struct ibv_pd *pd);
140 struct ibv_device **(*get_device_list)(int *num_devices);
141 void (*free_device_list)(struct ibv_device **list);
142 struct ibv_context *(*open_device)(struct ibv_device *device);
143 int (*close_device)(struct ibv_context *context);
144 int (*query_device)(struct ibv_context *context,
145 struct ibv_device_attr *device_attr);
146 int (*query_device_ex)(struct ibv_context *context,
147 const struct ibv_query_device_ex_input *input,
148 struct ibv_device_attr_ex *attr);
149 int (*query_rt_values_ex)(struct ibv_context *context,
150 struct ibv_values_ex *values);
151 int (*query_port)(struct ibv_context *context, uint8_t port_num,
152 struct ibv_port_attr *port_attr);
153 struct ibv_comp_channel *(*create_comp_channel)
154 (struct ibv_context *context);
155 int (*destroy_comp_channel)(struct ibv_comp_channel *channel);
156 struct ibv_cq *(*create_cq)(struct ibv_context *context, int cqe,
158 struct ibv_comp_channel *channel,
160 int (*destroy_cq)(struct ibv_cq *cq);
161 int (*get_cq_event)(struct ibv_comp_channel *channel,
162 struct ibv_cq **cq, void **cq_context);
163 void (*ack_cq_events)(struct ibv_cq *cq, unsigned int nevents);
164 struct ibv_rwq_ind_table *(*create_rwq_ind_table)
165 (struct ibv_context *context,
166 struct ibv_rwq_ind_table_init_attr *init_attr);
167 int (*destroy_rwq_ind_table)(struct ibv_rwq_ind_table *rwq_ind_table);
168 struct ibv_wq *(*create_wq)(struct ibv_context *context,
169 struct ibv_wq_init_attr *wq_init_attr);
170 int (*destroy_wq)(struct ibv_wq *wq);
171 int (*modify_wq)(struct ibv_wq *wq, struct ibv_wq_attr *wq_attr);
172 struct ibv_flow *(*create_flow)(struct ibv_qp *qp,
173 struct ibv_flow_attr *flow);
174 int (*destroy_flow)(struct ibv_flow *flow_id);
175 int (*destroy_flow_action)(void *action);
176 struct ibv_qp *(*create_qp)(struct ibv_pd *pd,
177 struct ibv_qp_init_attr *qp_init_attr);
178 struct ibv_qp *(*create_qp_ex)
179 (struct ibv_context *context,
180 struct ibv_qp_init_attr_ex *qp_init_attr_ex);
181 int (*destroy_qp)(struct ibv_qp *qp);
182 int (*modify_qp)(struct ibv_qp *qp, struct ibv_qp_attr *attr,
184 struct ibv_mr *(*reg_mr)(struct ibv_pd *pd, void *addr,
185 size_t length, int access);
186 struct ibv_mr *(*alloc_null_mr)(struct ibv_pd *pd);
187 int (*dereg_mr)(struct ibv_mr *mr);
188 struct ibv_counter_set *(*create_counter_set)
189 (struct ibv_context *context,
190 struct ibv_counter_set_init_attr *init_attr);
191 int (*destroy_counter_set)(struct ibv_counter_set *cs);
192 int (*describe_counter_set)
193 (struct ibv_context *context,
194 uint16_t counter_set_id,
195 struct ibv_counter_set_description *cs_desc);
196 int (*query_counter_set)(struct ibv_query_counter_set_attr *query_attr,
197 struct ibv_counter_set_data *cs_data);
198 struct ibv_counters *(*create_counters)
199 (struct ibv_context *context,
200 struct ibv_counters_init_attr *init_attr);
201 int (*destroy_counters)(struct ibv_counters *counters);
202 int (*attach_counters)(struct ibv_counters *counters,
203 struct ibv_counter_attach_attr *attr,
204 struct ibv_flow *flow);
205 int (*query_counters)(struct ibv_counters *counters,
206 uint64_t *counters_value,
209 void (*ack_async_event)(struct ibv_async_event *event);
210 int (*get_async_event)(struct ibv_context *context,
211 struct ibv_async_event *event);
212 const char *(*port_state_str)(enum ibv_port_state port_state);
213 struct ibv_cq *(*cq_ex_to_cq)(struct ibv_cq_ex *cq);
214 void *(*dr_create_flow_action_dest_flow_tbl)(void *tbl);
215 void *(*dr_create_flow_action_dest_port)(void *domain,
217 void *(*dr_create_flow_action_drop)(void);
218 void *(*dr_create_flow_action_push_vlan)
219 (struct mlx5dv_dr_domain *domain,
220 rte_be32_t vlan_tag);
221 void *(*dr_create_flow_action_pop_vlan)(void);
222 void *(*dr_create_flow_tbl)(void *domain, uint32_t level);
223 int (*dr_destroy_flow_tbl)(void *tbl);
224 void *(*dr_create_domain)(struct ibv_context *ctx,
225 enum mlx5dv_dr_domain_type domain);
226 int (*dr_destroy_domain)(void *domain);
227 int (*dr_sync_domain)(void *domain, uint32_t flags);
228 struct ibv_cq_ex *(*dv_create_cq)
229 (struct ibv_context *context,
230 struct ibv_cq_init_attr_ex *cq_attr,
231 struct mlx5dv_cq_init_attr *mlx5_cq_attr);
232 struct ibv_wq *(*dv_create_wq)
233 (struct ibv_context *context,
234 struct ibv_wq_init_attr *wq_attr,
235 struct mlx5dv_wq_init_attr *mlx5_wq_attr);
236 int (*dv_query_device)(struct ibv_context *ctx_in,
237 struct mlx5dv_context *attrs_out);
238 int (*dv_set_context_attr)(struct ibv_context *ibv_ctx,
239 enum mlx5dv_set_ctx_attr_type type,
241 int (*dv_init_obj)(struct mlx5dv_obj *obj, uint64_t obj_type);
242 struct ibv_qp *(*dv_create_qp)
243 (struct ibv_context *context,
244 struct ibv_qp_init_attr_ex *qp_init_attr_ex,
245 struct mlx5dv_qp_init_attr *dv_qp_init_attr);
246 void *(*dv_create_flow_matcher)
247 (struct ibv_context *context,
248 struct mlx5dv_flow_matcher_attr *matcher_attr,
250 void *(*dv_create_flow)(void *matcher, void *match_value,
251 size_t num_actions, void *actions[]);
252 void *(*dv_create_flow_action_counter)(void *obj, uint32_t offset);
253 void *(*dv_create_flow_action_dest_ibv_qp)(void *qp);
254 void *(*dv_create_flow_action_dest_devx_tir)(void *tir);
255 void *(*dv_create_flow_action_modify_header)
256 (struct ibv_context *ctx, enum mlx5dv_flow_table_type ft_type,
257 void *domain, uint64_t flags, size_t actions_sz,
259 void *(*dv_create_flow_action_packet_reformat)
260 (struct ibv_context *ctx,
261 enum mlx5dv_flow_action_packet_reformat_type reformat_type,
262 enum mlx5dv_flow_table_type ft_type,
263 struct mlx5dv_dr_domain *domain,
264 uint32_t flags, size_t data_sz, void *data);
265 void *(*dv_create_flow_action_tag)(uint32_t tag);
266 void *(*dv_create_flow_action_meter)
267 (struct mlx5dv_dr_flow_meter_attr *attr);
268 int (*dv_modify_flow_action_meter)(void *action,
269 struct mlx5dv_dr_flow_meter_attr *attr, uint64_t modify_bits);
270 void *(*dr_create_flow_action_default_miss)(void);
271 int (*dv_destroy_flow)(void *flow);
272 int (*dv_destroy_flow_matcher)(void *matcher);
273 struct ibv_context *(*dv_open_device)(struct ibv_device *device);
274 struct mlx5dv_var *(*dv_alloc_var)(struct ibv_context *context,
276 void (*dv_free_var)(struct mlx5dv_var *var);
277 struct mlx5dv_devx_uar *(*devx_alloc_uar)(struct ibv_context *context,
279 void (*devx_free_uar)(struct mlx5dv_devx_uar *devx_uar);
280 struct mlx5dv_devx_obj *(*devx_obj_create)
281 (struct ibv_context *ctx,
282 const void *in, size_t inlen,
283 void *out, size_t outlen);
284 int (*devx_obj_destroy)(struct mlx5dv_devx_obj *obj);
285 int (*devx_obj_query)(struct mlx5dv_devx_obj *obj,
286 const void *in, size_t inlen,
287 void *out, size_t outlen);
288 int (*devx_obj_modify)(struct mlx5dv_devx_obj *obj,
289 const void *in, size_t inlen,
290 void *out, size_t outlen);
291 int (*devx_general_cmd)(struct ibv_context *context,
292 const void *in, size_t inlen,
293 void *out, size_t outlen);
294 struct mlx5dv_devx_cmd_comp *(*devx_create_cmd_comp)
295 (struct ibv_context *context);
296 void (*devx_destroy_cmd_comp)(struct mlx5dv_devx_cmd_comp *cmd_comp);
297 int (*devx_obj_query_async)(struct mlx5dv_devx_obj *obj,
298 const void *in, size_t inlen,
299 size_t outlen, uint64_t wr_id,
300 struct mlx5dv_devx_cmd_comp *cmd_comp);
301 int (*devx_get_async_cmd_comp)(struct mlx5dv_devx_cmd_comp *cmd_comp,
302 struct mlx5dv_devx_async_cmd_hdr *resp,
303 size_t cmd_resp_len);
304 struct mlx5dv_devx_umem *(*devx_umem_reg)(struct ibv_context *context,
305 void *addr, size_t size,
307 int (*devx_umem_dereg)(struct mlx5dv_devx_umem *dv_devx_umem);
308 int (*devx_qp_query)(struct ibv_qp *qp,
309 const void *in, size_t inlen,
310 void *out, size_t outlen);
311 int (*devx_port_query)(struct ibv_context *ctx,
313 struct mlx5dv_devx_port *mlx5_devx_port);
314 int (*dr_dump_domain)(FILE *file, void *domain);
315 int (*devx_query_eqn)(struct ibv_context *context, uint32_t cpus,
317 struct mlx5dv_devx_event_channel *(*devx_create_event_channel)
318 (struct ibv_context *context, int flags);
319 void (*devx_destroy_event_channel)
320 (struct mlx5dv_devx_event_channel *event_channel);
321 int (*devx_subscribe_devx_event)
322 (struct mlx5dv_devx_event_channel *event_channel,
323 struct mlx5dv_devx_obj *obj,
325 uint16_t events_num[],
327 int (*devx_subscribe_devx_event_fd)
328 (struct mlx5dv_devx_event_channel *event_channel,
330 struct mlx5dv_devx_obj *obj,
332 ssize_t (*devx_get_event)
333 (struct mlx5dv_devx_event_channel *event_channel,
334 struct mlx5dv_devx_async_event_hdr *event_data,
335 size_t event_resp_len);
336 void (*dr_reclaim_domain_memory)(void *domain, uint32_t enable);
337 struct mlx5dv_pp *(*dv_alloc_pp)(struct ibv_context *context,
338 size_t pp_context_sz,
339 const void *pp_context,
341 void (*dv_free_pp)(struct mlx5dv_pp *pp);
342 void *(*dr_create_flow_action_sampler)
343 (struct mlx5dv_dr_flow_sampler_attr *attr);
344 void *(*dr_create_flow_action_dest_array)
347 struct mlx5dv_dr_action_dest_attr *dests[]);
350 extern const struct mlx5_glue *mlx5_glue;
352 #endif /* MLX5_GLUE_H_ */