net/ice/base: fix switch programming for IPv6
[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_VLAN_OFOS,
35         ICE_IPV4_OFOS,
36         ICE_IPV4_IL,
37         ICE_IPV6_OFOS,
38         ICE_IPV6_IL,
39         ICE_TCP_IL,
40         ICE_UDP_OF,
41         ICE_UDP_ILOS,
42         ICE_SCTP_IL,
43         ICE_VXLAN,
44         ICE_GENEVE,
45         ICE_VXLAN_GPE,
46         ICE_NVGRE,
47         ICE_GTP,
48         ICE_PPPOE,
49         ICE_PROTOCOL_LAST
50 };
51
52 enum ice_sw_tunnel_type {
53         ICE_NON_TUN = 0,
54         ICE_SW_TUN_AND_NON_TUN,
55         ICE_SW_TUN_VXLAN_GPE,
56         ICE_SW_TUN_GENEVE,
57         ICE_SW_TUN_VXLAN,
58         ICE_SW_TUN_NVGRE,
59         ICE_SW_TUN_UDP, /* This means all "UDP" tunnel types: VXLAN-GPE, VXLAN
60                          * and GENEVE
61                          */
62         ICE_SW_TUN_GTP,
63         ICE_SW_TUN_PPPOE,
64         ICE_ALL_TUNNELS /* All tunnel types including NVGRE */
65 };
66
67 /* Decoders for ice_prot_id:
68  * - F: First
69  * - I: Inner
70  * - L: Last
71  * - O: Outer
72  * - S: Single
73  */
74 enum ice_prot_id {
75         ICE_PROT_ID_INVAL       = 0,
76         ICE_PROT_MAC_OF_OR_S    = 1,
77         ICE_PROT_MAC_O2         = 2,
78         ICE_PROT_MAC_IL         = 4,
79         ICE_PROT_MAC_IN_MAC     = 7,
80         ICE_PROT_ETYPE_OL       = 9,
81         ICE_PROT_ETYPE_IL       = 10,
82         ICE_PROT_PAY            = 15,
83         ICE_PROT_EVLAN_O        = 16,
84         ICE_PROT_VLAN_O         = 17,
85         ICE_PROT_VLAN_IF        = 18,
86         ICE_PROT_MPLS_OL_MINUS_1 = 27,
87         ICE_PROT_MPLS_OL_OR_OS  = 28,
88         ICE_PROT_MPLS_IL        = 29,
89         ICE_PROT_IPV4_OF_OR_S   = 32,
90         ICE_PROT_IPV4_IL        = 33,
91         ICE_PROT_IPV6_OF_OR_S   = 40,
92         ICE_PROT_IPV6_IL        = 41,
93         ICE_PROT_IPV6_FRAG      = 47,
94         ICE_PROT_TCP_IL         = 49,
95         ICE_PROT_UDP_OF         = 52,
96         ICE_PROT_UDP_IL_OR_S    = 53,
97         ICE_PROT_GRE_OF         = 64,
98         ICE_PROT_NSH_F          = 84,
99         ICE_PROT_ESP_F          = 88,
100         ICE_PROT_ESP_2          = 89,
101         ICE_PROT_SCTP_IL        = 96,
102         ICE_PROT_ICMP_IL        = 98,
103         ICE_PROT_ICMPV6_IL      = 100,
104         ICE_PROT_VRRP_F         = 101,
105         ICE_PROT_OSPF           = 102,
106         ICE_PROT_PPPOE          = 103,
107         ICE_PROT_ATAOE_OF       = 114,
108         ICE_PROT_CTRL_OF        = 116,
109         ICE_PROT_LLDP_OF        = 117,
110         ICE_PROT_ARP_OF         = 118,
111         ICE_PROT_EAPOL_OF       = 120,
112         ICE_PROT_META_ID        = 255, /* when offset == metaddata */
113         ICE_PROT_INVALID        = 255  /* when offset == ICE_FV_OFFSET_INVAL */
114 };
115
116 #define ICE_VNI_OFFSET          12 /* offset of VNI from ICE_PROT_UDP_OF */
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_VLAN_OL_HW          17
122 #define ICE_IPV4_OFOS_HW        32
123 #define ICE_IPV4_IL_HW          33
124 #define ICE_IPV6_OFOS_HW        40
125 #define ICE_IPV6_IL_HW          41
126 #define ICE_TCP_IL_HW           49
127 #define ICE_UDP_ILOS_HW         53
128 #define ICE_SCTP_IL_HW          96
129 #define ICE_PPPOE_HW            103
130
131 /* ICE_UDP_OF is used to identify all 3 tunnel types
132  * VXLAN, GENEVE and VXLAN_GPE. To differentiate further
133  * need to use flags from the field vector
134  */
135 #define ICE_UDP_OF_HW   52 /* UDP Tunnels */
136 #define ICE_GRE_OF_HW   64 /* NVGRE */
137 #define ICE_META_DATA_ID_HW 255 /* this is used for tunnel type */
138
139 #define ICE_MDID_SIZE 2
140 #define ICE_TUN_FLAG_MDID 21
141 #define ICE_TUN_FLAG_MASK 0xFF
142 #define ICE_TUN_FLAG_FV_IND 2
143
144 #define ICE_PROTOCOL_MAX_ENTRIES 16
145
146 /* Mapping of software defined protocol ID to hardware defined protocol ID */
147 struct ice_protocol_entry {
148         enum ice_protocol_type type;
149         u8 protocol_id;
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         __be16 ethtype_id;
159 };
160
161 struct ice_ether_vlan_hdr {
162         u8 dst_addr[ETH_ALEN];
163         u8 src_addr[ETH_ALEN];
164         __be32 vlan_id;
165 };
166
167 struct ice_vlan_hdr {
168         __be16 vlan;
169         __be16 type;
170 };
171
172 struct ice_ipv4_hdr {
173         u8 version;
174         u8 tos;
175         __be16 total_length;
176         __be16 id;
177         __be16 frag_off;
178         u8 time_to_live;
179         u8 protocol;
180         __be16 check;
181         __be32 src_addr;
182         __be32 dst_addr;
183 };
184
185 struct ice_le_ver_tc_flow {
186         union {
187                 struct {
188                         u32 flow_label : 20;
189                         u32 tc : 8;
190                         u32 version : 4;
191                 } fld;
192                 u32 val;
193         } u;
194 };
195
196 struct ice_ipv6_hdr {
197         __be32 be_ver_tc_flow;
198         __be16 payload_len;
199         u8 next_hdr;
200         u8 hop_limit;
201         u8 src_addr[ICE_IPV6_ADDR_LENGTH];
202         u8 dst_addr[ICE_IPV6_ADDR_LENGTH];
203 };
204
205 struct ice_sctp_hdr {
206         __be16 src_port;
207         __be16 dst_port;
208         __be32 verification_tag;
209         __be32 check;
210 };
211
212 struct ice_l4_hdr {
213         __be16 src_port;
214         __be16 dst_port;
215         __be16 len;
216         __be16 check;
217 };
218
219 struct ice_udp_tnl_hdr {
220         __be16 field;
221         __be16 proto_type;
222         __be32 vni;     /* only use lower 24-bits */
223 };
224
225 #pragma pack(1)
226 struct ice_udp_gtp_hdr {
227         u8 flags;
228         u8 msg_type;
229         __be16 rsrvd_len;
230         __be32 teid;
231         __be16 rsrvd_seq_nbr;
232         u8 rsrvd_n_pdu_nbr;
233         u8 rsrvd_next_ext;
234         u8 rsvrd_ext_len;
235         u8 pdu_type;
236         u8 qfi;
237         u8 rsvrd;
238 };
239
240 struct ice_pppoe_hdr {
241         u8 rsrvd_ver_type;
242         u8 rsrvd_code;
243         __be16 session_id;
244         __be16 length;
245         __be16 ppp_prot_id; /* control and data only */
246 };
247 #pragma pack()
248
249 struct ice_nvgre {
250         __be16 flags;
251         __be16 protocol;
252         __be32 tni_flow;
253 };
254
255 union ice_prot_hdr {
256         struct ice_ether_hdr eth_hdr;
257         struct ice_ethtype_hdr ethertype;
258         struct ice_vlan_hdr vlan_hdr;
259         struct ice_ipv4_hdr ipv4_hdr;
260         struct ice_ipv6_hdr ipv6_hdr;
261         struct ice_l4_hdr l4_hdr;
262         struct ice_sctp_hdr sctp_hdr;
263         struct ice_udp_tnl_hdr tnl_hdr;
264         struct ice_nvgre nvgre_hdr;
265         struct ice_udp_gtp_hdr gtp_hdr;
266         struct ice_pppoe_hdr pppoe_hdr;
267 };
268
269 /* This is mapping table entry that maps every word within a given protocol
270  * structure to the real byte offset as per the specification of that
271  * protocol header.
272  * for e.g. dst address is 3 words in ethertype header and corresponding bytes
273  * are 0, 2, 3 in the actual packet header and src address is at 4, 6, 8
274  */
275 struct ice_prot_ext_tbl_entry {
276         enum ice_protocol_type prot_type;
277         /* Byte offset into header of given protocol type */
278         u8 offs[sizeof(union ice_prot_hdr)];
279 };
280
281 /* Extractions to be looked up for a given recipe */
282 struct ice_prot_lkup_ext {
283         u16 prot_type;
284         u8 n_val_words;
285         /* create a buffer to hold max words per recipe */
286         u16 field_off[ICE_MAX_CHAIN_WORDS];
287         u16 field_mask[ICE_MAX_CHAIN_WORDS];
288
289         struct ice_fv_word fv_words[ICE_MAX_CHAIN_WORDS];
290
291         /* Indicate field offsets that have field vector indices assigned */
292         ice_declare_bitmap(done, ICE_MAX_CHAIN_WORDS);
293 };
294
295 struct ice_pref_recipe_group {
296         u8 n_val_pairs;         /* Number of valid pairs */
297         struct ice_fv_word pairs[ICE_NUM_WORDS_RECIPE];
298         u16 mask[ICE_NUM_WORDS_RECIPE];
299 };
300
301 struct ice_recp_grp_entry {
302         struct LIST_ENTRY_TYPE l_entry;
303
304 #define ICE_INVAL_CHAIN_IND 0xFF
305         u16 rid;
306         u8 chain_idx;
307         u16 fv_idx[ICE_NUM_WORDS_RECIPE];
308         u16 fv_mask[ICE_NUM_WORDS_RECIPE];
309         struct ice_pref_recipe_group r_group;
310 };
311 #endif /* _ICE_PROTOCOL_TYPE_H_ */