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