326ff6f8120b49a2a52f4ec06309205bc42342db
[dpdk.git] / drivers / net / ice / base / ice_flow.h
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 /* 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))
36
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)
44
45 #define ICE_FLOW_HASH_GTP_TEID \
46         (BIT_ULL(ICE_FLOW_FIELD_IDX_GTPC_TEID))
47
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)
52
53 #define ICE_FLOW_HASH_GTP_U_TEID \
54         (BIT_ULL(ICE_FLOW_FIELD_IDX_GTPU_IP_TEID))
55
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)
60
61 #define ICE_FLOW_HASH_PPPOE_SESS_ID \
62         (BIT_ULL(ICE_FLOW_FIELD_IDX_PPPOE_SESS_ID))
63
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)
70
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,
75  * VxLAN, etc.
76  */
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,
95 };
96
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:
99  *
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
104  */
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)
108
109 enum ice_flow_field {
110         /* L2 */
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,
116         /* L3 */
117         ICE_FLOW_FIELD_IDX_IP_DSCP,
118         ICE_FLOW_FIELD_IDX_IP_TTL,
119         ICE_FLOW_FIELD_IDX_IP_PROT,
120         ICE_FLOW_FIELD_IDX_IPV4_SA,
121         ICE_FLOW_FIELD_IDX_IPV4_DA,
122         ICE_FLOW_FIELD_IDX_IPV6_SA,
123         ICE_FLOW_FIELD_IDX_IPV6_DA,
124         /* L4 */
125         ICE_FLOW_FIELD_IDX_TCP_SRC_PORT,
126         ICE_FLOW_FIELD_IDX_TCP_DST_PORT,
127         ICE_FLOW_FIELD_IDX_UDP_SRC_PORT,
128         ICE_FLOW_FIELD_IDX_UDP_DST_PORT,
129         ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT,
130         ICE_FLOW_FIELD_IDX_SCTP_DST_PORT,
131         ICE_FLOW_FIELD_IDX_TCP_FLAGS,
132         /* ARP */
133         ICE_FLOW_FIELD_IDX_ARP_SIP,
134         ICE_FLOW_FIELD_IDX_ARP_DIP,
135         ICE_FLOW_FIELD_IDX_ARP_SHA,
136         ICE_FLOW_FIELD_IDX_ARP_DHA,
137         ICE_FLOW_FIELD_IDX_ARP_OP,
138         /* ICMP */
139         ICE_FLOW_FIELD_IDX_ICMP_TYPE,
140         ICE_FLOW_FIELD_IDX_ICMP_CODE,
141         /* GRE */
142         ICE_FLOW_FIELD_IDX_GRE_KEYID,
143         /* GTPC_TEID */
144         ICE_FLOW_FIELD_IDX_GTPC_TEID,
145         /* GTPU_IP */
146         ICE_FLOW_FIELD_IDX_GTPU_IP_TEID,
147         /* GTPU_UP */
148         ICE_FLOW_FIELD_IDX_GTPU_UP_TEID,
149         /* GTPU_DWN */
150         ICE_FLOW_FIELD_IDX_GTPU_DWN_TEID,
151         /* PPPOE */
152         ICE_FLOW_FIELD_IDX_PPPOE_SESS_ID,
153          /* The total number of enums must not exceed 64 */
154         ICE_FLOW_FIELD_IDX_MAX
155 };
156
157 /* Flow headers and fields for AVF support */
158 enum ice_flow_avf_hdr_field {
159         /* Values 0 - 28 are reserved for future use */
160         ICE_AVF_FLOW_FIELD_INVALID              = 0,
161         ICE_AVF_FLOW_FIELD_UNICAST_IPV4_UDP     = 29,
162         ICE_AVF_FLOW_FIELD_MULTICAST_IPV4_UDP,
163         ICE_AVF_FLOW_FIELD_IPV4_UDP,
164         ICE_AVF_FLOW_FIELD_IPV4_TCP_SYN_NO_ACK,
165         ICE_AVF_FLOW_FIELD_IPV4_TCP,
166         ICE_AVF_FLOW_FIELD_IPV4_SCTP,
167         ICE_AVF_FLOW_FIELD_IPV4_OTHER,
168         ICE_AVF_FLOW_FIELD_FRAG_IPV4,
169         ICE_AVF_FLOW_FIELD_UNICAST_IPV6_UDP     = 39,
170         ICE_AVF_FLOW_FIELD_MULTICAST_IPV6_UDP,
171         ICE_AVF_FLOW_FIELD_IPV6_UDP,
172         ICE_AVF_FLOW_FIELD_IPV6_TCP_SYN_NO_ACK,
173         ICE_AVF_FLOW_FIELD_IPV6_TCP,
174         ICE_AVF_FLOW_FIELD_IPV6_SCTP,
175         ICE_AVF_FLOW_FIELD_IPV6_OTHER,
176         ICE_AVF_FLOW_FIELD_FRAG_IPV6,
177         ICE_AVF_FLOW_FIELD_RSVD47,
178         ICE_AVF_FLOW_FIELD_FCOE_OX,
179         ICE_AVF_FLOW_FIELD_FCOE_RX,
180         ICE_AVF_FLOW_FIELD_FCOE_OTHER,
181         /* Values 51-62 are reserved */
182         ICE_AVF_FLOW_FIELD_L2_PAYLOAD           = 63,
183         ICE_AVF_FLOW_FIELD_MAX
184 };
185
186 /* Supported RSS offloads  This macro is defined to support
187  * VIRTCHNL_OP_GET_RSS_HENA_CAPS ops. PF driver sends the RSS hardware
188  * capabilities to the caller of this ops.
189  */
190 #define ICE_DEFAULT_RSS_HENA ( \
191         BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_UDP) | \
192         BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_SCTP) | \
193         BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_TCP) | \
194         BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_OTHER) | \
195         BIT_ULL(ICE_AVF_FLOW_FIELD_FRAG_IPV4) | \
196         BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_UDP) | \
197         BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_TCP) | \
198         BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_SCTP) | \
199         BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_OTHER) | \
200         BIT_ULL(ICE_AVF_FLOW_FIELD_FRAG_IPV6) | \
201         BIT_ULL(ICE_AVF_FLOW_FIELD_IPV4_TCP_SYN_NO_ACK) | \
202         BIT_ULL(ICE_AVF_FLOW_FIELD_UNICAST_IPV4_UDP) | \
203         BIT_ULL(ICE_AVF_FLOW_FIELD_MULTICAST_IPV4_UDP) | \
204         BIT_ULL(ICE_AVF_FLOW_FIELD_IPV6_TCP_SYN_NO_ACK) | \
205         BIT_ULL(ICE_AVF_FLOW_FIELD_UNICAST_IPV6_UDP) | \
206         BIT_ULL(ICE_AVF_FLOW_FIELD_MULTICAST_IPV6_UDP))
207
208 enum ice_flow_dir {
209         ICE_FLOW_DIR_UNDEFINED  = 0,
210         ICE_FLOW_TX             = 0x01,
211         ICE_FLOW_RX             = 0x02,
212         ICE_FLOW_TX_RX          = ICE_FLOW_RX | ICE_FLOW_TX
213 };
214
215 enum ice_flow_priority {
216         ICE_FLOW_PRIO_LOW,
217         ICE_FLOW_PRIO_NORMAL,
218         ICE_FLOW_PRIO_HIGH
219 };
220
221 #define ICE_FLOW_SEG_MAX                2
222 #define ICE_FLOW_SEG_RAW_FLD_MAX        2
223 #define ICE_FLOW_PROFILE_MAX            1024
224 #define ICE_FLOW_SW_FIELD_VECTOR_MAX    48
225 #define ICE_FLOW_ACL_FIELD_VECTOR_MAX   32
226 #define ICE_FLOW_FV_EXTRACT_SZ          2
227
228 #define ICE_FLOW_SET_HDRS(seg, val)     ((seg)->hdrs |= (u32)(val))
229
230 struct ice_flow_seg_xtrct {
231         u8 prot_id;     /* Protocol ID of extracted header field */
232         u16 off;        /* Starting offset of the field in header in bytes */
233         u8 idx;         /* Index of FV entry used */
234         u8 disp;        /* Displacement of field in bits fr. FV entry's start */
235 };
236
237 enum ice_flow_fld_match_type {
238         ICE_FLOW_FLD_TYPE_REG,          /* Value, mask */
239         ICE_FLOW_FLD_TYPE_RANGE,        /* Value, mask, last (upper bound) */
240         ICE_FLOW_FLD_TYPE_PREFIX,       /* IP address, prefix, size of prefix */
241         ICE_FLOW_FLD_TYPE_SIZE,         /* Value, mask, size of match */
242 };
243
244 struct ice_flow_fld_loc {
245         /* Describe offsets of field information relative to the beginning of
246          * input buffer provided when adding flow entries.
247          */
248         u16 val;        /* Offset where the value is located */
249         u16 mask;       /* Offset where the mask/prefix value is located */
250         u16 last;       /* Length or offset where the upper value is located */
251 };
252
253 struct ice_flow_fld_info {
254         enum ice_flow_fld_match_type type;
255         /* Location where to retrieve data from an input buffer */
256         struct ice_flow_fld_loc src;
257         /* Location where to put the data into the final entry buffer */
258         struct ice_flow_fld_loc entry;
259         struct ice_flow_seg_xtrct xtrct;
260 };
261
262 struct ice_flow_seg_fld_raw {
263         int off;        /* Offset from the start of the segment */
264         struct ice_flow_fld_info info;
265 };
266
267 struct ice_flow_seg_info {
268         u32 hdrs;       /* Bitmask indicating protocol headers present */
269         u64 match;      /* Bitmask indicating header fields to be matched */
270         u64 range;      /* Bitmask indicating header fields matched as ranges */
271
272         struct ice_flow_fld_info fields[ICE_FLOW_FIELD_IDX_MAX];
273
274         u8 raws_cnt;    /* Number of raw fields to be matched */
275         struct ice_flow_seg_fld_raw raws[ICE_FLOW_SEG_RAW_FLD_MAX];
276 };
277
278 /* This structure describes a flow entry, and is tracked only in this file */
279 struct ice_flow_entry {
280         struct LIST_ENTRY_TYPE l_entry;
281
282         u64 id;
283         struct ice_flow_prof *prof;
284         /* Action list */
285         struct ice_flow_action *acts;
286         /* Flow entry's content */
287         void *entry;
288         enum ice_flow_priority priority;
289         u16 vsi_handle;
290         u16 entry_sz;
291         u8 acts_cnt;
292 };
293
294 #define ICE_FLOW_ENTRY_HNDL(e)  ((unsigned long)e)
295 #define ICE_FLOW_ENTRY_PTR(h)   ((struct ice_flow_entry *)(h))
296
297 struct ice_flow_prof {
298         struct LIST_ENTRY_TYPE l_entry;
299
300         u64 id;
301         enum ice_flow_dir dir;
302         u8 segs_cnt;
303         u8 acts_cnt;
304
305         /* Keep track of flow entries associated with this flow profile */
306         struct ice_lock entries_lock;
307         struct LIST_HEAD_TYPE entries;
308
309         struct ice_flow_seg_info segs[ICE_FLOW_SEG_MAX];
310
311         /* software VSI handles referenced by this flow profile */
312         ice_declare_bitmap(vsis, ICE_MAX_VSI);
313
314         union {
315                 /* struct sw_recipe */
316                 /* struct fd */
317                 u32 data;
318                 /* Symmetric Hash for RSS */
319                 bool symm;
320         } cfg;
321
322         /* Default actions */
323         struct ice_flow_action *acts;
324 };
325
326 struct ice_rss_cfg {
327         struct LIST_ENTRY_TYPE l_entry;
328         /* bitmap of VSIs added to the RSS entry */
329         ice_declare_bitmap(vsis, ICE_MAX_VSI);
330         u64 hashed_flds;
331         u32 packet_hdr;
332         bool symm;
333 };
334
335 enum ice_flow_action_type {
336         ICE_FLOW_ACT_NOP,
337         ICE_FLOW_ACT_ALLOW,
338         ICE_FLOW_ACT_DROP,
339         ICE_FLOW_ACT_CNTR_PKT,
340         ICE_FLOW_ACT_FWD_VSI,
341         ICE_FLOW_ACT_FWD_VSI_LIST,      /* Should be abstracted away */
342         ICE_FLOW_ACT_FWD_QUEUE,         /* Can Queues be abstracted away? */
343         ICE_FLOW_ACT_FWD_QUEUE_GROUP,   /* Can Queues be abstracted away? */
344         ICE_FLOW_ACT_PUSH,
345         ICE_FLOW_ACT_POP,
346         ICE_FLOW_ACT_MODIFY,
347         ICE_FLOW_ACT_CNTR_BYTES,
348         ICE_FLOW_ACT_CNTR_PKT_BYTES,
349         ICE_FLOW_ACT_GENERIC_0,
350         ICE_FLOW_ACT_GENERIC_1,
351         ICE_FLOW_ACT_GENERIC_2,
352         ICE_FLOW_ACT_GENERIC_3,
353         ICE_FLOW_ACT_GENERIC_4,
354         ICE_FLOW_ACT_RPT_FLOW_ID,
355         ICE_FLOW_ACT_BUILD_PROF_IDX,
356 };
357
358 struct ice_flow_action {
359         enum ice_flow_action_type type;
360         union {
361                 u32 dummy;
362         } data;
363 };
364
365 u64
366 ice_flow_find_prof(struct ice_hw *hw, enum ice_block blk, enum ice_flow_dir dir,
367                    struct ice_flow_seg_info *segs, u8 segs_cnt);
368 enum ice_status
369 ice_flow_add_prof(struct ice_hw *hw, enum ice_block blk, enum ice_flow_dir dir,
370                   u64 prof_id, struct ice_flow_seg_info *segs, u8 segs_cnt,
371                   struct ice_flow_action *acts, u8 acts_cnt,
372                   struct ice_flow_prof **prof);
373 enum ice_status
374 ice_flow_rem_prof(struct ice_hw *hw, enum ice_block blk, u64 prof_id);
375 enum ice_status
376 ice_flow_assoc_vsig_vsi(struct ice_hw *hw, enum ice_block blk, u16 vsi_handle,
377                         u16 vsig);
378 enum ice_status
379 ice_flow_get_hw_prof(struct ice_hw *hw, enum ice_block blk, u64 prof_id,
380                      u8 *hw_prof);
381
382 u64 ice_flow_find_entry(struct ice_hw *hw, enum ice_block blk, u64 entry_id);
383 enum ice_status
384 ice_flow_add_entry(struct ice_hw *hw, enum ice_block blk, u64 prof_id,
385                    u64 entry_id, u16 vsi, enum ice_flow_priority prio,
386                    void *data, struct ice_flow_action *acts, u8 acts_cnt,
387                    u64 *entry_h);
388 enum ice_status ice_flow_rem_entry(struct ice_hw *hw, u64 entry_h);
389 void
390 ice_flow_set_fld(struct ice_flow_seg_info *seg, enum ice_flow_field fld,
391                  u16 val_loc, u16 mask_loc, u16 last_loc, bool range);
392 void
393 ice_flow_set_fld_prefix(struct ice_flow_seg_info *seg, enum ice_flow_field fld,
394                         u16 val_loc, u16 prefix_loc, u8 prefix_sz);
395 void
396 ice_flow_add_fld_raw(struct ice_flow_seg_info *seg, u16 off, u8 len,
397                      u16 val_loc, u16 mask_loc);
398 void ice_rem_vsi_rss_list(struct ice_hw *hw, u16 vsi_handle);
399 enum ice_status ice_replay_rss_cfg(struct ice_hw *hw, u16 vsi_handle);
400 enum ice_status
401 ice_add_avf_rss_cfg(struct ice_hw *hw, u16 vsi_handle, u64 hashed_flds);
402 enum ice_status ice_rem_vsi_rss_cfg(struct ice_hw *hw, u16 vsi_handle);
403 enum ice_status
404 ice_add_rss_cfg(struct ice_hw *hw, u16 vsi_handle, u64 hashed_flds,
405                 u32 addl_hdrs, bool symm);
406 enum ice_status
407 ice_rem_rss_cfg(struct ice_hw *hw, u16 vsi_handle, u64 hashed_flds,
408                 u32 addl_hdrs);
409 u64 ice_get_rss_cfg(struct ice_hw *hw, u16 vsi_handle, u32 hdrs);
410 #endif /* _ICE_FLOW_H_ */