Imported Upstream version 16.04
[deb_dpdk.git] / lib / librte_ether / rte_eth_ctrl.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _RTE_ETH_CTRL_H_
35 #define _RTE_ETH_CTRL_H_
36
37 /**
38  * @file
39  *
40  * Ethernet device features and related data structures used
41  * by control APIs should be defined in this file.
42  *
43  */
44
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48
49 /*
50  * A packet can be identified by hardware as different flow types. Different
51  * NIC hardwares may support different flow types.
52  * Basically, the NIC hardware identifies the flow type as deep protocol as
53  * possible, and exclusively. For example, if a packet is identified as
54  * 'RTE_ETH_FLOW_NONFRAG_IPV4_TCP', it will not be any of other flow types,
55  * though it is an actual IPV4 packet.
56  * Note that the flow types are used to define RSS offload types in
57  * rte_ethdev.h.
58  */
59 #define RTE_ETH_FLOW_UNKNOWN             0
60 #define RTE_ETH_FLOW_RAW                 1
61 #define RTE_ETH_FLOW_IPV4                2
62 #define RTE_ETH_FLOW_FRAG_IPV4           3
63 #define RTE_ETH_FLOW_NONFRAG_IPV4_TCP    4
64 #define RTE_ETH_FLOW_NONFRAG_IPV4_UDP    5
65 #define RTE_ETH_FLOW_NONFRAG_IPV4_SCTP   6
66 #define RTE_ETH_FLOW_NONFRAG_IPV4_OTHER  7
67 #define RTE_ETH_FLOW_IPV6                8
68 #define RTE_ETH_FLOW_FRAG_IPV6           9
69 #define RTE_ETH_FLOW_NONFRAG_IPV6_TCP   10
70 #define RTE_ETH_FLOW_NONFRAG_IPV6_UDP   11
71 #define RTE_ETH_FLOW_NONFRAG_IPV6_SCTP  12
72 #define RTE_ETH_FLOW_NONFRAG_IPV6_OTHER 13
73 #define RTE_ETH_FLOW_L2_PAYLOAD         14
74 #define RTE_ETH_FLOW_IPV6_EX            15
75 #define RTE_ETH_FLOW_IPV6_TCP_EX        16
76 #define RTE_ETH_FLOW_IPV6_UDP_EX        17
77 #define RTE_ETH_FLOW_MAX                18
78
79 /**
80  * Feature filter types
81  */
82 enum rte_filter_type {
83         RTE_ETH_FILTER_NONE = 0,
84         RTE_ETH_FILTER_MACVLAN,
85         RTE_ETH_FILTER_ETHERTYPE,
86         RTE_ETH_FILTER_FLEXIBLE,
87         RTE_ETH_FILTER_SYN,
88         RTE_ETH_FILTER_NTUPLE,
89         RTE_ETH_FILTER_TUNNEL,
90         RTE_ETH_FILTER_FDIR,
91         RTE_ETH_FILTER_HASH,
92         RTE_ETH_FILTER_L2_TUNNEL,
93         RTE_ETH_FILTER_MAX
94 };
95
96 /**
97  * Generic operations on filters
98  */
99 enum rte_filter_op {
100         /** used to check whether the type filter is supported */
101         RTE_ETH_FILTER_NOP = 0,
102         RTE_ETH_FILTER_ADD,      /**< add filter entry */
103         RTE_ETH_FILTER_UPDATE,   /**< update filter entry */
104         RTE_ETH_FILTER_DELETE,   /**< delete filter entry */
105         RTE_ETH_FILTER_FLUSH,    /**< flush all entries */
106         RTE_ETH_FILTER_GET,      /**< get filter entry */
107         RTE_ETH_FILTER_SET,      /**< configurations */
108         RTE_ETH_FILTER_INFO,     /**< retrieve information */
109         RTE_ETH_FILTER_STATS,    /**< retrieve statistics */
110         RTE_ETH_FILTER_OP_MAX
111 };
112
113 /**
114  * MAC filter type
115  */
116 enum rte_mac_filter_type {
117         RTE_MAC_PERFECT_MATCH = 1, /**< exact match of MAC addr. */
118         RTE_MACVLAN_PERFECT_MATCH, /**< exact match of MAC addr and VLAN ID. */
119         RTE_MAC_HASH_MATCH, /**< hash match of MAC addr. */
120         /** hash match of MAC addr and exact match of VLAN ID. */
121         RTE_MACVLAN_HASH_MATCH,
122 };
123
124 /**
125  * MAC filter info
126  */
127 struct rte_eth_mac_filter {
128         uint8_t is_vf; /**< 1 for VF, 0 for port dev */
129         uint16_t dst_id; /**< VF ID, available when is_vf is 1*/
130         enum rte_mac_filter_type filter_type; /**< MAC filter type */
131         struct ether_addr mac_addr;
132 };
133
134 /**
135  * Define all structures for Ethertype Filter type.
136  */
137
138 #define RTE_ETHTYPE_FLAGS_MAC    0x0001 /**< If set, compare mac */
139 #define RTE_ETHTYPE_FLAGS_DROP   0x0002 /**< If set, drop packet when match */
140
141 /**
142  * A structure used to define the ethertype filter entry
143  * to support RTE_ETH_FILTER_ETHERTYPE with RTE_ETH_FILTER_ADD,
144  * RTE_ETH_FILTER_DELETE and RTE_ETH_FILTER_GET operations.
145  */
146 struct rte_eth_ethertype_filter {
147         struct ether_addr mac_addr;   /**< Mac address to match. */
148         uint16_t ether_type;          /**< Ether type to match */
149         uint16_t flags;               /**< Flags from RTE_ETHTYPE_FLAGS_* */
150         uint16_t queue;               /**< Queue assigned to when match*/
151 };
152
153 #define RTE_FLEX_FILTER_MAXLEN  128     /**< bytes to use in flex filter. */
154 #define RTE_FLEX_FILTER_MASK_SIZE       \
155         (RTE_ALIGN(RTE_FLEX_FILTER_MAXLEN, CHAR_BIT) / CHAR_BIT)
156                                         /**< mask bytes in flex filter. */
157
158 /**
159  *  A structure used to define the flex filter entry
160  *  to support RTE_ETH_FILTER_FLEXIBLE with RTE_ETH_FILTER_ADD,
161  *  RTE_ETH_FILTER_DELETE and RTE_ETH_FILTER_GET operations.
162  */
163 struct rte_eth_flex_filter {
164         uint16_t len;
165         uint8_t bytes[RTE_FLEX_FILTER_MAXLEN];  /**< flex bytes in big endian.*/
166         uint8_t mask[RTE_FLEX_FILTER_MASK_SIZE];    /**< if mask bit is 1b, do
167                                         not compare corresponding byte. */
168         uint8_t priority;
169         uint16_t queue;       /**< Queue assigned to when match. */
170 };
171
172 /**
173  * A structure used to define the TCP syn filter entry
174  * to support RTE_ETH_FILTER_SYN with RTE_ETH_FILTER_ADD,
175  * RTE_ETH_FILTER_DELETE and RTE_ETH_FILTER_GET operations.
176  */
177 struct rte_eth_syn_filter {
178         uint8_t hig_pri;     /**< 1 - higher priority than other filters,
179                                   0 - lower priority. */
180         uint16_t queue;      /**< Queue assigned to when match */
181 };
182
183 /**
184  * Define all structures for ntuple Filter type.
185  */
186
187 #define RTE_NTUPLE_FLAGS_DST_IP    0x0001 /**< If set, dst_ip is part of ntuple */
188 #define RTE_NTUPLE_FLAGS_SRC_IP    0x0002 /**< If set, src_ip is part of ntuple */
189 #define RTE_NTUPLE_FLAGS_DST_PORT  0x0004 /**< If set, dst_port is part of ntuple */
190 #define RTE_NTUPLE_FLAGS_SRC_PORT  0x0008 /**< If set, src_port is part of ntuple */
191 #define RTE_NTUPLE_FLAGS_PROTO     0x0010 /**< If set, protocol is part of ntuple */
192 #define RTE_NTUPLE_FLAGS_TCP_FLAG  0x0020 /**< If set, tcp flag is involved */
193
194 #define RTE_5TUPLE_FLAGS ( \
195                 RTE_NTUPLE_FLAGS_DST_IP | \
196                 RTE_NTUPLE_FLAGS_SRC_IP | \
197                 RTE_NTUPLE_FLAGS_DST_PORT | \
198                 RTE_NTUPLE_FLAGS_SRC_PORT | \
199                 RTE_NTUPLE_FLAGS_PROTO)
200
201 #define RTE_2TUPLE_FLAGS ( \
202                 RTE_NTUPLE_FLAGS_DST_PORT | \
203                 RTE_NTUPLE_FLAGS_PROTO)
204
205 #define TCP_URG_FLAG 0x20
206 #define TCP_ACK_FLAG 0x10
207 #define TCP_PSH_FLAG 0x08
208 #define TCP_RST_FLAG 0x04
209 #define TCP_SYN_FLAG 0x02
210 #define TCP_FIN_FLAG 0x01
211 #define TCP_FLAG_ALL 0x3F
212
213 /**
214  * A structure used to define the ntuple filter entry
215  * to support RTE_ETH_FILTER_NTUPLE with RTE_ETH_FILTER_ADD,
216  * RTE_ETH_FILTER_DELETE and RTE_ETH_FILTER_GET operations.
217  */
218 struct rte_eth_ntuple_filter {
219         uint16_t flags;          /**< Flags from RTE_NTUPLE_FLAGS_* */
220         uint32_t dst_ip;         /**< Destination IP address in big endian. */
221         uint32_t dst_ip_mask;    /**< Mask of destination IP address. */
222         uint32_t src_ip;         /**< Source IP address in big endian. */
223         uint32_t src_ip_mask;    /**< Mask of destination IP address. */
224         uint16_t dst_port;       /**< Destination port in big endian. */
225         uint16_t dst_port_mask;  /**< Mask of destination port. */
226         uint16_t src_port;       /**< Source Port in big endian. */
227         uint16_t src_port_mask;  /**< Mask of source port. */
228         uint8_t proto;           /**< L4 protocol. */
229         uint8_t proto_mask;      /**< Mask of L4 protocol. */
230         /** tcp_flags only meaningful when the proto is TCP.
231             The packet matched above ntuple fields and contain
232             any set bit in tcp_flags will hit this filter. */
233         uint8_t tcp_flags;
234         uint16_t priority;       /**< seven levels (001b-111b), 111b is highest,
235                                       used when more than one filter matches. */
236         uint16_t queue;          /**< Queue assigned to when match*/
237 };
238
239 /**
240  * Tunneled type.
241  */
242 enum rte_eth_tunnel_type {
243         RTE_TUNNEL_TYPE_NONE = 0,
244         RTE_TUNNEL_TYPE_VXLAN,
245         RTE_TUNNEL_TYPE_GENEVE,
246         RTE_TUNNEL_TYPE_TEREDO,
247         RTE_TUNNEL_TYPE_NVGRE,
248         RTE_TUNNEL_TYPE_IP_IN_GRE,
249         RTE_L2_TUNNEL_TYPE_E_TAG,
250         RTE_TUNNEL_TYPE_MAX,
251 };
252
253 /**
254  * filter type of tunneling packet
255  */
256 #define ETH_TUNNEL_FILTER_OMAC  0x01 /**< filter by outer MAC addr */
257 #define ETH_TUNNEL_FILTER_OIP   0x02 /**< filter by outer IP Addr */
258 #define ETH_TUNNEL_FILTER_TENID 0x04 /**< filter by tenant ID */
259 #define ETH_TUNNEL_FILTER_IMAC  0x08 /**< filter by inner MAC addr */
260 #define ETH_TUNNEL_FILTER_IVLAN 0x10 /**< filter by inner VLAN ID */
261 #define ETH_TUNNEL_FILTER_IIP   0x20 /**< filter by inner IP addr */
262
263 #define RTE_TUNNEL_FILTER_IMAC_IVLAN (ETH_TUNNEL_FILTER_IMAC | \
264                                         ETH_TUNNEL_FILTER_IVLAN)
265 #define RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID (ETH_TUNNEL_FILTER_IMAC | \
266                                         ETH_TUNNEL_FILTER_IVLAN | \
267                                         ETH_TUNNEL_FILTER_TENID)
268 #define RTE_TUNNEL_FILTER_IMAC_TENID (ETH_TUNNEL_FILTER_IMAC | \
269                                         ETH_TUNNEL_FILTER_TENID)
270 #define RTE_TUNNEL_FILTER_OMAC_TENID_IMAC (ETH_TUNNEL_FILTER_OMAC | \
271                                         ETH_TUNNEL_FILTER_TENID | \
272                                         ETH_TUNNEL_FILTER_IMAC)
273
274 /**
275  *  Select IPv4 or IPv6 for tunnel filters.
276  */
277 enum rte_tunnel_iptype {
278         RTE_TUNNEL_IPTYPE_IPV4 = 0, /**< IPv4. */
279         RTE_TUNNEL_IPTYPE_IPV6,     /**< IPv6. */
280 };
281
282 /**
283  * Tunneling Packet filter configuration.
284  */
285 struct rte_eth_tunnel_filter_conf {
286         struct ether_addr outer_mac;    /**< Outer MAC address to match. */
287         struct ether_addr inner_mac;    /**< Inner MAC address to match. */
288         uint16_t inner_vlan;            /**< Inner VLAN to match. */
289         enum rte_tunnel_iptype ip_type; /**< IP address type. */
290         /** Outer destination IP address to match if ETH_TUNNEL_FILTER_OIP
291             is set in filter_type, or inner destination IP address to match
292             if ETH_TUNNEL_FILTER_IIP is set in filter_type . */
293         union {
294                 uint32_t ipv4_addr;     /**< IPv4 address in big endian. */
295                 uint32_t ipv6_addr[4];  /**< IPv6 address in big endian. */
296         } ip_addr;
297         /** Flags from ETH_TUNNEL_FILTER_XX - see above. */
298         uint16_t filter_type;
299         enum rte_eth_tunnel_type tunnel_type; /**< Tunnel Type. */
300         uint32_t tenant_id;     /**< Tenant ID to match. VNI, GRE key... */
301         uint16_t queue_id;      /**< Queue assigned to if match. */
302 };
303
304 /**
305  * Global eth device configuration type.
306  */
307 enum rte_eth_global_cfg_type {
308         RTE_ETH_GLOBAL_CFG_TYPE_UNKNOWN = 0,
309         RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN,
310         RTE_ETH_GLOBAL_CFG_TYPE_MAX,
311 };
312
313 /**
314  * Global eth device configuration.
315  */
316 struct rte_eth_global_cfg {
317         enum rte_eth_global_cfg_type cfg_type; /**< Global config type. */
318         union {
319                 uint8_t gre_key_len; /**< Valid GRE key length in byte. */
320                 uint64_t reserved; /**< Reserve space for future use. */
321         } cfg;
322 };
323
324 #define RTE_ETH_FDIR_MAX_FLEXLEN 16  /**< Max length of flexbytes. */
325 #define RTE_ETH_INSET_SIZE_MAX   128 /**< Max length of input set. */
326
327 /**
328  * Input set fields for Flow Director and Hash filters
329  */
330 enum rte_eth_input_set_field {
331         RTE_ETH_INPUT_SET_UNKNOWN = 0,
332
333         /* L2 */
334         RTE_ETH_INPUT_SET_L2_SRC_MAC = 1,
335         RTE_ETH_INPUT_SET_L2_DST_MAC,
336         RTE_ETH_INPUT_SET_L2_OUTER_VLAN,
337         RTE_ETH_INPUT_SET_L2_INNER_VLAN,
338         RTE_ETH_INPUT_SET_L2_ETHERTYPE,
339
340         /* L3 */
341         RTE_ETH_INPUT_SET_L3_SRC_IP4 = 129,
342         RTE_ETH_INPUT_SET_L3_DST_IP4,
343         RTE_ETH_INPUT_SET_L3_SRC_IP6,
344         RTE_ETH_INPUT_SET_L3_DST_IP6,
345         RTE_ETH_INPUT_SET_L3_IP4_TOS,
346         RTE_ETH_INPUT_SET_L3_IP4_PROTO,
347         RTE_ETH_INPUT_SET_L3_IP6_TC,
348         RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER,
349         RTE_ETH_INPUT_SET_L3_IP4_TTL,
350         RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS,
351
352         /* L4 */
353         RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT = 257,
354         RTE_ETH_INPUT_SET_L4_UDP_DST_PORT,
355         RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT,
356         RTE_ETH_INPUT_SET_L4_TCP_DST_PORT,
357         RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT,
358         RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT,
359         RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG,
360
361         /* Tunnel */
362         RTE_ETH_INPUT_SET_TUNNEL_L2_INNER_DST_MAC = 385,
363         RTE_ETH_INPUT_SET_TUNNEL_L2_INNER_SRC_MAC,
364         RTE_ETH_INPUT_SET_TUNNEL_L2_INNER_VLAN,
365         RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY,
366         RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY,
367
368         /* Flexible Payload */
369         RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD = 641,
370         RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD,
371         RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD,
372         RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD,
373         RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD,
374         RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD,
375         RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD,
376         RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD,
377
378         RTE_ETH_INPUT_SET_DEFAULT = 65533,
379         RTE_ETH_INPUT_SET_NONE = 65534,
380         RTE_ETH_INPUT_SET_MAX = 65535,
381 };
382
383 /**
384  * Filters input set operations
385  */
386 enum rte_filter_input_set_op {
387         RTE_ETH_INPUT_SET_OP_UNKNOWN,
388         RTE_ETH_INPUT_SET_SELECT, /**< select input set */
389         RTE_ETH_INPUT_SET_ADD,    /**< add input set entry */
390         RTE_ETH_INPUT_SET_OP_MAX
391 };
392
393
394 /**
395  * A structure used to define the input set configuration for
396  * flow director and hash filters
397  */
398 struct rte_eth_input_set_conf {
399         uint16_t flow_type;
400         uint16_t inset_size;
401         enum rte_eth_input_set_field field[RTE_ETH_INSET_SIZE_MAX];
402         enum rte_filter_input_set_op op;
403 };
404
405 /**
406  * A structure used to define the input for L2 flow
407  */
408 struct rte_eth_l2_flow {
409         uint16_t ether_type;          /**< Ether type in big endian */
410 };
411
412 /**
413  * A structure used to define the input for IPV4 flow
414  */
415 struct rte_eth_ipv4_flow {
416         uint32_t src_ip;      /**< IPv4 source address in big endian. */
417         uint32_t dst_ip;      /**< IPv4 destination address in big endian. */
418         uint8_t  tos;         /**< Type of service to match. */
419         uint8_t  ttl;         /**< Time to live to match. */
420         uint8_t  proto;       /**< Protocol, next header in big endian. */
421 };
422
423 /**
424  * A structure used to define the input for IPV4 UDP flow
425  */
426 struct rte_eth_udpv4_flow {
427         struct rte_eth_ipv4_flow ip; /**< IPv4 fields to match. */
428         uint16_t src_port;           /**< UDP source port in big endian. */
429         uint16_t dst_port;           /**< UDP destination port in big endian. */
430 };
431
432 /**
433  * A structure used to define the input for IPV4 TCP flow
434  */
435 struct rte_eth_tcpv4_flow {
436         struct rte_eth_ipv4_flow ip; /**< IPv4 fields to match. */
437         uint16_t src_port;           /**< TCP source port in big endian. */
438         uint16_t dst_port;           /**< TCP destination port in big endian. */
439 };
440
441 /**
442  * A structure used to define the input for IPV4 SCTP flow
443  */
444 struct rte_eth_sctpv4_flow {
445         struct rte_eth_ipv4_flow ip; /**< IPv4 fields to match. */
446         uint16_t src_port;           /**< SCTP source port in big endian. */
447         uint16_t dst_port;           /**< SCTP destination port in big endian. */
448         uint32_t verify_tag;         /**< Verify tag in big endian */
449 };
450
451 /**
452  * A structure used to define the input for IPV6 flow
453  */
454 struct rte_eth_ipv6_flow {
455         uint32_t src_ip[4];      /**< IPv6 source address in big endian. */
456         uint32_t dst_ip[4];      /**< IPv6 destination address in big endian. */
457         uint8_t  tc;             /**< Traffic class to match. */
458         uint8_t  proto;          /**< Protocol, next header to match. */
459         uint8_t  hop_limits;     /**< Hop limits to match. */
460 };
461
462 /**
463  * A structure used to define the input for IPV6 UDP flow
464  */
465 struct rte_eth_udpv6_flow {
466         struct rte_eth_ipv6_flow ip; /**< IPv6 fields to match. */
467         uint16_t src_port;           /**< UDP source port in big endian. */
468         uint16_t dst_port;           /**< UDP destination port in big endian. */
469 };
470
471 /**
472  * A structure used to define the input for IPV6 TCP flow
473  */
474 struct rte_eth_tcpv6_flow {
475         struct rte_eth_ipv6_flow ip; /**< IPv6 fields to match. */
476         uint16_t src_port;           /**< TCP source port to in big endian. */
477         uint16_t dst_port;           /**< TCP destination port in big endian. */
478 };
479
480 /**
481  * A structure used to define the input for IPV6 SCTP flow
482  */
483 struct rte_eth_sctpv6_flow {
484         struct rte_eth_ipv6_flow ip; /**< IPv6 fields to match. */
485         uint16_t src_port;           /**< SCTP source port in big endian. */
486         uint16_t dst_port;           /**< SCTP destination port in big endian. */
487         uint32_t verify_tag;         /**< Verify tag in big endian. */
488 };
489
490 /**
491  * A structure used to define the input for MAC VLAN flow
492  */
493 struct rte_eth_mac_vlan_flow {
494         struct ether_addr mac_addr;  /**< Mac address to match. */
495 };
496
497 /**
498  * Tunnel type for flow director.
499  */
500 enum rte_eth_fdir_tunnel_type {
501         RTE_FDIR_TUNNEL_TYPE_UNKNOWN = 0,
502         RTE_FDIR_TUNNEL_TYPE_NVGRE,
503         RTE_FDIR_TUNNEL_TYPE_VXLAN,
504 };
505
506 /**
507  * A structure used to define the input for tunnel flow, now it's VxLAN or
508  * NVGRE
509  */
510 struct rte_eth_tunnel_flow {
511         enum rte_eth_fdir_tunnel_type tunnel_type; /**< Tunnel type to match. */
512         /** Tunnel ID to match. TNI, VNI... in big endian. */
513         uint32_t tunnel_id;
514         struct ether_addr mac_addr;                /**< Mac address to match. */
515 };
516
517 /**
518  * An union contains the inputs for all types of flow
519  * Items in flows need to be in big endian
520  */
521 union rte_eth_fdir_flow {
522         struct rte_eth_l2_flow     l2_flow;
523         struct rte_eth_udpv4_flow  udp4_flow;
524         struct rte_eth_tcpv4_flow  tcp4_flow;
525         struct rte_eth_sctpv4_flow sctp4_flow;
526         struct rte_eth_ipv4_flow   ip4_flow;
527         struct rte_eth_udpv6_flow  udp6_flow;
528         struct rte_eth_tcpv6_flow  tcp6_flow;
529         struct rte_eth_sctpv6_flow sctp6_flow;
530         struct rte_eth_ipv6_flow   ipv6_flow;
531         struct rte_eth_mac_vlan_flow mac_vlan_flow;
532         struct rte_eth_tunnel_flow   tunnel_flow;
533 };
534
535 /**
536  * A structure used to contain extend input of flow
537  */
538 struct rte_eth_fdir_flow_ext {
539         uint16_t vlan_tci;
540         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
541         /**< It is filled by the flexible payload to match. */
542         uint8_t is_vf;   /**< 1 for VF, 0 for port dev */
543         uint16_t dst_id; /**< VF ID, available when is_vf is 1*/
544 };
545
546 /**
547  * A structure used to define the input for a flow director filter entry
548  */
549 struct rte_eth_fdir_input {
550         uint16_t flow_type;
551         union rte_eth_fdir_flow flow;
552         /**< Flow fields to match, dependent on flow_type */
553         struct rte_eth_fdir_flow_ext flow_ext;
554         /**< Additional fields to match */
555 };
556
557 /**
558  * Behavior will be taken if FDIR match
559  */
560 enum rte_eth_fdir_behavior {
561         RTE_ETH_FDIR_ACCEPT = 0,
562         RTE_ETH_FDIR_REJECT,
563         RTE_ETH_FDIR_PASSTHRU,
564 };
565
566 /**
567  * Flow director report status
568  * It defines what will be reported if FDIR entry is matched.
569  */
570 enum rte_eth_fdir_status {
571         RTE_ETH_FDIR_NO_REPORT_STATUS = 0, /**< Report nothing. */
572         RTE_ETH_FDIR_REPORT_ID,            /**< Only report FD ID. */
573         RTE_ETH_FDIR_REPORT_ID_FLEX_4,     /**< Report FD ID and 4 flex bytes. */
574         RTE_ETH_FDIR_REPORT_FLEX_8,        /**< Report 8 flex bytes. */
575 };
576
577 /**
578  * A structure used to define an action when match FDIR packet filter.
579  */
580 struct rte_eth_fdir_action {
581         uint16_t rx_queue;        /**< Queue assigned to if FDIR match. */
582         enum rte_eth_fdir_behavior behavior;     /**< Behavior will be taken */
583         enum rte_eth_fdir_status report_status;  /**< Status report option */
584         uint8_t flex_off;
585         /**< If report_status is RTE_ETH_FDIR_REPORT_ID_FLEX_4 or
586              RTE_ETH_FDIR_REPORT_FLEX_8, flex_off specifies where the reported
587              flex bytes start from in flexible payload. */
588 };
589
590 /**
591  * A structure used to define the flow director filter entry by filter_ctrl API
592  * It supports RTE_ETH_FILTER_FDIR with RTE_ETH_FILTER_ADD and
593  * RTE_ETH_FILTER_DELETE operations.
594  */
595 struct rte_eth_fdir_filter {
596         uint32_t soft_id;
597         /**< ID, an unique value is required when deal with FDIR entry */
598         struct rte_eth_fdir_input input;    /**< Input set */
599         struct rte_eth_fdir_action action;  /**< Action taken when match */
600 };
601
602 /**
603  *  A structure used to configure FDIR masks that are used by the device
604  *  to match the various fields of RX packet headers.
605  */
606 struct rte_eth_fdir_masks {
607         uint16_t vlan_tci_mask;   /**< Bit mask for vlan_tci in big endian */
608         /** Bit mask for ipv4 flow in big endian. */
609         struct rte_eth_ipv4_flow   ipv4_mask;
610         /** Bit maks for ipv6 flow in big endian. */
611         struct rte_eth_ipv6_flow   ipv6_mask;
612         /** Bit mask for L4 source port in big endian. */
613         uint16_t src_port_mask;
614         /** Bit mask for L4 destination port in big endian. */
615         uint16_t dst_port_mask;
616         /** 6 bit mask for proper 6 bytes of Mac address, bit 0 matches the
617             first byte on the wire */
618         uint8_t mac_addr_byte_mask;
619         /** Bit mask for tunnel ID in big endian. */
620         uint32_t tunnel_id_mask;
621         uint8_t tunnel_type_mask; /**< 1 - Match tunnel type,
622                                        0 - Ignore tunnel type. */
623 };
624
625 /**
626  * Payload type
627  */
628 enum rte_eth_payload_type {
629         RTE_ETH_PAYLOAD_UNKNOWN = 0,
630         RTE_ETH_RAW_PAYLOAD,
631         RTE_ETH_L2_PAYLOAD,
632         RTE_ETH_L3_PAYLOAD,
633         RTE_ETH_L4_PAYLOAD,
634         RTE_ETH_PAYLOAD_MAX = 8,
635 };
636
637 /**
638  * A structure used to select bytes extracted from the protocol layers to
639  * flexible payload for filter
640  */
641 struct rte_eth_flex_payload_cfg {
642         enum rte_eth_payload_type type;  /**< Payload type */
643         uint16_t src_offset[RTE_ETH_FDIR_MAX_FLEXLEN];
644         /**< Offset in bytes from the beginning of packet's payload
645              src_offset[i] indicates the flexbyte i's offset in original
646              packet payload. This value should be less than
647              flex_payload_limit in struct rte_eth_fdir_info.*/
648 };
649
650 /**
651  * A structure used to define FDIR masks for flexible payload
652  * for each flow type
653  */
654 struct rte_eth_fdir_flex_mask {
655         uint16_t flow_type;
656         uint8_t mask[RTE_ETH_FDIR_MAX_FLEXLEN];
657         /**< Mask for the whole flexible payload */
658 };
659
660 /**
661  * A structure used to define all flexible payload related setting
662  * include flex payload and flex mask
663  */
664 struct rte_eth_fdir_flex_conf {
665         uint16_t nb_payloads;  /**< The number of following payload cfg */
666         uint16_t nb_flexmasks; /**< The number of following mask */
667         struct rte_eth_flex_payload_cfg flex_set[RTE_ETH_PAYLOAD_MAX];
668         /**< Flex payload configuration for each payload type */
669         struct rte_eth_fdir_flex_mask flex_mask[RTE_ETH_FLOW_MAX];
670         /**< Flex mask configuration for each flow type */
671 };
672
673 /**
674  *  Flow Director setting modes: none, signature or perfect.
675  */
676 enum rte_fdir_mode {
677         RTE_FDIR_MODE_NONE      = 0, /**< Disable FDIR support. */
678         RTE_FDIR_MODE_SIGNATURE,     /**< Enable FDIR signature filter mode. */
679         RTE_FDIR_MODE_PERFECT,       /**< Enable FDIR perfect filter mode. */
680         RTE_FDIR_MODE_PERFECT_MAC_VLAN, /**< Enable FDIR filter mode - MAC VLAN. */
681         RTE_FDIR_MODE_PERFECT_TUNNEL,   /**< Enable FDIR filter mode - tunnel. */
682 };
683
684 #define UINT32_BIT (CHAR_BIT * sizeof(uint32_t))
685 #define RTE_FLOW_MASK_ARRAY_SIZE \
686         (RTE_ALIGN(RTE_ETH_FLOW_MAX, UINT32_BIT)/UINT32_BIT)
687
688 /**
689  * A structure used to get the information of flow director filter.
690  * It supports RTE_ETH_FILTER_FDIR with RTE_ETH_FILTER_INFO operation.
691  * It includes the mode, flexible payload configuration information,
692  * capabilities and supported flow types, flexible payload characters.
693  * It can be gotten to help taking specific configurations per device.
694  */
695 struct rte_eth_fdir_info {
696         enum rte_fdir_mode mode; /**< Flow director mode */
697         struct rte_eth_fdir_masks mask;
698         /** Flex payload configuration information */
699         struct rte_eth_fdir_flex_conf flex_conf;
700         uint32_t guarant_spc; /**< Guaranteed spaces.*/
701         uint32_t best_spc; /**< Best effort spaces.*/
702         /** Bit mask for every supported flow type. */
703         uint32_t flow_types_mask[RTE_FLOW_MASK_ARRAY_SIZE];
704         uint32_t max_flexpayload; /**< Total flex payload in bytes. */
705         /** Flexible payload unit in bytes. Size and alignments of all flex
706             payload segments should be multiplies of this value. */
707         uint32_t flex_payload_unit;
708         /** Max number of flexible payload continuous segments.
709             Each segment should be a multiple of flex_payload_unit.*/
710         uint32_t max_flex_payload_segment_num;
711         /** Maximum src_offset in bytes allowed. It indicates that
712             src_offset[i] in struct rte_eth_flex_payload_cfg should be less
713             than this value. */
714         uint16_t flex_payload_limit;
715         /** Flex bitmask unit in bytes. Size of flex bitmasks should be a
716             multiply of this value. */
717         uint32_t flex_bitmask_unit;
718         /** Max supported size of flex bitmasks in flex_bitmask_unit */
719         uint32_t max_flex_bitmask_num;
720 };
721
722 /**
723  * A structure used to define the statistics of flow director.
724  * It supports RTE_ETH_FILTER_FDIR with RTE_ETH_FILTER_STATS operation.
725  */
726 struct rte_eth_fdir_stats {
727         uint32_t collision;    /**< Number of filters with collision. */
728         uint32_t free;         /**< Number of free filters. */
729         uint32_t maxhash;
730         /**< The lookup hash value of the added filter that updated the value
731            of the MAXLEN field */
732         uint32_t maxlen;       /**< Longest linked list of filters. */
733         uint64_t add;          /**< Number of added filters. */
734         uint64_t remove;       /**< Number of removed filters. */
735         uint64_t f_add;        /**< Number of failed added filters. */
736         uint64_t f_remove;     /**< Number of failed removed filters. */
737         uint32_t guarant_cnt;  /**< Number of filters in guaranteed spaces. */
738         uint32_t best_cnt;     /**< Number of filters in best effort spaces. */
739 };
740
741 /**
742  * Flow Director filter information types.
743  */
744 enum rte_eth_fdir_filter_info_type {
745         RTE_ETH_FDIR_FILTER_INFO_TYPE_UNKNOWN = 0,
746         /** Flow Director filter input set configuration */
747         RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT,
748         RTE_ETH_FDIR_FILTER_INFO_TYPE_MAX,
749 };
750
751 /**
752  * A structure used to set FDIR filter information, to support filter type
753  * of 'RTE_ETH_FILTER_FDIR' RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT operation.
754  */
755 struct rte_eth_fdir_filter_info {
756         enum rte_eth_fdir_filter_info_type info_type; /**< Information type */
757         /** Details of fdir filter information */
758         union {
759                 /** Flow Director input set configuration per port */
760                 struct rte_eth_input_set_conf input_set_conf;
761         } info;
762 };
763
764 /**
765  * Hash filter information types.
766  * - RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT is for getting/setting the
767  *   information/configuration of 'symmetric hash enable' per port.
768  * - RTE_ETH_HASH_FILTER_GLOBAL_CONFIG is for getting/setting the global
769  *   configurations of hash filters. Those global configurations are valid
770  *   for all ports of the same NIC.
771  * - RTE_ETH_HASH_FILTER_INPUT_SET_SELECT is for setting the global
772  *   hash input set fields
773  */
774 enum rte_eth_hash_filter_info_type {
775         RTE_ETH_HASH_FILTER_INFO_TYPE_UNKNOWN = 0,
776         /** Symmetric hash enable per port */
777         RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT,
778         /** Configure globally for hash filter */
779         RTE_ETH_HASH_FILTER_GLOBAL_CONFIG,
780         /** Global Hash filter input set configuration */
781         RTE_ETH_HASH_FILTER_INPUT_SET_SELECT,
782         RTE_ETH_HASH_FILTER_INFO_TYPE_MAX,
783 };
784
785 /**
786  * Hash function types.
787  */
788 enum rte_eth_hash_function {
789         RTE_ETH_HASH_FUNCTION_DEFAULT = 0,
790         RTE_ETH_HASH_FUNCTION_TOEPLITZ, /**< Toeplitz */
791         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR, /**< Simple XOR */
792         RTE_ETH_HASH_FUNCTION_MAX,
793 };
794
795 #define RTE_SYM_HASH_MASK_ARRAY_SIZE \
796         (RTE_ALIGN(RTE_ETH_FLOW_MAX, UINT32_BIT)/UINT32_BIT)
797 /**
798  * A structure used to set or get global hash function configurations which
799  * include symmetric hash enable per flow type and hash function type.
800  * Each bit in sym_hash_enable_mask[] indicates if the symmetric hash of the
801  * corresponding flow type is enabled or not.
802  * Each bit in valid_bit_mask[] indicates if the corresponding bit in
803  * sym_hash_enable_mask[] is valid or not. For the configurations gotten, it
804  * also means if the flow type is supported by hardware or not.
805  */
806 struct rte_eth_hash_global_conf {
807         enum rte_eth_hash_function hash_func; /**< Hash function type */
808         /** Bit mask for symmetric hash enable per flow type */
809         uint32_t sym_hash_enable_mask[RTE_SYM_HASH_MASK_ARRAY_SIZE];
810         /** Bit mask indicates if the corresponding bit is valid */
811         uint32_t valid_bit_mask[RTE_SYM_HASH_MASK_ARRAY_SIZE];
812 };
813
814 /**
815  * A structure used to set or get hash filter information, to support filter
816  * type of 'RTE_ETH_FILTER_HASH' and its operations.
817  */
818 struct rte_eth_hash_filter_info {
819         enum rte_eth_hash_filter_info_type info_type; /**< Information type */
820         /** Details of hash filter information */
821         union {
822                 /** For RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT */
823                 uint8_t enable;
824                 /** Global configurations of hash filter */
825                 struct rte_eth_hash_global_conf global_conf;
826                 /** Global configurations of hash filter input set */
827                 struct rte_eth_input_set_conf input_set_conf;
828         } info;
829 };
830
831 /**
832  * l2 tunnel configuration.
833  */
834 struct rte_eth_l2_tunnel_conf {
835         enum rte_eth_tunnel_type l2_tunnel_type;
836         uint16_t ether_type; /* ether type in l2 header */
837         uint32_t tunnel_id; /* port tag id for e-tag */
838         uint16_t vf_id; /* VF id for tag insertion */
839         uint32_t pool; /* destination pool for tag based forwarding */
840 };
841
842 #ifdef __cplusplus
843 }
844 #endif
845
846 #endif /* _RTE_ETH_CTRL_H_ */