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