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; };
71 #ifndef HAVE_IBV_DEVX_ASYNC
72 struct mlx5dv_devx_cmd_comp;
73 struct mlx5dv_devx_async_cmd_hdr;
76 #ifndef HAVE_MLX5DV_DR
77 enum mlx5dv_dr_domain_type { unused, };
78 struct mlx5dv_dr_domain;
81 #ifndef HAVE_MLX5DV_DR_DEVX_PORT
82 struct mlx5dv_devx_port;
85 #ifndef HAVE_MLX5_DR_CREATE_ACTION_FLOW_METER
86 struct mlx5dv_dr_flow_meter_attr;
89 /* LIB_GLUE_VERSION must be updated every time this structure is modified. */
92 int (*fork_init)(void);
93 struct ibv_pd *(*alloc_pd)(struct ibv_context *context);
94 int (*dealloc_pd)(struct ibv_pd *pd);
95 struct ibv_device **(*get_device_list)(int *num_devices);
96 void (*free_device_list)(struct ibv_device **list);
97 struct ibv_context *(*open_device)(struct ibv_device *device);
98 int (*close_device)(struct ibv_context *context);
99 int (*query_device)(struct ibv_context *context,
100 struct ibv_device_attr *device_attr);
101 int (*query_device_ex)(struct ibv_context *context,
102 const struct ibv_query_device_ex_input *input,
103 struct ibv_device_attr_ex *attr);
104 int (*query_rt_values_ex)(struct ibv_context *context,
105 struct ibv_values_ex *values);
106 int (*query_port)(struct ibv_context *context, uint8_t port_num,
107 struct ibv_port_attr *port_attr);
108 struct ibv_comp_channel *(*create_comp_channel)
109 (struct ibv_context *context);
110 int (*destroy_comp_channel)(struct ibv_comp_channel *channel);
111 struct ibv_cq *(*create_cq)(struct ibv_context *context, int cqe,
113 struct ibv_comp_channel *channel,
115 int (*destroy_cq)(struct ibv_cq *cq);
116 int (*get_cq_event)(struct ibv_comp_channel *channel,
117 struct ibv_cq **cq, void **cq_context);
118 void (*ack_cq_events)(struct ibv_cq *cq, unsigned int nevents);
119 struct ibv_rwq_ind_table *(*create_rwq_ind_table)
120 (struct ibv_context *context,
121 struct ibv_rwq_ind_table_init_attr *init_attr);
122 int (*destroy_rwq_ind_table)(struct ibv_rwq_ind_table *rwq_ind_table);
123 struct ibv_wq *(*create_wq)(struct ibv_context *context,
124 struct ibv_wq_init_attr *wq_init_attr);
125 int (*destroy_wq)(struct ibv_wq *wq);
126 int (*modify_wq)(struct ibv_wq *wq, struct ibv_wq_attr *wq_attr);
127 struct ibv_flow *(*create_flow)(struct ibv_qp *qp,
128 struct ibv_flow_attr *flow);
129 int (*destroy_flow)(struct ibv_flow *flow_id);
130 int (*destroy_flow_action)(void *action);
131 struct ibv_qp *(*create_qp)(struct ibv_pd *pd,
132 struct ibv_qp_init_attr *qp_init_attr);
133 struct ibv_qp *(*create_qp_ex)
134 (struct ibv_context *context,
135 struct ibv_qp_init_attr_ex *qp_init_attr_ex);
136 int (*destroy_qp)(struct ibv_qp *qp);
137 int (*modify_qp)(struct ibv_qp *qp, struct ibv_qp_attr *attr,
139 struct ibv_mr *(*reg_mr)(struct ibv_pd *pd, void *addr,
140 size_t length, int access);
141 int (*dereg_mr)(struct ibv_mr *mr);
142 struct ibv_counter_set *(*create_counter_set)
143 (struct ibv_context *context,
144 struct ibv_counter_set_init_attr *init_attr);
145 int (*destroy_counter_set)(struct ibv_counter_set *cs);
146 int (*describe_counter_set)
147 (struct ibv_context *context,
148 uint16_t counter_set_id,
149 struct ibv_counter_set_description *cs_desc);
150 int (*query_counter_set)(struct ibv_query_counter_set_attr *query_attr,
151 struct ibv_counter_set_data *cs_data);
152 struct ibv_counters *(*create_counters)
153 (struct ibv_context *context,
154 struct ibv_counters_init_attr *init_attr);
155 int (*destroy_counters)(struct ibv_counters *counters);
156 int (*attach_counters)(struct ibv_counters *counters,
157 struct ibv_counter_attach_attr *attr,
158 struct ibv_flow *flow);
159 int (*query_counters)(struct ibv_counters *counters,
160 uint64_t *counters_value,
163 void (*ack_async_event)(struct ibv_async_event *event);
164 int (*get_async_event)(struct ibv_context *context,
165 struct ibv_async_event *event);
166 const char *(*port_state_str)(enum ibv_port_state port_state);
167 struct ibv_cq *(*cq_ex_to_cq)(struct ibv_cq_ex *cq);
168 void *(*dr_create_flow_action_dest_flow_tbl)(void *tbl);
169 void *(*dr_create_flow_action_dest_port)(void *domain,
171 void *(*dr_create_flow_action_drop)();
172 void *(*dr_create_flow_action_push_vlan)
173 (struct mlx5dv_dr_domain *domain,
174 rte_be32_t vlan_tag);
175 void *(*dr_create_flow_action_pop_vlan)();
176 void *(*dr_create_flow_tbl)(void *domain, uint32_t level);
177 int (*dr_destroy_flow_tbl)(void *tbl);
178 void *(*dr_create_domain)(struct ibv_context *ctx,
179 enum mlx5dv_dr_domain_type domain);
180 int (*dr_destroy_domain)(void *domain);
181 struct ibv_cq_ex *(*dv_create_cq)
182 (struct ibv_context *context,
183 struct ibv_cq_init_attr_ex *cq_attr,
184 struct mlx5dv_cq_init_attr *mlx5_cq_attr);
185 struct ibv_wq *(*dv_create_wq)
186 (struct ibv_context *context,
187 struct ibv_wq_init_attr *wq_attr,
188 struct mlx5dv_wq_init_attr *mlx5_wq_attr);
189 int (*dv_query_device)(struct ibv_context *ctx_in,
190 struct mlx5dv_context *attrs_out);
191 int (*dv_set_context_attr)(struct ibv_context *ibv_ctx,
192 enum mlx5dv_set_ctx_attr_type type,
194 int (*dv_init_obj)(struct mlx5dv_obj *obj, uint64_t obj_type);
195 struct ibv_qp *(*dv_create_qp)
196 (struct ibv_context *context,
197 struct ibv_qp_init_attr_ex *qp_init_attr_ex,
198 struct mlx5dv_qp_init_attr *dv_qp_init_attr);
199 void *(*dv_create_flow_matcher)
200 (struct ibv_context *context,
201 struct mlx5dv_flow_matcher_attr *matcher_attr,
203 void *(*dv_create_flow)(void *matcher, void *match_value,
204 size_t num_actions, void *actions[]);
205 void *(*dv_create_flow_action_counter)(void *obj, uint32_t offset);
206 void *(*dv_create_flow_action_dest_ibv_qp)(void *qp);
207 void *(*dv_create_flow_action_dest_devx_tir)(void *tir);
208 void *(*dv_create_flow_action_modify_header)
209 (struct ibv_context *ctx, enum mlx5dv_flow_table_type ft_type,
210 void *domain, uint64_t flags, size_t actions_sz,
212 void *(*dv_create_flow_action_packet_reformat)
213 (struct ibv_context *ctx,
214 enum mlx5dv_flow_action_packet_reformat_type reformat_type,
215 enum mlx5dv_flow_table_type ft_type,
216 struct mlx5dv_dr_domain *domain,
217 uint32_t flags, size_t data_sz, void *data);
218 void *(*dv_create_flow_action_tag)(uint32_t tag);
219 void *(*dv_create_flow_action_meter)
220 (struct mlx5dv_dr_flow_meter_attr *attr);
221 int (*dv_modify_flow_action_meter)(void *action,
222 struct mlx5dv_dr_flow_meter_attr *attr, uint64_t modify_bits);
223 int (*dv_destroy_flow)(void *flow);
224 int (*dv_destroy_flow_matcher)(void *matcher);
225 struct ibv_context *(*dv_open_device)(struct ibv_device *device);
226 struct mlx5dv_devx_obj *(*devx_obj_create)
227 (struct ibv_context *ctx,
228 const void *in, size_t inlen,
229 void *out, size_t outlen);
230 int (*devx_obj_destroy)(struct mlx5dv_devx_obj *obj);
231 int (*devx_obj_query)(struct mlx5dv_devx_obj *obj,
232 const void *in, size_t inlen,
233 void *out, size_t outlen);
234 int (*devx_obj_modify)(struct mlx5dv_devx_obj *obj,
235 const void *in, size_t inlen,
236 void *out, size_t outlen);
237 int (*devx_general_cmd)(struct ibv_context *context,
238 const void *in, size_t inlen,
239 void *out, size_t outlen);
240 struct mlx5dv_devx_cmd_comp *(*devx_create_cmd_comp)
241 (struct ibv_context *context);
242 void (*devx_destroy_cmd_comp)(struct mlx5dv_devx_cmd_comp *cmd_comp);
243 int (*devx_obj_query_async)(struct mlx5dv_devx_obj *obj,
244 const void *in, size_t inlen,
245 size_t outlen, uint64_t wr_id,
246 struct mlx5dv_devx_cmd_comp *cmd_comp);
247 int (*devx_get_async_cmd_comp)(struct mlx5dv_devx_cmd_comp *cmd_comp,
248 struct mlx5dv_devx_async_cmd_hdr *resp,
249 size_t cmd_resp_len);
250 struct mlx5dv_devx_umem *(*devx_umem_reg)(struct ibv_context *context,
251 void *addr, size_t size,
253 int (*devx_umem_dereg)(struct mlx5dv_devx_umem *dv_devx_umem);
254 int (*devx_qp_query)(struct ibv_qp *qp,
255 const void *in, size_t inlen,
256 void *out, size_t outlen);
257 int (*devx_port_query)(struct ibv_context *ctx,
259 struct mlx5dv_devx_port *mlx5_devx_port);
260 int (*dr_dump_domain)(FILE *file, void *domain);
263 const struct mlx5_glue *mlx5_glue;
265 #endif /* MLX5_GLUE_H_ */