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_VLAN_OFOS,
33 	ICE_IPV4_OFOS,
34 	ICE_IPV4_IL,
35 	ICE_IPV6_OFOS,
36 	ICE_IPV6_IL,
37 	ICE_TCP_IL,
38 	ICE_UDP_OF,
39 	ICE_UDP_ILOS,
40 	ICE_VXLAN,
41 	ICE_GENEVE,
42 	ICE_NVGRE,
43 	ICE_VXLAN_GPE,
44 	ICE_SCTP_IL,
45 	ICE_PROTOCOL_LAST
46 };
47 
48 enum ice_sw_tunnel_type {
49 	ICE_NON_TUN = 0,
50 	ICE_SW_TUN_VXLAN,
51 	ICE_SW_TUN_GENEVE,
52 	ICE_SW_TUN_NVGRE,
53 	ICE_ALL_TUNNELS /* All tunnel types including NVGRE */
54 };
55 
56 /* Decoders for ice_prot_id:
57  * - F: First
58  * - I: Inner
59  * - L: Last
60  * - O: Outer
61  * - S: Single
62  */
63 enum ice_prot_id {
64 	ICE_PROT_ID_INVAL	= 0,
65 	ICE_PROT_MAC_OF_OR_S	= 1,
66 	ICE_PROT_MAC_IL		= 4,
67 	ICE_PROT_ETYPE_OL	= 9,
68 	ICE_PROT_ETYPE_IL	= 10,
69 	ICE_PROT_IPV4_OF_OR_S	= 32,
70 	ICE_PROT_IPV4_IL	= 33,
71 	ICE_PROT_IPV6_OF_OR_S	= 40,
72 	ICE_PROT_IPV6_IL	= 41,
73 	ICE_PROT_TCP_IL		= 49,
74 	ICE_PROT_UDP_OF		= 52,
75 	ICE_PROT_UDP_IL_OR_S	= 53,
76 	ICE_PROT_GRE_OF		= 64,
77 	ICE_PROT_ESP_F		= 88,
78 	ICE_PROT_ESP_2		= 89,
79 	ICE_PROT_SCTP_IL	= 96,
80 	ICE_PROT_ICMP_IL	= 98,
81 	ICE_PROT_ICMPV6_IL	= 100,
82 	ICE_PROT_PPPOE		= 103,
83 	ICE_PROT_L2TPV3		= 104,
84 	ICE_PROT_ARP_OF		= 118,
85 	ICE_PROT_META_ID	= 255, /* when offset == metadata */
86 	ICE_PROT_INVALID	= 255  /* when offset == ICE_FV_OFFSET_INVAL */
87 };
88 
89 #define ICE_VNI_OFFSET		12 /* offset of VNI from ICE_PROT_UDP_OF */
90 
91 #define ICE_MAC_OFOS_HW		1
92 #define ICE_MAC_IL_HW		4
93 #define ICE_ETYPE_OL_HW		9
94 #define ICE_VLAN_OF_HW		16
95 #define ICE_VLAN_OL_HW		17
96 #define ICE_IPV4_OFOS_HW	32
97 #define ICE_IPV4_IL_HW		33
98 #define ICE_IPV6_OFOS_HW	40
99 #define ICE_IPV6_IL_HW		41
100 #define ICE_TCP_IL_HW		49
101 #define ICE_UDP_ILOS_HW		53
102 #define ICE_GRE_OF_HW		64
103 
104 #define ICE_UDP_OF_HW	52 /* UDP Tunnels */
105 #define ICE_META_DATA_ID_HW 255 /* this is used for tunnel type */
106 
107 #define ICE_MDID_SIZE 2
108 #define ICE_TUN_FLAG_MDID 21
109 #define ICE_TUN_FLAG_MDID_OFF (ICE_MDID_SIZE * ICE_TUN_FLAG_MDID)
110 #define ICE_TUN_FLAG_MASK 0xFF
111 
112 #define ICE_TUN_FLAG_FV_IND 2
113 
114 /* Mapping of software defined protocol ID to hardware defined protocol ID */
115 struct ice_protocol_entry {
116 	enum ice_protocol_type type;
117 	u8 protocol_id;
118 };
119 
120 struct ice_ether_hdr {
121 	u8 dst_addr[ETH_ALEN];
122 	u8 src_addr[ETH_ALEN];
123 };
124 
125 struct ice_ethtype_hdr {
126 	__be16 ethtype_id;
127 };
128 
129 struct ice_ether_vlan_hdr {
130 	u8 dst_addr[ETH_ALEN];
131 	u8 src_addr[ETH_ALEN];
132 	__be32 vlan_id;
133 };
134 
135 struct ice_vlan_hdr {
136 	__be16 type;
137 	__be16 vlan;
138 };
139 
140 struct ice_ipv4_hdr {
141 	u8 version;
142 	u8 tos;
143 	__be16 total_length;
144 	__be16 id;
145 	__be16 frag_off;
146 	u8 time_to_live;
147 	u8 protocol;
148 	__be16 check;
149 	__be32 src_addr;
150 	__be32 dst_addr;
151 };
152 
153 struct ice_ipv6_hdr {
154 	__be32 be_ver_tc_flow;
155 	__be16 payload_len;
156 	u8 next_hdr;
157 	u8 hop_limit;
158 	u8 src_addr[ICE_IPV6_ADDR_LENGTH];
159 	u8 dst_addr[ICE_IPV6_ADDR_LENGTH];
160 };
161 
162 struct ice_sctp_hdr {
163 	__be16 src_port;
164 	__be16 dst_port;
165 	__be32 verification_tag;
166 	__be32 check;
167 };
168 
169 struct ice_l4_hdr {
170 	__be16 src_port;
171 	__be16 dst_port;
172 	__be16 len;
173 	__be16 check;
174 };
175 
176 struct ice_udp_tnl_hdr {
177 	__be16 field;
178 	__be16 proto_type;
179 	__be32 vni;     /* only use lower 24-bits */
180 };
181 
182 struct ice_nvgre_hdr {
183 	__be16 flags;
184 	__be16 protocol;
185 	__be32 tni_flow;
186 };
187 
188 union ice_prot_hdr {
189 	struct ice_ether_hdr eth_hdr;
190 	struct ice_ethtype_hdr ethertype;
191 	struct ice_vlan_hdr vlan_hdr;
192 	struct ice_ipv4_hdr ipv4_hdr;
193 	struct ice_ipv6_hdr ipv6_hdr;
194 	struct ice_l4_hdr l4_hdr;
195 	struct ice_sctp_hdr sctp_hdr;
196 	struct ice_udp_tnl_hdr tnl_hdr;
197 	struct ice_nvgre_hdr nvgre_hdr;
198 };
199 
200 /* This is mapping table entry that maps every word within a given protocol
201  * structure to the real byte offset as per the specification of that
202  * protocol header.
203  * for e.g. dst address is 3 words in ethertype header and corresponding bytes
204  * are 0, 2, 3 in the actual packet header and src address is at 4, 6, 8
205  */
206 struct ice_prot_ext_tbl_entry {
207 	enum ice_protocol_type prot_type;
208 	/* Byte offset into header of given protocol type */
209 	u8 offs[sizeof(union ice_prot_hdr)];
210 };
211 
212 /* Extractions to be looked up for a given recipe */
213 struct ice_prot_lkup_ext {
214 	u16 prot_type;
215 	u8 n_val_words;
216 	/* create a buffer to hold max words per recipe */
217 	u16 field_off[ICE_MAX_CHAIN_WORDS];
218 	u16 field_mask[ICE_MAX_CHAIN_WORDS];
219 
220 	struct ice_fv_word fv_words[ICE_MAX_CHAIN_WORDS];
221 
222 	/* Indicate field offsets that have field vector indices assigned */
223 	DECLARE_BITMAP(done, ICE_MAX_CHAIN_WORDS);
224 };
225 
226 struct ice_pref_recipe_group {
227 	u8 n_val_pairs;		/* Number of valid pairs */
228 	struct ice_fv_word pairs[ICE_NUM_WORDS_RECIPE];
229 	u16 mask[ICE_NUM_WORDS_RECIPE];
230 };
231 
232 struct ice_recp_grp_entry {
233 	struct list_head l_entry;
234 
235 #define ICE_INVAL_CHAIN_IND 0xFF
236 	u16 rid;
237 	u8 chain_idx;
238 	u16 fv_idx[ICE_NUM_WORDS_RECIPE];
239 	u16 fv_mask[ICE_NUM_WORDS_RECIPE];
240 	struct ice_pref_recipe_group r_group;
241 };
242 #endif /* _ICE_PROTOCOL_TYPE_H_ */
243