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