1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014-2019 Broadcom
3  * All rights reserved.
4  */
5 
6 #ifndef _ULP_TEMPLATE_STRUCT_H_
7 #define _ULP_TEMPLATE_STRUCT_H_
8 
9 #include <stdint.h>
10 #include "rte_ether.h"
11 #include "rte_icmp.h"
12 #include "rte_ip.h"
13 #include "rte_tcp.h"
14 #include "rte_udp.h"
15 #include "rte_esp.h"
16 #include "rte_sctp.h"
17 #include "rte_flow.h"
18 #include "tf_core.h"
19 
20 /* Number of fields for each protocol */
21 #define BNXT_ULP_PROTO_HDR_SVIF_NUM	1
22 #define BNXT_ULP_PROTO_HDR_ETH_NUM	3
23 #define BNXT_ULP_PROTO_HDR_S_VLAN_NUM	3
24 #define BNXT_ULP_PROTO_HDR_VLAN_NUM	6
25 #define BNXT_ULP_PROTO_HDR_IPV4_NUM	10
26 #define BNXT_ULP_PROTO_HDR_IPV6_NUM	8
27 #define BNXT_ULP_PROTO_HDR_UDP_NUM	4
28 #define BNXT_ULP_PROTO_HDR_TCP_NUM	9
29 #define BNXT_ULP_PROTO_HDR_VXLAN_NUM	4
30 #define BNXT_ULP_PROTO_HDR_MAX		128
31 #define BNXT_ULP_PROTO_HDR_FIELD_SVIF_IDX	0
32 
33 struct ulp_rte_hdr_bitmap {
34 	uint64_t	bits;
35 };
36 
37 struct ulp_rte_field_bitmap {
38 	uint64_t	bits;
39 };
40 
41 /* Structure to store the protocol fields */
42 #define RTE_PARSER_FLOW_HDR_FIELD_SIZE		16
43 struct ulp_rte_hdr_field {
44 	uint8_t		spec[RTE_PARSER_FLOW_HDR_FIELD_SIZE];
45 	uint8_t		mask[RTE_PARSER_FLOW_HDR_FIELD_SIZE];
46 	uint32_t	size;
47 };
48 
49 struct ulp_rte_act_bitmap {
50 	uint64_t	bits;
51 };
52 
53 /* Structure to hold the action property details. */
54 struct ulp_rte_act_prop {
55 	uint8_t	act_details[BNXT_ULP_ACT_PROP_IDX_LAST];
56 };
57 
58 /* Structure to be used for passing all the parser functions */
59 struct ulp_rte_parser_params {
60 	struct ulp_rte_hdr_bitmap	hdr_bitmap;
61 	struct ulp_rte_field_bitmap	fld_bitmap;
62 	struct ulp_rte_hdr_field	hdr_field[BNXT_ULP_PROTO_HDR_MAX];
63 	uint32_t			comp_fld[BNXT_ULP_CF_IDX_LAST];
64 	uint32_t			field_idx;
65 	uint32_t			vlan_idx;
66 	struct ulp_rte_act_bitmap	act_bitmap;
67 	struct ulp_rte_act_prop		act_prop;
68 	uint32_t			dir;
69 	struct bnxt_ulp_context		*ulp_ctx;
70 };
71 
72 /* Flow Parser Header Information Structure */
73 struct bnxt_ulp_rte_hdr_info {
74 	enum bnxt_ulp_hdr_type					hdr_type;
75 	/* Flow Parser Protocol Header Function Prototype */
76 	int (*proto_hdr_func)(const struct rte_flow_item	*item_list,
77 			      struct ulp_rte_parser_params	*params);
78 };
79 
80 /* Flow Parser Header Information Structure Array defined in template source*/
81 extern struct bnxt_ulp_rte_hdr_info	ulp_hdr_info[];
82 
83 /* Flow Parser Action Information Structure */
84 struct bnxt_ulp_rte_act_info {
85 	enum bnxt_ulp_act_type					act_type;
86 	/* Flow Parser Protocol Action Function Prototype */
87 	int32_t (*proto_act_func)
88 		(const struct rte_flow_action	*action_item,
89 		 struct ulp_rte_parser_params	*params);
90 };
91 
92 /* Flow Parser Action Information Structure Array defined in template source*/
93 extern struct bnxt_ulp_rte_act_info	ulp_act_info[];
94 
95 /* Flow Matcher structures */
96 struct bnxt_ulp_header_match_info {
97 	struct ulp_rte_hdr_bitmap		hdr_bitmap;
98 	uint32_t				start_idx;
99 	uint32_t				num_entries;
100 	uint32_t				class_tmpl_id;
101 	uint32_t				act_vnic;
102 };
103 
104 struct ulp_rte_bitmap {
105 	uint64_t	bits;
106 };
107 
108 struct bnxt_ulp_class_match_info {
109 	struct ulp_rte_bitmap	hdr_sig;
110 	struct ulp_rte_bitmap	field_sig;
111 	uint32_t		class_hid;
112 	uint32_t		class_tid;
113 	uint8_t			act_vnic;
114 	uint8_t			wc_pri;
115 };
116 
117 /* Flow Matcher templates Structure for class entries */
118 extern uint16_t ulp_class_sig_tbl[];
119 extern struct bnxt_ulp_class_match_info ulp_class_match_list[];
120 
121 /* Flow Matcher Action structures */
122 struct bnxt_ulp_action_match_info {
123 	struct ulp_rte_act_bitmap		act_bitmap;
124 	uint32_t				act_tmpl_id;
125 };
126 
127 struct bnxt_ulp_act_match_info {
128 	struct ulp_rte_bitmap	act_sig;
129 	uint32_t		act_hid;
130 	uint32_t		act_tid;
131 };
132 
133 /* Flow Matcher templates Structure for action entries */
134 extern	uint16_t ulp_act_sig_tbl[];
135 extern struct bnxt_ulp_act_match_info ulp_act_match_list[];
136 
137 /* Device specific parameters */
138 struct bnxt_ulp_device_params {
139 	uint8_t				description[16];
140 	enum bnxt_ulp_flow_mem_type	flow_mem_type;
141 	enum bnxt_ulp_byte_order	byte_order;
142 	uint8_t				encap_byte_swap;
143 	uint8_t				num_phy_ports;
144 	uint32_t			mark_db_lfid_entries;
145 	uint64_t			mark_db_gfid_entries;
146 	uint64_t			flow_db_num_entries;
147 	uint32_t			flow_count_db_entries;
148 	uint32_t			num_resources_per_flow;
149 	uint32_t			ext_cntr_table_type;
150 	uint64_t			byte_count_mask;
151 	uint64_t			packet_count_mask;
152 	uint32_t			byte_count_shift;
153 	uint32_t			packet_count_shift;
154 };
155 
156 /* Flow Mapper */
157 struct bnxt_ulp_mapper_tbl_list_info {
158 	uint32_t		device_name;
159 	uint32_t		start_tbl_idx;
160 	uint32_t		num_tbls;
161 	enum bnxt_ulp_fdb_type	flow_db_table_type;
162 };
163 
164 struct bnxt_ulp_mapper_tbl_info {
165 	enum bnxt_ulp_resource_func	resource_func;
166 	uint32_t			resource_type; /* TF_ enum type */
167 	enum bnxt_ulp_resource_sub_type	resource_sub_type;
168 	enum bnxt_ulp_cond_opcode	cond_opcode;
169 	uint32_t			cond_operand;
170 	uint8_t		direction;
171 	uint32_t	priority;
172 	uint8_t		srch_b4_alloc;
173 	enum bnxt_ulp_critical_resource	critical_resource;
174 
175 	/* Information for accessing the ulp_key_field_list */
176 	uint32_t	key_start_idx;
177 	uint16_t	key_bit_size;
178 	uint16_t	key_num_fields;
179 	/* Size of the blob that holds the key */
180 	uint16_t	blob_key_bit_size;
181 
182 	/* Information for accessing the ulp_class_result_field_list */
183 	uint32_t	result_start_idx;
184 	uint16_t	result_bit_size;
185 	uint16_t	result_num_fields;
186 	uint16_t	encap_num_fields;
187 
188 	/* Information for accessing the ulp_ident_list */
189 	uint32_t	ident_start_idx;
190 	uint16_t	ident_nums;
191 
192 	enum bnxt_ulp_mark_db_opcode	mark_db_opcode;
193 	enum bnxt_ulp_index_opcode	index_opcode;
194 	uint32_t			index_operand;
195 };
196 
197 struct bnxt_ulp_mapper_class_key_field_info {
198 	uint8_t				description[64];
199 	enum bnxt_ulp_mapper_opc	mask_opcode;
200 	enum bnxt_ulp_mapper_opc	spec_opcode;
201 	uint16_t			field_bit_size;
202 	uint8_t				mask_operand[16];
203 	uint8_t				spec_operand[16];
204 };
205 
206 struct bnxt_ulp_mapper_result_field_info {
207 	uint8_t				description[64];
208 	enum bnxt_ulp_mapper_opc	result_opcode;
209 	uint16_t			field_bit_size;
210 	uint8_t				result_operand[16];
211 };
212 
213 struct bnxt_ulp_mapper_ident_info {
214 	uint8_t		description[64];
215 	uint32_t	resource_func;
216 
217 	uint16_t	ident_type;
218 	uint16_t	ident_bit_size;
219 	uint16_t	ident_bit_pos;
220 	enum bnxt_ulp_regfile_index	regfile_idx;
221 };
222 
223 struct bnxt_ulp_glb_resource_info {
224 	enum bnxt_ulp_resource_func	resource_func;
225 	uint32_t			resource_type; /* TF_ enum type */
226 	enum bnxt_ulp_glb_regfile_index	glb_regfile_index;
227 	enum tf_dir			direction;
228 };
229 
230 struct bnxt_ulp_cache_tbl_params {
231 	uint16_t num_entries;
232 };
233 
234 /*
235  * Flow Mapper Static Data Externs:
236  * Access to the below static data should be done through access functions and
237  * directly throughout the code.
238  */
239 
240 /*
241  * The ulp_device_params is indexed by the dev_id.
242  * This table maintains the device specific parameters.
243  */
244 extern struct bnxt_ulp_device_params ulp_device_params[];
245 
246 /*
247  * The ulp_class_tmpl_list and ulp_act_tmpl_list are indexed by the dev_id
248  * and template id (either class or action) returned by the matcher.
249  * The result provides the start index and number of entries in the connected
250  * ulp_class_tbl_list/ulp_act_tbl_list.
251  */
252 extern struct bnxt_ulp_mapper_tbl_list_info	ulp_class_tmpl_list[];
253 extern struct bnxt_ulp_mapper_tbl_list_info	ulp_act_tmpl_list[];
254 
255 /*
256  * The ulp_class_tbl_list and ulp_act_tbl_list are indexed based on the results
257  * of the template lists.  Each entry describes the high level details of the
258  * table entry to include the start index and number of instructions in the
259  * field lists.
260  */
261 extern struct bnxt_ulp_mapper_tbl_info	ulp_class_tbl_list[];
262 extern struct bnxt_ulp_mapper_tbl_info	ulp_act_tbl_list[];
263 
264 /*
265  * The ulp_class_result_field_list provides the instructions for creating result
266  * records such as tcam/em results.
267  */
268 extern struct bnxt_ulp_mapper_result_field_info	ulp_class_result_field_list[];
269 
270 /*
271  * The ulp_data_field_list provides the instructions for creating an action
272  * record.  It uses the same structure as the result list, but is only used for
273  * actions.
274  */
275 extern
276 struct bnxt_ulp_mapper_result_field_info ulp_act_result_field_list[];
277 
278 /*
279  * The ulp_act_prop_map_table provides the mapping to index and size of action
280  * tcam and em tables.
281  */
282 extern
283 struct bnxt_ulp_mapper_class_key_field_info	ulp_class_key_field_list[];
284 
285 /*
286  * The ulp_ident_list provides the instructions for creating identifiers such
287  * as profile ids.
288  */
289 extern struct bnxt_ulp_mapper_ident_info	ulp_ident_list[];
290 
291 /*
292  * The ulp_act_prop_map_table provides the mapping to index and size of action
293  * properties.
294  */
295 extern uint32_t ulp_act_prop_map_table[];
296 
297 /*
298  * The ulp_glb_resource_tbl provides the list of global resources that need to
299  * be initialized and where to store them.
300  */
301 extern struct bnxt_ulp_glb_resource_info ulp_glb_resource_tbl[];
302 
303 /*
304  * The ulp_cache_tbl_parms table provides the sizes of the cache tables the
305  * mapper must dynamically allocate during initialization.
306  */
307 extern struct bnxt_ulp_cache_tbl_params ulp_cache_tbl_params[];
308 
309 /*
310  * The ulp_global template table is used to initialize default entries
311  * that could be reused by other templates.
312  */
313 extern uint32_t ulp_glb_template_tbl[];
314 
315 #endif /* _ULP_TEMPLATE_STRUCT_H_ */
316