ethdev: extend flow type and flexible payload type for flow director
[dpdk.git] / lib / librte_ether / rte_eth_ctrl.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 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  * Feature filter types
51  */
52 enum rte_filter_type {
53         RTE_ETH_FILTER_NONE = 0,
54         RTE_ETH_FILTER_MACVLAN,
55         RTE_ETH_FILTER_ETHERTYPE,
56         RTE_ETH_FILTER_TUNNEL,
57         RTE_ETH_FILTER_FDIR,
58         RTE_ETH_FILTER_HASH,
59         RTE_ETH_FILTER_MAX
60 };
61
62 /**
63  * Generic operations on filters
64  */
65 enum rte_filter_op {
66         /** used to check whether the type filter is supported */
67         RTE_ETH_FILTER_NOP = 0,
68         RTE_ETH_FILTER_ADD,      /**< add filter entry */
69         RTE_ETH_FILTER_UPDATE,   /**< update filter entry */
70         RTE_ETH_FILTER_DELETE,   /**< delete filter entry */
71         RTE_ETH_FILTER_FLUSH,    /**< flush all entries */
72         RTE_ETH_FILTER_GET,      /**< get filter entry */
73         RTE_ETH_FILTER_SET,      /**< configurations */
74         RTE_ETH_FILTER_INFO,     /**< retrieve information */
75         RTE_ETH_FILTER_STATS,    /**< retrieve statistics */
76         RTE_ETH_FILTER_OP_MAX
77 };
78
79 /*
80  * MAC filter type
81  */
82 enum rte_mac_filter_type {
83         RTE_MAC_PERFECT_MATCH = 1, /**< exact match of MAC addr. */
84         RTE_MACVLAN_PERFECT_MATCH, /**< exact match of MAC addr and VLAN ID. */
85         RTE_MAC_HASH_MATCH, /**< hash match of MAC addr. */
86         /** hash match of MAC addr and exact match of VLAN ID. */
87         RTE_MACVLAN_HASH_MATCH,
88 };
89
90 /**
91  * MAC filter info
92  */
93 struct rte_eth_mac_filter {
94         uint8_t is_vf; /**< 1 for VF, 0 for port dev */
95         uint16_t dst_id; /**< VF ID, available when is_vf is 1*/
96         enum rte_mac_filter_type filter_type; /**< MAC filter type */
97         struct ether_addr mac_addr;
98 };
99
100 /**
101  * Define all structures for Ethertype Filter type.
102  */
103
104 #define RTE_ETHTYPE_FLAGS_MAC    0x0001 /**< If set, compare mac */
105 #define RTE_ETHTYPE_FLAGS_DROP   0x0002 /**< If set, drop packet when match */
106
107 /**
108  * A structure used to define the ethertype filter entry
109  * to support RTE_ETH_FILTER_ETHERTYPE with RTE_ETH_FILTER_ADD,
110  * RTE_ETH_FILTER_DELETE and RTE_ETH_FILTER_GET operations.
111  */
112 struct rte_eth_ethertype_filter {
113         struct ether_addr mac_addr;   /**< Mac address to match. */
114         uint16_t ether_type;          /**< Ether type to match */
115         uint16_t flags;               /**< Flags from RTE_ETHTYPE_FLAGS_* */
116         uint16_t queue;               /**< Queue assigned to when match*/
117 };
118
119 /**
120  * Tunneled type.
121  */
122 enum rte_eth_tunnel_type {
123         RTE_TUNNEL_TYPE_NONE = 0,
124         RTE_TUNNEL_TYPE_VXLAN,
125         RTE_TUNNEL_TYPE_GENEVE,
126         RTE_TUNNEL_TYPE_TEREDO,
127         RTE_TUNNEL_TYPE_NVGRE,
128         RTE_TUNNEL_TYPE_MAX,
129 };
130
131 /**
132  * filter type of tunneling packet
133  */
134 #define ETH_TUNNEL_FILTER_OMAC  0x01 /**< filter by outer MAC addr */
135 #define ETH_TUNNEL_FILTER_OIP   0x02 /**< filter by outer IP Addr */
136 #define ETH_TUNNEL_FILTER_TENID 0x04 /**< filter by tenant ID */
137 #define ETH_TUNNEL_FILTER_IMAC  0x08 /**< filter by inner MAC addr */
138 #define ETH_TUNNEL_FILTER_IVLAN 0x10 /**< filter by inner VLAN ID */
139 #define ETH_TUNNEL_FILTER_IIP   0x20 /**< filter by inner IP addr */
140
141 #define RTE_TUNNEL_FILTER_IMAC_IVLAN (ETH_TUNNEL_FILTER_IMAC | \
142                                         ETH_TUNNEL_FILTER_IVLAN)
143 #define RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID (ETH_TUNNEL_FILTER_IMAC | \
144                                         ETH_TUNNEL_FILTER_IVLAN | \
145                                         ETH_TUNNEL_FILTER_TENID)
146 #define RTE_TUNNEL_FILTER_IMAC_TENID (ETH_TUNNEL_FILTER_IMAC | \
147                                         ETH_TUNNEL_FILTER_TENID)
148 #define RTE_TUNNEL_FILTER_OMAC_TENID_IMAC (ETH_TUNNEL_FILTER_OMAC | \
149                                         ETH_TUNNEL_FILTER_TENID | \
150                                         ETH_TUNNEL_FILTER_IMAC)
151
152 /**
153  *  Select IPv4 or IPv6 for tunnel filters.
154  */
155 enum rte_tunnel_iptype {
156         RTE_TUNNEL_IPTYPE_IPV4 = 0, /**< IPv4. */
157         RTE_TUNNEL_IPTYPE_IPV6,     /**< IPv6. */
158 };
159
160 /**
161  * Tunneling Packet filter configuration.
162  */
163 struct rte_eth_tunnel_filter_conf {
164         struct ether_addr *outer_mac;  /**< Outer MAC address filter. */
165         struct ether_addr *inner_mac;  /**< Inner MAC address filter. */
166         uint16_t inner_vlan;           /**< Inner VLAN filter. */
167         enum rte_tunnel_iptype ip_type; /**< IP address type. */
168         union {
169                 uint32_t ipv4_addr;    /**< IPv4 source address to match. */
170                 uint32_t ipv6_addr[4]; /**< IPv6 source address to match. */
171         } ip_addr; /**< IPv4/IPv6 source address to match (union of above). */
172
173         uint16_t filter_type;   /**< Filter type. */
174         enum rte_eth_tunnel_type tunnel_type; /**< Tunnel Type. */
175         uint32_t tenant_id;     /** < Tenant number. */
176         uint16_t queue_id;      /** < queue number. */
177 };
178
179 #define RTE_ETH_FDIR_MAX_FLEXLEN         16 /** < Max length of flexbytes. */
180
181 /**
182  * Flow type
183  */
184 enum rte_eth_flow_type {
185         RTE_ETH_FLOW_TYPE_NONE = 0,
186         RTE_ETH_FLOW_TYPE_RAW,
187         RTE_ETH_FLOW_TYPE_UDPV4,
188         RTE_ETH_FLOW_TYPE_TCPV4,
189         RTE_ETH_FLOW_TYPE_SCTPV4,
190         RTE_ETH_FLOW_TYPE_IPV4_OTHER,
191         RTE_ETH_FLOW_TYPE_FRAG_IPV4,
192         RTE_ETH_FLOW_TYPE_UDPV6,
193         RTE_ETH_FLOW_TYPE_TCPV6,
194         RTE_ETH_FLOW_TYPE_SCTPV6,
195         RTE_ETH_FLOW_TYPE_IPV6_OTHER,
196         RTE_ETH_FLOW_TYPE_FRAG_IPV6,
197         RTE_ETH_FLOW_TYPE_MAX = 64,
198 };
199
200 /**
201  * A structure used to define the input for IPV4 flow
202  */
203 struct rte_eth_ipv4_flow {
204         uint32_t src_ip;      /**< IPv4 source address to match. */
205         uint32_t dst_ip;      /**< IPv4 destination address to match. */
206 };
207
208 /**
209  * A structure used to define the input for IPV4 UDP flow
210  */
211 struct rte_eth_udpv4_flow {
212         struct rte_eth_ipv4_flow ip; /**< IPv4 fields to match. */
213         uint16_t src_port;           /**< UDP source port to match. */
214         uint16_t dst_port;           /**< UDP destination port to match. */
215 };
216
217 /**
218  * A structure used to define the input for IPV4 TCP flow
219  */
220 struct rte_eth_tcpv4_flow {
221         struct rte_eth_ipv4_flow ip; /**< IPv4 fields to match. */
222         uint16_t src_port;           /**< TCP source port to match. */
223         uint16_t dst_port;           /**< TCP destination port to match. */
224 };
225
226 /**
227  * A structure used to define the input for IPV4 SCTP flow
228  */
229 struct rte_eth_sctpv4_flow {
230         struct rte_eth_ipv4_flow ip; /**< IPv4 fields to match. */
231         uint32_t verify_tag;         /**< Verify tag to match */
232 };
233
234 /**
235  * A structure used to define the input for IPV6 flow
236  */
237 struct rte_eth_ipv6_flow {
238         uint32_t src_ip[4];      /**< IPv6 source address to match. */
239         uint32_t dst_ip[4];      /**< IPv6 destination address to match. */
240 };
241
242 /**
243  * A structure used to define the input for IPV6 UDP flow
244  */
245 struct rte_eth_udpv6_flow {
246         struct rte_eth_ipv6_flow ip; /**< IPv6 fields to match. */
247         uint16_t src_port;           /**< UDP source port to match. */
248         uint16_t dst_port;           /**< UDP destination port to match. */
249 };
250
251 /**
252  * A structure used to define the input for IPV6 TCP flow
253  */
254 struct rte_eth_tcpv6_flow {
255         struct rte_eth_ipv6_flow ip; /**< IPv6 fields to match. */
256         uint16_t src_port;           /**< TCP source port to match. */
257         uint16_t dst_port;           /**< TCP destination port to match. */
258 };
259
260 /**
261  * A structure used to define the input for IPV6 SCTP flow
262  */
263 struct rte_eth_sctpv6_flow {
264         struct rte_eth_ipv6_flow ip; /**< IPv6 fields to match. */
265         uint32_t verify_tag;         /**< Verify tag to match */
266 };
267
268 /**
269  * An union contains the inputs for all types of flow
270  */
271 union rte_eth_fdir_flow {
272         struct rte_eth_udpv4_flow  udp4_flow;
273         struct rte_eth_tcpv4_flow  tcp4_flow;
274         struct rte_eth_sctpv4_flow sctp4_flow;
275         struct rte_eth_ipv4_flow   ip4_flow;
276         struct rte_eth_udpv6_flow  udp6_flow;
277         struct rte_eth_tcpv6_flow  tcp6_flow;
278         struct rte_eth_sctpv6_flow sctp6_flow;
279         struct rte_eth_ipv6_flow   ipv6_flow;
280 };
281
282 /**
283  * A structure used to contain extend input of flow
284  */
285 struct rte_eth_fdir_flow_ext {
286         uint16_t vlan_tci;
287         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
288         /**< It is filled by the flexible payload to match. */
289 };
290
291 /**
292  * A structure used to define the input for a flow director filter entry
293  */
294 struct rte_eth_fdir_input {
295         enum rte_eth_flow_type flow_type;      /**< Type of flow */
296         union rte_eth_fdir_flow flow;
297         /**< Flow fields to match, dependent on flow_type */
298         struct rte_eth_fdir_flow_ext flow_ext;
299         /**< Additional fields to match */
300 };
301
302 /**
303  * Behavior will be taken if FDIR match
304  */
305 enum rte_eth_fdir_behavior {
306         RTE_ETH_FDIR_ACCEPT = 0,
307         RTE_ETH_FDIR_REJECT,
308 };
309
310 /**
311  * Flow director report status
312  * It defines what will be reported if FDIR entry is matched.
313  */
314 enum rte_eth_fdir_status {
315         RTE_ETH_FDIR_NO_REPORT_STATUS = 0, /**< Report nothing. */
316         RTE_ETH_FDIR_REPORT_ID,            /**< Only report FD ID. */
317         RTE_ETH_FDIR_REPORT_ID_FLEX_4,     /**< Report FD ID and 4 flex bytes. */
318         RTE_ETH_FDIR_REPORT_FLEX_8,        /**< Report 8 flex bytes. */
319 };
320
321 /**
322  * A structure used to define an action when match FDIR packet filter.
323  */
324 struct rte_eth_fdir_action {
325         uint16_t rx_queue;        /**< Queue assigned to if FDIR match. */
326         enum rte_eth_fdir_behavior behavior;     /**< Behavior will be taken */
327         enum rte_eth_fdir_status report_status;  /**< Status report option */
328         uint8_t flex_off;
329         /**< If report_status is RTE_ETH_FDIR_REPORT_ID_FLEX_4 or
330              RTE_ETH_FDIR_REPORT_FLEX_8, flex_off specifies where the reported
331              flex bytes start from in flexible payload. */
332 };
333
334 /**
335  * A structure used to define the flow director filter entry by filter_ctrl API
336  * It supports RTE_ETH_FILTER_FDIR with RTE_ETH_FILTER_ADD and
337  * RTE_ETH_FILTER_DELETE operations.
338  */
339 struct rte_eth_fdir_filter {
340         uint32_t soft_id;
341         /**< ID, an unique value is required when deal with FDIR entry */
342         struct rte_eth_fdir_input input;    /**< Input set */
343         struct rte_eth_fdir_action action;  /**< Action taken when match */
344 };
345
346 /**
347  * Payload type
348  */
349 enum rte_eth_payload_type {
350         RTE_ETH_PAYLOAD_UNKNOWN = 0,
351         RTE_ETH_RAW_PAYLOAD,
352         RTE_ETH_L2_PAYLOAD,
353         RTE_ETH_L3_PAYLOAD,
354         RTE_ETH_L4_PAYLOAD,
355         RTE_ETH_PAYLOAD_MAX = 8,
356 };
357
358 /**
359  * A structure used to select bytes extracted from the protocol layers to
360  * flexible payload for filter
361  */
362 struct rte_eth_flex_payload_cfg {
363         enum rte_eth_payload_type type;  /**< Payload type */
364         uint16_t src_offset[RTE_ETH_FDIR_MAX_FLEXLEN];
365         /**< Offset in bytes from the beginning of packet's payload
366              src_offset[i] indicates the flexbyte i's offset in original
367              packet payload. This value should be less than
368              flex_payload_limit in struct rte_eth_fdir_info.*/
369 };
370
371 /**
372  * A structure used to define FDIR masks for flexible payload
373  * for each flow type
374  */
375 struct rte_eth_fdir_flex_mask {
376         enum rte_eth_flow_type flow_type;  /**< Flow type */
377         uint8_t mask[RTE_ETH_FDIR_MAX_FLEXLEN];
378         /**< Mask for the whole flexible payload */
379 };
380
381 /**
382  * A structure used to define all flexible payload related setting
383  * include flexpay load and flex mask
384  */
385 struct rte_eth_fdir_flex_conf {
386         uint16_t nb_payloads;  /**< The number of following payload cfg */
387         uint16_t nb_flexmasks; /**< The number of following mask */
388         struct rte_eth_flex_payload_cfg flex_set[RTE_ETH_PAYLOAD_MAX];
389         /**< Flex payload configuration for each payload type */
390         struct rte_eth_fdir_flex_mask flex_mask[RTE_ETH_FLOW_TYPE_MAX];
391         /**< Flex mask configuration for each flow type */
392 };
393
394 /**
395  *  Flow Director setting modes: none, signature or perfect.
396  */
397 enum rte_fdir_mode {
398         RTE_FDIR_MODE_NONE      = 0, /**< Disable FDIR support. */
399         RTE_FDIR_MODE_SIGNATURE,     /**< Enable FDIR signature filter mode. */
400         RTE_FDIR_MODE_PERFECT,       /**< Enable FDIR perfect filter mode. */
401 };
402
403 /**
404  * A structure used to get the information of flow director filter.
405  * It supports RTE_ETH_FILTER_FDIR with RTE_ETH_FILTER_INFO operation.
406  * It includes the mode, flexible payload configuration information,
407  * capabilities and supported flow types, flexible payload characters.
408  * It can be gotten to help taking specific configurations per device.
409  */
410 struct rte_eth_fdir_info {
411         enum rte_fdir_mode mode;     /**< Flow director mode */
412         struct rte_eth_fdir_flex_conf flex_conf;
413         /**< Flex payload configuration information */
414         uint32_t guarant_spc;          /**< Guaranteed spaces.*/
415         uint32_t best_spc;             /**< Best effort spaces.*/
416         uint32_t flow_types_mask[RTE_ETH_FLOW_TYPE_MAX / sizeof(uint32_t)];
417         /**< Bit mask for every supported flow type. */
418         uint32_t max_flexpayload;      /**< Total flex payload in bytes. */
419         uint32_t flex_payload_unit;
420         /**< Flexible payload unit in bytes. Size and alignments of all flex
421              payload segments should be multiplies of this value. */
422         uint32_t max_flex_payload_segment_num;
423         /**< Max number of flexible payload continuous segments.
424              Each segment should be a multiple of flex_payload_unit.*/
425         uint16_t flex_payload_limit;
426         /**< Maximum src_offset in bytes allowed. It indicates that
427              src_offset[i] in struct rte_eth_flex_payload_cfg should be
428              less than this value. */
429         uint32_t flex_bitmask_unit;
430         /**< Flex bitmask unit in bytes. Size of flex bitmasks should
431              be a multiply of this value. */
432         uint32_t max_flex_bitmask_num;
433         /**< Max supported size of flex bitmasks in flex_bitmask_unit */
434 };
435
436 /**
437  * A structure used to define the statistics of flow director.
438  * It supports RTE_ETH_FILTER_FDIR with RTE_ETH_FILTER_STATS operation.
439  */
440 struct rte_eth_fdir_stats {
441         uint32_t collision;    /**< Number of filters with collision. */
442         uint32_t free;         /**< Number of free filters. */
443         uint32_t maxhash;
444         /**< The lookup hash value of the added filter that updated the value
445            of the MAXLEN field */
446         uint32_t maxlen;       /**< Longest linked list of filters. */
447         uint64_t add;          /**< Number of added filters. */
448         uint64_t remove;       /**< Number of removed filters. */
449         uint64_t f_add;        /**< Number of failed added filters. */
450         uint64_t f_remove;     /**< Number of failed removed filters. */
451         uint32_t guarant_cnt;  /**< Number of filters in guaranteed spaces. */
452         uint32_t best_cnt;     /**< Number of filters in best effort spaces. */
453 };
454
455 /**
456  * Hash filter information types.
457  * - RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT is for getting/setting the
458  *   information/configuration of 'symmetric hash enable' per port.
459  * - RTE_ETH_HASH_FILTER_GLOBAL_CONFIG is for getting/setting the global
460  *   configurations of hash filters. Those global configurations are valid
461  *   for all ports of the same NIC.
462  */
463 enum rte_eth_hash_filter_info_type {
464         RTE_ETH_HASH_FILTER_INFO_TYPE_UNKNOWN = 0,
465         /** Symmetric hash enable per port */
466         RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT,
467         /** Configure globally for hash filter */
468         RTE_ETH_HASH_FILTER_GLOBAL_CONFIG,
469         RTE_ETH_HASH_FILTER_INFO_TYPE_MAX,
470 };
471
472 /**
473  * Hash function types.
474  */
475 enum rte_eth_hash_function {
476         RTE_ETH_HASH_FUNCTION_DEFAULT = 0,
477         RTE_ETH_HASH_FUNCTION_TOEPLITZ, /**< Toeplitz */
478         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR, /**< Simple XOR */
479         RTE_ETH_HASH_FUNCTION_MAX,
480 };
481
482 #define UINT32_BIT (CHAR_BIT * sizeof(uint32_t))
483 #define RTE_SYM_HASH_MASK_ARRAY_SIZE \
484         (RTE_ALIGN(RTE_ETH_FLOW_TYPE_MAX, UINT32_BIT)/UINT32_BIT)
485 /**
486  * A structure used to set or get global hash function configurations which
487  * include symmetric hash enable per flow type and hash function type.
488  * Each bit in sym_hash_enable_mask[] indicates if the symmetric hash of the
489  * coresponding flow type is enabled or not.
490  * Each bit in valid_bit_mask[] indicates if the corresponding bit in
491  * sym_hash_enable_mask[] is valid or not. For the configurations gotten, it
492  * also means if the flow type is supported by hardware or not.
493  */
494 struct rte_eth_hash_global_conf {
495         enum rte_eth_hash_function hash_func; /**< Hash function type */
496         /** Bit mask for symmetric hash enable per flow type */
497         uint32_t sym_hash_enable_mask[RTE_SYM_HASH_MASK_ARRAY_SIZE];
498         /** Bit mask indicates if the corresponding bit is valid */
499         uint32_t valid_bit_mask[RTE_SYM_HASH_MASK_ARRAY_SIZE];
500 };
501
502 /**
503  * A structure used to set or get hash filter information, to support filter
504  * type of 'RTE_ETH_FILTER_HASH' and its operations.
505  */
506 struct rte_eth_hash_filter_info {
507         enum rte_eth_hash_filter_info_type info_type; /**< Information type */
508         /** Details of hash filter information */
509         union {
510                 /** For RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT */
511                 uint8_t enable;
512                 /** Global configurations of hash filter */
513                 struct rte_eth_hash_global_conf global_conf;
514         } info;
515 };
516
517 #ifdef __cplusplus
518 }
519 #endif
520
521 #endif /* _RTE_ETH_CTRL_H_ */