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