net/ice/base: replace single-element array hack
[dpdk.git] / drivers / net / ice / base / ice_flex_type.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2020 Intel Corporation
3  */
4
5 #ifndef _ICE_FLEX_TYPE_H_
6 #define _ICE_FLEX_TYPE_H_
7
8 #define ICE_FV_OFFSET_INVAL     0x1FF
9
10 #pragma pack(1)
11 /* Extraction Sequence (Field Vector) Table */
12 struct ice_fv_word {
13         u8 prot_id;
14         u16 off;                /* Offset within the protocol header */
15         u8 resvrd;
16 };
17 #pragma pack()
18
19 #define ICE_MAX_NUM_PROFILES 256
20
21 #define ICE_MAX_FV_WORDS 48
22 struct ice_fv {
23         struct ice_fv_word ew[ICE_MAX_FV_WORDS];
24 };
25
26 /* Package and segment headers and tables */
27 struct ice_pkg_hdr {
28         struct ice_pkg_ver pkg_format_ver;
29         __le32 seg_count;
30         __le32 seg_offset[STRUCT_HACK_VAR_LEN];
31 };
32
33 /* generic segment */
34 struct ice_generic_seg_hdr {
35 #define SEGMENT_TYPE_METADATA   0x00000001
36 #define SEGMENT_TYPE_ICE        0x00000010
37         __le32 seg_type;
38         struct ice_pkg_ver seg_format_ver;
39         __le32 seg_size;
40         char seg_id[ICE_PKG_NAME_SIZE];
41 };
42
43 /* ice specific segment */
44
45 union ice_device_id {
46         struct {
47                 __le16 device_id;
48                 __le16 vendor_id;
49         } dev_vend_id;
50         __le32 id;
51 };
52
53 struct ice_device_id_entry {
54         union ice_device_id device;
55         union ice_device_id sub_device;
56 };
57
58 struct ice_seg {
59         struct ice_generic_seg_hdr hdr;
60         __le32 device_table_count;
61         struct ice_device_id_entry device_table[STRUCT_HACK_VAR_LEN];
62 };
63
64 struct ice_nvm_table {
65         __le32 table_count;
66         __le32 vers[STRUCT_HACK_VAR_LEN];
67 };
68
69 struct ice_buf {
70 #define ICE_PKG_BUF_SIZE        4096
71         u8 buf[ICE_PKG_BUF_SIZE];
72 };
73
74 struct ice_buf_table {
75         __le32 buf_count;
76         struct ice_buf buf_array[STRUCT_HACK_VAR_LEN];
77 };
78
79 /* global metadata specific segment */
80 struct ice_global_metadata_seg {
81         struct ice_generic_seg_hdr hdr;
82         struct ice_pkg_ver pkg_ver;
83         __le32 rsvd;
84         char pkg_name[ICE_PKG_NAME_SIZE];
85 };
86
87 #define ICE_MIN_S_OFF           12
88 #define ICE_MAX_S_OFF           4095
89 #define ICE_MIN_S_SZ            1
90 #define ICE_MAX_S_SZ            4084
91
92 /* section information */
93 struct ice_section_entry {
94         __le32 type;
95         __le16 offset;
96         __le16 size;
97 };
98
99 #define ICE_MIN_S_COUNT         1
100 #define ICE_MAX_S_COUNT         511
101 #define ICE_MIN_S_DATA_END      12
102 #define ICE_MAX_S_DATA_END      4096
103
104 #define ICE_METADATA_BUF        0x80000000
105
106 struct ice_buf_hdr {
107         __le16 section_count;
108         __le16 data_end;
109         struct ice_section_entry section_entry[STRUCT_HACK_VAR_LEN];
110 };
111
112 #define ICE_MAX_ENTRIES_IN_BUF(hd_sz, ent_sz) ((ICE_PKG_BUF_SIZE - \
113         ice_struct_size((struct ice_buf_hdr *)0, section_entry, 1) - (hd_sz)) /\
114         (ent_sz))
115
116 /* ice package section IDs */
117 #define ICE_SID_XLT0_SW                 10
118 #define ICE_SID_XLT_KEY_BUILDER_SW      11
119 #define ICE_SID_XLT1_SW                 12
120 #define ICE_SID_XLT2_SW                 13
121 #define ICE_SID_PROFID_TCAM_SW          14
122 #define ICE_SID_PROFID_REDIR_SW         15
123 #define ICE_SID_FLD_VEC_SW              16
124 #define ICE_SID_CDID_KEY_BUILDER_SW     17
125 #define ICE_SID_CDID_REDIR_SW           18
126
127 #define ICE_SID_XLT0_ACL                20
128 #define ICE_SID_XLT_KEY_BUILDER_ACL     21
129 #define ICE_SID_XLT1_ACL                22
130 #define ICE_SID_XLT2_ACL                23
131 #define ICE_SID_PROFID_TCAM_ACL         24
132 #define ICE_SID_PROFID_REDIR_ACL        25
133 #define ICE_SID_FLD_VEC_ACL             26
134 #define ICE_SID_CDID_KEY_BUILDER_ACL    27
135 #define ICE_SID_CDID_REDIR_ACL          28
136
137 #define ICE_SID_XLT0_FD                 30
138 #define ICE_SID_XLT_KEY_BUILDER_FD      31
139 #define ICE_SID_XLT1_FD                 32
140 #define ICE_SID_XLT2_FD                 33
141 #define ICE_SID_PROFID_TCAM_FD          34
142 #define ICE_SID_PROFID_REDIR_FD         35
143 #define ICE_SID_FLD_VEC_FD              36
144 #define ICE_SID_CDID_KEY_BUILDER_FD     37
145 #define ICE_SID_CDID_REDIR_FD           38
146
147 #define ICE_SID_XLT0_RSS                40
148 #define ICE_SID_XLT_KEY_BUILDER_RSS     41
149 #define ICE_SID_XLT1_RSS                42
150 #define ICE_SID_XLT2_RSS                43
151 #define ICE_SID_PROFID_TCAM_RSS         44
152 #define ICE_SID_PROFID_REDIR_RSS        45
153 #define ICE_SID_FLD_VEC_RSS             46
154 #define ICE_SID_CDID_KEY_BUILDER_RSS    47
155 #define ICE_SID_CDID_REDIR_RSS          48
156
157 #define ICE_SID_RXPARSER_CAM            50
158 #define ICE_SID_RXPARSER_NOMATCH_CAM    51
159 #define ICE_SID_RXPARSER_IMEM           52
160 #define ICE_SID_RXPARSER_XLT0_BUILDER   53
161 #define ICE_SID_RXPARSER_NODE_PTYPE     54
162 #define ICE_SID_RXPARSER_MARKER_PTYPE   55
163 #define ICE_SID_RXPARSER_BOOST_TCAM     56
164 #define ICE_SID_RXPARSER_PROTO_GRP      57
165 #define ICE_SID_RXPARSER_METADATA_INIT  58
166 #define ICE_SID_RXPARSER_XLT0           59
167
168 #define ICE_SID_TXPARSER_CAM            60
169 #define ICE_SID_TXPARSER_NOMATCH_CAM    61
170 #define ICE_SID_TXPARSER_IMEM           62
171 #define ICE_SID_TXPARSER_XLT0_BUILDER   63
172 #define ICE_SID_TXPARSER_NODE_PTYPE     64
173 #define ICE_SID_TXPARSER_MARKER_PTYPE   65
174 #define ICE_SID_TXPARSER_BOOST_TCAM     66
175 #define ICE_SID_TXPARSER_PROTO_GRP      67
176 #define ICE_SID_TXPARSER_METADATA_INIT  68
177 #define ICE_SID_TXPARSER_XLT0           69
178
179 #define ICE_SID_RXPARSER_INIT_REDIR     70
180 #define ICE_SID_TXPARSER_INIT_REDIR     71
181 #define ICE_SID_RXPARSER_MARKER_GRP     72
182 #define ICE_SID_TXPARSER_MARKER_GRP     73
183 #define ICE_SID_RXPARSER_LAST_PROTO     74
184 #define ICE_SID_TXPARSER_LAST_PROTO     75
185 #define ICE_SID_RXPARSER_PG_SPILL       76
186 #define ICE_SID_TXPARSER_PG_SPILL       77
187 #define ICE_SID_RXPARSER_NOMATCH_SPILL  78
188 #define ICE_SID_TXPARSER_NOMATCH_SPILL  79
189
190 #define ICE_SID_XLT0_PE                 80
191 #define ICE_SID_XLT_KEY_BUILDER_PE      81
192 #define ICE_SID_XLT1_PE                 82
193 #define ICE_SID_XLT2_PE                 83
194 #define ICE_SID_PROFID_TCAM_PE          84
195 #define ICE_SID_PROFID_REDIR_PE         85
196 #define ICE_SID_FLD_VEC_PE              86
197 #define ICE_SID_CDID_KEY_BUILDER_PE     87
198 #define ICE_SID_CDID_REDIR_PE           88
199
200 /* Label Metadata section IDs */
201 #define ICE_SID_LBL_FIRST               0x80000010
202 #define ICE_SID_LBL_RXPARSER_IMEM       0x80000010
203 #define ICE_SID_LBL_TXPARSER_IMEM       0x80000011
204 #define ICE_SID_LBL_RESERVED_12         0x80000012
205 #define ICE_SID_LBL_RESERVED_13         0x80000013
206 #define ICE_SID_LBL_RXPARSER_MARKER     0x80000014
207 #define ICE_SID_LBL_TXPARSER_MARKER     0x80000015
208 #define ICE_SID_LBL_PTYPE               0x80000016
209 #define ICE_SID_LBL_PROTOCOL_ID         0x80000017
210 #define ICE_SID_LBL_RXPARSER_TMEM       0x80000018
211 #define ICE_SID_LBL_TXPARSER_TMEM       0x80000019
212 #define ICE_SID_LBL_RXPARSER_PG         0x8000001A
213 #define ICE_SID_LBL_TXPARSER_PG         0x8000001B
214 #define ICE_SID_LBL_RXPARSER_M_TCAM     0x8000001C
215 #define ICE_SID_LBL_TXPARSER_M_TCAM     0x8000001D
216 #define ICE_SID_LBL_SW_PROFID_TCAM      0x8000001E
217 #define ICE_SID_LBL_ACL_PROFID_TCAM     0x8000001F
218 #define ICE_SID_LBL_PE_PROFID_TCAM      0x80000020
219 #define ICE_SID_LBL_RSS_PROFID_TCAM     0x80000021
220 #define ICE_SID_LBL_FD_PROFID_TCAM      0x80000022
221 #define ICE_SID_LBL_FLAG                0x80000023
222 #define ICE_SID_LBL_REG                 0x80000024
223 #define ICE_SID_LBL_SW_PTG              0x80000025
224 #define ICE_SID_LBL_ACL_PTG             0x80000026
225 #define ICE_SID_LBL_PE_PTG              0x80000027
226 #define ICE_SID_LBL_RSS_PTG             0x80000028
227 #define ICE_SID_LBL_FD_PTG              0x80000029
228 #define ICE_SID_LBL_SW_VSIG             0x8000002A
229 #define ICE_SID_LBL_ACL_VSIG            0x8000002B
230 #define ICE_SID_LBL_PE_VSIG             0x8000002C
231 #define ICE_SID_LBL_RSS_VSIG            0x8000002D
232 #define ICE_SID_LBL_FD_VSIG             0x8000002E
233 #define ICE_SID_LBL_PTYPE_META          0x8000002F
234 #define ICE_SID_LBL_SW_PROFID           0x80000030
235 #define ICE_SID_LBL_ACL_PROFID          0x80000031
236 #define ICE_SID_LBL_PE_PROFID           0x80000032
237 #define ICE_SID_LBL_RSS_PROFID          0x80000033
238 #define ICE_SID_LBL_FD_PROFID           0x80000034
239 #define ICE_SID_LBL_RXPARSER_MARKER_GRP 0x80000035
240 #define ICE_SID_LBL_TXPARSER_MARKER_GRP 0x80000036
241 #define ICE_SID_LBL_RXPARSER_PROTO      0x80000037
242 #define ICE_SID_LBL_TXPARSER_PROTO      0x80000038
243 /* The following define MUST be updated to reflect the last label section ID */
244 #define ICE_SID_LBL_LAST                0x80000038
245
246 enum ice_block {
247         ICE_BLK_SW = 0,
248         ICE_BLK_ACL,
249         ICE_BLK_FD,
250         ICE_BLK_RSS,
251         ICE_BLK_PE,
252         ICE_BLK_COUNT
253 };
254
255 enum ice_sect {
256         ICE_XLT0 = 0,
257         ICE_XLT_KB,
258         ICE_XLT1,
259         ICE_XLT2,
260         ICE_PROF_TCAM,
261         ICE_PROF_REDIR,
262         ICE_VEC_TBL,
263         ICE_CDID_KB,
264         ICE_CDID_REDIR,
265         ICE_SECT_COUNT
266 };
267
268 /* Packet Type (PTYPE) values */
269 #define ICE_PTYPE_MAC_PAY               1
270 #define ICE_PTYPE_IPV4FRAG_PAY          22
271 #define ICE_PTYPE_IPV4_PAY              23
272 #define ICE_PTYPE_IPV4_UDP_PAY          24
273 #define ICE_PTYPE_IPV4_TCP_PAY          26
274 #define ICE_PTYPE_IPV4_SCTP_PAY         27
275 #define ICE_PTYPE_IPV4_ICMP_PAY         28
276 #define ICE_PTYPE_IPV6FRAG_PAY          88
277 #define ICE_PTYPE_IPV6_PAY              89
278 #define ICE_PTYPE_IPV6_UDP_PAY          90
279 #define ICE_PTYPE_IPV6_TCP_PAY          92
280 #define ICE_PTYPE_IPV6_SCTP_PAY         93
281 #define ICE_PTYPE_IPV6_ICMP_PAY         94
282 #define ICE_MAC_IPV4_GTPC_TEID          325
283 #define ICE_MAC_IPV6_GTPC_TEID          326
284 #define ICE_MAC_IPV4_GTPC               327
285 #define ICE_MAC_IPV6_GTPC               328
286 #define ICE_MAC_IPV4_GTPU               329
287 #define ICE_MAC_IPV6_GTPU               330
288 #define ICE_MAC_IPV4_GTPU_IPV4_FRAG     331
289 #define ICE_MAC_IPV4_GTPU_IPV4_PAY      332
290 #define ICE_MAC_IPV4_GTPU_IPV4_UDP_PAY  333
291 #define ICE_MAC_IPV4_GTPU_IPV4_TCP      334
292 #define ICE_MAC_IPV4_GTPU_IPV4_ICMP     335
293 #define ICE_MAC_IPV6_GTPU_IPV4_FRAG     336
294 #define ICE_MAC_IPV6_GTPU_IPV4_PAY      337
295 #define ICE_MAC_IPV6_GTPU_IPV4_UDP_PAY  338
296 #define ICE_MAC_IPV6_GTPU_IPV4_TCP      339
297 #define ICE_MAC_IPV6_GTPU_IPV4_ICMP     340
298 #define ICE_MAC_IPV4_GTPU_IPV6_FRAG     341
299 #define ICE_MAC_IPV4_GTPU_IPV6_PAY      342
300 #define ICE_MAC_IPV4_GTPU_IPV6_UDP_PAY  343
301 #define ICE_MAC_IPV4_GTPU_IPV6_TCP      344
302 #define ICE_MAC_IPV4_GTPU_IPV6_ICMPV6   345
303 #define ICE_MAC_IPV6_GTPU_IPV6_FRAG     346
304 #define ICE_MAC_IPV6_GTPU_IPV6_PAY      347
305 #define ICE_MAC_IPV6_GTPU_IPV6_UDP_PAY  348
306 #define ICE_MAC_IPV6_GTPU_IPV6_TCP      349
307 #define ICE_MAC_IPV6_GTPU_IPV6_ICMPV6   350
308
309 /* Attributes that can modify PTYPE definitions.
310  *
311  * These values will represent special attributes for PTYPES, which will
312  * resolve into metadata packet flags definitions that can be used in the TCAM
313  * for identifying a PTYPE with specific characteristics.
314  */
315 enum ice_ptype_attrib_type {
316         /* GTP PTYPES */
317         ICE_PTYPE_ATTR_GTP_PDU_EH,
318         ICE_PTYPE_ATTR_GTP_SESSION,
319         ICE_PTYPE_ATTR_GTP_DOWNLINK,
320         ICE_PTYPE_ATTR_GTP_UPLINK,
321 };
322
323 struct ice_ptype_attrib_info {
324         u16 flags;
325         u16 mask;
326 };
327
328 /* TCAM flag definitions */
329 #define ICE_GTP_PDU                     BIT(14)
330 #define ICE_GTP_PDU_LINK                BIT(13)
331
332 /* GTP attributes */
333 #define ICE_GTP_PDU_FLAG_MASK           (ICE_GTP_PDU)
334 #define ICE_GTP_PDU_EH                  ICE_GTP_PDU
335
336 #define ICE_GTP_FLAGS_MASK              (ICE_GTP_PDU | ICE_GTP_PDU_LINK)
337 #define ICE_GTP_SESSION                 0
338 #define ICE_GTP_DOWNLINK                ICE_GTP_PDU
339 #define ICE_GTP_UPLINK                  (ICE_GTP_PDU | ICE_GTP_PDU_LINK)
340
341 struct ice_ptype_attributes {
342         u16 ptype;
343         enum ice_ptype_attrib_type attrib;
344 };
345
346 /* Packet Type Groups (PTG) - Inner Most fields (IM) */
347 #define ICE_PTG_IM_IPV4_TCP             16
348 #define ICE_PTG_IM_IPV4_UDP             17
349 #define ICE_PTG_IM_IPV4_SCTP            18
350 #define ICE_PTG_IM_IPV4_PAY             20
351 #define ICE_PTG_IM_IPV4_OTHER           21
352 #define ICE_PTG_IM_IPV6_TCP             32
353 #define ICE_PTG_IM_IPV6_UDP             33
354 #define ICE_PTG_IM_IPV6_SCTP            34
355 #define ICE_PTG_IM_IPV6_OTHER           37
356 #define ICE_PTG_IM_L2_OTHER             67
357
358 struct ice_flex_fields {
359         union {
360                 struct {
361                         u8 src_ip;
362                         u8 dst_ip;
363                         u8 flow_label;  /* valid for IPv6 only */
364                 } ip_fields;
365
366                 struct {
367                         u8 src_prt;
368                         u8 dst_prt;
369                 } tcp_udp_fields;
370
371                 struct {
372                         u8 src_ip;
373                         u8 dst_ip;
374                         u8 src_prt;
375                         u8 dst_prt;
376                 } ip_tcp_udp_fields;
377
378                 struct {
379                         u8 src_prt;
380                         u8 dst_prt;
381                         u8 flow_label;  /* valid for IPv6 only */
382                         u8 spi;
383                 } ip_esp_fields;
384
385                 struct {
386                         u32 offset;
387                         u32 length;
388                 } off_len;
389         } fields;
390 };
391
392 #define ICE_XLT1_DFLT_GRP       0
393 #define ICE_XLT1_TABLE_SIZE     1024
394
395 /* package labels */
396 struct ice_label {
397         __le16 value;
398 #define ICE_PKG_LABEL_SIZE      64
399         char name[ICE_PKG_LABEL_SIZE];
400 };
401
402 struct ice_label_section {
403         __le16 count;
404         struct ice_label label[STRUCT_HACK_VAR_LEN];
405 };
406
407 #define ICE_MAX_LABELS_IN_BUF ICE_MAX_ENTRIES_IN_BUF( \
408         ice_struct_size((struct ice_label_section *)0, label, 1) - \
409         sizeof(struct ice_label), sizeof(struct ice_label))
410
411 struct ice_sw_fv_section {
412         __le16 count;
413         __le16 base_offset;
414         struct ice_fv fv[STRUCT_HACK_VAR_LEN];
415 };
416
417 struct ice_sw_fv_list_entry {
418         struct LIST_ENTRY_TYPE list_entry;
419         u32 profile_id;
420         struct ice_fv *fv_ptr;
421 };
422
423 #pragma pack(1)
424 /* The BOOST TCAM stores the match packet header in reverse order, meaning
425  * the fields are reversed; in addition, this means that the normally big endian
426  * fields of the packet are now little endian.
427  */
428 struct ice_boost_key_value {
429 #define ICE_BOOST_REMAINING_HV_KEY      15
430         u8 remaining_hv_key[ICE_BOOST_REMAINING_HV_KEY];
431         __le16 hv_dst_port_key;
432         __le16 hv_src_port_key;
433         u8 tcam_search_key;
434 };
435 #pragma pack()
436
437 struct ice_boost_key {
438         struct ice_boost_key_value key;
439         struct ice_boost_key_value key2;
440 };
441
442 /* package Boost TCAM entry */
443 struct ice_boost_tcam_entry {
444         __le16 addr;
445         __le16 reserved;
446         /* break up the 40 bytes of key into different fields */
447         struct ice_boost_key key;
448         u8 boost_hit_index_group;
449         /* The following contains bitfields which are not on byte boundaries.
450          * These fields are currently unused by driver software.
451          */
452 #define ICE_BOOST_BIT_FIELDS            43
453         u8 bit_fields[ICE_BOOST_BIT_FIELDS];
454 };
455
456 struct ice_boost_tcam_section {
457         __le16 count;
458         __le16 reserved;
459         struct ice_boost_tcam_entry tcam[STRUCT_HACK_VAR_LEN];
460 };
461
462 #define ICE_MAX_BST_TCAMS_IN_BUF ICE_MAX_ENTRIES_IN_BUF( \
463         ice_struct_size((struct ice_boost_tcam_section *)0, tcam, 1) - \
464         sizeof(struct ice_boost_tcam_entry), \
465         sizeof(struct ice_boost_tcam_entry))
466
467 struct ice_xlt1_section {
468         __le16 count;
469         __le16 offset;
470         u8 value[STRUCT_HACK_VAR_LEN];
471 };
472
473 struct ice_xlt2_section {
474         __le16 count;
475         __le16 offset;
476         __le16 value[STRUCT_HACK_VAR_LEN];
477 };
478
479 struct ice_prof_redir_section {
480         __le16 count;
481         __le16 offset;
482         u8 redir_value[STRUCT_HACK_VAR_LEN];
483 };
484
485 /* package buffer building */
486
487 struct ice_buf_build {
488         struct ice_buf buf;
489         u16 reserved_section_table_entries;
490 };
491
492 struct ice_pkg_enum {
493         struct ice_buf_table *buf_table;
494         u32 buf_idx;
495
496         u32 type;
497         struct ice_buf_hdr *buf;
498         u32 sect_idx;
499         void *sect;
500         u32 sect_type;
501
502         u32 entry_idx;
503         void *(*handler)(u32 sect_type, void *section, u32 index, u32 *offset);
504 };
505
506 /* Tunnel enabling */
507
508 enum ice_tunnel_type {
509         TNL_VXLAN = 0,
510         TNL_GENEVE,
511         TNL_LAST = 0xFF,
512         TNL_ALL = 0xFF,
513 };
514
515 struct ice_tunnel_type_scan {
516         enum ice_tunnel_type type;
517         const char *label_prefix;
518 };
519
520 struct ice_tunnel_entry {
521         enum ice_tunnel_type type;
522         u16 boost_addr;
523         u16 port;
524         u16 ref;
525         struct ice_boost_tcam_entry *boost_entry;
526         u8 valid;
527         u8 in_use;
528         u8 marked;
529 };
530
531 #define ICE_TUNNEL_MAX_ENTRIES  16
532
533 struct ice_tunnel_table {
534         struct ice_tunnel_entry tbl[ICE_TUNNEL_MAX_ENTRIES];
535         u16 count;
536 };
537
538 struct ice_pkg_es {
539         __le16 count;
540         __le16 offset;
541         struct ice_fv_word es[STRUCT_HACK_VAR_LEN];
542 };
543
544 struct ice_es {
545         u32 sid;
546         u16 count;
547         u16 fvw;
548         u16 *ref_count;
549         u32 *mask_ena;
550         struct LIST_HEAD_TYPE prof_map;
551         struct ice_fv_word *t;
552         struct ice_lock prof_map_lock;  /* protect access to profiles list */
553         u8 *written;
554         u8 reverse; /* set to true to reverse FV order */
555 };
556
557 /* PTYPE Group management */
558
559 /* Note: XLT1 table takes 13-bit as input, and results in an 8-bit packet type
560  * group (PTG) ID as output.
561  *
562  * Note: PTG 0 is the default packet type group and it is assumed that all PTYPE
563  * are a part of this group until moved to a new PTG.
564  */
565 #define ICE_DEFAULT_PTG 0
566
567 struct ice_ptg_entry {
568         struct ice_ptg_ptype *first_ptype;
569         u8 in_use;
570 };
571
572 struct ice_ptg_ptype {
573         struct ice_ptg_ptype *next_ptype;
574         u8 ptg;
575 };
576
577 #define ICE_MAX_TCAM_PER_PROFILE        32
578 #define ICE_MAX_PTG_PER_PROFILE         32
579
580 struct ice_prof_map {
581         struct LIST_ENTRY_TYPE list;
582         u64 profile_cookie;
583         u64 context;
584         u8 prof_id;
585         u8 ptg_cnt;
586         u8 ptg[ICE_MAX_PTG_PER_PROFILE];
587         struct ice_ptype_attrib_info attr[ICE_MAX_PTG_PER_PROFILE];
588 };
589
590 #define ICE_INVALID_TCAM        0xFFFF
591
592 struct ice_tcam_inf {
593         u16 tcam_idx;
594         struct ice_ptype_attrib_info attr;
595         u8 ptg;
596         u8 prof_id;
597         u8 in_use;
598 };
599
600 struct ice_vsig_prof {
601         struct LIST_ENTRY_TYPE list;
602         u64 profile_cookie;
603         u8 prof_id;
604         u8 tcam_count;
605         struct ice_tcam_inf tcam[ICE_MAX_TCAM_PER_PROFILE];
606 };
607
608 struct ice_vsig_entry {
609         struct LIST_HEAD_TYPE prop_lst;
610         struct ice_vsig_vsi *first_vsi;
611         u8 in_use;
612 };
613
614 struct ice_vsig_vsi {
615         struct ice_vsig_vsi *next_vsi;
616         u32 prop_mask;
617         u16 changed;
618         u16 vsig;
619 };
620
621 #define ICE_XLT1_CNT    1024
622 #define ICE_MAX_PTGS    256
623
624 /* XLT1 Table */
625 struct ice_xlt1 {
626         struct ice_ptg_entry *ptg_tbl;
627         struct ice_ptg_ptype *ptypes;
628         u8 *t;
629         u32 sid;
630         u16 count;
631 };
632
633 #define ICE_XLT2_CNT    768
634 #define ICE_MAX_VSIGS   768
635
636 /* VSIG bit layout:
637  * [0:12]: incremental VSIG index 1 to ICE_MAX_VSIGS
638  * [13:15]: PF number of device
639  */
640 #define ICE_VSIG_IDX_M  (0x1FFF)
641 #define ICE_PF_NUM_S    13
642 #define ICE_PF_NUM_M    (0x07 << ICE_PF_NUM_S)
643 #define ICE_VSIG_VALUE(vsig, pf_id) \
644         (u16)((((u16)(vsig)) & ICE_VSIG_IDX_M) | \
645               (((u16)(pf_id) << ICE_PF_NUM_S) & ICE_PF_NUM_M))
646 #define ICE_DEFAULT_VSIG        0
647
648 /* XLT2 Table */
649 struct ice_xlt2 {
650         struct ice_vsig_entry *vsig_tbl;
651         struct ice_vsig_vsi *vsis;
652         u16 *t;
653         u32 sid;
654         u16 count;
655 };
656
657 /* Extraction sequence - list of match fields:
658  * protocol ID, offset, profile length
659  */
660 union ice_match_fld {
661         struct {
662                 u8 prot_id;
663                 u8 offset;
664                 u8 length;
665                 u8 reserved; /* must be zero */
666         } fld;
667         u32 val;
668 };
669
670 #define ICE_MATCH_LIST_SZ       20
671 #pragma pack(1)
672 struct ice_match {
673         u8 count;
674         union ice_match_fld list[ICE_MATCH_LIST_SZ];
675 };
676
677 /* Profile ID Management */
678 struct ice_prof_id_key {
679         __le16 flags;
680         u8 xlt1;
681         __le16 xlt2_cdid;
682 };
683
684 /* Keys are made up of two values, each one-half the size of the key.
685  * For TCAM, the entire key is 80 bits wide (or 2, 40-bit wide values)
686  */
687 #define ICE_TCAM_KEY_VAL_SZ     5
688 #define ICE_TCAM_KEY_SZ         (2 * ICE_TCAM_KEY_VAL_SZ)
689
690 struct ice_prof_tcam_entry {
691         __le16 addr;
692         u8 key[ICE_TCAM_KEY_SZ];
693         u8 prof_id;
694 };
695
696 #pragma pack()
697
698 struct ice_prof_id_section {
699         __le16 count;
700         struct ice_prof_tcam_entry entry[STRUCT_HACK_VAR_LEN];
701 };
702
703 struct ice_prof_tcam {
704         u32 sid;
705         u16 count;
706         u16 max_prof_id;
707         struct ice_prof_tcam_entry *t;
708         u8 cdid_bits; /* # CDID bits to use in key, 0, 2, 4, or 8 */
709 };
710
711 struct ice_prof_redir {
712         u8 *t;
713         u32 sid;
714         u16 count;
715 };
716
717 struct ice_mask {
718         u16 mask;       /* 16-bit mask */
719         u16 idx;        /* index */
720         u16 ref;        /* reference count */
721         u8 in_use;      /* non-zero if used */
722 };
723
724 struct ice_masks {
725         struct ice_lock lock;  /* lock to protect this structure */
726         u16 first;      /* first mask owned by the PF */
727         u16 count;      /* number of masks owned by the PF */
728 #define ICE_PROF_MASK_COUNT 32
729         struct ice_mask masks[ICE_PROF_MASK_COUNT];
730 };
731
732 /* Tables per block */
733 struct ice_blk_info {
734         struct ice_xlt1 xlt1;
735         struct ice_xlt2 xlt2;
736         struct ice_prof_tcam prof;
737         struct ice_prof_redir prof_redir;
738         struct ice_es es;
739         struct ice_masks masks;
740         u8 overwrite; /* set to true to allow overwrite of table entries */
741         u8 is_list_init;
742 };
743
744 enum ice_chg_type {
745         ICE_TCAM_NONE = 0,
746         ICE_PTG_ES_ADD,
747         ICE_TCAM_ADD,
748         ICE_VSIG_ADD,
749         ICE_VSIG_REM,
750         ICE_VSI_MOVE,
751 };
752
753 struct ice_chs_chg {
754         struct LIST_ENTRY_TYPE list_entry;
755         enum ice_chg_type type;
756
757         u8 add_ptg;
758         u8 add_vsig;
759         u8 add_tcam_idx;
760         u8 add_prof;
761         u16 ptype;
762         u8 ptg;
763         u8 prof_id;
764         u16 vsi;
765         u16 vsig;
766         u16 orig_vsig;
767         u16 tcam_idx;
768         struct ice_ptype_attrib_info attr;
769 };
770
771 #define ICE_FLOW_PTYPE_MAX              ICE_XLT1_CNT
772
773 enum ice_prof_type {
774         ICE_PROF_NON_TUN = 0x1,
775         ICE_PROF_TUN_UDP = 0x2,
776         ICE_PROF_TUN_GRE = 0x4,
777         ICE_PROF_TUN_PPPOE = 0x8,
778         ICE_PROF_TUN_ALL = 0xE,
779         ICE_PROF_ALL = 0xFF,
780 };
781 #endif /* _ICE_FLEX_TYPE_H_ */