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