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