xref: /freebsd/sys/dev/ice/ice_protocol_type.h (revision 681ce946)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*  Copyright (c) 2021, 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_VLAN_OFOS,
63 	ICE_IPV4_OFOS,
64 	ICE_IPV4_IL,
65 	ICE_IPV6_OFOS,
66 	ICE_IPV6_IL,
67 	ICE_TCP_IL,
68 	ICE_UDP_OF,
69 	ICE_UDP_ILOS,
70 	ICE_SCTP_IL,
71 	ICE_VXLAN,
72 	ICE_GENEVE,
73 	ICE_VXLAN_GPE,
74 	ICE_NVGRE,
75 	ICE_GTP,
76 	ICE_PROTOCOL_LAST
77 };
78 
79 enum ice_sw_tunnel_type {
80 	ICE_NON_TUN = 0,
81 	ICE_SW_TUN_AND_NON_TUN,
82 	ICE_SW_TUN_VXLAN_GPE,
83 	ICE_SW_TUN_GENEVE,      /* GENEVE matches only non-VLAN pkts */
84 	ICE_SW_TUN_GENEVE_VLAN, /* GENEVE matches both VLAN and non-VLAN pkts */
85 	ICE_SW_TUN_VXLAN,	/* VXLAN matches only non-VLAN pkts */
86 	ICE_SW_TUN_VXLAN_VLAN,  /* VXLAN matches both VLAN and non-VLAN pkts */
87 	ICE_SW_TUN_NVGRE,
88 	ICE_SW_TUN_UDP, /* This means all "UDP" tunnel types: VXLAN-GPE, VXLAN
89 			 * and GENEVE
90 			 */
91 	ICE_SW_TUN_IPV4_GTP_IPV4_TCP,
92 	ICE_SW_TUN_IPV4_GTP_IPV4_UDP,
93 	ICE_SW_TUN_IPV4_GTP_IPV6_TCP,
94 	ICE_SW_TUN_IPV4_GTP_IPV6_UDP,
95 	ICE_SW_TUN_IPV6_GTP_IPV4_TCP,
96 	ICE_SW_TUN_IPV6_GTP_IPV4_UDP,
97 	ICE_SW_TUN_IPV6_GTP_IPV6_TCP,
98 	ICE_SW_TUN_IPV6_GTP_IPV6_UDP,
99 	ICE_SW_TUN_IPV4_GTPU_IPV4,
100 	ICE_SW_TUN_IPV4_GTPU_IPV6,
101 	ICE_SW_TUN_IPV6_GTPU_IPV4,
102 	ICE_SW_TUN_IPV6_GTPU_IPV6,
103 	ICE_ALL_TUNNELS /* All tunnel types including NVGRE */
104 };
105 
106 /* Decoders for ice_prot_id:
107  * - F: First
108  * - I: Inner
109  * - L: Last
110  * - O: Outer
111  * - S: Single
112  */
113 enum ice_prot_id {
114 	ICE_PROT_ID_INVAL	= 0,
115 	ICE_PROT_MAC_OF_OR_S	= 1,
116 	ICE_PROT_MAC_O2		= 2,
117 	ICE_PROT_MAC_IL		= 4,
118 	ICE_PROT_MAC_IN_MAC	= 7,
119 	ICE_PROT_ETYPE_OL	= 9,
120 	ICE_PROT_ETYPE_IL	= 10,
121 	ICE_PROT_PAY		= 15,
122 	ICE_PROT_EVLAN_O	= 16,
123 	ICE_PROT_VLAN_O		= 17,
124 	ICE_PROT_VLAN_IF	= 18,
125 	ICE_PROT_MPLS_OL_MINUS_1 = 27,
126 	ICE_PROT_MPLS_OL_OR_OS	= 28,
127 	ICE_PROT_MPLS_IL	= 29,
128 	ICE_PROT_IPV4_OF_OR_S	= 32,
129 	ICE_PROT_IPV4_IL	= 33,
130 	ICE_PROT_IPV6_OF_OR_S	= 40,
131 	ICE_PROT_IPV6_IL	= 41,
132 	ICE_PROT_IPV6_FRAG	= 47,
133 	ICE_PROT_TCP_IL		= 49,
134 	ICE_PROT_UDP_OF		= 52,
135 	ICE_PROT_UDP_IL_OR_S	= 53,
136 	ICE_PROT_GRE_OF		= 64,
137 	ICE_PROT_NSH_F		= 84,
138 	ICE_PROT_ESP_F		= 88,
139 	ICE_PROT_ESP_2		= 89,
140 	ICE_PROT_SCTP_IL	= 96,
141 	ICE_PROT_ICMP_IL	= 98,
142 	ICE_PROT_ICMPV6_IL	= 100,
143 	ICE_PROT_VRRP_F		= 101,
144 	ICE_PROT_OSPF		= 102,
145 	ICE_PROT_ATAOE_OF	= 114,
146 	ICE_PROT_CTRL_OF	= 116,
147 	ICE_PROT_LLDP_OF	= 117,
148 	ICE_PROT_ARP_OF		= 118,
149 	ICE_PROT_EAPOL_OF	= 120,
150 	ICE_PROT_META_ID	= 255, /* when offset == metaddata */
151 	ICE_PROT_INVALID	= 255  /* when offset == ICE_FV_OFFSET_INVAL */
152 };
153 
154 #define ICE_VNI_OFFSET		12 /* offset of VNI from ICE_PROT_UDP_OF */
155 
156 #define ICE_MAC_OFOS_HW		1
157 #define ICE_MAC_IL_HW		4
158 #define ICE_ETYPE_OL_HW		9
159 #define ICE_VLAN_OF_HW		16
160 #define ICE_VLAN_OL_HW		17
161 #define ICE_IPV4_OFOS_HW	32
162 #define ICE_IPV4_IL_HW		33
163 #define ICE_IPV6_OFOS_HW	40
164 #define ICE_IPV6_IL_HW		41
165 #define ICE_TCP_IL_HW		49
166 #define ICE_UDP_ILOS_HW		53
167 #define ICE_SCTP_IL_HW		96
168 
169 /* ICE_UDP_OF is used to identify all 3 tunnel types
170  * VXLAN, GENEVE and VXLAN_GPE. To differentiate further
171  * need to use flags from the field vector
172  */
173 #define ICE_UDP_OF_HW	52 /* UDP Tunnels */
174 #define ICE_GRE_OF_HW	64 /* NVGRE */
175 #define ICE_META_DATA_ID_HW 255 /* this is used for tunnel type */
176 
177 #define ICE_MDID_SIZE 2
178 #define ICE_TUN_FLAG_MDID 21
179 #define ICE_TUN_FLAG_MDID_OFF (ICE_MDID_SIZE * ICE_TUN_FLAG_MDID)
180 #define ICE_TUN_FLAG_MASK 0xFF
181 #define ICE_TUN_FLAG_VLAN_MASK 0x01
182 #define ICE_TUN_FLAG_FV_IND 2
183 
184 #define ICE_PROTOCOL_MAX_ENTRIES 16
185 
186 /* Mapping of software defined protocol ID to hardware defined protocol ID */
187 struct ice_protocol_entry {
188 	enum ice_protocol_type type;
189 	u8 protocol_id;
190 };
191 
192 struct ice_ether_hdr {
193 	u8 dst_addr[ETH_ALEN];
194 	u8 src_addr[ETH_ALEN];
195 };
196 
197 struct ice_ethtype_hdr {
198 	__be16 ethtype_id;
199 };
200 
201 struct ice_ether_vlan_hdr {
202 	u8 dst_addr[ETH_ALEN];
203 	u8 src_addr[ETH_ALEN];
204 	__be32 vlan_id;
205 };
206 
207 struct ice_vlan_hdr {
208 	__be16 vlan;
209 	__be16 type;
210 };
211 
212 struct ice_ipv4_hdr {
213 	u8 version;
214 	u8 tos;
215 	__be16 total_length;
216 	__be16 id;
217 	__be16 frag_off;
218 	u8 time_to_live;
219 	u8 protocol;
220 	__be16 check;
221 	__be32 src_addr;
222 	__be32 dst_addr;
223 };
224 
225 struct ice_le_ver_tc_flow {
226 	union {
227 		struct {
228 			u32 flow_label : 20;
229 			u32 tc : 8;
230 			u32 version : 4;
231 		} fld;
232 		u32 val;
233 	} u;
234 };
235 
236 struct ice_ipv6_hdr {
237 	__be32 be_ver_tc_flow;
238 	__be16 payload_len;
239 	u8 next_hdr;
240 	u8 hop_limit;
241 	u8 src_addr[ICE_IPV6_ADDR_LENGTH];
242 	u8 dst_addr[ICE_IPV6_ADDR_LENGTH];
243 };
244 
245 struct ice_sctp_hdr {
246 	__be16 src_port;
247 	__be16 dst_port;
248 	__be32 verification_tag;
249 	__be32 check;
250 };
251 
252 struct ice_l4_hdr {
253 	__be16 src_port;
254 	__be16 dst_port;
255 	__be16 len;
256 	__be16 check;
257 };
258 
259 struct ice_udp_tnl_hdr {
260 	__be16 field;
261 	__be16 proto_type;
262 	__be32 vni;	/* only use lower 24-bits */
263 };
264 
265 struct ice_udp_gtp_hdr {
266 	u8 flags;
267 	u8 msg_type;
268 	__be16 rsrvd_len;
269 	__be32 teid;
270 	__be16 rsrvd_seq_nbr;
271 	u8 rsrvd_n_pdu_nbr;
272 	u8 rsrvd_next_ext;
273 	u8 rsvrd_ext_len;
274 	u8 pdu_type;
275 	u8 qfi;
276 	u8 rsvrd;
277 };
278 
279 struct ice_nvgre {
280 	__be16 flags;
281 	__be16 protocol;
282 	__be32 tni_flow;
283 };
284 
285 union ice_prot_hdr {
286 	struct ice_ether_hdr eth_hdr;
287 	struct ice_ethtype_hdr ethertype;
288 	struct ice_vlan_hdr vlan_hdr;
289 	struct ice_ipv4_hdr ipv4_hdr;
290 	struct ice_ipv6_hdr ipv6_hdr;
291 	struct ice_l4_hdr l4_hdr;
292 	struct ice_sctp_hdr sctp_hdr;
293 	struct ice_udp_tnl_hdr tnl_hdr;
294 	struct ice_nvgre nvgre_hdr;
295 	struct ice_udp_gtp_hdr gtp_hdr;
296 };
297 
298 /* This is mapping table entry that maps every word within a given protocol
299  * structure to the real byte offset as per the specification of that
300  * protocol header.
301  * for e.g. dst address is 3 words in ethertype header and corresponding bytes
302  * are 0, 2, 3 in the actual packet header and src address is at 4, 6, 8
303  */
304 struct ice_prot_ext_tbl_entry {
305 	enum ice_protocol_type prot_type;
306 	/* Byte offset into header of given protocol type */
307 	u8 offs[sizeof(union ice_prot_hdr)];
308 };
309 
310 /* Extractions to be looked up for a given recipe */
311 struct ice_prot_lkup_ext {
312 	u16 prot_type;
313 	u8 n_val_words;
314 	/* create a buffer to hold max words per recipe */
315 	u16 field_off[ICE_MAX_CHAIN_WORDS];
316 	u16 field_mask[ICE_MAX_CHAIN_WORDS];
317 
318 	struct ice_fv_word fv_words[ICE_MAX_CHAIN_WORDS];
319 
320 	/* Indicate field offsets that have field vector indices assigned */
321 	ice_declare_bitmap(done, ICE_MAX_CHAIN_WORDS);
322 };
323 
324 struct ice_pref_recipe_group {
325 	u8 n_val_pairs;		/* Number of valid pairs */
326 	struct ice_fv_word pairs[ICE_NUM_WORDS_RECIPE];
327 	u16 mask[ICE_NUM_WORDS_RECIPE];
328 };
329 
330 struct ice_recp_grp_entry {
331 	struct LIST_ENTRY_TYPE l_entry;
332 
333 #define ICE_INVAL_CHAIN_IND 0xFF
334 	u16 rid;
335 	u8 chain_idx;
336 	u16 fv_idx[ICE_NUM_WORDS_RECIPE];
337 	u16 fv_mask[ICE_NUM_WORDS_RECIPE];
338 	struct ice_pref_recipe_group r_group;
339 };
340 #endif /* _ICE_PROTOCOL_TYPE_H_ */
341