xref: /dpdk/drivers/common/mlx5/linux/mlx5_glue.h (revision af0785a2447b307965377b62f46a5f39457a85a3)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2018 6WIND S.A.
3  * Copyright 2018 Mellanox Technologies, Ltd
4  */
5 
6 #ifndef MLX5_GLUE_H_
7 #define MLX5_GLUE_H_
8 
9 #include <stddef.h>
10 #include <stdint.h>
11 /* Verbs headers do not support -pedantic. */
12 #ifdef PEDANTIC
13 #pragma GCC diagnostic ignored "-Wpedantic"
14 #endif
15 #include <infiniband/mlx5dv.h>
16 #include <infiniband/verbs.h>
17 #ifdef PEDANTIC
18 #pragma GCC diagnostic error "-Wpedantic"
19 #endif
20 
21 #include <rte_byteorder.h>
22 
23 #include "mlx5_autoconf.h"
24 
25 #ifndef MLX5_GLUE_VERSION
26 #define MLX5_GLUE_VERSION ""
27 #endif
28 
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;
35 #endif
36 
37 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
38 struct ibv_counters;
39 struct ibv_counters_init_attr;
40 struct ibv_counter_attach_attr;
41 #endif
42 
43 #ifndef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
44 struct mlx5dv_qp_init_attr;
45 #endif
46 
47 #ifndef HAVE_IBV_DEVICE_STRIDING_RQ_SUPPORT
48 struct mlx5dv_wq_init_attr;
49 #endif
50 
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, };
60 #endif
61 
62 #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
63 #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
64 #endif
65 
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; };
70 #endif
71 
72 #ifndef HAVE_IBV_DEVX_ASYNC
73 struct mlx5dv_devx_cmd_comp;
74 struct mlx5dv_devx_async_cmd_hdr;
75 #endif
76 
77 #ifndef HAVE_MLX5DV_DR
78 enum  mlx5dv_dr_domain_type { unused, };
79 struct mlx5dv_dr_domain;
80 struct mlx5dv_dr_action;
81 #define MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL 1
82 #endif
83 
84 #ifndef HAVE_MLX5DV_DR_DEVX_PORT
85 struct mlx5dv_devx_port;
86 #endif
87 
88 #ifndef HAVE_MLX5DV_DR_DEVX_PORT_V35
89 struct mlx5dv_port;
90 #endif
91 
92 #define MLX5_PORT_QUERY_VPORT (1u << 0)
93 #define MLX5_PORT_QUERY_REG_C0 (1u << 1)
94 #define MLX5_PORT_QUERY_ESW_OWNER_VHCA_ID (1u << 2)
95 
96 struct mlx5_port_info {
97 	uint16_t query_flags;
98 	uint16_t vport_id; /* Associated VF vport index (if any). */
99 	uint16_t esw_owner_vhca_id; /* Associated the esw_owner that this VF belongs to. */
100 	uint32_t vport_meta_tag; /* Used for vport index match ove VF LAG. */
101 	uint32_t vport_meta_mask; /* Used for vport index field match mask. */
102 };
103 
104 #ifndef HAVE_MLX5_DR_CREATE_ACTION_FLOW_METER
105 struct mlx5dv_dr_flow_meter_attr;
106 #endif
107 
108 #ifndef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE
109 struct mlx5dv_dr_flow_sampler_attr {
110 	uint32_t sample_ratio;
111 	void *default_next_table;
112 	size_t num_sample_actions;
113 	struct mlx5dv_dr_action **sample_actions;
114 	uint64_t action;
115 };
116 #endif
117 
118 #ifndef HAVE_MLX5_DR_CREATE_ACTION_DEST_ARRAY
119 enum mlx5dv_dr_action_dest_type {
120 	MLX5DV_DR_ACTION_DEST,
121 	MLX5DV_DR_ACTION_DEST_REFORMAT,
122 };
123 struct mlx5dv_dr_action_dest_reformat {
124 	struct mlx5dv_dr_action *reformat;
125 	struct mlx5dv_dr_action *dest;
126 };
127 struct mlx5dv_dr_action_dest_attr {
128 	enum mlx5dv_dr_action_dest_type type;
129 	union {
130 		struct mlx5dv_dr_action *dest;
131 		struct mlx5dv_dr_action_dest_reformat *dest_reformat;
132 	};
133 };
134 #endif
135 
136 #ifndef HAVE_IBV_DEVX_EVENT
137 struct mlx5dv_devx_event_channel { int fd; };
138 struct mlx5dv_devx_async_event_hdr;
139 #define MLX5DV_DEVX_CREATE_EVENT_CHANNEL_FLAGS_OMIT_EV_DATA 1
140 #endif
141 
142 #ifndef HAVE_IBV_VAR
143 struct mlx5dv_var { uint32_t page_id; uint32_t length; off_t mmap_off;
144 			uint64_t comp_mask; };
145 #endif
146 
147 #ifndef HAVE_IBV_RELAXED_ORDERING
148 #define IBV_ACCESS_RELAXED_ORDERING 0
149 #endif
150 
151 struct mlx5_glue {
152 	const char *version;
153 	int (*fork_init)(void);
154 	struct ibv_pd *(*alloc_pd)(struct ibv_context *context);
155 	int (*dealloc_pd)(struct ibv_pd *pd);
156 	struct ibv_pd *(*import_pd)(struct ibv_context *context,
157 				    uint32_t pd_handle);
158 	int (*unimport_pd)(struct ibv_pd *pd);
159 	struct ibv_device **(*get_device_list)(int *num_devices);
160 	void (*free_device_list)(struct ibv_device **list);
161 	struct ibv_context *(*open_device)(struct ibv_device *device);
162 	struct ibv_context *(*import_device)(int cmd_fd);
163 	int (*close_device)(struct ibv_context *context);
164 	int (*query_device)(struct ibv_context *context,
165 			    struct ibv_device_attr *device_attr);
166 	int (*query_device_ex)(struct ibv_context *context,
167 			       const struct ibv_query_device_ex_input *input,
168 			       struct ibv_device_attr_ex *attr);
169 	const char *(*get_device_name)(struct ibv_device *device);
170 	int (*query_rt_values_ex)(struct ibv_context *context,
171 			       struct ibv_values_ex *values);
172 	int (*query_port)(struct ibv_context *context, uint8_t port_num,
173 			  struct ibv_port_attr *port_attr);
174 	struct ibv_comp_channel *(*create_comp_channel)
175 		(struct ibv_context *context);
176 	int (*destroy_comp_channel)(struct ibv_comp_channel *channel);
177 	struct ibv_cq *(*create_cq)(struct ibv_context *context, int cqe,
178 				    void *cq_context,
179 				    struct ibv_comp_channel *channel,
180 				    int comp_vector);
181 	int (*destroy_cq)(struct ibv_cq *cq);
182 	int (*get_cq_event)(struct ibv_comp_channel *channel,
183 			    struct ibv_cq **cq, void **cq_context);
184 	void (*ack_cq_events)(struct ibv_cq *cq, unsigned int nevents);
185 	struct ibv_rwq_ind_table *(*create_rwq_ind_table)
186 		(struct ibv_context *context,
187 		 struct ibv_rwq_ind_table_init_attr *init_attr);
188 	int (*destroy_rwq_ind_table)(struct ibv_rwq_ind_table *rwq_ind_table);
189 	struct ibv_wq *(*create_wq)(struct ibv_context *context,
190 				    struct ibv_wq_init_attr *wq_init_attr);
191 	int (*destroy_wq)(struct ibv_wq *wq);
192 	int (*modify_wq)(struct ibv_wq *wq, struct ibv_wq_attr *wq_attr);
193 	struct ibv_flow *(*create_flow)(struct ibv_qp *qp,
194 					struct ibv_flow_attr *flow);
195 	int (*destroy_flow)(struct ibv_flow *flow_id);
196 	int (*destroy_flow_action)(void *action);
197 	struct ibv_qp *(*create_qp)(struct ibv_pd *pd,
198 				    struct ibv_qp_init_attr *qp_init_attr);
199 	struct ibv_qp *(*create_qp_ex)
200 		(struct ibv_context *context,
201 		 struct ibv_qp_init_attr_ex *qp_init_attr_ex);
202 	int (*destroy_qp)(struct ibv_qp *qp);
203 	int (*modify_qp)(struct ibv_qp *qp, struct ibv_qp_attr *attr,
204 			 int attr_mask);
205 	struct ibv_mr *(*reg_mr)(struct ibv_pd *pd, void *addr,
206 				 size_t length, int access);
207 	struct ibv_mr *(*reg_mr_iova)(struct ibv_pd *pd, void *addr,
208 				      size_t length, uint64_t iova,
209 				      int access);
210 	struct ibv_mr *(*alloc_null_mr)(struct ibv_pd *pd);
211 	int (*dereg_mr)(struct ibv_mr *mr);
212 	struct ibv_counter_set *(*create_counter_set)
213 		(struct ibv_context *context,
214 		 struct ibv_counter_set_init_attr *init_attr);
215 	int (*destroy_counter_set)(struct ibv_counter_set *cs);
216 	int (*describe_counter_set)
217 		(struct ibv_context *context,
218 		 uint16_t counter_set_id,
219 		 struct ibv_counter_set_description *cs_desc);
220 	int (*query_counter_set)(struct ibv_query_counter_set_attr *query_attr,
221 				 struct ibv_counter_set_data *cs_data);
222 	struct ibv_counters *(*create_counters)
223 		(struct ibv_context *context,
224 		 struct ibv_counters_init_attr *init_attr);
225 	int (*destroy_counters)(struct ibv_counters *counters);
226 	int (*attach_counters)(struct ibv_counters *counters,
227 			       struct ibv_counter_attach_attr *attr,
228 			       struct ibv_flow *flow);
229 	int (*query_counters)(struct ibv_counters *counters,
230 			      uint64_t *counters_value,
231 			      uint32_t ncounters,
232 			      uint32_t flags);
233 	void (*ack_async_event)(struct ibv_async_event *event);
234 	int (*get_async_event)(struct ibv_context *context,
235 			       struct ibv_async_event *event);
236 	const char *(*port_state_str)(enum ibv_port_state port_state);
237 	struct ibv_cq *(*cq_ex_to_cq)(struct ibv_cq_ex *cq);
238 	void *(*dr_create_flow_action_dest_flow_tbl)(void *tbl);
239 	void *(*dr_create_flow_action_dest_port)(void *domain,
240 						 uint32_t port);
241 	void *(*dr_create_flow_action_drop)(void);
242 	void *(*dr_create_flow_action_push_vlan)
243 					(struct mlx5dv_dr_domain *domain,
244 					 rte_be32_t vlan_tag);
245 	void *(*dr_create_flow_action_pop_vlan)(void);
246 	void *(*dr_create_flow_tbl)(void *domain, uint32_t level);
247 	int (*dr_destroy_flow_tbl)(void *tbl);
248 	void *(*dr_create_domain)(struct ibv_context *ctx,
249 				  enum mlx5dv_dr_domain_type domain);
250 	int (*dr_destroy_domain)(void *domain);
251 	int (*dr_sync_domain)(void *domain, uint32_t flags);
252 	struct ibv_cq_ex *(*dv_create_cq)
253 		(struct ibv_context *context,
254 		 struct ibv_cq_init_attr_ex *cq_attr,
255 		 struct mlx5dv_cq_init_attr *mlx5_cq_attr);
256 	struct ibv_wq *(*dv_create_wq)
257 		(struct ibv_context *context,
258 		 struct ibv_wq_init_attr *wq_attr,
259 		 struct mlx5dv_wq_init_attr *mlx5_wq_attr);
260 	int (*dv_query_device)(struct ibv_context *ctx_in,
261 			       struct mlx5dv_context *attrs_out);
262 	int (*dv_set_context_attr)(struct ibv_context *ibv_ctx,
263 				   enum mlx5dv_set_ctx_attr_type type,
264 				   void *attr);
265 	int (*dv_init_obj)(struct mlx5dv_obj *obj, uint64_t obj_type);
266 	struct ibv_qp *(*dv_create_qp)
267 		(struct ibv_context *context,
268 		 struct ibv_qp_init_attr_ex *qp_init_attr_ex,
269 		 struct mlx5dv_qp_init_attr *dv_qp_init_attr);
270 	void *(*dv_create_flow_matcher)
271 		(struct ibv_context *context,
272 		 struct mlx5dv_flow_matcher_attr *matcher_attr,
273 		 void *tbl);
274 	void *(*dv_create_flow_matcher_root)
275 		(struct ibv_context *context,
276 		 struct mlx5dv_flow_matcher_attr *matcher_attr);
277 	void *(*dv_create_flow)(void *matcher, void *match_value,
278 			  size_t num_actions, void *actions[]);
279 	void *(*dv_create_flow_root)(void *matcher, void *match_value,
280 				     size_t num_actions, void *actions);
281 	void *(*dv_create_flow_action_counter)(void *obj, uint32_t  offset);
282 	void *(*dv_create_flow_action_dest_ibv_qp)(void *qp);
283 	void *(*dv_create_flow_action_dest_devx_tir)(void *tir);
284 	void *(*dv_create_flow_action_modify_header)
285 		(struct ibv_context *ctx, enum mlx5dv_flow_table_type ft_type,
286 		 void *domain, uint64_t flags, size_t actions_sz,
287 		 uint64_t actions[]);
288 	void *(*dv_create_flow_action_modify_header_root)
289 		(struct ibv_context *ctx, size_t actions_sz, uint64_t actions[],
290 		 enum mlx5dv_flow_table_type ft_type);
291 	void *(*dv_create_flow_action_packet_reformat)
292 		(struct ibv_context *ctx,
293 		 enum mlx5dv_flow_action_packet_reformat_type reformat_type,
294 		 enum mlx5dv_flow_table_type ft_type,
295 		 struct mlx5dv_dr_domain *domain,
296 		 uint32_t flags, size_t data_sz, void *data);
297 	void *(*dv_create_flow_action_packet_reformat_root)
298 		(struct ibv_context *ctx,
299 		 size_t data_sz, void *data,
300 		 enum mlx5dv_flow_action_packet_reformat_type reformat_type,
301 		 enum mlx5dv_flow_table_type ft_type);
302 	void *(*dv_create_flow_action_tag)(uint32_t tag);
303 	void *(*dv_create_flow_action_meter)
304 		(struct mlx5dv_dr_flow_meter_attr *attr);
305 	int (*dv_modify_flow_action_meter)(void *action,
306 		struct mlx5dv_dr_flow_meter_attr *attr, uint64_t modify_bits);
307 	void *(*dr_create_flow_action_default_miss)(void);
308 	int (*dv_destroy_flow)(void *flow);
309 	int (*dv_destroy_flow_matcher)(void *matcher);
310 	int (*dv_destroy_flow_matcher_root)(void *matcher);
311 	struct ibv_context *(*dv_open_device)(struct ibv_device *device);
312 	struct mlx5dv_var *(*dv_alloc_var)(struct ibv_context *context,
313 					   uint32_t flags);
314 	void (*dv_free_var)(struct mlx5dv_var *var);
315 	struct mlx5dv_devx_uar *(*devx_alloc_uar)(struct ibv_context *context,
316 						  uint32_t flags);
317 	void (*devx_free_uar)(struct mlx5dv_devx_uar *devx_uar);
318 	struct mlx5dv_devx_obj *(*devx_obj_create)
319 					(struct ibv_context *ctx,
320 					 const void *in, size_t inlen,
321 					 void *out, size_t outlen);
322 	int (*devx_obj_destroy)(struct mlx5dv_devx_obj *obj);
323 	int (*devx_obj_query)(struct mlx5dv_devx_obj *obj,
324 			      const void *in, size_t inlen,
325 			      void *out, size_t outlen);
326 	int (*devx_obj_modify)(struct mlx5dv_devx_obj *obj,
327 			       const void *in, size_t inlen,
328 			       void *out, size_t outlen);
329 	int (*devx_general_cmd)(struct ibv_context *context,
330 				const void *in, size_t inlen,
331 				void *out, size_t outlen);
332 	struct mlx5dv_devx_cmd_comp *(*devx_create_cmd_comp)
333 					(struct ibv_context *context);
334 	void (*devx_destroy_cmd_comp)(struct mlx5dv_devx_cmd_comp *cmd_comp);
335 	int (*devx_obj_query_async)(struct mlx5dv_devx_obj *obj,
336 				    const void *in, size_t inlen,
337 				    size_t outlen, uint64_t wr_id,
338 				    struct mlx5dv_devx_cmd_comp *cmd_comp);
339 	int (*devx_get_async_cmd_comp)(struct mlx5dv_devx_cmd_comp *cmd_comp,
340 				       struct mlx5dv_devx_async_cmd_hdr *resp,
341 				       size_t cmd_resp_len);
342 	struct mlx5dv_devx_umem *(*devx_umem_reg)(struct ibv_context *context,
343 						  void *addr, size_t size,
344 						  uint32_t access);
345 	int (*devx_umem_dereg)(struct mlx5dv_devx_umem *dv_devx_umem);
346 	int (*devx_qp_query)(struct ibv_qp *qp,
347 			     const void *in, size_t inlen,
348 			     void *out, size_t outlen);
349 	int (*devx_wq_query)(struct ibv_wq *wq, const void *in, size_t inlen,
350 			     void *out, size_t outlen);
351 	int (*devx_port_query)(struct ibv_context *ctx,
352 			       uint32_t port_num,
353 			       struct mlx5_port_info *info);
354 	int (*dr_dump_domain)(FILE *file, void *domain);
355 	int (*dr_dump_rule)(FILE *file, void *rule);
356 	int (*devx_query_eqn)(struct ibv_context *context, uint32_t cpus,
357 			      uint32_t *eqn);
358 	struct mlx5dv_devx_event_channel *(*devx_create_event_channel)
359 				(struct ibv_context *context, int flags);
360 	void (*devx_destroy_event_channel)
361 			(struct mlx5dv_devx_event_channel *event_channel);
362 	int (*devx_subscribe_devx_event)
363 			(struct mlx5dv_devx_event_channel *event_channel,
364 			 struct mlx5dv_devx_obj *obj,
365 			 uint16_t events_sz,
366 			 uint16_t events_num[],
367 			 uint64_t cookie);
368 	int (*devx_subscribe_devx_event_fd)
369 			(struct mlx5dv_devx_event_channel *event_channel,
370 			 int fd,
371 			 struct mlx5dv_devx_obj *obj,
372 			 uint16_t event_num);
373 	ssize_t (*devx_get_event)
374 			(struct mlx5dv_devx_event_channel *event_channel,
375 			 struct mlx5dv_devx_async_event_hdr *event_data,
376 			 size_t event_resp_len);
377 	void (*dr_reclaim_domain_memory)(void *domain, uint32_t enable);
378 	void (*dr_allow_duplicate_rules)(void *domain, uint32_t allow);
379 	struct mlx5dv_pp *(*dv_alloc_pp)(struct ibv_context *context,
380 					 size_t pp_context_sz,
381 					 const void *pp_context,
382 					 uint32_t flags);
383 	void (*dv_free_pp)(struct mlx5dv_pp *pp);
384 	void *(*dr_create_flow_action_sampler)
385 			(struct mlx5dv_dr_flow_sampler_attr *attr);
386 	void *(*dr_create_flow_action_dest_array)
387 			(void *domain,
388 			 size_t num_dest,
389 			 struct mlx5dv_dr_action_dest_attr *dests[]);
390 	void *(*dv_create_flow_action_aso)
391 			(struct mlx5dv_dr_domain *domain, void *aso_obj,
392 			 uint32_t offset, uint32_t flags, uint8_t return_reg_c);
393 	void *(*dr_create_flow_action_send_to_kernel)(void *tbl,
394 						      uint16_t priority);
395 };
396 
397 extern const struct mlx5_glue *mlx5_glue;
398 
399 #endif /* MLX5_GLUE_H_ */
400