xref: /dpdk/drivers/net/ice/base/ice_flow.h (revision d6cefc11)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2019
3  */
4 
5 #ifndef _ICE_FLOW_H_
6 #define _ICE_FLOW_H_
7 
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
16 
17 /* Use any of the type from flow field to generate a equivalent hash field */
18 #define ICE_FLOW_HASH_FLD(t)	(1ULL << (t))
19 
20 #define ICE_FLOW_HASH_IPV4	\
21 	(ICE_FLOW_HASH_FLD(ICE_FLOW_FIELD_IDX_IPV4_SA) | \
22 	 ICE_FLOW_HASH_FLD(ICE_FLOW_FIELD_IDX_IPV4_DA))
23 #define ICE_FLOW_HASH_IPV6	\
24 	(ICE_FLOW_HASH_FLD(ICE_FLOW_FIELD_IDX_IPV6_SA) | \
25 	 ICE_FLOW_HASH_FLD(ICE_FLOW_FIELD_IDX_IPV6_DA))
26 #define ICE_FLOW_HASH_TCP_PORT	\
27 	(ICE_FLOW_HASH_FLD(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT) | \
28 	 ICE_FLOW_HASH_FLD(ICE_FLOW_FIELD_IDX_TCP_DST_PORT))
29 #define ICE_FLOW_HASH_UDP_PORT	\
30 	(ICE_FLOW_HASH_FLD(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT) | \
31 	 ICE_FLOW_HASH_FLD(ICE_FLOW_FIELD_IDX_UDP_DST_PORT))
32 #define ICE_FLOW_HASH_SCTP_PORT	\
33 	(ICE_FLOW_HASH_FLD(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT) | \
34 	 ICE_FLOW_HASH_FLD(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT))
35 
36 #define ICE_HASH_INVALID	0
37 #define ICE_HASH_TCP_IPV4	(ICE_FLOW_HASH_IPV4 | ICE_FLOW_HASH_TCP_PORT)
38 #define ICE_HASH_TCP_IPV6	(ICE_FLOW_HASH_IPV6 | ICE_FLOW_HASH_TCP_PORT)
39 #define ICE_HASH_UDP_IPV4	(ICE_FLOW_HASH_IPV4 | ICE_FLOW_HASH_UDP_PORT)
40 #define ICE_HASH_UDP_IPV6	(ICE_FLOW_HASH_IPV6 | ICE_FLOW_HASH_UDP_PORT)
41 #define ICE_HASH_SCTP_IPV4	(ICE_FLOW_HASH_IPV4 | ICE_FLOW_HASH_SCTP_PORT)
42 #define ICE_HASH_SCTP_IPV6	(ICE_FLOW_HASH_IPV6 | ICE_FLOW_HASH_SCTP_PORT)
43 
44 /* Protocol header fields within a packet segment. A segment consists of one or
45  * more protocol headers that make up a logical group of protocol headers. Each
46  * logical group of protocol headers encapsulates or is encapsulated using/by
47  * tunneling or encapsulation protocols for network virtualization such as GRE,
48  * VxLAN, etc.
49  */
50 enum ice_flow_seg_hdr {
51 	ICE_FLOW_SEG_HDR_NONE	= 0x00000000,
52 	ICE_FLOW_SEG_HDR_ETH	= 0x00000001,
53 	ICE_FLOW_SEG_HDR_VLAN	= 0x00000002,
54 	ICE_FLOW_SEG_HDR_IPV4	= 0x00000004,
55 	ICE_FLOW_SEG_HDR_IPV6	= 0x00000008,
56 	ICE_FLOW_SEG_HDR_ARP	= 0x00000010,
57 	ICE_FLOW_SEG_HDR_ICMP	= 0x00000020,
58 	ICE_FLOW_SEG_HDR_TCP	= 0x00000040,
59 	ICE_FLOW_SEG_HDR_UDP	= 0x00000080,
60 	ICE_FLOW_SEG_HDR_SCTP	= 0x00000100,
61 	ICE_FLOW_SEG_HDR_GRE	= 0x00000200,
62 };
63 
64 enum ice_flow_field {
65 	/* L2 */
66 	ICE_FLOW_FIELD_IDX_ETH_DA,
67 	ICE_FLOW_FIELD_IDX_ETH_SA,
68 	ICE_FLOW_FIELD_IDX_S_VLAN,
69 	ICE_FLOW_FIELD_IDX_C_VLAN,
70 	ICE_FLOW_FIELD_IDX_ETH_TYPE,
71 	/* L3 */
72 	ICE_FLOW_FIELD_IDX_IP_DSCP,
73 	ICE_FLOW_FIELD_IDX_IP_TTL,
74 	ICE_FLOW_FIELD_IDX_IP_PROT,
75 	ICE_FLOW_FIELD_IDX_IPV4_SA,
76 	ICE_FLOW_FIELD_IDX_IPV4_DA,
77 	ICE_FLOW_FIELD_IDX_IPV6_SA,
78 	ICE_FLOW_FIELD_IDX_IPV6_DA,
79 	/* L4 */
80 	ICE_FLOW_FIELD_IDX_TCP_SRC_PORT,
81 	ICE_FLOW_FIELD_IDX_TCP_DST_PORT,
82 	ICE_FLOW_FIELD_IDX_UDP_SRC_PORT,
83 	ICE_FLOW_FIELD_IDX_UDP_DST_PORT,
84 	ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT,
85 	ICE_FLOW_FIELD_IDX_SCTP_DST_PORT,
86 	ICE_FLOW_FIELD_IDX_TCP_FLAGS,
87 	/* ARP */
88 	ICE_FLOW_FIELD_IDX_ARP_SIP,
89 	ICE_FLOW_FIELD_IDX_ARP_DIP,
90 	ICE_FLOW_FIELD_IDX_ARP_SHA,
91 	ICE_FLOW_FIELD_IDX_ARP_DHA,
92 	ICE_FLOW_FIELD_IDX_ARP_OP,
93 	/* ICMP */
94 	ICE_FLOW_FIELD_IDX_ICMP_TYPE,
95 	ICE_FLOW_FIELD_IDX_ICMP_CODE,
96 	/* GRE */
97 	ICE_FLOW_FIELD_IDX_GRE_KEYID,
98 	 /* The total number of enums must not exceed 64 */
99 	ICE_FLOW_FIELD_IDX_MAX
100 };
101 
102 /* Flow headers and fields for AVF support */
103 enum ice_flow_avf_hdr_field {
104 	/* Values 0 - 28 are reserved for future use */
105 	ICE_AVF_FLOW_FIELD_INVALID		= 0,
106 	ICE_AVF_FLOW_FIELD_UNICAST_IPV4_UDP	= 29,
107 	ICE_AVF_FLOW_FIELD_MULTICAST_IPV4_UDP,
108 	ICE_AVF_FLOW_FIELD_IPV4_UDP,
109 	ICE_AVF_FLOW_FIELD_IPV4_TCP_SYN_NO_ACK,
110 	ICE_AVF_FLOW_FIELD_IPV4_TCP,
111 	ICE_AVF_FLOW_FIELD_IPV4_SCTP,
112 	ICE_AVF_FLOW_FIELD_IPV4_OTHER,
113 	ICE_AVF_FLOW_FIELD_FRAG_IPV4,
114 	ICE_AVF_FLOW_FIELD_UNICAST_IPV6_UDP	= 39,
115 	ICE_AVF_FLOW_FIELD_MULTICAST_IPV6_UDP,
116 	ICE_AVF_FLOW_FIELD_IPV6_UDP,
117 	ICE_AVF_FLOW_FIELD_IPV6_TCP_SYN_NO_ACK,
118 	ICE_AVF_FLOW_FIELD_IPV6_TCP,
119 	ICE_AVF_FLOW_FIELD_IPV6_SCTP,
120 	ICE_AVF_FLOW_FIELD_IPV6_OTHER,
121 	ICE_AVF_FLOW_FIELD_FRAG_IPV6,
122 	ICE_AVF_FLOW_FIELD_RSVD47,
123 	ICE_AVF_FLOW_FIELD_FCOE_OX,
124 	ICE_AVF_FLOW_FIELD_FCOE_RX,
125 	ICE_AVF_FLOW_FIELD_FCOE_OTHER,
126 	/* Values 51-62 are reserved */
127 	ICE_AVF_FLOW_FIELD_L2_PAYLOAD		= 63,
128 	ICE_AVF_FLOW_FIELD_MAX
129 };
130 
131 /* Supported RSS offloads  This macro is defined to support
132  * VIRTCHNL_OP_GET_RSS_HENA_CAPS ops. PF driver sends the RSS hardware
133  * capabilities to the caller of this ops.
134  */
135 #define ICE_DEFAULT_RSS_HENA ( \
136 	BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_UDP) | \
137 	BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_SCTP) | \
138 	BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_TCP) | \
139 	BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_OTHER) | \
140 	BIT_ULL(ICE_AVF_FLOW_FIELD_FRAG_IPV4) | \
141 	BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_UDP) | \
142 	BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_TCP) | \
143 	BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_SCTP) | \
144 	BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_OTHER) | \
145 	BIT_ULL(ICE_AVF_FLOW_FIELD_FRAG_IPV6) | \
146 	BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_TCP_SYN_NO_ACK) | \
147 	BIT_ULL(ICE_AVF_FLOW_FIELD_UNICAST_IPV4_UDP) | \
148 	BIT_ULL(ICE_AVF_FLOW_FIELD_MULTICAST_IPV4_UDP) | \
149 	BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_TCP_SYN_NO_ACK) | \
150 	BIT_ULL(ICE_AVF_FLOW_FIELD_UNICAST_IPV6_UDP) | \
151 	BIT_ULL(ICE_AVF_FLOW_FIELD_MULTICAST_IPV6_UDP))
152 
153 enum ice_flow_dir {
154 	ICE_FLOW_DIR_UNDEFINED	= 0,
155 	ICE_FLOW_TX		= 0x01,
156 	ICE_FLOW_RX		= 0x02,
157 	ICE_FLOW_TX_RX		= ICE_FLOW_RX | ICE_FLOW_TX
158 };
159 
160 enum ice_flow_priority {
161 	ICE_FLOW_PRIO_LOW,
162 	ICE_FLOW_PRIO_NORMAL,
163 	ICE_FLOW_PRIO_HIGH
164 };
165 
166 #define ICE_FLOW_SEG_MAX		2
167 #define ICE_FLOW_SEG_RAW_FLD_MAX	2
168 #define ICE_FLOW_PROFILE_MAX		1024
169 #define ICE_FLOW_SW_FIELD_VECTOR_MAX	48
170 #define ICE_FLOW_ACL_FIELD_VECTOR_MAX	32
171 #define ICE_FLOW_FV_EXTRACT_SZ		2
172 
173 #define ICE_FLOW_SET_HDRS(seg, val)	((seg)->hdrs |= (u32)(val))
174 
175 struct ice_flow_seg_xtrct {
176 	u8 prot_id;	/* Protocol ID of extracted header field */
177 	u16 off;	/* Starting offset of the field in header in bytes */
178 	u8 idx;		/* Index of FV entry used */
179 	u8 disp;	/* Displacement of field in bits fr. FV entry's start */
180 };
181 
182 enum ice_flow_fld_match_type {
183 	ICE_FLOW_FLD_TYPE_REG,		/* Value, mask */
184 	ICE_FLOW_FLD_TYPE_RANGE,	/* Value, mask, last (upper bound) */
185 	ICE_FLOW_FLD_TYPE_PREFIX,	/* IP address, prefix, size of prefix */
186 	ICE_FLOW_FLD_TYPE_SIZE,		/* Value, mask, size of match */
187 };
188 
189 struct ice_flow_fld_loc {
190 	/* Describe offsets of field information relative to the beginning of
191 	 * input buffer provided when adding flow entries.
192 	 */
193 	u16 val;	/* Offset where the value is located */
194 	u16 mask;	/* Offset where the mask/prefix value is located */
195 	u16 last;	/* Length or offset where the upper value is located */
196 };
197 
198 struct ice_flow_fld_info {
199 	enum ice_flow_fld_match_type type;
200 	/* Location where to retrieve data from an input buffer */
201 	struct ice_flow_fld_loc src;
202 	/* Location where to put the data into the final entry buffer */
203 	struct ice_flow_fld_loc entry;
204 	struct ice_flow_seg_xtrct xtrct;
205 };
206 
207 struct ice_flow_seg_fld_raw {
208 	int off;	/* Offset from the start of the segment */
209 	struct ice_flow_fld_info info;
210 };
211 
212 struct ice_flow_seg_info {
213 	u32 hdrs;	/* Bitmask indicating protocol headers present */
214 	u64 match;	/* Bitmask indicating header fields to be matched */
215 	u64 range;	/* Bitmask indicating header fields matched as ranges */
216 
217 	struct ice_flow_fld_info fields[ICE_FLOW_FIELD_IDX_MAX];
218 
219 	u8 raws_cnt;	/* Number of raw fields to be matched */
220 	struct ice_flow_seg_fld_raw raws[ICE_FLOW_SEG_RAW_FLD_MAX];
221 };
222 
223 /* This structure describes a flow entry, and is tracked only in this file */
224 struct ice_flow_entry {
225 	struct LIST_ENTRY_TYPE l_entry;
226 
227 	u64 id;
228 	u16 vsi_handle;
229 	enum ice_flow_priority priority;
230 	struct ice_flow_prof *prof;
231 
232 	/* Flow entry's content */
233 	u16 entry_sz;
234 	void *entry;
235 
236 	/* Action list */
237 	u8 acts_cnt;
238 	struct ice_flow_action *acts;
239 };
240 
241 #define ICE_FLOW_ENTRY_HNDL(e)	((unsigned long)e)
242 #define ICE_FLOW_ENTRY_PTR(h)	((struct ice_flow_entry *)(h))
243 
244 struct ice_flow_prof {
245 	struct LIST_ENTRY_TYPE l_entry;
246 
247 	u64 id;
248 	enum ice_flow_dir dir;
249 
250 	/* Keep track of flow entries associated with this flow profile */
251 	struct ice_lock entries_lock;
252 	struct LIST_HEAD_TYPE entries;
253 
254 	u8 segs_cnt;
255 	struct ice_flow_seg_info segs[ICE_FLOW_SEG_MAX];
256 
257 	/* software VSI handles referenced by this flow profile */
258 	ice_declare_bitmap(vsis, ICE_MAX_VSI);
259 
260 	union {
261 		/* struct sw_recipe */
262 		/* struct fd */
263 		u32 data;
264 	} cfg;
265 
266 	/* Default actions */
267 	u8 acts_cnt;
268 	struct ice_flow_action *acts;
269 };
270 
271 struct ice_rss_cfg {
272 	struct LIST_ENTRY_TYPE l_entry;
273 	u64 hashed_flds;
274 	u32 packet_hdr;
275 };
276 
277 enum ice_flow_action_type {
278 	ICE_FLOW_ACT_NOP,
279 	ICE_FLOW_ACT_ALLOW,
280 	ICE_FLOW_ACT_DROP,
281 	ICE_FLOW_ACT_CNTR_PKT,
282 	ICE_FLOW_ACT_FWD_VSI,
283 	ICE_FLOW_ACT_FWD_VSI_LIST,	/* Should be abstracted away */
284 	ICE_FLOW_ACT_FWD_QUEUE,		/* Can Queues be abstracted away? */
285 	ICE_FLOW_ACT_FWD_QUEUE_GROUP,	/* Can Queues be abstracted away? */
286 	ICE_FLOW_ACT_PUSH,
287 	ICE_FLOW_ACT_POP,
288 	ICE_FLOW_ACT_MODIFY,
289 	ICE_FLOW_ACT_CNTR_BYTES,
290 	ICE_FLOW_ACT_CNTR_PKT_BYTES,
291 	ICE_FLOW_ACT_GENERIC_0,
292 	ICE_FLOW_ACT_GENERIC_1,
293 	ICE_FLOW_ACT_GENERIC_2,
294 	ICE_FLOW_ACT_GENERIC_3,
295 	ICE_FLOW_ACT_GENERIC_4,
296 	ICE_FLOW_ACT_RPT_FLOW_ID,
297 	ICE_FLOW_ACT_BUILD_PROF_IDX,
298 };
299 
300 struct ice_flow_action {
301 	enum ice_flow_action_type type;
302 	union {
303 		u32 dummy;
304 	} data;
305 };
306 
307 /* TDD esp in the linux code doesn't like prototypes, so
308  * ifdef them all out, so they stop conflicting with our mocks
309  */
310 u64
311 ice_flow_find_prof(struct ice_hw *hw, enum ice_block blk, enum ice_flow_dir dir,
312 		   struct ice_flow_seg_info *segs, u8 segs_cnt);
313 enum ice_status
314 ice_flow_add_prof(struct ice_hw *hw, enum ice_block blk, enum ice_flow_dir dir,
315 		  u64 prof_id, struct ice_flow_seg_info *segs, u8 segs_cnt,
316 		  struct ice_flow_action *acts, u8 acts_cnt,
317 		  struct ice_flow_prof **prof);
318 enum ice_status
319 ice_flow_rem_prof(struct ice_hw *hw, enum ice_block blk, u64 prof_id);
320 
321 enum ice_status
322 ice_flow_get_hw_prof(struct ice_hw *hw, enum ice_block blk, u64 prof_id,
323 		     u8 *hw_prof);
324 
325 u64 ice_flow_find_entry(struct ice_hw *hw, enum ice_block blk, u64 entry_id);
326 enum ice_status
327 ice_flow_add_entry(struct ice_hw *hw, enum ice_block blk, u64 prof_id,
328 		   u64 entry_id, u16 vsi, enum ice_flow_priority prio,
329 		   void *data, struct ice_flow_action *acts, u8 acts_cnt,
330 		   u64 *entry_h);
331 enum ice_status ice_flow_rem_entry(struct ice_hw *hw, u64 entry_h);
332 void
333 ice_flow_set_fld(struct ice_flow_seg_info *seg, enum ice_flow_field fld,
334 		 u16 val_loc, u16 mask_loc, u16 last_loc, bool range);
335 void
336 ice_flow_set_fld_prefix(struct ice_flow_seg_info *seg, enum ice_flow_field fld,
337 			u16 val_loc, u16 prefix_loc, u8 prefix_sz);
338 void
339 ice_flow_add_fld_raw(struct ice_flow_seg_info *seg, u16 off, u8 len,
340 		     u16 val_loc, u16 mask_loc);
341 void ice_rem_all_rss_vsi_ctx(struct ice_hw *hw, u16 vsi_handle);
342 enum ice_status ice_replay_rss_cfg(struct ice_hw *hw, u16 vsi_handle);
343 enum ice_status
344 ice_add_avf_rss_cfg(struct ice_hw *hw, u16 vsi_handle, u64 hashed_flds);
345 enum ice_status ice_rem_vsi_rss_cfg(struct ice_hw *hw, u16 vsi_handle);
346 enum ice_status
347 ice_add_rss_cfg(struct ice_hw *hw, u16 vsi_handle, u64 hashed_flds,
348 		u32 addl_hdrs);
349 enum ice_status
350 ice_rem_rss_cfg(struct ice_hw *hw, u16 vsi_handle, u64 hashed_flds,
351 		u32 addl_hdrs);
352 u64 ice_get_rss_cfg(struct ice_hw *hw, u16 vsi_handle, u32 hdrs);
353 #endif /* _ICE_FLOW_H_ */
354