1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2019, Intel Corporation. */
3 
4 #ifndef _ICE_FLEX_TYPE_H_
5 #define _ICE_FLEX_TYPE_H_
6 #include "ice_ddp.h"
7 
8 /* Packet Type (PTYPE) values */
9 #define ICE_PTYPE_MAC_PAY		1
10 #define ICE_PTYPE_IPV4_PAY		23
11 #define ICE_PTYPE_IPV4_UDP_PAY		24
12 #define ICE_PTYPE_IPV4_TCP_PAY		26
13 #define ICE_PTYPE_IPV4_SCTP_PAY		27
14 #define ICE_PTYPE_IPV6_PAY		89
15 #define ICE_PTYPE_IPV6_UDP_PAY		90
16 #define ICE_PTYPE_IPV6_TCP_PAY		92
17 #define ICE_PTYPE_IPV6_SCTP_PAY		93
18 #define ICE_MAC_IPV4_ESP		160
19 #define ICE_MAC_IPV6_ESP		161
20 #define ICE_MAC_IPV4_AH			162
21 #define ICE_MAC_IPV6_AH			163
22 #define ICE_MAC_IPV4_NAT_T_ESP		164
23 #define ICE_MAC_IPV6_NAT_T_ESP		165
24 #define ICE_MAC_IPV4_GTPU		329
25 #define ICE_MAC_IPV6_GTPU		330
26 #define ICE_MAC_IPV4_GTPU_IPV4_FRAG	331
27 #define ICE_MAC_IPV4_GTPU_IPV4_PAY	332
28 #define ICE_MAC_IPV4_GTPU_IPV4_UDP_PAY	333
29 #define ICE_MAC_IPV4_GTPU_IPV4_TCP	334
30 #define ICE_MAC_IPV4_GTPU_IPV4_ICMP	335
31 #define ICE_MAC_IPV6_GTPU_IPV4_FRAG	336
32 #define ICE_MAC_IPV6_GTPU_IPV4_PAY	337
33 #define ICE_MAC_IPV6_GTPU_IPV4_UDP_PAY	338
34 #define ICE_MAC_IPV6_GTPU_IPV4_TCP	339
35 #define ICE_MAC_IPV6_GTPU_IPV4_ICMP	340
36 #define ICE_MAC_IPV4_GTPU_IPV6_FRAG	341
37 #define ICE_MAC_IPV4_GTPU_IPV6_PAY	342
38 #define ICE_MAC_IPV4_GTPU_IPV6_UDP_PAY	343
39 #define ICE_MAC_IPV4_GTPU_IPV6_TCP	344
40 #define ICE_MAC_IPV4_GTPU_IPV6_ICMPV6	345
41 #define ICE_MAC_IPV6_GTPU_IPV6_FRAG	346
42 #define ICE_MAC_IPV6_GTPU_IPV6_PAY	347
43 #define ICE_MAC_IPV6_GTPU_IPV6_UDP_PAY	348
44 #define ICE_MAC_IPV6_GTPU_IPV6_TCP	349
45 #define ICE_MAC_IPV6_GTPU_IPV6_ICMPV6	350
46 #define ICE_MAC_IPV4_PFCP_SESSION	352
47 #define ICE_MAC_IPV6_PFCP_SESSION	354
48 #define ICE_MAC_IPV4_L2TPV3		360
49 #define ICE_MAC_IPV6_L2TPV3		361
50 
51 /* Attributes that can modify PTYPE definitions.
52  *
53  * These values will represent special attributes for PTYPEs, which will
54  * resolve into metadata packet flags definitions that can be used in the TCAM
55  * for identifying a PTYPE with specific characteristics.
56  */
57 enum ice_ptype_attrib_type {
58 	/* GTP PTYPEs */
59 	ICE_PTYPE_ATTR_GTP_PDU_EH,
60 	ICE_PTYPE_ATTR_GTP_SESSION,
61 	ICE_PTYPE_ATTR_GTP_DOWNLINK,
62 	ICE_PTYPE_ATTR_GTP_UPLINK,
63 };
64 
65 struct ice_ptype_attrib_info {
66 	u16 flags;
67 	u16 mask;
68 };
69 
70 /* TCAM flag definitions */
71 #define ICE_GTP_PDU			BIT(14)
72 #define ICE_GTP_PDU_LINK		BIT(13)
73 
74 /* GTP attributes */
75 #define ICE_GTP_PDU_FLAG_MASK		(ICE_GTP_PDU)
76 #define ICE_GTP_PDU_EH			ICE_GTP_PDU
77 
78 #define ICE_GTP_FLAGS_MASK		(ICE_GTP_PDU | ICE_GTP_PDU_LINK)
79 #define ICE_GTP_SESSION			0
80 #define ICE_GTP_DOWNLINK		ICE_GTP_PDU
81 #define ICE_GTP_UPLINK			(ICE_GTP_PDU | ICE_GTP_PDU_LINK)
82 
83 struct ice_ptype_attributes {
84 	u16 ptype;
85 	enum ice_ptype_attrib_type attrib;
86 };
87 
88 /* Tunnel enabling */
89 
90 enum ice_tunnel_type {
91 	TNL_VXLAN = 0,
92 	TNL_GENEVE,
93 	TNL_GRETAP,
94 	TNL_GTPC,
95 	TNL_GTPU,
96 	TNL_PFCP,
97 	__TNL_TYPE_CNT,
98 	TNL_LAST = 0xFF,
99 	TNL_ALL = 0xFF,
100 };
101 
102 struct ice_tunnel_type_scan {
103 	enum ice_tunnel_type type;
104 	const char *label_prefix;
105 };
106 
107 struct ice_tunnel_entry {
108 	enum ice_tunnel_type type;
109 	u16 boost_addr;
110 	u16 port;
111 	struct ice_boost_tcam_entry *boost_entry;
112 	u8 valid;
113 };
114 
115 #define ICE_TUNNEL_MAX_ENTRIES	16
116 
117 struct ice_tunnel_table {
118 	struct ice_tunnel_entry tbl[ICE_TUNNEL_MAX_ENTRIES];
119 	u16 count;
120 	u16 valid_count[__TNL_TYPE_CNT];
121 };
122 
123 struct ice_dvm_entry {
124 	u16 boost_addr;
125 	u16 enable;
126 	struct ice_boost_tcam_entry *boost_entry;
127 };
128 
129 #define ICE_DVM_MAX_ENTRIES	48
130 
131 struct ice_dvm_table {
132 	struct ice_dvm_entry tbl[ICE_DVM_MAX_ENTRIES];
133 	u16 count;
134 };
135 
136 struct ice_pkg_es {
137 	__le16 count;
138 	__le16 offset;
139 	struct ice_fv_word es[];
140 };
141 
142 struct ice_es {
143 	u32 sid;
144 	u16 count;
145 	u16 fvw;
146 	u16 *ref_count;
147 	u32 *mask_ena;
148 	struct list_head prof_map;
149 	struct ice_fv_word *t;
150 	u8 *symm;	/* symmetric setting per profile (RSS blk)*/
151 	struct mutex prof_map_lock;	/* protect access to profiles list */
152 	u8 *written;
153 	u8 reverse; /* set to true to reverse FV order */
154 };
155 
156 /* PTYPE Group management */
157 
158 /* Note: XLT1 table takes 13-bit as input, and results in an 8-bit packet type
159  * group (PTG) ID as output.
160  *
161  * Note: PTG 0 is the default packet type group and it is assumed that all PTYPE
162  * are a part of this group until moved to a new PTG.
163  */
164 #define ICE_DEFAULT_PTG	0
165 
166 struct ice_ptg_entry {
167 	struct ice_ptg_ptype *first_ptype;
168 	u8 in_use;
169 };
170 
171 struct ice_ptg_ptype {
172 	struct ice_ptg_ptype *next_ptype;
173 	u8 ptg;
174 };
175 
176 #define ICE_MAX_TCAM_PER_PROFILE	32
177 #define ICE_MAX_PTG_PER_PROFILE		32
178 
179 struct ice_prof_map {
180 	struct list_head list;
181 	u64 profile_cookie;
182 	u64 context;
183 	u8 prof_id;
184 	u8 ptg_cnt;
185 	u8 ptg[ICE_MAX_PTG_PER_PROFILE];
186 	struct ice_ptype_attrib_info attr[ICE_MAX_PTG_PER_PROFILE];
187 };
188 
189 #define ICE_INVALID_TCAM	0xFFFF
190 
191 struct ice_tcam_inf {
192 	u16 tcam_idx;
193 	struct ice_ptype_attrib_info attr;
194 	u8 ptg;
195 	u8 prof_id;
196 	u8 in_use;
197 };
198 
199 struct ice_vsig_prof {
200 	struct list_head list;
201 	u64 profile_cookie;
202 	u8 prof_id;
203 	u8 tcam_count;
204 	struct ice_tcam_inf tcam[ICE_MAX_TCAM_PER_PROFILE];
205 };
206 
207 struct ice_vsig_entry {
208 	struct list_head prop_lst;
209 	struct ice_vsig_vsi *first_vsi;
210 	u8 in_use;
211 };
212 
213 struct ice_vsig_vsi {
214 	struct ice_vsig_vsi *next_vsi;
215 	u32 prop_mask;
216 	u16 changed;
217 	u16 vsig;
218 };
219 
220 #define ICE_XLT1_CNT	1024
221 #define ICE_MAX_PTGS	256
222 
223 /* XLT1 Table */
224 struct ice_xlt1 {
225 	struct ice_ptg_entry *ptg_tbl;
226 	struct ice_ptg_ptype *ptypes;
227 	u8 *t;
228 	u32 sid;
229 	u16 count;
230 };
231 
232 #define ICE_XLT2_CNT	768
233 #define ICE_MAX_VSIGS	768
234 
235 /* VSIG bit layout:
236  * [0:12]: incremental VSIG index 1 to ICE_MAX_VSIGS
237  * [13:15]: PF number of device
238  */
239 #define ICE_VSIG_IDX_M	(0x1FFF)
240 #define ICE_PF_NUM_S	13
241 #define ICE_PF_NUM_M	(0x07 << ICE_PF_NUM_S)
242 #define ICE_VSIG_VALUE(vsig, pf_id) \
243 	((u16)((((u16)(vsig)) & ICE_VSIG_IDX_M) | \
244 	       (((u16)(pf_id) << ICE_PF_NUM_S) & ICE_PF_NUM_M)))
245 #define ICE_DEFAULT_VSIG	0
246 
247 /* XLT2 Table */
248 struct ice_xlt2 {
249 	struct ice_vsig_entry *vsig_tbl;
250 	struct ice_vsig_vsi *vsis;
251 	u16 *t;
252 	u32 sid;
253 	u16 count;
254 };
255 
256 /* Profile ID Management */
257 struct ice_prof_id_key {
258 	__le16 flags;
259 	u8 xlt1;
260 	__le16 xlt2_cdid;
261 } __packed;
262 
263 /* Keys are made up of two values, each one-half the size of the key.
264  * For TCAM, the entire key is 80 bits wide (or 2, 40-bit wide values)
265  */
266 #define ICE_TCAM_KEY_VAL_SZ	5
267 #define ICE_TCAM_KEY_SZ		(2 * ICE_TCAM_KEY_VAL_SZ)
268 
269 struct ice_prof_tcam_entry {
270 	__le16 addr;
271 	u8 key[ICE_TCAM_KEY_SZ];
272 	u8 prof_id;
273 } __packed;
274 
275 struct ice_prof_id_section {
276 	__le16 count;
277 	struct ice_prof_tcam_entry entry[];
278 };
279 
280 struct ice_prof_tcam {
281 	u32 sid;
282 	u16 count;
283 	u16 max_prof_id;
284 	struct ice_prof_tcam_entry *t;
285 	u8 cdid_bits; /* # CDID bits to use in key, 0, 2, 4, or 8 */
286 };
287 
288 struct ice_prof_redir {
289 	u8 *t;
290 	u32 sid;
291 	u16 count;
292 };
293 
294 struct ice_mask {
295 	u16 mask;	/* 16-bit mask */
296 	u16 idx;	/* index */
297 	u16 ref;	/* reference count */
298 	u8 in_use;	/* non-zero if used */
299 };
300 
301 struct ice_masks {
302 	struct mutex lock; /* lock to protect this structure */
303 	u16 first;	/* first mask owned by the PF */
304 	u16 count;	/* number of masks owned by the PF */
305 #define ICE_PROF_MASK_COUNT 32
306 	struct ice_mask masks[ICE_PROF_MASK_COUNT];
307 };
308 
309 struct ice_prof_id {
310 	unsigned long *id;
311 	int count;
312 };
313 
314 /* Tables per block */
315 struct ice_blk_info {
316 	struct ice_xlt1 xlt1;
317 	struct ice_xlt2 xlt2;
318 	struct ice_prof_id prof_id;
319 	struct ice_prof_tcam prof;
320 	struct ice_prof_redir prof_redir;
321 	struct ice_es es;
322 	struct ice_masks masks;
323 	u8 overwrite; /* set to true to allow overwrite of table entries */
324 	u8 is_list_init;
325 };
326 
327 enum ice_chg_type {
328 	ICE_TCAM_NONE = 0,
329 	ICE_PTG_ES_ADD,
330 	ICE_TCAM_ADD,
331 	ICE_VSIG_ADD,
332 	ICE_VSIG_REM,
333 	ICE_VSI_MOVE,
334 };
335 
336 struct ice_chs_chg {
337 	struct list_head list_entry;
338 	enum ice_chg_type type;
339 
340 	u8 add_ptg;
341 	u8 add_vsig;
342 	u8 add_tcam_idx;
343 	u8 add_prof;
344 	u16 ptype;
345 	u8 ptg;
346 	u8 prof_id;
347 	u16 vsi;
348 	u16 vsig;
349 	u16 orig_vsig;
350 	u16 tcam_idx;
351 	struct ice_ptype_attrib_info attr;
352 };
353 
354 #define ICE_FLOW_PTYPE_MAX		ICE_XLT1_CNT
355 
356 enum ice_prof_type {
357 	ICE_PROF_NON_TUN = 0x1,
358 	ICE_PROF_TUN_UDP = 0x2,
359 	ICE_PROF_TUN_GRE = 0x4,
360 	ICE_PROF_TUN_GTPU = 0x8,
361 	ICE_PROF_TUN_GTPC = 0x10,
362 	ICE_PROF_TUN_PFCP = 0x20,
363 	ICE_PROF_TUN_ALL = 0x3E,
364 	ICE_PROF_ALL = 0xFF,
365 };
366 
367 /* Number of bits/bytes contained in meta init entry. Note, this should be a
368  * multiple of 32 bits.
369  */
370 #define ICE_META_INIT_BITS	192
371 #define ICE_META_INIT_DW_CNT	(ICE_META_INIT_BITS / (sizeof(__le32) * \
372 				 BITS_PER_BYTE))
373 
374 /* The meta init Flag field starts at this bit */
375 #define ICE_META_FLAGS_ST		123
376 
377 /* The entry and bit to check for Double VLAN Mode (DVM) support */
378 #define ICE_META_VLAN_MODE_ENTRY	0
379 #define ICE_META_FLAG_VLAN_MODE		60
380 #define ICE_META_VLAN_MODE_BIT		(ICE_META_FLAGS_ST + \
381 					 ICE_META_FLAG_VLAN_MODE)
382 
383 struct ice_meta_init_entry {
384 	__le32 bm[ICE_META_INIT_DW_CNT];
385 };
386 
387 struct ice_meta_init_section {
388 	__le16 count;
389 	__le16 offset;
390 	struct ice_meta_init_entry entry;
391 };
392 #endif /* _ICE_FLEX_TYPE_H_ */
393