1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2019
8 #include "ice_flex_type.h"
9 #define ICE_IPV4_MAKE_PREFIX_MASK(prefix) ((u32)(~0) << (32 - (prefix)))
10 #define ICE_FLOW_PROF_ID_INVAL 0xfffffffffffffffful
11 #define ICE_FLOW_PROF_ID_BYPASS 0
12 #define ICE_FLOW_PROF_ID_DEFAULT 1
13 #define ICE_FLOW_ENTRY_HANDLE_INVAL 0
14 #define ICE_FLOW_VSI_INVAL 0xffff
15 #define ICE_FLOW_FLD_OFF_INVAL 0xffff
17 /* Generate flow hash field from flow field type(s) */
18 #define ICE_FLOW_HASH_ETH \
19 (BIT_ULL(ICE_FLOW_FIELD_IDX_ETH_DA) | \
20 BIT_ULL(ICE_FLOW_FIELD_IDX_ETH_SA))
21 #define ICE_FLOW_HASH_IPV4 \
22 (BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA) | \
23 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA))
24 #define ICE_FLOW_HASH_IPV6 \
25 (BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA) | \
26 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA))
27 #define ICE_FLOW_HASH_TCP_PORT \
28 (BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT) | \
29 BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT))
30 #define ICE_FLOW_HASH_UDP_PORT \
31 (BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT) | \
32 BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT))
33 #define ICE_FLOW_HASH_SCTP_PORT \
34 (BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT) | \
35 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT))
37 #define ICE_HASH_INVALID 0
38 #define ICE_HASH_TCP_IPV4 (ICE_FLOW_HASH_IPV4 | ICE_FLOW_HASH_TCP_PORT)
39 #define ICE_HASH_TCP_IPV6 (ICE_FLOW_HASH_IPV6 | ICE_FLOW_HASH_TCP_PORT)
40 #define ICE_HASH_UDP_IPV4 (ICE_FLOW_HASH_IPV4 | ICE_FLOW_HASH_UDP_PORT)
41 #define ICE_HASH_UDP_IPV6 (ICE_FLOW_HASH_IPV6 | ICE_FLOW_HASH_UDP_PORT)
42 #define ICE_HASH_SCTP_IPV4 (ICE_FLOW_HASH_IPV4 | ICE_FLOW_HASH_SCTP_PORT)
43 #define ICE_HASH_SCTP_IPV6 (ICE_FLOW_HASH_IPV6 | ICE_FLOW_HASH_SCTP_PORT)
45 #define ICE_FLOW_HASH_GTP_TEID \
46 (BIT_ULL(ICE_FLOW_FIELD_IDX_GTPC_TEID))
48 #define ICE_FLOW_HASH_GTP_IPV4_TEID \
49 (ICE_FLOW_HASH_IPV4 | ICE_FLOW_HASH_GTP_TEID)
50 #define ICE_FLOW_HASH_GTP_IPV6_TEID \
51 (ICE_FLOW_HASH_IPV6 | ICE_FLOW_HASH_GTP_TEID)
53 #define ICE_FLOW_HASH_GTP_U_TEID \
54 (BIT_ULL(ICE_FLOW_FIELD_IDX_GTPU_IP_TEID))
56 #define ICE_FLOW_HASH_GTP_U_IPV4_TEID \
57 (ICE_FLOW_HASH_IPV4 | ICE_FLOW_HASH_GTP_U_TEID)
58 #define ICE_FLOW_HASH_GTP_U_IPV6_TEID \
59 (ICE_FLOW_HASH_IPV6 | ICE_FLOW_HASH_GTP_U_TEID)
61 #define ICE_FLOW_HASH_PPPOE_SESS_ID \
62 (BIT_ULL(ICE_FLOW_FIELD_IDX_PPPOE_SESS_ID))
64 #define ICE_FLOW_HASH_PPPOE_SESS_ID_ETH \
65 (ICE_FLOW_HASH_ETH | ICE_FLOW_HASH_PPPOE_SESS_ID)
66 #define ICE_FLOW_HASH_PPPOE_TCP_ID \
67 (ICE_FLOW_HASH_TCP_PORT | ICE_FLOW_HASH_PPPOE_SESS_ID)
68 #define ICE_FLOW_HASH_PPPOE_UDP_ID \
69 (ICE_FLOW_HASH_UDP_PORT | ICE_FLOW_HASH_PPPOE_SESS_ID)
71 /* Protocol header fields within a packet segment. A segment consists of one or
72 * more protocol headers that make up a logical group of protocol headers. Each
73 * logical group of protocol headers encapsulates or is encapsulated using/by
74 * tunneling or encapsulation protocols for network virtualization such as GRE,
77 enum ice_flow_seg_hdr {
78 ICE_FLOW_SEG_HDR_NONE = 0x00000000,
79 ICE_FLOW_SEG_HDR_ETH = 0x00000001,
80 ICE_FLOW_SEG_HDR_VLAN = 0x00000002,
81 ICE_FLOW_SEG_HDR_IPV4 = 0x00000004,
82 ICE_FLOW_SEG_HDR_IPV6 = 0x00000008,
83 ICE_FLOW_SEG_HDR_ARP = 0x00000010,
84 ICE_FLOW_SEG_HDR_ICMP = 0x00000020,
85 ICE_FLOW_SEG_HDR_TCP = 0x00000040,
86 ICE_FLOW_SEG_HDR_UDP = 0x00000080,
87 ICE_FLOW_SEG_HDR_SCTP = 0x00000100,
88 ICE_FLOW_SEG_HDR_GRE = 0x00000200,
89 ICE_FLOW_SEG_HDR_GTPC = 0x00000400,
90 ICE_FLOW_SEG_HDR_GTPC_TEID = 0x00000800,
91 ICE_FLOW_SEG_HDR_GTPU_IP = 0x00001000,
92 ICE_FLOW_SEG_HDR_GTPU_DWN = 0x00002000,
93 ICE_FLOW_SEG_HDR_GTPU_UP = 0x00004000,
94 ICE_FLOW_SEG_HDR_PPPOE = 0x00008000,
97 /* These segements all have the same PTYPES, but are otherwise distinguished by
98 * the value of the gtp_eh_pdu and gtp_eh_pdu_link flags:
100 * gtp_eh_pdu gtp_eh_pdu_link
101 * ICE_FLOW_SEG_HDR_GTPU_IP 0 0
102 * ICE_FLOW_SEG_HDR_GTPU_DWN 1 0
103 * ICE_FLOW_SEG_HDR_GTPU_UP 1 1
105 #define ICE_FLOW_SEG_HDR_GTPU (ICE_FLOW_SEG_HDR_GTPU_IP | \
106 ICE_FLOW_SEG_HDR_GTPU_DWN | \
107 ICE_FLOW_SEG_HDR_GTPU_UP)
109 enum ice_flow_field {
111 ICE_FLOW_FIELD_IDX_ETH_DA,
112 ICE_FLOW_FIELD_IDX_ETH_SA,
113 ICE_FLOW_FIELD_IDX_S_VLAN,
114 ICE_FLOW_FIELD_IDX_C_VLAN,
115 ICE_FLOW_FIELD_IDX_ETH_TYPE,
117 ICE_FLOW_FIELD_IDX_IPV4_DSCP,
118 ICE_FLOW_FIELD_IDX_IPV6_DSCP,
119 ICE_FLOW_FIELD_IDX_IPV4_TTL,
120 ICE_FLOW_FIELD_IDX_IPV4_PROT,
121 ICE_FLOW_FIELD_IDX_IPV6_TTL,
122 ICE_FLOW_FIELD_IDX_IPV6_PROT,
123 ICE_FLOW_FIELD_IDX_IPV4_SA,
124 ICE_FLOW_FIELD_IDX_IPV4_DA,
125 ICE_FLOW_FIELD_IDX_IPV6_SA,
126 ICE_FLOW_FIELD_IDX_IPV6_DA,
128 ICE_FLOW_FIELD_IDX_TCP_SRC_PORT,
129 ICE_FLOW_FIELD_IDX_TCP_DST_PORT,
130 ICE_FLOW_FIELD_IDX_UDP_SRC_PORT,
131 ICE_FLOW_FIELD_IDX_UDP_DST_PORT,
132 ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT,
133 ICE_FLOW_FIELD_IDX_SCTP_DST_PORT,
134 ICE_FLOW_FIELD_IDX_TCP_FLAGS,
136 ICE_FLOW_FIELD_IDX_ARP_SIP,
137 ICE_FLOW_FIELD_IDX_ARP_DIP,
138 ICE_FLOW_FIELD_IDX_ARP_SHA,
139 ICE_FLOW_FIELD_IDX_ARP_DHA,
140 ICE_FLOW_FIELD_IDX_ARP_OP,
142 ICE_FLOW_FIELD_IDX_ICMP_TYPE,
143 ICE_FLOW_FIELD_IDX_ICMP_CODE,
145 ICE_FLOW_FIELD_IDX_GRE_KEYID,
147 ICE_FLOW_FIELD_IDX_GTPC_TEID,
149 ICE_FLOW_FIELD_IDX_GTPU_IP_TEID,
151 ICE_FLOW_FIELD_IDX_GTPU_UP_TEID,
153 ICE_FLOW_FIELD_IDX_GTPU_DWN_TEID,
155 ICE_FLOW_FIELD_IDX_PPPOE_SESS_ID,
156 /* The total number of enums must not exceed 64 */
157 ICE_FLOW_FIELD_IDX_MAX
160 /* Flow headers and fields for AVF support */
161 enum ice_flow_avf_hdr_field {
162 /* Values 0 - 28 are reserved for future use */
163 ICE_AVF_FLOW_FIELD_INVALID = 0,
164 ICE_AVF_FLOW_FIELD_UNICAST_IPV4_UDP = 29,
165 ICE_AVF_FLOW_FIELD_MULTICAST_IPV4_UDP,
166 ICE_AVF_FLOW_FIELD_IPV4_UDP,
167 ICE_AVF_FLOW_FIELD_IPV4_TCP_SYN_NO_ACK,
168 ICE_AVF_FLOW_FIELD_IPV4_TCP,
169 ICE_AVF_FLOW_FIELD_IPV4_SCTP,
170 ICE_AVF_FLOW_FIELD_IPV4_OTHER,
171 ICE_AVF_FLOW_FIELD_FRAG_IPV4,
172 ICE_AVF_FLOW_FIELD_UNICAST_IPV6_UDP = 39,
173 ICE_AVF_FLOW_FIELD_MULTICAST_IPV6_UDP,
174 ICE_AVF_FLOW_FIELD_IPV6_UDP,
175 ICE_AVF_FLOW_FIELD_IPV6_TCP_SYN_NO_ACK,
176 ICE_AVF_FLOW_FIELD_IPV6_TCP,
177 ICE_AVF_FLOW_FIELD_IPV6_SCTP,
178 ICE_AVF_FLOW_FIELD_IPV6_OTHER,
179 ICE_AVF_FLOW_FIELD_FRAG_IPV6,
180 ICE_AVF_FLOW_FIELD_RSVD47,
181 ICE_AVF_FLOW_FIELD_FCOE_OX,
182 ICE_AVF_FLOW_FIELD_FCOE_RX,
183 ICE_AVF_FLOW_FIELD_FCOE_OTHER,
184 /* Values 51-62 are reserved */
185 ICE_AVF_FLOW_FIELD_L2_PAYLOAD = 63,
186 ICE_AVF_FLOW_FIELD_MAX
189 /* Supported RSS offloads This macro is defined to support
190 * VIRTCHNL_OP_GET_RSS_HENA_CAPS ops. PF driver sends the RSS hardware
191 * capabilities to the caller of this ops.
193 #define ICE_DEFAULT_RSS_HENA ( \
194 BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_UDP) | \
195 BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_SCTP) | \
196 BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_TCP) | \
197 BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_OTHER) | \
198 BIT_ULL(ICE_AVF_FLOW_FIELD_FRAG_IPV4) | \
199 BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_UDP) | \
200 BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_TCP) | \
201 BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_SCTP) | \
202 BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_OTHER) | \
203 BIT_ULL(ICE_AVF_FLOW_FIELD_FRAG_IPV6) | \
204 BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_TCP_SYN_NO_ACK) | \
205 BIT_ULL(ICE_AVF_FLOW_FIELD_UNICAST_IPV4_UDP) | \
206 BIT_ULL(ICE_AVF_FLOW_FIELD_MULTICAST_IPV4_UDP) | \
207 BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_TCP_SYN_NO_ACK) | \
208 BIT_ULL(ICE_AVF_FLOW_FIELD_UNICAST_IPV6_UDP) | \
209 BIT_ULL(ICE_AVF_FLOW_FIELD_MULTICAST_IPV6_UDP))
212 ICE_FLOW_DIR_UNDEFINED = 0,
215 ICE_FLOW_TX_RX = ICE_FLOW_RX | ICE_FLOW_TX
218 enum ice_flow_priority {
220 ICE_FLOW_PRIO_NORMAL,
224 #define ICE_FLOW_SEG_MAX 2
225 #define ICE_FLOW_SEG_RAW_FLD_MAX 2
226 #define ICE_FLOW_PROFILE_MAX 1024
227 #define ICE_FLOW_SW_FIELD_VECTOR_MAX 48
228 #define ICE_FLOW_ACL_FIELD_VECTOR_MAX 32
229 #define ICE_FLOW_FV_EXTRACT_SZ 2
231 #define ICE_FLOW_SET_HDRS(seg, val) ((seg)->hdrs |= (u32)(val))
233 struct ice_flow_seg_xtrct {
234 u8 prot_id; /* Protocol ID of extracted header field */
235 u16 off; /* Starting offset of the field in header in bytes */
236 u8 idx; /* Index of FV entry used */
237 u8 disp; /* Displacement of field in bits fr. FV entry's start */
238 u16 mask; /* Mask for field */
241 enum ice_flow_fld_match_type {
242 ICE_FLOW_FLD_TYPE_REG, /* Value, mask */
243 ICE_FLOW_FLD_TYPE_RANGE, /* Value, mask, last (upper bound) */
244 ICE_FLOW_FLD_TYPE_PREFIX, /* IP address, prefix, size of prefix */
245 ICE_FLOW_FLD_TYPE_SIZE, /* Value, mask, size of match */
248 struct ice_flow_fld_loc {
249 /* Describe offsets of field information relative to the beginning of
250 * input buffer provided when adding flow entries.
252 u16 val; /* Offset where the value is located */
253 u16 mask; /* Offset where the mask/prefix value is located */
254 u16 last; /* Length or offset where the upper value is located */
257 struct ice_flow_fld_info {
258 enum ice_flow_fld_match_type type;
259 /* Location where to retrieve data from an input buffer */
260 struct ice_flow_fld_loc src;
261 /* Location where to put the data into the final entry buffer */
262 struct ice_flow_fld_loc entry;
263 struct ice_flow_seg_xtrct xtrct;
266 struct ice_flow_seg_fld_raw {
267 int off; /* Offset from the start of the segment */
268 struct ice_flow_fld_info info;
271 struct ice_flow_seg_info {
272 u32 hdrs; /* Bitmask indicating protocol headers present */
273 u64 match; /* Bitmask indicating header fields to be matched */
274 u64 range; /* Bitmask indicating header fields matched as ranges */
276 struct ice_flow_fld_info fields[ICE_FLOW_FIELD_IDX_MAX];
278 u8 raws_cnt; /* Number of raw fields to be matched */
279 struct ice_flow_seg_fld_raw raws[ICE_FLOW_SEG_RAW_FLD_MAX];
282 /* This structure describes a flow entry, and is tracked only in this file */
283 struct ice_flow_entry {
284 struct LIST_ENTRY_TYPE l_entry;
287 struct ice_flow_prof *prof;
289 struct ice_flow_action *acts;
290 /* Flow entry's content */
292 enum ice_flow_priority priority;
298 #define ICE_FLOW_ENTRY_HNDL(e) ((unsigned long)e)
299 #define ICE_FLOW_ENTRY_PTR(h) ((struct ice_flow_entry *)(h))
301 struct ice_flow_prof {
302 struct LIST_ENTRY_TYPE l_entry;
305 enum ice_flow_dir dir;
309 /* Keep track of flow entries associated with this flow profile */
310 struct ice_lock entries_lock;
311 struct LIST_HEAD_TYPE entries;
313 struct ice_flow_seg_info segs[ICE_FLOW_SEG_MAX];
315 /* software VSI handles referenced by this flow profile */
316 ice_declare_bitmap(vsis, ICE_MAX_VSI);
319 /* struct sw_recipe */
322 /* Symmetric Hash for RSS */
326 /* Default actions */
327 struct ice_flow_action *acts;
331 struct LIST_ENTRY_TYPE l_entry;
332 /* bitmap of VSIs added to the RSS entry */
333 ice_declare_bitmap(vsis, ICE_MAX_VSI);
339 enum ice_flow_action_type {
343 ICE_FLOW_ACT_CNTR_PKT,
344 ICE_FLOW_ACT_FWD_VSI,
345 ICE_FLOW_ACT_FWD_VSI_LIST, /* Should be abstracted away */
346 ICE_FLOW_ACT_FWD_QUEUE, /* Can Queues be abstracted away? */
347 ICE_FLOW_ACT_FWD_QUEUE_GROUP, /* Can Queues be abstracted away? */
351 ICE_FLOW_ACT_CNTR_BYTES,
352 ICE_FLOW_ACT_CNTR_PKT_BYTES,
353 ICE_FLOW_ACT_GENERIC_0,
354 ICE_FLOW_ACT_GENERIC_1,
355 ICE_FLOW_ACT_GENERIC_2,
356 ICE_FLOW_ACT_GENERIC_3,
357 ICE_FLOW_ACT_GENERIC_4,
358 ICE_FLOW_ACT_RPT_FLOW_ID,
359 ICE_FLOW_ACT_BUILD_PROF_IDX,
362 struct ice_flow_action {
363 enum ice_flow_action_type type;
370 ice_flow_find_prof(struct ice_hw *hw, enum ice_block blk, enum ice_flow_dir dir,
371 struct ice_flow_seg_info *segs, u8 segs_cnt);
373 ice_flow_add_prof(struct ice_hw *hw, enum ice_block blk, enum ice_flow_dir dir,
374 u64 prof_id, struct ice_flow_seg_info *segs, u8 segs_cnt,
375 struct ice_flow_action *acts, u8 acts_cnt,
376 struct ice_flow_prof **prof);
378 ice_flow_rem_prof(struct ice_hw *hw, enum ice_block blk, u64 prof_id);
380 ice_flow_assoc_vsig_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi_handle,
383 ice_flow_get_hw_prof(struct ice_hw *hw, enum ice_block blk, u64 prof_id,
386 u64 ice_flow_find_entry(struct ice_hw *hw, enum ice_block blk, u64 entry_id);
388 ice_flow_add_entry(struct ice_hw *hw, enum ice_block blk, u64 prof_id,
389 u64 entry_id, u16 vsi, enum ice_flow_priority prio,
390 void *data, struct ice_flow_action *acts, u8 acts_cnt,
392 enum ice_status ice_flow_rem_entry(struct ice_hw *hw, u64 entry_h);
394 ice_flow_set_fld(struct ice_flow_seg_info *seg, enum ice_flow_field fld,
395 u16 val_loc, u16 mask_loc, u16 last_loc, bool range);
397 ice_flow_set_fld_prefix(struct ice_flow_seg_info *seg, enum ice_flow_field fld,
398 u16 val_loc, u16 prefix_loc, u8 prefix_sz);
400 ice_flow_add_fld_raw(struct ice_flow_seg_info *seg, u16 off, u8 len,
401 u16 val_loc, u16 mask_loc);
402 void ice_rem_vsi_rss_list(struct ice_hw *hw, u16 vsi_handle);
403 enum ice_status ice_replay_rss_cfg(struct ice_hw *hw, u16 vsi_handle);
405 ice_add_avf_rss_cfg(struct ice_hw *hw, u16 vsi_handle, u64 hashed_flds);
406 enum ice_status ice_rem_vsi_rss_cfg(struct ice_hw *hw, u16 vsi_handle);
408 ice_add_rss_cfg(struct ice_hw *hw, u16 vsi_handle, u64 hashed_flds,
409 u32 addl_hdrs, bool symm);
411 ice_rem_rss_cfg(struct ice_hw *hw, u16 vsi_handle, u64 hashed_flds,
413 u64 ice_get_rss_cfg(struct ice_hw *hw, u16 vsi_handle, u32 hdrs);
414 #endif /* _ICE_FLOW_H_ */