7fa83497dc5dfa0afaf26cb99db28c5c2cae0728
[dpdk.git] / drivers / net / mlx5 / mlx5_glue.h
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
12 #include "rte_byteorder.h"
13
14 /* Verbs headers do not support -pedantic. */
15 #ifdef PEDANTIC
16 #pragma GCC diagnostic ignored "-Wpedantic"
17 #endif
18 #include <infiniband/mlx5dv.h>
19 #include <infiniband/verbs.h>
20 #ifdef PEDANTIC
21 #pragma GCC diagnostic error "-Wpedantic"
22 #endif
23
24 #ifndef MLX5_GLUE_VERSION
25 #define MLX5_GLUE_VERSION ""
26 #endif
27
28 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V42
29 struct ibv_counter_set;
30 struct ibv_counter_set_data;
31 struct ibv_counter_set_description;
32 struct ibv_counter_set_init_attr;
33 struct ibv_query_counter_set_attr;
34 #endif
35
36 #ifndef HAVE_IBV_DEVICE_COUNTERS_SET_V45
37 struct ibv_counters;
38 struct ibv_counters_init_attr;
39 struct ibv_counter_attach_attr;
40 #endif
41
42 #ifndef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
43 struct mlx5dv_qp_init_attr;
44 #endif
45
46 #ifndef HAVE_IBV_DEVICE_STRIDING_RQ_SUPPORT
47 struct mlx5dv_wq_init_attr;
48 #endif
49
50 #ifndef HAVE_IBV_FLOW_DV_SUPPORT
51 struct mlx5dv_flow_matcher;
52 struct mlx5dv_flow_matcher_attr;
53 struct mlx5dv_flow_action_attr;
54 struct mlx5dv_flow_match_parameters;
55 struct ibv_flow_action;
56 enum mlx5dv_flow_action_packet_reformat_type { packet_reformat_type = 0, };
57 enum mlx5dv_flow_table_type { flow_table_type = 0, };
58 #endif
59
60 #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
61 #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
62 #endif
63
64 #ifndef HAVE_IBV_DEVX_OBJ
65 struct mlx5dv_devx_obj;
66 struct mlx5dv_devx_umem { uint32_t umem_id; };
67 #endif
68
69 #ifndef HAVE_IBV_DEVX_ASYNC
70 struct mlx5dv_devx_cmd_comp;
71 struct mlx5dv_devx_async_cmd_hdr;
72 #endif
73
74 #ifndef HAVE_MLX5DV_DR
75 enum  mlx5dv_dr_domain_type { unused, };
76 struct mlx5dv_dr_domain;
77 #endif
78
79 #ifndef HAVE_MLX5DV_DR_DEVX_PORT
80 struct mlx5dv_devx_port;
81 #endif
82
83 /* LIB_GLUE_VERSION must be updated every time this structure is modified. */
84 struct mlx5_glue {
85         const char *version;
86         int (*fork_init)(void);
87         struct ibv_pd *(*alloc_pd)(struct ibv_context *context);
88         int (*dealloc_pd)(struct ibv_pd *pd);
89         struct ibv_device **(*get_device_list)(int *num_devices);
90         void (*free_device_list)(struct ibv_device **list);
91         struct ibv_context *(*open_device)(struct ibv_device *device);
92         int (*close_device)(struct ibv_context *context);
93         int (*query_device)(struct ibv_context *context,
94                             struct ibv_device_attr *device_attr);
95         int (*query_device_ex)(struct ibv_context *context,
96                                const struct ibv_query_device_ex_input *input,
97                                struct ibv_device_attr_ex *attr);
98         int (*query_rt_values_ex)(struct ibv_context *context,
99                                struct ibv_values_ex *values);
100         int (*query_port)(struct ibv_context *context, uint8_t port_num,
101                           struct ibv_port_attr *port_attr);
102         struct ibv_comp_channel *(*create_comp_channel)
103                 (struct ibv_context *context);
104         int (*destroy_comp_channel)(struct ibv_comp_channel *channel);
105         struct ibv_cq *(*create_cq)(struct ibv_context *context, int cqe,
106                                     void *cq_context,
107                                     struct ibv_comp_channel *channel,
108                                     int comp_vector);
109         int (*destroy_cq)(struct ibv_cq *cq);
110         int (*get_cq_event)(struct ibv_comp_channel *channel,
111                             struct ibv_cq **cq, void **cq_context);
112         void (*ack_cq_events)(struct ibv_cq *cq, unsigned int nevents);
113         struct ibv_rwq_ind_table *(*create_rwq_ind_table)
114                 (struct ibv_context *context,
115                  struct ibv_rwq_ind_table_init_attr *init_attr);
116         int (*destroy_rwq_ind_table)(struct ibv_rwq_ind_table *rwq_ind_table);
117         struct ibv_wq *(*create_wq)(struct ibv_context *context,
118                                     struct ibv_wq_init_attr *wq_init_attr);
119         int (*destroy_wq)(struct ibv_wq *wq);
120         int (*modify_wq)(struct ibv_wq *wq, struct ibv_wq_attr *wq_attr);
121         struct ibv_flow *(*create_flow)(struct ibv_qp *qp,
122                                         struct ibv_flow_attr *flow);
123         int (*destroy_flow)(struct ibv_flow *flow_id);
124         int (*destroy_flow_action)(void *action);
125         struct ibv_qp *(*create_qp)(struct ibv_pd *pd,
126                                     struct ibv_qp_init_attr *qp_init_attr);
127         struct ibv_qp *(*create_qp_ex)
128                 (struct ibv_context *context,
129                  struct ibv_qp_init_attr_ex *qp_init_attr_ex);
130         int (*destroy_qp)(struct ibv_qp *qp);
131         int (*modify_qp)(struct ibv_qp *qp, struct ibv_qp_attr *attr,
132                          int attr_mask);
133         struct ibv_mr *(*reg_mr)(struct ibv_pd *pd, void *addr,
134                                  size_t length, int access);
135         int (*dereg_mr)(struct ibv_mr *mr);
136         struct ibv_counter_set *(*create_counter_set)
137                 (struct ibv_context *context,
138                  struct ibv_counter_set_init_attr *init_attr);
139         int (*destroy_counter_set)(struct ibv_counter_set *cs);
140         int (*describe_counter_set)
141                 (struct ibv_context *context,
142                  uint16_t counter_set_id,
143                  struct ibv_counter_set_description *cs_desc);
144         int (*query_counter_set)(struct ibv_query_counter_set_attr *query_attr,
145                                  struct ibv_counter_set_data *cs_data);
146         struct ibv_counters *(*create_counters)
147                 (struct ibv_context *context,
148                  struct ibv_counters_init_attr *init_attr);
149         int (*destroy_counters)(struct ibv_counters *counters);
150         int (*attach_counters)(struct ibv_counters *counters,
151                                struct ibv_counter_attach_attr *attr,
152                                struct ibv_flow *flow);
153         int (*query_counters)(struct ibv_counters *counters,
154                               uint64_t *counters_value,
155                               uint32_t ncounters,
156                               uint32_t flags);
157         void (*ack_async_event)(struct ibv_async_event *event);
158         int (*get_async_event)(struct ibv_context *context,
159                                struct ibv_async_event *event);
160         const char *(*port_state_str)(enum ibv_port_state port_state);
161         struct ibv_cq *(*cq_ex_to_cq)(struct ibv_cq_ex *cq);
162         void *(*dr_create_flow_action_dest_flow_tbl)(void *tbl);
163         void *(*dr_create_flow_action_dest_vport)(void *domain, uint32_t vport);
164         void *(*dr_create_flow_action_drop)();
165         void *(*dr_create_flow_action_push_vlan)
166                                         (struct mlx5dv_dr_domain *domain,
167                                          rte_be32_t vlan_tag);
168         void *(*dr_create_flow_action_pop_vlan)();
169         void *(*dr_create_flow_tbl)(void *domain, uint32_t level);
170         int (*dr_destroy_flow_tbl)(void *tbl);
171         void *(*dr_create_domain)(struct ibv_context *ctx,
172                                   enum mlx5dv_dr_domain_type domain);
173         int (*dr_destroy_domain)(void *domain);
174         struct ibv_cq_ex *(*dv_create_cq)
175                 (struct ibv_context *context,
176                  struct ibv_cq_init_attr_ex *cq_attr,
177                  struct mlx5dv_cq_init_attr *mlx5_cq_attr);
178         struct ibv_wq *(*dv_create_wq)
179                 (struct ibv_context *context,
180                  struct ibv_wq_init_attr *wq_attr,
181                  struct mlx5dv_wq_init_attr *mlx5_wq_attr);
182         int (*dv_query_device)(struct ibv_context *ctx_in,
183                                struct mlx5dv_context *attrs_out);
184         int (*dv_set_context_attr)(struct ibv_context *ibv_ctx,
185                                    enum mlx5dv_set_ctx_attr_type type,
186                                    void *attr);
187         int (*dv_init_obj)(struct mlx5dv_obj *obj, uint64_t obj_type);
188         struct ibv_qp *(*dv_create_qp)
189                 (struct ibv_context *context,
190                  struct ibv_qp_init_attr_ex *qp_init_attr_ex,
191                  struct mlx5dv_qp_init_attr *dv_qp_init_attr);
192         void *(*dv_create_flow_matcher)
193                 (struct ibv_context *context,
194                  struct mlx5dv_flow_matcher_attr *matcher_attr,
195                  void *tbl);
196         void *(*dv_create_flow)(void *matcher, void *match_value,
197                           size_t num_actions, void *actions[]);
198         void *(*dv_create_flow_action_counter)(void *obj, uint32_t  offset);
199         void *(*dv_create_flow_action_dest_ibv_qp)(void *qp);
200         void *(*dv_create_flow_action_dest_devx_tir)(void *tir);
201         void *(*dv_create_flow_action_modify_header)
202                 (struct ibv_context *ctx, enum mlx5dv_flow_table_type ft_type,
203                  void *domain, uint64_t flags, size_t actions_sz,
204                  uint64_t actions[]);
205         void *(*dv_create_flow_action_packet_reformat)
206                 (struct ibv_context *ctx,
207                  enum mlx5dv_flow_action_packet_reformat_type reformat_type,
208                  enum mlx5dv_flow_table_type ft_type,
209                  struct mlx5dv_dr_domain *domain,
210                  uint32_t flags, size_t data_sz, void *data);
211         void *(*dv_create_flow_action_tag)(uint32_t tag);
212         int (*dv_destroy_flow)(void *flow);
213         int (*dv_destroy_flow_matcher)(void *matcher);
214         struct ibv_context *(*dv_open_device)(struct ibv_device *device);
215         struct mlx5dv_devx_obj *(*devx_obj_create)
216                                         (struct ibv_context *ctx,
217                                          const void *in, size_t inlen,
218                                          void *out, size_t outlen);
219         int (*devx_obj_destroy)(struct mlx5dv_devx_obj *obj);
220         int (*devx_obj_query)(struct mlx5dv_devx_obj *obj,
221                               const void *in, size_t inlen,
222                               void *out, size_t outlen);
223         int (*devx_obj_modify)(struct mlx5dv_devx_obj *obj,
224                                const void *in, size_t inlen,
225                                void *out, size_t outlen);
226         int (*devx_general_cmd)(struct ibv_context *context,
227                                 const void *in, size_t inlen,
228                                 void *out, size_t outlen);
229         struct mlx5dv_devx_cmd_comp *(*devx_create_cmd_comp)
230                                         (struct ibv_context *context);
231         void (*devx_destroy_cmd_comp)(struct mlx5dv_devx_cmd_comp *cmd_comp);
232         int (*devx_obj_query_async)(struct mlx5dv_devx_obj *obj,
233                                     const void *in, size_t inlen,
234                                     size_t outlen, uint64_t wr_id,
235                                     struct mlx5dv_devx_cmd_comp *cmd_comp);
236         int (*devx_get_async_cmd_comp)(struct mlx5dv_devx_cmd_comp *cmd_comp,
237                                        struct mlx5dv_devx_async_cmd_hdr *resp,
238                                        size_t cmd_resp_len);
239         struct mlx5dv_devx_umem *(*devx_umem_reg)(struct ibv_context *context,
240                                                   void *addr, size_t size,
241                                                   uint32_t access);
242         int (*devx_umem_dereg)(struct mlx5dv_devx_umem *dv_devx_umem);
243         int (*devx_qp_query)(struct ibv_qp *qp,
244                              const void *in, size_t inlen,
245                              void *out, size_t outlen);
246         int (*devx_port_query)(struct ibv_context *ctx,
247                                uint32_t port_num,
248                                struct mlx5dv_devx_port *mlx5_devx_port);
249 };
250
251 const struct mlx5_glue *mlx5_glue;
252
253 #endif /* MLX5_GLUE_H_ */