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