4d3136fb26a32ace2c4181264d0dfe5325203473
[dpdk.git] / drivers / net / ice / base / ice_protocol_type.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2020 Intel Corporation
3  */
4
5 #ifndef _ICE_PROTOCOL_TYPE_H_
6 #define _ICE_PROTOCOL_TYPE_H_
7 #include "ice_flex_type.h"
8 #define ICE_IPV6_ADDR_LENGTH 16
9
10 /* Each recipe can match up to 5 different fields. Fields to match can be meta-
11  * data, values extracted from packet headers, or results from other recipes.
12  * One of the 5 fields is reserved for matching the switch ID. So, up to 4
13  * recipes can provide intermediate results to another one through chaining,
14  * e.g. recipes 0, 1, 2, and 3 can provide intermediate results to recipe 4.
15  */
16 #define ICE_NUM_WORDS_RECIPE 4
17
18 /* Max recipes that can be chained */
19 #define ICE_MAX_CHAIN_RECIPE 5
20
21 /* 1 word reserved for switch ID from allowed 5 words.
22  * So a recipe can have max 4 words. And you can chain 5 such recipes
23  * together. So maximum words that can be programmed for look up is 5 * 4.
24  */
25 #define ICE_MAX_CHAIN_WORDS (ICE_NUM_WORDS_RECIPE * ICE_MAX_CHAIN_RECIPE)
26
27 /* Field vector index corresponding to chaining */
28 #define ICE_CHAIN_FV_INDEX_START 47
29
30 enum ice_protocol_type {
31         ICE_MAC_OFOS = 0,
32         ICE_MAC_IL,
33         ICE_ETYPE_OL,
34         ICE_VLAN_OFOS,
35         ICE_IPV4_OFOS,
36         ICE_IPV4_IL,
37         ICE_IPV6_OFOS,
38         ICE_IPV6_IL,
39         ICE_TCP_IL,
40         ICE_UDP_OF,
41         ICE_UDP_ILOS,
42         ICE_SCTP_IL,
43         ICE_VXLAN,
44         ICE_GENEVE,
45         ICE_VXLAN_GPE,
46         ICE_NVGRE,
47         ICE_GTP,
48         ICE_PPPOE,
49         ICE_PFCP,
50         ICE_L2TPV3,
51         ICE_ESP,
52         ICE_AH,
53         ICE_NAT_T,
54         ICE_GTP_NO_PAY,
55         ICE_PROTOCOL_LAST
56 };
57
58 enum ice_sw_tunnel_type {
59         ICE_NON_TUN = 0,
60         ICE_SW_TUN_AND_NON_TUN,
61         ICE_SW_TUN_VXLAN_GPE,
62         ICE_SW_TUN_GENEVE,      /* GENEVE matches only non-VLAN pkts */
63         ICE_SW_TUN_GENEVE_VLAN, /* GENEVE matches both VLAN and non-VLAN pkts */
64         ICE_SW_TUN_VXLAN,       /* VXLAN matches only non-VLAN pkts */
65         ICE_SW_TUN_VXLAN_VLAN,  /* VXLAN matches both VLAN and non-VLAN pkts */
66         ICE_SW_TUN_NVGRE,
67         ICE_SW_TUN_UDP, /* This means all "UDP" tunnel types: VXLAN-GPE, VXLAN
68                          * and GENEVE
69                          */
70         ICE_SW_IPV4_TCP,
71         ICE_SW_IPV4_UDP,
72         ICE_SW_IPV6_TCP,
73         ICE_SW_IPV6_UDP,
74         ICE_SW_TUN_GTP,
75         ICE_SW_TUN_IPV4_GTPU_NO_PAY,
76         ICE_SW_TUN_IPV6_GTPU_NO_PAY,
77         ICE_SW_TUN_IPV4_GTPU_IPV4,
78         ICE_SW_TUN_IPV4_GTPU_IPV6,
79         ICE_SW_TUN_IPV6_GTPU_IPV4,
80         ICE_SW_TUN_IPV6_GTPU_IPV6,
81         ICE_SW_TUN_PPPOE,
82         ICE_SW_TUN_PPPOE_PAY,
83         ICE_SW_TUN_PPPOE_IPV4,
84         ICE_SW_TUN_PPPOE_IPV4_TCP,
85         ICE_SW_TUN_PPPOE_IPV4_UDP,
86         ICE_SW_TUN_PPPOE_IPV6,
87         ICE_SW_TUN_PPPOE_IPV6_TCP,
88         ICE_SW_TUN_PPPOE_IPV6_UDP,
89         ICE_SW_TUN_IPV4_ESP,
90         ICE_SW_TUN_IPV6_ESP,
91         ICE_SW_TUN_IPV4_AH,
92         ICE_SW_TUN_IPV6_AH,
93         ICE_SW_TUN_IPV4_NAT_T,
94         ICE_SW_TUN_IPV6_NAT_T,
95         ICE_SW_TUN_IPV4_L2TPV3,
96         ICE_SW_TUN_IPV6_L2TPV3,
97         ICE_SW_TUN_PROFID_IPV6_ESP,
98         ICE_SW_TUN_PROFID_IPV6_AH,
99         ICE_SW_TUN_PROFID_MAC_IPV6_L2TPV3,
100         ICE_SW_TUN_PROFID_IPV6_NAT_T,
101         ICE_SW_TUN_PROFID_IPV4_PFCP_NODE,
102         ICE_SW_TUN_PROFID_IPV4_PFCP_SESSION,
103         ICE_SW_TUN_PROFID_IPV6_PFCP_NODE,
104         ICE_SW_TUN_PROFID_IPV6_PFCP_SESSION,
105         ICE_ALL_TUNNELS /* All tunnel types including NVGRE */
106 };
107
108 /* Decoders for ice_prot_id:
109  * - F: First
110  * - I: Inner
111  * - L: Last
112  * - O: Outer
113  * - S: Single
114  */
115 enum ice_prot_id {
116         ICE_PROT_ID_INVAL       = 0,
117         ICE_PROT_MAC_OF_OR_S    = 1,
118         ICE_PROT_MAC_O2         = 2,
119         ICE_PROT_MAC_IL         = 4,
120         ICE_PROT_MAC_IN_MAC     = 7,
121         ICE_PROT_ETYPE_OL       = 9,
122         ICE_PROT_ETYPE_IL       = 10,
123         ICE_PROT_PAY            = 15,
124         ICE_PROT_EVLAN_O        = 16,
125         ICE_PROT_VLAN_O         = 17,
126         ICE_PROT_VLAN_IF        = 18,
127         ICE_PROT_MPLS_OL_MINUS_1 = 27,
128         ICE_PROT_MPLS_OL_OR_OS  = 28,
129         ICE_PROT_MPLS_IL        = 29,
130         ICE_PROT_IPV4_OF_OR_S   = 32,
131         ICE_PROT_IPV4_IL        = 33,
132         ICE_PROT_IPV6_OF_OR_S   = 40,
133         ICE_PROT_IPV6_IL        = 41,
134         ICE_PROT_IPV6_FRAG      = 47,
135         ICE_PROT_TCP_IL         = 49,
136         ICE_PROT_UDP_OF         = 52,
137         ICE_PROT_UDP_IL_OR_S    = 53,
138         ICE_PROT_GRE_OF         = 64,
139         ICE_PROT_NSH_F          = 84,
140         ICE_PROT_ESP_F          = 88,
141         ICE_PROT_ESP_2          = 89,
142         ICE_PROT_SCTP_IL        = 96,
143         ICE_PROT_ICMP_IL        = 98,
144         ICE_PROT_ICMPV6_IL      = 100,
145         ICE_PROT_VRRP_F         = 101,
146         ICE_PROT_OSPF           = 102,
147         ICE_PROT_PPPOE          = 103,
148         ICE_PROT_L2TPV3         = 104,
149         ICE_PROT_ATAOE_OF       = 114,
150         ICE_PROT_CTRL_OF        = 116,
151         ICE_PROT_LLDP_OF        = 117,
152         ICE_PROT_ARP_OF         = 118,
153         ICE_PROT_EAPOL_OF       = 120,
154         ICE_PROT_META_ID        = 255, /* when offset == metaddata */
155         ICE_PROT_INVALID        = 255  /* when offset == ICE_FV_OFFSET_INVAL */
156 };
157
158 #define ICE_VNI_OFFSET          12 /* offset of VNI from ICE_PROT_UDP_OF */
159
160 #define ICE_MAC_OFOS_HW         1
161 #define ICE_MAC_IL_HW           4
162 #define ICE_ETYPE_OL_HW         9
163 #define ICE_VLAN_OL_HW          17
164 #define ICE_IPV4_OFOS_HW        32
165 #define ICE_IPV4_IL_HW          33
166 #define ICE_IPV6_OFOS_HW        40
167 #define ICE_IPV6_IL_HW          41
168 #define ICE_TCP_IL_HW           49
169 #define ICE_UDP_ILOS_HW         53
170 #define ICE_ESP_HW                      88
171 #define ICE_AH_HW                       89
172 #define ICE_SCTP_IL_HW          96
173 #define ICE_PPPOE_HW            103
174 #define ICE_L2TPV3_HW           104
175
176 /* ICE_UDP_OF is used to identify all 3 tunnel types
177  * VXLAN, GENEVE and VXLAN_GPE. To differentiate further
178  * need to use flags from the field vector
179  */
180 #define ICE_UDP_OF_HW   52 /* UDP Tunnels */
181 #define ICE_GRE_OF_HW   64 /* NVGRE */
182 #define ICE_META_DATA_ID_HW 255 /* this is used for tunnel type */
183
184 #define ICE_MDID_SIZE 2
185 #define ICE_TUN_FLAG_MDID 21
186 #define ICE_TUN_FLAG_MDID_OFF (ICE_MDID_SIZE * ICE_TUN_FLAG_MDID)
187 #define ICE_TUN_FLAG_MASK 0xFF
188 #define ICE_TUN_FLAG_VLAN_MASK 0x01
189 #define ICE_TUN_FLAG_FV_IND 2
190
191 #define ICE_PROTOCOL_MAX_ENTRIES 16
192
193 /* Mapping of software defined protocol ID to hardware defined protocol ID */
194 struct ice_protocol_entry {
195         enum ice_protocol_type type;
196         u8 protocol_id;
197 };
198
199 struct ice_ether_hdr {
200         u8 dst_addr[ETH_ALEN];
201         u8 src_addr[ETH_ALEN];
202 };
203
204 struct ice_ethtype_hdr {
205         __be16 ethtype_id;
206 };
207
208 struct ice_ether_vlan_hdr {
209         u8 dst_addr[ETH_ALEN];
210         u8 src_addr[ETH_ALEN];
211         __be32 vlan_id;
212 };
213
214 struct ice_vlan_hdr {
215         __be16 vlan;
216         __be16 type;
217 };
218
219 struct ice_ipv4_hdr {
220         u8 version;
221         u8 tos;
222         __be16 total_length;
223         __be16 id;
224         __be16 frag_off;
225         u8 time_to_live;
226         u8 protocol;
227         __be16 check;
228         __be32 src_addr;
229         __be32 dst_addr;
230 };
231
232 struct ice_le_ver_tc_flow {
233         union {
234                 struct {
235                         u32 flow_label : 20;
236                         u32 tc : 8;
237                         u32 version : 4;
238                 } fld;
239                 u32 val;
240         } u;
241 };
242
243 struct ice_ipv6_hdr {
244         __be32 be_ver_tc_flow;
245         __be16 payload_len;
246         u8 next_hdr;
247         u8 hop_limit;
248         u8 src_addr[ICE_IPV6_ADDR_LENGTH];
249         u8 dst_addr[ICE_IPV6_ADDR_LENGTH];
250 };
251
252 struct ice_sctp_hdr {
253         __be16 src_port;
254         __be16 dst_port;
255         __be32 verification_tag;
256         __be32 check;
257 };
258
259 struct ice_l4_hdr {
260         __be16 src_port;
261         __be16 dst_port;
262         __be16 len;
263         __be16 check;
264 };
265
266 struct ice_udp_tnl_hdr {
267         __be16 field;
268         __be16 proto_type;
269         __be32 vni;     /* only use lower 24-bits */
270 };
271
272 struct ice_udp_gtp_hdr {
273         u8 flags;
274         u8 msg_type;
275         __be16 rsrvd_len;
276         __be32 teid;
277         __be16 rsrvd_seq_nbr;
278         u8 rsrvd_n_pdu_nbr;
279         u8 rsrvd_next_ext;
280         u8 rsvrd_ext_len;
281         u8 pdu_type;
282         u8 qfi;
283         u8 rsvrd;
284 };
285
286 struct ice_pppoe_hdr {
287         u8 rsrvd_ver_type;
288         u8 rsrvd_code;
289         __be16 session_id;
290         __be16 length;
291         __be16 ppp_prot_id; /* control and data only */
292 };
293
294 struct ice_pfcp_hdr {
295         u8 flags;
296         u8 msg_type;
297         __be16 length;
298         __be64 seid;
299         __be32 seq;
300         u8 spare;
301 };
302
303 struct ice_l2tpv3_sess_hdr {
304         __be32 session_id;
305         __be64 cookie;
306 };
307
308 struct ice_esp_hdr {
309         __be32 spi;
310         __be32 seq;
311 };
312
313 struct ice_ah_hdr {
314         u8 next_hdr;
315         u8 paylen;
316         __be16 rsrvd;
317         __be32 spi;
318         __be32 seq;
319 };
320
321 struct ice_nat_t_hdr {
322         struct ice_esp_hdr esp;
323 };
324
325 struct ice_nvgre {
326         __be16 flags;
327         __be16 protocol;
328         __be32 tni_flow;
329 };
330
331 union ice_prot_hdr {
332         struct ice_ether_hdr eth_hdr;
333         struct ice_ethtype_hdr ethertype;
334         struct ice_vlan_hdr vlan_hdr;
335         struct ice_ipv4_hdr ipv4_hdr;
336         struct ice_ipv6_hdr ipv6_hdr;
337         struct ice_l4_hdr l4_hdr;
338         struct ice_sctp_hdr sctp_hdr;
339         struct ice_udp_tnl_hdr tnl_hdr;
340         struct ice_nvgre nvgre_hdr;
341         struct ice_udp_gtp_hdr gtp_hdr;
342         struct ice_pppoe_hdr pppoe_hdr;
343         struct ice_pfcp_hdr pfcp_hdr;
344         struct ice_l2tpv3_sess_hdr l2tpv3_sess_hdr;
345         struct ice_esp_hdr esp_hdr;
346         struct ice_ah_hdr ah_hdr;
347         struct ice_nat_t_hdr nat_t_hdr;
348 };
349
350 /* This is mapping table entry that maps every word within a given protocol
351  * structure to the real byte offset as per the specification of that
352  * protocol header.
353  * for e.g. dst address is 3 words in ethertype header and corresponding bytes
354  * are 0, 2, 3 in the actual packet header and src address is at 4, 6, 8
355  */
356 struct ice_prot_ext_tbl_entry {
357         enum ice_protocol_type prot_type;
358         /* Byte offset into header of given protocol type */
359         u8 offs[sizeof(union ice_prot_hdr)];
360 };
361
362 /* Extractions to be looked up for a given recipe */
363 struct ice_prot_lkup_ext {
364         u16 prot_type;
365         u8 n_val_words;
366         /* create a buffer to hold max words per recipe */
367         u16 field_off[ICE_MAX_CHAIN_WORDS];
368         u16 field_mask[ICE_MAX_CHAIN_WORDS];
369
370         struct ice_fv_word fv_words[ICE_MAX_CHAIN_WORDS];
371
372         /* Indicate field offsets that have field vector indices assigned */
373         ice_declare_bitmap(done, ICE_MAX_CHAIN_WORDS);
374 };
375
376 struct ice_pref_recipe_group {
377         u8 n_val_pairs;         /* Number of valid pairs */
378         struct ice_fv_word pairs[ICE_NUM_WORDS_RECIPE];
379         u16 mask[ICE_NUM_WORDS_RECIPE];
380 };
381
382 struct ice_recp_grp_entry {
383         struct LIST_ENTRY_TYPE l_entry;
384
385 #define ICE_INVAL_CHAIN_IND 0xFF
386         u16 rid;
387         u8 chain_idx;
388         u16 fv_idx[ICE_NUM_WORDS_RECIPE];
389         u16 fv_mask[ICE_NUM_WORDS_RECIPE];
390         struct ice_pref_recipe_group r_group;
391 };
392 #endif /* _ICE_PROTOCOL_TYPE_H_ */