1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 Broadcom
11 #include <sys/queue.h>
13 #include "rte_version.h"
14 #include "rte_ethdev.h"
16 #include "ulp_template_db_enum.h"
18 #include "bnxt_tf_common.h"
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)
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)
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
50 enum bnxt_rte_flow_item_type {
51 BNXT_RTE_FLOW_ITEM_TYPE_END = (uint32_t)INT_MIN,
52 BNXT_RTE_FLOW_ITEM_TYPE_VXLAN_DECAP,
53 BNXT_RTE_FLOW_ITEM_TYPE_LAST
56 enum bnxt_rte_flow_action_type {
57 BNXT_RTE_FLOW_ACTION_TYPE_END = (uint32_t)INT_MIN,
58 BNXT_RTE_FLOW_ACTION_TYPE_VXLAN_DECAP,
59 BNXT_RTE_FLOW_ACTION_TYPE_LAST
62 struct bnxt_ulp_df_rule_info {
63 uint32_t def_port_flow_id;
67 struct bnxt_ulp_vfr_rule_info {
69 uint16_t parent_port_id;
73 struct bnxt_ulp_data {
74 uint32_t tbl_scope_id;
75 struct bnxt_ulp_mark_tbl *mark_tbl;
76 uint32_t dev_id; /* Hardware device id */
78 struct bnxt_ulp_flow_db *flow_db;
79 pthread_mutex_t flow_db_lock;
81 struct bnxt_ulp_port_db *port_db;
82 struct bnxt_ulp_fc_info *fc_info;
83 struct bnxt_ulp_ha_mgr_info *ha_info;
85 struct bnxt_ulp_df_rule_info df_rule_info[RTE_MAX_ETHPORTS];
86 struct bnxt_ulp_vfr_rule_info vfr_rule_info[RTE_MAX_ETHPORTS];
87 enum bnxt_ulp_flow_mem_type mem_type;
88 #define BNXT_ULP_TUN_ENTRY_INVALID -1
89 #define BNXT_ULP_MAX_TUN_CACHE_ENTRIES 16
90 struct bnxt_tun_cache_entry tun_tbl[BNXT_ULP_MAX_TUN_CACHE_ENTRIES];
93 uint8_t num_shared_clients;
94 struct bnxt_flow_app_tun_ent app_tun[BNXT_ULP_MAX_TUN_CACHE_ENTRIES];
97 struct bnxt_ulp_context {
98 struct bnxt_ulp_data *cfg_data;
100 struct tf *g_shared_tfp;
103 struct bnxt_ulp_pci_info {
108 struct bnxt_ulp_session_state {
109 STAILQ_ENTRY(bnxt_ulp_session_state) next;
111 pthread_mutex_t bnxt_ulp_mutex;
112 struct bnxt_ulp_pci_info pci_info;
113 struct bnxt_ulp_data *cfg_data;
115 struct tf g_shared_tfp;
116 uint32_t session_opened;
119 /* ULP flow id structure */
124 struct ulp_tlv_param {
125 enum bnxt_ulp_df_param_type type;
130 struct ulp_context_list_entry {
131 TAILQ_ENTRY(ulp_context_list_entry) next;
132 struct bnxt_ulp_context *ulp_ctx;
136 * Allow the deletion of context only for the bnxt device that
137 * created the session
140 ulp_ctx_deinit_allowed(struct bnxt_ulp_context *ulp_ctx);
142 /* Function to set the device id of the hardware. */
144 bnxt_ulp_cntxt_dev_id_set(struct bnxt_ulp_context *ulp_ctx, uint32_t dev_id);
146 /* Function to get the device id of the hardware. */
148 bnxt_ulp_cntxt_dev_id_get(struct bnxt_ulp_context *ulp_ctx, uint32_t *dev_id);
150 /* Function to get whether or not ext mem is used for EM */
152 bnxt_ulp_cntxt_mem_type_get(struct bnxt_ulp_context *ulp_ctx,
153 enum bnxt_ulp_flow_mem_type *mem_type);
155 /* Function to set whether or not ext mem is used for EM */
157 bnxt_ulp_cntxt_mem_type_set(struct bnxt_ulp_context *ulp_ctx,
158 enum bnxt_ulp_flow_mem_type mem_type);
160 /* Function to set the table scope id of the EEM table. */
162 bnxt_ulp_cntxt_tbl_scope_id_set(struct bnxt_ulp_context *ulp_ctx,
163 uint32_t tbl_scope_id);
165 /* Function to get the table scope id of the EEM table. */
167 bnxt_ulp_cntxt_tbl_scope_id_get(struct bnxt_ulp_context *ulp_ctx,
168 uint32_t *tbl_scope_id);
170 /* Function to set the tfp session details in the ulp context. */
172 bnxt_ulp_cntxt_shared_tfp_set(struct bnxt_ulp_context *ulp, struct tf *tfp);
174 /* Function to get the tfp session details from ulp context. */
176 bnxt_ulp_cntxt_shared_tfp_get(struct bnxt_ulp_context *ulp);
178 /* Function to set the tfp session details in the ulp context. */
180 bnxt_ulp_cntxt_tfp_set(struct bnxt_ulp_context *ulp, struct tf *tfp);
182 /* Function to get the tfp session details from ulp context. */
184 bnxt_ulp_cntxt_tfp_get(struct bnxt_ulp_context *ulp,
185 enum bnxt_ulp_shared_session shared);
187 /* Get the device table entry based on the device id. */
188 struct bnxt_ulp_device_params *
189 bnxt_ulp_device_params_get(uint32_t dev_id);
192 bnxt_ulp_ctxt_ptr2_mark_db_set(struct bnxt_ulp_context *ulp_ctx,
193 struct bnxt_ulp_mark_tbl *mark_tbl);
195 struct bnxt_ulp_mark_tbl *
196 bnxt_ulp_ctxt_ptr2_mark_db_get(struct bnxt_ulp_context *ulp_ctx);
198 /* Function to set the flow database to the ulp context. */
200 bnxt_ulp_cntxt_ptr2_flow_db_set(struct bnxt_ulp_context *ulp_ctx,
201 struct bnxt_ulp_flow_db *flow_db);
203 /* Function to get the flow database from the ulp context. */
204 struct bnxt_ulp_flow_db *
205 bnxt_ulp_cntxt_ptr2_flow_db_get(struct bnxt_ulp_context *ulp_ctx);
207 /* Function to get the tunnel cache table info from the ulp context. */
208 struct bnxt_tun_cache_entry *
209 bnxt_ulp_cntxt_ptr2_tun_tbl_get(struct bnxt_ulp_context *ulp_ctx);
211 /* Function to get the ulp context from eth device. */
212 struct bnxt_ulp_context *
213 bnxt_ulp_eth_dev_ptr2_cntxt_get(struct rte_eth_dev *dev);
215 /* Function to add the ulp mapper data to the ulp context */
217 bnxt_ulp_cntxt_ptr2_mapper_data_set(struct bnxt_ulp_context *ulp_ctx,
220 /* Function to get the ulp mapper data from the ulp context */
222 bnxt_ulp_cntxt_ptr2_mapper_data_get(struct bnxt_ulp_context *ulp_ctx);
224 /* Function to set the port database to the ulp context. */
226 bnxt_ulp_cntxt_ptr2_port_db_set(struct bnxt_ulp_context *ulp_ctx,
227 struct bnxt_ulp_port_db *port_db);
229 /* Function to get the port database from the ulp context. */
230 struct bnxt_ulp_port_db *
231 bnxt_ulp_cntxt_ptr2_port_db_get(struct bnxt_ulp_context *ulp_ctx);
233 /* Function to create default flows. */
235 ulp_default_flow_create(struct rte_eth_dev *eth_dev,
236 struct ulp_tlv_param *param_list,
237 uint32_t ulp_class_tid,
240 /* Function to destroy default flows. */
242 ulp_default_flow_destroy(struct rte_eth_dev *eth_dev,
246 bnxt_ulp_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow,
247 struct rte_flow_error *error);
250 bnxt_ulp_cntxt_ptr2_fc_info_set(struct bnxt_ulp_context *ulp_ctx,
251 struct bnxt_ulp_fc_info *ulp_fc_info);
253 struct bnxt_ulp_fc_info *
254 bnxt_ulp_cntxt_ptr2_fc_info_get(struct bnxt_ulp_context *ulp_ctx);
257 bnxt_ulp_cntxt_ptr2_ulp_flags_get(struct bnxt_ulp_context *ulp_ctx,
261 bnxt_ulp_get_df_rule_info(uint8_t port_id, struct bnxt_ulp_context *ulp_ctx,
262 struct bnxt_ulp_df_rule_info *info);
264 struct bnxt_ulp_vfr_rule_info*
265 bnxt_ulp_cntxt_ptr2_ulp_vfr_info_get(struct bnxt_ulp_context *ulp_ctx,
269 bnxt_ulp_cntxt_acquire_fdb_lock(struct bnxt_ulp_context *ulp_ctx);
272 bnxt_ulp_cntxt_release_fdb_lock(struct bnxt_ulp_context *ulp_ctx);
274 struct bnxt_ulp_glb_resource_info *
275 bnxt_ulp_app_glb_resource_info_list_get(uint32_t *num_entries);
278 bnxt_ulp_cntxt_app_id_set(struct bnxt_ulp_context *ulp_ctx, uint8_t app_id);
281 bnxt_ulp_cntxt_app_id_get(struct bnxt_ulp_context *ulp_ctx, uint8_t *app_id);
284 bnxt_ulp_cntxt_shared_session_enabled(struct bnxt_ulp_context *ulp_ctx);
286 struct bnxt_ulp_app_capabilities_info *
287 bnxt_ulp_app_cap_list_get(uint32_t *num_entries);
290 bnxt_ulp_cntxt_app_caps_init(struct bnxt_ulp_context *ulp_ctx,
291 uint8_t app_id, uint32_t dev_id);
293 struct bnxt_ulp_resource_resv_info *
294 bnxt_ulp_resource_resv_list_get(uint32_t *num_entries);
297 bnxt_ulp_cntxt_ptr2_ha_info_set(struct bnxt_ulp_context *ulp_ctx,
298 struct bnxt_ulp_ha_mgr_info *ulp_ha_info);
300 struct bnxt_ulp_ha_mgr_info *
301 bnxt_ulp_cntxt_ptr2_ha_info_get(struct bnxt_ulp_context *ulp_ctx);
304 bnxt_ulp_cntxt_ha_enabled(struct bnxt_ulp_context *ulp_ctx);
306 struct bnxt_ulp_context *
307 bnxt_ulp_cntxt_entry_acquire(void);
310 bnxt_ulp_cntxt_entry_release(void);
313 bnxt_ulp_cntxt_num_shared_clients_get(struct bnxt_ulp_context *ulp_ctx);
315 struct bnxt_flow_app_tun_ent *
316 bnxt_ulp_cntxt_ptr2_app_tun_list_get(struct bnxt_ulp_context *ulp);
318 #endif /* _BNXT_ULP_H_ */