xref: /linux/drivers/net/ethernet/intel/ice/ice_protocol_type.h (revision 8f7aa3d3c7323f4ca2768a9e74ebbe359c4f8f88)
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  * Therefore, up to 5 recipes can provide intermediate results to another one
11  * through chaining, e.g. recipes 0, 1, 2, 3 and 4 can provide intermediate
12  * results to recipe 5. Note that one of the fields in one of the recipes must
13  * always be reserved for matching the switch ID.
14  */
15 #define ICE_NUM_WORDS_RECIPE 5
16 
17 /* Max recipes that can be chained, not including the last one, which combines
18  * intermediate results.
19  */
20 #define ICE_MAX_CHAIN_RECIPE 5
21 
22 /* Total max recipes in chain recipe (including intermediate results) */
23 #define ICE_MAX_CHAIN_RECIPE_RES (ICE_MAX_CHAIN_RECIPE + 1)
24 
25 /* A recipe can have max 5 words, and 5 recipes can be chained together (using
26  * the 6th one, which would contain only result indexes). So maximum words that
27  * can be programmed for lookup is 5 * 5 (not including intermediate results).
28  */
29 #define ICE_MAX_CHAIN_WORDS (ICE_NUM_WORDS_RECIPE * ICE_MAX_CHAIN_RECIPE)
30 
31 /* Field vector index corresponding to chaining */
32 #define ICE_CHAIN_FV_INDEX_START 47
33 
34 enum ice_protocol_type {
35 	ICE_MAC_OFOS = 0,
36 	ICE_MAC_IL,
37 	ICE_ETYPE_OL,
38 	ICE_ETYPE_IL,
39 	ICE_VLAN_OFOS,
40 	ICE_IPV4_OFOS,
41 	ICE_IPV4_IL,
42 	ICE_IPV6_OFOS,
43 	ICE_IPV6_IL,
44 	ICE_TCP_IL,
45 	ICE_UDP_OF,
46 	ICE_UDP_ILOS,
47 	ICE_VXLAN,
48 	ICE_GENEVE,
49 	ICE_NVGRE,
50 	ICE_GTP,
51 	ICE_GTP_NO_PAY,
52 	ICE_PFCP,
53 	ICE_PPPOE,
54 	ICE_L2TPV3,
55 	ICE_VLAN_EX,
56 	ICE_VLAN_IN,
57 	ICE_HW_METADATA,
58 	ICE_VXLAN_GPE,
59 	ICE_SCTP_IL,
60 	ICE_PROTOCOL_LAST
61 };
62 
63 enum ice_sw_tunnel_type {
64 	ICE_NON_TUN = 0,
65 	ICE_SW_TUN_AND_NON_TUN,
66 	ICE_SW_TUN_VXLAN,
67 	ICE_SW_TUN_GENEVE,
68 	ICE_SW_TUN_NVGRE,
69 	ICE_SW_TUN_GTPU,
70 	ICE_SW_TUN_GTPC,
71 	ICE_SW_TUN_PFCP,
72 	ICE_ALL_TUNNELS /* All tunnel types including NVGRE */
73 };
74 
75 /* Decoders for ice_prot_id:
76  * - F: First
77  * - I: Inner
78  * - L: Last
79  * - O: Outer
80  * - S: Single
81  */
82 enum ice_prot_id {
83 	ICE_PROT_ID_INVAL	= 0,
84 	ICE_PROT_MAC_OF_OR_S	= 1,
85 	ICE_PROT_MAC_O2		= 2,
86 	ICE_PROT_MAC_IL		= 4,
87 	ICE_PROT_MAC_IN_MAC	= 7,
88 	ICE_PROT_ETYPE_OL	= 9,
89 	ICE_PROT_ETYPE_IL	= 10,
90 	ICE_PROT_PAY		= 15,
91 	ICE_PROT_EVLAN_O	= 16,
92 	ICE_PROT_VLAN_O		= 17,
93 	ICE_PROT_VLAN_IF	= 18,
94 	ICE_PROT_MPLS_OL_MINUS_1 = 27,
95 	ICE_PROT_MPLS_OL_OR_OS	= 28,
96 	ICE_PROT_MPLS_IL	= 29,
97 	ICE_PROT_IPV4_OF_OR_S	= 32,
98 	ICE_PROT_IPV4_IL	= 33,
99 	ICE_PROT_IPV4_IL_IL	= 34,
100 	ICE_PROT_IPV6_OF_OR_S	= 40,
101 	ICE_PROT_IPV6_IL	= 41,
102 	ICE_PROT_IPV6_IL_IL	= 42,
103 	ICE_PROT_IPV6_NEXT_PROTO = 43,
104 	ICE_PROT_IPV6_FRAG	= 47,
105 	ICE_PROT_TCP_IL		= 49,
106 	ICE_PROT_UDP_OF		= 52,
107 	ICE_PROT_UDP_IL_OR_S	= 53,
108 	ICE_PROT_GRE_OF		= 64,
109 	ICE_PROT_NSH_F		= 84,
110 	ICE_PROT_ESP_F		= 88,
111 	ICE_PROT_ESP_2		= 89,
112 	ICE_PROT_SCTP_IL	= 96,
113 	ICE_PROT_ICMP_IL	= 98,
114 	ICE_PROT_ICMPV6_IL	= 100,
115 	ICE_PROT_VRRP_F		= 101,
116 	ICE_PROT_OSPF		= 102,
117 	ICE_PROT_PPPOE		= 103,
118 	ICE_PROT_L2TPV3		= 104,
119 	ICE_PROT_ATAOE_OF	= 114,
120 	ICE_PROT_CTRL_OF	= 116,
121 	ICE_PROT_LLDP_OF	= 117,
122 	ICE_PROT_ARP_OF		= 118,
123 	ICE_PROT_META_ID	= 255, /* when offset == metadata */
124 	ICE_PROT_EAPOL_OF	= 120,
125 	ICE_PROT_INVALID	= 255  /* when offset == ICE_FV_OFFSET_INVAL */
126 };
127 
128 #define ICE_VNI_OFFSET		12 /* offset of VNI from ICE_PROT_UDP_OF */
129 
130 #define ICE_MAC_OFOS_HW		1
131 #define ICE_MAC_IL_HW		4
132 #define ICE_ETYPE_OL_HW		9
133 #define ICE_ETYPE_IL_HW		10
134 #define ICE_VLAN_OF_HW		16
135 #define ICE_VLAN_OL_HW		17
136 #define ICE_IPV4_OFOS_HW	32
137 #define ICE_IPV4_IL_HW		33
138 #define ICE_IPV6_OFOS_HW	40
139 #define ICE_IPV6_IL_HW		41
140 #define ICE_TCP_IL_HW		49
141 #define ICE_UDP_ILOS_HW		53
142 #define ICE_GRE_OF_HW		64
143 #define ICE_PPPOE_HW		103
144 #define ICE_L2TPV3_HW		104
145 
146 #define ICE_UDP_OF_HW	52 /* UDP Tunnels */
147 
148 
149 #define ICE_TUN_FLAG_FV_IND 2
150 
151 /* Mapping of software defined protocol ID to hardware defined protocol ID */
152 struct ice_protocol_entry {
153 	enum ice_protocol_type type;
154 	u8 protocol_id;
155 };
156 
157 struct ice_ether_hdr {
158 	u8 dst_addr[ETH_ALEN];
159 	u8 src_addr[ETH_ALEN];
160 };
161 
162 struct ice_ethtype_hdr {
163 	__be16 ethtype_id;
164 };
165 
166 struct ice_ether_vlan_hdr {
167 	u8 dst_addr[ETH_ALEN];
168 	u8 src_addr[ETH_ALEN];
169 	__be32 vlan_id;
170 };
171 
172 struct ice_vlan_hdr {
173 	__be16 type;
174 	__be16 vlan;
175 };
176 
177 struct ice_ipv4_hdr {
178 	u8 version;
179 	u8 tos;
180 	__be16 total_length;
181 	__be16 id;
182 	__be16 frag_off;
183 	u8 time_to_live;
184 	u8 protocol;
185 	__be16 check;
186 	__be32 src_addr;
187 	__be32 dst_addr;
188 };
189 
190 struct ice_ipv6_hdr {
191 	__be32 be_ver_tc_flow;
192 	__be16 payload_len;
193 	u8 next_hdr;
194 	u8 hop_limit;
195 	u8 src_addr[ICE_IPV6_ADDR_LENGTH];
196 	u8 dst_addr[ICE_IPV6_ADDR_LENGTH];
197 };
198 
199 struct ice_sctp_hdr {
200 	__be16 src_port;
201 	__be16 dst_port;
202 	__be32 verification_tag;
203 	__be32 check;
204 };
205 
206 struct ice_l4_hdr {
207 	__be16 src_port;
208 	__be16 dst_port;
209 	__be16 len;
210 	__be16 check;
211 };
212 
213 struct ice_udp_tnl_hdr {
214 	__be16 field;
215 	__be16 proto_type;
216 	__be32 vni;     /* only use lower 24-bits */
217 };
218 
219 struct ice_udp_gtp_hdr {
220 	u8 flags;
221 	u8 msg_type;
222 	__be16 rsrvd_len;
223 	__be32 teid;
224 	__be16 rsrvd_seq_nbr;
225 	u8 rsrvd_n_pdu_nbr;
226 	u8 rsrvd_next_ext;
227 	u8 rsvrd_ext_len;
228 	u8 pdu_type;
229 	u8 qfi;
230 	u8 rsvrd;
231 };
232 
233 struct ice_pfcp_hdr {
234 	u8 flags;
235 	u8 msg_type;
236 	__be16 length;
237 	__be64 seid;
238 	__be32 seq;
239 	u8 spare;
240 } __packed __aligned(__alignof__(u16));
241 
242 struct ice_pppoe_hdr {
243 	u8 rsrvd_ver_type;
244 	u8 rsrvd_code;
245 	__be16 session_id;
246 	__be16 length;
247 	__be16 ppp_prot_id; /* control and data only */
248 };
249 
250 struct ice_l2tpv3_sess_hdr {
251 	__be32 session_id;
252 	__be64 cookie;
253 };
254 
255 struct ice_nvgre_hdr {
256 	__be16 flags;
257 	__be16 protocol;
258 	__be32 tni_flow;
259 };
260 
261 /* Metadata information
262  *
263  * Not all MDIDs can be used by switch block. It depends on package version.
264  *
265  * MDID 16 (Rx offset)
266  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
267  * |  A  |   B     |   Reserved    |
268  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
269  *
270  * A = Source port where the transaction came from (3b).
271  *
272  * B = Destination TC of the packet. The TC is relative to a port (5b).
273  *
274  * MDID 17
275  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
276  * |      PTYPE        | Reserved  |
277  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
278  *
279  * PTYPE = Encodes the packet type (10b).
280  *
281  * MDID 18
282  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
283  * | Packet length             | R |
284  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
285  *
286  * Packet length = Length of the packet in bytes
287  *		   (packet always carriers CRC) (14b).
288  * R = Reserved (2b).
289  *
290  * MDID 19
291  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
292  * |   Source VSI      | Reserved  |
293  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
294  *
295  * Source VSI = Source VSI of packet loopbacked in switch (for egress) (10b).
296  */
297 #define ICE_MDID_SOURCE_VSI_MASK GENMASK(9, 0)
298 
299 /*
300  * MDID 20
301  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
302  * |A|B|C|D|E|F|R|R|G|H|I|J|K|L|M|N|
303  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
304  *
305  * A = DSI - set for DSI RX pkts.
306  * B = ipsec_decrypted - invalid on NIC.
307  * C = marker - this is a marker packet.
308  * D = from_network - for TX sets to 0
309  *		      for RX:
310  *		        * 1 - packet is from external link
311  *		        * 0 - packet source is from internal
312  * E = source_interface_is_rx - reflect the physical interface from where the
313  *				packet was received:
314  *				* 1 - Rx
315  *				* 0 - Tx
316  * F = from_mng - The bit signals that the packet's origin is the management.
317  * G = ucast - Outer L2 MAC address is unicast.
318  * H = mcast - Outer L2 MAC address is multicast.
319  * I = bcast - Outer L2 MAC address is broadcast.
320  * J = second_outer_mac_present - 2 outer MAC headers are present in the packet.
321  * K = STAG or BVLAN - Outer L2 header has STAG (ethernet type 0x88a8) or
322  *		       BVLAN (ethernet type 0x88a8).
323  * L = ITAG - Outer L2 header has ITAG *ethernet type 0x88e7)
324  * M = EVLAN (0x8100) - Outer L2 header has EVLAN (ethernet type 0x8100)
325  * N = EVLAN (0x9100) - Outer L2 header has EVLAN (ethernet type 0x9100)
326  */
327 #define ICE_PKT_FROM_NETWORK	BIT(3)
328 #define ICE_PKT_VLAN_STAG	BIT(12)
329 #define ICE_PKT_VLAN_ITAG	BIT(13)
330 #define ICE_PKT_VLAN_EVLAN	(BIT(14) | BIT(15))
331 #define ICE_PKT_VLAN_MASK	(ICE_PKT_VLAN_STAG | ICE_PKT_VLAN_ITAG | \
332 				ICE_PKT_VLAN_EVLAN)
333 /* MDID 21
334  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
335  * |A|B|C|D|E|F|G|H|I|J|R|R|K|L|M|N|
336  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
337  *
338  * A = VLAN (0x8100) - Outer L2 header has VLAN (ethernet type 0x8100)
339  * B = NSHoE - Outer L2 header has NSH (ethernet type 0x894f)
340  * C = MPLS (0x8847) - There is at least 1 MPLS tag in the outer header
341  *		       (ethernet type 0x8847)
342  * D = MPLS (0x8848) - There is at least 1 MPLS tag in the outer header
343  *		       (ethernet type 0x8848)
344  * E = multi MPLS - There is more than a single MPLS tag in the outer header
345  * F = inner MPLS - There is inner MPLS tag in the packet
346  * G = tunneled MAC - Set if the packet includes a tunneled MAC
347  * H = tunneled VLAN - Same as VLAN, but for a tunneled header
348  * I = pkt_is_frag - Packet is fragmented (ipv4 or ipv6)
349  * J = ipv6_ext - The packet has routing or destination ipv6 extension in inner
350  *		  or outer ipv6 headers
351  * K = RoCE - UDP packet detected as RoCEv2
352  * L = UDP_XSUM_0 - Set to 1 if L4 checksum is 0 in a UDP packet
353  * M = ESP - This is a ESP packet
354  * N = NAT_ESP - This is a ESP packet encapsulated in UDP NAT
355  */
356 #define ICE_PKT_TUNNEL_MAC	BIT(6)
357 #define ICE_PKT_TUNNEL_VLAN	BIT(7)
358 #define ICE_PKT_TUNNEL_MASK	(ICE_PKT_TUNNEL_MAC | ICE_PKT_TUNNEL_VLAN)
359 
360 /* MDID 22
361  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
362  * |A|B|C|D|E|F|  G  |H|I|J| K |L|M|
363  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
364  *
365  * A = fin - fin flag in tcp header
366  * B = sync - sync flag in tcp header
367  * C = rst - rst flag in tcp header
368  * D = psh - psh flag in tcp header
369  * E = ack - ack flag in tcp header
370  * F = urg - urg flag in tcp header
371  * G = tunnel type (3b) - Flags used to decode tunnel type:
372  *			  * b000 - not a VXLAN/Geneve/GRE tunnel
373  *			  * b001 - VXLAN-GPE
374  *			  * b010 - VXLAN (non-GPE)
375  *			  * b011 - Geneve
376  *			  * b100 - GRE (no key, no xsum)
377  *			  * b101 - GREK (key, no xsum)
378  *			  * b110 - GREC (no key, xsum)
379  *			  * b111 - GREKC (key, xsum)
380  * H = UDP_GRE - Packet is UDP (VXLAN or VLAN_GPE or Geneve or MPLSoUDP or GRE)
381  *		 tunnel
382  * I = OAM - VXLAN/Geneve/tunneled NSH packet with the OAM bit set
383  * J = tunneled NSH - Packet has NSHoGRE or NSHoUDP
384  * K = switch (2b) - Direction on switch
385  *		     * b00 - normal
386  *		     * b01 - TX force only LAN
387  *		     * b10 - TX disable LAN
388  *		     * b11 - direct to VSI
389  * L = swpe - Represents SWPE bit in TX command
390  * M = sw_cmd - Switch command
391  *
392  * MDID 23
393  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
394  * |A|B|C|D|        R        |E|F|R|
395  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
396  *
397  * A = MAC error - Produced by MAC according to L2 error conditions
398  * B = PPRS no offload - FIFO overflow in PPRS or any problematic condition in
399  *			 PPRS ANA
400  * C = abort - Set when malicious packet is detected
401  * D = partial analysis - ANA's analysing got cut in the middle
402  *			 (header > 504B etc.)
403  * E = FLM - Flow director hit indication
404  * F = FDLONG - Flow direector long bucket indication
405  *
406  */
407 #define ICE_MDID_SIZE 2
408 #define ICE_META_DATA_ID_HW 255
409 
410 enum ice_hw_metadata_id {
411 	ICE_SOURCE_PORT_MDID = 16,
412 	ICE_PTYPE_MDID = 17,
413 	ICE_PACKET_LENGTH_MDID = 18,
414 	ICE_SOURCE_VSI_MDID = 19,
415 	ICE_PKT_VLAN_MDID = 20,
416 	ICE_PKT_TUNNEL_MDID = 21,
417 	ICE_PKT_TCP_MDID = 22,
418 	ICE_PKT_ERROR_MDID = 23,
419 };
420 
421 enum ice_hw_metadata_offset {
422 	ICE_SOURCE_PORT_MDID_OFFSET = ICE_MDID_SIZE * ICE_SOURCE_PORT_MDID,
423 	ICE_PTYPE_MDID_OFFSET = ICE_MDID_SIZE * ICE_PTYPE_MDID,
424 	ICE_PACKET_LENGTH_MDID_OFFSET = ICE_MDID_SIZE * ICE_PACKET_LENGTH_MDID,
425 	ICE_SOURCE_VSI_MDID_OFFSET = ICE_MDID_SIZE * ICE_SOURCE_VSI_MDID,
426 	ICE_PKT_VLAN_MDID_OFFSET = ICE_MDID_SIZE * ICE_PKT_VLAN_MDID,
427 	ICE_PKT_TUNNEL_MDID_OFFSET = ICE_MDID_SIZE * ICE_PKT_TUNNEL_MDID,
428 	ICE_PKT_TCP_MDID_OFFSET = ICE_MDID_SIZE * ICE_PKT_TCP_MDID,
429 	ICE_PKT_ERROR_MDID_OFFSET = ICE_MDID_SIZE * ICE_PKT_ERROR_MDID,
430 };
431 
432 enum ice_pkt_flags {
433 	ICE_PKT_FLAGS_MDID20 = 0,
434 	ICE_PKT_FLAGS_MDID21 = 1,
435 	ICE_PKT_FLAGS_MDID22 = 2,
436 	ICE_PKT_FLAGS_MDID23 = 3,
437 };
438 
439 struct ice_hw_metadata {
440 	__be16 source_port;
441 	__be16 ptype;
442 	__be16 packet_length;
443 	__be16 source_vsi;
444 	__be16 flags[4];
445 };
446 
447 union ice_prot_hdr {
448 	struct ice_ether_hdr eth_hdr;
449 	struct ice_ethtype_hdr ethertype;
450 	struct ice_vlan_hdr vlan_hdr;
451 	struct ice_ipv4_hdr ipv4_hdr;
452 	struct ice_ipv6_hdr ipv6_hdr;
453 	struct ice_l4_hdr l4_hdr;
454 	struct ice_sctp_hdr sctp_hdr;
455 	struct ice_udp_tnl_hdr tnl_hdr;
456 	struct ice_nvgre_hdr nvgre_hdr;
457 	struct ice_udp_gtp_hdr gtp_hdr;
458 	struct ice_pfcp_hdr pfcp_hdr;
459 	struct ice_pppoe_hdr pppoe_hdr;
460 	struct ice_l2tpv3_sess_hdr l2tpv3_sess_hdr;
461 	struct ice_hw_metadata metadata;
462 };
463 
464 /* This is mapping table entry that maps every word within a given protocol
465  * structure to the real byte offset as per the specification of that
466  * protocol header.
467  * for e.g. dst address is 3 words in ethertype header and corresponding bytes
468  * are 0, 2, 3 in the actual packet header and src address is at 4, 6, 8
469  */
470 struct ice_prot_ext_tbl_entry {
471 	enum ice_protocol_type prot_type;
472 	/* Byte offset into header of given protocol type */
473 	u8 offs[sizeof(union ice_prot_hdr)];
474 };
475 
476 /* Extractions to be looked up for a given recipe */
477 struct ice_prot_lkup_ext {
478 	u8 n_val_words;
479 	/* create a buffer to hold max words per recipe */
480 	u16 field_mask[ICE_MAX_CHAIN_WORDS];
481 
482 	struct ice_fv_word fv_words[ICE_MAX_CHAIN_WORDS];
483 };
484 
485 #endif /* _ICE_PROTOCOL_TYPE_H_ */
486