avf: enable rss action of flow
[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 VIRTCHNL_MAX_SIZE_GEN_PACKET 1024
49 #define PROTO_HDR_SHIFT             5
50 #define PROTO_HDR_FIELD_START(proto_hdr_type)                                 \
51   (proto_hdr_type << PROTO_HDR_SHIFT)
52 #define PROTO_HDR_FIELD_MASK ((1UL << PROTO_HDR_SHIFT) - 1)
53
54 /* VF use these macros to configure each protocol header.
55  * Specify which protocol headers and protocol header fields base on
56  * virtchnl_proto_hdr_type and virtchnl_proto_hdr_field.
57  * @param hdr: a struct of virtchnl_proto_hdr
58  * @param hdr_type: ETH/IPV4/TCP, etc
59  * @param field: SRC/DST/TEID/SPI, etc
60  */
61 #define VIRTCHNL_ADD_PROTO_HDR_FIELD(hdr, field)                              \
62   ((hdr)->field_selector |= BIT ((field) &PROTO_HDR_FIELD_MASK))
63 #define VIRTCHNL_DEL_PROTO_HDR_FIELD(hdr, field)                              \
64   ((hdr)->field_selector &= ~BIT ((field) &PROTO_HDR_FIELD_MASK))
65 #define VIRTCHNL_TEST_PROTO_HDR_FIELD(hdr, val)                               \
66   ((hdr)->field_selector & BIT ((val) &PROTO_HDR_FIELD_MASK))
67 #define VIRTCHNL_GET_PROTO_HDR_FIELD(hdr) ((hdr)->field_selector)
68
69 #define VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, hdr_type, field)                \
70   (VIRTCHNL_ADD_PROTO_HDR_FIELD (hdr, VIRTCHNL_PROTO_HDR_##hdr_type##_##field))
71 #define VIRTCHNL_DEL_PROTO_HDR_FIELD_BIT(hdr, hdr_type, field)                \
72   (VIRTCHNL_DEL_PROTO_HDR_FIELD (hdr, VIRTCHNL_PROTO_HDR_##hdr_type##_##field))
73
74 #define VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, hdr_type)                            \
75   ((hdr)->type = VIRTCHNL_PROTO_HDR_##hdr_type)
76 #define VIRTCHNL_GET_PROTO_HDR_TYPE(hdr) (((hdr)->type) >> PROTO_HDR_SHIFT)
77 #define VIRTCHNL_TEST_PROTO_HDR_TYPE(hdr, val)                                \
78   ((hdr)->type == ((val) >> PROTO_HDR_SHIFT))
79 #define VIRTCHNL_TEST_PROTO_HDR(hdr, val)                                     \
80   (VIRTCHNL_TEST_PROTO_HDR_TYPE (hdr, val) &&                                 \
81    VIRTCHNL_TEST_PROTO_HDR_FIELD (hdr, val))
82
83 /* protocol */
84
85 #define AVF_PROT_MAC_INNER   (1ULL << 1)
86 #define AVF_PROT_MAC_OUTER   (1ULL << 2)
87 #define AVF_PROT_VLAN_INNER  (1ULL << 3)
88 #define AVF_PROT_VLAN_OUTER  (1ULL << 4)
89 #define AVF_PROT_IPV4_INNER  (1ULL << 5)
90 #define AVF_PROT_IPV4_OUTER  (1ULL << 6)
91 #define AVF_PROT_IPV6_INNER  (1ULL << 7)
92 #define AVF_PROT_IPV6_OUTER  (1ULL << 8)
93 #define AVF_PROT_TCP_INNER   (1ULL << 9)
94 #define AVF_PROT_TCP_OUTER   (1ULL << 10)
95 #define AVF_PROT_UDP_INNER   (1ULL << 11)
96 #define AVF_PROT_UDP_OUTER   (1ULL << 12)
97 #define AVF_PROT_SCTP_INNER  (1ULL << 13)
98 #define AVF_PROT_SCTP_OUTER  (1ULL << 14)
99 #define AVF_PROT_ICMP4_INNER (1ULL << 15)
100 #define AVF_PROT_ICMP4_OUTER (1ULL << 16)
101 #define AVF_PROT_ICMP6_INNER (1ULL << 17)
102 #define AVF_PROT_ICMP6_OUTER (1ULL << 18)
103 #define AVF_PROT_VXLAN       (1ULL << 19)
104 #define AVF_PROT_NVGRE       (1ULL << 20)
105 #define AVF_PROT_GTPU        (1ULL << 21)
106 #define AVF_PROT_ESP         (1ULL << 22)
107 #define AVF_PROT_AH          (1ULL << 23)
108 #define AVF_PROT_L2TPV3OIP   (1ULL << 24)
109 #define AVF_PROT_PFCP        (1ULL << 25)
110
111 /* field */
112
113 #define AVF_SMAC                 (1ULL << 63)
114 #define AVF_DMAC                 (1ULL << 62)
115 #define AVF_ETHERTYPE            (1ULL << 61)
116 #define AVF_IP_SRC               (1ULL << 60)
117 #define AVF_IP_DST               (1ULL << 59)
118 #define AVF_IP_PROTO             (1ULL << 58)
119 #define AVF_IP_TTL               (1ULL << 57)
120 #define AVF_IP_TOS               (1ULL << 56)
121 #define AVF_SPORT                (1ULL << 55)
122 #define AVF_DPORT                (1ULL << 54)
123 #define AVF_ICMP_TYPE            (1ULL << 53)
124 #define AVF_ICMP_CODE            (1ULL << 52)
125 #define AVF_VXLAN_VNI            (1ULL << 51)
126 #define AVF_NVGRE_TNI            (1ULL << 50)
127 #define AVF_GTPU_TEID            (1ULL << 49)
128 #define AVF_GTPU_QFI             (1ULL << 48)
129 #define AVF_ESP_SPI              (1ULL << 47)
130 #define AVF_AH_SPI               (1ULL << 46)
131 #define AVF_L2TPV3OIP_SESSION_ID (1ULL << 45)
132 #define AVF_PFCP_S_FIELD         (1ULL << 44)
133 #define AVF_PFCP_SEID            (1ULL << 43)
134
135 /* input set */
136
137 #define AVF_INSET_NONE 0ULL
138
139 /* non-tunnel */
140
141 #define AVF_INSET_SMAC       (AVF_PROT_MAC_OUTER | AVF_SMAC)
142 #define AVF_INSET_DMAC       (AVF_PROT_MAC_OUTER | AVF_DMAC)
143 #define AVF_INSET_VLAN_INNER (AVF_PROT_VLAN_INNER)
144 #define AVF_INSET_VLAN_OUTER (AVF_PROT_VLAN_OUTER)
145 #define AVF_INSET_ETHERTYPE  (AVF_ETHERTYPE)
146
147 #define AVF_INSET_IPV4_SRC       (AVF_PROT_IPV4_OUTER | AVF_IP_SRC)
148 #define AVF_INSET_IPV4_DST       (AVF_PROT_IPV4_OUTER | AVF_IP_DST)
149 #define AVF_INSET_IPV4_TOS       (AVF_PROT_IPV4_OUTER | AVF_IP_TOS)
150 #define AVF_INSET_IPV4_PROTO     (AVF_PROT_IPV4_OUTER | AVF_IP_PROTO)
151 #define AVF_INSET_IPV4_TTL       (AVF_PROT_IPV4_OUTER | AVF_IP_TTL)
152 #define AVF_INSET_IPV6_SRC       (AVF_PROT_IPV6_OUTER | AVF_IP_SRC)
153 #define AVF_INSET_IPV6_DST       (AVF_PROT_IPV6_OUTER | AVF_IP_DST)
154 #define AVF_INSET_IPV6_NEXT_HDR  (AVF_PROT_IPV6_OUTER | AVF_IP_PROTO)
155 #define AVF_INSET_IPV6_HOP_LIMIT (AVF_PROT_IPV6_OUTER | AVF_IP_TTL)
156 #define AVF_INSET_IPV6_TC        (AVF_PROT_IPV6_OUTER | AVF_IP_TOS)
157
158 #define AVF_INSET_TCP_SRC_PORT   (AVF_PROT_TCP_OUTER | AVF_SPORT)
159 #define AVF_INSET_TCP_DST_PORT   (AVF_PROT_TCP_OUTER | AVF_DPORT)
160 #define AVF_INSET_UDP_SRC_PORT   (AVF_PROT_UDP_OUTER | AVF_SPORT)
161 #define AVF_INSET_UDP_DST_PORT   (AVF_PROT_UDP_OUTER | AVF_DPORT)
162 #define AVF_INSET_SCTP_SRC_PORT  (AVF_PROT_SCTP_OUTER | AVF_SPORT)
163 #define AVF_INSET_SCTP_DST_PORT  (AVF_PROT_SCTP_OUTER | AVF_DPORT)
164 #define AVF_INSET_ICMP4_SRC_PORT (AVF_PROT_ICMP4_OUTER | AVF_SPORT)
165 #define AVF_INSET_ICMP4_DST_PORT (AVF_PROT_ICMP4_OUTER | AVF_DPORT)
166 #define AVF_INSET_ICMP6_SRC_PORT (AVF_PROT_ICMP6_OUTER | AVF_SPORT)
167 #define AVF_INSET_ICMP6_DST_PORT (AVF_PROT_ICMP6_OUTER | AVF_DPORT)
168 #define AVF_INSET_ICMP4_TYPE     (AVF_PROT_ICMP4_OUTER | AVF_ICMP_TYPE)
169 #define AVF_INSET_ICMP4_CODE     (AVF_PROT_ICMP4_OUTER | AVF_ICMP_CODE)
170 #define AVF_INSET_ICMP6_TYPE     (AVF_PROT_ICMP6_OUTER | AVF_ICMP_TYPE)
171 #define AVF_INSET_ICMP6_CODE     (AVF_PROT_ICMP6_OUTER | AVF_ICMP_CODE)
172 #define AVF_INSET_GTPU_TEID      (AVF_PROT_GTPU | AVF_GTPU_TEID)
173 #define AVF_INSET_GTPU_QFI       (AVF_PROT_GTPU | AVF_GTPU_QFI)
174 #define AVF_INSET_ESP_SPI        (AVF_PROT_ESP | AVF_ESP_SPI)
175 #define AVF_INSET_AH_SPI         (AVF_PROT_AH | AVF_AH_SPI)
176 #define AVF_INSET_L2TPV3OIP_SESSION_ID                                        \
177   (AVF_PROT_L2TPV3OIP | AVF_L2TPV3OIP_SESSION_ID)
178 #define AVF_INSET_PFCP_S_FIELD (AVF_PROT_PFCP | AVF_PFCP_S_FIELD)
179 #define AVF_INSET_PFCP_SEID    (AVF_PROT_PFCP | AVF_PFCP_S_FIELD | AVF_PFCP_SEID)
180
181 #define AVF_ETH_RSS_IPV4               BIT_ULL (2)
182 #define AVF_ETH_RSS_FRAG_IPV4          BIT_ULL (3)
183 #define AVF_ETH_RSS_NONFRAG_IPV4_TCP   BIT_ULL (4)
184 #define AVF_ETH_RSS_NONFRAG_IPV4_UDP   BIT_ULL (5)
185 #define AVF_ETH_RSS_NONFRAG_IPV4_SCTP  BIT_ULL (6)
186 #define AVF_ETH_RSS_NONFRAG_IPV4_OTHER BIT_ULL (7)
187 #define AVF_ETH_RSS_IPV6               BIT_ULL (8)
188 #define AVF_ETH_RSS_FRAG_IPV6          BIT_ULL (9)
189 #define AVF_ETH_RSS_NONFRAG_IPV6_TCP   BIT_ULL (10)
190 #define AVF_ETH_RSS_NONFRAG_IPV6_UDP   BIT_ULL (11)
191 #define AVF_ETH_RSS_NONFRAG_IPV6_SCTP  BIT_ULL (12)
192 #define AVF_ETH_RSS_NONFRAG_IPV6_OTHER BIT_ULL (13)
193 #define AVF_ETH_RSS_L2_PAYLOAD         BIT_ULL (14)
194 #define AVF_ETH_RSS_IPV6_EX            BIT_ULL (15)
195 #define AVF_ETH_RSS_IPV6_TCP_EX        BIT_ULL (16)
196 #define AVF_ETH_RSS_IPV6_UDP_EX        BIT_ULL (17)
197 #define AVF_ETH_RSS_PORT               BIT_ULL (18)
198 #define AVF_ETH_RSS_VXLAN              BIT_ULL (19)
199 #define AVF_ETH_RSS_GENEVE             BIT_ULL (20)
200 #define AVF_ETH_RSS_NVGRE              BIT_ULL (21)
201 #define AVF_ETH_RSS_GTPU               BIT_ULL (23)
202 #define AVF_ETH_RSS_ETH                BIT_ULL (24)
203 #define AVF_ETH_RSS_S_VLAN             BIT_ULL (25)
204 #define AVF_ETH_RSS_C_VLAN             BIT_ULL (26)
205 #define AVF_ETH_RSS_ESP                BIT_ULL (27)
206 #define AVF_ETH_RSS_AH                 BIT_ULL (28)
207 #define AVF_ETH_RSS_L2TPV3             BIT_ULL (29)
208 #define AVF_ETH_RSS_PFCP               BIT_ULL (30)
209 #define AVF_ETH_RSS_PPPOE              BIT_ULL (31)
210 #define AVF_ETH_RSS_ECPRI              BIT_ULL (32)
211 #define AVF_ETH_RSS_MPLS               BIT_ULL (33)
212 #define AVF_ETH_RSS_IPV4_CHKSUM        BIT_ULL (34)
213 #define AVF_ETH_RSS_L4_CHKSUM          BIT_ULL (35)
214 #define AVF_ETH_RSS_L2TPV2             BIT_ULL (36)
215 #define AVF_ETH_RSS_L3_SRC_ONLY        BIT_ULL (63)
216 #define AVF_ETH_RSS_L3_DST_ONLY        BIT_ULL (62)
217 #define AVF_ETH_RSS_L4_SRC_ONLY        BIT_ULL (61)
218 #define AVF_ETH_RSS_L4_DST_ONLY        BIT_ULL (60)
219 #define AVF_ETH_RSS_L2_SRC_ONLY        BIT_ULL (59)
220 #define AVF_ETH_RSS_L2_DST_ONLY        BIT_ULL (58)
221 #define AVF_ETH_RSS_L3_PRE32           BIT_ULL (57)
222 #define AVF_ETH_RSS_L3_PRE40           BIT_ULL (56)
223 #define AVF_ETH_RSS_L3_PRE48           BIT_ULL (55)
224 #define AVF_ETH_RSS_L3_PRE56           BIT_ULL (54)
225 #define AVF_ETH_RSS_L3_PRE64           BIT_ULL (53)
226 #define AVF_ETH_RSS_L3_PRE96           BIT_ULL (52)
227
228 #define foreach_avf_rss_hf                                                    \
229   _ (0, AVF_ETH_RSS_FRAG_IPV4, "ipv4-frag")                                   \
230   _ (1, AVF_ETH_RSS_NONFRAG_IPV4_TCP, "ipv4-tcp")                             \
231   _ (2, AVF_ETH_RSS_NONFRAG_IPV4_UDP, "ipv4-udp")                             \
232   _ (3, AVF_ETH_RSS_NONFRAG_IPV4_SCTP, "ipv4-sctp")                           \
233   _ (4, AVF_ETH_RSS_NONFRAG_IPV4_OTHER, "ipv4-other")                         \
234   _ (5, AVF_ETH_RSS_IPV4, "ipv4")                                             \
235   _ (6, AVF_ETH_RSS_IPV6_TCP_EX, "ipv6-tcp-ex")                               \
236   _ (7, AVF_ETH_RSS_IPV6_UDP_EX, "ipv6-udp-ex")                               \
237   _ (8, AVF_ETH_RSS_FRAG_IPV6, "ipv6-frag")                                   \
238   _ (9, AVF_ETH_RSS_NONFRAG_IPV6_TCP, "ipv6-tcp")                             \
239   _ (10, AVF_ETH_RSS_NONFRAG_IPV6_UDP, "ipv6-udp")                            \
240   _ (11, AVF_ETH_RSS_NONFRAG_IPV6_SCTP, "ipv6-sctp")                          \
241   _ (12, AVF_ETH_RSS_NONFRAG_IPV6_OTHER, "ipv6-other")                        \
242   _ (13, AVF_ETH_RSS_IPV6_EX, "ipv6-ex")                                      \
243   _ (14, AVF_ETH_RSS_IPV6, "ipv6")                                            \
244   _ (15, AVF_ETH_RSS_L2_PAYLOAD, "l2-payload")                                \
245   _ (16, AVF_ETH_RSS_PORT, "port")                                            \
246   _ (17, AVF_ETH_RSS_VXLAN, "vxlan")                                          \
247   _ (18, AVF_ETH_RSS_GENEVE, "geneve")                                        \
248   _ (19, AVF_ETH_RSS_NVGRE, "nvgre")                                          \
249   _ (20, AVF_ETH_RSS_GTPU, "gtpu")                                            \
250   _ (21, AVF_ETH_RSS_ESP, "esp")                                              \
251   _ (60, AVF_ETH_RSS_L4_DST_ONLY, "l4-dst-only")                              \
252   _ (61, AVF_ETH_RSS_L4_SRC_ONLY, "l4-src-only")                              \
253   _ (62, AVF_ETH_RSS_L3_DST_ONLY, "l3-dst-only")                              \
254   _ (63, AVF_ETH_RSS_L3_SRC_ONLY, "l3-src-only")
255
256 /* Protocol header type within a packet segment. A segment consists of one or
257  * more protocol headers that make up a logical group of protocol headers. Each
258  * logical group of protocol headers encapsulates or is encapsulated using/by
259  * tunneling or encapsulation protocols for network virtualization.
260  */
261 enum virtchnl_proto_hdr_type
262 {
263   VIRTCHNL_PROTO_HDR_NONE,
264   VIRTCHNL_PROTO_HDR_ETH,
265   VIRTCHNL_PROTO_HDR_S_VLAN,
266   VIRTCHNL_PROTO_HDR_C_VLAN,
267   VIRTCHNL_PROTO_HDR_IPV4,
268   VIRTCHNL_PROTO_HDR_IPV6,
269   VIRTCHNL_PROTO_HDR_TCP,
270   VIRTCHNL_PROTO_HDR_UDP,
271   VIRTCHNL_PROTO_HDR_SCTP,
272   VIRTCHNL_PROTO_HDR_GTPU_IP,
273   VIRTCHNL_PROTO_HDR_GTPU_EH,
274   VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_DWN,
275   VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_UP,
276   VIRTCHNL_PROTO_HDR_PPPOE,
277   VIRTCHNL_PROTO_HDR_L2TPV3,
278   VIRTCHNL_PROTO_HDR_ESP,
279   VIRTCHNL_PROTO_HDR_AH,
280   VIRTCHNL_PROTO_HDR_PFCP,
281   VIRTCHNL_PROTO_HDR_GTPC,
282   VIRTCHNL_PROTO_HDR_ECPRI,
283   VIRTCHNL_PROTO_HDR_L2TPV2,
284   VIRTCHNL_PROTO_HDR_PPP,
285   /* IPv4 and IPv6 Fragment header types are only associated to
286    * VIRTCHNL_PROTO_HDR_IPV4 and VIRTCHNL_PROTO_HDR_IPV6 respectively,
287    * cannot be used independently.
288    */
289   VIRTCHNL_PROTO_HDR_IPV4_FRAG,
290   VIRTCHNL_PROTO_HDR_IPV6_EH_FRAG,
291   VIRTCHNL_PROTO_HDR_GRE,
292 };
293
294 /* Protocol header field within a protocol header. */
295 enum virtchnl_proto_hdr_field
296 {
297   /* ETHER */
298   VIRTCHNL_PROTO_HDR_ETH_SRC = PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_ETH),
299   VIRTCHNL_PROTO_HDR_ETH_DST,
300   VIRTCHNL_PROTO_HDR_ETH_ETHERTYPE,
301   /* S-VLAN */
302   VIRTCHNL_PROTO_HDR_S_VLAN_ID =
303     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_S_VLAN),
304   /* C-VLAN */
305   VIRTCHNL_PROTO_HDR_C_VLAN_ID =
306     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_C_VLAN),
307   /* IPV4 */
308   VIRTCHNL_PROTO_HDR_IPV4_SRC =
309     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_IPV4),
310   VIRTCHNL_PROTO_HDR_IPV4_DST,
311   VIRTCHNL_PROTO_HDR_IPV4_DSCP,
312   VIRTCHNL_PROTO_HDR_IPV4_TTL,
313   VIRTCHNL_PROTO_HDR_IPV4_PROT,
314   VIRTCHNL_PROTO_HDR_IPV4_CHKSUM,
315   /* IPV6 */
316   VIRTCHNL_PROTO_HDR_IPV6_SRC =
317     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_IPV6),
318   VIRTCHNL_PROTO_HDR_IPV6_DST,
319   VIRTCHNL_PROTO_HDR_IPV6_TC,
320   VIRTCHNL_PROTO_HDR_IPV6_HOP_LIMIT,
321   VIRTCHNL_PROTO_HDR_IPV6_PROT,
322   /* IPV6 Prefix */
323   VIRTCHNL_PROTO_HDR_IPV6_PREFIX32_SRC,
324   VIRTCHNL_PROTO_HDR_IPV6_PREFIX32_DST,
325   VIRTCHNL_PROTO_HDR_IPV6_PREFIX40_SRC,
326   VIRTCHNL_PROTO_HDR_IPV6_PREFIX40_DST,
327   VIRTCHNL_PROTO_HDR_IPV6_PREFIX48_SRC,
328   VIRTCHNL_PROTO_HDR_IPV6_PREFIX48_DST,
329   VIRTCHNL_PROTO_HDR_IPV6_PREFIX56_SRC,
330   VIRTCHNL_PROTO_HDR_IPV6_PREFIX56_DST,
331   VIRTCHNL_PROTO_HDR_IPV6_PREFIX64_SRC,
332   VIRTCHNL_PROTO_HDR_IPV6_PREFIX64_DST,
333   VIRTCHNL_PROTO_HDR_IPV6_PREFIX96_SRC,
334   VIRTCHNL_PROTO_HDR_IPV6_PREFIX96_DST,
335   /* TCP */
336   VIRTCHNL_PROTO_HDR_TCP_SRC_PORT =
337     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_TCP),
338   VIRTCHNL_PROTO_HDR_TCP_DST_PORT,
339   VIRTCHNL_PROTO_HDR_TCP_CHKSUM,
340   /* UDP */
341   VIRTCHNL_PROTO_HDR_UDP_SRC_PORT =
342     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_UDP),
343   VIRTCHNL_PROTO_HDR_UDP_DST_PORT,
344   VIRTCHNL_PROTO_HDR_UDP_CHKSUM,
345   /* SCTP */
346   VIRTCHNL_PROTO_HDR_SCTP_SRC_PORT =
347     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_SCTP),
348   VIRTCHNL_PROTO_HDR_SCTP_DST_PORT,
349   VIRTCHNL_PROTO_HDR_SCTP_CHKSUM,
350   /* GTPU_IP */
351   VIRTCHNL_PROTO_HDR_GTPU_IP_TEID =
352     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_GTPU_IP),
353   /* GTPU_EH */
354   VIRTCHNL_PROTO_HDR_GTPU_EH_PDU =
355     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_GTPU_EH),
356   VIRTCHNL_PROTO_HDR_GTPU_EH_QFI,
357   /* PPPOE */
358   VIRTCHNL_PROTO_HDR_PPPOE_SESS_ID =
359     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_PPPOE),
360   /* L2TPV3 */
361   VIRTCHNL_PROTO_HDR_L2TPV3_SESS_ID =
362     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_L2TPV3),
363   /* ESP */
364   VIRTCHNL_PROTO_HDR_ESP_SPI = PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_ESP),
365   /* AH */
366   VIRTCHNL_PROTO_HDR_AH_SPI = PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_AH),
367   /* PFCP */
368   VIRTCHNL_PROTO_HDR_PFCP_S_FIELD =
369     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_PFCP),
370   VIRTCHNL_PROTO_HDR_PFCP_SEID,
371   /* GTPC */
372   VIRTCHNL_PROTO_HDR_GTPC_TEID =
373     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_GTPC),
374   /* ECPRI */
375   VIRTCHNL_PROTO_HDR_ECPRI_MSG_TYPE =
376     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_ECPRI),
377   VIRTCHNL_PROTO_HDR_ECPRI_PC_RTC_ID,
378   /* IPv4 Dummy Fragment */
379   VIRTCHNL_PROTO_HDR_IPV4_FRAG_PKID =
380     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_IPV4_FRAG),
381   /* IPv6 Extension Fragment */
382   VIRTCHNL_PROTO_HDR_IPV6_EH_FRAG_PKID =
383     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_IPV6_EH_FRAG),
384   /* GTPU_DWN/UP */
385   VIRTCHNL_PROTO_HDR_GTPU_DWN_QFI =
386     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_DWN),
387   VIRTCHNL_PROTO_HDR_GTPU_UP_QFI =
388     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_UP),
389   /* L2TPv2 */
390   VIRTCHNL_PROTO_HDR_L2TPV2_SESS_ID =
391     PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_L2TPV2),
392   VIRTCHNL_PROTO_HDR_L2TPV2_LEN_SESS_ID,
393 };
394
395 struct virtchnl_proto_hdr
396 {
397   enum virtchnl_proto_hdr_type type;
398   u32 field_selector; /* a bit mask to select field for header type */
399   u8 buffer[64];
400   /**
401    * binary buffer in network order for specific header type.
402    * For example, if type = VIRTCHNL_PROTO_HDR_IPV4, a IPv4
403    * header is expected to be copied into the buffer.
404    */
405 };
406
407 VIRTCHNL_CHECK_STRUCT_LEN (72, virtchnl_proto_hdr);
408
409 struct virtchnl_proto_hdrs
410 {
411   u8 tunnel_level;
412   /**
413    * specify where protocol header start from. Must be 0 when sending a generic
414    * packet request. 0 - from the outer layer 1 - from the first inner layer 2
415    *- from the second inner layer
416    * ....
417    **/
418   int count;
419   /**
420    * the proto layers must < VIRTCHNL_MAX_NUM_PROTO_HDRS.
421    * Must be 0 when sending a generic packet request.
422    **/
423   union
424   {
425     struct virtchnl_proto_hdr proto_hdr[VIRTCHNL_MAX_NUM_PROTO_HDRS];
426     struct
427     {
428       u16 pkt_len;
429       u8 spec[VIRTCHNL_MAX_SIZE_GEN_PACKET];
430       u8 mask[VIRTCHNL_MAX_SIZE_GEN_PACKET];
431     } raw;
432   };
433 };
434
435 VIRTCHNL_CHECK_STRUCT_LEN (2312, virtchnl_proto_hdrs);
436
437 /* VIRTCHNL_OP_CONFIG_RSS_KEY
438  * VIRTCHNL_OP_CONFIG_RSS_LUT
439  * VF sends these messages to configure RSS. Only supported if both PF
440  * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during
441  * configuration negotiation. If this is the case, then the RSS fields in
442  * the VF resource struct are valid.
443  * Both the key and LUT are initialized to 0 by the PF, meaning that
444  * RSS is effectively disabled until set up by the VF.
445  */
446 struct virtchnl_rss_key
447 {
448   u16 vsi_id;
449   u16 key_len;
450   u8 key[1]; /* RSS hash key, packed bytes */
451 };
452
453 VIRTCHNL_CHECK_STRUCT_LEN (6, virtchnl_rss_key);
454
455 struct virtchnl_rss_lut
456 {
457   u16 vsi_id;
458   u16 lut_entries;
459   u8 lut[1]; /* RSS lookup table */
460 };
461
462 VIRTCHNL_CHECK_STRUCT_LEN (6, virtchnl_rss_lut);
463
464 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS
465  * VIRTCHNL_OP_SET_RSS_HENA
466  * VF sends these messages to get and set the hash filter enable bits for RSS.
467  * By default, the PF sets these to all possible traffic types that the
468  * hardware supports. The VF can query this value if it wants to change the
469  * traffic types that are hashed by the hardware.
470  */
471 struct virtchnl_rss_hena
472 {
473   u64 hena;
474 };
475
476 VIRTCHNL_CHECK_STRUCT_LEN (8, virtchnl_rss_hena);
477
478 /* Type of RSS algorithm */
479 enum virtchnl_rss_algorithm
480 {
481   VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC = 0,
482   VIRTCHNL_RSS_ALG_XOR_ASYMMETRIC = 1,
483   VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC = 2,
484   VIRTCHNL_RSS_ALG_XOR_SYMMETRIC = 3,
485 };
486
487 struct virtchnl_rss_cfg
488 {
489   struct virtchnl_proto_hdrs proto_hdrs;     /* protocol headers */
490   enum virtchnl_rss_algorithm rss_algorithm; /* rss algorithm type */
491   u8 reserved[128];                          /* reserve for future */
492 };
493
494 VIRTCHNL_CHECK_STRUCT_LEN (2444, virtchnl_rss_cfg);
495
496 struct avf_pattern_match_item
497 {
498   enum avf_flow_item_type *pattern_list;
499   u64 input_set_mask;
500   void *meta;
501 };
502
503 enum avf_flow_item_type
504 {
505   AVF_FLOW_ITEM_TYPE_END,
506   AVF_FLOW_ITEM_TYPE_VOID,
507   AVF_FLOW_ITEM_TYPE_INVERT,
508   AVF_FLOW_ITEM_TYPE_ANY,
509   AVF_FLOW_ITEM_TYPE_PORT_ID,
510   AVF_FLOW_ITEM_TYPE_RAW,
511   AVF_FLOW_ITEM_TYPE_ETH,
512   AVF_FLOW_ITEM_TYPE_VLAN,
513   AVF_FLOW_ITEM_TYPE_IPV4,
514   AVF_FLOW_ITEM_TYPE_IPV6,
515   AVF_FLOW_ITEM_TYPE_ICMP,
516   AVF_FLOW_ITEM_TYPE_UDP,
517   AVF_FLOW_ITEM_TYPE_TCP,
518   AVF_FLOW_ITEM_TYPE_SCTP,
519   AVF_FLOW_ITEM_TYPE_VXLAN,
520   AVF_FLOW_ITEM_TYPE_E_TAG,
521   AVF_FLOW_ITEM_TYPE_NVGRE,
522   AVF_FLOW_ITEM_TYPE_MPLS,
523   AVF_FLOW_ITEM_TYPE_GRE,
524   AVF_FLOW_ITEM_TYPE_FUZZY,
525   AVF_FLOW_ITEM_TYPE_GTP,
526   AVF_FLOW_ITEM_TYPE_GTPC,
527   AVF_FLOW_ITEM_TYPE_GTPU,
528   AVF_FLOW_ITEM_TYPE_ESP,
529   AVF_FLOW_ITEM_TYPE_GENEVE,
530   AVF_FLOW_ITEM_TYPE_VXLAN_GPE,
531   AVF_FLOW_ITEM_TYPE_ARP_ETH_IPV4,
532   AVF_FLOW_ITEM_TYPE_IPV6_EXT,
533   AVF_FLOW_ITEM_TYPE_ICMP6,
534   AVF_FLOW_ITEM_TYPE_ICMP6_ND_NS,
535   AVF_FLOW_ITEM_TYPE_ICMP6_ND_NA,
536   AVF_FLOW_ITEM_TYPE_ICMP6_ND_OPT,
537   AVF_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH,
538   AVF_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH,
539   AVF_FLOW_ITEM_TYPE_MARK,
540   AVF_FLOW_ITEM_TYPE_META,
541   AVF_FLOW_ITEM_TYPE_GRE_KEY,
542   AVF_FLOW_ITEM_TYPE_GTP_PSC,
543   AVF_FLOW_ITEM_TYPE_PPPOES,
544   AVF_FLOW_ITEM_TYPE_PPPOED,
545   AVF_FLOW_ITEM_TYPE_PPPOE_PROTO_ID,
546   AVF_FLOW_ITEM_TYPE_NSH,
547   AVF_FLOW_ITEM_TYPE_IGMP,
548   AVF_FLOW_ITEM_TYPE_AH,
549   AVF_FLOW_ITEM_TYPE_HIGIG2,
550   AVF_FLOW_ITEM_TYPE_TAG,
551   AVF_FLOW_ITEM_TYPE_L2TPV3OIP,
552   AVF_FLOW_ITEM_TYPE_PFCP,
553   AVF_FLOW_ITEM_TYPE_ECPRI,
554   AVF_FLOW_ITEM_TYPE_IPV6_FRAG_EXT,
555   AVF_FLOW_ITEM_TYPE_GENEVE_OPT,
556   AVF_FLOW_ITEM_TYPE_INTEGRITY,
557   AVF_FLOW_ITEM_TYPE_CONNTRACK,
558   AVF_FLOW_ITEM_TYPE_PORT_REPRESENTOR,
559   AVF_FLOW_ITEM_TYPE_REPRESENTED_PORT,
560   AVF_FLOW_ITEM_TYPE_FLEX,
561   AVF_FLOW_ITEM_TYPE_L2TPV2,
562   AVF_FLOW_ITEM_TYPE_PPP,
563   AVF_FLOW_ITEM_TYPE_GRE_OPTION,
564   AVF_FLOW_ITEM_TYPE_MACSEC,
565   AVF_FLOW_ITEM_TYPE_METER_COLOR,
566 };
567
568 enum avf_flow_action_type
569 {
570   AVF_FLOW_ACTION_TYPE_END,
571   AVF_FLOW_ACTION_TYPE_VOID,
572   AVF_FLOW_ACTION_TYPE_PASSTHRU,
573   AVF_FLOW_ACTION_TYPE_JUMP,
574   AVF_FLOW_ACTION_TYPE_MARK,
575   AVF_FLOW_ACTION_TYPE_FLAG,
576   AVF_FLOW_ACTION_TYPE_QUEUE,
577   AVF_FLOW_ACTION_TYPE_DROP,
578   AVF_FLOW_ACTION_TYPE_COUNT,
579   AVF_FLOW_ACTION_TYPE_RSS,
580   AVF_FLOW_ACTION_TYPE_PF,
581   AVF_FLOW_ACTION_TYPE_VF,
582   AVF_FLOW_ACTION_TYPE_PORT_ID,
583   AVF_FLOW_ACTION_TYPE_METER,
584   AVF_FLOW_ACTION_TYPE_SECURITY,
585   AVF_FLOW_ACTION_TYPE_OF_DEC_NW_TTL,
586   AVF_FLOW_ACTION_TYPE_OF_POP_VLAN,
587   AVF_FLOW_ACTION_TYPE_OF_PUSH_VLAN,
588   AVF_FLOW_ACTION_TYPE_OF_SET_VLAN_VID,
589   AVF_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP,
590   AVF_FLOW_ACTION_TYPE_OF_POP_MPLS,
591   AVF_FLOW_ACTION_TYPE_OF_PUSH_MPLS,
592   AVF_FLOW_ACTION_TYPE_VXLAN_ENCAP,
593   AVF_FLOW_ACTION_TYPE_VXLAN_DECAP,
594   AVF_FLOW_ACTION_TYPE_NVGRE_ENCAP,
595   AVF_FLOW_ACTION_TYPE_NVGRE_DECAP,
596   AVF_FLOW_ACTION_TYPE_RAW_ENCAP,
597   AVF_FLOW_ACTION_TYPE_RAW_DECAP,
598   AVF_FLOW_ACTION_TYPE_SET_IPV4_SRC,
599   AVF_FLOW_ACTION_TYPE_SET_IPV4_DST,
600   AVF_FLOW_ACTION_TYPE_SET_IPV6_SRC,
601   AVF_FLOW_ACTION_TYPE_SET_IPV6_DST,
602   AVF_FLOW_ACTION_TYPE_SET_TP_SRC,
603   AVF_FLOW_ACTION_TYPE_SET_TP_DST,
604   AVF_FLOW_ACTION_TYPE_MAC_SWAP,
605   AVF_FLOW_ACTION_TYPE_DEC_TTL,
606   AVF_FLOW_ACTION_TYPE_SET_TTL,
607   AVF_FLOW_ACTION_TYPE_SET_MAC_SRC,
608   AVF_FLOW_ACTION_TYPE_SET_MAC_DST,
609   AVF_FLOW_ACTION_TYPE_INC_TCP_SEQ,
610   AVF_FLOW_ACTION_TYPE_DEC_TCP_SEQ,
611   AVF_FLOW_ACTION_TYPE_INC_TCP_ACK,
612   AVF_FLOW_ACTION_TYPE_DEC_TCP_ACK,
613   AVF_FLOW_ACTION_TYPE_SET_TAG,
614   AVF_FLOW_ACTION_TYPE_SET_META,
615   AVF_FLOW_ACTION_TYPE_SET_IPV4_DSCP,
616   AVF_FLOW_ACTION_TYPE_SET_IPV6_DSCP,
617   AVF_FLOW_ACTION_TYPE_AGE,
618   AVF_FLOW_ACTION_TYPE_SAMPLE,
619   AVF_FLOW_ACTION_TYPE_SHARED,
620   AVF_FLOW_ACTION_TYPE_MODIFY_FIELD,
621   AVF_FLOW_ACTION_TYPE_INDIRECT,
622   AVF_FLOW_ACTION_TYPE_CONNTRACK,
623   AVF_FLOW_ACTION_TYPE_METER_COLOR,
624   AVF_FLOW_ACTION_TYPE_PORT_REPRESENTOR,
625   AVF_FLOW_ACTION_TYPE_REPRESENTED_PORT,
626   AVF_FLOW_ACTION_TYPE_METER_MARK,
627   AVF_FLOW_ACTION_TYPE_SEND_TO_KERNEL,
628 };
629
630 enum virtchnl_action
631 {
632   /* action types */
633   VIRTCHNL_ACTION_DROP = 0,
634   VIRTCHNL_ACTION_TC_REDIRECT,
635   VIRTCHNL_ACTION_PASSTHRU,
636   VIRTCHNL_ACTION_QUEUE,
637   VIRTCHNL_ACTION_Q_REGION,
638   VIRTCHNL_ACTION_MARK,
639   VIRTCHNL_ACTION_COUNT,
640   VIRTCHNL_ACTION_NONE,
641 };
642
643 /* action configuration for FDIR */
644 struct virtchnl_filter_action
645 {
646   enum virtchnl_action type;
647   union
648   {
649     /* used for queue and qgroup action */
650     struct
651     {
652       u16 index;
653       u8 region;
654     } queue;
655     /* used for count action */
656     struct
657     {
658       /* share counter ID with other flow rules */
659       u8 shared;
660       u32 id; /* counter ID */
661     } count;
662     /* used for mark action */
663     u32 mark_id;
664     u8 reserve[32];
665   } act_conf;
666 };
667
668 VIRTCHNL_CHECK_STRUCT_LEN (36, virtchnl_filter_action);
669
670 #define VIRTCHNL_MAX_NUM_ACTIONS 8
671
672 struct virtchnl_filter_action_set
673 {
674   /* action number must be less then VIRTCHNL_MAX_NUM_ACTIONS */
675   int count;
676   struct virtchnl_filter_action actions[VIRTCHNL_MAX_NUM_ACTIONS];
677 };
678
679 VIRTCHNL_CHECK_STRUCT_LEN (292, virtchnl_filter_action_set);
680
681 /* pattern and action for FDIR rule */
682 struct virtchnl_fdir_rule
683 {
684   struct virtchnl_proto_hdrs proto_hdrs;
685   struct virtchnl_filter_action_set action_set;
686 };
687
688 VIRTCHNL_CHECK_STRUCT_LEN (2604, virtchnl_fdir_rule);
689
690 /* query information to retrieve fdir rule counters.
691  * PF will fill out this structure to reset counter.
692  */
693 struct virtchnl_fdir_query_info
694 {
695   u32 match_packets_valid : 1;
696   u32 match_bytes_valid : 1;
697   u32 reserved : 30; /* Reserved, must be zero. */
698   u32 pad;
699   u64 matched_packets; /* Number of packets for this rule. */
700   u64 matched_bytes;   /* Number of bytes through this rule. */
701 };
702
703 VIRTCHNL_CHECK_STRUCT_LEN (24, virtchnl_fdir_query_info);
704
705 /* Status returned to VF after VF requests FDIR commands
706  * VIRTCHNL_FDIR_SUCCESS
707  * VF FDIR related request is successfully done by PF
708  * The request can be OP_ADD/DEL/QUERY_FDIR_FILTER.
709  *
710  * VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE
711  * OP_ADD_FDIR_FILTER request is failed due to no Hardware resource.
712  *
713  * VIRTCHNL_FDIR_FAILURE_RULE_EXIST
714  * OP_ADD_FDIR_FILTER request is failed due to the rule is already existed.
715  *
716  * VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT
717  * OP_ADD_FDIR_FILTER request is failed due to conflict with existing rule.
718  *
719  * VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST
720  * OP_DEL_FDIR_FILTER request is failed due to this rule doesn't exist.
721  *
722  * VIRTCHNL_FDIR_FAILURE_RULE_INVALID
723  * OP_ADD_FDIR_FILTER request is failed due to parameters validation
724  * or HW doesn't support.
725  *
726  * VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT
727  * OP_ADD/DEL_FDIR_FILTER request is failed due to timing out
728  * for programming.
729  *
730  * VIRTCHNL_FDIR_FAILURE_QUERY_INVALID
731  * OP_QUERY_FDIR_FILTER request is failed due to parameters validation,
732  * for example, VF query counter of a rule who has no counter action.
733  */
734 enum virtchnl_fdir_prgm_status
735 {
736   VIRTCHNL_FDIR_SUCCESS = 0,
737   VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE,
738   VIRTCHNL_FDIR_FAILURE_RULE_EXIST,
739   VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT,
740   VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST,
741   VIRTCHNL_FDIR_FAILURE_RULE_INVALID,
742   VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT,
743   VIRTCHNL_FDIR_FAILURE_QUERY_INVALID,
744   VIRTCHNL_FDIR_FAILURE_MAX,
745 };
746
747 /* VIRTCHNL_OP_ADD_FDIR_FILTER
748  * VF sends this request to PF by filling out vsi_id,
749  * validate_only and rule_cfg. PF will return flow_id
750  * if the request is successfully done and return add_status to VF.
751  */
752 struct virtchnl_fdir_add
753 {
754   u16 vsi_id; /* INPUT */
755   /*
756    * 1 for validating a fdir rule, 0 for creating a fdir rule.
757    * Validate and create share one ops: VIRTCHNL_OP_ADD_FDIR_FILTER.
758    */
759   u16 validate_only;                     /* INPUT */
760   u32 flow_id;                           /* OUTPUT */
761   struct virtchnl_fdir_rule rule_cfg;    /* INPUT */
762   enum virtchnl_fdir_prgm_status status; /* OUTPUT */
763 };
764
765 VIRTCHNL_CHECK_STRUCT_LEN (2616, virtchnl_fdir_add);
766
767 /* VIRTCHNL_OP_DEL_FDIR_FILTER
768  * VF sends this request to PF by filling out vsi_id
769  * and flow_id. PF will return del_status to VF.
770  */
771 struct virtchnl_fdir_del
772 {
773   u16 vsi_id; /* INPUT */
774   u16 pad;
775   u32 flow_id;                           /* INPUT */
776   enum virtchnl_fdir_prgm_status status; /* OUTPUT */
777 };
778
779 VIRTCHNL_CHECK_STRUCT_LEN (12, virtchnl_fdir_del);
780
781 /* VIRTCHNL_OP_QUERY_FDIR_FILTER
782  * VF sends this request to PF by filling out vsi_id,
783  * flow_id and reset_counter. PF will return query_info
784  * and query_status to VF.
785  */
786 struct virtchnl_fdir_query
787 {
788   u16 vsi_id; /* INPUT */
789   u16 pad1[3];
790   u32 flow_id;                                /* INPUT */
791   u32 reset_counter : 1;                      /* INPUT */
792   struct virtchnl_fdir_query_info query_info; /* OUTPUT */
793   enum virtchnl_fdir_prgm_status status;      /* OUTPUT */
794   u32 pad2;
795 };
796
797 VIRTCHNL_CHECK_STRUCT_LEN (48, virtchnl_fdir_query);
798
799 /**
800  * Those headers used temporary, maybe OS packet
801  * definition can replace. Add flow error, pattern
802  * and action definition.
803  */
804
805 /**
806  * Verbose error types.
807  *
808  * Most of them provide the type of the object referenced by struct
809  * rte_flow_error.cause.
810  */
811 enum avf_flow_error_type
812 {
813   AVF_FLOW_ERROR_TYPE_NONE,          /**< No error. */
814   AVF_FLOW_ERROR_TYPE_UNSPECIFIED,   /**< Cause unspecified. */
815   AVF_FLOW_ERROR_TYPE_HANDLE,        /**< Flow rule (handle). */
816   AVF_FLOW_ERROR_TYPE_ATTR_GROUP,    /**< Group field. */
817   AVF_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
818   AVF_FLOW_ERROR_TYPE_ATTR_INGRESS,  /**< Ingress field. */
819   AVF_FLOW_ERROR_TYPE_ATTR_EGRESS,   /**< Egress field. */
820   AVF_FLOW_ERROR_TYPE_ATTR_TRANSFER, /**< Transfer field. */
821   AVF_FLOW_ERROR_TYPE_ATTR,          /**< Attributes structure. */
822   AVF_FLOW_ERROR_TYPE_ITEM_NUM,      /**< Pattern length. */
823   AVF_FLOW_ERROR_TYPE_ITEM_SPEC,     /**< Item specification. */
824   AVF_FLOW_ERROR_TYPE_ITEM_LAST,     /**< Item specification range. */
825   AVF_FLOW_ERROR_TYPE_ITEM_MASK,     /**< Item specification mask. */
826   AVF_FLOW_ERROR_TYPE_ITEM,          /**< Specific pattern item. */
827   AVF_FLOW_ERROR_TYPE_ACTION_NUM,    /**< Number of actions. */
828   AVF_FLOW_ERROR_TYPE_ACTION_CONF,   /**< Action configuration. */
829   AVF_FLOW_ERROR_TYPE_ACTION,        /**< Specific action. */
830 };
831
832 /**
833  * Verbose error structure definition.
834  * Both cause and message may be NULL regardless of the error type.
835  */
836 struct avf_flow_error
837 {
838   enum avf_flow_error_type type; /**< Cause field and error types. */
839   const void *cause;             /**< Object responsible for the error. */
840   const char *message;           /**< Human-readable error message. */
841 };
842
843 #define AVF_ETHER_ADDR_LEN 6
844 struct avf_ether_addr
845 {
846   u8 addr_bytes[AVF_ETHER_ADDR_LEN]; /**< Addr bytes in tx order */
847 } __attribute__ ((__aligned__ (2)));
848
849 struct avf_flow_eth_hdr
850 {
851   struct avf_ether_addr dst; /**< Destination MAC. */
852   struct avf_ether_addr src; /**< Source MAC. */
853   u16 type;                  /**< EtherType or TPID. */
854 };
855
856 /**
857  * IPv4 Header
858  */
859 struct avf_ipv4_hdr
860 {
861   u8 version_ihl;      /**< version and header length */
862   u8 type_of_service;  /**< type of service */
863   u16 total_length;    /**< length of packet */
864   u16 packet_id;       /**< packet ID */
865   u16 fragment_offset; /**< fragmentation offset */
866   u8 time_to_live;     /**< time to live */
867   u8 next_proto_id;    /**< protocol ID */
868   u16 hdr_checksum;    /**< header checksum */
869   u32 src_addr;        /**< source address */
870   u32 dst_addr;        /**< destination address */
871 } __attribute__ ((__packed__));
872
873 /**
874  * IPv6 Header
875  */
876 struct avf_ipv6_hdr
877 {
878   u32 vtc_flow;    /**< IP version, traffic class & flow label. */
879   u16 payload_len; /**< IP packet length - includes header size */
880   u8 proto;        /**< Protocol, next header. */
881   u8 hop_limits;   /**< Hop limits. */
882   u8 src_addr[16]; /**< IP address of source host. */
883   u8 dst_addr[16]; /**< IP address of destination host(s). */
884 } __attribute__ ((__packed__));
885
886 /**
887  * TCP Header
888  */
889 struct avf_tcp_hdr
890 {
891   u16 src_port; /**< TCP source port. */
892   u16 dst_port; /**< TCP destination port. */
893   u32 sent_seq; /**< TX data sequence number. */
894   u32 recv_ack; /**< RX data acknowledgment sequence number. */
895   u8 data_off;  /**< Data offset. */
896   u8 tcp_flags; /**< TCP flags */
897   u16 rx_win;   /**< RX flow control window. */
898   u16 cksum;    /**< TCP checksum. */
899   u16 tcp_urp;  /**< TCP urgent pointer, if any. */
900 } __attribute__ ((__packed__));
901
902 /**
903  * UDP Header
904  */
905 struct avf_udp_hdr
906 {
907   u16 src_port;    /**< UDP source port. */
908   u16 dst_port;    /**< UDP destination port. */
909   u16 dgram_len;   /**< UDP datagram length */
910   u16 dgram_cksum; /**< UDP datagram checksum */
911 } __attribute__ ((__packed__));
912
913 /**
914  * Match IP Authentication Header (AH), RFC 4302
915  */
916 struct avf_ah_hdr
917 {
918   u32 next_hdr : 8;
919   u32 payload_len : 8;
920   u32 reserved : 16;
921   u32 spi;
922   u32 seq_num;
923 };
924
925 /**
926  * ESP Header
927  */
928 struct avf_esp_hdr
929 {
930   u32 spi; /**< Security Parameters Index */
931   u32 seq; /**< packet sequence number */
932 } __attribute__ ((__packed__));
933
934 /**
935  * Match PFCP Header
936  */
937 struct avf_pfcp_hdr
938 {
939   u8 s_field;
940   u8 msg_type;
941   u16 msg_len;
942   u64 seid;
943 };
944
945 /**
946  * Matches a L2TPv3 over IP header.
947  */
948 struct avf_l2tpv3oip_hdr
949 {
950   u32 session_id; /**< Session ID. */
951 };
952
953 /**
954  * Matches a GTP PDU extension header with type 0x85.
955  */
956 struct avf_gtp_psc_hdr
957 {
958   u8 pdu_type; /**< PDU type. */
959   u8 qfi;      /**< QoS flow identifier. */
960 };
961
962 /**
963  * Matches a GTPv1 header.
964  */
965 struct avf_gtp_hdr
966 {
967   /**
968    * Version (3b), protocol type (1b), reserved (1b),
969    * Extension header flag (1b),
970    * Sequence number flag (1b),
971    * N-PDU number flag (1b).
972    */
973   u8 v_pt_rsv_flags;
974   u8 msg_type; /**< Message type. */
975   u16 msg_len; /**< Message length. */
976   u32 teid;    /**< Tunnel endpoint identifier. */
977 };
978
979 /**
980  * SCTP Header
981  */
982 struct avf_sctp_hdr
983 {
984   u16 src_port; /**< Source port. */
985   u16 dst_port; /**< Destin port. */
986   u32 tag;      /**< Validation tag. */
987   u32 cksum;    /**< Checksum. */
988 } __attribute__ ((__packed__));
989
990 /**
991  * Hash function types.
992  */
993 enum avf_eth_hash_function
994 {
995   AVF_ETH_HASH_FUNCTION_DEFAULT = 0,
996   AVF_ETH_HASH_FUNCTION_TOEPLITZ,   /**< Toeplitz */
997   AVF_ETH_HASH_FUNCTION_SIMPLE_XOR, /**< Simple XOR */
998   /**
999    * Symmetric Toeplitz: src, dst will be replaced by
1000    * xor(src, dst). For the case with src/dst only,
1001    * src or dst address will xor with zero pair.
1002    */
1003   AVF_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ,
1004   AVF_ETH_HASH_FUNCTION_MAX,
1005 };
1006
1007 struct avf_flow_action_rss
1008 {
1009   enum avf_eth_hash_function func; /**< RSS hash function to apply. */
1010
1011   u32 level;
1012   u64 types;        /**< Specific RSS hash types (see ETH_RSS_*). */
1013   u32 key_len;      /**< Hash key length in bytes. */
1014   u32 queue_num;    /**< Number of entries in @p queue. */
1015   const u8 *key;    /**< Hash key. */
1016   const u16 *queue; /**< Queue indices to use. */
1017 };
1018
1019 struct avf_flow_action_queue
1020 {
1021   u16 index; /**< Queue index to use. */
1022 };
1023
1024 struct avf_flow_action_mark
1025 {
1026   u32 id; /**< Integer value to return with packets. */
1027 };
1028
1029 struct avf_flow_action
1030 {
1031   enum avf_flow_action_type type; /**< Action type. */
1032   const void *conf;          /**< Pointer to action configuration object. */
1033 };
1034
1035 struct avf_flow_item
1036 {
1037   enum avf_flow_item_type type; /**< Item type. */
1038   const void *spec; /**< Pointer to item specification structure. */
1039   const void *mask; /**< Bit-mask applied to spec and last. */
1040   int is_generic;   /* indicate if this item is for a generic flow pattern. */
1041 };
1042
1043 struct avf_fdir_conf
1044 {
1045   struct virtchnl_fdir_add add_fltr;
1046   struct virtchnl_fdir_del del_fltr;
1047   u64 input_set;
1048   u32 flow_id;
1049   u32 mark_flag;
1050   u32 vsi;
1051   u32 nb_rx_queues;
1052 };
1053
1054 enum virthnl_adv_ops
1055 {
1056   VIRTCHNL_ADV_OP_ADD_FDIR_FILTER = 0,
1057   VIRTCHNL_ADV_OP_DEL_FDIR_FILTER,
1058   VIRTCHNL_ADV_OP_QUERY_FDIR_FILTER,
1059   VIRTCHNL_ADV_OP_ADD_RSS_CFG,
1060   VIRTCHNL_ADV_OP_DEL_RSS_CFG,
1061   VIRTCHNL_ADV_OP_MAX
1062 };
1063
1064 /* virtual channel op handler */
1065 typedef int (*avf_flow_vc_op_t) (void *vc_hdl, enum virthnl_adv_ops vc_op,
1066                                  void *in, u32 in_len, void *out, u32 out_len);
1067
1068 /* virtual channel context object */
1069 struct avf_flow_vc_ctx
1070 {
1071   void *vc_hdl; /* virtual channel handler */
1072   avf_flow_vc_op_t vc_op;
1073 };
1074
1075 /**
1076  * Create a rule cfg object.
1077  *
1078  * @param rcfg
1079  *      created rule cfg object.
1080  * @param tunnel
1081  *      tunnel level where protocol header start from
1082  *      0 from moster outer layer.
1083  *      1 from first inner layer.
1084  *      2 form second inner layer.
1085  *      ...
1086  * @param vsi
1087  *      avf vsi id
1088  *
1089  * @param nrxq
1090  *      the rx queue number of the avf
1091  *
1092  * @return
1093  *      0 = successful.
1094  *      < 0 = failure.
1095  */
1096 int avf_fdir_rcfg_create (struct avf_fdir_conf **rcfg, int tunnel_level,
1097                           u16 vsi, u16 nrxq);
1098
1099 /**
1100  * Destroy a rule cfg object.
1101  *
1102  * @param rcfg
1103  *      the cfg object to destroy.
1104  *
1105  * @return
1106  *      0 = successful.
1107  *      < 0 = failure.
1108  */
1109 int avf_fdir_rcfg_destroy (struct avf_fdir_conf *rcfg);
1110
1111 /**
1112  * Set match potocol header on specific layer, it will overwrite is already be
1113  * set.
1114  *
1115  * @param rcfg
1116  *      the rule cfg object
1117  * @param layer
1118  *      layer of the protocol header.
1119  * @param hdr
1120  *      protocol header type.
1121  *
1122  * @return
1123  *      0 = successful.
1124  *      < 0 = failure.
1125  */
1126 int avf_fdir_rcfg_set_hdr (struct avf_fdir_conf *rcfg, int layer,
1127                            enum virtchnl_proto_hdr_type hdr);
1128
1129 /**
1130  * Set a match field on specific protocol layer, if any match field already be
1131  * set on this layer, it will be overwritten.
1132  *
1133  * @param rcfg
1134  *      the rule cfg object
1135  * @param layer
1136  *      layer of the protocol header.
1137  * @param item
1138  *      flow item
1139  * @param error
1140  *      save error cause
1141  *
1142  * @return
1143  *      0 = successful.
1144  *      < 0 = failure.
1145  */
1146 int avf_fdir_rcfg_set_field (struct avf_fdir_conf *rcfg, int layer,
1147                              struct avf_flow_item *item,
1148                              struct avf_flow_error *error);
1149
1150 /**
1151  * Set action as to queue(group), conflict with drop action.
1152  *
1153  * @param rcfg
1154  *      rule cfg object
1155  * @param queue
1156  *      queue id.
1157  * @param size
1158  *      queue group size, must be 2^n. 1 means only to single queue.
1159  * @param act_idx
1160  *      action index
1161  *
1162  * @return
1163  *      0 = successful.
1164  *      < 0 = failure.
1165  */
1166 int avf_fdir_rcfg_act_queue (struct avf_fdir_conf *rcfg, int queue, int size,
1167                              int act_idx);
1168
1169 /**
1170  * Set action as to queue group, conflict with drop action.
1171  *
1172  * @param rcfg
1173  *      the rule cfg object
1174  * @param act
1175  *      flow actions
1176  * @param act_idx
1177  *      action index
1178  * @error
1179  *      save error cause
1180  *
1181  * @return
1182  *      0 = successful.
1183  *      < 0 = failure.
1184  */
1185 int avf_fdir_parse_action_qregion (struct avf_fdir_conf *rcfg,
1186                                    const struct avf_flow_action *act,
1187                                    int act_idx, struct avf_flow_error *error);
1188
1189 /**
1190  * Set action as as drop, conflict with to queue(gropu) action.
1191  *
1192  * @param rcfg
1193  *      the rule cfg object
1194  * @param act_idx
1195  *      action index
1196  *
1197  * @return
1198  *      0 = successful.
1199  *      < 0 = failure.
1200  */
1201 int avf_fdir_rcfg_act_drop (struct avf_fdir_conf *rcfg, int act_idx);
1202
1203 /**
1204  * Set action as mark, it can co-exist with to queue(group) or drop action.
1205  *
1206  * @param rcfg
1207  *      the rule cfg object
1208  * @param mark
1209  *      a 32 bit flow mark
1210  * @param act_idx
1211  *      action index
1212  *
1213  * @return
1214  *      0 = successful.
1215  *      < 0 = failure.
1216  */
1217 int avf_fdir_rcfg_act_mark (struct avf_fdir_conf *rcfg, const u32 mark,
1218                             int act_idx);
1219
1220 /**
1221  * Validate a flow rule cfg, check with PF driver if the rule cfg is supportted
1222  *or not.
1223  *
1224  * @param ctx
1225  *       virtual channel context
1226  * @param rcfg
1227  *      the rule cfg object.
1228  *
1229  * @return
1230  *      0 = successful.
1231  *      < 0 = failure.
1232  */
1233 int avf_fdir_rcfg_validate (struct avf_flow_vc_ctx *ctx,
1234                             struct avf_fdir_conf *rcfg);
1235
1236 /**
1237  * Create a flow rule, a FDIR rule is expected to be programmed into hardware
1238  *if return success.
1239  *
1240  * @param ctx
1241  *       virtual channel context
1242  * @param rcfg
1243  *      rule cfg object.
1244  *
1245  * @return
1246  *      0 = successfule.
1247  *      < 0 = failure.
1248  */
1249 int avf_fdir_rule_create (struct avf_flow_vc_ctx *ctx,
1250                           struct avf_fdir_conf *rcfg);
1251
1252 /**
1253  * Destroy a flow rule.
1254  *
1255  * @param ctx
1256  *       virtual channel context
1257  * @param rcfg
1258  *      the rule cfg object.
1259  *
1260  * @return
1261  *      0 = successfule.
1262  *      < 0 = failure.
1263  */
1264 int avf_fdir_rule_destroy (struct avf_flow_vc_ctx *ctx,
1265                            struct avf_fdir_conf *rcfg);
1266
1267 /*
1268  * Parse avf patterns and set pattern fields.
1269  *
1270  * @param rcfg
1271  *      flow config
1272  * @param avf_items
1273  *      pattern items
1274  * @param error
1275  *      save error cause
1276  *
1277  * @return
1278  *      0 = successful.
1279  *      < 0 = failure
1280  */
1281 int avf_fdir_parse_pattern (struct avf_fdir_conf *rcfg,
1282                             struct avf_flow_item avf_items[],
1283                             struct avf_flow_error *error);
1284
1285 /*
1286  * Parse avf patterns for generic flow and set pattern fields.
1287  *
1288  * @param rcfg
1289  *      flow config
1290  * @param avf_items
1291  *      pattern items
1292  * @param error
1293  *      save error cause
1294  *
1295  * @return
1296  *      0 = successful.
1297  *      < 0 = failure
1298  */
1299 int avf_fdir_parse_generic_pattern (struct avf_fdir_conf *rcfg,
1300                                     struct avf_flow_item avf_items[],
1301                                     struct avf_flow_error *error);
1302
1303 /*
1304  * Parse flow actions, set actions.
1305  *
1306  * @param actions
1307  *      flow actions
1308  * @param rcfg
1309  *      flow config
1310  * @param error
1311  *      save error cause
1312  *
1313  * @return
1314  *  0 = successful.
1315  *  < 0 = failure
1316  */
1317 int avf_fdir_parse_action (const struct avf_flow_action actions[],
1318                            struct avf_fdir_conf *rcfg,
1319                            struct avf_flow_error *error);
1320
1321 /*
1322  * Parse flow patterns and rss actions, set rss config.
1323  *
1324  * @param avf_items
1325  *      flow pattern
1326  * @param avf_actions
1327  *  flow actions
1328  * @param rss_cfg
1329  *      rss config
1330  * @param error
1331  *      save error cause
1332  *
1333  * @return
1334  *  0 = successful.
1335  *  < 0 = failure
1336  */
1337 int avf_rss_parse_pattern_action (struct avf_flow_item avf_items[],
1338                                   struct avf_flow_action avf_actions[],
1339                                   struct virtchnl_rss_cfg *rss_cfg,
1340                                   struct avf_flow_error *error);
1341
1342 /**
1343  * Create a RSS rule cfg object.
1344  *
1345  * @param rss_cfg
1346  *      created rule cfg object.
1347  * @param tunnel
1348  *      tunnel level where protocol header start from
1349  *      0 from moster outer layer.
1350  *      1 from first inner layer.
1351  *      2 form second inner layer.
1352  *  Must be 0 for generic flow.
1353  *
1354  * @return
1355  *      0 = successful.
1356  *      < 0 = failure.
1357  */
1358 int avf_rss_cfg_create (struct virtchnl_rss_cfg **rss_cfg, int tunnel_level);
1359
1360 int avf_rss_rcfg_destroy (struct virtchnl_rss_cfg *rss_cfg);
1361
1362 /**
1363  * Create a RSS flow rule
1364  *
1365  * @param ctx
1366  *       virtual channel context
1367  * @param rss_cfg
1368  *      rule cfg object.
1369  *
1370  * @return
1371  *      0 = successfule.
1372  *      < 0 = failure.
1373  */
1374 int avf_rss_rule_create (struct avf_flow_vc_ctx *ctx,
1375                          struct virtchnl_rss_cfg *rss_cfg);
1376
1377 /**
1378  * Destroy a RSS flow rule
1379  *
1380  * @param ctx
1381  *       virtual channel context
1382  * @param rss_cfg
1383  *      rule cfg object.
1384  *
1385  * @return
1386  *      0 = successfule.
1387  *      < 0 = failure.
1388  */
1389 int avf_rss_rule_destroy (struct avf_flow_vc_ctx *ctx,
1390                           struct virtchnl_rss_cfg *rss_cfg);
1391
1392 /**
1393  * Parse generic flow pattern to get spec and mask
1394  *
1395  * @param item
1396  *      flow item
1397  * @param pkt_buf
1398  *      spec buffer.
1399  * @param msk_buf
1400  *      mask buffer .
1401  * @param spec_len
1402  *      length of spec.
1403  */
1404 void avf_parse_generic_pattern (struct avf_flow_item *item, u8 *pkt_buf,
1405                                 u8 *msk_buf, u16 spec_len);
1406
1407 /**
1408  * Initialize flow error structure.
1409  *
1410  * @param[out] error
1411  *   Pointer to flow error structure (may be NULL).
1412  * @param code
1413  *   Related error code
1414  * @param type
1415  *   Cause field and error types.
1416  * @param cause
1417  *   Object responsible for the error.
1418  * @param message
1419  *   Human-readable error message.
1420  *
1421  * @return
1422  *   Negative error code (errno value)
1423  */
1424 int avf_flow_error_set (struct avf_flow_error *error, int code,
1425                         enum avf_flow_error_type type, const void *cause,
1426                         const char *message);
1427
1428 /*
1429  * decode the error number to Verbose error string
1430  *
1431  * @param err_no
1432  *  error number
1433  *
1434  * @return
1435  *  Verbose error string
1436  */
1437 char *avf_fdir_prgm_error_decode (int err_no);
1438
1439 #endif /* _AVF_ADVANCED_FLOW_H_ */
1440
1441 /*
1442  * fd.io coding-style-patch-verification: ON
1443  *
1444  * Local Variables:
1445  * eval: (c-set-style "gnu")
1446  * End:
1447  */