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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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 *------------------------------------------------------------------
18 #ifndef _AVF_ADVANCED_FLOW_H_
19 #define _AVF_ADVANCED_FLOW_H_
21 #define AVF_SUCCESS (0)
22 #define AVF_FAILURE (-1)
24 #define BIT(a) (1UL << (a))
25 #define BIT_ULL(a) (1ULL << (a))
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
32 #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) \
33 enum virtchnl_static_assert_enum_##X \
35 virtchnl_static_assert_##X = (n) / ((sizeof (struct X) == (n)) ? 1 : 0) \
37 #define VIRTCHNL_CHECK_UNION_LEN(n, X) \
38 enum virtchnl_static_asset_enum_##X \
40 virtchnl_static_assert_##X = (n) / ((sizeof (union X) == (n)) ? 1 : 0) \
43 /* AVF ethernet frame types */
44 #define AVF_ETHER_TYPE_IPV4 0x0800 /**< IPv4 Protocol. */
45 #define AVF_ETHER_TYPE_IPV6 0x86DD /**< IPv6 Protocol. */
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)
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
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)
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))
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))
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)
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)
137 #define AVF_INSET_NONE 0ULL
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)
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)
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)
181 /* Protocol header type within a packet segment. A segment consists of one or
182 * more protocol headers that make up a logical group of protocol headers. Each
183 * logical group of protocol headers encapsulates or is encapsulated using/by
184 * tunneling or encapsulation protocols for network virtualization.
186 enum virtchnl_proto_hdr_type
188 VIRTCHNL_PROTO_HDR_NONE,
189 VIRTCHNL_PROTO_HDR_ETH,
190 VIRTCHNL_PROTO_HDR_S_VLAN,
191 VIRTCHNL_PROTO_HDR_C_VLAN,
192 VIRTCHNL_PROTO_HDR_IPV4,
193 VIRTCHNL_PROTO_HDR_IPV6,
194 VIRTCHNL_PROTO_HDR_TCP,
195 VIRTCHNL_PROTO_HDR_UDP,
196 VIRTCHNL_PROTO_HDR_SCTP,
197 VIRTCHNL_PROTO_HDR_GTPU_IP,
198 VIRTCHNL_PROTO_HDR_GTPU_EH,
199 VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_DWN,
200 VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_UP,
201 VIRTCHNL_PROTO_HDR_PPPOE,
202 VIRTCHNL_PROTO_HDR_L2TPV3,
203 VIRTCHNL_PROTO_HDR_ESP,
204 VIRTCHNL_PROTO_HDR_AH,
205 VIRTCHNL_PROTO_HDR_PFCP,
208 /* Protocol header field within a protocol header. */
209 enum virtchnl_proto_hdr_field
212 VIRTCHNL_PROTO_HDR_ETH_SRC = PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_ETH),
213 VIRTCHNL_PROTO_HDR_ETH_DST,
214 VIRTCHNL_PROTO_HDR_ETH_ETHERTYPE,
216 VIRTCHNL_PROTO_HDR_S_VLAN_ID =
217 PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_S_VLAN),
219 VIRTCHNL_PROTO_HDR_C_VLAN_ID =
220 PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_C_VLAN),
222 VIRTCHNL_PROTO_HDR_IPV4_SRC =
223 PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_IPV4),
224 VIRTCHNL_PROTO_HDR_IPV4_DST,
225 VIRTCHNL_PROTO_HDR_IPV4_DSCP,
226 VIRTCHNL_PROTO_HDR_IPV4_TTL,
227 VIRTCHNL_PROTO_HDR_IPV4_PROT,
229 VIRTCHNL_PROTO_HDR_IPV6_SRC =
230 PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_IPV6),
231 VIRTCHNL_PROTO_HDR_IPV6_DST,
232 VIRTCHNL_PROTO_HDR_IPV6_TC,
233 VIRTCHNL_PROTO_HDR_IPV6_HOP_LIMIT,
234 VIRTCHNL_PROTO_HDR_IPV6_PROT,
236 VIRTCHNL_PROTO_HDR_TCP_SRC_PORT =
237 PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_TCP),
238 VIRTCHNL_PROTO_HDR_TCP_DST_PORT,
240 VIRTCHNL_PROTO_HDR_UDP_SRC_PORT =
241 PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_UDP),
242 VIRTCHNL_PROTO_HDR_UDP_DST_PORT,
244 VIRTCHNL_PROTO_HDR_SCTP_SRC_PORT =
245 PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_SCTP),
246 VIRTCHNL_PROTO_HDR_SCTP_DST_PORT,
248 VIRTCHNL_PROTO_HDR_GTPU_IP_TEID =
249 PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_GTPU_IP),
251 VIRTCHNL_PROTO_HDR_GTPU_EH_PDU =
252 PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_GTPU_EH),
253 VIRTCHNL_PROTO_HDR_GTPU_EH_QFI,
255 VIRTCHNL_PROTO_HDR_PPPOE_SESS_ID =
256 PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_PPPOE),
258 VIRTCHNL_PROTO_HDR_L2TPV3_SESS_ID =
259 PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_L2TPV3),
261 VIRTCHNL_PROTO_HDR_ESP_SPI = PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_ESP),
263 VIRTCHNL_PROTO_HDR_AH_SPI = PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_AH),
265 VIRTCHNL_PROTO_HDR_PFCP_S_FIELD =
266 PROTO_HDR_FIELD_START (VIRTCHNL_PROTO_HDR_PFCP),
267 VIRTCHNL_PROTO_HDR_PFCP_SEID,
270 struct virtchnl_proto_hdr
272 enum virtchnl_proto_hdr_type type;
273 u32 field_selector; /* a bit mask to select field for header type */
276 * binary buffer in network order for specific header type.
277 * For example, if type = VIRTCHNL_PROTO_HDR_IPV4, a IPv4
278 * header is expected to be copied into the buffer.
282 VIRTCHNL_CHECK_STRUCT_LEN (72, virtchnl_proto_hdr);
284 struct virtchnl_proto_hdrs
288 * specify where protocol header start from. Must be 0 when sending a generic
289 * packet request. 0 - from the outer layer 1 - from the first inner layer 2
290 *- from the second inner layer
295 * the proto layers must < VIRTCHNL_MAX_NUM_PROTO_HDRS.
296 * Must be 0 when sending a generic packet request.
300 struct virtchnl_proto_hdr proto_hdr[VIRTCHNL_MAX_NUM_PROTO_HDRS];
304 u8 spec[VIRTCHNL_MAX_SIZE_GEN_PACKET];
305 u8 mask[VIRTCHNL_MAX_SIZE_GEN_PACKET];
310 VIRTCHNL_CHECK_STRUCT_LEN (2312, virtchnl_proto_hdrs);
312 /* VIRTCHNL_OP_CONFIG_RSS_KEY
313 * VIRTCHNL_OP_CONFIG_RSS_LUT
314 * VF sends these messages to configure RSS. Only supported if both PF
315 * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during
316 * configuration negotiation. If this is the case, then the RSS fields in
317 * the VF resource struct are valid.
318 * Both the key and LUT are initialized to 0 by the PF, meaning that
319 * RSS is effectively disabled until set up by the VF.
321 struct virtchnl_rss_key
325 u8 key[1]; /* RSS hash key, packed bytes */
328 VIRTCHNL_CHECK_STRUCT_LEN (6, virtchnl_rss_key);
330 struct virtchnl_rss_lut
334 u8 lut[1]; /* RSS lookup table */
337 VIRTCHNL_CHECK_STRUCT_LEN (6, virtchnl_rss_lut);
339 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS
340 * VIRTCHNL_OP_SET_RSS_HENA
341 * VF sends these messages to get and set the hash filter enable bits for RSS.
342 * By default, the PF sets these to all possible traffic types that the
343 * hardware supports. The VF can query this value if it wants to change the
344 * traffic types that are hashed by the hardware.
346 struct virtchnl_rss_hena
351 VIRTCHNL_CHECK_STRUCT_LEN (8, virtchnl_rss_hena);
353 /* Type of RSS algorithm */
354 enum virtchnl_rss_algorithm
356 VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC = 0,
357 VIRTCHNL_RSS_ALG_XOR_ASYMMETRIC = 1,
358 VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC = 2,
359 VIRTCHNL_RSS_ALG_XOR_SYMMETRIC = 3,
362 struct virtchnl_rss_cfg
364 struct virtchnl_proto_hdrs proto_hdrs; /* protocol headers */
365 enum virtchnl_rss_algorithm rss_algorithm; /* rss algorithm type */
366 u8 reserved[128]; /* reserve for future */
369 VIRTCHNL_CHECK_STRUCT_LEN (2444, virtchnl_rss_cfg);
374 VIRTCHNL_ACTION_DROP = 0,
375 VIRTCHNL_ACTION_TC_REDIRECT,
376 VIRTCHNL_ACTION_PASSTHRU,
377 VIRTCHNL_ACTION_QUEUE,
378 VIRTCHNL_ACTION_Q_REGION,
379 VIRTCHNL_ACTION_MARK,
380 VIRTCHNL_ACTION_COUNT,
381 VIRTCHNL_ACTION_NONE,
384 /* action configuration for FDIR */
385 struct virtchnl_filter_action
387 enum virtchnl_action type;
390 /* used for queue and qgroup action */
396 /* used for count action */
399 /* share counter ID with other flow rules */
401 u32 id; /* counter ID */
403 /* used for mark action */
409 VIRTCHNL_CHECK_STRUCT_LEN (36, virtchnl_filter_action);
411 #define VIRTCHNL_MAX_NUM_ACTIONS 8
413 struct virtchnl_filter_action_set
415 /* action number must be less then VIRTCHNL_MAX_NUM_ACTIONS */
417 struct virtchnl_filter_action actions[VIRTCHNL_MAX_NUM_ACTIONS];
420 VIRTCHNL_CHECK_STRUCT_LEN (292, virtchnl_filter_action_set);
422 /* pattern and action for FDIR rule */
423 struct virtchnl_fdir_rule
425 struct virtchnl_proto_hdrs proto_hdrs;
426 struct virtchnl_filter_action_set action_set;
429 VIRTCHNL_CHECK_STRUCT_LEN (2604, virtchnl_fdir_rule);
431 /* query information to retrieve fdir rule counters.
432 * PF will fill out this structure to reset counter.
434 struct virtchnl_fdir_query_info
436 u32 match_packets_valid : 1;
437 u32 match_bytes_valid : 1;
438 u32 reserved : 30; /* Reserved, must be zero. */
440 u64 matched_packets; /* Number of packets for this rule. */
441 u64 matched_bytes; /* Number of bytes through this rule. */
444 VIRTCHNL_CHECK_STRUCT_LEN (24, virtchnl_fdir_query_info);
446 /* Status returned to VF after VF requests FDIR commands
447 * VIRTCHNL_FDIR_SUCCESS
448 * VF FDIR related request is successfully done by PF
449 * The request can be OP_ADD/DEL/QUERY_FDIR_FILTER.
451 * VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE
452 * OP_ADD_FDIR_FILTER request is failed due to no Hardware resource.
454 * VIRTCHNL_FDIR_FAILURE_RULE_EXIST
455 * OP_ADD_FDIR_FILTER request is failed due to the rule is already existed.
457 * VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT
458 * OP_ADD_FDIR_FILTER request is failed due to conflict with existing rule.
460 * VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST
461 * OP_DEL_FDIR_FILTER request is failed due to this rule doesn't exist.
463 * VIRTCHNL_FDIR_FAILURE_RULE_INVALID
464 * OP_ADD_FDIR_FILTER request is failed due to parameters validation
465 * or HW doesn't support.
467 * VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT
468 * OP_ADD/DEL_FDIR_FILTER request is failed due to timing out
471 * VIRTCHNL_FDIR_FAILURE_QUERY_INVALID
472 * OP_QUERY_FDIR_FILTER request is failed due to parameters validation,
473 * for example, VF query counter of a rule who has no counter action.
475 enum virtchnl_fdir_prgm_status
477 VIRTCHNL_FDIR_SUCCESS = 0,
478 VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE,
479 VIRTCHNL_FDIR_FAILURE_RULE_EXIST,
480 VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT,
481 VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST,
482 VIRTCHNL_FDIR_FAILURE_RULE_INVALID,
483 VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT,
484 VIRTCHNL_FDIR_FAILURE_QUERY_INVALID,
485 VIRTCHNL_FDIR_FAILURE_MAX,
488 /* VIRTCHNL_OP_ADD_FDIR_FILTER
489 * VF sends this request to PF by filling out vsi_id,
490 * validate_only and rule_cfg. PF will return flow_id
491 * if the request is successfully done and return add_status to VF.
493 struct virtchnl_fdir_add
495 u16 vsi_id; /* INPUT */
497 * 1 for validating a fdir rule, 0 for creating a fdir rule.
498 * Validate and create share one ops: VIRTCHNL_OP_ADD_FDIR_FILTER.
500 u16 validate_only; /* INPUT */
501 u32 flow_id; /* OUTPUT */
502 struct virtchnl_fdir_rule rule_cfg; /* INPUT */
503 enum virtchnl_fdir_prgm_status status; /* OUTPUT */
506 VIRTCHNL_CHECK_STRUCT_LEN (2616, virtchnl_fdir_add);
508 /* VIRTCHNL_OP_DEL_FDIR_FILTER
509 * VF sends this request to PF by filling out vsi_id
510 * and flow_id. PF will return del_status to VF.
512 struct virtchnl_fdir_del
514 u16 vsi_id; /* INPUT */
516 u32 flow_id; /* INPUT */
517 enum virtchnl_fdir_prgm_status status; /* OUTPUT */
520 VIRTCHNL_CHECK_STRUCT_LEN (12, virtchnl_fdir_del);
522 /* VIRTCHNL_OP_QUERY_FDIR_FILTER
523 * VF sends this request to PF by filling out vsi_id,
524 * flow_id and reset_counter. PF will return query_info
525 * and query_status to VF.
527 struct virtchnl_fdir_query
529 u16 vsi_id; /* INPUT */
531 u32 flow_id; /* INPUT */
532 u32 reset_counter : 1; /* INPUT */
533 struct virtchnl_fdir_query_info query_info; /* OUTPUT */
534 enum virtchnl_fdir_prgm_status status; /* OUTPUT */
538 VIRTCHNL_CHECK_STRUCT_LEN (48, virtchnl_fdir_query);
541 * Those headers used temporary, maybe OS packet
542 * definition can replace. Add flow error, pattern
543 * and action definition.
547 * Verbose error types.
549 * Most of them provide the type of the object referenced by struct
550 * rte_flow_error.cause.
552 enum avf_flow_error_type
554 AVF_FLOW_ERROR_TYPE_NONE, /**< No error. */
555 AVF_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
556 AVF_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
557 AVF_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
558 AVF_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
559 AVF_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
560 AVF_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
561 AVF_FLOW_ERROR_TYPE_ATTR_TRANSFER, /**< Transfer field. */
562 AVF_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
563 AVF_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
564 AVF_FLOW_ERROR_TYPE_ITEM_SPEC, /**< Item specification. */
565 AVF_FLOW_ERROR_TYPE_ITEM_LAST, /**< Item specification range. */
566 AVF_FLOW_ERROR_TYPE_ITEM_MASK, /**< Item specification mask. */
567 AVF_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
568 AVF_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
569 AVF_FLOW_ERROR_TYPE_ACTION_CONF, /**< Action configuration. */
570 AVF_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
574 * Verbose error structure definition.
575 * Both cause and message may be NULL regardless of the error type.
577 struct avf_flow_error
579 enum avf_flow_error_type type; /**< Cause field and error types. */
580 const void *cause; /**< Object responsible for the error. */
581 const char *message; /**< Human-readable error message. */
584 #define AVF_ETHER_ADDR_LEN 6
585 struct avf_ether_addr
587 u8 addr_bytes[AVF_ETHER_ADDR_LEN]; /**< Addr bytes in tx order */
588 } __attribute__ ((__aligned__ (2)));
590 struct avf_flow_eth_hdr
592 struct avf_ether_addr dst; /**< Destination MAC. */
593 struct avf_ether_addr src; /**< Source MAC. */
594 u16 type; /**< EtherType or TPID. */
602 u8 version_ihl; /**< version and header length */
603 u8 type_of_service; /**< type of service */
604 u16 total_length; /**< length of packet */
605 u16 packet_id; /**< packet ID */
606 u16 fragment_offset; /**< fragmentation offset */
607 u8 time_to_live; /**< time to live */
608 u8 next_proto_id; /**< protocol ID */
609 u16 hdr_checksum; /**< header checksum */
610 u32 src_addr; /**< source address */
611 u32 dst_addr; /**< destination address */
612 } __attribute__ ((__packed__));
619 u32 vtc_flow; /**< IP version, traffic class & flow label. */
620 u16 payload_len; /**< IP packet length - includes header size */
621 u8 proto; /**< Protocol, next header. */
622 u8 hop_limits; /**< Hop limits. */
623 u8 src_addr[16]; /**< IP address of source host. */
624 u8 dst_addr[16]; /**< IP address of destination host(s). */
625 } __attribute__ ((__packed__));
632 u16 src_port; /**< TCP source port. */
633 u16 dst_port; /**< TCP destination port. */
634 u32 sent_seq; /**< TX data sequence number. */
635 u32 recv_ack; /**< RX data acknowledgment sequence number. */
636 u8 data_off; /**< Data offset. */
637 u8 tcp_flags; /**< TCP flags */
638 u16 rx_win; /**< RX flow control window. */
639 u16 cksum; /**< TCP checksum. */
640 u16 tcp_urp; /**< TCP urgent pointer, if any. */
641 } __attribute__ ((__packed__));
648 u16 src_port; /**< UDP source port. */
649 u16 dst_port; /**< UDP destination port. */
650 u16 dgram_len; /**< UDP datagram length */
651 u16 dgram_cksum; /**< UDP datagram checksum */
652 } __attribute__ ((__packed__));
655 * Match IP Authentication Header (AH), RFC 4302
671 u32 spi; /**< Security Parameters Index */
672 u32 seq; /**< packet sequence number */
673 } __attribute__ ((__packed__));
687 * Matches a L2TPv3 over IP header.
689 struct avf_l2tpv3oip_hdr
691 u32 session_id; /**< Session ID. */
695 * Matches a GTP PDU extension header with type 0x85.
697 struct avf_gtp_psc_hdr
699 u8 pdu_type; /**< PDU type. */
700 u8 qfi; /**< QoS flow identifier. */
704 * Matches a GTPv1 header.
709 * Version (3b), protocol type (1b), reserved (1b),
710 * Extension header flag (1b),
711 * Sequence number flag (1b),
712 * N-PDU number flag (1b).
715 u8 msg_type; /**< Message type. */
716 u16 msg_len; /**< Message length. */
717 u32 teid; /**< Tunnel endpoint identifier. */
725 u16 src_port; /**< Source port. */
726 u16 dst_port; /**< Destin port. */
727 u32 tag; /**< Validation tag. */
728 u32 cksum; /**< Checksum. */
729 } __attribute__ ((__packed__));
732 * Hash function types.
734 enum avf_eth_hash_function
736 AVF_ETH_HASH_FUNCTION_DEFAULT = 0,
737 AVF_ETH_HASH_FUNCTION_TOEPLITZ, /**< Toeplitz */
738 AVF_ETH_HASH_FUNCTION_SIMPLE_XOR, /**< Simple XOR */
740 * Symmetric Toeplitz: src, dst will be replaced by
741 * xor(src, dst). For the case with src/dst only,
742 * src or dst address will xor with zero pair.
744 AVF_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ,
745 AVF_ETH_HASH_FUNCTION_MAX,
748 struct avf_flow_action_rss
750 enum avf_eth_hash_function func; /**< RSS hash function to apply. */
753 u64 types; /**< Specific RSS hash types (see ETH_RSS_*). */
754 u32 key_len; /**< Hash key length in bytes. */
755 u32 queue_num; /**< Number of entries in @p queue. */
756 const u8 *key; /**< Hash key. */
757 const u16 *queue; /**< Queue indices to use. */
760 struct avf_flow_action_queue
762 u16 index; /**< Queue index to use. */
765 struct avf_flow_action_mark
767 u32 id; /**< Integer value to return with packets. */
770 struct avf_flow_action
772 enum virtchnl_action type; /**< Action type. */
773 const void *conf; /**< Pointer to action configuration object. */
778 enum virtchnl_proto_hdr_type type; /**< Item type. */
779 const void *spec; /**< Pointer to item specification structure. */
780 const void *mask; /**< Bit-mask applied to spec and last. */
781 int is_generic; /* indicate if this item is for a generic flow pattern. */
786 struct virtchnl_fdir_add add_fltr;
787 struct virtchnl_fdir_del del_fltr;
797 VIRTCHNL_ADV_OP_ADD_FDIR_FILTER = 0,
798 VIRTCHNL_ADV_OP_DEL_FDIR_FILTER,
799 VIRTCHNL_ADV_OP_QUERY_FDIR_FILTER,
800 VIRTCHNL_ADV_OP_ADD_RSS_CFG,
801 VIRTCHNL_ADV_OP_DEL_RSS_CFG,
805 /* virtual channel op handler */
806 typedef int (*avf_flow_vc_op_t) (void *vc_hdl, enum virthnl_adv_ops vc_op,
807 void *in, u32 in_len, void *out, u32 out_len);
809 /* virtual channel context object */
810 struct avf_flow_vc_ctx
812 void *vc_hdl; /* virtual channel handler */
813 avf_flow_vc_op_t vc_op;
817 * Create a rule cfg object.
820 * created rule cfg object.
822 * tunnel level where protocol header start from
823 * 0 from moster outer layer.
824 * 1 from first inner layer.
825 * 2 form second inner layer.
831 * the rx queue number of the avf
837 int avf_fdir_rcfg_create (struct avf_fdir_conf **rcfg, int tunnel_level,
841 * Destroy a rule cfg object.
844 * the cfg object to destroy.
850 int avf_fdir_rcfg_destroy (struct avf_fdir_conf *rcfg);
853 * Set match potocol header on specific layer, it will overwrite is already be
857 * the rule cfg object
859 * layer of the protocol header.
861 * protocol header type.
867 int avf_fdir_rcfg_set_hdr (struct avf_fdir_conf *rcfg, int layer,
868 enum virtchnl_proto_hdr_type hdr);
871 * Set a match field on specific protocol layer, if any match field already be
872 * set on this layer, it will be overwritten.
875 * the rule cfg object
877 * layer of the protocol header.
887 int avf_fdir_rcfg_set_field (struct avf_fdir_conf *rcfg, int layer,
888 struct avf_flow_item *item,
889 struct avf_flow_error *error);
892 * Set action as to queue(group), conflict with drop action.
899 * queue group size, must be 2^n. 1 means only to single queue.
907 int avf_fdir_rcfg_act_queue (struct avf_fdir_conf *rcfg, int queue, int size,
911 * Set action as to queue group, conflict with drop action.
914 * the rule cfg object
926 int avf_fdir_parse_action_qregion (struct avf_fdir_conf *rcfg,
927 const struct avf_flow_action *act,
928 int act_idx, struct avf_flow_error *error);
931 * Set action as as drop, conflict with to queue(gropu) action.
934 * the rule cfg object
942 int avf_fdir_rcfg_act_drop (struct avf_fdir_conf *rcfg, int act_idx);
945 * Set action as mark, it can co-exist with to queue(group) or drop action.
948 * the rule cfg object
958 int avf_fdir_rcfg_act_mark (struct avf_fdir_conf *rcfg, const u32 mark,
962 * Validate a flow rule cfg, check with PF driver if the rule cfg is supportted
966 * virtual channel context
968 * the rule cfg object.
974 int avf_fdir_rcfg_validate (struct avf_flow_vc_ctx *ctx,
975 struct avf_fdir_conf *rcfg);
978 * Create a flow rule, a FDIR rule is expected to be programmed into hardware
982 * virtual channel context
990 int avf_fdir_rule_create (struct avf_flow_vc_ctx *ctx,
991 struct avf_fdir_conf *rcfg);
994 * Destroy a flow rule.
997 * virtual channel context
999 * the rule cfg object.
1005 int avf_fdir_rule_destroy (struct avf_flow_vc_ctx *ctx,
1006 struct avf_fdir_conf *rcfg);
1009 * Parse avf patterns and set pattern fields.
1022 int avf_fdir_parse_pattern (struct avf_fdir_conf *rcfg,
1023 struct avf_flow_item avf_items[],
1024 struct avf_flow_error *error);
1027 * Parse avf patterns for generic flow and set pattern fields.
1040 int avf_fdir_parse_generic_pattern (struct avf_fdir_conf *rcfg,
1041 struct avf_flow_item avf_items[],
1042 struct avf_flow_error *error);
1045 * Parse flow actions, set actions.
1058 int avf_fdir_parse_action (const struct avf_flow_action actions[],
1059 struct avf_fdir_conf *rcfg,
1060 struct avf_flow_error *error);
1063 * Parse avf patterns and set pattern fields for RSS.
1076 int avf_rss_parse_pattern (struct virtchnl_rss_cfg *rss_cfg,
1077 struct avf_flow_item avf_items[],
1078 struct avf_flow_error *error);
1081 * Parse avf patterns and set pattern fields for RSS generic flow.
1094 int avf_rss_parse_generic_pattern (struct virtchnl_rss_cfg *rss_cfg,
1095 struct avf_flow_item avf_items[],
1096 struct avf_flow_error *error);
1099 * Parse RSS flow actions, set actions.
1112 int avf_rss_parse_action (const struct avf_flow_action actions[],
1113 struct virtchnl_rss_cfg *rss_cfg,
1114 struct avf_flow_error *error);
1117 * Create a RSS rule cfg object.
1120 * created rule cfg object.
1122 * tunnel level where protocol header start from
1123 * 0 from moster outer layer.
1124 * 1 from first inner layer.
1125 * 2 form second inner layer.
1126 * Must be 0 for generic flow.
1132 int avf_rss_cfg_create (struct virtchnl_rss_cfg **rss_cfg, int tunnel_level);
1134 int avf_rss_rcfg_destroy (struct virtchnl_rss_cfg *rss_cfg);
1137 * Create a RSS flow rule
1140 * virtual channel context
1148 int avf_rss_rule_create (struct avf_flow_vc_ctx *ctx,
1149 struct virtchnl_rss_cfg *rss_cfg);
1152 * Destroy a RSS flow rule
1155 * virtual channel context
1163 int avf_rss_rule_destroy (struct avf_flow_vc_ctx *ctx,
1164 struct virtchnl_rss_cfg *rss_cfg);
1167 * Parse generic flow pattern to get spec and mask
1178 void avf_parse_generic_pattern (struct avf_flow_item *item, u8 *pkt_buf,
1179 u8 *msk_buf, u16 spec_len);
1182 * Initialize flow error structure.
1185 * Pointer to flow error structure (may be NULL).
1187 * Related error code
1189 * Cause field and error types.
1191 * Object responsible for the error.
1193 * Human-readable error message.
1196 * Negative error code (errno value)
1198 int avf_flow_error_set (struct avf_flow_error *error, int code,
1199 enum avf_flow_error_type type, const void *cause,
1200 const char *message);
1203 * decode the error number to Verbose error string
1209 * Verbose error string
1211 char *avf_fdir_prgm_error_decode (int err_no);
1213 #endif /* _AVF_ADVANCED_FLOW_H_ */
1216 * fd.io coding-style-patch-verification: ON
1219 * eval: (c-set-style "gnu")