082ca501b65e7b4d0c727640cd02fd24e4fd6065
[dpdk.git] / drivers / net / bnxt / tf_ulp / bnxt_ulp.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2021 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _BNXT_ULP_H_
7 #define _BNXT_ULP_H_
8
9 #include <inttypes.h>
10 #include <stdbool.h>
11 #include <sys/queue.h>
12
13 #include "rte_version.h"
14 #include "rte_ethdev.h"
15
16 #include "ulp_template_db_enum.h"
17 #include "ulp_tun.h"
18 #include "bnxt_tf_common.h"
19
20 /* NAT defines to reuse existing inner L2 SMAC and DMAC */
21 #define BNXT_ULP_NAT_INNER_L2_HEADER_SMAC       0x2000
22 #define BNXT_ULP_NAT_OUTER_MOST_L2_HDR_SMAC     0x6000
23 #define BNXT_ULP_NAT_OUTER_MOST_L2_VLAN_TAGS    0xc00
24 #define BNXT_ULP_NAT_INNER_L2_HEADER_DMAC       0x100
25 #define BNXT_ULP_NAT_OUTER_MOST_L2_HDR_DMAC     0x300
26 #define BNXT_ULP_NAT_OUTER_MOST_FLAGS (BNXT_ULP_NAT_OUTER_MOST_L2_HDR_SMAC |\
27                                         BNXT_ULP_NAT_OUTER_MOST_L2_VLAN_TAGS |\
28                                         BNXT_ULP_NAT_OUTER_MOST_L2_HDR_DMAC)
29
30 /* defines for the ulp_flags */
31 #define BNXT_ULP_VF_REP_ENABLED         0x1
32 #define BNXT_ULP_SHARED_SESSION_ENABLED 0x2
33 #define BNXT_ULP_APP_DEV_UNSUPPORTED    0x4
34 #define BNXT_ULP_HIGH_AVAIL_ENABLED     0x8
35 #define BNXT_ULP_APP_UNICAST_ONLY       0x10
36 #define ULP_VF_REP_IS_ENABLED(flag)     ((flag) & BNXT_ULP_VF_REP_ENABLED)
37 #define ULP_SHARED_SESSION_IS_ENABLED(flag) ((flag) &\
38                                              BNXT_ULP_SHARED_SESSION_ENABLED)
39 #define ULP_APP_DEV_UNSUPPORTED_ENABLED(flag)   ((flag) &\
40                                                  BNXT_ULP_APP_DEV_UNSUPPORTED)
41 #define ULP_HIGH_AVAIL_IS_ENABLED(flag) ((flag) & BNXT_ULP_HIGH_AVAIL_ENABLED)
42
43 enum bnxt_ulp_flow_mem_type {
44         BNXT_ULP_FLOW_MEM_TYPE_INT = 0,
45         BNXT_ULP_FLOW_MEM_TYPE_EXT = 1,
46         BNXT_ULP_FLOW_MEM_TYPE_BOTH = 2,
47         BNXT_ULP_FLOW_MEM_TYPE_LAST = 3
48 };
49
50 struct bnxt_ulp_df_rule_info {
51         uint32_t                        def_port_flow_id;
52         uint8_t                         valid;
53 };
54
55 struct bnxt_ulp_vfr_rule_info {
56         uint32_t                        vfr_flow_id;
57         uint16_t                        parent_port_id;
58         uint8_t                         valid;
59 };
60
61 struct bnxt_ulp_data {
62         uint32_t                        tbl_scope_id;
63         struct bnxt_ulp_mark_tbl        *mark_tbl;
64         uint32_t                        dev_id; /* Hardware device id */
65         uint32_t                        ref_cnt;
66         struct bnxt_ulp_flow_db         *flow_db;
67         pthread_mutex_t                 flow_db_lock;
68         void                            *mapper_data;
69         struct bnxt_ulp_port_db         *port_db;
70         struct bnxt_ulp_fc_info         *fc_info;
71         struct bnxt_ulp_ha_mgr_info     *ha_info;
72         uint32_t                        ulp_flags;
73         struct bnxt_ulp_df_rule_info    df_rule_info[RTE_MAX_ETHPORTS];
74         struct bnxt_ulp_vfr_rule_info   vfr_rule_info[RTE_MAX_ETHPORTS];
75         enum bnxt_ulp_flow_mem_type     mem_type;
76 #define BNXT_ULP_TUN_ENTRY_INVALID      -1
77 #define BNXT_ULP_MAX_TUN_CACHE_ENTRIES  16
78         struct bnxt_tun_cache_entry     tun_tbl[BNXT_ULP_MAX_TUN_CACHE_ENTRIES];
79         bool                            accum_stats;
80         uint8_t                         app_id;
81         uint8_t                         num_shared_clients;
82 };
83
84 struct bnxt_ulp_context {
85         struct bnxt_ulp_data    *cfg_data;
86         struct tf               *g_tfp;
87         struct tf               *g_shared_tfp;
88 };
89
90 struct bnxt_ulp_pci_info {
91         uint32_t        domain;
92         uint8_t         bus;
93 };
94
95 struct bnxt_ulp_session_state {
96         STAILQ_ENTRY(bnxt_ulp_session_state)    next;
97         bool                                    bnxt_ulp_init;
98         pthread_mutex_t                         bnxt_ulp_mutex;
99         struct bnxt_ulp_pci_info                pci_info;
100         struct bnxt_ulp_data                    *cfg_data;
101         struct tf                               *g_tfp;
102         struct tf                               g_shared_tfp;
103         uint32_t                                session_opened;
104 };
105
106 /* ULP flow id structure */
107 struct rte_tf_flow {
108         uint32_t        flow_id;
109 };
110
111 struct ulp_tlv_param {
112         enum bnxt_ulp_df_param_type type;
113         uint32_t length;
114         uint8_t value[16];
115 };
116
117 struct ulp_context_list_entry {
118         TAILQ_ENTRY(ulp_context_list_entry)     next;
119         struct bnxt_ulp_context                 *ulp_ctx;
120 };
121
122 /*
123  * Allow the deletion of context only for the bnxt device that
124  * created the session
125  */
126 bool
127 ulp_ctx_deinit_allowed(struct bnxt_ulp_context *ulp_ctx);
128
129 /* Function to set the device id of the hardware. */
130 int32_t
131 bnxt_ulp_cntxt_dev_id_set(struct bnxt_ulp_context *ulp_ctx, uint32_t dev_id);
132
133 /* Function to get the device id of the hardware. */
134 int32_t
135 bnxt_ulp_cntxt_dev_id_get(struct bnxt_ulp_context *ulp_ctx, uint32_t *dev_id);
136
137 /* Function to get whether or not ext mem is used for EM */
138 int32_t
139 bnxt_ulp_cntxt_mem_type_get(struct bnxt_ulp_context *ulp_ctx,
140                             enum bnxt_ulp_flow_mem_type *mem_type);
141
142 /* Function to set whether or not ext mem is used for EM */
143 int32_t
144 bnxt_ulp_cntxt_mem_type_set(struct bnxt_ulp_context *ulp_ctx,
145                             enum bnxt_ulp_flow_mem_type mem_type);
146
147 /* Function to set the table scope id of the EEM table. */
148 int32_t
149 bnxt_ulp_cntxt_tbl_scope_id_set(struct bnxt_ulp_context *ulp_ctx,
150                                 uint32_t tbl_scope_id);
151
152 /* Function to get the table scope id of the EEM table. */
153 int32_t
154 bnxt_ulp_cntxt_tbl_scope_id_get(struct bnxt_ulp_context *ulp_ctx,
155                                 uint32_t *tbl_scope_id);
156
157 /* Function to set the tfp session details in the ulp context. */
158 int32_t
159 bnxt_ulp_cntxt_shared_tfp_set(struct bnxt_ulp_context *ulp, struct tf *tfp);
160
161 /* Function to get the tfp session details from ulp context. */
162 struct tf *
163 bnxt_ulp_cntxt_shared_tfp_get(struct bnxt_ulp_context *ulp);
164
165 /* Function to set the tfp session details in the ulp context. */
166 int32_t
167 bnxt_ulp_cntxt_tfp_set(struct bnxt_ulp_context *ulp, struct tf *tfp);
168
169 /* Function to get the tfp session details from ulp context. */
170 struct tf *
171 bnxt_ulp_cntxt_tfp_get(struct bnxt_ulp_context *ulp,
172                        enum bnxt_ulp_shared_session shared);
173
174 /* Get the device table entry based on the device id. */
175 struct bnxt_ulp_device_params *
176 bnxt_ulp_device_params_get(uint32_t dev_id);
177
178 int32_t
179 bnxt_ulp_ctxt_ptr2_mark_db_set(struct bnxt_ulp_context *ulp_ctx,
180                                struct bnxt_ulp_mark_tbl *mark_tbl);
181
182 struct bnxt_ulp_mark_tbl *
183 bnxt_ulp_ctxt_ptr2_mark_db_get(struct bnxt_ulp_context *ulp_ctx);
184
185 /* Function to set the flow database to the ulp context. */
186 int32_t
187 bnxt_ulp_cntxt_ptr2_flow_db_set(struct bnxt_ulp_context *ulp_ctx,
188                                 struct bnxt_ulp_flow_db *flow_db);
189
190 /* Function to get the flow database from the ulp context. */
191 struct bnxt_ulp_flow_db *
192 bnxt_ulp_cntxt_ptr2_flow_db_get(struct bnxt_ulp_context *ulp_ctx);
193
194 /* Function to get the tunnel cache table info from the ulp context. */
195 struct bnxt_tun_cache_entry *
196 bnxt_ulp_cntxt_ptr2_tun_tbl_get(struct bnxt_ulp_context *ulp_ctx);
197
198 /* Function to get the ulp context from eth device. */
199 struct bnxt_ulp_context *
200 bnxt_ulp_eth_dev_ptr2_cntxt_get(struct rte_eth_dev *dev);
201
202 /* Function to add the ulp mapper data to the ulp context */
203 int32_t
204 bnxt_ulp_cntxt_ptr2_mapper_data_set(struct bnxt_ulp_context *ulp_ctx,
205                                     void *mapper_data);
206
207 /* Function to get the ulp mapper data from the ulp context */
208 void *
209 bnxt_ulp_cntxt_ptr2_mapper_data_get(struct bnxt_ulp_context *ulp_ctx);
210
211 /* Function to set the port database to the ulp context. */
212 int32_t
213 bnxt_ulp_cntxt_ptr2_port_db_set(struct bnxt_ulp_context *ulp_ctx,
214                                 struct bnxt_ulp_port_db *port_db);
215
216 /* Function to get the port database from the ulp context. */
217 struct bnxt_ulp_port_db *
218 bnxt_ulp_cntxt_ptr2_port_db_get(struct bnxt_ulp_context *ulp_ctx);
219
220 /* Function to create default flows. */
221 int32_t
222 ulp_default_flow_create(struct rte_eth_dev *eth_dev,
223                         struct ulp_tlv_param *param_list,
224                         uint32_t ulp_class_tid,
225                         uint32_t *flow_id);
226
227 /* Function to destroy default flows. */
228 int32_t
229 ulp_default_flow_destroy(struct rte_eth_dev *eth_dev,
230                          uint32_t flow_id);
231
232 int
233 bnxt_ulp_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow,
234                       struct rte_flow_error *error);
235
236 int32_t
237 bnxt_ulp_cntxt_ptr2_fc_info_set(struct bnxt_ulp_context *ulp_ctx,
238                                 struct bnxt_ulp_fc_info *ulp_fc_info);
239
240 struct bnxt_ulp_fc_info *
241 bnxt_ulp_cntxt_ptr2_fc_info_get(struct bnxt_ulp_context *ulp_ctx);
242
243 int32_t
244 bnxt_ulp_cntxt_ptr2_ulp_flags_get(struct bnxt_ulp_context *ulp_ctx,
245                                   uint32_t *flags);
246
247 int32_t
248 bnxt_ulp_get_df_rule_info(uint8_t port_id, struct bnxt_ulp_context *ulp_ctx,
249                           struct bnxt_ulp_df_rule_info *info);
250
251 struct bnxt_ulp_vfr_rule_info*
252 bnxt_ulp_cntxt_ptr2_ulp_vfr_info_get(struct bnxt_ulp_context *ulp_ctx,
253                                      uint32_t port_id);
254
255 int32_t
256 bnxt_ulp_cntxt_acquire_fdb_lock(struct bnxt_ulp_context *ulp_ctx);
257
258 void
259 bnxt_ulp_cntxt_release_fdb_lock(struct bnxt_ulp_context *ulp_ctx);
260
261 int32_t
262 ulp_post_process_tun_flow(struct ulp_rte_parser_params *params);
263
264 struct bnxt_ulp_glb_resource_info *
265 bnxt_ulp_app_glb_resource_info_list_get(uint32_t *num_entries);
266
267 int32_t
268 bnxt_ulp_cntxt_app_id_set(struct bnxt_ulp_context *ulp_ctx, uint8_t app_id);
269
270 int32_t
271 bnxt_ulp_cntxt_app_id_get(struct bnxt_ulp_context *ulp_ctx, uint8_t *app_id);
272
273 bool
274 bnxt_ulp_cntxt_shared_session_enabled(struct bnxt_ulp_context *ulp_ctx);
275
276 struct bnxt_ulp_app_capabilities_info *
277 bnxt_ulp_app_cap_list_get(uint32_t *num_entries);
278
279 int32_t
280 bnxt_ulp_cntxt_app_caps_init(struct bnxt_ulp_context *ulp_ctx,
281                              uint8_t app_id, uint32_t dev_id);
282
283 struct bnxt_ulp_resource_resv_info *
284 bnxt_ulp_resource_resv_list_get(uint32_t *num_entries);
285
286 int32_t
287 bnxt_ulp_cntxt_ptr2_ha_info_set(struct bnxt_ulp_context *ulp_ctx,
288                                 struct bnxt_ulp_ha_mgr_info *ulp_ha_info);
289
290 struct bnxt_ulp_ha_mgr_info *
291 bnxt_ulp_cntxt_ptr2_ha_info_get(struct bnxt_ulp_context *ulp_ctx);
292
293 bool
294 bnxt_ulp_cntxt_ha_enabled(struct bnxt_ulp_context *ulp_ctx);
295
296 struct bnxt_ulp_context *
297 bnxt_ulp_cntxt_entry_acquire(void);
298
299 void
300 bnxt_ulp_cntxt_entry_release(void);
301
302 uint8_t
303 bnxt_ulp_cntxt_num_shared_clients_get(struct bnxt_ulp_context *ulp_ctx);
304 #endif /* _BNXT_ULP_H_ */