avf: add avf flow framework
[vpp.git] / src / plugins / avf / avf_advanced_flow.h
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2020 Intel and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17
18 #ifndef _AVF_ADVANCED_FLOW_H_
19 #define _AVF_ADVANCED_FLOW_H_
20
21 #define AVF_SUCCESS (0)
22 #define AVF_FAILURE (-1)
23
24 #define BIT(a)     (1UL << (a))
25 #define BIT_ULL(a) (1ULL << (a))
26
27 /* These macros are used to generate compilation errors if a structure/union
28  * is not exactly the correct length. It gives a divide by zero error if the
29  * structure/union is not of the correct size, otherwise it creates an enum
30  * that is never used.
31  */
32 #define VIRTCHNL_CHECK_STRUCT_LEN(n, X)                                       \
33   enum virtchnl_static_assert_enum_##X                                        \
34   {                                                                           \
35     virtchnl_static_assert_##X = (n) / ((sizeof (struct X) == (n)) ? 1 : 0)   \
36   }
37 #define VIRTCHNL_CHECK_UNION_LEN(n, X)                                        \
38   enum virtchnl_static_asset_enum_##X                                         \
39   {                                                                           \
40     virtchnl_static_assert_##X = (n) / ((sizeof (union X) == (n)) ? 1 : 0)    \
41   }
42
43 /* AVF ethernet frame types */
44 #define AVF_ETHER_TYPE_IPV4 0x0800 /**< IPv4 Protocol. */
45 #define AVF_ETHER_TYPE_IPV6 0x86DD /**< IPv6 Protocol. */
46
47 #define VIRTCHNL_MAX_NUM_PROTO_HDRS 32
48 #define PROTO_HDR_SHIFT             5
49 #define PROTO_HDR_FIELD_START(proto_hdr_type)                                 \
50   (proto_hdr_type << PROTO_HDR_SHIFT)
51 #define PROTO_HDR_FIELD_MASK ((1UL << PROTO_HDR_SHIFT) - 1)
52
53 /* VF use these macros to configure each protocol header.
54  * Specify which protocol headers and protocol header fields base on
55  * virtchnl_proto_hdr_type and virtchnl_proto_hdr_field.
56  * @param hdr: a struct of virtchnl_proto_hdr
57  * @param hdr_type: ETH/IPV4/TCP, etc
58  * @param field: SRC/DST/TEID/SPI, etc
59  */
60 #define VIRTCHNL_ADD_PROTO_HDR_FIELD(hdr, field)                              \
61   ((hdr)->field_selector |= BIT ((field) &PROTO_HDR_FIELD_MASK))
62 #define VIRTCHNL_DEL_PROTO_HDR_FIELD(hdr, field)                              \
63   ((hdr)->field_selector &= ~BIT ((field) &PROTO_HDR_FIELD_MASK))
64 #define VIRTCHNL_TEST_PROTO_HDR_FIELD(hdr, val)                               \
65   ((hdr)->field_selector & BIT ((val) &PROTO_HDR_FIELD_MASK))
66 #define VIRTCHNL_GET_PROTO_HDR_FIELD(hdr) ((hdr)->field_selector)
67
68 #define VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, hdr_type, field)                \
69   (VIRTCHNL_ADD_PROTO_HDR_FIELD (hdr, VIRTCHNL_PROTO_HDR_##hdr_type##_##field))
70 #define VIRTCHNL_DEL_PROTO_HDR_FIELD_BIT(hdr, hdr_type, field)                \
71   (VIRTCHNL_DEL_PROTO_HDR_FIELD (hdr, VIRTCHNL_PROTO_HDR_##hdr_type##_##field))
72
73 #define VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, hdr_type)                            \
74   ((hdr)->type = VIRTCHNL_PROTO_HDR_##hdr_type)
75 #define VIRTCHNL_GET_PROTO_HDR_TYPE(hdr) (((hdr)->type) >> PROTO_HDR_SHIFT)
76 #define VIRTCHNL_TEST_PROTO_HDR_TYPE(hdr, val)                                \
77   ((hdr)->type == ((val) >> PROTO_HDR_SHIFT))
78 #define VIRTCHNL_TEST_PROTO_HDR(hdr, val)                                     \
79   (VIRTCHNL_TEST_PROTO_HDR_TYPE (hdr, val) &&                                 \
80    VIRTCHNL_TEST_PROTO_HDR_FIELD (hdr, val))
81
82 /* protocol */
83
84 #define AVF_PROT_MAC_INNER   (1ULL << 1)
85 #define AVF_PROT_MAC_OUTER   (1ULL << 2)
86 #define AVF_PROT_VLAN_INNER  (1ULL << 3)
87 #define AVF_PROT_VLAN_OUTER  (1ULL << 4)
88 #define AVF_PROT_IPV4_INNER  (1ULL << 5)
89 #define AVF_PROT_IPV4_OUTER  (1ULL << 6)
90 #define AVF_PROT_IPV6_INNER  (1ULL << 7)
91 #define AVF_PROT_IPV6_OUTER  (1ULL << 8)
92 #define AVF_PROT_TCP_INNER   (1ULL << 9)
93 #define AVF_PROT_TCP_OUTER   (1ULL << 10)
94 #define AVF_PROT_UDP_INNER   (1ULL << 11)
95 #define AVF_PROT_UDP_OUTER   (1ULL << 12)
96 #define AVF_PROT_SCTP_INNER  (1ULL << 13)
97 #define AVF_PROT_SCTP_OUTER  (1ULL << 14)
98 #define AVF_PROT_ICMP4_INNER (1ULL << 15)
99 #define AVF_PROT_ICMP4_OUTER (1ULL << 16)
100 #define AVF_PROT_ICMP6_INNER (1ULL << 17)
101 #define AVF_PROT_ICMP6_OUTER (1ULL << 18)
102 #define AVF_PROT_VXLAN       (1ULL << 19)
103 #define AVF_PROT_NVGRE       (1ULL << 20)
104 #define AVF_PROT_GTPU        (1ULL << 21)
105 #define AVF_PROT_ESP         (1ULL << 22)
106 #define AVF_PROT_AH          (1ULL << 23)
107 #define AVF_PROT_L2TPV3OIP   (1ULL << 24)
108 #define AVF_PROT_PFCP        (1ULL << 25)
109
110 /* field */
111
112 #define AVF_SMAC                 (1ULL << 63)
113 #define AVF_DMAC                 (1ULL << 62)
114 #define AVF_ETHERTYPE            (1ULL << 61)
115 #define AVF_IP_SRC               (1ULL << 60)
116 #define AVF_IP_DST               (1ULL << 59)
117 #define AVF_IP_PROTO             (1ULL << 58)
118 #define AVF_IP_TTL               (1ULL << 57)
119 #define AVF_IP_TOS               (1ULL << 56)
120 #define AVF_SPORT                (1ULL << 55)
121 #define AVF_DPORT                (1ULL << 54)
122 #define AVF_ICMP_TYPE            (1ULL << 53)
123 #define AVF_ICMP_CODE            (1ULL << 52)
124 #define AVF_VXLAN_VNI            (1ULL << 51)
125 #define AVF_NVGRE_TNI            (1ULL << 50)
126 #define AVF_GTPU_TEID            (1ULL << 49)
127 #define AVF_GTPU_QFI             (1ULL << 48)
128 #define AVF_ESP_SPI              (1ULL << 47)
129 #define AVF_AH_SPI               (1ULL << 46)
130 #define AVF_L2TPV3OIP_SESSION_ID (1ULL << 45)
131 #define AVF_PFCP_S_FIELD         (1ULL << 44)
132 #define AVF_PFCP_SEID            (1ULL << 43)
133
134 /* input set */
135
136 #define AVF_INSET_NONE 0ULL
137
138 /* non-tunnel */
139
140 #define AVF_INSET_SMAC       (AVF_PROT_MAC_OUTER | AVF_SMAC)
141 #define AVF_INSET_DMAC       (AVF_PROT_MAC_OUTER | AVF_DMAC)
142 #define AVF_INSET_VLAN_INNER (AVF_PROT_VLAN_INNER)
143 #define AVF_INSET_VLAN_OUTER (AVF_PROT_VLAN_OUTER)
144 #define AVF_INSET_ETHERTYPE  (AVF_ETHERTYPE)
145
146 #define AVF_INSET_IPV4_SRC       (AVF_PROT_IPV4_OUTER | AVF_IP_SRC)
147 #define AVF_INSET_IPV4_DST       (AVF_PROT_IPV4_OUTER | AVF_IP_DST)
148 #define AVF_INSET_IPV4_TOS       (AVF_PROT_IPV4_OUTER | AVF_IP_TOS)
149 #define AVF_INSET_IPV4_PROTO     (AVF_PROT_IPV4_OUTER | AVF_IP_PROTO)
150 #define AVF_INSET_IPV4_TTL       (AVF_PROT_IPV4_OUTER | AVF_IP_TTL)
151 #define AVF_INSET_IPV6_SRC       (AVF_PROT_IPV6_OUTER | AVF_IP_SRC)
152 #define AVF_INSET_IPV6_DST       (AVF_PROT_IPV6_OUTER | AVF_IP_DST)
153 #define AVF_INSET_IPV6_NEXT_HDR  (AVF_PROT_IPV6_OUTER | AVF_IP_PROTO)
154 #define AVF_INSET_IPV6_HOP_LIMIT (AVF_PROT_IPV6_OUTER | AVF_IP_TTL)
155 #define AVF_INSET_IPV6_TC        (AVF_PROT_IPV6_OUTER | AVF_IP_TOS)
156
157 #define AVF_INSET_TCP_SRC_PORT   (AVF_PROT_TCP_OUTER | AVF_SPORT)
158 #define AVF_INSET_TCP_DST_PORT   (AVF_PROT_TCP_OUTER | AVF_DPORT)
159 #define AVF_INSET_UDP_SRC_PORT   (AVF_PROT_UDP_OUTER | AVF_SPORT)
160 #define AVF_INSET_UDP_DST_PORT   (AVF_PROT_UDP_OUTER | AVF_DPORT)
161 #define AVF_INSET_SCTP_SRC_PORT  (AVF_PROT_SCTP_OUTER | AVF_SPORT)
162 #define AVF_INSET_SCTP_DST_PORT  (AVF_PROT_SCTP_OUTER | AVF_DPORT)
163 #define AVF_INSET_ICMP4_SRC_PORT (AVF_PROT_ICMP4_OUTER | AVF_SPORT)
164 #define AVF_INSET_ICMP4_DST_PORT (AVF_PROT_ICMP4_OUTER | AVF_DPORT)
165 #define AVF_INSET_ICMP6_SRC_PORT (AVF_PROT_ICMP6_OUTER | AVF_SPORT)
166 #define AVF_INSET_ICMP6_DST_PORT (AVF_PROT_ICMP6_OUTER | AVF_DPORT)
167 #define AVF_INSET_ICMP4_TYPE     (AVF_PROT_ICMP4_OUTER | AVF_ICMP_TYPE)
168 #define AVF_INSET_ICMP4_CODE     (AVF_PROT_ICMP4_OUTER | AVF_ICMP_CODE)
169 #define AVF_INSET_ICMP6_TYPE     (AVF_PROT_ICMP6_OUTER | AVF_ICMP_TYPE)
170 #define AVF_INSET_ICMP6_CODE     (AVF_PROT_ICMP6_OUTER | AVF_ICMP_CODE)
171 #define AVF_INSET_GTPU_TEID      (AVF_PROT_GTPU | AVF_GTPU_TEID)
172 #define AVF_INSET_GTPU_QFI       (AVF_PROT_GTPU | AVF_GTPU_QFI)
173 #define AVF_INSET_ESP_SPI        (AVF_PROT_ESP | AVF_ESP_SPI)
174 #define AVF_INSET_AH_SPI         (AVF_PROT_AH | AVF_AH_SPI)
175 #define AVF_INSET_L2TPV3OIP_SESSION_ID                                        \
176   (AVF_PROT_L2TPV3OIP | AVF_L2TPV3OIP_SESSION_ID)
177 #define AVF_INSET_PFCP_S_FIELD (AVF_PROT_PFCP | AVF_PFCP_S_FIELD)
178 #define AVF_INSET_PFCP_SEID    (AVF_PROT_PFCP | AVF_PFCP_S_FIELD | AVF_PFCP_SEID)
179
180 /* Protocol header type within a packet segment. A segment consists of one or
181  * more protocol headers that make up a logical group of protocol headers. Each
182  * logical group of protocol headers encapsulates or is encapsulated using/by
183  * tunneling or encapsulation protocols for network virtualization.
184  */
185 enum virtchnl_proto_hdr_type
186 {
187   VIRTCHNL_PROTO_HDR_NONE,
188   VIRTCHNL_PROTO_HDR_ETH,
189   VIRTCHNL_PROTO_HDR_S_VLAN,
190   VIRTCHNL_PROTO_HDR_C_VLAN,
191   VIRTCHNL_PROTO_HDR_IPV4,
192   VIRTCHNL_PROTO_HDR_IPV6,
193   VIRTCHNL_PROTO_HDR_TCP,
194   VIRTCHNL_PROTO_HDR_UDP,
195   VIRTCHNL_PROTO_HDR_SCTP,
196   VIRTCHNL_PROTO_HDR_GTPU_IP,
197   VIRTCHNL_PROTO_HDR_GTPU_EH,
198   VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_DWN,
199   VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_UP,
200   VIRTCHNL_PROTO_HDR_PPPOE,
201   VIRTCHNL_PROTO_HDR_L2TPV3,
202   VIRTCHNL_PROTO_HDR_ESP,
203   VIRTCHNL_PROTO_HDR_AH,
204   VIRTCHNL_PROTO_HDR_PFCP,
205 };
206
207 /* Protocol header field within a protocol header. */
208 enum virtchnl_proto_hdr_field
209 {
210   /* ETHER */
211   VIRTCHNL_PROTO_HDR_ETH_SRC = PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_ETH),
212   VIRTCHNL_PROTO_HDR_ETH_DST,
213   VIRTCHNL_PROTO_HDR_ETH_ETHERTYPE,
214   /* S-VLAN */
215   VIRTCHNL_PROTO_HDR_S_VLAN_ID =
216     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_S_VLAN),
217   /* C-VLAN */
218   VIRTCHNL_PROTO_HDR_C_VLAN_ID =
219     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_C_VLAN),
220   /* IPV4 */
221   VIRTCHNL_PROTO_HDR_IPV4_SRC =
222     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_IPV4),
223   VIRTCHNL_PROTO_HDR_IPV4_DST,
224   VIRTCHNL_PROTO_HDR_IPV4_DSCP,
225   VIRTCHNL_PROTO_HDR_IPV4_TTL,
226   VIRTCHNL_PROTO_HDR_IPV4_PROT,
227   /* IPV6 */
228   VIRTCHNL_PROTO_HDR_IPV6_SRC =
229     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_IPV6),
230   VIRTCHNL_PROTO_HDR_IPV6_DST,
231   VIRTCHNL_PROTO_HDR_IPV6_TC,
232   VIRTCHNL_PROTO_HDR_IPV6_HOP_LIMIT,
233   VIRTCHNL_PROTO_HDR_IPV6_PROT,
234   /* TCP */
235   VIRTCHNL_PROTO_HDR_TCP_SRC_PORT =
236     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_TCP),
237   VIRTCHNL_PROTO_HDR_TCP_DST_PORT,
238   /* UDP */
239   VIRTCHNL_PROTO_HDR_UDP_SRC_PORT =
240     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_UDP),
241   VIRTCHNL_PROTO_HDR_UDP_DST_PORT,
242   /* SCTP */
243   VIRTCHNL_PROTO_HDR_SCTP_SRC_PORT =
244     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_SCTP),
245   VIRTCHNL_PROTO_HDR_SCTP_DST_PORT,
246   /* GTPU_IP */
247   VIRTCHNL_PROTO_HDR_GTPU_IP_TEID =
248     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_GTPU_IP),
249   /* GTPU_EH */
250   VIRTCHNL_PROTO_HDR_GTPU_EH_PDU =
251     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_GTPU_EH),
252   VIRTCHNL_PROTO_HDR_GTPU_EH_QFI,
253   /* PPPOE */
254   VIRTCHNL_PROTO_HDR_PPPOE_SESS_ID =
255     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_PPPOE),
256   /* L2TPV3 */
257   VIRTCHNL_PROTO_HDR_L2TPV3_SESS_ID =
258     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_L2TPV3),
259   /* ESP */
260   VIRTCHNL_PROTO_HDR_ESP_SPI = PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_ESP),
261   /* AH */
262   VIRTCHNL_PROTO_HDR_AH_SPI = PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_AH),
263   /* PFCP */
264   VIRTCHNL_PROTO_HDR_PFCP_S_FIELD =
265     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_PFCP),
266   VIRTCHNL_PROTO_HDR_PFCP_SEID,
267 };
268
269 struct virtchnl_proto_hdr
270 {
271   enum virtchnl_proto_hdr_type type;
272   u32 field_selector; /* a bit mask to select field for header type */
273   u8 buffer[64];
274   /**
275    * binary buffer in network order for specific header type.
276    * For example, if type = VIRTCHNL_PROTO_HDR_IPV4, a IPv4
277    * header is expected to be copied into the buffer.
278    */
279 };
280
281 VIRTCHNL_CHECK_STRUCT_LEN (72, virtchnl_proto_hdr);
282
283 struct virtchnl_proto_hdrs
284 {
285   u8 tunnel_level;
286   /**
287    * specify where protocol header start from.
288    * 0 - from the outer layer
289    * 1 - from the first inner layer
290    * 2 - from the second inner layer
291    * ....
292    **/
293   int count; /* the proto layers must < VIRTCHNL_MAX_NUM_PROTO_HDRS */
294   struct virtchnl_proto_hdr proto_hdr[VIRTCHNL_MAX_NUM_PROTO_HDRS];
295 };
296
297 VIRTCHNL_CHECK_STRUCT_LEN (2312, virtchnl_proto_hdrs);
298
299 /* VIRTCHNL_OP_CONFIG_RSS_KEY
300  * VIRTCHNL_OP_CONFIG_RSS_LUT
301  * VF sends these messages to configure RSS. Only supported if both PF
302  * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during
303  * configuration negotiation. If this is the case, then the RSS fields in
304  * the VF resource struct are valid.
305  * Both the key and LUT are initialized to 0 by the PF, meaning that
306  * RSS is effectively disabled until set up by the VF.
307  */
308 struct virtchnl_rss_key
309 {
310   u16 vsi_id;
311   u16 key_len;
312   u8 key[1]; /* RSS hash key, packed bytes */
313 };
314
315 VIRTCHNL_CHECK_STRUCT_LEN (6, virtchnl_rss_key);
316
317 struct virtchnl_rss_lut
318 {
319   u16 vsi_id;
320   u16 lut_entries;
321   u8 lut[1]; /* RSS lookup table */
322 };
323
324 VIRTCHNL_CHECK_STRUCT_LEN (6, virtchnl_rss_lut);
325
326 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS
327  * VIRTCHNL_OP_SET_RSS_HENA
328  * VF sends these messages to get and set the hash filter enable bits for RSS.
329  * By default, the PF sets these to all possible traffic types that the
330  * hardware supports. The VF can query this value if it wants to change the
331  * traffic types that are hashed by the hardware.
332  */
333 struct virtchnl_rss_hena
334 {
335   u64 hena;
336 };
337
338 VIRTCHNL_CHECK_STRUCT_LEN (8, virtchnl_rss_hena);
339
340 /* Type of RSS algorithm */
341 enum virtchnl_rss_algorithm
342 {
343   VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC = 0,
344   VIRTCHNL_RSS_ALG_XOR_ASYMMETRIC = 1,
345   VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC = 2,
346   VIRTCHNL_RSS_ALG_XOR_SYMMETRIC = 3,
347 };
348
349 struct virtchnl_rss_cfg
350 {
351   struct virtchnl_proto_hdrs proto_hdrs;     /* protocol headers */
352   enum virtchnl_rss_algorithm rss_algorithm; /* rss algorithm type */
353   u8 reserved[128];                          /* reserve for future */
354 };
355
356 VIRTCHNL_CHECK_STRUCT_LEN (2444, virtchnl_rss_cfg);
357
358 enum virtchnl_action
359 {
360   /* action types */
361   VIRTCHNL_ACTION_DROP = 0,
362   VIRTCHNL_ACTION_TC_REDIRECT,
363   VIRTCHNL_ACTION_PASSTHRU,
364   VIRTCHNL_ACTION_QUEUE,
365   VIRTCHNL_ACTION_Q_REGION,
366   VIRTCHNL_ACTION_MARK,
367   VIRTCHNL_ACTION_COUNT,
368   VIRTCHNL_ACTION_NONE,
369 };
370
371 /* action configuration for FDIR */
372 struct virtchnl_filter_action
373 {
374   enum virtchnl_action type;
375   union
376   {
377     /* used for queue and qgroup action */
378     struct
379     {
380       u16 index;
381       u8 region;
382     } queue;
383     /* used for count action */
384     struct
385     {
386       /* share counter ID with other flow rules */
387       u8 shared;
388       u32 id; /* counter ID */
389     } count;
390     /* used for mark action */
391     u32 mark_id;
392     u8 reserve[32];
393   } act_conf;
394 };
395
396 VIRTCHNL_CHECK_STRUCT_LEN (36, virtchnl_filter_action);
397
398 #define VIRTCHNL_MAX_NUM_ACTIONS 8
399
400 struct virtchnl_filter_action_set
401 {
402   /* action number must be less then VIRTCHNL_MAX_NUM_ACTIONS */
403   int count;
404   struct virtchnl_filter_action actions[VIRTCHNL_MAX_NUM_ACTIONS];
405 };
406
407 VIRTCHNL_CHECK_STRUCT_LEN (292, virtchnl_filter_action_set);
408
409 /* pattern and action for FDIR rule */
410 struct virtchnl_fdir_rule
411 {
412   struct virtchnl_proto_hdrs proto_hdrs;
413   struct virtchnl_filter_action_set action_set;
414 };
415
416 VIRTCHNL_CHECK_STRUCT_LEN (2604, virtchnl_fdir_rule);
417
418 /* query information to retrieve fdir rule counters.
419  * PF will fill out this structure to reset counter.
420  */
421 struct virtchnl_fdir_query_info
422 {
423   u32 match_packets_valid : 1;
424   u32 match_bytes_valid : 1;
425   u32 reserved : 30; /* Reserved, must be zero. */
426   u32 pad;
427   u64 matched_packets; /* Number of packets for this rule. */
428   u64 matched_bytes;   /* Number of bytes through this rule. */
429 };
430
431 VIRTCHNL_CHECK_STRUCT_LEN (24, virtchnl_fdir_query_info);
432
433 /* Status returned to VF after VF requests FDIR commands
434  * VIRTCHNL_FDIR_SUCCESS
435  * VF FDIR related request is successfully done by PF
436  * The request can be OP_ADD/DEL/QUERY_FDIR_FILTER.
437  *
438  * VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE
439  * OP_ADD_FDIR_FILTER request is failed due to no Hardware resource.
440  *
441  * VIRTCHNL_FDIR_FAILURE_RULE_EXIST
442  * OP_ADD_FDIR_FILTER request is failed due to the rule is already existed.
443  *
444  * VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT
445  * OP_ADD_FDIR_FILTER request is failed due to conflict with existing rule.
446  *
447  * VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST
448  * OP_DEL_FDIR_FILTER request is failed due to this rule doesn't exist.
449  *
450  * VIRTCHNL_FDIR_FAILURE_RULE_INVALID
451  * OP_ADD_FDIR_FILTER request is failed due to parameters validation
452  * or HW doesn't support.
453  *
454  * VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT
455  * OP_ADD/DEL_FDIR_FILTER request is failed due to timing out
456  * for programming.
457  *
458  * VIRTCHNL_FDIR_FAILURE_QUERY_INVALID
459  * OP_QUERY_FDIR_FILTER request is failed due to parameters validation,
460  * for example, VF query counter of a rule who has no counter action.
461  */
462 enum virtchnl_fdir_prgm_status
463 {
464   VIRTCHNL_FDIR_SUCCESS = 0,
465   VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE,
466   VIRTCHNL_FDIR_FAILURE_RULE_EXIST,
467   VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT,
468   VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST,
469   VIRTCHNL_FDIR_FAILURE_RULE_INVALID,
470   VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT,
471   VIRTCHNL_FDIR_FAILURE_QUERY_INVALID,
472   VIRTCHNL_FDIR_FAILURE_MAX,
473 };
474
475 /* VIRTCHNL_OP_ADD_FDIR_FILTER
476  * VF sends this request to PF by filling out vsi_id,
477  * validate_only and rule_cfg. PF will return flow_id
478  * if the request is successfully done and return add_status to VF.
479  */
480 struct virtchnl_fdir_add
481 {
482   u16 vsi_id; /* INPUT */
483   /*
484    * 1 for validating a fdir rule, 0 for creating a fdir rule.
485    * Validate and create share one ops: VIRTCHNL_OP_ADD_FDIR_FILTER.
486    */
487   u16 validate_only;                     /* INPUT */
488   u32 flow_id;                           /* OUTPUT */
489   struct virtchnl_fdir_rule rule_cfg;    /* INPUT */
490   enum virtchnl_fdir_prgm_status status; /* OUTPUT */
491 };
492
493 VIRTCHNL_CHECK_STRUCT_LEN (2616, virtchnl_fdir_add);
494
495 /* VIRTCHNL_OP_DEL_FDIR_FILTER
496  * VF sends this request to PF by filling out vsi_id
497  * and flow_id. PF will return del_status to VF.
498  */
499 struct virtchnl_fdir_del
500 {
501   u16 vsi_id; /* INPUT */
502   u16 pad;
503   u32 flow_id;                           /* INPUT */
504   enum virtchnl_fdir_prgm_status status; /* OUTPUT */
505 };
506
507 VIRTCHNL_CHECK_STRUCT_LEN (12, virtchnl_fdir_del);
508
509 /* VIRTCHNL_OP_QUERY_FDIR_FILTER
510  * VF sends this request to PF by filling out vsi_id,
511  * flow_id and reset_counter. PF will return query_info
512  * and query_status to VF.
513  */
514 struct virtchnl_fdir_query
515 {
516   u16 vsi_id; /* INPUT */
517   u16 pad1[3];
518   u32 flow_id;                                /* INPUT */
519   u32 reset_counter : 1;                      /* INPUT */
520   struct virtchnl_fdir_query_info query_info; /* OUTPUT */
521   enum virtchnl_fdir_prgm_status status;      /* OUTPUT */
522   u32 pad2;
523 };
524
525 VIRTCHNL_CHECK_STRUCT_LEN (48, virtchnl_fdir_query);
526
527 /**
528  * Those headers used temporary, maybe OS packet
529  * definition can replace. Add flow error, pattern
530  * and action definition.
531  */
532
533 /**
534  * Verbose error types.
535  *
536  * Most of them provide the type of the object referenced by struct
537  * rte_flow_error.cause.
538  */
539 enum avf_flow_error_type
540 {
541   AVF_FLOW_ERROR_TYPE_NONE,          /**< No error. */
542   AVF_FLOW_ERROR_TYPE_UNSPECIFIED,   /**< Cause unspecified. */
543   AVF_FLOW_ERROR_TYPE_HANDLE,        /**< Flow rule (handle). */
544   AVF_FLOW_ERROR_TYPE_ATTR_GROUP,    /**< Group field. */
545   AVF_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
546   AVF_FLOW_ERROR_TYPE_ATTR_INGRESS,  /**< Ingress field. */
547   AVF_FLOW_ERROR_TYPE_ATTR_EGRESS,   /**< Egress field. */
548   AVF_FLOW_ERROR_TYPE_ATTR_TRANSFER, /**< Transfer field. */
549   AVF_FLOW_ERROR_TYPE_ATTR,          /**< Attributes structure. */
550   AVF_FLOW_ERROR_TYPE_ITEM_NUM,      /**< Pattern length. */
551   AVF_FLOW_ERROR_TYPE_ITEM_SPEC,     /**< Item specification. */
552   AVF_FLOW_ERROR_TYPE_ITEM_LAST,     /**< Item specification range. */
553   AVF_FLOW_ERROR_TYPE_ITEM_MASK,     /**< Item specification mask. */
554   AVF_FLOW_ERROR_TYPE_ITEM,          /**< Specific pattern item. */
555   AVF_FLOW_ERROR_TYPE_ACTION_NUM,    /**< Number of actions. */
556   AVF_FLOW_ERROR_TYPE_ACTION_CONF,   /**< Action configuration. */
557   AVF_FLOW_ERROR_TYPE_ACTION,        /**< Specific action. */
558 };
559
560 /**
561  * Verbose error structure definition.
562  * Both cause and message may be NULL regardless of the error type.
563  */
564 struct avf_flow_error
565 {
566   enum avf_flow_error_type type; /**< Cause field and error types. */
567   const void *cause;             /**< Object responsible for the error. */
568   const char *message;           /**< Human-readable error message. */
569 };
570
571 #define AVF_ETHER_ADDR_LEN 6
572 struct avf_ether_addr
573 {
574   u8 addr_bytes[AVF_ETHER_ADDR_LEN]; /**< Addr bytes in tx order */
575 } __attribute__ ((__aligned__ (2)));
576
577 struct avf_flow_eth_hdr
578 {
579   struct avf_ether_addr dst; /**< Destination MAC. */
580   struct avf_ether_addr src; /**< Source MAC. */
581   u16 type;                  /**< EtherType or TPID. */
582 };
583
584 /**
585  * IPv4 Header
586  */
587 struct avf_ipv4_hdr
588 {
589   u8 version_ihl;      /**< version and header length */
590   u8 type_of_service;  /**< type of service */
591   u16 total_length;    /**< length of packet */
592   u16 packet_id;       /**< packet ID */
593   u16 fragment_offset; /**< fragmentation offset */
594   u8 time_to_live;     /**< time to live */
595   u8 next_proto_id;    /**< protocol ID */
596   u16 hdr_checksum;    /**< header checksum */
597   u32 src_addr;        /**< source address */
598   u32 dst_addr;        /**< destination address */
599 } __attribute__ ((__packed__));
600
601 /**
602  * IPv6 Header
603  */
604 struct avf_ipv6_hdr
605 {
606   u32 vtc_flow;    /**< IP version, traffic class & flow label. */
607   u16 payload_len; /**< IP packet length - includes header size */
608   u8 proto;        /**< Protocol, next header. */
609   u8 hop_limits;   /**< Hop limits. */
610   u8 src_addr[16]; /**< IP address of source host. */
611   u8 dst_addr[16]; /**< IP address of destination host(s). */
612 } __attribute__ ((__packed__));
613
614 /**
615  * TCP Header
616  */
617 struct avf_tcp_hdr
618 {
619   u16 src_port; /**< TCP source port. */
620   u16 dst_port; /**< TCP destination port. */
621   u32 sent_seq; /**< TX data sequence number. */
622   u32 recv_ack; /**< RX data acknowledgment sequence number. */
623   u8 data_off;  /**< Data offset. */
624   u8 tcp_flags; /**< TCP flags */
625   u16 rx_win;   /**< RX flow control window. */
626   u16 cksum;    /**< TCP checksum. */
627   u16 tcp_urp;  /**< TCP urgent pointer, if any. */
628 } __attribute__ ((__packed__));
629
630 /**
631  * UDP Header
632  */
633 struct avf_udp_hdr
634 {
635   u16 src_port;    /**< UDP source port. */
636   u16 dst_port;    /**< UDP destination port. */
637   u16 dgram_len;   /**< UDP datagram length */
638   u16 dgram_cksum; /**< UDP datagram checksum */
639 } __attribute__ ((__packed__));
640
641 /**
642  * Match IP Authentication Header (AH), RFC 4302
643  */
644 struct avf_ah_hdr
645 {
646   u32 next_hdr : 8;
647   u32 payload_len : 8;
648   u32 reserved : 16;
649   u32 spi;
650   u32 seq_num;
651 };
652
653 /**
654  * ESP Header
655  */
656 struct avf_esp_hdr
657 {
658   u32 spi; /**< Security Parameters Index */
659   u32 seq; /**< packet sequence number */
660 } __attribute__ ((__packed__));
661
662 /**
663  * Match PFCP Header
664  */
665 struct avf_pfcp_hdr
666 {
667   u8 s_field;
668   u8 msg_type;
669   u16 msg_len;
670   u64 seid;
671 };
672
673 /**
674  * Matches a L2TPv3 over IP header.
675  */
676 struct avf_l2tpv3oip_hdr
677 {
678   u32 session_id; /**< Session ID. */
679 };
680
681 /**
682  * Matches a GTP PDU extension header with type 0x85.
683  */
684 struct avf_gtp_psc_hdr
685 {
686   u8 pdu_type; /**< PDU type. */
687   u8 qfi;      /**< QoS flow identifier. */
688 };
689
690 /**
691  * Matches a GTPv1 header.
692  */
693 struct avf_gtp_hdr
694 {
695   /**
696    * Version (3b), protocol type (1b), reserved (1b),
697    * Extension header flag (1b),
698    * Sequence number flag (1b),
699    * N-PDU number flag (1b).
700    */
701   u8 v_pt_rsv_flags;
702   u8 msg_type; /**< Message type. */
703   u16 msg_len; /**< Message length. */
704   u32 teid;    /**< Tunnel endpoint identifier. */
705 };
706
707 /**
708  * SCTP Header
709  */
710 struct avf_sctp_hdr
711 {
712   u16 src_port; /**< Source port. */
713   u16 dst_port; /**< Destin port. */
714   u32 tag;      /**< Validation tag. */
715   u32 cksum;    /**< Checksum. */
716 } __attribute__ ((__packed__));
717
718 /**
719  * Hash function types.
720  */
721 enum avf_eth_hash_function
722 {
723   AVF_ETH_HASH_FUNCTION_DEFAULT = 0,
724   AVF_ETH_HASH_FUNCTION_TOEPLITZ,   /**< Toeplitz */
725   AVF_ETH_HASH_FUNCTION_SIMPLE_XOR, /**< Simple XOR */
726   /**
727    * Symmetric Toeplitz: src, dst will be replaced by
728    * xor(src, dst). For the case with src/dst only,
729    * src or dst address will xor with zero pair.
730    */
731   AVF_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ,
732   AVF_ETH_HASH_FUNCTION_MAX,
733 };
734
735 struct avf_flow_action_rss
736 {
737   enum avf_eth_hash_function func; /**< RSS hash function to apply. */
738
739   u32 level;
740   u64 types;        /**< Specific RSS hash types (see ETH_RSS_*). */
741   u32 key_len;      /**< Hash key length in bytes. */
742   u32 queue_num;    /**< Number of entries in @p queue. */
743   const u8 *key;    /**< Hash key. */
744   const u16 *queue; /**< Queue indices to use. */
745 };
746
747 struct avf_flow_action_queue
748 {
749   u16 index; /**< Queue index to use. */
750 };
751
752 struct avf_flow_action_mark
753 {
754   u32 id; /**< Integer value to return with packets. */
755 };
756
757 struct avf_flow_action
758 {
759   enum virtchnl_action type; /**< Action type. */
760   const void *conf;          /**< Pointer to action configuration object. */
761 };
762
763 struct avf_flow_item
764 {
765   enum virtchnl_proto_hdr_type type; /**< Item type. */
766   const void *spec; /**< Pointer to item specification structure. */
767   const void *mask; /**< Bit-mask applied to spec and last. */
768 };
769
770 struct avf_fdir_conf
771 {
772   struct virtchnl_fdir_add add_fltr;
773   struct virtchnl_fdir_del del_fltr;
774   u64 input_set;
775   u32 flow_id;
776   u32 mark_flag;
777   u32 vsi;
778   u32 nb_rx_queues;
779 };
780
781 enum virthnl_adv_ops
782 {
783   VIRTCHNL_ADV_OP_ADD_FDIR_FILTER = 0,
784   VIRTCHNL_ADV_OP_DEL_FDIR_FILTER,
785   VIRTCHNL_ADV_OP_QUERY_FDIR_FILTER,
786   VIRTCHNL_ADV_OP_MAX
787 };
788
789 /* virtual channel op handler */
790 typedef int (*avf_fdir_vc_op_t) (void *vc_hdl, enum virthnl_adv_ops vc_op,
791                                  void *in, u32 in_len, void *out, u32 out_len);
792
793 /* virtual channel context object */
794 struct avf_fdir_vc_ctx
795 {
796   void *vc_hdl; /* virtual channel handler */
797   avf_fdir_vc_op_t vc_op;
798 };
799
800 /**
801  * Create a rule cfg object.
802  *
803  * @param rcfg
804  *      created rule cfg object.
805  * @param tunnel
806  *      tunnel level where protocol header start from
807  *      0 from moster outer layer.
808  *      1 from first inner layer.
809  *      2 form second inner layer.
810  *      ...
811  * @param vsi
812  *      avf vsi id
813  *
814  * @param nrxq
815  *      the rx queue number of the avf
816  *
817  * @return
818  *      0 = successful.
819  *      < 0 = failure.
820  */
821 int avf_fdir_rcfg_create (struct avf_fdir_conf **rcfg, int tunnel_level,
822                           u16 vsi, u16 nrxq);
823
824 /**
825  * Destroy a rule cfg object.
826  *
827  * @param rcfg
828  *      the cfg object to destroy.
829  *
830  * @return
831  *      0 = successful.
832  *      < 0 = failure.
833  */
834 int avf_fdir_rcfg_destroy (struct avf_fdir_conf *rcfg);
835
836 /**
837  * Set match potocol header on specific layer, it will overwrite is already be
838  * set.
839  *
840  * @param rcfg
841  *      the rule cfg object
842  * @param layer
843  *      layer of the protocol header.
844  * @param hdr
845  *      protocol header type.
846  *
847  * @return
848  *      0 = successful.
849  *      < 0 = failure.
850  */
851 int avf_fdir_rcfg_set_hdr (struct avf_fdir_conf *rcfg, int layer,
852                            enum virtchnl_proto_hdr_type hdr);
853
854 /**
855  * Set a match field on specific protocol layer, if any match field already be
856  * set on this layer, it will be overwritten.
857  *
858  * @param rcfg
859  *      the rule cfg object
860  * @param layer
861  *      layer of the protocol header.
862  * @param item
863  *      flow item
864  * @param error
865  *      save error cause
866  *
867  * @return
868  *      0 = successful.
869  *      < 0 = failure.
870  */
871 int avf_fdir_rcfg_set_field (struct avf_fdir_conf *rcfg, int layer,
872                              struct avf_flow_item *item,
873                              struct avf_flow_error *error);
874
875 /**
876  * Set action as to queue(group), conflict with drop action.
877  *
878  * @param rcfg
879  *      rule cfg object
880  * @param queue
881  *      queue id.
882  * @param size
883  *      queue group size, must be 2^n. 1 means only to single queue.
884  * @param act_idx
885  *      action index
886  *
887  * @return
888  *      0 = successful.
889  *      < 0 = failure.
890  */
891 int avf_fdir_rcfg_act_queue (struct avf_fdir_conf *rcfg, int queue, int size,
892                              int act_idx);
893
894 /**
895  * Set action as to queue group, conflict with drop action.
896  *
897  * @param rcfg
898  *      the rule cfg object
899  * @param act
900  *      flow actions
901  * @param act_idx
902  *      action index
903  * @error
904  *      save error cause
905  *
906  * @return
907  *      0 = successful.
908  *      < 0 = failure.
909  */
910 int avf_fdir_parse_action_qregion (struct avf_fdir_conf *rcfg,
911                                    const struct avf_flow_action *act,
912                                    int act_idx, struct avf_flow_error *error);
913
914 /**
915  * Set action as as drop, conflict with to queue(gropu) action.
916  *
917  * @param rcfg
918  *      the rule cfg object
919  * @param act_idx
920  *      action index
921  *
922  * @return
923  *      0 = successful.
924  *      < 0 = failure.
925  */
926 int avf_fdir_rcfg_act_drop (struct avf_fdir_conf *rcfg, int act_idx);
927
928 /**
929  * Set action as mark, it can co-exist with to queue(group) or drop action.
930  *
931  * @param rcfg
932  *      the rule cfg object
933  * @param mark
934  *      a 32 bit flow mark
935  * @param act_idx
936  *      action index
937  *
938  * @return
939  *      0 = successful.
940  *      < 0 = failure.
941  */
942 int avf_fdir_rcfg_act_mark (struct avf_fdir_conf *rcfg, const u32 mark,
943                             int act_idx);
944
945 /**
946  * Validate a flow rule cfg, check with PF driver if the rule cfg is supportted
947  *or not.
948  *
949  * @param ctx
950  *       virtual channel context
951  * @param rcfg
952  *      the rule cfg object.
953  *
954  * @return
955  *      0 = successful.
956  *      < 0 = failure.
957  */
958 int avf_fdir_rcfg_validate (struct avf_fdir_vc_ctx *ctx,
959                             struct avf_fdir_conf *rcfg);
960
961 /**
962  * Create a flow rule, a FDIR rule is expected to be programmed into hardware
963  *if return success.
964  *
965  * @param ctx
966  *       virtual channel context
967  * @param rcfg
968  *      rule cfg object.
969  *
970  * @return
971  *      0 = successfule.
972  *      < 0 = failure.
973  */
974 int avf_fdir_rule_create (struct avf_fdir_vc_ctx *ctx,
975                           struct avf_fdir_conf *rcfg);
976
977 /**
978  * Destroy a flow rule.
979  *
980  * @param ctx
981  *       virtual channel context
982  * @param rcfg
983  *      the rule cfg object.
984  *
985  * @return
986  *      0 = successfule.
987  *      < 0 = failure.
988  */
989 int avf_fdir_rule_destroy (struct avf_fdir_vc_ctx *ctx,
990                            struct avf_fdir_conf *rcfg);
991
992 /*
993  * Parse avf patterns and set pattern fields.
994  *
995  * @param rcfg
996  *      flow config
997  * @param avf_items
998  *      pattern items
999  * @param error
1000  *      save error cause
1001  *
1002  * @return
1003  *      0 = successful.
1004  *      < 0 = failure
1005  */
1006 int avf_fdir_parse_pattern (struct avf_fdir_conf *rcfg,
1007                             struct avf_flow_item avf_items[],
1008                             struct avf_flow_error *error);
1009
1010 /*
1011  * Parse flow actions, set actions.
1012  *
1013  * @param actions
1014  *      flow actions
1015  * @param rcfg
1016  *      flow config
1017  * @param error
1018  *      save error cause
1019  *
1020  * @return
1021  *  0 = successful.
1022  *  < 0 = failure
1023  */
1024 int avf_fdir_parse_action (const struct avf_flow_action actions[],
1025                            struct avf_fdir_conf *rcfg,
1026                            struct avf_flow_error *error);
1027
1028 /**
1029  * Initialize flow error structure.
1030  *
1031  * @param[out] error
1032  *   Pointer to flow error structure (may be NULL).
1033  * @param code
1034  *   Related error code
1035  * @param type
1036  *   Cause field and error types.
1037  * @param cause
1038  *   Object responsible for the error.
1039  * @param message
1040  *   Human-readable error message.
1041  *
1042  * @return
1043  *   Negative error code (errno value)
1044  */
1045 int avf_flow_error_set (struct avf_flow_error *error, int code,
1046                         enum avf_flow_error_type type, const void *cause,
1047                         const char *message);
1048
1049 /*
1050  * decode the error number to Verbose error string
1051  *
1052  * @param err_no
1053  *  error number
1054  *
1055  * @return
1056  *  Verbose error string
1057  */
1058 char *avf_fdir_prgm_error_decode (int err_no);
1059
1060 #endif /* _AVF_ADVANCED_FLOW_H_ */
1061
1062 /*
1063  * fd.io coding-style-patch-verification: ON
1064  *
1065  * Local Variables:
1066  * eval: (c-set-style "gnu")
1067  * End:
1068  */