ethdev: get flow director information
[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_TUNNEL,
56         RTE_ETH_FILTER_FDIR,
57         RTE_ETH_FILTER_MAX
58 };
59
60 /**
61  * Generic operations on filters
62  */
63 enum rte_filter_op {
64         RTE_ETH_FILTER_NOP = 0,
65         /**< used to check whether the type filter is supported */
66         RTE_ETH_FILTER_ADD,      /**< add filter entry */
67         RTE_ETH_FILTER_UPDATE,   /**< update filter entry */
68         RTE_ETH_FILTER_DELETE,   /**< delete filter entry */
69         RTE_ETH_FILTER_FLUSH,    /**< flush all entries */
70         RTE_ETH_FILTER_GET,      /**< get filter entry */
71         RTE_ETH_FILTER_SET,      /**< configurations */
72         RTE_ETH_FILTER_INFO,     /**< retrieve information */
73         RTE_ETH_FILTER_OP_MAX
74 };
75
76 /**
77  * MAC filter type
78  */
79 enum rte_mac_filter_type {
80         RTE_MAC_PERFECT_MATCH = 1, /**< exact match of MAC addr. */
81         RTE_MACVLAN_PERFECT_MATCH,
82         /**< exact match of MAC addr and VLAN ID. */
83         RTE_MAC_HASH_MATCH, /**< hash match of MAC addr. */
84         RTE_MACVLAN_HASH_MATCH,
85         /**< hash match of MAC addr and exact match of VLAN ID. */
86 };
87
88 /**
89  * MAC filter info
90  */
91 struct rte_eth_mac_filter {
92         uint8_t is_vf; /**< 1 for VF, 0 for port dev */
93         uint16_t dst_id; /**< VF ID, available when is_vf is 1*/
94         enum rte_mac_filter_type filter_type; /**< MAC filter type */
95         struct ether_addr mac_addr;
96 };
97
98 /**
99  * Tunneled type.
100  */
101 enum rte_eth_tunnel_type {
102         RTE_TUNNEL_TYPE_NONE = 0,
103         RTE_TUNNEL_TYPE_VXLAN,
104         RTE_TUNNEL_TYPE_GENEVE,
105         RTE_TUNNEL_TYPE_TEREDO,
106         RTE_TUNNEL_TYPE_NVGRE,
107         RTE_TUNNEL_TYPE_MAX,
108 };
109
110 /**
111  * filter type of tunneling packet
112  */
113 #define ETH_TUNNEL_FILTER_OMAC  0x01 /**< filter by outer MAC addr */
114 #define ETH_TUNNEL_FILTER_OIP   0x02 /**< filter by outer IP Addr */
115 #define ETH_TUNNEL_FILTER_TENID 0x04 /**< filter by tenant ID */
116 #define ETH_TUNNEL_FILTER_IMAC  0x08 /**< filter by inner MAC addr */
117 #define ETH_TUNNEL_FILTER_IVLAN 0x10 /**< filter by inner VLAN ID */
118 #define ETH_TUNNEL_FILTER_IIP   0x20 /**< filter by inner IP addr */
119
120 #define RTE_TUNNEL_FILTER_IMAC_IVLAN (ETH_TUNNEL_FILTER_IMAC | \
121                                         ETH_TUNNEL_FILTER_IVLAN)
122 #define RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID (ETH_TUNNEL_FILTER_IMAC | \
123                                         ETH_TUNNEL_FILTER_IVLAN | \
124                                         ETH_TUNNEL_FILTER_TENID)
125 #define RTE_TUNNEL_FILTER_IMAC_TENID (ETH_TUNNEL_FILTER_IMAC | \
126                                         ETH_TUNNEL_FILTER_TENID)
127 #define RTE_TUNNEL_FILTER_OMAC_TENID_IMAC (ETH_TUNNEL_FILTER_OMAC | \
128                                         ETH_TUNNEL_FILTER_TENID | \
129                                         ETH_TUNNEL_FILTER_IMAC)
130
131 /**
132  *  Select IPv4 or IPv6 for tunnel filters.
133  */
134 enum rte_tunnel_iptype {
135         RTE_TUNNEL_IPTYPE_IPV4 = 0, /**< IPv4. */
136         RTE_TUNNEL_IPTYPE_IPV6,     /**< IPv6. */
137 };
138
139 /**
140  * Tunneling Packet filter configuration.
141  */
142 struct rte_eth_tunnel_filter_conf {
143         struct ether_addr *outer_mac;  /**< Outer MAC address filter. */
144         struct ether_addr *inner_mac;  /**< Inner MAC address filter. */
145         uint16_t inner_vlan;           /**< Inner VLAN filter. */
146         enum rte_tunnel_iptype ip_type; /**< IP address type. */
147         union {
148                 uint32_t ipv4_addr;    /**< IPv4 source address to match. */
149                 uint32_t ipv6_addr[4]; /**< IPv6 source address to match. */
150         } ip_addr; /**< IPv4/IPv6 source address to match (union of above). */
151
152         uint16_t filter_type;   /**< Filter type. */
153         enum rte_eth_tunnel_type tunnel_type; /**< Tunnel Type. */
154         uint32_t tenant_id;     /** < Tenant number. */
155         uint16_t queue_id;      /** < queue number. */
156 };
157
158 #define RTE_ETH_FDIR_MAX_FLEXLEN         16 /** < Max length of flexbytes. */
159
160 /**
161  * Flow type
162  */
163 enum rte_eth_flow_type {
164         RTE_ETH_FLOW_TYPE_NONE = 0,
165         RTE_ETH_FLOW_TYPE_UDPV4,
166         RTE_ETH_FLOW_TYPE_TCPV4,
167         RTE_ETH_FLOW_TYPE_SCTPV4,
168         RTE_ETH_FLOW_TYPE_IPV4_OTHER,
169         RTE_ETH_FLOW_TYPE_FRAG_IPV4,
170         RTE_ETH_FLOW_TYPE_UDPV6,
171         RTE_ETH_FLOW_TYPE_TCPV6,
172         RTE_ETH_FLOW_TYPE_SCTPV6,
173         RTE_ETH_FLOW_TYPE_IPV6_OTHER,
174         RTE_ETH_FLOW_TYPE_FRAG_IPV6,
175         RTE_ETH_FLOW_TYPE_MAX = 64,
176 };
177
178 /**
179  * A structure used to define the input for IPV4 flow
180  */
181 struct rte_eth_ipv4_flow {
182         uint32_t src_ip;      /**< IPv4 source address to match. */
183         uint32_t dst_ip;      /**< IPv4 destination address to match. */
184 };
185
186 /**
187  * A structure used to define the input for IPV4 UDP flow
188  */
189 struct rte_eth_udpv4_flow {
190         struct rte_eth_ipv4_flow ip; /**< IPv4 fields to match. */
191         uint16_t src_port;           /**< UDP source port to match. */
192         uint16_t dst_port;           /**< UDP destination port to match. */
193 };
194
195 /**
196  * A structure used to define the input for IPV4 TCP flow
197  */
198 struct rte_eth_tcpv4_flow {
199         struct rte_eth_ipv4_flow ip; /**< IPv4 fields to match. */
200         uint16_t src_port;           /**< TCP source port to match. */
201         uint16_t dst_port;           /**< TCP destination port to match. */
202 };
203
204 /**
205  * A structure used to define the input for IPV4 SCTP flow
206  */
207 struct rte_eth_sctpv4_flow {
208         struct rte_eth_ipv4_flow ip; /**< IPv4 fields to match. */
209         uint32_t verify_tag;         /**< Verify tag to match */
210 };
211
212 /**
213  * A structure used to define the input for IPV6 flow
214  */
215 struct rte_eth_ipv6_flow {
216         uint32_t src_ip[4];      /**< IPv6 source address to match. */
217         uint32_t dst_ip[4];      /**< IPv6 destination address to match. */
218 };
219
220 /**
221  * A structure used to define the input for IPV6 UDP flow
222  */
223 struct rte_eth_udpv6_flow {
224         struct rte_eth_ipv6_flow ip; /**< IPv6 fields to match. */
225         uint16_t src_port;           /**< UDP source port to match. */
226         uint16_t dst_port;           /**< UDP destination port to match. */
227 };
228
229 /**
230  * A structure used to define the input for IPV6 TCP flow
231  */
232 struct rte_eth_tcpv6_flow {
233         struct rte_eth_ipv6_flow ip; /**< IPv6 fields to match. */
234         uint16_t src_port;           /**< TCP source port to match. */
235         uint16_t dst_port;           /**< TCP destination port to match. */
236 };
237
238 /**
239  * A structure used to define the input for IPV6 SCTP flow
240  */
241 struct rte_eth_sctpv6_flow {
242         struct rte_eth_ipv6_flow ip; /**< IPv6 fields to match. */
243         uint32_t verify_tag;         /**< Verify tag to match */
244 };
245
246 /**
247  * An union contains the inputs for all types of flow
248  */
249 union rte_eth_fdir_flow {
250         struct rte_eth_udpv4_flow  udp4_flow;
251         struct rte_eth_tcpv4_flow  tcp4_flow;
252         struct rte_eth_sctpv4_flow sctp4_flow;
253         struct rte_eth_ipv4_flow   ip4_flow;
254         struct rte_eth_udpv6_flow  udp6_flow;
255         struct rte_eth_tcpv6_flow  tcp6_flow;
256         struct rte_eth_sctpv6_flow sctp6_flow;
257         struct rte_eth_ipv6_flow   ip6_flow;
258 };
259
260 /**
261  * A structure used to contain extend input of flow
262  */
263 struct rte_eth_fdir_flow_ext {
264         uint16_t vlan_tci;
265         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
266         /**< It is filled by the flexible payload to match. */
267 };
268
269 /**
270  * A structure used to define the input for a flow director filter entry
271  */
272 struct rte_eth_fdir_input {
273         enum rte_eth_flow_type flow_type;      /**< Type of flow */
274         union rte_eth_fdir_flow flow;
275         /**< Flow fields to match, dependent on flow_type */
276         struct rte_eth_fdir_flow_ext flow_ext;
277         /**< Additional fields to match */
278 };
279
280 /**
281  * Behavior will be taken if FDIR match
282  */
283 enum rte_eth_fdir_behavior {
284         RTE_ETH_FDIR_ACCEPT = 0,
285         RTE_ETH_FDIR_REJECT,
286 };
287
288 /**
289  * Flow director report status
290  * It defines what will be reported if FDIR entry is matched.
291  */
292 enum rte_eth_fdir_status {
293         RTE_ETH_FDIR_NO_REPORT_STATUS = 0, /**< Report nothing. */
294         RTE_ETH_FDIR_REPORT_ID,            /**< Only report FD ID. */
295         RTE_ETH_FDIR_REPORT_ID_FLEX_4,     /**< Report FD ID and 4 flex bytes. */
296         RTE_ETH_FDIR_REPORT_FLEX_8,        /**< Report 8 flex bytes. */
297 };
298
299 /**
300  * A structure used to define an action when match FDIR packet filter.
301  */
302 struct rte_eth_fdir_action {
303         uint16_t rx_queue;        /**< Queue assigned to if FDIR match. */
304         enum rte_eth_fdir_behavior behavior;     /**< Behavior will be taken */
305         enum rte_eth_fdir_status report_status;  /**< Status report option */
306         uint8_t flex_off;
307         /**< If report_status is RTE_ETH_FDIR_REPORT_ID_FLEX_4 or
308              RTE_ETH_FDIR_REPORT_FLEX_8, flex_off specifies where the reported
309              flex bytes start from in flexible payload. */
310 };
311
312 /**
313  * A structure used to define the flow director filter entry by filter_ctrl API
314  * It supports RTE_ETH_FILTER_FDIR with RTE_ETH_FILTER_ADD and
315  * RTE_ETH_FILTER_DELETE operations.
316  */
317 struct rte_eth_fdir_filter {
318         uint32_t soft_id;
319         /**< ID, an unique value is required when deal with FDIR entry */
320         struct rte_eth_fdir_input input;    /**< Input set */
321         struct rte_eth_fdir_action action;  /**< Action taken when match */
322 };
323
324 /**
325  * Payload type
326  */
327 enum rte_eth_payload_type {
328         RTE_ETH_PAYLOAD_UNKNOWN = 0,
329         RTE_ETH_L2_PAYLOAD,
330         RTE_ETH_L3_PAYLOAD,
331         RTE_ETH_L4_PAYLOAD,
332         RTE_ETH_PAYLOAD_MAX = 8,
333 };
334
335 /**
336  * A structure used to select bytes extracted from the protocol layers to
337  * flexible payload for filter
338  */
339 struct rte_eth_flex_payload_cfg {
340         enum rte_eth_payload_type type;  /**< Payload type */
341         uint16_t src_offset[RTE_ETH_FDIR_MAX_FLEXLEN];
342         /**< Offset in bytes from the beginning of packet's payload
343              src_offset[i] indicates the flexbyte i's offset in original
344              packet payload. This value should be less than
345              flex_payload_limit in struct rte_eth_fdir_info.*/
346 };
347
348 /**
349  * A structure used to define FDIR masks for flexible payload
350  * for each flow type
351  */
352 struct rte_eth_fdir_flex_mask {
353         enum rte_eth_flow_type flow_type;  /**< Flow type */
354         uint8_t mask[RTE_ETH_FDIR_MAX_FLEXLEN];
355         /**< Mask for the whole flexible payload */
356 };
357
358 /**
359  * A structure used to define all flexible payload related setting
360  * include flexpay load and flex mask
361  */
362 struct rte_eth_fdir_flex_conf {
363         uint16_t nb_payloads;  /**< The number of following payload cfg */
364         uint16_t nb_flexmasks; /**< The number of following mask */
365         struct rte_eth_flex_payload_cfg flex_set[RTE_ETH_PAYLOAD_MAX];
366         /**< Flex payload configuration for each payload type */
367         struct rte_eth_fdir_flex_mask flex_mask[RTE_ETH_FLOW_TYPE_MAX];
368         /**< Flex mask configuration for each flow type */
369 };
370
371 /**
372  *  Flow Director setting modes: none, signature or perfect.
373  */
374 enum rte_fdir_mode {
375         RTE_FDIR_MODE_NONE      = 0, /**< Disable FDIR support. */
376         RTE_FDIR_MODE_SIGNATURE,     /**< Enable FDIR signature filter mode. */
377         RTE_FDIR_MODE_PERFECT,       /**< Enable FDIR perfect filter mode. */
378 };
379
380 /**
381  * A structure used to get the information of flow director filter.
382  * It supports RTE_ETH_FILTER_FDIR with RTE_ETH_FILTER_INFO operation.
383  * It includes the mode, flexible payload configuration information,
384  * capabilities and supported flow types, flexible payload characters.
385  * It can be gotten to help taking specific configurations per device.
386  */
387 struct rte_eth_fdir_info {
388         enum rte_fdir_mode mode;     /**< Flow director mode */
389         struct rte_eth_fdir_flex_conf flex_conf;
390         /**< Flex payload configuration information */
391         uint32_t guarant_spc;          /**< Guaranteed spaces.*/
392         uint32_t best_spc;             /**< Best effort spaces.*/
393         uint32_t flow_types_mask[RTE_ETH_FLOW_TYPE_MAX / sizeof(uint32_t)];
394         /**< Bit mask for every supported flow type. */
395         uint32_t max_flexpayload;      /**< Total flex payload in bytes. */
396         uint32_t flex_payload_unit;
397         /**< Flexible payload unit in bytes. Size and alignments of all flex
398              payload segments should be multiplies of this value. */
399         uint32_t max_flex_payload_segment_num;
400         /**< Max number of flexible payload continuous segments.
401              Each segment should be a multiple of flex_payload_unit.*/
402         uint16_t flex_payload_limit;
403         /**< Maximum src_offset in bytes allowed. It indicates that
404              src_offset[i] in struct rte_eth_flex_payload_cfg should be
405              less than this value. */
406         uint32_t flex_bitmask_unit;
407         /**< Flex bitmask unit in bytes. Size of flex bitmasks should
408              be a multiply of this value. */
409         uint32_t max_flex_bitmask_num;
410         /**< Max supported size of flex bitmasks in flex_bitmask_unit */
411 };
412
413 #ifdef __cplusplus
414 }
415 #endif
416
417 #endif /* _RTE_ETH_CTRL_H_ */