net/ice/base: improve switch chained recipe
[dpdk.git] / drivers / net / ice / base / ice_protocol_type.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2019
3  */
4
5 #ifndef _ICE_PROTOCOL_TYPE_H_
6 #define _ICE_PROTOCOL_TYPE_H_
7 #include "ice_flex_type.h"
8 #define ICE_IPV6_ADDR_LENGTH 16
9
10 /* Each recipe can match up to 5 different fields. Fields to match can be meta-
11  * data, values extracted from packet headers, or results from other recipes.
12  * One of the 5 fields is reserved for matching the switch ID. So, up to 4
13  * recipes can provide intermediate results to another one through chaining,
14  * e.g. recipes 0, 1, 2, and 3 can provide intermediate results to recipe 4.
15  */
16 #define ICE_NUM_WORDS_RECIPE 4
17
18 /* Max recipes that can be chained */
19 #define ICE_MAX_CHAIN_RECIPE 5
20
21 /* 1 word reserved for switch ID from allowed 5 words.
22  * So a recipe can have max 4 words. And you can chain 5 such recipes
23  * together. So maximum words that can be programmed for look up is 5 * 4.
24  */
25 #define ICE_MAX_CHAIN_WORDS (ICE_NUM_WORDS_RECIPE * ICE_MAX_CHAIN_RECIPE)
26
27 /* Field vector index corresponding to chaining */
28 #define ICE_CHAIN_FV_INDEX_START 47
29
30 enum ice_protocol_type {
31         ICE_MAC_OFOS = 0,
32         ICE_MAC_IL,
33         ICE_ETYPE_OL,
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_SCTP_IL,
42         ICE_VXLAN,
43         ICE_GENEVE,
44         ICE_VXLAN_GPE,
45         ICE_NVGRE,
46         ICE_GTP,
47         ICE_PPPOE,
48         ICE_PROTOCOL_LAST
49 };
50
51 enum ice_sw_tunnel_type {
52         ICE_NON_TUN = 0,
53         ICE_SW_TUN_AND_NON_TUN,
54         ICE_SW_TUN_VXLAN_GPE,
55         ICE_SW_TUN_GENEVE,
56         ICE_SW_TUN_VXLAN,
57         ICE_SW_TUN_NVGRE,
58         ICE_SW_TUN_UDP, /* This means all "UDP" tunnel types: VXLAN-GPE, VXLAN
59                          * and GENEVE
60                          */
61         ICE_SW_TUN_GTP,
62         ICE_SW_TUN_PPPOE,
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_O2         = 2,
77         ICE_PROT_MAC_IL         = 4,
78         ICE_PROT_MAC_IN_MAC     = 7,
79         ICE_PROT_ETYPE_OL       = 9,
80         ICE_PROT_ETYPE_IL       = 10,
81         ICE_PROT_PAY            = 15,
82         ICE_PROT_EVLAN_O        = 16,
83         ICE_PROT_VLAN_O         = 17,
84         ICE_PROT_VLAN_IF        = 18,
85         ICE_PROT_MPLS_OL_MINUS_1 = 27,
86         ICE_PROT_MPLS_OL_OR_OS  = 28,
87         ICE_PROT_MPLS_IL        = 29,
88         ICE_PROT_IPV4_OF_OR_S   = 32,
89         ICE_PROT_IPV4_IL        = 33,
90         ICE_PROT_IPV6_OF_OR_S   = 40,
91         ICE_PROT_IPV6_IL        = 41,
92         ICE_PROT_IPV6_FRAG      = 47,
93         ICE_PROT_TCP_IL         = 49,
94         ICE_PROT_UDP_OF         = 52,
95         ICE_PROT_UDP_IL_OR_S    = 53,
96         ICE_PROT_GRE_OF         = 64,
97         ICE_PROT_NSH_F          = 84,
98         ICE_PROT_ESP_F          = 88,
99         ICE_PROT_ESP_2          = 89,
100         ICE_PROT_SCTP_IL        = 96,
101         ICE_PROT_ICMP_IL        = 98,
102         ICE_PROT_ICMPV6_IL      = 100,
103         ICE_PROT_VRRP_F         = 101,
104         ICE_PROT_OSPF           = 102,
105         ICE_PROT_PPPOE          = 103,
106         ICE_PROT_ATAOE_OF       = 114,
107         ICE_PROT_CTRL_OF        = 116,
108         ICE_PROT_LLDP_OF        = 117,
109         ICE_PROT_ARP_OF         = 118,
110         ICE_PROT_EAPOL_OF       = 120,
111         ICE_PROT_META_ID        = 255, /* when offset == metaddata */
112         ICE_PROT_INVALID        = 255  /* when offset == 0xFF */
113 };
114
115 #define ICE_VNI_OFFSET          12 /* offset of VNI from ICE_PROT_UDP_OF */
116
117
118 #define ICE_MAC_OFOS_HW         1
119 #define ICE_MAC_IL_HW           4
120 #define ICE_ETYPE_OL_HW         9
121 #define ICE_IPV4_OFOS_HW        32
122 #define ICE_IPV4_IL_HW          33
123 #define ICE_IPV6_OFOS_HW        40
124 #define ICE_IPV6_IL_HW          41
125 #define ICE_TCP_IL_HW           49
126 #define ICE_UDP_ILOS_HW         53
127 #define ICE_SCTP_IL_HW          96
128 #define ICE_PPPOE_HW            103
129
130 /* ICE_UDP_OF is used to identify all 3 tunnel types
131  * VXLAN, GENEVE and VXLAN_GPE. To differentiate further
132  * need to use flags from the field vector
133  */
134 #define ICE_UDP_OF_HW   52 /* UDP Tunnels */
135 #define ICE_GRE_OF_HW   64 /* NVGRE */
136 #define ICE_META_DATA_ID_HW 255 /* this is used for tunnel type */
137
138 #define ICE_MDID_SIZE 2
139 #define ICE_TUN_FLAG_MDID 21
140 #define ICE_TUN_FLAG_MASK 0xFF
141 #define ICE_TUN_FLAG_FV_IND 2
142
143 #define ICE_PROTOCOL_MAX_ENTRIES 16
144
145 /* Mapping of software defined protocol ID to hardware defined protocol ID */
146 struct ice_protocol_entry {
147         enum ice_protocol_type type;
148         u8 protocol_id;
149 };
150
151
152 struct ice_ether_hdr {
153         u8 dst_addr[ETH_ALEN];
154         u8 src_addr[ETH_ALEN];
155 };
156
157 struct ice_ethtype_hdr {
158         u16 ethtype_id;
159 };
160
161 struct ice_ether_vlan_hdr {
162         u8 dst_addr[ETH_ALEN];
163         u8 src_addr[ETH_ALEN];
164         u32 vlan_id;
165 };
166
167 struct ice_ipv4_hdr {
168         u8 version;
169         u8 tos;
170         u16 total_length;
171         u16 id;
172         u16 frag_off;
173         u8 time_to_live;
174         u8 protocol;
175         u16 check;
176         u32 src_addr;
177         u32 dst_addr;
178 };
179
180 struct ice_ipv6_hdr {
181         u8 version;
182         u8 tc;
183         u16 flow_label;
184         u16 payload_len;
185         u8 next_hdr;
186         u8 hop_limit;
187         u8 src_addr[ICE_IPV6_ADDR_LENGTH];
188         u8 dst_addr[ICE_IPV6_ADDR_LENGTH];
189 };
190
191 struct ice_sctp_hdr {
192         u16 src_port;
193         u16 dst_port;
194         u32 verification_tag;
195         u32 check;
196 };
197
198 struct ice_l4_hdr {
199         u16 src_port;
200         u16 dst_port;
201         u16 len;
202         u16 check;
203 };
204
205 struct ice_udp_tnl_hdr {
206         u16 field;
207         u16 proto_type;
208         u32 vni;        /* only use lower 24-bits */
209 };
210
211 #pragma pack(1)
212 struct ice_udp_gtp_hdr {
213         u8 flags;
214         u8 msg_type;
215         u16 rsrvd_len;
216         u32 teid;
217         u16 rsrvd_seq_nbr;
218         u8 rsrvd_n_pdu_nbr;
219         u8 rsrvd_next_ext;
220         u8 rsvrd_ext_len;
221         u8 pdu_type;
222         u8 qfi;
223         u8 rsvrd;
224 };
225
226 struct ice_pppoe_hdr {
227         u8 rsrvd_ver_type;
228         u8 rsrved_code;
229         u16 session_id;
230         u16 length;
231         u16 ppp_prot_id; /* control and data only */
232 };
233 #pragma pack()
234
235 struct ice_nvgre {
236         u16 flags;
237         u16 protocol;
238         u32 tni_flow;
239 };
240
241 union ice_prot_hdr {
242         struct ice_ether_hdr eth_hdr;
243         struct ice_ethtype_hdr ethertype;
244         struct ice_ipv4_hdr ipv4_hdr;
245         struct ice_ipv6_hdr ipv6_hdr;
246         struct ice_l4_hdr l4_hdr;
247         struct ice_sctp_hdr sctp_hdr;
248         struct ice_udp_tnl_hdr tnl_hdr;
249         struct ice_nvgre nvgre_hdr;
250         struct ice_udp_gtp_hdr gtp_hdr;
251         struct ice_pppoe_hdr pppoe_hdr;
252 };
253
254 /* This is mapping table entry that maps every word within a given protocol
255  * structure to the real byte offset as per the specification of that
256  * protocol header.
257  * for e.g. dst address is 3 words in ethertype header and corresponding bytes
258  * are 0, 2, 3 in the actual packet header and src address is at 4, 6, 8
259  */
260 struct ice_prot_ext_tbl_entry {
261         enum ice_protocol_type prot_type;
262         /* Byte offset into header of given protocol type */
263         u8 offs[sizeof(union ice_prot_hdr)];
264 };
265
266 /* Extractions to be looked up for a given recipe */
267 struct ice_prot_lkup_ext {
268         u16 prot_type;
269         u8 n_val_words;
270         /* create a buffer to hold max words per recipe */
271         u16 field_off[ICE_MAX_CHAIN_WORDS];
272         u16 field_mask[ICE_MAX_CHAIN_WORDS];
273
274         struct ice_fv_word fv_words[ICE_MAX_CHAIN_WORDS];
275
276         /* Indicate field offsets that have field vector indices assigned */
277         ice_declare_bitmap(done, ICE_MAX_CHAIN_WORDS);
278 };
279
280 struct ice_pref_recipe_group {
281         u8 n_val_pairs;         /* Number of valid pairs */
282         struct ice_fv_word pairs[ICE_NUM_WORDS_RECIPE];
283         u16 mask[ICE_NUM_WORDS_RECIPE];
284 };
285
286 struct ice_recp_grp_entry {
287         struct LIST_ENTRY_TYPE l_entry;
288
289 #define ICE_INVAL_CHAIN_IND 0xFF
290         u16 rid;
291         u8 chain_idx;
292         u16 fv_idx[ICE_NUM_WORDS_RECIPE];
293         u16 fv_mask[ICE_NUM_WORDS_RECIPE];
294         struct ice_pref_recipe_group r_group;
295 };
296 #endif /* _ICE_PROTOCOL_TYPE_H_ */