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