xref: /freebsd/sys/dev/ice/ice_protocol_type.h (revision 2b833162)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*  Copyright (c) 2022, Intel Corporation
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *
8  *   1. Redistributions of source code must retain the above copyright notice,
9  *      this list of conditions and the following disclaimer.
10  *
11  *   2. Redistributions in binary form must reproduce the above copyright
12  *      notice, this list of conditions and the following disclaimer in the
13  *      documentation and/or other materials provided with the distribution.
14  *
15  *   3. Neither the name of the Intel Corporation nor the names of its
16  *      contributors may be used to endorse or promote products derived from
17  *      this software without specific prior written permission.
18  *
19  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *  POSSIBILITY OF SUCH DAMAGE.
30  */
31 /*$FreeBSD$*/
32 
33 #ifndef _ICE_PROTOCOL_TYPE_H_
34 #define _ICE_PROTOCOL_TYPE_H_
35 #include "ice_flex_type.h"
36 #define ICE_IPV6_ADDR_LENGTH 16
37 
38 /* Each recipe can match up to 5 different fields. Fields to match can be meta-
39  * data, values extracted from packet headers, or results from other recipes.
40  * One of the 5 fields is reserved for matching the switch ID. So, up to 4
41  * recipes can provide intermediate results to another one through chaining,
42  * e.g. recipes 0, 1, 2, and 3 can provide intermediate results to recipe 4.
43  */
44 #define ICE_NUM_WORDS_RECIPE 4
45 
46 /* Max recipes that can be chained */
47 #define ICE_MAX_CHAIN_RECIPE 5
48 
49 /* 1 word reserved for switch ID from allowed 5 words.
50  * So a recipe can have max 4 words. And you can chain 5 such recipes
51  * together. So maximum words that can be programmed for look up is 5 * 4.
52  */
53 #define ICE_MAX_CHAIN_WORDS (ICE_NUM_WORDS_RECIPE * ICE_MAX_CHAIN_RECIPE)
54 
55 /* Field vector index corresponding to chaining */
56 #define ICE_CHAIN_FV_INDEX_START 47
57 
58 enum ice_protocol_type {
59 	ICE_MAC_OFOS = 0,
60 	ICE_MAC_IL,
61 	ICE_ETYPE_OL,
62 	ICE_ETYPE_IL,
63 	ICE_VLAN_OFOS,
64 	ICE_IPV4_OFOS,
65 	ICE_IPV4_IL,
66 	ICE_IPV6_OFOS,
67 	ICE_IPV6_IL,
68 	ICE_TCP_IL,
69 	ICE_UDP_OF,
70 	ICE_UDP_ILOS,
71 	ICE_SCTP_IL,
72 	ICE_VXLAN,
73 	ICE_GENEVE,
74 	ICE_VXLAN_GPE,
75 	ICE_NVGRE,
76 	ICE_GTP,
77 	ICE_GTP_NO_PAY,
78 	ICE_PPPOE,
79 	ICE_PROTOCOL_LAST
80 };
81 
82 enum ice_sw_tunnel_type {
83 	ICE_NON_TUN = 0,
84 	ICE_SW_TUN_AND_NON_TUN,
85 	ICE_SW_TUN_VXLAN_GPE,
86 	ICE_SW_TUN_GENEVE,      /* GENEVE matches only non-VLAN pkts */
87 	ICE_SW_TUN_GENEVE_VLAN, /* GENEVE matches both VLAN and non-VLAN pkts */
88 	ICE_SW_TUN_VXLAN,	/* VXLAN matches only non-VLAN pkts */
89 	ICE_SW_TUN_VXLAN_VLAN,  /* VXLAN matches both VLAN and non-VLAN pkts */
90 	ICE_SW_TUN_NVGRE,
91 	ICE_SW_TUN_UDP, /* This means all "UDP" tunnel types: VXLAN-GPE, VXLAN
92 			 * and GENEVE
93 			 */
94 	ICE_SW_TUN_IPV4_GTP_IPV4_TCP,
95 	ICE_SW_TUN_IPV4_GTP_IPV4_UDP,
96 	ICE_SW_TUN_IPV4_GTP_IPV6_TCP,
97 	ICE_SW_TUN_IPV4_GTP_IPV6_UDP,
98 	ICE_SW_TUN_IPV6_GTP_IPV4_TCP,
99 	ICE_SW_TUN_IPV6_GTP_IPV4_UDP,
100 	ICE_SW_TUN_IPV6_GTP_IPV6_TCP,
101 	ICE_SW_TUN_IPV6_GTP_IPV6_UDP,
102 
103 	/* following adds support for GTP, just using inner protocols,
104 	 * outer L3 and L4 protocols can be anything
105 	 */
106 	ICE_SW_TUN_GTP_IPV4_TCP,
107 	ICE_SW_TUN_GTP_IPV4_UDP,
108 	ICE_SW_TUN_GTP_IPV6_TCP,
109 	ICE_SW_TUN_GTP_IPV6_UDP,
110 	ICE_SW_TUN_GTPU,
111 	ICE_SW_TUN_GTPC,
112 	ICE_SW_TUN_IPV4_GTPU_IPV4,
113 	ICE_SW_TUN_IPV4_GTPU_IPV6,
114 	ICE_SW_TUN_IPV6_GTPU_IPV4,
115 	ICE_SW_TUN_IPV6_GTPU_IPV6,
116 	ICE_SW_TUN_GTP_IPV4,
117 	ICE_SW_TUN_GTP_IPV6,
118 	ICE_ALL_TUNNELS /* All tunnel types including NVGRE */
119 };
120 
121 /* Decoders for ice_prot_id:
122  * - F: First
123  * - I: Inner
124  * - L: Last
125  * - O: Outer
126  * - S: Single
127  */
128 enum ice_prot_id {
129 	ICE_PROT_ID_INVAL	= 0,
130 	ICE_PROT_MAC_OF_OR_S	= 1,
131 	ICE_PROT_MAC_O2		= 2,
132 	ICE_PROT_MAC_IL		= 4,
133 	ICE_PROT_MAC_IN_MAC	= 7,
134 	ICE_PROT_ETYPE_OL	= 9,
135 	ICE_PROT_ETYPE_IL	= 10,
136 	ICE_PROT_PAY		= 15,
137 	ICE_PROT_EVLAN_O	= 16,
138 	ICE_PROT_VLAN_O		= 17,
139 	ICE_PROT_VLAN_IF	= 18,
140 	ICE_PROT_MPLS_OL_MINUS_1 = 27,
141 	ICE_PROT_MPLS_OL_OR_OS	= 28,
142 	ICE_PROT_MPLS_IL	= 29,
143 	ICE_PROT_IPV4_OF_OR_S	= 32,
144 	ICE_PROT_IPV4_IL	= 33,
145 	ICE_PROT_IPV4_IL_IL	= 34,
146 	ICE_PROT_IPV6_OF_OR_S	= 40,
147 	ICE_PROT_IPV6_IL	= 41,
148 	ICE_PROT_IPV6_IL_IL	= 42,
149 	ICE_PROT_IPV6_NEXT_PROTO = 43,
150 	ICE_PROT_IPV6_FRAG	= 47,
151 	ICE_PROT_TCP_IL		= 49,
152 	ICE_PROT_UDP_OF		= 52,
153 	ICE_PROT_UDP_IL_OR_S	= 53,
154 	ICE_PROT_GRE_OF		= 64,
155 	ICE_PROT_NSH_F		= 84,
156 	ICE_PROT_ESP_F		= 88,
157 	ICE_PROT_ESP_2		= 89,
158 	ICE_PROT_SCTP_IL	= 96,
159 	ICE_PROT_ICMP_IL	= 98,
160 	ICE_PROT_ICMPV6_IL	= 100,
161 	ICE_PROT_VRRP_F		= 101,
162 	ICE_PROT_OSPF		= 102,
163 	ICE_PROT_ATAOE_OF	= 114,
164 	ICE_PROT_CTRL_OF	= 116,
165 	ICE_PROT_LLDP_OF	= 117,
166 	ICE_PROT_ARP_OF		= 118,
167 	ICE_PROT_EAPOL_OF	= 120,
168 	ICE_PROT_META_ID	= 255, /* when offset == metaddata */
169 	ICE_PROT_INVALID	= 255  /* when offset == ICE_FV_OFFSET_INVAL */
170 };
171 
172 #define ICE_VNI_OFFSET		12 /* offset of VNI from ICE_PROT_UDP_OF */
173 
174 #define ICE_NAN_OFFSET		511
175 #define ICE_MAC_OFOS_HW		1
176 #define ICE_MAC_IL_HW		4
177 #define ICE_ETYPE_OL_HW		9
178 #define ICE_ETYPE_IL_HW		10
179 #define ICE_VLAN_OF_HW		16
180 #define ICE_VLAN_OL_HW		17
181 #define ICE_IPV4_OFOS_HW	32
182 #define ICE_IPV4_IL_HW		33
183 #define ICE_IPV6_OFOS_HW	40
184 #define ICE_IPV6_IL_HW		41
185 #define ICE_TCP_IL_HW		49
186 #define ICE_UDP_ILOS_HW		53
187 #define ICE_SCTP_IL_HW		96
188 
189 /* ICE_UDP_OF is used to identify all 3 tunnel types
190  * VXLAN, GENEVE and VXLAN_GPE. To differentiate further
191  * need to use flags from the field vector
192  */
193 #define ICE_UDP_OF_HW	52 /* UDP Tunnels */
194 #define ICE_GRE_OF_HW	64 /* NVGRE */
195 #define ICE_PPPOE_HW	103
196 #define ICE_META_DATA_ID_HW 255 /* this is used for tunnel type */
197 
198 #define ICE_MDID_SIZE 2
199 #define ICE_TUN_FLAG_MDID 20
200 #define ICE_TUN_FLAG_MDID_OFF(word) \
201 	(ICE_MDID_SIZE * (ICE_TUN_FLAG_MDID + (word)))
202 #define ICE_TUN_FLAG_MASK 0xFF
203 #define ICE_DIR_FLAG_MASK 0x10
204 #define ICE_TUN_FLAG_VLAN_MASK 0x01
205 #define ICE_TUN_FLAG_FV_IND 2
206 
207 #define ICE_PROTOCOL_MAX_ENTRIES 16
208 
209 /* Mapping of software defined protocol ID to hardware defined protocol ID */
210 struct ice_protocol_entry {
211 	enum ice_protocol_type type;
212 	u8 protocol_id;
213 };
214 
215 struct ice_ether_hdr {
216 	u8 dst_addr[ETH_ALEN];
217 	u8 src_addr[ETH_ALEN];
218 };
219 
220 struct ice_ethtype_hdr {
221 	__be16 ethtype_id;
222 };
223 
224 struct ice_ether_vlan_hdr {
225 	u8 dst_addr[ETH_ALEN];
226 	u8 src_addr[ETH_ALEN];
227 	__be32 vlan_id;
228 };
229 
230 struct ice_vlan_hdr {
231 	__be16 type;
232 	__be16 vlan;
233 };
234 
235 struct ice_ipv4_hdr {
236 	u8 version;
237 	u8 tos;
238 	__be16 total_length;
239 	__be16 id;
240 	__be16 frag_off;
241 	u8 time_to_live;
242 	u8 protocol;
243 	__be16 check;
244 	__be32 src_addr;
245 	__be32 dst_addr;
246 };
247 
248 struct ice_le_ver_tc_flow {
249 	union {
250 		struct {
251 			u32 flow_label : 20;
252 			u32 tc : 8;
253 			u32 version : 4;
254 		} fld;
255 		u32 val;
256 	} u;
257 };
258 
259 struct ice_ipv6_hdr {
260 	__be32 be_ver_tc_flow;
261 	__be16 payload_len;
262 	u8 next_hdr;
263 	u8 hop_limit;
264 	u8 src_addr[ICE_IPV6_ADDR_LENGTH];
265 	u8 dst_addr[ICE_IPV6_ADDR_LENGTH];
266 };
267 
268 struct ice_sctp_hdr {
269 	__be16 src_port;
270 	__be16 dst_port;
271 	__be32 verification_tag;
272 	__be32 check;
273 };
274 
275 struct ice_l4_hdr {
276 	__be16 src_port;
277 	__be16 dst_port;
278 	__be16 len;
279 	__be16 check;
280 };
281 
282 struct ice_udp_tnl_hdr {
283 	__be16 field;
284 	__be16 proto_type;
285 	__be32 vni;	/* only use lower 24-bits */
286 };
287 
288 struct ice_udp_gtp_hdr {
289 	u8 flags;
290 	u8 msg_type;
291 	__be16 rsrvd_len;
292 	__be32 teid;
293 	__be16 rsrvd_seq_nbr;
294 	u8 rsrvd_n_pdu_nbr;
295 	u8 rsrvd_next_ext;
296 	u8 rsvrd_ext_len;
297 	u8 pdu_type;
298 	u8 qfi;
299 	u8 rsvrd;
300 };
301 struct ice_pppoe_hdr {
302 	u8 rsrvd_ver_type;
303 	u8 rsrvd_code;
304 	__be16 session_id;
305 	__be16 length;
306 	__be16 ppp_prot_id; /* control and data only */
307 };
308 
309 struct ice_nvgre {
310 	__be16 flags;
311 	__be16 protocol;
312 	__be32 tni_flow;
313 };
314 
315 union ice_prot_hdr {
316 	struct ice_ether_hdr eth_hdr;
317 	struct ice_ethtype_hdr ethertype;
318 	struct ice_vlan_hdr vlan_hdr;
319 	struct ice_ipv4_hdr ipv4_hdr;
320 	struct ice_ipv6_hdr ipv6_hdr;
321 	struct ice_l4_hdr l4_hdr;
322 	struct ice_sctp_hdr sctp_hdr;
323 	struct ice_udp_tnl_hdr tnl_hdr;
324 	struct ice_nvgre nvgre_hdr;
325 	struct ice_udp_gtp_hdr gtp_hdr;
326 	struct ice_pppoe_hdr pppoe_hdr;
327 };
328 
329 /* This is mapping table entry that maps every word within a given protocol
330  * structure to the real byte offset as per the specification of that
331  * protocol header.
332  * for e.g. dst address is 3 words in ethertype header and corresponding bytes
333  * are 0, 2, 3 in the actual packet header and src address is at 4, 6, 8
334  */
335 struct ice_prot_ext_tbl_entry {
336 	enum ice_protocol_type prot_type;
337 	/* Byte offset into header of given protocol type */
338 	u8 offs[sizeof(union ice_prot_hdr)];
339 };
340 
341 /* Extractions to be looked up for a given recipe */
342 struct ice_prot_lkup_ext {
343 	u16 prot_type;
344 	u8 n_val_words;
345 	/* create a buffer to hold max words per recipe */
346 	u16 field_off[ICE_MAX_CHAIN_WORDS];
347 	u16 field_mask[ICE_MAX_CHAIN_WORDS];
348 
349 	struct ice_fv_word fv_words[ICE_MAX_CHAIN_WORDS];
350 
351 	/* Indicate field offsets that have field vector indices assigned */
352 	ice_declare_bitmap(done, ICE_MAX_CHAIN_WORDS);
353 };
354 
355 struct ice_pref_recipe_group {
356 	u8 n_val_pairs;		/* Number of valid pairs */
357 	struct ice_fv_word pairs[ICE_NUM_WORDS_RECIPE];
358 	u16 mask[ICE_NUM_WORDS_RECIPE];
359 };
360 
361 struct ice_recp_grp_entry {
362 	struct LIST_ENTRY_TYPE l_entry;
363 
364 #define ICE_INVAL_CHAIN_IND 0xFF
365 	u16 rid;
366 	u8 chain_idx;
367 	u16 fv_idx[ICE_NUM_WORDS_RECIPE];
368 	u16 fv_mask[ICE_NUM_WORDS_RECIPE];
369 	struct ice_pref_recipe_group r_group;
370 };
371 #endif /* _ICE_PROTOCOL_TYPE_H_ */
372