131ad4e4eSTony Nguyen /* SPDX-License-Identifier: GPL-2.0 */
231ad4e4eSTony Nguyen /* Copyright (c) 2019, Intel Corporation. */
331ad4e4eSTony Nguyen 
431ad4e4eSTony Nguyen #ifndef _ICE_PROTOCOL_TYPE_H_
531ad4e4eSTony Nguyen #define _ICE_PROTOCOL_TYPE_H_
6*fd2a6b71SDan Nowlin #define ICE_IPV6_ADDR_LENGTH 16
7*fd2a6b71SDan Nowlin 
8*fd2a6b71SDan Nowlin /* Each recipe can match up to 5 different fields. Fields to match can be meta-
9*fd2a6b71SDan Nowlin  * data, values extracted from packet headers, or results from other recipes.
10*fd2a6b71SDan Nowlin  * One of the 5 fields is reserved for matching the switch ID. So, up to 4
11*fd2a6b71SDan Nowlin  * recipes can provide intermediate results to another one through chaining,
12*fd2a6b71SDan Nowlin  * e.g. recipes 0, 1, 2, and 3 can provide intermediate results to recipe 4.
13*fd2a6b71SDan Nowlin  */
14*fd2a6b71SDan Nowlin #define ICE_NUM_WORDS_RECIPE 4
15*fd2a6b71SDan Nowlin 
16*fd2a6b71SDan Nowlin /* Max recipes that can be chained */
17*fd2a6b71SDan Nowlin #define ICE_MAX_CHAIN_RECIPE 5
18*fd2a6b71SDan Nowlin 
19*fd2a6b71SDan Nowlin /* 1 word reserved for switch ID from allowed 5 words.
20*fd2a6b71SDan Nowlin  * So a recipe can have max 4 words. And you can chain 5 such recipes
21*fd2a6b71SDan Nowlin  * together. So maximum words that can be programmed for look up is 5 * 4.
22*fd2a6b71SDan Nowlin  */
23*fd2a6b71SDan Nowlin #define ICE_MAX_CHAIN_WORDS (ICE_NUM_WORDS_RECIPE * ICE_MAX_CHAIN_RECIPE)
24*fd2a6b71SDan Nowlin 
25*fd2a6b71SDan Nowlin /* Field vector index corresponding to chaining */
26*fd2a6b71SDan Nowlin #define ICE_CHAIN_FV_INDEX_START 47
27*fd2a6b71SDan Nowlin 
28*fd2a6b71SDan Nowlin enum ice_protocol_type {
29*fd2a6b71SDan Nowlin 	ICE_MAC_OFOS = 0,
30*fd2a6b71SDan Nowlin 	ICE_MAC_IL,
31*fd2a6b71SDan Nowlin 	ICE_ETYPE_OL,
32*fd2a6b71SDan Nowlin 	ICE_VLAN_OFOS,
33*fd2a6b71SDan Nowlin 	ICE_IPV4_OFOS,
34*fd2a6b71SDan Nowlin 	ICE_IPV4_IL,
35*fd2a6b71SDan Nowlin 	ICE_IPV6_OFOS,
36*fd2a6b71SDan Nowlin 	ICE_IPV6_IL,
37*fd2a6b71SDan Nowlin 	ICE_TCP_IL,
38*fd2a6b71SDan Nowlin 	ICE_UDP_OF,
39*fd2a6b71SDan Nowlin 	ICE_UDP_ILOS,
40*fd2a6b71SDan Nowlin 	ICE_SCTP_IL,
41*fd2a6b71SDan Nowlin 	ICE_PROTOCOL_LAST
42*fd2a6b71SDan Nowlin };
43*fd2a6b71SDan Nowlin 
4431ad4e4eSTony Nguyen /* Decoders for ice_prot_id:
4531ad4e4eSTony Nguyen  * - F: First
4631ad4e4eSTony Nguyen  * - I: Inner
4731ad4e4eSTony Nguyen  * - L: Last
4831ad4e4eSTony Nguyen  * - O: Outer
4931ad4e4eSTony Nguyen  * - S: Single
5031ad4e4eSTony Nguyen  */
5131ad4e4eSTony Nguyen enum ice_prot_id {
5231ad4e4eSTony Nguyen 	ICE_PROT_ID_INVAL	= 0,
532c57ffcbSHenry Tieman 	ICE_PROT_MAC_OF_OR_S	= 1,
54390bd141SQi Zhang 	ICE_PROT_MAC_IL		= 4,
55390bd141SQi Zhang 	ICE_PROT_ETYPE_OL	= 9,
56390bd141SQi Zhang 	ICE_PROT_ETYPE_IL	= 10,
5731ad4e4eSTony Nguyen 	ICE_PROT_IPV4_OF_OR_S	= 32,
5831ad4e4eSTony Nguyen 	ICE_PROT_IPV4_IL	= 33,
5931ad4e4eSTony Nguyen 	ICE_PROT_IPV6_OF_OR_S	= 40,
6031ad4e4eSTony Nguyen 	ICE_PROT_IPV6_IL	= 41,
6131ad4e4eSTony Nguyen 	ICE_PROT_TCP_IL		= 49,
62148beb61SHenry Tieman 	ICE_PROT_UDP_OF		= 52,
6331ad4e4eSTony Nguyen 	ICE_PROT_UDP_IL_OR_S	= 53,
64a4e82a81STony Nguyen 	ICE_PROT_GRE_OF		= 64,
650577313eSQi Zhang 	ICE_PROT_ESP_F		= 88,
660577313eSQi Zhang 	ICE_PROT_ESP_2		= 89,
671c01c8c6SMd Fahad Iqbal Polash 	ICE_PROT_SCTP_IL	= 96,
68390bd141SQi Zhang 	ICE_PROT_ICMP_IL	= 98,
69390bd141SQi Zhang 	ICE_PROT_ICMPV6_IL	= 100,
700577313eSQi Zhang 	ICE_PROT_PPPOE		= 103,
710577313eSQi Zhang 	ICE_PROT_L2TPV3		= 104,
72390bd141SQi Zhang 	ICE_PROT_ARP_OF		= 118,
7331ad4e4eSTony Nguyen 	ICE_PROT_META_ID	= 255, /* when offset == metadata */
7431ad4e4eSTony Nguyen 	ICE_PROT_INVALID	= 255  /* when offset == ICE_FV_OFFSET_INVAL */
7531ad4e4eSTony Nguyen };
76*fd2a6b71SDan Nowlin 
77*fd2a6b71SDan Nowlin #define ICE_MAC_OFOS_HW		1
78*fd2a6b71SDan Nowlin #define ICE_MAC_IL_HW		4
79*fd2a6b71SDan Nowlin #define ICE_ETYPE_OL_HW		9
80*fd2a6b71SDan Nowlin #define ICE_VLAN_OF_HW		16
81*fd2a6b71SDan Nowlin #define ICE_VLAN_OL_HW		17
82*fd2a6b71SDan Nowlin #define ICE_IPV4_OFOS_HW	32
83*fd2a6b71SDan Nowlin #define ICE_IPV4_IL_HW		33
84*fd2a6b71SDan Nowlin #define ICE_IPV6_OFOS_HW	40
85*fd2a6b71SDan Nowlin #define ICE_IPV6_IL_HW		41
86*fd2a6b71SDan Nowlin #define ICE_TCP_IL_HW		49
87*fd2a6b71SDan Nowlin #define ICE_UDP_ILOS_HW		53
88*fd2a6b71SDan Nowlin 
89*fd2a6b71SDan Nowlin #define ICE_UDP_OF_HW	52 /* UDP Tunnels */
90*fd2a6b71SDan Nowlin 
91*fd2a6b71SDan Nowlin #define ICE_TUN_FLAG_FV_IND 2
92*fd2a6b71SDan Nowlin 
93*fd2a6b71SDan Nowlin /* Mapping of software defined protocol ID to hardware defined protocol ID */
94*fd2a6b71SDan Nowlin struct ice_protocol_entry {
95*fd2a6b71SDan Nowlin 	enum ice_protocol_type type;
96*fd2a6b71SDan Nowlin 	u8 protocol_id;
97*fd2a6b71SDan Nowlin };
98*fd2a6b71SDan Nowlin 
99*fd2a6b71SDan Nowlin struct ice_ether_hdr {
100*fd2a6b71SDan Nowlin 	u8 dst_addr[ETH_ALEN];
101*fd2a6b71SDan Nowlin 	u8 src_addr[ETH_ALEN];
102*fd2a6b71SDan Nowlin };
103*fd2a6b71SDan Nowlin 
104*fd2a6b71SDan Nowlin struct ice_ethtype_hdr {
105*fd2a6b71SDan Nowlin 	__be16 ethtype_id;
106*fd2a6b71SDan Nowlin };
107*fd2a6b71SDan Nowlin 
108*fd2a6b71SDan Nowlin struct ice_ether_vlan_hdr {
109*fd2a6b71SDan Nowlin 	u8 dst_addr[ETH_ALEN];
110*fd2a6b71SDan Nowlin 	u8 src_addr[ETH_ALEN];
111*fd2a6b71SDan Nowlin 	__be32 vlan_id;
112*fd2a6b71SDan Nowlin };
113*fd2a6b71SDan Nowlin 
114*fd2a6b71SDan Nowlin struct ice_vlan_hdr {
115*fd2a6b71SDan Nowlin 	__be16 type;
116*fd2a6b71SDan Nowlin 	__be16 vlan;
117*fd2a6b71SDan Nowlin };
118*fd2a6b71SDan Nowlin 
119*fd2a6b71SDan Nowlin struct ice_ipv4_hdr {
120*fd2a6b71SDan Nowlin 	u8 version;
121*fd2a6b71SDan Nowlin 	u8 tos;
122*fd2a6b71SDan Nowlin 	__be16 total_length;
123*fd2a6b71SDan Nowlin 	__be16 id;
124*fd2a6b71SDan Nowlin 	__be16 frag_off;
125*fd2a6b71SDan Nowlin 	u8 time_to_live;
126*fd2a6b71SDan Nowlin 	u8 protocol;
127*fd2a6b71SDan Nowlin 	__be16 check;
128*fd2a6b71SDan Nowlin 	__be32 src_addr;
129*fd2a6b71SDan Nowlin 	__be32 dst_addr;
130*fd2a6b71SDan Nowlin };
131*fd2a6b71SDan Nowlin 
132*fd2a6b71SDan Nowlin struct ice_ipv6_hdr {
133*fd2a6b71SDan Nowlin 	__be32 be_ver_tc_flow;
134*fd2a6b71SDan Nowlin 	__be16 payload_len;
135*fd2a6b71SDan Nowlin 	u8 next_hdr;
136*fd2a6b71SDan Nowlin 	u8 hop_limit;
137*fd2a6b71SDan Nowlin 	u8 src_addr[ICE_IPV6_ADDR_LENGTH];
138*fd2a6b71SDan Nowlin 	u8 dst_addr[ICE_IPV6_ADDR_LENGTH];
139*fd2a6b71SDan Nowlin };
140*fd2a6b71SDan Nowlin 
141*fd2a6b71SDan Nowlin struct ice_sctp_hdr {
142*fd2a6b71SDan Nowlin 	__be16 src_port;
143*fd2a6b71SDan Nowlin 	__be16 dst_port;
144*fd2a6b71SDan Nowlin 	__be32 verification_tag;
145*fd2a6b71SDan Nowlin 	__be32 check;
146*fd2a6b71SDan Nowlin };
147*fd2a6b71SDan Nowlin 
148*fd2a6b71SDan Nowlin struct ice_l4_hdr {
149*fd2a6b71SDan Nowlin 	__be16 src_port;
150*fd2a6b71SDan Nowlin 	__be16 dst_port;
151*fd2a6b71SDan Nowlin 	__be16 len;
152*fd2a6b71SDan Nowlin 	__be16 check;
153*fd2a6b71SDan Nowlin };
154*fd2a6b71SDan Nowlin 
155*fd2a6b71SDan Nowlin union ice_prot_hdr {
156*fd2a6b71SDan Nowlin 	struct ice_ether_hdr eth_hdr;
157*fd2a6b71SDan Nowlin 	struct ice_ethtype_hdr ethertype;
158*fd2a6b71SDan Nowlin 	struct ice_vlan_hdr vlan_hdr;
159*fd2a6b71SDan Nowlin 	struct ice_ipv4_hdr ipv4_hdr;
160*fd2a6b71SDan Nowlin 	struct ice_ipv6_hdr ipv6_hdr;
161*fd2a6b71SDan Nowlin 	struct ice_l4_hdr l4_hdr;
162*fd2a6b71SDan Nowlin 	struct ice_sctp_hdr sctp_hdr;
163*fd2a6b71SDan Nowlin };
164*fd2a6b71SDan Nowlin 
165*fd2a6b71SDan Nowlin /* This is mapping table entry that maps every word within a given protocol
166*fd2a6b71SDan Nowlin  * structure to the real byte offset as per the specification of that
167*fd2a6b71SDan Nowlin  * protocol header.
168*fd2a6b71SDan Nowlin  * for e.g. dst address is 3 words in ethertype header and corresponding bytes
169*fd2a6b71SDan Nowlin  * are 0, 2, 3 in the actual packet header and src address is at 4, 6, 8
170*fd2a6b71SDan Nowlin  */
171*fd2a6b71SDan Nowlin struct ice_prot_ext_tbl_entry {
172*fd2a6b71SDan Nowlin 	enum ice_protocol_type prot_type;
173*fd2a6b71SDan Nowlin 	/* Byte offset into header of given protocol type */
174*fd2a6b71SDan Nowlin 	u8 offs[sizeof(union ice_prot_hdr)];
175*fd2a6b71SDan Nowlin };
176*fd2a6b71SDan Nowlin 
177*fd2a6b71SDan Nowlin /* Extractions to be looked up for a given recipe */
178*fd2a6b71SDan Nowlin struct ice_prot_lkup_ext {
179*fd2a6b71SDan Nowlin 	u16 prot_type;
180*fd2a6b71SDan Nowlin 	u8 n_val_words;
181*fd2a6b71SDan Nowlin 	/* create a buffer to hold max words per recipe */
182*fd2a6b71SDan Nowlin 	u16 field_off[ICE_MAX_CHAIN_WORDS];
183*fd2a6b71SDan Nowlin 	u16 field_mask[ICE_MAX_CHAIN_WORDS];
184*fd2a6b71SDan Nowlin 
185*fd2a6b71SDan Nowlin 	struct ice_fv_word fv_words[ICE_MAX_CHAIN_WORDS];
186*fd2a6b71SDan Nowlin 
187*fd2a6b71SDan Nowlin 	/* Indicate field offsets that have field vector indices assigned */
188*fd2a6b71SDan Nowlin 	DECLARE_BITMAP(done, ICE_MAX_CHAIN_WORDS);
189*fd2a6b71SDan Nowlin };
190*fd2a6b71SDan Nowlin 
191*fd2a6b71SDan Nowlin struct ice_pref_recipe_group {
192*fd2a6b71SDan Nowlin 	u8 n_val_pairs;		/* Number of valid pairs */
193*fd2a6b71SDan Nowlin 	struct ice_fv_word pairs[ICE_NUM_WORDS_RECIPE];
194*fd2a6b71SDan Nowlin 	u16 mask[ICE_NUM_WORDS_RECIPE];
195*fd2a6b71SDan Nowlin };
196*fd2a6b71SDan Nowlin 
197*fd2a6b71SDan Nowlin struct ice_recp_grp_entry {
198*fd2a6b71SDan Nowlin 	struct list_head l_entry;
199*fd2a6b71SDan Nowlin 
200*fd2a6b71SDan Nowlin #define ICE_INVAL_CHAIN_IND 0xFF
201*fd2a6b71SDan Nowlin 	u16 rid;
202*fd2a6b71SDan Nowlin 	u8 chain_idx;
203*fd2a6b71SDan Nowlin 	u16 fv_idx[ICE_NUM_WORDS_RECIPE];
204*fd2a6b71SDan Nowlin 	u16 fv_mask[ICE_NUM_WORDS_RECIPE];
205*fd2a6b71SDan Nowlin 	struct ice_pref_recipe_group r_group;
206*fd2a6b71SDan Nowlin };
20731ad4e4eSTony Nguyen #endif /* _ICE_PROTOCOL_TYPE_H_ */
208