• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2019, Intel Corporation. */
3 
4 #ifndef _ICE_PROTOCOL_TYPE_H_
5 #define _ICE_PROTOCOL_TYPE_H_
6 #define ICE_IPV6_ADDR_LENGTH 16
7 
8 /* Each recipe can match up to 5 different fields. Fields to match can be meta-
9  * data, values extracted from packet headers, or results from other recipes.
10  * One of the 5 fields is reserved for matching the switch ID. So, up to 4
11  * recipes can provide intermediate results to another one through chaining,
12  * e.g. recipes 0, 1, 2, and 3 can provide intermediate results to recipe 4.
13  */
14 #define ICE_NUM_WORDS_RECIPE 4
15 
16 /* Max recipes that can be chained */
17 #define ICE_MAX_CHAIN_RECIPE 5
18 
19 /* 1 word reserved for switch ID from allowed 5 words.
20  * So a recipe can have max 4 words. And you can chain 5 such recipes
21  * together. So maximum words that can be programmed for look up is 5 * 4.
22  */
23 #define ICE_MAX_CHAIN_WORDS (ICE_NUM_WORDS_RECIPE * ICE_MAX_CHAIN_RECIPE)
24 
25 /* Field vector index corresponding to chaining */
26 #define ICE_CHAIN_FV_INDEX_START 47
27 
28 enum ice_protocol_type {
29 	ICE_MAC_OFOS = 0,
30 	ICE_MAC_IL,
31 	ICE_ETYPE_OL,
32 	ICE_ETYPE_IL,
33 	ICE_VLAN_OFOS,
34 	ICE_IPV4_OFOS,
35 	ICE_IPV4_IL,
36 	ICE_IPV6_OFOS,
37 	ICE_IPV6_IL,
38 	ICE_TCP_IL,
39 	ICE_UDP_OF,
40 	ICE_UDP_ILOS,
41 	ICE_VXLAN,
42 	ICE_GENEVE,
43 	ICE_NVGRE,
44 	ICE_GTP,
45 	ICE_GTP_NO_PAY,
46 	ICE_PPPOE,
47 	ICE_L2TPV3,
48 	ICE_VLAN_EX,
49 	ICE_VLAN_IN,
50 	ICE_VXLAN_GPE,
51 	ICE_SCTP_IL,
52 	ICE_PROTOCOL_LAST
53 };
54 
55 enum ice_sw_tunnel_type {
56 	ICE_NON_TUN = 0,
57 	ICE_SW_TUN_AND_NON_TUN,
58 	ICE_SW_TUN_VXLAN,
59 	ICE_SW_TUN_GENEVE,
60 	ICE_SW_TUN_NVGRE,
61 	ICE_SW_TUN_GTPU,
62 	ICE_SW_TUN_GTPC,
63 	ICE_ALL_TUNNELS /* All tunnel types including NVGRE */
64 };
65 
66 /* Decoders for ice_prot_id:
67  * - F: First
68  * - I: Inner
69  * - L: Last
70  * - O: Outer
71  * - S: Single
72  */
73 enum ice_prot_id {
74 	ICE_PROT_ID_INVAL	= 0,
75 	ICE_PROT_MAC_OF_OR_S	= 1,
76 	ICE_PROT_MAC_IL		= 4,
77 	ICE_PROT_ETYPE_OL	= 9,
78 	ICE_PROT_ETYPE_IL	= 10,
79 	ICE_PROT_IPV4_OF_OR_S	= 32,
80 	ICE_PROT_IPV4_IL	= 33,
81 	ICE_PROT_IPV6_OF_OR_S	= 40,
82 	ICE_PROT_IPV6_IL	= 41,
83 	ICE_PROT_TCP_IL		= 49,
84 	ICE_PROT_UDP_OF		= 52,
85 	ICE_PROT_UDP_IL_OR_S	= 53,
86 	ICE_PROT_GRE_OF		= 64,
87 	ICE_PROT_ESP_F		= 88,
88 	ICE_PROT_ESP_2		= 89,
89 	ICE_PROT_SCTP_IL	= 96,
90 	ICE_PROT_ICMP_IL	= 98,
91 	ICE_PROT_ICMPV6_IL	= 100,
92 	ICE_PROT_PPPOE		= 103,
93 	ICE_PROT_L2TPV3		= 104,
94 	ICE_PROT_ARP_OF		= 118,
95 	ICE_PROT_META_ID	= 255, /* when offset == metadata */
96 	ICE_PROT_INVALID	= 255  /* when offset == ICE_FV_OFFSET_INVAL */
97 };
98 
99 #define ICE_VNI_OFFSET		12 /* offset of VNI from ICE_PROT_UDP_OF */
100 
101 #define ICE_MAC_OFOS_HW		1
102 #define ICE_MAC_IL_HW		4
103 #define ICE_ETYPE_OL_HW		9
104 #define ICE_ETYPE_IL_HW		10
105 #define ICE_VLAN_OF_HW		16
106 #define ICE_VLAN_OL_HW		17
107 #define ICE_IPV4_OFOS_HW	32
108 #define ICE_IPV4_IL_HW		33
109 #define ICE_IPV6_OFOS_HW	40
110 #define ICE_IPV6_IL_HW		41
111 #define ICE_TCP_IL_HW		49
112 #define ICE_UDP_ILOS_HW		53
113 #define ICE_GRE_OF_HW		64
114 #define ICE_PPPOE_HW		103
115 #define ICE_L2TPV3_HW		104
116 
117 #define ICE_UDP_OF_HW	52 /* UDP Tunnels */
118 #define ICE_META_DATA_ID_HW 255 /* this is used for tunnel and VLAN type */
119 
120 #define ICE_MDID_SIZE 2
121 
122 #define ICE_TUN_FLAG_MDID 21
123 #define ICE_TUN_FLAG_MDID_OFF (ICE_MDID_SIZE * ICE_TUN_FLAG_MDID)
124 #define ICE_TUN_FLAG_MASK 0xFF
125 
126 #define ICE_VLAN_FLAG_MDID 20
127 #define ICE_VLAN_FLAG_MDID_OFF (ICE_MDID_SIZE * ICE_VLAN_FLAG_MDID)
128 #define ICE_PKT_FLAGS_0_TO_15_VLAN_FLAGS_MASK 0xD000
129 
130 #define ICE_TUN_FLAG_FV_IND 2
131 
132 /* Mapping of software defined protocol ID to hardware defined protocol ID */
133 struct ice_protocol_entry {
134 	enum ice_protocol_type type;
135 	u8 protocol_id;
136 };
137 
138 struct ice_ether_hdr {
139 	u8 dst_addr[ETH_ALEN];
140 	u8 src_addr[ETH_ALEN];
141 };
142 
143 struct ice_ethtype_hdr {
144 	__be16 ethtype_id;
145 };
146 
147 struct ice_ether_vlan_hdr {
148 	u8 dst_addr[ETH_ALEN];
149 	u8 src_addr[ETH_ALEN];
150 	__be32 vlan_id;
151 };
152 
153 struct ice_vlan_hdr {
154 	__be16 type;
155 	__be16 vlan;
156 };
157 
158 struct ice_ipv4_hdr {
159 	u8 version;
160 	u8 tos;
161 	__be16 total_length;
162 	__be16 id;
163 	__be16 frag_off;
164 	u8 time_to_live;
165 	u8 protocol;
166 	__be16 check;
167 	__be32 src_addr;
168 	__be32 dst_addr;
169 };
170 
171 struct ice_ipv6_hdr {
172 	__be32 be_ver_tc_flow;
173 	__be16 payload_len;
174 	u8 next_hdr;
175 	u8 hop_limit;
176 	u8 src_addr[ICE_IPV6_ADDR_LENGTH];
177 	u8 dst_addr[ICE_IPV6_ADDR_LENGTH];
178 };
179 
180 struct ice_sctp_hdr {
181 	__be16 src_port;
182 	__be16 dst_port;
183 	__be32 verification_tag;
184 	__be32 check;
185 };
186 
187 struct ice_l4_hdr {
188 	__be16 src_port;
189 	__be16 dst_port;
190 	__be16 len;
191 	__be16 check;
192 };
193 
194 struct ice_udp_tnl_hdr {
195 	__be16 field;
196 	__be16 proto_type;
197 	__be32 vni;     /* only use lower 24-bits */
198 };
199 
200 struct ice_udp_gtp_hdr {
201 	u8 flags;
202 	u8 msg_type;
203 	__be16 rsrvd_len;
204 	__be32 teid;
205 	__be16 rsrvd_seq_nbr;
206 	u8 rsrvd_n_pdu_nbr;
207 	u8 rsrvd_next_ext;
208 	u8 rsvrd_ext_len;
209 	u8 pdu_type;
210 	u8 qfi;
211 	u8 rsvrd;
212 };
213 
214 struct ice_pppoe_hdr {
215 	u8 rsrvd_ver_type;
216 	u8 rsrvd_code;
217 	__be16 session_id;
218 	__be16 length;
219 	__be16 ppp_prot_id; /* control and data only */
220 };
221 
222 struct ice_l2tpv3_sess_hdr {
223 	__be32 session_id;
224 	__be64 cookie;
225 };
226 
227 struct ice_nvgre_hdr {
228 	__be16 flags;
229 	__be16 protocol;
230 	__be32 tni_flow;
231 };
232 
233 union ice_prot_hdr {
234 	struct ice_ether_hdr eth_hdr;
235 	struct ice_ethtype_hdr ethertype;
236 	struct ice_vlan_hdr vlan_hdr;
237 	struct ice_ipv4_hdr ipv4_hdr;
238 	struct ice_ipv6_hdr ipv6_hdr;
239 	struct ice_l4_hdr l4_hdr;
240 	struct ice_sctp_hdr sctp_hdr;
241 	struct ice_udp_tnl_hdr tnl_hdr;
242 	struct ice_nvgre_hdr nvgre_hdr;
243 	struct ice_udp_gtp_hdr gtp_hdr;
244 	struct ice_pppoe_hdr pppoe_hdr;
245 	struct ice_l2tpv3_sess_hdr l2tpv3_sess_hdr;
246 };
247 
248 /* This is mapping table entry that maps every word within a given protocol
249  * structure to the real byte offset as per the specification of that
250  * protocol header.
251  * for e.g. dst address is 3 words in ethertype header and corresponding bytes
252  * are 0, 2, 3 in the actual packet header and src address is at 4, 6, 8
253  */
254 struct ice_prot_ext_tbl_entry {
255 	enum ice_protocol_type prot_type;
256 	/* Byte offset into header of given protocol type */
257 	u8 offs[sizeof(union ice_prot_hdr)];
258 };
259 
260 /* Extractions to be looked up for a given recipe */
261 struct ice_prot_lkup_ext {
262 	u16 prot_type;
263 	u8 n_val_words;
264 	/* create a buffer to hold max words per recipe */
265 	u16 field_off[ICE_MAX_CHAIN_WORDS];
266 	u16 field_mask[ICE_MAX_CHAIN_WORDS];
267 
268 	struct ice_fv_word fv_words[ICE_MAX_CHAIN_WORDS];
269 
270 	/* Indicate field offsets that have field vector indices assigned */
271 	DECLARE_BITMAP(done, ICE_MAX_CHAIN_WORDS);
272 };
273 
274 struct ice_pref_recipe_group {
275 	u8 n_val_pairs;		/* Number of valid pairs */
276 	struct ice_fv_word pairs[ICE_NUM_WORDS_RECIPE];
277 	u16 mask[ICE_NUM_WORDS_RECIPE];
278 };
279 
280 struct ice_recp_grp_entry {
281 	struct list_head l_entry;
282 
283 #define ICE_INVAL_CHAIN_IND 0xFF
284 	u16 rid;
285 	u8 chain_idx;
286 	u16 fv_idx[ICE_NUM_WORDS_RECIPE];
287 	u16 fv_mask[ICE_NUM_WORDS_RECIPE];
288 	struct ice_pref_recipe_group r_group;
289 };
290 #endif /* _ICE_PROTOCOL_TYPE_H_ */
291