net/enic: add flow implementation based on Flow Manager API
[dpdk.git] / drivers / net / enic / base / vnic_flowman.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2018-2019 Cisco Systems, Inc.  All rights reserved.
3  */
4 #ifndef _VNIC_FLOWMAN_H_
5 #define _VNIC_FLOWMAN_H_
6
7 /* This file contains Flow Manager (FM) API of the firmware */
8
9 /* Flow manager sub-ops */
10 enum {
11         FM_EXACT_TABLE_ALLOC,
12         FM_TCAM_TABLE_ALLOC,
13         FM_MATCH_TABLE_FREE,
14         FM_COUNTER_BRK,
15         FM_COUNTER_QUERY,
16         FM_COUNTER_CLEAR_ALL,
17         FM_COUNTER_DMA,
18         FM_ACTION_ALLOC,
19         FM_ACTION_FREE,
20         FM_EXACT_ENTRY_INSTALL,
21         FM_TCAM_ENTRY_INSTALL,
22         FM_MATCH_ENTRY_REMOVE,
23         FM_VNIC_FIND,
24         FM_API_VERSION_QUERY,
25         FM_API_VERSION_SELECT,
26         FM_INFO_QUERY
27 };
28
29 /*
30  * FKM (flow key metadata) flags used to match packet metadata
31  * (e.g. packet is tcp)
32  */
33 #define FKM_BITS                \
34         FBIT(FKM_QTAG)          \
35         FBIT(FKM_CMD)           \
36         FBIT(FKM_IPV4)          \
37         FBIT(FKM_IPV6)          \
38         FBIT(FKM_ROCE)          \
39         FBIT(FKM_UDP)           \
40         FBIT(FKM_TCP)           \
41         FBIT(FKM_TCPORUDP)      \
42         FBIT(FKM_IPFRAG)        \
43         FBIT(FKM_NVGRE)         \
44         FBIT(FKM_VXLAN)         \
45         FBIT(FKM_GENEVE)        \
46         FBIT(FKM_NSH)           \
47         FBIT(FKM_ROCEV2)        \
48         FBIT(FKM_VLAN_PRES)     \
49         FBIT(FKM_IPOK)          \
50         FBIT(FKM_L4OK)          \
51         FBIT(FKM_ROCEOK)        \
52         FBIT(FKM_FCSOK)         \
53         FBIT(FKM_EG_SPAN)       \
54         FBIT(FKM_IG_SPAN)       \
55         FBIT(FKM_EG_HAIRPINNED)
56
57 /*
58  * FKH (flow key header) flags.
59  * This selects which headers are valid in the struct.
60  * This is distinct from metadata in that metadata is requesting actual
61  * selection criteria.  If, for example, a TCAM match with metadata "FKM_UDP"
62  * is feeding into an exact match table, there may be no need for the
63  * exact match table to also specify FKM_UDP, so FKH_UDP is used to
64  * specify that the UDP header fields should be used in the match.
65  */
66 #define FKH_BITS        \
67         FBIT(FKH_ETHER) \
68         FBIT(FKH_QTAG)  \
69         FBIT(FKH_L2RAW) \
70         FBIT(FKH_IPV4)  \
71         FBIT(FKH_IPV6)  \
72         FBIT(FKH_L3RAW) \
73         FBIT(FKH_UDP)   \
74         FBIT(FKH_TCP)   \
75         FBIT(FKH_ICMP)  \
76         FBIT(FKH_VXLAN) \
77         FBIT(FKH_L4RAW)
78
79 #define FBIT(X) X##_BIT,
80 enum {
81         FKM_BITS
82         FKM_BIT_COUNT
83 };
84
85 enum {
86         FKH_BITS
87         FKH_BIT_COUNT
88 };
89 #undef FBIT
90 #define FBIT(X) X = (1 << X##_BIT),
91 enum {
92         FKM_BITS
93 };
94 enum {
95         FKH_BITS
96 };
97 #undef FBIT
98
99 #define FM_ETH_ALEN 6
100 #define FM_LAYER_SIZE 64
101
102 /* Header match pattern */
103 struct fm_header_set {
104         uint32_t fk_metadata;       /* FKM flags */
105         uint32_t fk_header_select;  /* FKH flags */
106         uint16_t fk_vlan;
107         /* L2: Ethernet Header (valid if FKH_ETHER) */
108         union {
109                 struct {
110                         uint8_t fk_dstmac[FM_ETH_ALEN];
111                         uint8_t fk_srcmac[FM_ETH_ALEN];
112                         uint16_t fk_ethtype;
113                 } __rte_packed eth;
114                 uint8_t rawdata[FM_LAYER_SIZE];
115         } __rte_packed l2;
116         /* L3: IPv4 or IPv6 (valid if FKH_IPV4,6) */
117         union {
118                 /* Valid if FKH_IPV4 */
119                 struct {
120                         uint8_t fk_ihl_vers;
121                         uint8_t fk_tos;
122                         uint16_t fk_tot_len;
123                         uint16_t fk_id;
124                         uint16_t fk_frag_off;
125                         uint8_t fk_ttl;
126                         uint8_t fk_proto;
127                         uint16_t fk_check;
128                         uint32_t fk_saddr;
129                         uint32_t fk_daddr;
130                 } __rte_packed ip4;
131                 /* Valid if FKH_IPV6 */
132                 struct {
133                         union {
134                                 struct {
135                                         uint32_t fk_un1_flow;
136                                         uint16_t fk_un1_plen;
137                                         uint8_t fk_un1_nxt;
138                                         uint8_t fk_un1_hlim;
139                                 } unl;
140                                 uint8_t fk_un2_vfc;
141                         } ctl;
142                         uint8_t fk_srcip[16];
143                         uint8_t fk_dstip[16];
144                 } __rte_packed ip6;
145                 uint8_t rawdata[FM_LAYER_SIZE];
146         } __rte_packed l3;
147         /* L4: UDP, TCP, or ICMP (valid if FKH_UDP,TCP,ICMP) */
148         union {
149                 struct {
150                         uint16_t fk_source;
151                         uint16_t fk_dest;
152                         uint16_t fk_len;
153                         uint16_t fk_check;
154                 } __rte_packed udp;
155                 struct {
156                         uint16_t fk_source;
157                         uint16_t fk_dest;
158                         uint32_t fk_seq;
159                         uint32_t fk_ack_seq;
160                         uint16_t fk_flags;
161                         uint16_t fk_window;
162                         uint16_t fk_check;
163                         uint16_t fk_urg_ptr;
164                 } __rte_packed tcp;
165                 struct {
166                         uint8_t fk_code;
167                         uint8_t fk_type;
168                 } __rte_packed icmp;
169                 uint8_t rawdata[FM_LAYER_SIZE];
170         } __rte_packed l4;
171         /* VXLAN (valid if FKH_VXLAN) */
172         struct {
173                 uint8_t fkvx_flags;
174                 uint8_t fkvx_res0[3];
175                 uint8_t fkvx_vni[3];
176                 uint8_t fkvx_res1;
177         } __rte_packed vxlan;
178         /* Payload or unknown inner-most protocol */
179         uint8_t fk_l5_data[64];
180 } __rte_packed;
181
182 /*
183  * FK (flow key) template.
184  * fk_hdrset specifies a set of headers per layer of encapsulation.
185  * Currently FM supports two header sets: outer (0) and inner(1)
186  */
187 #define FM_HDRSET_MAX 2
188
189 struct fm_key_template {
190         struct fm_header_set fk_hdrset[FM_HDRSET_MAX];
191         uint32_t fk_flags;
192         uint16_t fk_packet_tag;
193         uint16_t fk_packet_size;
194         uint16_t fk_port_id;
195         uint32_t fk_wq_id;    /* WQ index */
196         uint64_t fk_wq_vnic;  /* VNIC handle for WQ index */
197 } __rte_packed;
198
199 /* Action operation types */
200 enum {
201         FMOP_NOP = 0,
202         /* End the action chain. */
203         FMOP_END,
204         /* Drop packet and end the action chain. */
205         FMOP_DROP,
206         /* Steer packet to an RQ. */
207         FMOP_RQ_STEER,
208         /*
209          * Jump to an exact match table.
210          * arg1: exact match table handle
211          */
212         FMOP_EXACT_MATCH,
213         /* Apply CQ-visible mark on packet. Mark is written to RSS HASH. */
214         FMOP_MARK,
215         /*
216          * Apply CQ-visible mark on packet. Mark is written to a field in
217          * extended CQ. RSS HASH is preserved.
218          */
219         FMOP_EXT_MARK,
220         /*
221          * Apply internal tag which can be matched in subsequent
222          * stages or hairpin.
223          */
224         FMOP_TAG,
225         /* Hairpin packet from EG -> IG */
226         FMOP_EG_HAIRPIN,
227         /* Hairpin packet from IG -> EG */
228         FMOP_IG_HAIRPIN,
229         /* Encap with VXLAN and inner VLAN from metadata. */
230         FMOP_ENCAP_IVLAN,
231         /* Encap, no inner VLAN. */
232         FMOP_ENCAP_NOIVLAN,
233         /* Encap, add inner VLAN if present. */
234         FMOP_ENCAP,
235         /* Set outer VLAN. */
236         FMOP_SET_OVLAN,
237         /* Decap when vlan_strip is off */
238         FMOP_DECAP_NOSTRIP,
239         FMOP_OP_MAX,
240 };
241
242 /*
243  * Action operation.
244  * Complex actions are achieved by a series of "transform operations"
245  * We can have complex transform operations like "decap" or "vxlan
246  * encap" and also simple ops like insert this data, add PACKET_LEN to
247  * this address, etc.
248  */
249 struct fm_action_op {
250         uint32_t fa_op;         /* FMOP flags */
251
252         union {
253                 struct {
254                         uint8_t len1_offset;
255                         uint8_t len1_delta;
256                         uint8_t len2_offset;
257                         uint8_t len2_delta;
258                         uint16_t outer_vlan;
259                         uint8_t template_offset;
260                         uint8_t template_len;
261                 } __rte_packed encap;
262                 struct {
263                         uint32_t rq_index;
264                         uint64_t vnic_handle;
265                 } __rte_packed rq_steer;
266                 struct {
267                         uint16_t vlan;
268                 } __rte_packed ovlan;
269                 struct {
270                         uint16_t mark;
271                 } __rte_packed mark;
272                 struct {
273                         uint32_t ext_mark;
274                 } __rte_packed ext_mark;
275                 struct {
276                         uint8_t tag;
277                 } __rte_packed tag;
278                 struct {
279                         uint64_t handle;
280                 } __rte_packed exact;
281         } __rte_packed;
282 } __rte_packed;
283
284 #define FM_ACTION_OP_MAX 64
285 #define FM_ACTION_DATA_MAX 96
286
287 /*
288  * Action is a series of action operations applied to matched
289  * packet. FMA (flowman action).
290  */
291 struct fm_action {
292         struct fm_action_op fma_action_ops[FM_ACTION_OP_MAX];
293         uint8_t fma_data[FM_ACTION_DATA_MAX];
294 } __rte_packed;
295
296 /* Match entry flags. FMEF (flow match entry flag) */
297 #define FMEF_COUNTER    0x0001  /* counter index is valid */
298
299 /* FEM (flow exact match) entry */
300 struct fm_exact_match_entry {
301         struct fm_key_template fem_data;  /* Match data. Mask is per table */
302         uint32_t fem_flags;               /* FMEF_xxx */
303         uint64_t fem_action;              /* Action handle */
304         uint32_t fem_counter;             /* Counter index */
305 } __rte_packed;
306
307 /* FTM (flow TCAM match) entry */
308 struct fm_tcam_match_entry {
309         struct fm_key_template ftm_mask;  /* Key mask */
310         struct fm_key_template ftm_data;  /* Match data */
311         uint32_t ftm_flags;               /* FMEF_xxx */
312         uint32_t ftm_position;            /* Entry position */
313         uint64_t ftm_action;              /* Action handle */
314         uint32_t ftm_counter;             /* Counter index */
315 } __rte_packed;
316
317 /* Match directions */
318 enum {
319         FM_INGRESS,
320         FM_EGRESS,
321         FM_DIR_CNT
322 };
323
324 /* Last stage ID, independent of the number of stages in hardware */
325 #define FM_STAGE_LAST 0xff
326
327 /* Hash based exact match table. FET (flow exact match table) */
328 struct fm_exact_match_table {
329         uint8_t fet_direction; /* FM_INGRESS or EGRESS*/
330         uint8_t fet_stage;
331         uint8_t pad[2];
332         uint32_t fet_max_entries;
333         uint64_t fet_dflt_action;
334         struct fm_key_template fet_key;
335 } __rte_packed;
336
337 /* TCAM based match table. FTT (flow TCAM match table) */
338 struct fm_tcam_match_table {
339         uint8_t ftt_direction;
340         uint8_t ftt_stage;
341         uint8_t pad[2];
342         uint32_t ftt_max_entries;
343 } __rte_packed;
344
345 struct fm_counter_counts {
346         uint64_t fcc_packets;
347         uint64_t fcc_bytes;
348 } __rte_packed;
349
350 /*
351  * Return structure for FM_INFO_QUERY devcmd
352  */
353 #define FM_VERSION 1            /* This header file is for version 1 */
354
355 struct fm_info {
356         uint64_t fm_op_mask;            /* Bitmask of action supported ops */
357         uint64_t fm_current_ts;         /* Current VIC timestamp */
358         uint64_t fm_clock_freq;         /* Timestamp clock frequency */
359         uint16_t fm_max_ops;            /* Max ops in an action */
360         uint8_t fm_stages;              /* Number of match-action stages */
361         uint8_t pad[5];
362         uint32_t fm_counter_count;      /* Number of allocated counters */
363 } __rte_packed;
364
365 #endif /* _VNIC_FLOWMAN_H_ */