xref: /dpdk/drivers/net/bnxt/tf_ulp/bnxt_ulp.h (revision 67ad40007cd6bb6ce9f0b3eefe2af611848d10dc)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2023 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 #include "rte_mtr.h"
16 
17 #include "bnxt.h"
18 #include "ulp_template_db_enum.h"
19 #include "ulp_tun.h"
20 #include "bnxt_tf_common.h"
21 
22 /* NAT defines to reuse existing inner L2 SMAC and DMAC */
23 #define BNXT_ULP_NAT_INNER_L2_HEADER_SMAC	0x2000
24 #define BNXT_ULP_NAT_OUTER_MOST_L2_HDR_SMAC	0x6000
25 #define BNXT_ULP_NAT_OUTER_MOST_L2_VLAN_TAGS	0xc00
26 #define BNXT_ULP_NAT_INNER_L2_HEADER_DMAC	0x100
27 #define BNXT_ULP_NAT_OUTER_MOST_L2_HDR_DMAC	0x300
28 #define BNXT_ULP_NAT_OUTER_MOST_FLAGS (BNXT_ULP_NAT_OUTER_MOST_L2_HDR_SMAC |\
29 					BNXT_ULP_NAT_OUTER_MOST_L2_VLAN_TAGS |\
30 					BNXT_ULP_NAT_OUTER_MOST_L2_HDR_DMAC)
31 
32 /* defines for the ulp_flags */
33 #define BNXT_ULP_VF_REP_ENABLED		0x1
34 #define BNXT_ULP_SHARED_SESSION_ENABLED	0x2
35 #define BNXT_ULP_APP_DEV_UNSUPPORTED	0x4
36 #define BNXT_ULP_HIGH_AVAIL_ENABLED	0x8
37 #define BNXT_ULP_APP_UNICAST_ONLY	0x10
38 #define BNXT_ULP_APP_SOCKET_DIRECT	0x20
39 #define BNXT_ULP_APP_TOS_PROTO_SUPPORT	0x40
40 #define BNXT_ULP_APP_BC_MC_SUPPORT	0x80
41 #define BNXT_ULP_STATIC_VXLAN_SUPPORT	0x100
42 #define BNXT_ULP_MULTI_SHARED_SUPPORT	0x200
43 #define BNXT_ULP_APP_HA_DYNAMIC		0x400
44 #define BNXT_ULP_APP_SRV6               0x800
45 #define BNXT_ULP_APP_L2_ETYPE		0x1000
46 #define BNXT_ULP_SHARED_TBL_SCOPE_ENABLED 0x2000
47 #define BNXT_ULP_DYNAMIC_VXLAN_PORT	0x4000
48 #define BNXT_ULP_DYNAMIC_GENEVE_PORT	0x8000
49 
50 #define ULP_VF_REP_IS_ENABLED(flag)	((flag) & BNXT_ULP_VF_REP_ENABLED)
51 #define ULP_SHARED_SESSION_IS_ENABLED(flag) ((flag) &\
52 					     BNXT_ULP_SHARED_SESSION_ENABLED)
53 #define ULP_APP_DEV_UNSUPPORTED_ENABLED(flag)	((flag) &\
54 						 BNXT_ULP_APP_DEV_UNSUPPORTED)
55 #define ULP_HIGH_AVAIL_IS_ENABLED(flag)	((flag) & BNXT_ULP_HIGH_AVAIL_ENABLED)
56 #define ULP_SOCKET_DIRECT_IS_ENABLED(flag) ((flag) & BNXT_ULP_APP_SOCKET_DIRECT)
57 #define ULP_APP_TOS_PROTO_SUPPORT(ctx)	((ctx)->cfg_data->ulp_flags &\
58 					BNXT_ULP_APP_TOS_PROTO_SUPPORT)
59 #define ULP_APP_BC_MC_SUPPORT(ctx)	((ctx)->cfg_data->ulp_flags &\
60 					BNXT_ULP_APP_BC_MC_SUPPORT)
61 #define ULP_MULTI_SHARED_IS_SUPPORTED(ctx)	((ctx)->cfg_data->ulp_flags &\
62 					BNXT_ULP_MULTI_SHARED_SUPPORT)
63 #define ULP_APP_HA_IS_DYNAMIC(ctx)	((ctx)->cfg_data->ulp_flags &\
64 					BNXT_ULP_APP_HA_DYNAMIC)
65 
66 #define ULP_APP_L2_ETYPE_SUPPORT(ctx)	((ctx)->cfg_data->ulp_flags &\
67 					BNXT_ULP_APP_L2_ETYPE)
68 
69 #define ULP_APP_STATIC_VXLAN_PORT_EN(ctx)	((ctx)->cfg_data->ulp_flags &\
70 					BNXT_ULP_STATIC_VXLAN_SUPPORT)
71 #define ULP_APP_DYNAMIC_VXLAN_PORT_EN(ctx)	((ctx)->cfg_data->ulp_flags &\
72 					BNXT_ULP_DYNAMIC_VXLAN_PORT)
73 #define ULP_APP_DYNAMIC_GENEVE_PORT_EN(ctx)	((ctx)->cfg_data->ulp_flags &\
74 					BNXT_ULP_DYNAMIC_GENEVE_PORT)
75 
76 enum bnxt_ulp_flow_mem_type {
77 	BNXT_ULP_FLOW_MEM_TYPE_INT = 0,
78 	BNXT_ULP_FLOW_MEM_TYPE_EXT = 1,
79 	BNXT_ULP_FLOW_MEM_TYPE_BOTH = 2,
80 	BNXT_ULP_FLOW_MEM_TYPE_LAST = 3
81 };
82 
83 enum bnxt_rte_flow_item_type {
84 	BNXT_RTE_FLOW_ITEM_TYPE_END = (uint32_t)INT_MIN,
85 	BNXT_RTE_FLOW_ITEM_TYPE_VXLAN_DECAP,
86 	BNXT_RTE_FLOW_ITEM_TYPE_LAST
87 };
88 
89 enum bnxt_rte_flow_action_type {
90 	BNXT_RTE_FLOW_ACTION_TYPE_END = (uint32_t)INT_MIN,
91 	BNXT_RTE_FLOW_ACTION_TYPE_VXLAN_DECAP,
92 	BNXT_RTE_FLOW_ACTION_TYPE_LAST
93 };
94 
95 #define BNXT_ULP_MAX_GROUP_CNT		8
96 struct bnxt_ulp_grp_rule_info {
97 	uint32_t			group_id;
98 	uint32_t			flow_id;
99 	uint8_t				dir;
100 	uint8_t				valid;
101 };
102 
103 struct bnxt_ulp_df_rule_info {
104 	uint32_t			def_port_flow_id;
105 	uint32_t			promisc_flow_id;
106 	uint8_t				valid;
107 	struct bnxt_ulp_grp_rule_info	grp_df_rule[BNXT_ULP_MAX_GROUP_CNT];
108 };
109 
110 struct bnxt_ulp_vfr_rule_info {
111 	uint32_t			vfr_flow_id;
112 	uint16_t			parent_port_id;
113 	uint8_t				valid;
114 };
115 
116 struct bnxt_ulp_data {
117 	uint32_t			tbl_scope_id;
118 	struct bnxt_ulp_mark_tbl	*mark_tbl;
119 	uint32_t			dev_id; /* Hardware device id */
120 	uint32_t			ref_cnt;
121 	struct bnxt_ulp_flow_db		*flow_db;
122 	pthread_mutex_t			flow_db_lock;
123 	void				*mapper_data;
124 	void				*matcher_data;
125 	struct bnxt_ulp_port_db		*port_db;
126 	struct bnxt_ulp_fc_info		*fc_info;
127 	struct bnxt_ulp_ha_mgr_info	*ha_info;
128 	uint32_t			ulp_flags;
129 	struct bnxt_ulp_df_rule_info	df_rule_info[RTE_MAX_ETHPORTS];
130 	struct bnxt_ulp_vfr_rule_info	vfr_rule_info[RTE_MAX_ETHPORTS];
131 	enum bnxt_ulp_flow_mem_type	mem_type;
132 #define	BNXT_ULP_TUN_ENTRY_INVALID	-1
133 #define	BNXT_ULP_MAX_TUN_CACHE_ENTRIES	16
134 	struct bnxt_tun_cache_entry	tun_tbl[BNXT_ULP_MAX_TUN_CACHE_ENTRIES];
135 	uint8_t				app_id;
136 	uint8_t				num_shared_clients;
137 	struct bnxt_flow_app_tun_ent	app_tun[BNXT_ULP_MAX_TUN_CACHE_ENTRIES];
138 	uint32_t			default_priority;
139 	uint32_t			max_def_priority;
140 	uint32_t			min_flow_priority;
141 	uint32_t			max_flow_priority;
142 	uint32_t			vxlan_port;
143 	uint32_t			vxlan_gpe_port;
144 	uint32_t			vxlan_ip_port;
145 	uint32_t			ecpri_udp_port;
146 	uint32_t			hu_session_type;
147 	uint32_t			max_pools;
148 	uint32_t			num_rx_flows;
149 	uint32_t			num_tx_flows;
150 	uint16_t			act_rx_max_sz;
151 	uint16_t			act_tx_max_sz;
152 	uint16_t			em_rx_key_max_sz;
153 	uint16_t			em_tx_key_max_sz;
154 	uint32_t			page_sz;
155 	uint8_t				hu_reg_state;
156 	uint8_t				hu_reg_cnt;
157 	uint8_t				ha_pool_id;
158 	uint8_t				tunnel_next_proto;
159 	uint8_t				em_multiplier;
160 	enum bnxt_ulp_session_type	def_session_type;
161 	uint16_t			num_key_recipes_per_dir;
162 	uint64_t			feature_bits;
163 	uint64_t			default_class_bits;
164 	uint64_t			default_act_bits;
165 	struct ulp_fc_tfc_stats_cache_entry *stats_cache;
166 	struct bnxt_ulp_sc_info		*sc_info;
167 };
168 
169 enum bnxt_ulp_tfo_type {
170 	BNXT_ULP_TFO_TYPE_INVALID = 0,
171 	BNXT_ULP_TFO_TYPE_TF,
172 	BNXT_ULP_TFO_TYPE_TFC
173 };
174 
175 #define BNXT_ULP_SESSION_MAX 3
176 #define BNXT_ULP_TFO_SID_FLAG (1)
177 #define BNXT_ULP_TFO_TSID_FLAG (1 << 1)
178 
179 struct bnxt_ulp_context {
180 	struct bnxt_ulp_data	*cfg_data;
181 	struct bnxt *bp;
182 	enum bnxt_ulp_tfo_type tfo_type;
183 	union {
184 		void *g_tfp[BNXT_ULP_SESSION_MAX];
185 		struct {
186 			uint32_t tfo_flags;
187 			void *tfcp;
188 			uint16_t sid;
189 			uint8_t tsid;
190 		};
191 	};
192 	const struct bnxt_ulp_core_ops *ops;
193 };
194 
195 struct bnxt_ulp_pci_info {
196 	uint32_t	domain;
197 	uint8_t		bus;
198 };
199 
200 #define BNXT_ULP_DEVICE_SERIAL_NUM_SIZE 8
201 struct bnxt_ulp_session_state {
202 	STAILQ_ENTRY(bnxt_ulp_session_state)	next;
203 	bool				bnxt_ulp_init;
204 	pthread_mutex_t			bnxt_ulp_mutex;
205 	struct bnxt_ulp_pci_info	pci_info;
206 	uint8_t				dsn[BNXT_ULP_DEVICE_SERIAL_NUM_SIZE];
207 	struct bnxt_ulp_data		*cfg_data;
208 	struct tf			*g_tfp[BNXT_ULP_SESSION_MAX];
209 	uint32_t			session_opened[BNXT_ULP_SESSION_MAX];
210 	/* Need to revisit a union for the tf related data */
211 	uint16_t			session_id;
212 };
213 
214 /* ULP flow id structure */
215 struct rte_tf_flow {
216 	uint32_t	flow_id;
217 };
218 
219 struct ulp_tlv_param {
220 	enum bnxt_ulp_df_param_type type;
221 	uint32_t length;
222 	uint8_t value[16];
223 };
224 
225 struct ulp_context_list_entry {
226 	TAILQ_ENTRY(ulp_context_list_entry)	next;
227 	struct bnxt_ulp_context			*ulp_ctx;
228 };
229 
230 struct bnxt_ulp_core_ops {
231 	int32_t
232 	(*ulp_init)(struct bnxt *bp,
233 		      struct bnxt_ulp_session_state *session);
234 	void
235 	(*ulp_deinit)(struct bnxt *bp,
236 		      struct bnxt_ulp_session_state *session);
237 	int32_t
238 	(*ulp_ctx_attach)(struct bnxt *bp,
239 			  struct bnxt_ulp_session_state *session);
240 	void
241 	(*ulp_ctx_detach)(struct bnxt *bp,
242 			  struct bnxt_ulp_session_state *session);
243 	int32_t
244 	(*ulp_vfr_session_fid_add)(struct bnxt_ulp_context *ulp_ctx,
245 				  uint16_t rep_fid);
246 	int32_t
247 	(*ulp_vfr_session_fid_rem)(struct bnxt_ulp_context *ulp_ctx,
248 				  uint16_t rep_fid);
249 
250 	int32_t
251 	(*ulp_mtr_cap_get)(struct bnxt *bp,
252 			   struct rte_mtr_capabilities *cap);
253 };
254 
255 extern const struct bnxt_ulp_core_ops bnxt_ulp_tf_core_ops;
256 extern const struct bnxt_ulp_core_ops bnxt_ulp_tfc_core_ops;
257 
258 bool
259 ulp_is_default_session_active(struct bnxt_ulp_context *ulp_ctx);
260 
261 /*
262  * Allow the deletion of context only for the bnxt device that
263  * created the session
264  */
265 bool
266 ulp_ctx_deinit_allowed(struct bnxt_ulp_context *ulp_ctx);
267 
268 void
269 bnxt_ulp_destroy_vfr_default_rules(struct bnxt *bp, bool global);
270 
271 int32_t
272 bnxt_flow_mtr_init(struct bnxt *bp __rte_unused);
273 
274 /* Function to create default flows. */
275 int32_t
276 ulp_default_flow_create(struct rte_eth_dev *eth_dev,
277 			struct ulp_tlv_param *param_list,
278 			uint32_t ulp_class_tid,
279 			uint16_t port_id,
280 			uint32_t *flow_id);
281 
282 int
283 bnxt_ulp_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow,
284 		      struct rte_flow_error *error);
285 
286 /* Function to destroy default flows. */
287 int32_t
288 ulp_default_flow_destroy(struct rte_eth_dev *eth_dev,
289 			 uint32_t flow_id);
290 
291 int32_t
292 bnxt_ulp_cntxt_list_init(void);
293 
294 int32_t
295 bnxt_ulp_cntxt_list_add(struct bnxt_ulp_context *ulp_ctx);
296 
297 void
298 bnxt_ulp_cntxt_list_del(struct bnxt_ulp_context *ulp_ctx);
299 
300 int
301 bnxt_ulp_cntxt_list_count(void);
302 
303 struct bnxt_ulp_context *
304 bnxt_ulp_cntxt_entry_acquire(void *arg);
305 
306 void
307 bnxt_ulp_cntxt_entry_release(void);
308 
309 int32_t
310 bnxt_ulp_promisc_mode_set(struct bnxt *bp, uint8_t enable);
311 
312 int32_t
313 bnxt_ulp_set_prio_attribute(struct ulp_rte_parser_params *params,
314 			    const struct rte_flow_attr *attr);
315 
316 void
317 bnxt_ulp_set_dir_attributes(struct ulp_rte_parser_params *params,
318 			    const struct rte_flow_attr *attr);
319 
320 void
321 bnxt_ulp_init_parser_cf_defaults(struct ulp_rte_parser_params *params,
322 				 uint16_t port_id);
323 
324 int32_t
325 bnxt_ulp_grp_miss_act_set(struct rte_eth_dev *dev,
326 			  const struct rte_flow_attr *attr,
327 			  const struct rte_flow_action actions[],
328 			  uint32_t *flow_id);
329 
330 #endif /* _BNXT_ULP_H_ */
331