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_MLX5DV_DR_DEVX_PORT_V35
91 #define MLX5_PORT_QUERY_VPORT (1u << 0)
92 #define MLX5_PORT_QUERY_REG_C0 (1u << 1)
94 struct mlx5_port_info {
96 uint16_t vport_id; /* Associated VF vport index (if any). */
97 uint32_t vport_meta_tag; /* Used for vport index match ove VF LAG. */
98 uint32_t vport_meta_mask; /* Used for vport index field match mask. */
101 #ifndef HAVE_MLX5_DR_CREATE_ACTION_FLOW_METER
102 struct mlx5dv_dr_flow_meter_attr;
105 #ifndef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE
106 struct mlx5dv_dr_flow_sampler_attr {
107 uint32_t sample_ratio;
108 void *default_next_table;
109 size_t num_sample_actions;
110 struct mlx5dv_dr_action **sample_actions;
115 #ifndef HAVE_MLX5_DR_CREATE_ACTION_DEST_ARRAY
116 enum mlx5dv_dr_action_dest_type {
117 MLX5DV_DR_ACTION_DEST,
118 MLX5DV_DR_ACTION_DEST_REFORMAT,
120 struct mlx5dv_dr_action_dest_reformat {
121 struct mlx5dv_dr_action *reformat;
122 struct mlx5dv_dr_action *dest;
124 struct mlx5dv_dr_action_dest_attr {
125 enum mlx5dv_dr_action_dest_type type;
127 struct mlx5dv_dr_action *dest;
128 struct mlx5dv_dr_action_dest_reformat *dest_reformat;
133 #ifndef HAVE_IBV_DEVX_EVENT
134 struct mlx5dv_devx_event_channel { int fd; };
135 struct mlx5dv_devx_async_event_hdr;
136 #define MLX5DV_DEVX_CREATE_EVENT_CHANNEL_FLAGS_OMIT_EV_DATA 1
140 struct mlx5dv_var { uint32_t page_id; uint32_t length; off_t mmap_off;
141 uint64_t comp_mask; };
144 #ifndef HAVE_IBV_RELAXED_ORDERING
145 #define IBV_ACCESS_RELAXED_ORDERING 0
150 int (*fork_init)(void);
151 struct ibv_pd *(*alloc_pd)(struct ibv_context *context);
152 int (*dealloc_pd)(struct ibv_pd *pd);
153 struct ibv_device **(*get_device_list)(int *num_devices);
154 void (*free_device_list)(struct ibv_device **list);
155 struct ibv_context *(*open_device)(struct ibv_device *device);
156 int (*close_device)(struct ibv_context *context);
157 int (*query_device)(struct ibv_context *context,
158 struct ibv_device_attr *device_attr);
159 int (*query_device_ex)(struct ibv_context *context,
160 const struct ibv_query_device_ex_input *input,
161 struct ibv_device_attr_ex *attr);
162 int (*query_rt_values_ex)(struct ibv_context *context,
163 struct ibv_values_ex *values);
164 int (*query_port)(struct ibv_context *context, uint8_t port_num,
165 struct ibv_port_attr *port_attr);
166 struct ibv_comp_channel *(*create_comp_channel)
167 (struct ibv_context *context);
168 int (*destroy_comp_channel)(struct ibv_comp_channel *channel);
169 struct ibv_cq *(*create_cq)(struct ibv_context *context, int cqe,
171 struct ibv_comp_channel *channel,
173 int (*destroy_cq)(struct ibv_cq *cq);
174 int (*get_cq_event)(struct ibv_comp_channel *channel,
175 struct ibv_cq **cq, void **cq_context);
176 void (*ack_cq_events)(struct ibv_cq *cq, unsigned int nevents);
177 struct ibv_rwq_ind_table *(*create_rwq_ind_table)
178 (struct ibv_context *context,
179 struct ibv_rwq_ind_table_init_attr *init_attr);
180 int (*destroy_rwq_ind_table)(struct ibv_rwq_ind_table *rwq_ind_table);
181 struct ibv_wq *(*create_wq)(struct ibv_context *context,
182 struct ibv_wq_init_attr *wq_init_attr);
183 int (*destroy_wq)(struct ibv_wq *wq);
184 int (*modify_wq)(struct ibv_wq *wq, struct ibv_wq_attr *wq_attr);
185 struct ibv_flow *(*create_flow)(struct ibv_qp *qp,
186 struct ibv_flow_attr *flow);
187 int (*destroy_flow)(struct ibv_flow *flow_id);
188 int (*destroy_flow_action)(void *action);
189 struct ibv_qp *(*create_qp)(struct ibv_pd *pd,
190 struct ibv_qp_init_attr *qp_init_attr);
191 struct ibv_qp *(*create_qp_ex)
192 (struct ibv_context *context,
193 struct ibv_qp_init_attr_ex *qp_init_attr_ex);
194 int (*destroy_qp)(struct ibv_qp *qp);
195 int (*modify_qp)(struct ibv_qp *qp, struct ibv_qp_attr *attr,
197 struct ibv_mr *(*reg_mr)(struct ibv_pd *pd, void *addr,
198 size_t length, int access);
199 struct ibv_mr *(*alloc_null_mr)(struct ibv_pd *pd);
200 int (*dereg_mr)(struct ibv_mr *mr);
201 struct ibv_counter_set *(*create_counter_set)
202 (struct ibv_context *context,
203 struct ibv_counter_set_init_attr *init_attr);
204 int (*destroy_counter_set)(struct ibv_counter_set *cs);
205 int (*describe_counter_set)
206 (struct ibv_context *context,
207 uint16_t counter_set_id,
208 struct ibv_counter_set_description *cs_desc);
209 int (*query_counter_set)(struct ibv_query_counter_set_attr *query_attr,
210 struct ibv_counter_set_data *cs_data);
211 struct ibv_counters *(*create_counters)
212 (struct ibv_context *context,
213 struct ibv_counters_init_attr *init_attr);
214 int (*destroy_counters)(struct ibv_counters *counters);
215 int (*attach_counters)(struct ibv_counters *counters,
216 struct ibv_counter_attach_attr *attr,
217 struct ibv_flow *flow);
218 int (*query_counters)(struct ibv_counters *counters,
219 uint64_t *counters_value,
222 void (*ack_async_event)(struct ibv_async_event *event);
223 int (*get_async_event)(struct ibv_context *context,
224 struct ibv_async_event *event);
225 const char *(*port_state_str)(enum ibv_port_state port_state);
226 struct ibv_cq *(*cq_ex_to_cq)(struct ibv_cq_ex *cq);
227 void *(*dr_create_flow_action_dest_flow_tbl)(void *tbl);
228 void *(*dr_create_flow_action_dest_port)(void *domain,
230 void *(*dr_create_flow_action_drop)(void);
231 void *(*dr_create_flow_action_push_vlan)
232 (struct mlx5dv_dr_domain *domain,
233 rte_be32_t vlan_tag);
234 void *(*dr_create_flow_action_pop_vlan)(void);
235 void *(*dr_create_flow_tbl)(void *domain, uint32_t level);
236 int (*dr_destroy_flow_tbl)(void *tbl);
237 void *(*dr_create_domain)(struct ibv_context *ctx,
238 enum mlx5dv_dr_domain_type domain);
239 int (*dr_destroy_domain)(void *domain);
240 int (*dr_sync_domain)(void *domain, uint32_t flags);
241 struct ibv_cq_ex *(*dv_create_cq)
242 (struct ibv_context *context,
243 struct ibv_cq_init_attr_ex *cq_attr,
244 struct mlx5dv_cq_init_attr *mlx5_cq_attr);
245 struct ibv_wq *(*dv_create_wq)
246 (struct ibv_context *context,
247 struct ibv_wq_init_attr *wq_attr,
248 struct mlx5dv_wq_init_attr *mlx5_wq_attr);
249 int (*dv_query_device)(struct ibv_context *ctx_in,
250 struct mlx5dv_context *attrs_out);
251 int (*dv_set_context_attr)(struct ibv_context *ibv_ctx,
252 enum mlx5dv_set_ctx_attr_type type,
254 int (*dv_init_obj)(struct mlx5dv_obj *obj, uint64_t obj_type);
255 struct ibv_qp *(*dv_create_qp)
256 (struct ibv_context *context,
257 struct ibv_qp_init_attr_ex *qp_init_attr_ex,
258 struct mlx5dv_qp_init_attr *dv_qp_init_attr);
259 void *(*dv_create_flow_matcher)
260 (struct ibv_context *context,
261 struct mlx5dv_flow_matcher_attr *matcher_attr,
263 void *(*dv_create_flow)(void *matcher, void *match_value,
264 size_t num_actions, void *actions[]);
265 void *(*dv_create_flow_action_counter)(void *obj, uint32_t offset);
266 void *(*dv_create_flow_action_dest_ibv_qp)(void *qp);
267 void *(*dv_create_flow_action_dest_devx_tir)(void *tir);
268 void *(*dv_create_flow_action_modify_header)
269 (struct ibv_context *ctx, enum mlx5dv_flow_table_type ft_type,
270 void *domain, uint64_t flags, size_t actions_sz,
272 void *(*dv_create_flow_action_packet_reformat)
273 (struct ibv_context *ctx,
274 enum mlx5dv_flow_action_packet_reformat_type reformat_type,
275 enum mlx5dv_flow_table_type ft_type,
276 struct mlx5dv_dr_domain *domain,
277 uint32_t flags, size_t data_sz, void *data);
278 void *(*dv_create_flow_action_tag)(uint32_t tag);
279 void *(*dv_create_flow_action_meter)
280 (struct mlx5dv_dr_flow_meter_attr *attr);
281 int (*dv_modify_flow_action_meter)(void *action,
282 struct mlx5dv_dr_flow_meter_attr *attr, uint64_t modify_bits);
283 void *(*dr_create_flow_action_default_miss)(void);
284 int (*dv_destroy_flow)(void *flow);
285 int (*dv_destroy_flow_matcher)(void *matcher);
286 struct ibv_context *(*dv_open_device)(struct ibv_device *device);
287 struct mlx5dv_var *(*dv_alloc_var)(struct ibv_context *context,
289 void (*dv_free_var)(struct mlx5dv_var *var);
290 struct mlx5dv_devx_uar *(*devx_alloc_uar)(struct ibv_context *context,
292 void (*devx_free_uar)(struct mlx5dv_devx_uar *devx_uar);
293 struct mlx5dv_devx_obj *(*devx_obj_create)
294 (struct ibv_context *ctx,
295 const void *in, size_t inlen,
296 void *out, size_t outlen);
297 int (*devx_obj_destroy)(struct mlx5dv_devx_obj *obj);
298 int (*devx_obj_query)(struct mlx5dv_devx_obj *obj,
299 const void *in, size_t inlen,
300 void *out, size_t outlen);
301 int (*devx_obj_modify)(struct mlx5dv_devx_obj *obj,
302 const void *in, size_t inlen,
303 void *out, size_t outlen);
304 int (*devx_general_cmd)(struct ibv_context *context,
305 const void *in, size_t inlen,
306 void *out, size_t outlen);
307 struct mlx5dv_devx_cmd_comp *(*devx_create_cmd_comp)
308 (struct ibv_context *context);
309 void (*devx_destroy_cmd_comp)(struct mlx5dv_devx_cmd_comp *cmd_comp);
310 int (*devx_obj_query_async)(struct mlx5dv_devx_obj *obj,
311 const void *in, size_t inlen,
312 size_t outlen, uint64_t wr_id,
313 struct mlx5dv_devx_cmd_comp *cmd_comp);
314 int (*devx_get_async_cmd_comp)(struct mlx5dv_devx_cmd_comp *cmd_comp,
315 struct mlx5dv_devx_async_cmd_hdr *resp,
316 size_t cmd_resp_len);
317 struct mlx5dv_devx_umem *(*devx_umem_reg)(struct ibv_context *context,
318 void *addr, size_t size,
320 int (*devx_umem_dereg)(struct mlx5dv_devx_umem *dv_devx_umem);
321 int (*devx_qp_query)(struct ibv_qp *qp,
322 const void *in, size_t inlen,
323 void *out, size_t outlen);
324 int (*devx_wq_query)(struct ibv_wq *wq, const void *in, size_t inlen,
325 void *out, size_t outlen);
326 int (*devx_port_query)(struct ibv_context *ctx,
328 struct mlx5_port_info *info);
329 int (*dr_dump_domain)(FILE *file, void *domain);
330 int (*dr_dump_rule)(FILE *file, void *rule);
331 int (*devx_query_eqn)(struct ibv_context *context, uint32_t cpus,
333 struct mlx5dv_devx_event_channel *(*devx_create_event_channel)
334 (struct ibv_context *context, int flags);
335 void (*devx_destroy_event_channel)
336 (struct mlx5dv_devx_event_channel *event_channel);
337 int (*devx_subscribe_devx_event)
338 (struct mlx5dv_devx_event_channel *event_channel,
339 struct mlx5dv_devx_obj *obj,
341 uint16_t events_num[],
343 int (*devx_subscribe_devx_event_fd)
344 (struct mlx5dv_devx_event_channel *event_channel,
346 struct mlx5dv_devx_obj *obj,
348 ssize_t (*devx_get_event)
349 (struct mlx5dv_devx_event_channel *event_channel,
350 struct mlx5dv_devx_async_event_hdr *event_data,
351 size_t event_resp_len);
352 void (*dr_reclaim_domain_memory)(void *domain, uint32_t enable);
353 void (*dr_allow_duplicate_rules)(void *domain, uint32_t allow);
354 struct mlx5dv_pp *(*dv_alloc_pp)(struct ibv_context *context,
355 size_t pp_context_sz,
356 const void *pp_context,
358 void (*dv_free_pp)(struct mlx5dv_pp *pp);
359 void *(*dr_create_flow_action_sampler)
360 (struct mlx5dv_dr_flow_sampler_attr *attr);
361 void *(*dr_create_flow_action_dest_array)
364 struct mlx5dv_dr_action_dest_attr *dests[]);
365 void *(*dv_create_flow_action_aso)
366 (struct mlx5dv_dr_domain *domain, void *aso_obj,
367 uint32_t offset, uint32_t flags, uint8_t return_reg_c);
370 extern const struct mlx5_glue *mlx5_glue;
372 #endif /* MLX5_GLUE_H_ */