ethdev: add Tx preparation
[dpdk.git] / lib / librte_ether / rte_ethdev.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 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_ETHDEV_H_
35 #define _RTE_ETHDEV_H_
36
37 /**
38  * @file
39  *
40  * RTE Ethernet Device API
41  *
42  * The Ethernet Device API is composed of two parts:
43  *
44  * - The application-oriented Ethernet API that includes functions to setup
45  *   an Ethernet device (configure it, setup its RX and TX queues and start it),
46  *   to get its MAC address, the speed and the status of its physical link,
47  *   to receive and to transmit packets, and so on.
48  *
49  * - The driver-oriented Ethernet API that exports a function allowing
50  *   an Ethernet Poll Mode Driver (PMD) to simultaneously register itself as
51  *   an Ethernet device driver and as a PCI driver for a set of matching PCI
52  *   [Ethernet] devices classes.
53  *
54  * By default, all the functions of the Ethernet Device API exported by a PMD
55  * are lock-free functions which assume to not be invoked in parallel on
56  * different logical cores to work on the same target object.  For instance,
57  * the receive function of a PMD cannot be invoked in parallel on two logical
58  * cores to poll the same RX queue [of the same port]. Of course, this function
59  * can be invoked in parallel by different logical cores on different RX queues.
60  * It is the responsibility of the upper level application to enforce this rule.
61  *
62  * If needed, parallel accesses by multiple logical cores to shared queues
63  * shall be explicitly protected by dedicated inline lock-aware functions
64  * built on top of their corresponding lock-free functions of the PMD API.
65  *
66  * In all functions of the Ethernet API, the Ethernet device is
67  * designated by an integer >= 0 named the device port identifier.
68  *
69  * At the Ethernet driver level, Ethernet devices are represented by a generic
70  * data structure of type *rte_eth_dev*.
71  *
72  * Ethernet devices are dynamically registered during the PCI probing phase
73  * performed at EAL initialization time.
74  * When an Ethernet device is being probed, an *rte_eth_dev* structure and
75  * a new port identifier are allocated for that device. Then, the eth_dev_init()
76  * function supplied by the Ethernet driver matching the probed PCI
77  * device is invoked to properly initialize the device.
78  *
79  * The role of the device init function consists of resetting the hardware,
80  * checking access to Non-volatile Memory (NVM), reading the MAC address
81  * from NVM etc.
82  *
83  * If the device init operation is successful, the correspondence between
84  * the port identifier assigned to the new device and its associated
85  * *rte_eth_dev* structure is effectively registered.
86  * Otherwise, both the *rte_eth_dev* structure and the port identifier are
87  * freed.
88  *
89  * The functions exported by the application Ethernet API to setup a device
90  * designated by its port identifier must be invoked in the following order:
91  *     - rte_eth_dev_configure()
92  *     - rte_eth_tx_queue_setup()
93  *     - rte_eth_rx_queue_setup()
94  *     - rte_eth_dev_start()
95  *
96  * Then, the network application can invoke, in any order, the functions
97  * exported by the Ethernet API to get the MAC address of a given device, to
98  * get the speed and the status of a device physical link, to receive/transmit
99  * [burst of] packets, and so on.
100  *
101  * If the application wants to change the configuration (i.e. call
102  * rte_eth_dev_configure(), rte_eth_tx_queue_setup(), or
103  * rte_eth_rx_queue_setup()), it must call rte_eth_dev_stop() first to stop the
104  * device and then do the reconfiguration before calling rte_eth_dev_start()
105  * again. The transmit and receive functions should not be invoked when the
106  * device is stopped.
107  *
108  * Please note that some configuration is not stored between calls to
109  * rte_eth_dev_stop()/rte_eth_dev_start(). The following configuration will
110  * be retained:
111  *
112  *     - flow control settings
113  *     - receive mode configuration (promiscuous mode, hardware checksum mode,
114  *       RSS/VMDQ settings etc.)
115  *     - VLAN filtering configuration
116  *     - MAC addresses supplied to MAC address array
117  *     - flow director filtering mode (but not filtering rules)
118  *     - NIC queue statistics mappings
119  *
120  * Any other configuration will not be stored and will need to be re-entered
121  * after a call to rte_eth_dev_start().
122  *
123  * Finally, a network application can close an Ethernet device by invoking the
124  * rte_eth_dev_close() function.
125  *
126  * Each function of the application Ethernet API invokes a specific function
127  * of the PMD that controls the target device designated by its port
128  * identifier.
129  * For this purpose, all device-specific functions of an Ethernet driver are
130  * supplied through a set of pointers contained in a generic structure of type
131  * *eth_dev_ops*.
132  * The address of the *eth_dev_ops* structure is stored in the *rte_eth_dev*
133  * structure by the device init function of the Ethernet driver, which is
134  * invoked during the PCI probing phase, as explained earlier.
135  *
136  * In other words, each function of the Ethernet API simply retrieves the
137  * *rte_eth_dev* structure associated with the device port identifier and
138  * performs an indirect invocation of the corresponding driver function
139  * supplied in the *eth_dev_ops* structure of the *rte_eth_dev* structure.
140  *
141  * For performance reasons, the address of the burst-oriented RX and TX
142  * functions of the Ethernet driver are not contained in the *eth_dev_ops*
143  * structure. Instead, they are directly stored at the beginning of the
144  * *rte_eth_dev* structure to avoid an extra indirect memory access during
145  * their invocation.
146  *
147  * RTE ethernet device drivers do not use interrupts for transmitting or
148  * receiving. Instead, Ethernet drivers export Poll-Mode receive and transmit
149  * functions to applications.
150  * Both receive and transmit functions are packet-burst oriented to minimize
151  * their cost per packet through the following optimizations:
152  *
153  * - Sharing among multiple packets the incompressible cost of the
154  *   invocation of receive/transmit functions.
155  *
156  * - Enabling receive/transmit functions to take advantage of burst-oriented
157  *   hardware features (L1 cache, prefetch instructions, NIC head/tail
158  *   registers) to minimize the number of CPU cycles per packet, for instance,
159  *   by avoiding useless read memory accesses to ring descriptors, or by
160  *   systematically using arrays of pointers that exactly fit L1 cache line
161  *   boundaries and sizes.
162  *
163  * The burst-oriented receive function does not provide any error notification,
164  * to avoid the corresponding overhead. As a hint, the upper-level application
165  * might check the status of the device link once being systematically returned
166  * a 0 value by the receive function of the driver for a given number of tries.
167  */
168
169 #ifdef __cplusplus
170 extern "C" {
171 #endif
172
173 #include <stdint.h>
174
175 #include <rte_dev.h>
176
177 /* Use this macro to check if LRO API is supported */
178 #define RTE_ETHDEV_HAS_LRO_SUPPORT
179
180 #include <rte_log.h>
181 #include <rte_interrupts.h>
182 #include <rte_pci.h>
183 #include <rte_dev.h>
184 #include <rte_devargs.h>
185 #include <rte_errno.h>
186 #include "rte_ether.h"
187 #include "rte_eth_ctrl.h"
188 #include "rte_dev_info.h"
189
190 struct rte_mbuf;
191
192 /**
193  * A structure used to retrieve statistics for an Ethernet port.
194  * Not all statistics fields in struct rte_eth_stats are supported
195  * by any type of network interface card (NIC). If any statistics
196  * field is not supported, its value is 0.
197  */
198 struct rte_eth_stats {
199         uint64_t ipackets;  /**< Total number of successfully received packets. */
200         uint64_t opackets;  /**< Total number of successfully transmitted packets.*/
201         uint64_t ibytes;    /**< Total number of successfully received bytes. */
202         uint64_t obytes;    /**< Total number of successfully transmitted bytes. */
203         uint64_t imissed;
204         /**< Total of RX packets dropped by the HW,
205          * because there are no available buffer (i.e. RX queues are full).
206          */
207         uint64_t ierrors;   /**< Total number of erroneous received packets. */
208         uint64_t oerrors;   /**< Total number of failed transmitted packets. */
209         uint64_t rx_nombuf; /**< Total number of RX mbuf allocation failures. */
210         uint64_t q_ipackets[RTE_ETHDEV_QUEUE_STAT_CNTRS];
211         /**< Total number of queue RX packets. */
212         uint64_t q_opackets[RTE_ETHDEV_QUEUE_STAT_CNTRS];
213         /**< Total number of queue TX packets. */
214         uint64_t q_ibytes[RTE_ETHDEV_QUEUE_STAT_CNTRS];
215         /**< Total number of successfully received queue bytes. */
216         uint64_t q_obytes[RTE_ETHDEV_QUEUE_STAT_CNTRS];
217         /**< Total number of successfully transmitted queue bytes. */
218         uint64_t q_errors[RTE_ETHDEV_QUEUE_STAT_CNTRS];
219         /**< Total number of queue packets received that are dropped. */
220 };
221
222 /**
223  * Device supported speeds bitmap flags
224  */
225 #define ETH_LINK_SPEED_AUTONEG  (0 <<  0)  /**< Autonegotiate (all speeds) */
226 #define ETH_LINK_SPEED_FIXED    (1 <<  0)  /**< Disable autoneg (fixed speed) */
227 #define ETH_LINK_SPEED_10M_HD   (1 <<  1)  /**<  10 Mbps half-duplex */
228 #define ETH_LINK_SPEED_10M      (1 <<  2)  /**<  10 Mbps full-duplex */
229 #define ETH_LINK_SPEED_100M_HD  (1 <<  3)  /**< 100 Mbps half-duplex */
230 #define ETH_LINK_SPEED_100M     (1 <<  4)  /**< 100 Mbps full-duplex */
231 #define ETH_LINK_SPEED_1G       (1 <<  5)  /**<   1 Gbps */
232 #define ETH_LINK_SPEED_2_5G     (1 <<  6)  /**< 2.5 Gbps */
233 #define ETH_LINK_SPEED_5G       (1 <<  7)  /**<   5 Gbps */
234 #define ETH_LINK_SPEED_10G      (1 <<  8)  /**<  10 Gbps */
235 #define ETH_LINK_SPEED_20G      (1 <<  9)  /**<  20 Gbps */
236 #define ETH_LINK_SPEED_25G      (1 << 10)  /**<  25 Gbps */
237 #define ETH_LINK_SPEED_40G      (1 << 11)  /**<  40 Gbps */
238 #define ETH_LINK_SPEED_50G      (1 << 12)  /**<  50 Gbps */
239 #define ETH_LINK_SPEED_56G      (1 << 13)  /**<  56 Gbps */
240 #define ETH_LINK_SPEED_100G     (1 << 14)  /**< 100 Gbps */
241
242 /**
243  * Ethernet numeric link speeds in Mbps
244  */
245 #define ETH_SPEED_NUM_NONE         0 /**< Not defined */
246 #define ETH_SPEED_NUM_10M         10 /**<  10 Mbps */
247 #define ETH_SPEED_NUM_100M       100 /**< 100 Mbps */
248 #define ETH_SPEED_NUM_1G        1000 /**<   1 Gbps */
249 #define ETH_SPEED_NUM_2_5G      2500 /**< 2.5 Gbps */
250 #define ETH_SPEED_NUM_5G        5000 /**<   5 Gbps */
251 #define ETH_SPEED_NUM_10G      10000 /**<  10 Gbps */
252 #define ETH_SPEED_NUM_20G      20000 /**<  20 Gbps */
253 #define ETH_SPEED_NUM_25G      25000 /**<  25 Gbps */
254 #define ETH_SPEED_NUM_40G      40000 /**<  40 Gbps */
255 #define ETH_SPEED_NUM_50G      50000 /**<  50 Gbps */
256 #define ETH_SPEED_NUM_56G      56000 /**<  56 Gbps */
257 #define ETH_SPEED_NUM_100G    100000 /**< 100 Gbps */
258
259 /**
260  * A structure used to retrieve link-level information of an Ethernet port.
261  */
262 __extension__
263 struct rte_eth_link {
264         uint32_t link_speed;        /**< ETH_SPEED_NUM_ */
265         uint16_t link_duplex  : 1;  /**< ETH_LINK_[HALF/FULL]_DUPLEX */
266         uint16_t link_autoneg : 1;  /**< ETH_LINK_SPEED_[AUTONEG/FIXED] */
267         uint16_t link_status  : 1;  /**< ETH_LINK_[DOWN/UP] */
268 } __attribute__((aligned(8)));      /**< aligned for atomic64 read/write */
269
270 /* Utility constants */
271 #define ETH_LINK_HALF_DUPLEX    0 /**< Half-duplex connection. */
272 #define ETH_LINK_FULL_DUPLEX    1 /**< Full-duplex connection. */
273 #define ETH_LINK_DOWN           0 /**< Link is down. */
274 #define ETH_LINK_UP             1 /**< Link is up. */
275 #define ETH_LINK_FIXED          0 /**< No autonegotiation. */
276 #define ETH_LINK_AUTONEG        1 /**< Autonegotiated. */
277
278 /**
279  * A structure used to configure the ring threshold registers of an RX/TX
280  * queue for an Ethernet port.
281  */
282 struct rte_eth_thresh {
283         uint8_t pthresh; /**< Ring prefetch threshold. */
284         uint8_t hthresh; /**< Ring host threshold. */
285         uint8_t wthresh; /**< Ring writeback threshold. */
286 };
287
288 /**
289  *  Simple flags are used for rte_eth_conf.rxmode.mq_mode.
290  */
291 #define ETH_MQ_RX_RSS_FLAG  0x1
292 #define ETH_MQ_RX_DCB_FLAG  0x2
293 #define ETH_MQ_RX_VMDQ_FLAG 0x4
294
295 /**
296  *  A set of values to identify what method is to be used to route
297  *  packets to multiple queues.
298  */
299 enum rte_eth_rx_mq_mode {
300         /** None of DCB,RSS or VMDQ mode */
301         ETH_MQ_RX_NONE = 0,
302
303         /** For RX side, only RSS is on */
304         ETH_MQ_RX_RSS = ETH_MQ_RX_RSS_FLAG,
305         /** For RX side,only DCB is on. */
306         ETH_MQ_RX_DCB = ETH_MQ_RX_DCB_FLAG,
307         /** Both DCB and RSS enable */
308         ETH_MQ_RX_DCB_RSS = ETH_MQ_RX_RSS_FLAG | ETH_MQ_RX_DCB_FLAG,
309
310         /** Only VMDQ, no RSS nor DCB */
311         ETH_MQ_RX_VMDQ_ONLY = ETH_MQ_RX_VMDQ_FLAG,
312         /** RSS mode with VMDQ */
313         ETH_MQ_RX_VMDQ_RSS = ETH_MQ_RX_RSS_FLAG | ETH_MQ_RX_VMDQ_FLAG,
314         /** Use VMDQ+DCB to route traffic to queues */
315         ETH_MQ_RX_VMDQ_DCB = ETH_MQ_RX_VMDQ_FLAG | ETH_MQ_RX_DCB_FLAG,
316         /** Enable both VMDQ and DCB in VMDq */
317         ETH_MQ_RX_VMDQ_DCB_RSS = ETH_MQ_RX_RSS_FLAG | ETH_MQ_RX_DCB_FLAG |
318                                  ETH_MQ_RX_VMDQ_FLAG,
319 };
320
321 /**
322  * for rx mq mode backward compatible
323  */
324 #define ETH_RSS                       ETH_MQ_RX_RSS
325 #define VMDQ_DCB                      ETH_MQ_RX_VMDQ_DCB
326 #define ETH_DCB_RX                    ETH_MQ_RX_DCB
327
328 /**
329  * A set of values to identify what method is to be used to transmit
330  * packets using multi-TCs.
331  */
332 enum rte_eth_tx_mq_mode {
333         ETH_MQ_TX_NONE    = 0,  /**< It is in neither DCB nor VT mode. */
334         ETH_MQ_TX_DCB,          /**< For TX side,only DCB is on. */
335         ETH_MQ_TX_VMDQ_DCB,     /**< For TX side,both DCB and VT is on. */
336         ETH_MQ_TX_VMDQ_ONLY,    /**< Only VT on, no DCB */
337 };
338
339 /**
340  * for tx mq mode backward compatible
341  */
342 #define ETH_DCB_NONE                ETH_MQ_TX_NONE
343 #define ETH_VMDQ_DCB_TX             ETH_MQ_TX_VMDQ_DCB
344 #define ETH_DCB_TX                  ETH_MQ_TX_DCB
345
346 /**
347  * A structure used to configure the RX features of an Ethernet port.
348  */
349 struct rte_eth_rxmode {
350         /** The multi-queue packet distribution mode to be used, e.g. RSS. */
351         enum rte_eth_rx_mq_mode mq_mode;
352         uint32_t max_rx_pkt_len;  /**< Only used if jumbo_frame enabled. */
353         uint16_t split_hdr_size;  /**< hdr buf size (header_split enabled).*/
354         __extension__
355         uint16_t header_split : 1, /**< Header Split enable. */
356                 hw_ip_checksum   : 1, /**< IP/UDP/TCP checksum offload enable. */
357                 hw_vlan_filter   : 1, /**< VLAN filter enable. */
358                 hw_vlan_strip    : 1, /**< VLAN strip enable. */
359                 hw_vlan_extend   : 1, /**< Extended VLAN enable. */
360                 jumbo_frame      : 1, /**< Jumbo Frame Receipt enable. */
361                 hw_strip_crc     : 1, /**< Enable CRC stripping by hardware. */
362                 enable_scatter   : 1, /**< Enable scatter packets rx handler */
363                 enable_lro       : 1; /**< Enable LRO */
364 };
365
366 /**
367  * VLAN types to indicate if it is for single VLAN, inner VLAN or outer VLAN.
368  * Note that single VLAN is treated the same as inner VLAN.
369  */
370 enum rte_vlan_type {
371         ETH_VLAN_TYPE_UNKNOWN = 0,
372         ETH_VLAN_TYPE_INNER, /**< Inner VLAN. */
373         ETH_VLAN_TYPE_OUTER, /**< Single VLAN, or outer VLAN. */
374         ETH_VLAN_TYPE_MAX,
375 };
376
377 /**
378  * A structure used to configure the Receive Side Scaling (RSS) feature
379  * of an Ethernet port.
380  * If not NULL, the *rss_key* pointer of the *rss_conf* structure points
381  * to an array holding the RSS key to use for hashing specific header
382  * fields of received packets. The length of this array should be indicated
383  * by *rss_key_len* below. Otherwise, a default random hash key is used by
384  * the device driver.
385  *
386  * The *rss_key_len* field of the *rss_conf* structure indicates the length
387  * in bytes of the array pointed by *rss_key*. To be compatible, this length
388  * will be checked in i40e only. Others assume 40 bytes to be used as before.
389  *
390  * The *rss_hf* field of the *rss_conf* structure indicates the different
391  * types of IPv4/IPv6 packets to which the RSS hashing must be applied.
392  * Supplying an *rss_hf* equal to zero disables the RSS feature.
393  */
394 struct rte_eth_rss_conf {
395         uint8_t *rss_key;    /**< If not NULL, 40-byte hash key. */
396         uint8_t rss_key_len; /**< hash key length in bytes. */
397         uint64_t rss_hf;     /**< Hash functions to apply - see below. */
398 };
399
400 /*
401  * The RSS offload types are defined based on flow types which are defined
402  * in rte_eth_ctrl.h. Different NIC hardwares may support different RSS offload
403  * types. The supported flow types or RSS offload types can be queried by
404  * rte_eth_dev_info_get().
405  */
406 #define ETH_RSS_IPV4               (1ULL << RTE_ETH_FLOW_IPV4)
407 #define ETH_RSS_FRAG_IPV4          (1ULL << RTE_ETH_FLOW_FRAG_IPV4)
408 #define ETH_RSS_NONFRAG_IPV4_TCP   (1ULL << RTE_ETH_FLOW_NONFRAG_IPV4_TCP)
409 #define ETH_RSS_NONFRAG_IPV4_UDP   (1ULL << RTE_ETH_FLOW_NONFRAG_IPV4_UDP)
410 #define ETH_RSS_NONFRAG_IPV4_SCTP  (1ULL << RTE_ETH_FLOW_NONFRAG_IPV4_SCTP)
411 #define ETH_RSS_NONFRAG_IPV4_OTHER (1ULL << RTE_ETH_FLOW_NONFRAG_IPV4_OTHER)
412 #define ETH_RSS_IPV6               (1ULL << RTE_ETH_FLOW_IPV6)
413 #define ETH_RSS_FRAG_IPV6          (1ULL << RTE_ETH_FLOW_FRAG_IPV6)
414 #define ETH_RSS_NONFRAG_IPV6_TCP   (1ULL << RTE_ETH_FLOW_NONFRAG_IPV6_TCP)
415 #define ETH_RSS_NONFRAG_IPV6_UDP   (1ULL << RTE_ETH_FLOW_NONFRAG_IPV6_UDP)
416 #define ETH_RSS_NONFRAG_IPV6_SCTP  (1ULL << RTE_ETH_FLOW_NONFRAG_IPV6_SCTP)
417 #define ETH_RSS_NONFRAG_IPV6_OTHER (1ULL << RTE_ETH_FLOW_NONFRAG_IPV6_OTHER)
418 #define ETH_RSS_L2_PAYLOAD         (1ULL << RTE_ETH_FLOW_L2_PAYLOAD)
419 #define ETH_RSS_IPV6_EX            (1ULL << RTE_ETH_FLOW_IPV6_EX)
420 #define ETH_RSS_IPV6_TCP_EX        (1ULL << RTE_ETH_FLOW_IPV6_TCP_EX)
421 #define ETH_RSS_IPV6_UDP_EX        (1ULL << RTE_ETH_FLOW_IPV6_UDP_EX)
422 #define ETH_RSS_PORT               (1ULL << RTE_ETH_FLOW_PORT)
423 #define ETH_RSS_VXLAN              (1ULL << RTE_ETH_FLOW_VXLAN)
424 #define ETH_RSS_GENEVE             (1ULL << RTE_ETH_FLOW_GENEVE)
425 #define ETH_RSS_NVGRE              (1ULL << RTE_ETH_FLOW_NVGRE)
426
427 #define ETH_RSS_IP ( \
428         ETH_RSS_IPV4 | \
429         ETH_RSS_FRAG_IPV4 | \
430         ETH_RSS_NONFRAG_IPV4_OTHER | \
431         ETH_RSS_IPV6 | \
432         ETH_RSS_FRAG_IPV6 | \
433         ETH_RSS_NONFRAG_IPV6_OTHER | \
434         ETH_RSS_IPV6_EX)
435
436 #define ETH_RSS_UDP ( \
437         ETH_RSS_NONFRAG_IPV4_UDP | \
438         ETH_RSS_NONFRAG_IPV6_UDP | \
439         ETH_RSS_IPV6_UDP_EX)
440
441 #define ETH_RSS_TCP ( \
442         ETH_RSS_NONFRAG_IPV4_TCP | \
443         ETH_RSS_NONFRAG_IPV6_TCP | \
444         ETH_RSS_IPV6_TCP_EX)
445
446 #define ETH_RSS_SCTP ( \
447         ETH_RSS_NONFRAG_IPV4_SCTP | \
448         ETH_RSS_NONFRAG_IPV6_SCTP)
449
450 #define ETH_RSS_TUNNEL ( \
451         ETH_RSS_VXLAN  | \
452         ETH_RSS_GENEVE | \
453         ETH_RSS_NVGRE)
454
455
456 /**< Mask of valid RSS hash protocols */
457 #define ETH_RSS_PROTO_MASK ( \
458         ETH_RSS_IPV4 | \
459         ETH_RSS_FRAG_IPV4 | \
460         ETH_RSS_NONFRAG_IPV4_TCP | \
461         ETH_RSS_NONFRAG_IPV4_UDP | \
462         ETH_RSS_NONFRAG_IPV4_SCTP | \
463         ETH_RSS_NONFRAG_IPV4_OTHER | \
464         ETH_RSS_IPV6 | \
465         ETH_RSS_FRAG_IPV6 | \
466         ETH_RSS_NONFRAG_IPV6_TCP | \
467         ETH_RSS_NONFRAG_IPV6_UDP | \
468         ETH_RSS_NONFRAG_IPV6_SCTP | \
469         ETH_RSS_NONFRAG_IPV6_OTHER | \
470         ETH_RSS_L2_PAYLOAD | \
471         ETH_RSS_IPV6_EX | \
472         ETH_RSS_IPV6_TCP_EX | \
473         ETH_RSS_IPV6_UDP_EX | \
474         ETH_RSS_PORT  | \
475         ETH_RSS_VXLAN | \
476         ETH_RSS_GENEVE | \
477         ETH_RSS_NVGRE)
478
479 /*
480  * Definitions used for redirection table entry size.
481  * Some RSS RETA sizes may not be supported by some drivers, check the
482  * documentation or the description of relevant functions for more details.
483  */
484 #define ETH_RSS_RETA_SIZE_64  64
485 #define ETH_RSS_RETA_SIZE_128 128
486 #define ETH_RSS_RETA_SIZE_256 256
487 #define ETH_RSS_RETA_SIZE_512 512
488 #define RTE_RETA_GROUP_SIZE   64
489
490 /* Definitions used for VMDQ and DCB functionality */
491 #define ETH_VMDQ_MAX_VLAN_FILTERS   64 /**< Maximum nb. of VMDQ vlan filters. */
492 #define ETH_DCB_NUM_USER_PRIORITIES 8  /**< Maximum nb. of DCB priorities. */
493 #define ETH_VMDQ_DCB_NUM_QUEUES     128 /**< Maximum nb. of VMDQ DCB queues. */
494 #define ETH_DCB_NUM_QUEUES          128 /**< Maximum nb. of DCB queues. */
495
496 /* DCB capability defines */
497 #define ETH_DCB_PG_SUPPORT      0x00000001 /**< Priority Group(ETS) support. */
498 #define ETH_DCB_PFC_SUPPORT     0x00000002 /**< Priority Flow Control support. */
499
500 /* Definitions used for VLAN Offload functionality */
501 #define ETH_VLAN_STRIP_OFFLOAD   0x0001 /**< VLAN Strip  On/Off */
502 #define ETH_VLAN_FILTER_OFFLOAD  0x0002 /**< VLAN Filter On/Off */
503 #define ETH_VLAN_EXTEND_OFFLOAD  0x0004 /**< VLAN Extend On/Off */
504
505 /* Definitions used for mask VLAN setting */
506 #define ETH_VLAN_STRIP_MASK   0x0001 /**< VLAN Strip  setting mask */
507 #define ETH_VLAN_FILTER_MASK  0x0002 /**< VLAN Filter  setting mask*/
508 #define ETH_VLAN_EXTEND_MASK  0x0004 /**< VLAN Extend  setting mask*/
509 #define ETH_VLAN_ID_MAX       0x0FFF /**< VLAN ID is in lower 12 bits*/
510
511 /* Definitions used for receive MAC address   */
512 #define ETH_NUM_RECEIVE_MAC_ADDR  128 /**< Maximum nb. of receive mac addr. */
513
514 /* Definitions used for unicast hash  */
515 #define ETH_VMDQ_NUM_UC_HASH_ARRAY  128 /**< Maximum nb. of UC hash array. */
516
517 /* Definitions used for VMDQ pool rx mode setting */
518 #define ETH_VMDQ_ACCEPT_UNTAG   0x0001 /**< accept untagged packets. */
519 #define ETH_VMDQ_ACCEPT_HASH_MC 0x0002 /**< accept packets in multicast table . */
520 #define ETH_VMDQ_ACCEPT_HASH_UC 0x0004 /**< accept packets in unicast table. */
521 #define ETH_VMDQ_ACCEPT_BROADCAST   0x0008 /**< accept broadcast packets. */
522 #define ETH_VMDQ_ACCEPT_MULTICAST   0x0010 /**< multicast promiscuous. */
523
524 /** Maximum nb. of vlan per mirror rule */
525 #define ETH_MIRROR_MAX_VLANS       64
526
527 #define ETH_MIRROR_VIRTUAL_POOL_UP     0x01  /**< Virtual Pool uplink Mirroring. */
528 #define ETH_MIRROR_UPLINK_PORT         0x02  /**< Uplink Port Mirroring. */
529 #define ETH_MIRROR_DOWNLINK_PORT       0x04  /**< Downlink Port Mirroring. */
530 #define ETH_MIRROR_VLAN                0x08  /**< VLAN Mirroring. */
531 #define ETH_MIRROR_VIRTUAL_POOL_DOWN   0x10  /**< Virtual Pool downlink Mirroring. */
532
533 /**
534  * A structure used to configure VLAN traffic mirror of an Ethernet port.
535  */
536 struct rte_eth_vlan_mirror {
537         uint64_t vlan_mask; /**< mask for valid VLAN ID. */
538         /** VLAN ID list for vlan mirroring. */
539         uint16_t vlan_id[ETH_MIRROR_MAX_VLANS];
540 };
541
542 /**
543  * A structure used to configure traffic mirror of an Ethernet port.
544  */
545 struct rte_eth_mirror_conf {
546         uint8_t rule_type; /**< Mirroring rule type */
547         uint8_t dst_pool;  /**< Destination pool for this mirror rule. */
548         uint64_t pool_mask; /**< Bitmap of pool for pool mirroring */
549         /** VLAN ID setting for VLAN mirroring. */
550         struct rte_eth_vlan_mirror vlan;
551 };
552
553 /**
554  * A structure used to configure 64 entries of Redirection Table of the
555  * Receive Side Scaling (RSS) feature of an Ethernet port. To configure
556  * more than 64 entries supported by hardware, an array of this structure
557  * is needed.
558  */
559 struct rte_eth_rss_reta_entry64 {
560         uint64_t mask;
561         /**< Mask bits indicate which entries need to be updated/queried. */
562         uint16_t reta[RTE_RETA_GROUP_SIZE];
563         /**< Group of 64 redirection table entries. */
564 };
565
566 /**
567  * This enum indicates the possible number of traffic classes
568  * in DCB configratioins
569  */
570 enum rte_eth_nb_tcs {
571         ETH_4_TCS = 4, /**< 4 TCs with DCB. */
572         ETH_8_TCS = 8  /**< 8 TCs with DCB. */
573 };
574
575 /**
576  * This enum indicates the possible number of queue pools
577  * in VMDQ configurations.
578  */
579 enum rte_eth_nb_pools {
580         ETH_8_POOLS = 8,    /**< 8 VMDq pools. */
581         ETH_16_POOLS = 16,  /**< 16 VMDq pools. */
582         ETH_32_POOLS = 32,  /**< 32 VMDq pools. */
583         ETH_64_POOLS = 64   /**< 64 VMDq pools. */
584 };
585
586 /* This structure may be extended in future. */
587 struct rte_eth_dcb_rx_conf {
588         enum rte_eth_nb_tcs nb_tcs; /**< Possible DCB TCs, 4 or 8 TCs */
589         /** Traffic class each UP mapped to. */
590         uint8_t dcb_tc[ETH_DCB_NUM_USER_PRIORITIES];
591 };
592
593 struct rte_eth_vmdq_dcb_tx_conf {
594         enum rte_eth_nb_pools nb_queue_pools; /**< With DCB, 16 or 32 pools. */
595         /** Traffic class each UP mapped to. */
596         uint8_t dcb_tc[ETH_DCB_NUM_USER_PRIORITIES];
597 };
598
599 struct rte_eth_dcb_tx_conf {
600         enum rte_eth_nb_tcs nb_tcs; /**< Possible DCB TCs, 4 or 8 TCs. */
601         /** Traffic class each UP mapped to. */
602         uint8_t dcb_tc[ETH_DCB_NUM_USER_PRIORITIES];
603 };
604
605 struct rte_eth_vmdq_tx_conf {
606         enum rte_eth_nb_pools nb_queue_pools; /**< VMDq mode, 64 pools. */
607 };
608
609 /**
610  * A structure used to configure the VMDQ+DCB feature
611  * of an Ethernet port.
612  *
613  * Using this feature, packets are routed to a pool of queues, based
614  * on the vlan id in the vlan tag, and then to a specific queue within
615  * that pool, using the user priority vlan tag field.
616  *
617  * A default pool may be used, if desired, to route all traffic which
618  * does not match the vlan filter rules.
619  */
620 struct rte_eth_vmdq_dcb_conf {
621         enum rte_eth_nb_pools nb_queue_pools; /**< With DCB, 16 or 32 pools */
622         uint8_t enable_default_pool; /**< If non-zero, use a default pool */
623         uint8_t default_pool; /**< The default pool, if applicable */
624         uint8_t nb_pool_maps; /**< We can have up to 64 filters/mappings */
625         struct {
626                 uint16_t vlan_id; /**< The vlan id of the received frame */
627                 uint64_t pools;   /**< Bitmask of pools for packet rx */
628         } pool_map[ETH_VMDQ_MAX_VLAN_FILTERS]; /**< VMDq vlan pool maps. */
629         uint8_t dcb_tc[ETH_DCB_NUM_USER_PRIORITIES];
630         /**< Selects a queue in a pool */
631 };
632
633 struct rte_eth_vmdq_rx_conf {
634         enum rte_eth_nb_pools nb_queue_pools; /**< VMDq only mode, 8 or 64 pools */
635         uint8_t enable_default_pool; /**< If non-zero, use a default pool */
636         uint8_t default_pool; /**< The default pool, if applicable */
637         uint8_t enable_loop_back; /**< Enable VT loop back */
638         uint8_t nb_pool_maps; /**< We can have up to 64 filters/mappings */
639         uint32_t rx_mode; /**< Flags from ETH_VMDQ_ACCEPT_* */
640         struct {
641                 uint16_t vlan_id; /**< The vlan id of the received frame */
642                 uint64_t pools;   /**< Bitmask of pools for packet rx */
643         } pool_map[ETH_VMDQ_MAX_VLAN_FILTERS]; /**< VMDq vlan pool maps. */
644 };
645
646 /**
647  * A structure used to configure the TX features of an Ethernet port.
648  */
649 struct rte_eth_txmode {
650         enum rte_eth_tx_mq_mode mq_mode; /**< TX multi-queues mode. */
651
652         /* For i40e specifically */
653         uint16_t pvid;
654         __extension__
655         uint8_t hw_vlan_reject_tagged : 1,
656                 /**< If set, reject sending out tagged pkts */
657                 hw_vlan_reject_untagged : 1,
658                 /**< If set, reject sending out untagged pkts */
659                 hw_vlan_insert_pvid : 1;
660                 /**< If set, enable port based VLAN insertion */
661 };
662
663 /**
664  * A structure used to configure an RX ring of an Ethernet port.
665  */
666 struct rte_eth_rxconf {
667         struct rte_eth_thresh rx_thresh; /**< RX ring threshold registers. */
668         uint16_t rx_free_thresh; /**< Drives the freeing of RX descriptors. */
669         uint8_t rx_drop_en; /**< Drop packets if no descriptors are available. */
670         uint8_t rx_deferred_start; /**< Do not start queue with rte_eth_dev_start(). */
671 };
672
673 #define ETH_TXQ_FLAGS_NOMULTSEGS 0x0001 /**< nb_segs=1 for all mbufs */
674 #define ETH_TXQ_FLAGS_NOREFCOUNT 0x0002 /**< refcnt can be ignored */
675 #define ETH_TXQ_FLAGS_NOMULTMEMP 0x0004 /**< all bufs come from same mempool */
676 #define ETH_TXQ_FLAGS_NOVLANOFFL 0x0100 /**< disable VLAN offload */
677 #define ETH_TXQ_FLAGS_NOXSUMSCTP 0x0200 /**< disable SCTP checksum offload */
678 #define ETH_TXQ_FLAGS_NOXSUMUDP  0x0400 /**< disable UDP checksum offload */
679 #define ETH_TXQ_FLAGS_NOXSUMTCP  0x0800 /**< disable TCP checksum offload */
680 #define ETH_TXQ_FLAGS_NOOFFLOADS \
681                 (ETH_TXQ_FLAGS_NOVLANOFFL | ETH_TXQ_FLAGS_NOXSUMSCTP | \
682                  ETH_TXQ_FLAGS_NOXSUMUDP  | ETH_TXQ_FLAGS_NOXSUMTCP)
683 #define ETH_TXQ_FLAGS_NOXSUMS \
684                 (ETH_TXQ_FLAGS_NOXSUMSCTP | ETH_TXQ_FLAGS_NOXSUMUDP | \
685                  ETH_TXQ_FLAGS_NOXSUMTCP)
686 /**
687  * A structure used to configure a TX ring of an Ethernet port.
688  */
689 struct rte_eth_txconf {
690         struct rte_eth_thresh tx_thresh; /**< TX ring threshold registers. */
691         uint16_t tx_rs_thresh; /**< Drives the setting of RS bit on TXDs. */
692         uint16_t tx_free_thresh; /**< Start freeing TX buffers if there are
693                                       less free descriptors than this value. */
694
695         uint32_t txq_flags; /**< Set flags for the Tx queue */
696         uint8_t tx_deferred_start; /**< Do not start queue with rte_eth_dev_start(). */
697 };
698
699 /**
700  * A structure contains information about HW descriptor ring limitations.
701  */
702 struct rte_eth_desc_lim {
703         uint16_t nb_max;   /**< Max allowed number of descriptors. */
704         uint16_t nb_min;   /**< Min allowed number of descriptors. */
705         uint16_t nb_align; /**< Number of descriptors should be aligned to. */
706
707         /**
708          * Max allowed number of segments per whole packet.
709          *
710          * - For TSO packet this is the total number of data descriptors allowed
711          *   by device.
712          *
713          * @see nb_mtu_seg_max
714          */
715         uint16_t nb_seg_max;
716
717         /**
718          * Max number of segments per one MTU.
719          *
720          * - For non-TSO packet, this is the maximum allowed number of segments
721          *   in a single transmit packet.
722          *
723          * - For TSO packet each segment within the TSO may span up to this
724          *   value.
725          *
726          * @see nb_seg_max
727          */
728         uint16_t nb_mtu_seg_max;
729 };
730
731 /**
732  * This enum indicates the flow control mode
733  */
734 enum rte_eth_fc_mode {
735         RTE_FC_NONE = 0, /**< Disable flow control. */
736         RTE_FC_RX_PAUSE, /**< RX pause frame, enable flowctrl on TX side. */
737         RTE_FC_TX_PAUSE, /**< TX pause frame, enable flowctrl on RX side. */
738         RTE_FC_FULL      /**< Enable flow control on both side. */
739 };
740
741 /**
742  * A structure used to configure Ethernet flow control parameter.
743  * These parameters will be configured into the register of the NIC.
744  * Please refer to the corresponding data sheet for proper value.
745  */
746 struct rte_eth_fc_conf {
747         uint32_t high_water;  /**< High threshold value to trigger XOFF */
748         uint32_t low_water;   /**< Low threshold value to trigger XON */
749         uint16_t pause_time;  /**< Pause quota in the Pause frame */
750         uint16_t send_xon;    /**< Is XON frame need be sent */
751         enum rte_eth_fc_mode mode;  /**< Link flow control mode */
752         uint8_t mac_ctrl_frame_fwd; /**< Forward MAC control frames */
753         uint8_t autoneg;      /**< Use Pause autoneg */
754 };
755
756 /**
757  * A structure used to configure Ethernet priority flow control parameter.
758  * These parameters will be configured into the register of the NIC.
759  * Please refer to the corresponding data sheet for proper value.
760  */
761 struct rte_eth_pfc_conf {
762         struct rte_eth_fc_conf fc; /**< General flow control parameter. */
763         uint8_t priority;          /**< VLAN User Priority. */
764 };
765
766 /**
767  *  Memory space that can be configured to store Flow Director filters
768  *  in the board memory.
769  */
770 enum rte_fdir_pballoc_type {
771         RTE_FDIR_PBALLOC_64K = 0,  /**< 64k. */
772         RTE_FDIR_PBALLOC_128K,     /**< 128k. */
773         RTE_FDIR_PBALLOC_256K,     /**< 256k. */
774 };
775
776 /**
777  *  Select report mode of FDIR hash information in RX descriptors.
778  */
779 enum rte_fdir_status_mode {
780         RTE_FDIR_NO_REPORT_STATUS = 0, /**< Never report FDIR hash. */
781         RTE_FDIR_REPORT_STATUS, /**< Only report FDIR hash for matching pkts. */
782         RTE_FDIR_REPORT_STATUS_ALWAYS, /**< Always report FDIR hash. */
783 };
784
785 /**
786  * A structure used to configure the Flow Director (FDIR) feature
787  * of an Ethernet port.
788  *
789  * If mode is RTE_FDIR_DISABLE, the pballoc value is ignored.
790  */
791 struct rte_fdir_conf {
792         enum rte_fdir_mode mode; /**< Flow Director mode. */
793         enum rte_fdir_pballoc_type pballoc; /**< Space for FDIR filters. */
794         enum rte_fdir_status_mode status;  /**< How to report FDIR hash. */
795         /** RX queue of packets matching a "drop" filter in perfect mode. */
796         uint8_t drop_queue;
797         struct rte_eth_fdir_masks mask;
798         struct rte_eth_fdir_flex_conf flex_conf;
799         /**< Flex payload configuration. */
800 };
801
802 /**
803  * UDP tunneling configuration.
804  * Used to config the UDP port for a type of tunnel.
805  * NICs need the UDP port to identify the tunnel type.
806  * Normally a type of tunnel has a default UDP port, this structure can be used
807  * in case if the users want to change or support more UDP port.
808  */
809 struct rte_eth_udp_tunnel {
810         uint16_t udp_port; /**< UDP port used for the tunnel. */
811         uint8_t prot_type; /**< Tunnel type. Defined in rte_eth_tunnel_type. */
812 };
813
814 /**
815  * A structure used to enable/disable specific device interrupts.
816  */
817 struct rte_intr_conf {
818         /** enable/disable lsc interrupt. 0 (default) - disable, 1 enable */
819         uint16_t lsc;
820         /** enable/disable rxq interrupt. 0 (default) - disable, 1 enable */
821         uint16_t rxq;
822 };
823
824 /**
825  * A structure used to configure an Ethernet port.
826  * Depending upon the RX multi-queue mode, extra advanced
827  * configuration settings may be needed.
828  */
829 struct rte_eth_conf {
830         uint32_t link_speeds; /**< bitmap of ETH_LINK_SPEED_XXX of speeds to be
831                                 used. ETH_LINK_SPEED_FIXED disables link
832                                 autonegotiation, and a unique speed shall be
833                                 set. Otherwise, the bitmap defines the set of
834                                 speeds to be advertised. If the special value
835                                 ETH_LINK_SPEED_AUTONEG (0) is used, all speeds
836                                 supported are advertised. */
837         struct rte_eth_rxmode rxmode; /**< Port RX configuration. */
838         struct rte_eth_txmode txmode; /**< Port TX configuration. */
839         uint32_t lpbk_mode; /**< Loopback operation mode. By default the value
840                                  is 0, meaning the loopback mode is disabled.
841                                  Read the datasheet of given ethernet controller
842                                  for details. The possible values of this field
843                                  are defined in implementation of each driver. */
844         struct {
845                 struct rte_eth_rss_conf rss_conf; /**< Port RSS configuration */
846                 struct rte_eth_vmdq_dcb_conf vmdq_dcb_conf;
847                 /**< Port vmdq+dcb configuration. */
848                 struct rte_eth_dcb_rx_conf dcb_rx_conf;
849                 /**< Port dcb RX configuration. */
850                 struct rte_eth_vmdq_rx_conf vmdq_rx_conf;
851                 /**< Port vmdq RX configuration. */
852         } rx_adv_conf; /**< Port RX filtering configuration (union). */
853         union {
854                 struct rte_eth_vmdq_dcb_tx_conf vmdq_dcb_tx_conf;
855                 /**< Port vmdq+dcb TX configuration. */
856                 struct rte_eth_dcb_tx_conf dcb_tx_conf;
857                 /**< Port dcb TX configuration. */
858                 struct rte_eth_vmdq_tx_conf vmdq_tx_conf;
859                 /**< Port vmdq TX configuration. */
860         } tx_adv_conf; /**< Port TX DCB configuration (union). */
861         /** Currently,Priority Flow Control(PFC) are supported,if DCB with PFC
862             is needed,and the variable must be set ETH_DCB_PFC_SUPPORT. */
863         uint32_t dcb_capability_en;
864         struct rte_fdir_conf fdir_conf; /**< FDIR configuration. */
865         struct rte_intr_conf intr_conf; /**< Interrupt mode configuration. */
866 };
867
868 /**
869  * A structure used to retrieve the contextual information of
870  * an Ethernet device, such as the controlling driver of the device,
871  * its PCI context, etc...
872  */
873
874 /**
875  * RX offload capabilities of a device.
876  */
877 #define DEV_RX_OFFLOAD_VLAN_STRIP  0x00000001
878 #define DEV_RX_OFFLOAD_IPV4_CKSUM  0x00000002
879 #define DEV_RX_OFFLOAD_UDP_CKSUM   0x00000004
880 #define DEV_RX_OFFLOAD_TCP_CKSUM   0x00000008
881 #define DEV_RX_OFFLOAD_TCP_LRO     0x00000010
882 #define DEV_RX_OFFLOAD_QINQ_STRIP  0x00000020
883 #define DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM 0x00000040
884
885 /**
886  * TX offload capabilities of a device.
887  */
888 #define DEV_TX_OFFLOAD_VLAN_INSERT 0x00000001
889 #define DEV_TX_OFFLOAD_IPV4_CKSUM  0x00000002
890 #define DEV_TX_OFFLOAD_UDP_CKSUM   0x00000004
891 #define DEV_TX_OFFLOAD_TCP_CKSUM   0x00000008
892 #define DEV_TX_OFFLOAD_SCTP_CKSUM  0x00000010
893 #define DEV_TX_OFFLOAD_TCP_TSO     0x00000020
894 #define DEV_TX_OFFLOAD_UDP_TSO     0x00000040
895 #define DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM 0x00000080 /**< Used for tunneling packet. */
896 #define DEV_TX_OFFLOAD_QINQ_INSERT 0x00000100
897 #define DEV_TX_OFFLOAD_VXLAN_TNL_TSO    0x00000200    /**< Used for tunneling packet. */
898 #define DEV_TX_OFFLOAD_GRE_TNL_TSO      0x00000400    /**< Used for tunneling packet. */
899 #define DEV_TX_OFFLOAD_IPIP_TNL_TSO     0x00000800    /**< Used for tunneling packet. */
900 #define DEV_TX_OFFLOAD_GENEVE_TNL_TSO   0x00001000    /**< Used for tunneling packet. */
901
902 /**
903  * Ethernet device information
904  */
905 struct rte_eth_dev_info {
906         struct rte_pci_device *pci_dev; /**< Device PCI information. */
907         const char *driver_name; /**< Device Driver name. */
908         unsigned int if_index; /**< Index to bound host interface, or 0 if none.
909                 Use if_indextoname() to translate into an interface name. */
910         uint32_t min_rx_bufsize; /**< Minimum size of RX buffer. */
911         uint32_t max_rx_pktlen; /**< Maximum configurable length of RX pkt. */
912         uint16_t max_rx_queues; /**< Maximum number of RX queues. */
913         uint16_t max_tx_queues; /**< Maximum number of TX queues. */
914         uint32_t max_mac_addrs; /**< Maximum number of MAC addresses. */
915         uint32_t max_hash_mac_addrs;
916         /** Maximum number of hash MAC addresses for MTA and UTA. */
917         uint16_t max_vfs; /**< Maximum number of VFs. */
918         uint16_t max_vmdq_pools; /**< Maximum number of VMDq pools. */
919         uint32_t rx_offload_capa; /**< Device RX offload capabilities. */
920         uint32_t tx_offload_capa; /**< Device TX offload capabilities. */
921         uint16_t reta_size;
922         /**< Device redirection table size, the total number of entries. */
923         uint8_t hash_key_size; /**< Hash key size in bytes */
924         /** Bit mask of RSS offloads, the bit offset also means flow type */
925         uint64_t flow_type_rss_offloads;
926         struct rte_eth_rxconf default_rxconf; /**< Default RX configuration */
927         struct rte_eth_txconf default_txconf; /**< Default TX configuration */
928         uint16_t vmdq_queue_base; /**< First queue ID for VMDQ pools. */
929         uint16_t vmdq_queue_num;  /**< Queue number for VMDQ pools. */
930         uint16_t vmdq_pool_base;  /**< First ID of VMDQ pools. */
931         struct rte_eth_desc_lim rx_desc_lim;  /**< RX descriptors limits */
932         struct rte_eth_desc_lim tx_desc_lim;  /**< TX descriptors limits */
933         uint32_t speed_capa;  /**< Supported speeds bitmap (ETH_LINK_SPEED_). */
934         /** Configured number of rx/tx queues */
935         uint16_t nb_rx_queues; /**< Number of RX queues. */
936         uint16_t nb_tx_queues; /**< Number of TX queues. */
937 };
938
939 /**
940  * Ethernet device RX queue information structure.
941  * Used to retieve information about configured queue.
942  */
943 struct rte_eth_rxq_info {
944         struct rte_mempool *mp;     /**< mempool used by that queue. */
945         struct rte_eth_rxconf conf; /**< queue config parameters. */
946         uint8_t scattered_rx;       /**< scattered packets RX supported. */
947         uint16_t nb_desc;           /**< configured number of RXDs. */
948 } __rte_cache_min_aligned;
949
950 /**
951  * Ethernet device TX queue information structure.
952  * Used to retieve information about configured queue.
953  */
954 struct rte_eth_txq_info {
955         struct rte_eth_txconf conf; /**< queue config parameters. */
956         uint16_t nb_desc;           /**< configured number of TXDs. */
957 } __rte_cache_min_aligned;
958
959 /** Maximum name length for extended statistics counters */
960 #define RTE_ETH_XSTATS_NAME_SIZE 64
961
962 /**
963  * An Ethernet device extended statistic structure
964  *
965  * This structure is used by rte_eth_xstats_get() to provide
966  * statistics that are not provided in the generic *rte_eth_stats*
967  * structure.
968  * It maps a name id, corresponding to an index in the array returned
969  * by rte_eth_xstats_get_names(), to a statistic value.
970  */
971 struct rte_eth_xstat {
972         uint64_t id;        /**< The index in xstats name array. */
973         uint64_t value;     /**< The statistic counter value. */
974 };
975
976 /**
977  * A name element for extended statistics.
978  *
979  * An array of this structure is returned by rte_eth_xstats_get_names().
980  * It lists the names of extended statistics for a PMD. The *rte_eth_xstat*
981  * structure references these names by their array index.
982  */
983 struct rte_eth_xstat_name {
984         char name[RTE_ETH_XSTATS_NAME_SIZE]; /**< The statistic name. */
985 };
986
987 #define ETH_DCB_NUM_TCS    8
988 #define ETH_MAX_VMDQ_POOL  64
989
990 /**
991  * A structure used to get the information of queue and
992  * TC mapping on both TX and RX paths.
993  */
994 struct rte_eth_dcb_tc_queue_mapping {
995         /** rx queues assigned to tc per Pool */
996         struct {
997                 uint8_t base;
998                 uint8_t nb_queue;
999         } tc_rxq[ETH_MAX_VMDQ_POOL][ETH_DCB_NUM_TCS];
1000         /** rx queues assigned to tc per Pool */
1001         struct {
1002                 uint8_t base;
1003                 uint8_t nb_queue;
1004         } tc_txq[ETH_MAX_VMDQ_POOL][ETH_DCB_NUM_TCS];
1005 };
1006
1007 /**
1008  * A structure used to get the information of DCB.
1009  * It includes TC UP mapping and queue TC mapping.
1010  */
1011 struct rte_eth_dcb_info {
1012         uint8_t nb_tcs;        /**< number of TCs */
1013         uint8_t prio_tc[ETH_DCB_NUM_USER_PRIORITIES]; /**< Priority to tc */
1014         uint8_t tc_bws[ETH_DCB_NUM_TCS]; /**< TX BW percentage for each TC */
1015         /** rx queues assigned to tc */
1016         struct rte_eth_dcb_tc_queue_mapping tc_queue;
1017 };
1018
1019 /**
1020  * RX/TX queue states
1021  */
1022 #define RTE_ETH_QUEUE_STATE_STOPPED 0
1023 #define RTE_ETH_QUEUE_STATE_STARTED 1
1024
1025 struct rte_eth_dev;
1026
1027 struct rte_eth_dev_callback;
1028 /** @internal Structure to keep track of registered callbacks */
1029 TAILQ_HEAD(rte_eth_dev_cb_list, rte_eth_dev_callback);
1030
1031
1032 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
1033 #define RTE_PMD_DEBUG_TRACE(...) \
1034         rte_pmd_debug_trace(__func__, __VA_ARGS__)
1035 #else
1036 #define RTE_PMD_DEBUG_TRACE(...)
1037 #endif
1038
1039
1040 /* Macros to check for valid port */
1041 #define RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, retval) do { \
1042         if (!rte_eth_dev_is_valid_port(port_id)) { \
1043                 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); \
1044                 return retval; \
1045         } \
1046 } while (0)
1047
1048 #define RTE_ETH_VALID_PORTID_OR_RET(port_id) do { \
1049         if (!rte_eth_dev_is_valid_port(port_id)) { \
1050                 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); \
1051                 return; \
1052         } \
1053 } while (0)
1054
1055 /**
1056  * l2 tunnel configuration.
1057  */
1058
1059 /**< l2 tunnel enable mask */
1060 #define ETH_L2_TUNNEL_ENABLE_MASK       0x00000001
1061 /**< l2 tunnel insertion mask */
1062 #define ETH_L2_TUNNEL_INSERTION_MASK    0x00000002
1063 /**< l2 tunnel stripping mask */
1064 #define ETH_L2_TUNNEL_STRIPPING_MASK    0x00000004
1065 /**< l2 tunnel forwarding mask */
1066 #define ETH_L2_TUNNEL_FORWARDING_MASK   0x00000008
1067
1068 /*
1069  * Definitions of all functions exported by an Ethernet driver through the
1070  * the generic structure of type *eth_dev_ops* supplied in the *rte_eth_dev*
1071  * structure associated with an Ethernet device.
1072  */
1073
1074 typedef int  (*eth_dev_configure_t)(struct rte_eth_dev *dev);
1075 /**< @internal Ethernet device configuration. */
1076
1077 typedef int  (*eth_dev_start_t)(struct rte_eth_dev *dev);
1078 /**< @internal Function used to start a configured Ethernet device. */
1079
1080 typedef void (*eth_dev_stop_t)(struct rte_eth_dev *dev);
1081 /**< @internal Function used to stop a configured Ethernet device. */
1082
1083 typedef int  (*eth_dev_set_link_up_t)(struct rte_eth_dev *dev);
1084 /**< @internal Function used to link up a configured Ethernet device. */
1085
1086 typedef int  (*eth_dev_set_link_down_t)(struct rte_eth_dev *dev);
1087 /**< @internal Function used to link down a configured Ethernet device. */
1088
1089 typedef void (*eth_dev_close_t)(struct rte_eth_dev *dev);
1090 /**< @internal Function used to close a configured Ethernet device. */
1091
1092 typedef void (*eth_promiscuous_enable_t)(struct rte_eth_dev *dev);
1093 /**< @internal Function used to enable the RX promiscuous mode of an Ethernet device. */
1094
1095 typedef void (*eth_promiscuous_disable_t)(struct rte_eth_dev *dev);
1096 /**< @internal Function used to disable the RX promiscuous mode of an Ethernet device. */
1097
1098 typedef void (*eth_allmulticast_enable_t)(struct rte_eth_dev *dev);
1099 /**< @internal Enable the receipt of all multicast packets by an Ethernet device. */
1100
1101 typedef void (*eth_allmulticast_disable_t)(struct rte_eth_dev *dev);
1102 /**< @internal Disable the receipt of all multicast packets by an Ethernet device. */
1103
1104 typedef int (*eth_link_update_t)(struct rte_eth_dev *dev,
1105                                 int wait_to_complete);
1106 /**< @internal Get link speed, duplex mode and state (up/down) of an Ethernet device. */
1107
1108 typedef void (*eth_stats_get_t)(struct rte_eth_dev *dev,
1109                                 struct rte_eth_stats *igb_stats);
1110 /**< @internal Get global I/O statistics of an Ethernet device. */
1111
1112 typedef void (*eth_stats_reset_t)(struct rte_eth_dev *dev);
1113 /**< @internal Reset global I/O statistics of an Ethernet device to 0. */
1114
1115 typedef int (*eth_xstats_get_t)(struct rte_eth_dev *dev,
1116         struct rte_eth_xstat *stats, unsigned n);
1117 /**< @internal Get extended stats of an Ethernet device. */
1118
1119 typedef void (*eth_xstats_reset_t)(struct rte_eth_dev *dev);
1120 /**< @internal Reset extended stats of an Ethernet device. */
1121
1122 typedef int (*eth_xstats_get_names_t)(struct rte_eth_dev *dev,
1123         struct rte_eth_xstat_name *xstats_names, unsigned size);
1124 /**< @internal Get names of extended stats of an Ethernet device. */
1125
1126 typedef int (*eth_queue_stats_mapping_set_t)(struct rte_eth_dev *dev,
1127                                              uint16_t queue_id,
1128                                              uint8_t stat_idx,
1129                                              uint8_t is_rx);
1130 /**< @internal Set a queue statistics mapping for a tx/rx queue of an Ethernet device. */
1131
1132 typedef void (*eth_dev_infos_get_t)(struct rte_eth_dev *dev,
1133                                     struct rte_eth_dev_info *dev_info);
1134 /**< @internal Get specific informations of an Ethernet device. */
1135
1136 typedef const uint32_t *(*eth_dev_supported_ptypes_get_t)(struct rte_eth_dev *dev);
1137 /**< @internal Get supported ptypes of an Ethernet device. */
1138
1139 typedef int (*eth_queue_start_t)(struct rte_eth_dev *dev,
1140                                     uint16_t queue_id);
1141 /**< @internal Start rx and tx of a queue of an Ethernet device. */
1142
1143 typedef int (*eth_queue_stop_t)(struct rte_eth_dev *dev,
1144                                     uint16_t queue_id);
1145 /**< @internal Stop rx and tx of a queue of an Ethernet device. */
1146
1147 typedef int (*eth_rx_queue_setup_t)(struct rte_eth_dev *dev,
1148                                     uint16_t rx_queue_id,
1149                                     uint16_t nb_rx_desc,
1150                                     unsigned int socket_id,
1151                                     const struct rte_eth_rxconf *rx_conf,
1152                                     struct rte_mempool *mb_pool);
1153 /**< @internal Set up a receive queue of an Ethernet device. */
1154
1155 typedef int (*eth_tx_queue_setup_t)(struct rte_eth_dev *dev,
1156                                     uint16_t tx_queue_id,
1157                                     uint16_t nb_tx_desc,
1158                                     unsigned int socket_id,
1159                                     const struct rte_eth_txconf *tx_conf);
1160 /**< @internal Setup a transmit queue of an Ethernet device. */
1161
1162 typedef int (*eth_rx_enable_intr_t)(struct rte_eth_dev *dev,
1163                                     uint16_t rx_queue_id);
1164 /**< @internal Enable interrupt of a receive queue of an Ethernet device. */
1165
1166 typedef int (*eth_rx_disable_intr_t)(struct rte_eth_dev *dev,
1167                                     uint16_t rx_queue_id);
1168 /**< @internal Disable interrupt of a receive queue of an Ethernet device. */
1169
1170 typedef void (*eth_queue_release_t)(void *queue);
1171 /**< @internal Release memory resources allocated by given RX/TX queue. */
1172
1173 typedef uint32_t (*eth_rx_queue_count_t)(struct rte_eth_dev *dev,
1174                                          uint16_t rx_queue_id);
1175 /**< @internal Get number of available descriptors on a receive queue of an Ethernet device. */
1176
1177 typedef int (*eth_rx_descriptor_done_t)(void *rxq, uint16_t offset);
1178 /**< @internal Check DD bit of specific RX descriptor */
1179
1180 typedef void (*eth_rxq_info_get_t)(struct rte_eth_dev *dev,
1181         uint16_t rx_queue_id, struct rte_eth_rxq_info *qinfo);
1182
1183 typedef void (*eth_txq_info_get_t)(struct rte_eth_dev *dev,
1184         uint16_t tx_queue_id, struct rte_eth_txq_info *qinfo);
1185
1186 typedef int (*mtu_set_t)(struct rte_eth_dev *dev, uint16_t mtu);
1187 /**< @internal Set MTU. */
1188
1189 typedef int (*vlan_filter_set_t)(struct rte_eth_dev *dev,
1190                                   uint16_t vlan_id,
1191                                   int on);
1192 /**< @internal filtering of a VLAN Tag Identifier by an Ethernet device. */
1193
1194 typedef int (*vlan_tpid_set_t)(struct rte_eth_dev *dev,
1195                                enum rte_vlan_type type, uint16_t tpid);
1196 /**< @internal set the outer/inner VLAN-TPID by an Ethernet device. */
1197
1198 typedef void (*vlan_offload_set_t)(struct rte_eth_dev *dev, int mask);
1199 /**< @internal set VLAN offload function by an Ethernet device. */
1200
1201 typedef int (*vlan_pvid_set_t)(struct rte_eth_dev *dev,
1202                                uint16_t vlan_id,
1203                                int on);
1204 /**< @internal set port based TX VLAN insertion by an Ethernet device. */
1205
1206 typedef void (*vlan_strip_queue_set_t)(struct rte_eth_dev *dev,
1207                                   uint16_t rx_queue_id,
1208                                   int on);
1209 /**< @internal VLAN stripping enable/disable by an queue of Ethernet device. */
1210
1211 typedef uint16_t (*eth_rx_burst_t)(void *rxq,
1212                                    struct rte_mbuf **rx_pkts,
1213                                    uint16_t nb_pkts);
1214 /**< @internal Retrieve input packets from a receive queue of an Ethernet device. */
1215
1216 typedef uint16_t (*eth_tx_burst_t)(void *txq,
1217                                    struct rte_mbuf **tx_pkts,
1218                                    uint16_t nb_pkts);
1219 /**< @internal Send output packets on a transmit queue of an Ethernet device. */
1220
1221 typedef uint16_t (*eth_tx_prep_t)(void *txq,
1222                                    struct rte_mbuf **tx_pkts,
1223                                    uint16_t nb_pkts);
1224 /**< @internal Prepare output packets on a transmit queue of an Ethernet device. */
1225
1226 typedef int (*flow_ctrl_get_t)(struct rte_eth_dev *dev,
1227                                struct rte_eth_fc_conf *fc_conf);
1228 /**< @internal Get current flow control parameter on an Ethernet device */
1229
1230 typedef int (*flow_ctrl_set_t)(struct rte_eth_dev *dev,
1231                                struct rte_eth_fc_conf *fc_conf);
1232 /**< @internal Setup flow control parameter on an Ethernet device */
1233
1234 typedef int (*priority_flow_ctrl_set_t)(struct rte_eth_dev *dev,
1235                                 struct rte_eth_pfc_conf *pfc_conf);
1236 /**< @internal Setup priority flow control parameter on an Ethernet device */
1237
1238 typedef int (*reta_update_t)(struct rte_eth_dev *dev,
1239                              struct rte_eth_rss_reta_entry64 *reta_conf,
1240                              uint16_t reta_size);
1241 /**< @internal Update RSS redirection table on an Ethernet device */
1242
1243 typedef int (*reta_query_t)(struct rte_eth_dev *dev,
1244                             struct rte_eth_rss_reta_entry64 *reta_conf,
1245                             uint16_t reta_size);
1246 /**< @internal Query RSS redirection table on an Ethernet device */
1247
1248 typedef int (*rss_hash_update_t)(struct rte_eth_dev *dev,
1249                                  struct rte_eth_rss_conf *rss_conf);
1250 /**< @internal Update RSS hash configuration of an Ethernet device */
1251
1252 typedef int (*rss_hash_conf_get_t)(struct rte_eth_dev *dev,
1253                                    struct rte_eth_rss_conf *rss_conf);
1254 /**< @internal Get current RSS hash configuration of an Ethernet device */
1255
1256 typedef int (*eth_dev_led_on_t)(struct rte_eth_dev *dev);
1257 /**< @internal Turn on SW controllable LED on an Ethernet device */
1258
1259 typedef int (*eth_dev_led_off_t)(struct rte_eth_dev *dev);
1260 /**< @internal Turn off SW controllable LED on an Ethernet device */
1261
1262 typedef void (*eth_mac_addr_remove_t)(struct rte_eth_dev *dev, uint32_t index);
1263 /**< @internal Remove MAC address from receive address register */
1264
1265 typedef void (*eth_mac_addr_add_t)(struct rte_eth_dev *dev,
1266                                   struct ether_addr *mac_addr,
1267                                   uint32_t index,
1268                                   uint32_t vmdq);
1269 /**< @internal Set a MAC address into Receive Address Address Register */
1270
1271 typedef void (*eth_mac_addr_set_t)(struct rte_eth_dev *dev,
1272                                   struct ether_addr *mac_addr);
1273 /**< @internal Set a MAC address into Receive Address Address Register */
1274
1275 typedef int (*eth_uc_hash_table_set_t)(struct rte_eth_dev *dev,
1276                                   struct ether_addr *mac_addr,
1277                                   uint8_t on);
1278 /**< @internal Set a Unicast Hash bitmap */
1279
1280 typedef int (*eth_uc_all_hash_table_set_t)(struct rte_eth_dev *dev,
1281                                   uint8_t on);
1282 /**< @internal Set all Unicast Hash bitmap */
1283
1284 typedef int (*eth_set_vf_rx_mode_t)(struct rte_eth_dev *dev,
1285                                   uint16_t vf,
1286                                   uint16_t rx_mode,
1287                                   uint8_t on);
1288 /**< @internal Set a VF receive mode */
1289
1290 typedef int (*eth_set_vf_rx_t)(struct rte_eth_dev *dev,
1291                                 uint16_t vf,
1292                                 uint8_t on);
1293 /**< @internal Set a VF receive  mode */
1294
1295 typedef int (*eth_set_vf_tx_t)(struct rte_eth_dev *dev,
1296                                 uint16_t vf,
1297                                 uint8_t on);
1298 /**< @internal Enable or disable a VF transmit   */
1299
1300 typedef int (*eth_set_vf_vlan_filter_t)(struct rte_eth_dev *dev,
1301                                   uint16_t vlan,
1302                                   uint64_t vf_mask,
1303                                   uint8_t vlan_on);
1304 /**< @internal Set VF VLAN pool filter */
1305
1306 typedef int (*eth_set_queue_rate_limit_t)(struct rte_eth_dev *dev,
1307                                 uint16_t queue_idx,
1308                                 uint16_t tx_rate);
1309 /**< @internal Set queue TX rate */
1310
1311 typedef int (*eth_set_vf_rate_limit_t)(struct rte_eth_dev *dev,
1312                                 uint16_t vf,
1313                                 uint16_t tx_rate,
1314                                 uint64_t q_msk);
1315 /**< @internal Set VF TX rate */
1316
1317 typedef int (*eth_mirror_rule_set_t)(struct rte_eth_dev *dev,
1318                                   struct rte_eth_mirror_conf *mirror_conf,
1319                                   uint8_t rule_id,
1320                                   uint8_t on);
1321 /**< @internal Add a traffic mirroring rule on an Ethernet device */
1322
1323 typedef int (*eth_mirror_rule_reset_t)(struct rte_eth_dev *dev,
1324                                   uint8_t rule_id);
1325 /**< @internal Remove a traffic mirroring rule on an Ethernet device */
1326
1327 typedef int (*eth_udp_tunnel_port_add_t)(struct rte_eth_dev *dev,
1328                                          struct rte_eth_udp_tunnel *tunnel_udp);
1329 /**< @internal Add tunneling UDP port */
1330
1331 typedef int (*eth_udp_tunnel_port_del_t)(struct rte_eth_dev *dev,
1332                                          struct rte_eth_udp_tunnel *tunnel_udp);
1333 /**< @internal Delete tunneling UDP port */
1334
1335 typedef int (*eth_set_mc_addr_list_t)(struct rte_eth_dev *dev,
1336                                       struct ether_addr *mc_addr_set,
1337                                       uint32_t nb_mc_addr);
1338 /**< @internal set the list of multicast addresses on an Ethernet device */
1339
1340 typedef int (*eth_timesync_enable_t)(struct rte_eth_dev *dev);
1341 /**< @internal Function used to enable IEEE1588/802.1AS timestamping. */
1342
1343 typedef int (*eth_timesync_disable_t)(struct rte_eth_dev *dev);
1344 /**< @internal Function used to disable IEEE1588/802.1AS timestamping. */
1345
1346 typedef int (*eth_timesync_read_rx_timestamp_t)(struct rte_eth_dev *dev,
1347                                                 struct timespec *timestamp,
1348                                                 uint32_t flags);
1349 /**< @internal Function used to read an RX IEEE1588/802.1AS timestamp. */
1350
1351 typedef int (*eth_timesync_read_tx_timestamp_t)(struct rte_eth_dev *dev,
1352                                                 struct timespec *timestamp);
1353 /**< @internal Function used to read a TX IEEE1588/802.1AS timestamp. */
1354
1355 typedef int (*eth_timesync_adjust_time)(struct rte_eth_dev *dev, int64_t);
1356 /**< @internal Function used to adjust the device clock */
1357
1358 typedef int (*eth_timesync_read_time)(struct rte_eth_dev *dev,
1359                                       struct timespec *timestamp);
1360 /**< @internal Function used to get time from the device clock. */
1361
1362 typedef int (*eth_timesync_write_time)(struct rte_eth_dev *dev,
1363                                        const struct timespec *timestamp);
1364 /**< @internal Function used to get time from the device clock */
1365
1366 typedef int (*eth_get_reg_t)(struct rte_eth_dev *dev,
1367                                 struct rte_dev_reg_info *info);
1368 /**< @internal Retrieve registers  */
1369
1370 typedef int (*eth_get_eeprom_length_t)(struct rte_eth_dev *dev);
1371 /**< @internal Retrieve eeprom size  */
1372
1373 typedef int (*eth_get_eeprom_t)(struct rte_eth_dev *dev,
1374                                 struct rte_dev_eeprom_info *info);
1375 /**< @internal Retrieve eeprom data  */
1376
1377 typedef int (*eth_set_eeprom_t)(struct rte_eth_dev *dev,
1378                                 struct rte_dev_eeprom_info *info);
1379 /**< @internal Program eeprom data  */
1380
1381 typedef int (*eth_l2_tunnel_eth_type_conf_t)
1382         (struct rte_eth_dev *dev, struct rte_eth_l2_tunnel_conf *l2_tunnel);
1383 /**< @internal config l2 tunnel ether type */
1384
1385 typedef int (*eth_l2_tunnel_offload_set_t)
1386         (struct rte_eth_dev *dev,
1387          struct rte_eth_l2_tunnel_conf *l2_tunnel,
1388          uint32_t mask,
1389          uint8_t en);
1390 /**< @internal enable/disable the l2 tunnel offload functions */
1391
1392 #ifdef RTE_NIC_BYPASS
1393
1394 enum {
1395         RTE_BYPASS_MODE_NONE,
1396         RTE_BYPASS_MODE_NORMAL,
1397         RTE_BYPASS_MODE_BYPASS,
1398         RTE_BYPASS_MODE_ISOLATE,
1399         RTE_BYPASS_MODE_NUM,
1400 };
1401
1402 #define RTE_BYPASS_MODE_VALID(x)        \
1403         ((x) > RTE_BYPASS_MODE_NONE && (x) < RTE_BYPASS_MODE_NUM)
1404
1405 enum {
1406         RTE_BYPASS_EVENT_NONE,
1407         RTE_BYPASS_EVENT_START,
1408         RTE_BYPASS_EVENT_OS_ON = RTE_BYPASS_EVENT_START,
1409         RTE_BYPASS_EVENT_POWER_ON,
1410         RTE_BYPASS_EVENT_OS_OFF,
1411         RTE_BYPASS_EVENT_POWER_OFF,
1412         RTE_BYPASS_EVENT_TIMEOUT,
1413         RTE_BYPASS_EVENT_NUM
1414 };
1415
1416 #define RTE_BYPASS_EVENT_VALID(x)       \
1417         ((x) > RTE_BYPASS_EVENT_NONE && (x) < RTE_BYPASS_MODE_NUM)
1418
1419 enum {
1420         RTE_BYPASS_TMT_OFF,     /* timeout disabled. */
1421         RTE_BYPASS_TMT_1_5_SEC, /* timeout for 1.5 seconds */
1422         RTE_BYPASS_TMT_2_SEC,   /* timeout for 2 seconds */
1423         RTE_BYPASS_TMT_3_SEC,   /* timeout for 3 seconds */
1424         RTE_BYPASS_TMT_4_SEC,   /* timeout for 4 seconds */
1425         RTE_BYPASS_TMT_8_SEC,   /* timeout for 8 seconds */
1426         RTE_BYPASS_TMT_16_SEC,  /* timeout for 16 seconds */
1427         RTE_BYPASS_TMT_32_SEC,  /* timeout for 32 seconds */
1428         RTE_BYPASS_TMT_NUM
1429 };
1430
1431 #define RTE_BYPASS_TMT_VALID(x) \
1432         ((x) == RTE_BYPASS_TMT_OFF || \
1433         ((x) > RTE_BYPASS_TMT_OFF && (x) < RTE_BYPASS_TMT_NUM))
1434
1435 typedef void (*bypass_init_t)(struct rte_eth_dev *dev);
1436 typedef int32_t (*bypass_state_set_t)(struct rte_eth_dev *dev, uint32_t *new_state);
1437 typedef int32_t (*bypass_state_show_t)(struct rte_eth_dev *dev, uint32_t *state);
1438 typedef int32_t (*bypass_event_set_t)(struct rte_eth_dev *dev, uint32_t state, uint32_t event);
1439 typedef int32_t (*bypass_event_show_t)(struct rte_eth_dev *dev, uint32_t event_shift, uint32_t *event);
1440 typedef int32_t (*bypass_wd_timeout_set_t)(struct rte_eth_dev *dev, uint32_t timeout);
1441 typedef int32_t (*bypass_wd_timeout_show_t)(struct rte_eth_dev *dev, uint32_t *wd_timeout);
1442 typedef int32_t (*bypass_ver_show_t)(struct rte_eth_dev *dev, uint32_t *ver);
1443 typedef int32_t (*bypass_wd_reset_t)(struct rte_eth_dev *dev);
1444 #endif
1445
1446 typedef int (*eth_filter_ctrl_t)(struct rte_eth_dev *dev,
1447                                  enum rte_filter_type filter_type,
1448                                  enum rte_filter_op filter_op,
1449                                  void *arg);
1450 /**< @internal Take operations to assigned filter type on an Ethernet device */
1451
1452 typedef int (*eth_get_dcb_info)(struct rte_eth_dev *dev,
1453                                  struct rte_eth_dcb_info *dcb_info);
1454 /**< @internal Get dcb information on an Ethernet device */
1455
1456 /**
1457  * @internal A structure containing the functions exported by an Ethernet driver.
1458  */
1459 struct eth_dev_ops {
1460         eth_dev_configure_t        dev_configure; /**< Configure device. */
1461         eth_dev_start_t            dev_start;     /**< Start device. */
1462         eth_dev_stop_t             dev_stop;      /**< Stop device. */
1463         eth_dev_set_link_up_t      dev_set_link_up;   /**< Device link up. */
1464         eth_dev_set_link_down_t    dev_set_link_down; /**< Device link down. */
1465         eth_dev_close_t            dev_close;     /**< Close device. */
1466         eth_link_update_t          link_update;   /**< Get device link state. */
1467
1468         eth_promiscuous_enable_t   promiscuous_enable; /**< Promiscuous ON. */
1469         eth_promiscuous_disable_t  promiscuous_disable;/**< Promiscuous OFF. */
1470         eth_allmulticast_enable_t  allmulticast_enable;/**< RX multicast ON. */
1471         eth_allmulticast_disable_t allmulticast_disable;/**< RX multicast OF. */
1472         eth_mac_addr_remove_t      mac_addr_remove; /**< Remove MAC address. */
1473         eth_mac_addr_add_t         mac_addr_add;  /**< Add a MAC address. */
1474         eth_mac_addr_set_t         mac_addr_set;  /**< Set a MAC address. */
1475         eth_set_mc_addr_list_t     set_mc_addr_list; /**< set list of mcast addrs. */
1476         mtu_set_t                  mtu_set;       /**< Set MTU. */
1477
1478         eth_stats_get_t            stats_get;     /**< Get generic device statistics. */
1479         eth_stats_reset_t          stats_reset;   /**< Reset generic device statistics. */
1480         eth_xstats_get_t           xstats_get;    /**< Get extended device statistics. */
1481         eth_xstats_reset_t         xstats_reset;  /**< Reset extended device statistics. */
1482         eth_xstats_get_names_t     xstats_get_names;
1483         /**< Get names of extended statistics. */
1484         eth_queue_stats_mapping_set_t queue_stats_mapping_set;
1485         /**< Configure per queue stat counter mapping. */
1486
1487         eth_dev_infos_get_t        dev_infos_get; /**< Get device info. */
1488         eth_rxq_info_get_t         rxq_info_get; /**< retrieve RX queue information. */
1489         eth_txq_info_get_t         txq_info_get; /**< retrieve TX queue information. */
1490         eth_dev_supported_ptypes_get_t dev_supported_ptypes_get;
1491         /**< Get packet types supported and identified by device. */
1492
1493         vlan_filter_set_t          vlan_filter_set; /**< Filter VLAN Setup. */
1494         vlan_tpid_set_t            vlan_tpid_set; /**< Outer/Inner VLAN TPID Setup. */
1495         vlan_strip_queue_set_t     vlan_strip_queue_set; /**< VLAN Stripping on queue. */
1496         vlan_offload_set_t         vlan_offload_set; /**< Set VLAN Offload. */
1497         vlan_pvid_set_t            vlan_pvid_set; /**< Set port based TX VLAN insertion. */
1498
1499         eth_queue_start_t          rx_queue_start;/**< Start RX for a queue. */
1500         eth_queue_stop_t           rx_queue_stop; /**< Stop RX for a queue. */
1501         eth_queue_start_t          tx_queue_start;/**< Start TX for a queue. */
1502         eth_queue_stop_t           tx_queue_stop; /**< Stop TX for a queue. */
1503         eth_rx_queue_setup_t       rx_queue_setup;/**< Set up device RX queue. */
1504         eth_queue_release_t        rx_queue_release; /**< Release RX queue. */
1505         eth_rx_queue_count_t       rx_queue_count;/**< Get Rx queue count. */
1506         eth_rx_descriptor_done_t   rx_descriptor_done; /**< Check rxd DD bit. */
1507         eth_rx_enable_intr_t       rx_queue_intr_enable;  /**< Enable Rx queue interrupt. */
1508         eth_rx_disable_intr_t      rx_queue_intr_disable; /**< Disable Rx queue interrupt. */
1509         eth_tx_queue_setup_t       tx_queue_setup;/**< Set up device TX queue. */
1510         eth_queue_release_t        tx_queue_release; /**< Release TX queue. */
1511
1512         eth_dev_led_on_t           dev_led_on;    /**< Turn on LED. */
1513         eth_dev_led_off_t          dev_led_off;   /**< Turn off LED. */
1514
1515         flow_ctrl_get_t            flow_ctrl_get; /**< Get flow control. */
1516         flow_ctrl_set_t            flow_ctrl_set; /**< Setup flow control. */
1517         priority_flow_ctrl_set_t   priority_flow_ctrl_set; /**< Setup priority flow control. */
1518
1519         eth_uc_hash_table_set_t    uc_hash_table_set; /**< Set Unicast Table Array. */
1520         eth_uc_all_hash_table_set_t uc_all_hash_table_set; /**< Set Unicast hash bitmap. */
1521
1522         eth_mirror_rule_set_t      mirror_rule_set; /**< Add a traffic mirror rule. */
1523         eth_mirror_rule_reset_t    mirror_rule_reset; /**< reset a traffic mirror rule. */
1524
1525         eth_set_vf_rx_mode_t       set_vf_rx_mode;/**< Set VF RX mode. */
1526         eth_set_vf_rx_t            set_vf_rx;     /**< enable/disable a VF receive. */
1527         eth_set_vf_tx_t            set_vf_tx;     /**< enable/disable a VF transmit. */
1528         eth_set_vf_vlan_filter_t   set_vf_vlan_filter; /**< Set VF VLAN filter. */
1529         eth_set_vf_rate_limit_t    set_vf_rate_limit; /**< Set VF rate limit. */
1530
1531         eth_udp_tunnel_port_add_t  udp_tunnel_port_add; /** Add UDP tunnel port. */
1532         eth_udp_tunnel_port_del_t  udp_tunnel_port_del; /** Del UDP tunnel port. */
1533         eth_l2_tunnel_eth_type_conf_t l2_tunnel_eth_type_conf;
1534         /** Config ether type of l2 tunnel. */
1535         eth_l2_tunnel_offload_set_t   l2_tunnel_offload_set;
1536         /** Enable/disable l2 tunnel offload functions. */
1537
1538         eth_set_queue_rate_limit_t set_queue_rate_limit; /**< Set queue rate limit. */
1539
1540         rss_hash_update_t          rss_hash_update; /** Configure RSS hash protocols. */
1541         rss_hash_conf_get_t        rss_hash_conf_get; /** Get current RSS hash configuration. */
1542         reta_update_t              reta_update;   /** Update redirection table. */
1543         reta_query_t               reta_query;    /** Query redirection table. */
1544
1545         eth_get_reg_t              get_reg;           /**< Get registers. */
1546         eth_get_eeprom_length_t    get_eeprom_length; /**< Get eeprom length. */
1547         eth_get_eeprom_t           get_eeprom;        /**< Get eeprom data. */
1548         eth_set_eeprom_t           set_eeprom;        /**< Set eeprom. */
1549
1550         /* bypass control */
1551 #ifdef RTE_NIC_BYPASS
1552         bypass_init_t              bypass_init;
1553         bypass_state_set_t         bypass_state_set;
1554         bypass_state_show_t        bypass_state_show;
1555         bypass_event_set_t         bypass_event_set;
1556         bypass_event_show_t        bypass_event_show;
1557         bypass_wd_timeout_set_t    bypass_wd_timeout_set;
1558         bypass_wd_timeout_show_t   bypass_wd_timeout_show;
1559         bypass_ver_show_t          bypass_ver_show;
1560         bypass_wd_reset_t          bypass_wd_reset;
1561 #endif
1562
1563         eth_filter_ctrl_t          filter_ctrl; /**< common filter control. */
1564
1565         eth_get_dcb_info           get_dcb_info; /** Get DCB information. */
1566
1567         eth_timesync_enable_t      timesync_enable;
1568         /** Turn IEEE1588/802.1AS timestamping on. */
1569         eth_timesync_disable_t     timesync_disable;
1570         /** Turn IEEE1588/802.1AS timestamping off. */
1571         eth_timesync_read_rx_timestamp_t timesync_read_rx_timestamp;
1572         /** Read the IEEE1588/802.1AS RX timestamp. */
1573         eth_timesync_read_tx_timestamp_t timesync_read_tx_timestamp;
1574         /** Read the IEEE1588/802.1AS TX timestamp. */
1575         eth_timesync_adjust_time   timesync_adjust_time; /** Adjust the device clock. */
1576         eth_timesync_read_time     timesync_read_time; /** Get the device clock time. */
1577         eth_timesync_write_time    timesync_write_time; /** Set the device clock time. */
1578 };
1579
1580 /**
1581  * Function type used for RX packet processing packet callbacks.
1582  *
1583  * The callback function is called on RX with a burst of packets that have
1584  * been received on the given port and queue.
1585  *
1586  * @param port
1587  *   The Ethernet port on which RX is being performed.
1588  * @param queue
1589  *   The queue on the Ethernet port which is being used to receive the packets.
1590  * @param pkts
1591  *   The burst of packets that have just been received.
1592  * @param nb_pkts
1593  *   The number of packets in the burst pointed to by "pkts".
1594  * @param max_pkts
1595  *   The max number of packets that can be stored in the "pkts" array.
1596  * @param user_param
1597  *   The arbitrary user parameter passed in by the application when the callback
1598  *   was originally configured.
1599  * @return
1600  *   The number of packets returned to the user.
1601  */
1602 typedef uint16_t (*rte_rx_callback_fn)(uint8_t port, uint16_t queue,
1603         struct rte_mbuf *pkts[], uint16_t nb_pkts, uint16_t max_pkts,
1604         void *user_param);
1605
1606 /**
1607  * Function type used for TX packet processing packet callbacks.
1608  *
1609  * The callback function is called on TX with a burst of packets immediately
1610  * before the packets are put onto the hardware queue for transmission.
1611  *
1612  * @param port
1613  *   The Ethernet port on which TX is being performed.
1614  * @param queue
1615  *   The queue on the Ethernet port which is being used to transmit the packets.
1616  * @param pkts
1617  *   The burst of packets that are about to be transmitted.
1618  * @param nb_pkts
1619  *   The number of packets in the burst pointed to by "pkts".
1620  * @param user_param
1621  *   The arbitrary user parameter passed in by the application when the callback
1622  *   was originally configured.
1623  * @return
1624  *   The number of packets to be written to the NIC.
1625  */
1626 typedef uint16_t (*rte_tx_callback_fn)(uint8_t port, uint16_t queue,
1627         struct rte_mbuf *pkts[], uint16_t nb_pkts, void *user_param);
1628
1629 /**
1630  * @internal
1631  * Structure used to hold information about the callbacks to be called for a
1632  * queue on RX and TX.
1633  */
1634 struct rte_eth_rxtx_callback {
1635         struct rte_eth_rxtx_callback *next;
1636         union{
1637                 rte_rx_callback_fn rx;
1638                 rte_tx_callback_fn tx;
1639         } fn;
1640         void *param;
1641 };
1642
1643 /**
1644  * @internal
1645  * The generic data structure associated with each ethernet device.
1646  *
1647  * Pointers to burst-oriented packet receive and transmit functions are
1648  * located at the beginning of the structure, along with the pointer to
1649  * where all the data elements for the particular device are stored in shared
1650  * memory. This split allows the function pointer and driver data to be per-
1651  * process, while the actual configuration data for the device is shared.
1652  */
1653 struct rte_eth_dev {
1654         eth_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive function. */
1655         eth_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit function. */
1656         eth_tx_prep_t tx_pkt_prepare; /**< Pointer to PMD transmit prepare function. */
1657         struct rte_eth_dev_data *data;  /**< Pointer to device data */
1658         const struct eth_driver *driver;/**< Driver for this device */
1659         const struct eth_dev_ops *dev_ops; /**< Functions exported by PMD */
1660         struct rte_device *device; /**< Backing device */
1661         struct rte_intr_handle *intr_handle; /**< Device interrupt handle */
1662         /** User application callbacks for NIC interrupts */
1663         struct rte_eth_dev_cb_list link_intr_cbs;
1664         /**
1665          * User-supplied functions called from rx_burst to post-process
1666          * received packets before passing them to the user
1667          */
1668         struct rte_eth_rxtx_callback *post_rx_burst_cbs[RTE_MAX_QUEUES_PER_PORT];
1669         /**
1670          * User-supplied functions called from tx_burst to pre-process
1671          * received packets before passing them to the driver for transmission.
1672          */
1673         struct rte_eth_rxtx_callback *pre_tx_burst_cbs[RTE_MAX_QUEUES_PER_PORT];
1674         uint8_t attached; /**< Flag indicating the port is attached */
1675 } __rte_cache_aligned;
1676
1677 struct rte_eth_dev_sriov {
1678         uint8_t active;               /**< SRIOV is active with 16, 32 or 64 pools */
1679         uint8_t nb_q_per_pool;        /**< rx queue number per pool */
1680         uint16_t def_vmdq_idx;        /**< Default pool num used for PF */
1681         uint16_t def_pool_q_idx;      /**< Default pool queue start reg index */
1682 };
1683 #define RTE_ETH_DEV_SRIOV(dev)         ((dev)->data->sriov)
1684
1685 #define RTE_ETH_NAME_MAX_LEN (32)
1686
1687 /**
1688  * @internal
1689  * The data part, with no function pointers, associated with each ethernet device.
1690  *
1691  * This structure is safe to place in shared memory to be common among different
1692  * processes in a multi-process configuration.
1693  */
1694 struct rte_eth_dev_data {
1695         char name[RTE_ETH_NAME_MAX_LEN]; /**< Unique identifier name */
1696
1697         void **rx_queues; /**< Array of pointers to RX queues. */
1698         void **tx_queues; /**< Array of pointers to TX queues. */
1699         uint16_t nb_rx_queues; /**< Number of RX queues. */
1700         uint16_t nb_tx_queues; /**< Number of TX queues. */
1701
1702         struct rte_eth_dev_sriov sriov;    /**< SRIOV data */
1703
1704         void *dev_private;              /**< PMD-specific private data */
1705
1706         struct rte_eth_link dev_link;
1707         /**< Link-level information & status */
1708
1709         struct rte_eth_conf dev_conf;   /**< Configuration applied to device. */
1710         uint16_t mtu;                   /**< Maximum Transmission Unit. */
1711
1712         uint32_t min_rx_buf_size;
1713         /**< Common rx buffer size handled by all queues */
1714
1715         uint64_t rx_mbuf_alloc_failed; /**< RX ring mbuf allocation failures. */
1716         struct ether_addr* mac_addrs;/**< Device Ethernet Link address. */
1717         uint64_t mac_pool_sel[ETH_NUM_RECEIVE_MAC_ADDR];
1718         /** bitmap array of associating Ethernet MAC addresses to pools */
1719         struct ether_addr* hash_mac_addrs;
1720         /** Device Ethernet MAC addresses of hash filtering. */
1721         uint8_t port_id;           /**< Device [external] port identifier. */
1722         __extension__
1723         uint8_t promiscuous   : 1, /**< RX promiscuous mode ON(1) / OFF(0). */
1724                 scattered_rx : 1,  /**< RX of scattered packets is ON(1) / OFF(0) */
1725                 all_multicast : 1, /**< RX all multicast mode ON(1) / OFF(0). */
1726                 dev_started : 1,   /**< Device state: STARTED(1) / STOPPED(0). */
1727                 lro         : 1;   /**< RX LRO is ON(1) / OFF(0) */
1728         uint8_t rx_queue_state[RTE_MAX_QUEUES_PER_PORT];
1729         /** Queues state: STARTED(1) / STOPPED(0) */
1730         uint8_t tx_queue_state[RTE_MAX_QUEUES_PER_PORT];
1731         /** Queues state: STARTED(1) / STOPPED(0) */
1732         uint32_t dev_flags; /**< Capabilities */
1733         enum rte_kernel_driver kdrv;    /**< Kernel driver passthrough */
1734         int numa_node;  /**< NUMA node connection */
1735         const char *drv_name;   /**< Driver name */
1736 };
1737
1738 /** Device supports hotplug detach */
1739 #define RTE_ETH_DEV_DETACHABLE   0x0001
1740 /** Device supports link state interrupt */
1741 #define RTE_ETH_DEV_INTR_LSC     0x0002
1742 /** Device is a bonded slave */
1743 #define RTE_ETH_DEV_BONDED_SLAVE 0x0004
1744
1745 /**
1746  * @internal
1747  * The pool of *rte_eth_dev* structures. The size of the pool
1748  * is configured at compile-time in the <rte_ethdev.c> file.
1749  */
1750 extern struct rte_eth_dev rte_eth_devices[];
1751
1752 /**
1753  * Get the total number of Ethernet devices that have been successfully
1754  * initialized by the [matching] Ethernet driver during the PCI probing phase.
1755  * All devices whose port identifier is in the range
1756  * [0,  rte_eth_dev_count() - 1] can be operated on by network applications
1757  * immediately after invoking rte_eal_init().
1758  * If the application unplugs a port using hotplug function, The enabled port
1759  * numbers may be noncontiguous. In the case, the applications need to manage
1760  * enabled port by themselves.
1761  *
1762  * @return
1763  *   - The total number of usable Ethernet devices.
1764  */
1765 uint8_t rte_eth_dev_count(void);
1766
1767 /**
1768  * @internal
1769  * Returns a ethdev slot specified by the unique identifier name.
1770  *
1771  * @param       name
1772  *  The pointer to the Unique identifier name for each Ethernet device
1773  * @return
1774  *   - The pointer to the ethdev slot, on success. NULL on error
1775  */
1776 struct rte_eth_dev *rte_eth_dev_allocated(const char *name);
1777
1778 /**
1779  * @internal
1780  * Allocates a new ethdev slot for an ethernet device and returns the pointer
1781  * to that slot for the driver to use.
1782  *
1783  * @param       name    Unique identifier name for each Ethernet device
1784  * @param       type    Device type of this Ethernet device
1785  * @return
1786  *   - Slot in the rte_dev_devices array for a new device;
1787  */
1788 struct rte_eth_dev *rte_eth_dev_allocate(const char *name);
1789
1790 /**
1791  * @internal
1792  * Release the specified ethdev port.
1793  *
1794  * @param eth_dev
1795  * The *eth_dev* pointer is the address of the *rte_eth_dev* structure.
1796  * @return
1797  *   - 0 on success, negative on error
1798  */
1799 int rte_eth_dev_release_port(struct rte_eth_dev *eth_dev);
1800
1801 /**
1802  * Attach a new Ethernet device specified by aruguments.
1803  *
1804  * @param devargs
1805  *  A pointer to a strings array describing the new device
1806  *  to be attached. The strings should be a pci address like
1807  *  '0000:01:00.0' or virtual device name like 'net_pcap0'.
1808  * @param port_id
1809  *  A pointer to a port identifier actually attached.
1810  * @return
1811  *  0 on success and port_id is filled, negative on error
1812  */
1813 int rte_eth_dev_attach(const char *devargs, uint8_t *port_id);
1814
1815 /**
1816  * Detach a Ethernet device specified by port identifier.
1817  * This function must be called when the device is in the
1818  * closed state.
1819  *
1820  * @param port_id
1821  *   The port identifier of the device to detach.
1822  * @param devname
1823  *  A pointer to a device name actually detached.
1824  * @return
1825  *  0 on success and devname is filled, negative on error
1826  */
1827 int rte_eth_dev_detach(uint8_t port_id, char *devname);
1828
1829 struct eth_driver;
1830 /**
1831  * @internal
1832  * Initialization function of an Ethernet driver invoked for each matching
1833  * Ethernet PCI device detected during the PCI probing phase.
1834  *
1835  * @param eth_dev
1836  *   The *eth_dev* pointer is the address of the *rte_eth_dev* structure
1837  *   associated with the matching device and which have been [automatically]
1838  *   allocated in the *rte_eth_devices* array.
1839  *   The *eth_dev* structure is supplied to the driver initialization function
1840  *   with the following fields already initialized:
1841  *
1842  *   - *pci_dev*: Holds the pointers to the *rte_pci_device* structure which
1843  *     contains the generic PCI information of the matching device.
1844  *
1845  *   - *driver*: Holds the pointer to the *eth_driver* structure.
1846  *
1847  *   - *dev_private*: Holds a pointer to the device private data structure.
1848  *
1849  *   - *mtu*: Contains the default Ethernet maximum frame length (1500).
1850  *
1851  *   - *port_id*: Contains the port index of the device (actually the index
1852  *     of the *eth_dev* structure in the *rte_eth_devices* array).
1853  *
1854  * @return
1855  *   - 0: Success, the device is properly initialized by the driver.
1856  *        In particular, the driver MUST have set up the *dev_ops* pointer
1857  *        of the *eth_dev* structure.
1858  *   - <0: Error code of the device initialization failure.
1859  */
1860 typedef int (*eth_dev_init_t)(struct rte_eth_dev *eth_dev);
1861
1862 /**
1863  * @internal
1864  * Finalization function of an Ethernet driver invoked for each matching
1865  * Ethernet PCI device detected during the PCI closing phase.
1866  *
1867  * @param eth_dev
1868  *   The *eth_dev* pointer is the address of the *rte_eth_dev* structure
1869  *   associated with the matching device and which have been [automatically]
1870  *   allocated in the *rte_eth_devices* array.
1871  * @return
1872  *   - 0: Success, the device is properly finalized by the driver.
1873  *        In particular, the driver MUST free the *dev_ops* pointer
1874  *        of the *eth_dev* structure.
1875  *   - <0: Error code of the device initialization failure.
1876  */
1877 typedef int (*eth_dev_uninit_t)(struct rte_eth_dev *eth_dev);
1878
1879 /**
1880  * @internal
1881  * The structure associated with a PMD Ethernet driver.
1882  *
1883  * Each Ethernet driver acts as a PCI driver and is represented by a generic
1884  * *eth_driver* structure that holds:
1885  *
1886  * - An *rte_pci_driver* structure (which must be the first field).
1887  *
1888  * - The *eth_dev_init* function invoked for each matching PCI device.
1889  *
1890  * - The *eth_dev_uninit* function invoked for each matching PCI device.
1891  *
1892  * - The size of the private data to allocate for each matching device.
1893  */
1894 struct eth_driver {
1895         struct rte_pci_driver pci_drv;    /**< The PMD is also a PCI driver. */
1896         eth_dev_init_t eth_dev_init;      /**< Device init function. */
1897         eth_dev_uninit_t eth_dev_uninit;  /**< Device uninit function. */
1898         unsigned int dev_private_size;    /**< Size of device private data. */
1899 };
1900
1901 /**
1902  * Convert a numerical speed in Mbps to a bitmap flag that can be used in
1903  * the bitmap link_speeds of the struct rte_eth_conf
1904  *
1905  * @param speed
1906  *   Numerical speed value in Mbps
1907  * @param duplex
1908  *   ETH_LINK_[HALF/FULL]_DUPLEX (only for 10/100M speeds)
1909  * @return
1910  *   0 if the speed cannot be mapped
1911  */
1912 uint32_t rte_eth_speed_bitflag(uint32_t speed, int duplex);
1913
1914 /**
1915  * Configure an Ethernet device.
1916  * This function must be invoked first before any other function in the
1917  * Ethernet API. This function can also be re-invoked when a device is in the
1918  * stopped state.
1919  *
1920  * @param port_id
1921  *   The port identifier of the Ethernet device to configure.
1922  * @param nb_rx_queue
1923  *   The number of receive queues to set up for the Ethernet device.
1924  * @param nb_tx_queue
1925  *   The number of transmit queues to set up for the Ethernet device.
1926  * @param eth_conf
1927  *   The pointer to the configuration data to be used for the Ethernet device.
1928  *   The *rte_eth_conf* structure includes:
1929  *     -  the hardware offload features to activate, with dedicated fields for
1930  *        each statically configurable offload hardware feature provided by
1931  *        Ethernet devices, such as IP checksum or VLAN tag stripping for
1932  *        example.
1933  *     - the Receive Side Scaling (RSS) configuration when using multiple RX
1934  *         queues per port.
1935  *
1936  *   Embedding all configuration information in a single data structure
1937  *   is the more flexible method that allows the addition of new features
1938  *   without changing the syntax of the API.
1939  * @return
1940  *   - 0: Success, device configured.
1941  *   - <0: Error code returned by the driver configuration function.
1942  */
1943 int rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_queue,
1944                 uint16_t nb_tx_queue, const struct rte_eth_conf *eth_conf);
1945
1946 /**
1947  * @internal
1948  * Release device queues and clear its configuration to force the user
1949  * application to reconfigure it. It is for internal use only.
1950  *
1951  * @param dev
1952  *  Pointer to struct rte_eth_dev.
1953  *
1954  * @return
1955  *  void
1956  */
1957 void _rte_eth_dev_reset(struct rte_eth_dev *dev);
1958
1959 /**
1960  * Allocate and set up a receive queue for an Ethernet device.
1961  *
1962  * The function allocates a contiguous block of memory for *nb_rx_desc*
1963  * receive descriptors from a memory zone associated with *socket_id*
1964  * and initializes each receive descriptor with a network buffer allocated
1965  * from the memory pool *mb_pool*.
1966  *
1967  * @param port_id
1968  *   The port identifier of the Ethernet device.
1969  * @param rx_queue_id
1970  *   The index of the receive queue to set up.
1971  *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
1972  *   to rte_eth_dev_configure().
1973  * @param nb_rx_desc
1974  *   The number of receive descriptors to allocate for the receive ring.
1975  * @param socket_id
1976  *   The *socket_id* argument is the socket identifier in case of NUMA.
1977  *   The value can be *SOCKET_ID_ANY* if there is no NUMA constraint for
1978  *   the DMA memory allocated for the receive descriptors of the ring.
1979  * @param rx_conf
1980  *   The pointer to the configuration data to be used for the receive queue.
1981  *   NULL value is allowed, in which case default RX configuration
1982  *   will be used.
1983  *   The *rx_conf* structure contains an *rx_thresh* structure with the values
1984  *   of the Prefetch, Host, and Write-Back threshold registers of the receive
1985  *   ring.
1986  * @param mb_pool
1987  *   The pointer to the memory pool from which to allocate *rte_mbuf* network
1988  *   memory buffers to populate each descriptor of the receive ring.
1989  * @return
1990  *   - 0: Success, receive queue correctly set up.
1991  *   - -EINVAL: The size of network buffers which can be allocated from the
1992  *      memory pool does not fit the various buffer sizes allowed by the
1993  *      device controller.
1994  *   - -ENOMEM: Unable to allocate the receive ring descriptors or to
1995  *      allocate network memory buffers from the memory pool when
1996  *      initializing receive descriptors.
1997  */
1998 int rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1999                 uint16_t nb_rx_desc, unsigned int socket_id,
2000                 const struct rte_eth_rxconf *rx_conf,
2001                 struct rte_mempool *mb_pool);
2002
2003 /**
2004  * Allocate and set up a transmit queue for an Ethernet device.
2005  *
2006  * @param port_id
2007  *   The port identifier of the Ethernet device.
2008  * @param tx_queue_id
2009  *   The index of the transmit queue to set up.
2010  *   The value must be in the range [0, nb_tx_queue - 1] previously supplied
2011  *   to rte_eth_dev_configure().
2012  * @param nb_tx_desc
2013  *   The number of transmit descriptors to allocate for the transmit ring.
2014  * @param socket_id
2015  *   The *socket_id* argument is the socket identifier in case of NUMA.
2016  *   Its value can be *SOCKET_ID_ANY* if there is no NUMA constraint for
2017  *   the DMA memory allocated for the transmit descriptors of the ring.
2018  * @param tx_conf
2019  *   The pointer to the configuration data to be used for the transmit queue.
2020  *   NULL value is allowed, in which case default RX configuration
2021  *   will be used.
2022  *   The *tx_conf* structure contains the following data:
2023  *   - The *tx_thresh* structure with the values of the Prefetch, Host, and
2024  *     Write-Back threshold registers of the transmit ring.
2025  *     When setting Write-Back threshold to the value greater then zero,
2026  *     *tx_rs_thresh* value should be explicitly set to one.
2027  *   - The *tx_free_thresh* value indicates the [minimum] number of network
2028  *     buffers that must be pending in the transmit ring to trigger their
2029  *     [implicit] freeing by the driver transmit function.
2030  *   - The *tx_rs_thresh* value indicates the [minimum] number of transmit
2031  *     descriptors that must be pending in the transmit ring before setting the
2032  *     RS bit on a descriptor by the driver transmit function.
2033  *     The *tx_rs_thresh* value should be less or equal then
2034  *     *tx_free_thresh* value, and both of them should be less then
2035  *     *nb_tx_desc* - 3.
2036  *   - The *txq_flags* member contains flags to pass to the TX queue setup
2037  *     function to configure the behavior of the TX queue. This should be set
2038  *     to 0 if no special configuration is required.
2039  *
2040  *     Note that setting *tx_free_thresh* or *tx_rs_thresh* value to 0 forces
2041  *     the transmit function to use default values.
2042  * @return
2043  *   - 0: Success, the transmit queue is correctly set up.
2044  *   - -ENOMEM: Unable to allocate the transmit ring descriptors.
2045  */
2046 int rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
2047                 uint16_t nb_tx_desc, unsigned int socket_id,
2048                 const struct rte_eth_txconf *tx_conf);
2049
2050 /**
2051  * Return the NUMA socket to which an Ethernet device is connected
2052  *
2053  * @param port_id
2054  *   The port identifier of the Ethernet device
2055  * @return
2056  *   The NUMA socket id to which the Ethernet device is connected or
2057  *   a default of zero if the socket could not be determined.
2058  *   -1 is returned is the port_id value is out of range.
2059  */
2060 int rte_eth_dev_socket_id(uint8_t port_id);
2061
2062 /**
2063  * Check if port_id of device is attached
2064  *
2065  * @param port_id
2066  *   The port identifier of the Ethernet device
2067  * @return
2068  *   - 0 if port is out of range or not attached
2069  *   - 1 if device is attached
2070  */
2071 int rte_eth_dev_is_valid_port(uint8_t port_id);
2072
2073 /**
2074  * Start specified RX queue of a port. It is used when rx_deferred_start
2075  * flag of the specified queue is true.
2076  *
2077  * @param port_id
2078  *   The port identifier of the Ethernet device
2079  * @param rx_queue_id
2080  *   The index of the rx queue to update the ring.
2081  *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
2082  *   to rte_eth_dev_configure().
2083  * @return
2084  *   - 0: Success, the receive queue is started.
2085  *   - -EINVAL: The port_id or the queue_id out of range.
2086  *   - -ENOTSUP: The function not supported in PMD driver.
2087  */
2088 int rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id);
2089
2090 /**
2091  * Stop specified RX queue of a port
2092  *
2093  * @param port_id
2094  *   The port identifier of the Ethernet device
2095  * @param rx_queue_id
2096  *   The index of the rx queue to update the ring.
2097  *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
2098  *   to rte_eth_dev_configure().
2099  * @return
2100  *   - 0: Success, the receive queue is stopped.
2101  *   - -EINVAL: The port_id or the queue_id out of range.
2102  *   - -ENOTSUP: The function not supported in PMD driver.
2103  */
2104 int rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id);
2105
2106 /**
2107  * Start TX for specified queue of a port. It is used when tx_deferred_start
2108  * flag of the specified queue is true.
2109  *
2110  * @param port_id
2111  *   The port identifier of the Ethernet device
2112  * @param tx_queue_id
2113  *   The index of the tx queue to update the ring.
2114  *   The value must be in the range [0, nb_tx_queue - 1] previously supplied
2115  *   to rte_eth_dev_configure().
2116  * @return
2117  *   - 0: Success, the transmit queue is started.
2118  *   - -EINVAL: The port_id or the queue_id out of range.
2119  *   - -ENOTSUP: The function not supported in PMD driver.
2120  */
2121 int rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id);
2122
2123 /**
2124  * Stop specified TX queue of a port
2125  *
2126  * @param port_id
2127  *   The port identifier of the Ethernet device
2128  * @param tx_queue_id
2129  *   The index of the tx queue to update the ring.
2130  *   The value must be in the range [0, nb_tx_queue - 1] previously supplied
2131  *   to rte_eth_dev_configure().
2132  * @return
2133  *   - 0: Success, the transmit queue is stopped.
2134  *   - -EINVAL: The port_id or the queue_id out of range.
2135  *   - -ENOTSUP: The function not supported in PMD driver.
2136  */
2137 int rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id);
2138
2139
2140
2141 /**
2142  * Start an Ethernet device.
2143  *
2144  * The device start step is the last one and consists of setting the configured
2145  * offload features and in starting the transmit and the receive units of the
2146  * device.
2147  * On success, all basic functions exported by the Ethernet API (link status,
2148  * receive/transmit, and so on) can be invoked.
2149  *
2150  * @param port_id
2151  *   The port identifier of the Ethernet device.
2152  * @return
2153  *   - 0: Success, Ethernet device started.
2154  *   - <0: Error code of the driver device start function.
2155  */
2156 int rte_eth_dev_start(uint8_t port_id);
2157
2158 /**
2159  * Stop an Ethernet device. The device can be restarted with a call to
2160  * rte_eth_dev_start()
2161  *
2162  * @param port_id
2163  *   The port identifier of the Ethernet device.
2164  */
2165 void rte_eth_dev_stop(uint8_t port_id);
2166
2167
2168 /**
2169  * Link up an Ethernet device.
2170  *
2171  * Set device link up will re-enable the device rx/tx
2172  * functionality after it is previously set device linked down.
2173  *
2174  * @param port_id
2175  *   The port identifier of the Ethernet device.
2176  * @return
2177  *   - 0: Success, Ethernet device linked up.
2178  *   - <0: Error code of the driver device link up function.
2179  */
2180 int rte_eth_dev_set_link_up(uint8_t port_id);
2181
2182 /**
2183  * Link down an Ethernet device.
2184  * The device rx/tx functionality will be disabled if success,
2185  * and it can be re-enabled with a call to
2186  * rte_eth_dev_set_link_up()
2187  *
2188  * @param port_id
2189  *   The port identifier of the Ethernet device.
2190  */
2191 int rte_eth_dev_set_link_down(uint8_t port_id);
2192
2193 /**
2194  * Close a stopped Ethernet device. The device cannot be restarted!
2195  * The function frees all resources except for needed by the
2196  * closed state. To free these resources, call rte_eth_dev_detach().
2197  *
2198  * @param port_id
2199  *   The port identifier of the Ethernet device.
2200  */
2201 void rte_eth_dev_close(uint8_t port_id);
2202
2203 /**
2204  * Enable receipt in promiscuous mode for an Ethernet device.
2205  *
2206  * @param port_id
2207  *   The port identifier of the Ethernet device.
2208  */
2209 void rte_eth_promiscuous_enable(uint8_t port_id);
2210
2211 /**
2212  * Disable receipt in promiscuous mode for an Ethernet device.
2213  *
2214  * @param port_id
2215  *   The port identifier of the Ethernet device.
2216  */
2217 void rte_eth_promiscuous_disable(uint8_t port_id);
2218
2219 /**
2220  * Return the value of promiscuous mode for an Ethernet device.
2221  *
2222  * @param port_id
2223  *   The port identifier of the Ethernet device.
2224  * @return
2225  *   - (1) if promiscuous is enabled
2226  *   - (0) if promiscuous is disabled.
2227  *   - (-1) on error
2228  */
2229 int rte_eth_promiscuous_get(uint8_t port_id);
2230
2231 /**
2232  * Enable the receipt of any multicast frame by an Ethernet device.
2233  *
2234  * @param port_id
2235  *   The port identifier of the Ethernet device.
2236  */
2237 void rte_eth_allmulticast_enable(uint8_t port_id);
2238
2239 /**
2240  * Disable the receipt of all multicast frames by an Ethernet device.
2241  *
2242  * @param port_id
2243  *   The port identifier of the Ethernet device.
2244  */
2245 void rte_eth_allmulticast_disable(uint8_t port_id);
2246
2247 /**
2248  * Return the value of allmulticast mode for an Ethernet device.
2249  *
2250  * @param port_id
2251  *   The port identifier of the Ethernet device.
2252  * @return
2253  *   - (1) if allmulticast is enabled
2254  *   - (0) if allmulticast is disabled.
2255  *   - (-1) on error
2256  */
2257 int rte_eth_allmulticast_get(uint8_t port_id);
2258
2259 /**
2260  * Retrieve the status (ON/OFF), the speed (in Mbps) and the mode (HALF-DUPLEX
2261  * or FULL-DUPLEX) of the physical link of an Ethernet device. It might need
2262  * to wait up to 9 seconds in it.
2263  *
2264  * @param port_id
2265  *   The port identifier of the Ethernet device.
2266  * @param link
2267  *   A pointer to an *rte_eth_link* structure to be filled with
2268  *   the status, the speed and the mode of the Ethernet device link.
2269  */
2270 void rte_eth_link_get(uint8_t port_id, struct rte_eth_link *link);
2271
2272 /**
2273  * Retrieve the status (ON/OFF), the speed (in Mbps) and the mode (HALF-DUPLEX
2274  * or FULL-DUPLEX) of the physical link of an Ethernet device. It is a no-wait
2275  * version of rte_eth_link_get().
2276  *
2277  * @param port_id
2278  *   The port identifier of the Ethernet device.
2279  * @param link
2280  *   A pointer to an *rte_eth_link* structure to be filled with
2281  *   the status, the speed and the mode of the Ethernet device link.
2282  */
2283 void rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *link);
2284
2285 /**
2286  * Retrieve the general I/O statistics of an Ethernet device.
2287  *
2288  * @param port_id
2289  *   The port identifier of the Ethernet device.
2290  * @param stats
2291  *   A pointer to a structure of type *rte_eth_stats* to be filled with
2292  *   the values of device counters for the following set of statistics:
2293  *   - *ipackets* with the total of successfully received packets.
2294  *   - *opackets* with the total of successfully transmitted packets.
2295  *   - *ibytes*   with the total of successfully received bytes.
2296  *   - *obytes*   with the total of successfully transmitted bytes.
2297  *   - *ierrors*  with the total of erroneous received packets.
2298  *   - *oerrors*  with the total of failed transmitted packets.
2299  * @return
2300  *   Zero if successful. Non-zero otherwise.
2301  */
2302 int rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats);
2303
2304 /**
2305  * Reset the general I/O statistics of an Ethernet device.
2306  *
2307  * @param port_id
2308  *   The port identifier of the Ethernet device.
2309  */
2310 void rte_eth_stats_reset(uint8_t port_id);
2311
2312 /**
2313  * Retrieve names of extended statistics of an Ethernet device.
2314  *
2315  * @param port_id
2316  *   The port identifier of the Ethernet device.
2317  * @param xstats_names
2318  *   An rte_eth_xstat_name array of at least *size* elements to
2319  *   be filled. If set to NULL, the function returns the required number
2320  *   of elements.
2321  * @param size
2322  *   The size of the xstats_names array (number of elements).
2323  * @return
2324  *   - A positive value lower or equal to size: success. The return value
2325  *     is the number of entries filled in the stats table.
2326  *   - A positive value higher than size: error, the given statistics table
2327  *     is too small. The return value corresponds to the size that should
2328  *     be given to succeed. The entries in the table are not valid and
2329  *     shall not be used by the caller.
2330  *   - A negative value on error (invalid port id).
2331  */
2332 int rte_eth_xstats_get_names(uint8_t port_id,
2333                 struct rte_eth_xstat_name *xstats_names,
2334                 unsigned size);
2335
2336 /**
2337  * Retrieve extended statistics of an Ethernet device.
2338  *
2339  * @param port_id
2340  *   The port identifier of the Ethernet device.
2341  * @param xstats
2342  *   A pointer to a table of structure of type *rte_eth_xstat*
2343  *   to be filled with device statistics ids and values: id is the
2344  *   index of the name string in xstats_names (see rte_eth_xstats_get_names()),
2345  *   and value is the statistic counter.
2346  *   This parameter can be set to NULL if n is 0.
2347  * @param n
2348  *   The size of the xstats array (number of elements).
2349  * @return
2350  *   - A positive value lower or equal to n: success. The return value
2351  *     is the number of entries filled in the stats table.
2352  *   - A positive value higher than n: error, the given statistics table
2353  *     is too small. The return value corresponds to the size that should
2354  *     be given to succeed. The entries in the table are not valid and
2355  *     shall not be used by the caller.
2356  *   - A negative value on error (invalid port id).
2357  */
2358 int rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstat *xstats,
2359                 unsigned n);
2360
2361 /**
2362  * Reset extended statistics of an Ethernet device.
2363  *
2364  * @param port_id
2365  *   The port identifier of the Ethernet device.
2366  */
2367 void rte_eth_xstats_reset(uint8_t port_id);
2368
2369 /**
2370  *  Set a mapping for the specified transmit queue to the specified per-queue
2371  *  statistics counter.
2372  *
2373  * @param port_id
2374  *   The port identifier of the Ethernet device.
2375  * @param tx_queue_id
2376  *   The index of the transmit queue for which a queue stats mapping is required.
2377  *   The value must be in the range [0, nb_tx_queue - 1] previously supplied
2378  *   to rte_eth_dev_configure().
2379  * @param stat_idx
2380  *   The per-queue packet statistics functionality number that the transmit
2381  *   queue is to be assigned.
2382  *   The value must be in the range [0, RTE_MAX_ETHPORT_QUEUE_STATS_MAPS - 1].
2383  * @return
2384  *   Zero if successful. Non-zero otherwise.
2385  */
2386 int rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id,
2387                 uint16_t tx_queue_id, uint8_t stat_idx);
2388
2389 /**
2390  *  Set a mapping for the specified receive queue to the specified per-queue
2391  *  statistics counter.
2392  *
2393  * @param port_id
2394  *   The port identifier of the Ethernet device.
2395  * @param rx_queue_id
2396  *   The index of the receive queue for which a queue stats mapping is required.
2397  *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
2398  *   to rte_eth_dev_configure().
2399  * @param stat_idx
2400  *   The per-queue packet statistics functionality number that the receive
2401  *   queue is to be assigned.
2402  *   The value must be in the range [0, RTE_MAX_ETHPORT_QUEUE_STATS_MAPS - 1].
2403  * @return
2404  *   Zero if successful. Non-zero otherwise.
2405  */
2406 int rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id,
2407                                            uint16_t rx_queue_id,
2408                                            uint8_t stat_idx);
2409
2410 /**
2411  * Retrieve the Ethernet address of an Ethernet device.
2412  *
2413  * @param port_id
2414  *   The port identifier of the Ethernet device.
2415  * @param mac_addr
2416  *   A pointer to a structure of type *ether_addr* to be filled with
2417  *   the Ethernet address of the Ethernet device.
2418  */
2419 void rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr);
2420
2421 /**
2422  * Retrieve the contextual information of an Ethernet device.
2423  *
2424  * @param port_id
2425  *   The port identifier of the Ethernet device.
2426  * @param dev_info
2427  *   A pointer to a structure of type *rte_eth_dev_info* to be filled with
2428  *   the contextual information of the Ethernet device.
2429  */
2430 void rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info);
2431
2432 /**
2433  * Retrieve the supported packet types of an Ethernet device.
2434  *
2435  * When a packet type is announced as supported, it *must* be recognized by
2436  * the PMD. For instance, if RTE_PTYPE_L2_ETHER, RTE_PTYPE_L2_ETHER_VLAN
2437  * and RTE_PTYPE_L3_IPV4 are announced, the PMD must return the following
2438  * packet types for these packets:
2439  * - Ether/IPv4              -> RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4
2440  * - Ether/Vlan/IPv4         -> RTE_PTYPE_L2_ETHER_VLAN | RTE_PTYPE_L3_IPV4
2441  * - Ether/[anything else]   -> RTE_PTYPE_L2_ETHER
2442  * - Ether/Vlan/[anything else] -> RTE_PTYPE_L2_ETHER_VLAN
2443  *
2444  * When a packet is received by a PMD, the most precise type must be
2445  * returned among the ones supported. However a PMD is allowed to set
2446  * packet type that is not in the supported list, at the condition that it
2447  * is more precise. Therefore, a PMD announcing no supported packet types
2448  * can still set a matching packet type in a received packet.
2449  *
2450  * @note
2451  *   Better to invoke this API after the device is already started or rx burst
2452  *   function is decided, to obtain correct supported ptypes.
2453  * @note
2454  *   if a given PMD does not report what ptypes it supports, then the supported
2455  *   ptype count is reported as 0.
2456  * @param port_id
2457  *   The port identifier of the Ethernet device.
2458  * @param ptype_mask
2459  *   A hint of what kind of packet type which the caller is interested in.
2460  * @param ptypes
2461  *   An array pointer to store adequent packet types, allocated by caller.
2462  * @param num
2463  *  Size of the array pointed by param ptypes.
2464  * @return
2465  *   - (>=0) Number of supported ptypes. If the number of types exceeds num,
2466  *           only num entries will be filled into the ptypes array, but the full
2467  *           count of supported ptypes will be returned.
2468  *   - (-ENODEV) if *port_id* invalid.
2469  */
2470 int rte_eth_dev_get_supported_ptypes(uint8_t port_id, uint32_t ptype_mask,
2471                                      uint32_t *ptypes, int num);
2472
2473 /**
2474  * Retrieve the MTU of an Ethernet device.
2475  *
2476  * @param port_id
2477  *   The port identifier of the Ethernet device.
2478  * @param mtu
2479  *   A pointer to a uint16_t where the retrieved MTU is to be stored.
2480  * @return
2481  *   - (0) if successful.
2482  *   - (-ENODEV) if *port_id* invalid.
2483  */
2484 int rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu);
2485
2486 /**
2487  * Change the MTU of an Ethernet device.
2488  *
2489  * @param port_id
2490  *   The port identifier of the Ethernet device.
2491  * @param mtu
2492  *   A uint16_t for the MTU to be applied.
2493  * @return
2494  *   - (0) if successful.
2495  *   - (-ENOTSUP) if operation is not supported.
2496  *   - (-ENODEV) if *port_id* invalid.
2497  *   - (-EINVAL) if *mtu* invalid.
2498  *   - (-EBUSY) if operation is not allowed when the port is running
2499  */
2500 int rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu);
2501
2502 /**
2503  * Enable/Disable hardware filtering by an Ethernet device of received
2504  * VLAN packets tagged with a given VLAN Tag Identifier.
2505  *
2506  * @param port_id
2507  *   The port identifier of the Ethernet device.
2508  * @param vlan_id
2509  *   The VLAN Tag Identifier whose filtering must be enabled or disabled.
2510  * @param on
2511  *   If > 0, enable VLAN filtering of VLAN packets tagged with *vlan_id*.
2512  *   Otherwise, disable VLAN filtering of VLAN packets tagged with *vlan_id*.
2513  * @return
2514  *   - (0) if successful.
2515  *   - (-ENOSUP) if hardware-assisted VLAN filtering not configured.
2516  *   - (-ENODEV) if *port_id* invalid.
2517  *   - (-ENOSYS) if VLAN filtering on *port_id* disabled.
2518  *   - (-EINVAL) if *vlan_id* > 4095.
2519  */
2520 int rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on);
2521
2522 /**
2523  * Enable/Disable hardware VLAN Strip by a rx queue of an Ethernet device.
2524  * 82599/X540/X550 can support VLAN stripping at the rx queue level
2525  *
2526  * @param port_id
2527  *   The port identifier of the Ethernet device.
2528  * @param rx_queue_id
2529  *   The index of the receive queue for which a queue stats mapping is required.
2530  *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
2531  *   to rte_eth_dev_configure().
2532  * @param on
2533  *   If 1, Enable VLAN Stripping of the receive queue of the Ethernet port.
2534  *   If 0, Disable VLAN Stripping of the receive queue of the Ethernet port.
2535  * @return
2536  *   - (0) if successful.
2537  *   - (-ENOSUP) if hardware-assisted VLAN stripping not configured.
2538  *   - (-ENODEV) if *port_id* invalid.
2539  *   - (-EINVAL) if *rx_queue_id* invalid.
2540  */
2541 int rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id,
2542                 int on);
2543
2544 /**
2545  * Set the Outer VLAN Ether Type by an Ethernet device, it can be inserted to
2546  * the VLAN Header. This is a register setup available on some Intel NIC, not
2547  * but all, please check the data sheet for availability.
2548  *
2549  * @param port_id
2550  *   The port identifier of the Ethernet device.
2551  * @param vlan_type
2552  *   The vlan type.
2553  * @param tag_type
2554  *   The Tag Protocol ID
2555  * @return
2556  *   - (0) if successful.
2557  *   - (-ENOSUP) if hardware-assisted VLAN TPID setup is not supported.
2558  *   - (-ENODEV) if *port_id* invalid.
2559  */
2560 int rte_eth_dev_set_vlan_ether_type(uint8_t port_id,
2561                                     enum rte_vlan_type vlan_type,
2562                                     uint16_t tag_type);
2563
2564 /**
2565  * Set VLAN offload configuration on an Ethernet device
2566  * Enable/Disable Extended VLAN by an Ethernet device, This is a register setup
2567  * available on some Intel NIC, not but all, please check the data sheet for
2568  * availability.
2569  * Enable/Disable VLAN Strip can be done on rx queue for certain NIC, but here
2570  * the configuration is applied on the port level.
2571  *
2572  * @param port_id
2573  *   The port identifier of the Ethernet device.
2574  * @param offload_mask
2575  *   The VLAN Offload bit mask can be mixed use with "OR"
2576  *       ETH_VLAN_STRIP_OFFLOAD
2577  *       ETH_VLAN_FILTER_OFFLOAD
2578  *       ETH_VLAN_EXTEND_OFFLOAD
2579  * @return
2580  *   - (0) if successful.
2581  *   - (-ENOSUP) if hardware-assisted VLAN filtering not configured.
2582  *   - (-ENODEV) if *port_id* invalid.
2583  */
2584 int rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask);
2585
2586 /**
2587  * Read VLAN Offload configuration from an Ethernet device
2588  *
2589  * @param port_id
2590  *   The port identifier of the Ethernet device.
2591  * @return
2592  *   - (>0) if successful. Bit mask to indicate
2593  *       ETH_VLAN_STRIP_OFFLOAD
2594  *       ETH_VLAN_FILTER_OFFLOAD
2595  *       ETH_VLAN_EXTEND_OFFLOAD
2596  *   - (-ENODEV) if *port_id* invalid.
2597  */
2598 int rte_eth_dev_get_vlan_offload(uint8_t port_id);
2599
2600 /**
2601  * Set port based TX VLAN insersion on or off.
2602  *
2603  * @param port_id
2604  *  The port identifier of the Ethernet device.
2605  * @param pvid
2606  *  Port based TX VLAN identifier togeth with user priority.
2607  * @param on
2608  *  Turn on or off the port based TX VLAN insertion.
2609  *
2610  * @return
2611  *   - (0) if successful.
2612  *   - negative if failed.
2613  */
2614 int rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on);
2615
2616 /**
2617  *
2618  * Retrieve a burst of input packets from a receive queue of an Ethernet
2619  * device. The retrieved packets are stored in *rte_mbuf* structures whose
2620  * pointers are supplied in the *rx_pkts* array.
2621  *
2622  * The rte_eth_rx_burst() function loops, parsing the RX ring of the
2623  * receive queue, up to *nb_pkts* packets, and for each completed RX
2624  * descriptor in the ring, it performs the following operations:
2625  *
2626  * - Initialize the *rte_mbuf* data structure associated with the
2627  *   RX descriptor according to the information provided by the NIC into
2628  *   that RX descriptor.
2629  *
2630  * - Store the *rte_mbuf* data structure into the next entry of the
2631  *   *rx_pkts* array.
2632  *
2633  * - Replenish the RX descriptor with a new *rte_mbuf* buffer
2634  *   allocated from the memory pool associated with the receive queue at
2635  *   initialization time.
2636  *
2637  * When retrieving an input packet that was scattered by the controller
2638  * into multiple receive descriptors, the rte_eth_rx_burst() function
2639  * appends the associated *rte_mbuf* buffers to the first buffer of the
2640  * packet.
2641  *
2642  * The rte_eth_rx_burst() function returns the number of packets
2643  * actually retrieved, which is the number of *rte_mbuf* data structures
2644  * effectively supplied into the *rx_pkts* array.
2645  * A return value equal to *nb_pkts* indicates that the RX queue contained
2646  * at least *rx_pkts* packets, and this is likely to signify that other
2647  * received packets remain in the input queue. Applications implementing
2648  * a "retrieve as much received packets as possible" policy can check this
2649  * specific case and keep invoking the rte_eth_rx_burst() function until
2650  * a value less than *nb_pkts* is returned.
2651  *
2652  * This receive method has the following advantages:
2653  *
2654  * - It allows a run-to-completion network stack engine to retrieve and
2655  *   to immediately process received packets in a fast burst-oriented
2656  *   approach, avoiding the overhead of unnecessary intermediate packet
2657  *   queue/dequeue operations.
2658  *
2659  * - Conversely, it also allows an asynchronous-oriented processing
2660  *   method to retrieve bursts of received packets and to immediately
2661  *   queue them for further parallel processing by another logical core,
2662  *   for instance. However, instead of having received packets being
2663  *   individually queued by the driver, this approach allows the invoker
2664  *   of the rte_eth_rx_burst() function to queue a burst of retrieved
2665  *   packets at a time and therefore dramatically reduce the cost of
2666  *   enqueue/dequeue operations per packet.
2667  *
2668  * - It allows the rte_eth_rx_burst() function of the driver to take
2669  *   advantage of burst-oriented hardware features (CPU cache,
2670  *   prefetch instructions, and so on) to minimize the number of CPU
2671  *   cycles per packet.
2672  *
2673  * To summarize, the proposed receive API enables many
2674  * burst-oriented optimizations in both synchronous and asynchronous
2675  * packet processing environments with no overhead in both cases.
2676  *
2677  * The rte_eth_rx_burst() function does not provide any error
2678  * notification to avoid the corresponding overhead. As a hint, the
2679  * upper-level application might check the status of the device link once
2680  * being systematically returned a 0 value for a given number of tries.
2681  *
2682  * @param port_id
2683  *   The port identifier of the Ethernet device.
2684  * @param queue_id
2685  *   The index of the receive queue from which to retrieve input packets.
2686  *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
2687  *   to rte_eth_dev_configure().
2688  * @param rx_pkts
2689  *   The address of an array of pointers to *rte_mbuf* structures that
2690  *   must be large enough to store *nb_pkts* pointers in it.
2691  * @param nb_pkts
2692  *   The maximum number of packets to retrieve.
2693  * @return
2694  *   The number of packets actually retrieved, which is the number
2695  *   of pointers to *rte_mbuf* structures effectively supplied to the
2696  *   *rx_pkts* array.
2697  */
2698 static inline uint16_t
2699 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2700                  struct rte_mbuf **rx_pkts, const uint16_t nb_pkts)
2701 {
2702         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2703
2704 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2705         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0);
2706         RTE_FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);
2707
2708         if (queue_id >= dev->data->nb_rx_queues) {
2709                 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2710                 return 0;
2711         }
2712 #endif
2713         int16_t nb_rx = (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2714                         rx_pkts, nb_pkts);
2715
2716 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
2717         struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
2718
2719         if (unlikely(cb != NULL)) {
2720                 do {
2721                         nb_rx = cb->fn.rx(port_id, queue_id, rx_pkts, nb_rx,
2722                                                 nb_pkts, cb->param);
2723                         cb = cb->next;
2724                 } while (cb != NULL);
2725         }
2726 #endif
2727
2728         return nb_rx;
2729 }
2730
2731 /**
2732  * Get the number of used descriptors in a specific queue
2733  *
2734  * @param port_id
2735  *  The port identifier of the Ethernet device.
2736  * @param queue_id
2737  *  The queue id on the specific port.
2738  * @return
2739  *  The number of used descriptors in the specific queue, or:
2740  *     (-EINVAL) if *port_id* is invalid
2741  *     (-ENOTSUP) if the device does not support this function
2742  */
2743 static inline int
2744 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2745 {
2746         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2747         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2748         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, -ENOTSUP);
2749         return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2750 }
2751
2752 /**
2753  * Check if the DD bit of the specific RX descriptor in the queue has been set
2754  *
2755  * @param port_id
2756  *  The port identifier of the Ethernet device.
2757  * @param queue_id
2758  *  The queue id on the specific port.
2759  * @param offset
2760  *  The offset of the descriptor ID from tail.
2761  * @return
2762  *  - (1) if the specific DD bit is set.
2763  *  - (0) if the specific DD bit is not set.
2764  *  - (-ENODEV) if *port_id* invalid.
2765  *  - (-ENOTSUP) if the device does not support this function
2766  */
2767 static inline int
2768 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2769 {
2770         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2771         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2772         RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2773         return (*dev->dev_ops->rx_descriptor_done)( \
2774                 dev->data->rx_queues[queue_id], offset);
2775 }
2776
2777 /**
2778  * Send a burst of output packets on a transmit queue of an Ethernet device.
2779  *
2780  * The rte_eth_tx_burst() function is invoked to transmit output packets
2781  * on the output queue *queue_id* of the Ethernet device designated by its
2782  * *port_id*.
2783  * The *nb_pkts* parameter is the number of packets to send which are
2784  * supplied in the *tx_pkts* array of *rte_mbuf* structures, each of them
2785  * allocated from a pool created with rte_pktmbuf_pool_create().
2786  * The rte_eth_tx_burst() function loops, sending *nb_pkts* packets,
2787  * up to the number of transmit descriptors available in the TX ring of the
2788  * transmit queue.
2789  * For each packet to send, the rte_eth_tx_burst() function performs
2790  * the following operations:
2791  *
2792  * - Pick up the next available descriptor in the transmit ring.
2793  *
2794  * - Free the network buffer previously sent with that descriptor, if any.
2795  *
2796  * - Initialize the transmit descriptor with the information provided
2797  *   in the *rte_mbuf data structure.
2798  *
2799  * In the case of a segmented packet composed of a list of *rte_mbuf* buffers,
2800  * the rte_eth_tx_burst() function uses several transmit descriptors
2801  * of the ring.
2802  *
2803  * The rte_eth_tx_burst() function returns the number of packets it
2804  * actually sent. A return value equal to *nb_pkts* means that all packets
2805  * have been sent, and this is likely to signify that other output packets
2806  * could be immediately transmitted again. Applications that implement a
2807  * "send as many packets to transmit as possible" policy can check this
2808  * specific case and keep invoking the rte_eth_tx_burst() function until
2809  * a value less than *nb_pkts* is returned.
2810  *
2811  * It is the responsibility of the rte_eth_tx_burst() function to
2812  * transparently free the memory buffers of packets previously sent.
2813  * This feature is driven by the *tx_free_thresh* value supplied to the
2814  * rte_eth_dev_configure() function at device configuration time.
2815  * When the number of free TX descriptors drops below this threshold, the
2816  * rte_eth_tx_burst() function must [attempt to] free the *rte_mbuf*  buffers
2817  * of those packets whose transmission was effectively completed.
2818  *
2819  * @param port_id
2820  *   The port identifier of the Ethernet device.
2821  * @param queue_id
2822  *   The index of the transmit queue through which output packets must be
2823  *   sent.
2824  *   The value must be in the range [0, nb_tx_queue - 1] previously supplied
2825  *   to rte_eth_dev_configure().
2826  * @param tx_pkts
2827  *   The address of an array of *nb_pkts* pointers to *rte_mbuf* structures
2828  *   which contain the output packets.
2829  * @param nb_pkts
2830  *   The maximum number of packets to transmit.
2831  * @return
2832  *   The number of output packets actually stored in transmit descriptors of
2833  *   the transmit ring. The return value can be less than the value of the
2834  *   *tx_pkts* parameter when the transmit ring is full or has been filled up.
2835  */
2836 static inline uint16_t
2837 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2838                  struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2839 {
2840         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2841
2842 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2843         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0);
2844         RTE_FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0);
2845
2846         if (queue_id >= dev->data->nb_tx_queues) {
2847                 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2848                 return 0;
2849         }
2850 #endif
2851
2852 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
2853         struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
2854
2855         if (unlikely(cb != NULL)) {
2856                 do {
2857                         nb_pkts = cb->fn.tx(port_id, queue_id, tx_pkts, nb_pkts,
2858                                         cb->param);
2859                         cb = cb->next;
2860                 } while (cb != NULL);
2861         }
2862 #endif
2863
2864         return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id], tx_pkts, nb_pkts);
2865 }
2866
2867 /**
2868  * @warning
2869  * @b EXPERIMENTAL: this API may change without prior notice
2870  *
2871  * Process a burst of output packets on a transmit queue of an Ethernet device.
2872  *
2873  * The rte_eth_tx_prepare() function is invoked to prepare output packets to be
2874  * transmitted on the output queue *queue_id* of the Ethernet device designated
2875  * by its *port_id*.
2876  * The *nb_pkts* parameter is the number of packets to be prepared which are
2877  * supplied in the *tx_pkts* array of *rte_mbuf* structures, each of them
2878  * allocated from a pool created with rte_pktmbuf_pool_create().
2879  * For each packet to send, the rte_eth_tx_prepare() function performs
2880  * the following operations:
2881  *
2882  * - Check if packet meets devices requirements for tx offloads.
2883  *
2884  * - Check limitations about number of segments.
2885  *
2886  * - Check additional requirements when debug is enabled.
2887  *
2888  * - Update and/or reset required checksums when tx offload is set for packet.
2889  *
2890  * Since this function can modify packet data, provided mbufs must be safely
2891  * writable (e.g. modified data cannot be in shared segment).
2892  *
2893  * The rte_eth_tx_prepare() function returns the number of packets ready to be
2894  * sent. A return value equal to *nb_pkts* means that all packets are valid and
2895  * ready to be sent, otherwise stops processing on the first invalid packet and
2896  * leaves the rest packets untouched.
2897  *
2898  * When this functionality is not implemented in the driver, all packets are
2899  * are returned untouched.
2900  *
2901  * @param port_id
2902  *   The port identifier of the Ethernet device.
2903  *   The value must be a valid port id.
2904  * @param queue_id
2905  *   The index of the transmit queue through which output packets must be
2906  *   sent.
2907  *   The value must be in the range [0, nb_tx_queue - 1] previously supplied
2908  *   to rte_eth_dev_configure().
2909  * @param tx_pkts
2910  *   The address of an array of *nb_pkts* pointers to *rte_mbuf* structures
2911  *   which contain the output packets.
2912  * @param nb_pkts
2913  *   The maximum number of packets to process.
2914  * @return
2915  *   The number of packets correct and ready to be sent. The return value can be
2916  *   less than the value of the *tx_pkts* parameter when some packet doesn't
2917  *   meet devices requirements with rte_errno set appropriately:
2918  *   - -EINVAL: offload flags are not correctly set
2919  *   - -ENOTSUP: the offload feature is not supported by the hardware
2920  *
2921  */
2922
2923 #ifndef RTE_ETHDEV_TX_PREPARE_NOOP
2924
2925 static inline uint16_t
2926 rte_eth_tx_prepare(uint8_t port_id, uint16_t queue_id,
2927                 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2928 {
2929         struct rte_eth_dev *dev;
2930
2931 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2932         if (!rte_eth_dev_is_valid_port(port_id)) {
2933                 RTE_PMD_DEBUG_TRACE("Invalid TX port_id=%d\n", port_id);
2934                 rte_errno = -EINVAL;
2935                 return 0;
2936         }
2937 #endif
2938
2939         dev = &rte_eth_devices[port_id];
2940
2941 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2942         if (queue_id >= dev->data->nb_tx_queues) {
2943                 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2944                 rte_errno = -EINVAL;
2945                 return 0;
2946         }
2947 #endif
2948
2949         if (!dev->tx_pkt_prepare)
2950                 return nb_pkts;
2951
2952         return (*dev->tx_pkt_prepare)(dev->data->tx_queues[queue_id],
2953                         tx_pkts, nb_pkts);
2954 }
2955
2956 #else
2957
2958 /*
2959  * Native NOOP operation for compilation targets which doesn't require any
2960  * preparations steps, and functional NOOP may introduce unnecessary performance
2961  * drop.
2962  *
2963  * Generally this is not a good idea to turn it on globally and didn't should
2964  * be used if behavior of tx_preparation can change.
2965  */
2966
2967 static inline uint16_t
2968 rte_eth_tx_prepare(__rte_unused uint8_t port_id, __rte_unused uint16_t queue_id,
2969                 __rte_unused struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2970 {
2971         return nb_pkts;
2972 }
2973
2974 #endif
2975
2976 typedef void (*buffer_tx_error_fn)(struct rte_mbuf **unsent, uint16_t count,
2977                 void *userdata);
2978
2979 /**
2980  * Structure used to buffer packets for future TX
2981  * Used by APIs rte_eth_tx_buffer and rte_eth_tx_buffer_flush
2982  */
2983 struct rte_eth_dev_tx_buffer {
2984         buffer_tx_error_fn error_callback;
2985         void *error_userdata;
2986         uint16_t size;           /**< Size of buffer for buffered tx */
2987         uint16_t length;         /**< Number of packets in the array */
2988         struct rte_mbuf *pkts[];
2989         /**< Pending packets to be sent on explicit flush or when full */
2990 };
2991
2992 /**
2993  * Calculate the size of the tx buffer.
2994  *
2995  * @param sz
2996  *   Number of stored packets.
2997  */
2998 #define RTE_ETH_TX_BUFFER_SIZE(sz) \
2999         (sizeof(struct rte_eth_dev_tx_buffer) + (sz) * sizeof(struct rte_mbuf *))
3000
3001 /**
3002  * Initialize default values for buffered transmitting
3003  *
3004  * @param buffer
3005  *   Tx buffer to be initialized.
3006  * @param size
3007  *   Buffer size
3008  * @return
3009  *   0 if no error
3010  */
3011 int
3012 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size);
3013
3014 /**
3015  * Send any packets queued up for transmission on a port and HW queue
3016  *
3017  * This causes an explicit flush of packets previously buffered via the
3018  * rte_eth_tx_buffer() function. It returns the number of packets successfully
3019  * sent to the NIC, and calls the error callback for any unsent packets. Unless
3020  * explicitly set up otherwise, the default callback simply frees the unsent
3021  * packets back to the owning mempool.
3022  *
3023  * @param port_id
3024  *   The port identifier of the Ethernet device.
3025  * @param queue_id
3026  *   The index of the transmit queue through which output packets must be
3027  *   sent.
3028  *   The value must be in the range [0, nb_tx_queue - 1] previously supplied
3029  *   to rte_eth_dev_configure().
3030  * @param buffer
3031  *   Buffer of packets to be transmit.
3032  * @return
3033  *   The number of packets successfully sent to the Ethernet device. The error
3034  *   callback is called for any packets which could not be sent.
3035  */
3036 static inline uint16_t
3037 rte_eth_tx_buffer_flush(uint8_t port_id, uint16_t queue_id,
3038                 struct rte_eth_dev_tx_buffer *buffer)
3039 {
3040         uint16_t sent;
3041         uint16_t to_send = buffer->length;
3042
3043         if (to_send == 0)
3044                 return 0;
3045
3046         sent = rte_eth_tx_burst(port_id, queue_id, buffer->pkts, to_send);
3047
3048         buffer->length = 0;
3049
3050         /* All packets sent, or to be dealt with by callback below */
3051         if (unlikely(sent != to_send))
3052                 buffer->error_callback(&buffer->pkts[sent], to_send - sent,
3053                                 buffer->error_userdata);
3054
3055         return sent;
3056 }
3057
3058 /**
3059  * Buffer a single packet for future transmission on a port and queue
3060  *
3061  * This function takes a single mbuf/packet and buffers it for later
3062  * transmission on the particular port and queue specified. Once the buffer is
3063  * full of packets, an attempt will be made to transmit all the buffered
3064  * packets. In case of error, where not all packets can be transmitted, a
3065  * callback is called with the unsent packets as a parameter. If no callback
3066  * is explicitly set up, the unsent packets are just freed back to the owning
3067  * mempool. The function returns the number of packets actually sent i.e.
3068  * 0 if no buffer flush occurred, otherwise the number of packets successfully
3069  * flushed
3070  *
3071  * @param port_id
3072  *   The port identifier of the Ethernet device.
3073  * @param queue_id
3074  *   The index of the transmit queue through which output packets must be
3075  *   sent.
3076  *   The value must be in the range [0, nb_tx_queue - 1] previously supplied
3077  *   to rte_eth_dev_configure().
3078  * @param buffer
3079  *   Buffer used to collect packets to be sent.
3080  * @param tx_pkt
3081  *   Pointer to the packet mbuf to be sent.
3082  * @return
3083  *   0 = packet has been buffered for later transmission
3084  *   N > 0 = packet has been buffered, and the buffer was subsequently flushed,
3085  *     causing N packets to be sent, and the error callback to be called for
3086  *     the rest.
3087  */
3088 static inline uint16_t __attribute__((always_inline))
3089 rte_eth_tx_buffer(uint8_t port_id, uint16_t queue_id,
3090                 struct rte_eth_dev_tx_buffer *buffer, struct rte_mbuf *tx_pkt)
3091 {
3092         buffer->pkts[buffer->length++] = tx_pkt;
3093         if (buffer->length < buffer->size)
3094                 return 0;
3095
3096         return rte_eth_tx_buffer_flush(port_id, queue_id, buffer);
3097 }
3098
3099 /**
3100  * Configure a callback for buffered packets which cannot be sent
3101  *
3102  * Register a specific callback to be called when an attempt is made to send
3103  * all packets buffered on an ethernet port, but not all packets can
3104  * successfully be sent. The callback registered here will be called only
3105  * from calls to rte_eth_tx_buffer() and rte_eth_tx_buffer_flush() APIs.
3106  * The default callback configured for each queue by default just frees the
3107  * packets back to the calling mempool. If additional behaviour is required,
3108  * for example, to count dropped packets, or to retry transmission of packets
3109  * which cannot be sent, this function should be used to register a suitable
3110  * callback function to implement the desired behaviour.
3111  * The example callback "rte_eth_count_unsent_packet_callback()" is also
3112  * provided as reference.
3113  *
3114  * @param buffer
3115  *   The port identifier of the Ethernet device.
3116  * @param callback
3117  *   The function to be used as the callback.
3118  * @param userdata
3119  *   Arbitrary parameter to be passed to the callback function
3120  * @return
3121  *   0 on success, or -1 on error with rte_errno set appropriately
3122  */
3123 int
3124 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
3125                 buffer_tx_error_fn callback, void *userdata);
3126
3127 /**
3128  * Callback function for silently dropping unsent buffered packets.
3129  *
3130  * This function can be passed to rte_eth_tx_buffer_set_err_callback() to
3131  * adjust the default behavior when buffered packets cannot be sent. This
3132  * function drops any unsent packets silently and is used by tx buffered
3133  * operations as default behavior.
3134  *
3135  * NOTE: this function should not be called directly, instead it should be used
3136  *       as a callback for packet buffering.
3137  *
3138  * NOTE: when configuring this function as a callback with
3139  *       rte_eth_tx_buffer_set_err_callback(), the final, userdata parameter
3140  *       should point to an uint64_t value.
3141  *
3142  * @param pkts
3143  *   The previously buffered packets which could not be sent
3144  * @param unsent
3145  *   The number of unsent packets in the pkts array
3146  * @param userdata
3147  *   Not used
3148  */
3149 void
3150 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
3151                 void *userdata);
3152
3153 /**
3154  * Callback function for tracking unsent buffered packets.
3155  *
3156  * This function can be passed to rte_eth_tx_buffer_set_err_callback() to
3157  * adjust the default behavior when buffered packets cannot be sent. This
3158  * function drops any unsent packets, but also updates a user-supplied counter
3159  * to track the overall number of packets dropped. The counter should be an
3160  * uint64_t variable.
3161  *
3162  * NOTE: this function should not be called directly, instead it should be used
3163  *       as a callback for packet buffering.
3164  *
3165  * NOTE: when configuring this function as a callback with
3166  *       rte_eth_tx_buffer_set_err_callback(), the final, userdata parameter
3167  *       should point to an uint64_t value.
3168  *
3169  * @param pkts
3170  *   The previously buffered packets which could not be sent
3171  * @param unsent
3172  *   The number of unsent packets in the pkts array
3173  * @param userdata
3174  *   Pointer to an uint64_t value, which will be incremented by unsent
3175  */
3176 void
3177 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
3178                 void *userdata);
3179
3180 /**
3181  * The eth device event type for interrupt, and maybe others in the future.
3182  */
3183 enum rte_eth_event_type {
3184         RTE_ETH_EVENT_UNKNOWN,  /**< unknown event type */
3185         RTE_ETH_EVENT_INTR_LSC, /**< lsc interrupt event */
3186         RTE_ETH_EVENT_QUEUE_STATE,
3187                                 /**< queue state event (enabled/disabled) */
3188         RTE_ETH_EVENT_INTR_RESET,
3189                         /**< reset interrupt event, sent to VF on PF reset */
3190         RTE_ETH_EVENT_VF_MBOX,  /**< message from the VF received by PF */
3191         RTE_ETH_EVENT_MAX       /**< max value of this enum */
3192 };
3193
3194 typedef void (*rte_eth_dev_cb_fn)(uint8_t port_id, \
3195                 enum rte_eth_event_type event, void *cb_arg);
3196 /**< user application callback to be registered for interrupts */
3197
3198
3199
3200 /**
3201  * Register a callback function for specific port id.
3202  *
3203  * @param port_id
3204  *  Port id.
3205  * @param event
3206  *  Event interested.
3207  * @param cb_fn
3208  *  User supplied callback function to be called.
3209  * @param cb_arg
3210  *  Pointer to the parameters for the registered callback.
3211  *
3212  *  The user data is overwritten in the case of RTE_ETH_EVENT_VF_MBOX.
3213  *      This even occurs when a message from the VF is received by the PF.
3214  *      The user data is overwritten with struct rte_pmd_ixgbe_mb_event_param.
3215  *      This struct is defined in rte_pmd_ixgbe.h.
3216  *
3217  * @return
3218  *  - On success, zero.
3219  *  - On failure, a negative value.
3220  */
3221 int rte_eth_dev_callback_register(uint8_t port_id,
3222                         enum rte_eth_event_type event,
3223                 rte_eth_dev_cb_fn cb_fn, void *cb_arg);
3224
3225 /**
3226  * Unregister a callback function for specific port id.
3227  *
3228  * @param port_id
3229  *  Port id.
3230  * @param event
3231  *  Event interested.
3232  * @param cb_fn
3233  *  User supplied callback function to be called.
3234  * @param cb_arg
3235  *  Pointer to the parameters for the registered callback. -1 means to
3236  *  remove all for the same callback address and same event.
3237  *
3238  * @return
3239  *  - On success, zero.
3240  *  - On failure, a negative value.
3241  */
3242 int rte_eth_dev_callback_unregister(uint8_t port_id,
3243                         enum rte_eth_event_type event,
3244                 rte_eth_dev_cb_fn cb_fn, void *cb_arg);
3245
3246 /**
3247  * @internal Executes all the user application registered callbacks for
3248  * the specific device. It is for DPDK internal user only. User
3249  * application should not call it directly.
3250  *
3251  * @param dev
3252  *  Pointer to struct rte_eth_dev.
3253  * @param event
3254  *  Eth device interrupt event type.
3255  * @param cb_arg
3256  *  Update callback parameter to pass data back to user application.
3257  *  This allows the user application to decide if a particular function
3258  *  is permitted or not.
3259  *
3260  * @return
3261  *  void
3262  */
3263 void _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
3264                                 enum rte_eth_event_type event, void *cb_arg);
3265
3266 /**
3267  * When there is no rx packet coming in Rx Queue for a long time, we can
3268  * sleep lcore related to RX Queue for power saving, and enable rx interrupt
3269  * to be triggered when rx packect arrives.
3270  *
3271  * The rte_eth_dev_rx_intr_enable() function enables rx queue
3272  * interrupt on specific rx queue of a port.
3273  *
3274  * @param port_id
3275  *   The port identifier of the Ethernet device.
3276  * @param queue_id
3277  *   The index of the receive queue from which to retrieve input packets.
3278  *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
3279  *   to rte_eth_dev_configure().
3280  * @return
3281  *   - (0) if successful.
3282  *   - (-ENOTSUP) if underlying hardware OR driver doesn't support
3283  *     that operation.
3284  *   - (-ENODEV) if *port_id* invalid.
3285  */
3286 int rte_eth_dev_rx_intr_enable(uint8_t port_id, uint16_t queue_id);
3287
3288 /**
3289  * When lcore wakes up from rx interrupt indicating packet coming, disable rx
3290  * interrupt and returns to polling mode.
3291  *
3292  * The rte_eth_dev_rx_intr_disable() function disables rx queue
3293  * interrupt on specific rx queue of a port.
3294  *
3295  * @param port_id
3296  *   The port identifier of the Ethernet device.
3297  * @param queue_id
3298  *   The index of the receive queue from which to retrieve input packets.
3299  *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
3300  *   to rte_eth_dev_configure().
3301  * @return
3302  *   - (0) if successful.
3303  *   - (-ENOTSUP) if underlying hardware OR driver doesn't support
3304  *     that operation.
3305  *   - (-ENODEV) if *port_id* invalid.
3306  */
3307 int rte_eth_dev_rx_intr_disable(uint8_t port_id, uint16_t queue_id);
3308
3309 /**
3310  * RX Interrupt control per port.
3311  *
3312  * @param port_id
3313  *   The port identifier of the Ethernet device.
3314  * @param epfd
3315  *   Epoll instance fd which the intr vector associated to.
3316  *   Using RTE_EPOLL_PER_THREAD allows to use per thread epoll instance.
3317  * @param op
3318  *   The operation be performed for the vector.
3319  *   Operation type of {RTE_INTR_EVENT_ADD, RTE_INTR_EVENT_DEL}.
3320  * @param data
3321  *   User raw data.
3322  * @return
3323  *   - On success, zero.
3324  *   - On failure, a negative value.
3325  */
3326 int rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data);
3327
3328 /**
3329  * RX Interrupt control per queue.
3330  *
3331  * @param port_id
3332  *   The port identifier of the Ethernet device.
3333  * @param queue_id
3334  *   The index of the receive queue from which to retrieve input packets.
3335  *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
3336  *   to rte_eth_dev_configure().
3337  * @param epfd
3338  *   Epoll instance fd which the intr vector associated to.
3339  *   Using RTE_EPOLL_PER_THREAD allows to use per thread epoll instance.
3340  * @param op
3341  *   The operation be performed for the vector.
3342  *   Operation type of {RTE_INTR_EVENT_ADD, RTE_INTR_EVENT_DEL}.
3343  * @param data
3344  *   User raw data.
3345  * @return
3346  *   - On success, zero.
3347  *   - On failure, a negative value.
3348  */
3349 int rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
3350                               int epfd, int op, void *data);
3351
3352 /**
3353  * Turn on the LED on the Ethernet device.
3354  * This function turns on the LED on the Ethernet device.
3355  *
3356  * @param port_id
3357  *   The port identifier of the Ethernet device.
3358  * @return
3359  *   - (0) if successful.
3360  *   - (-ENOTSUP) if underlying hardware OR driver doesn't support
3361  *     that operation.
3362  *   - (-ENODEV) if *port_id* invalid.
3363  */
3364 int  rte_eth_led_on(uint8_t port_id);
3365
3366 /**
3367  * Turn off the LED on the Ethernet device.
3368  * This function turns off the LED on the Ethernet device.
3369  *
3370  * @param port_id
3371  *   The port identifier of the Ethernet device.
3372  * @return
3373  *   - (0) if successful.
3374  *   - (-ENOTSUP) if underlying hardware OR driver doesn't support
3375  *     that operation.
3376  *   - (-ENODEV) if *port_id* invalid.
3377  */
3378 int  rte_eth_led_off(uint8_t port_id);
3379
3380 /**
3381  * Get current status of the Ethernet link flow control for Ethernet device
3382  *
3383  * @param port_id
3384  *   The port identifier of the Ethernet device.
3385  * @param fc_conf
3386  *   The pointer to the structure where to store the flow control parameters.
3387  * @return
3388  *   - (0) if successful.
3389  *   - (-ENOTSUP) if hardware doesn't support flow control.
3390  *   - (-ENODEV)  if *port_id* invalid.
3391  */
3392 int rte_eth_dev_flow_ctrl_get(uint8_t port_id,
3393                               struct rte_eth_fc_conf *fc_conf);
3394
3395 /**
3396  * Configure the Ethernet link flow control for Ethernet device
3397  *
3398  * @param port_id
3399  *   The port identifier of the Ethernet device.
3400  * @param fc_conf
3401  *   The pointer to the structure of the flow control parameters.
3402  * @return
3403  *   - (0) if successful.
3404  *   - (-ENOTSUP) if hardware doesn't support flow control mode.
3405  *   - (-ENODEV)  if *port_id* invalid.
3406  *   - (-EINVAL)  if bad parameter
3407  *   - (-EIO)     if flow control setup failure
3408  */
3409 int rte_eth_dev_flow_ctrl_set(uint8_t port_id,
3410                               struct rte_eth_fc_conf *fc_conf);
3411
3412 /**
3413  * Configure the Ethernet priority flow control under DCB environment
3414  * for Ethernet device.
3415  *
3416  * @param port_id
3417  * The port identifier of the Ethernet device.
3418  * @param pfc_conf
3419  * The pointer to the structure of the priority flow control parameters.
3420  * @return
3421  *   - (0) if successful.
3422  *   - (-ENOTSUP) if hardware doesn't support priority flow control mode.
3423  *   - (-ENODEV)  if *port_id* invalid.
3424  *   - (-EINVAL)  if bad parameter
3425  *   - (-EIO)     if flow control setup failure
3426  */
3427 int rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id,
3428                                 struct rte_eth_pfc_conf *pfc_conf);
3429
3430 /**
3431  * Add a MAC address to an internal array of addresses used to enable whitelist
3432  * filtering to accept packets only if the destination MAC address matches.
3433  *
3434  * @param port
3435  *   The port identifier of the Ethernet device.
3436  * @param mac_addr
3437  *   The MAC address to add.
3438  * @param pool
3439  *   VMDq pool index to associate address with (if VMDq is enabled). If VMDq is
3440  *   not enabled, this should be set to 0.
3441  * @return
3442  *   - (0) if successfully added or *mac_addr" was already added.
3443  *   - (-ENOTSUP) if hardware doesn't support this feature.
3444  *   - (-ENODEV) if *port* is invalid.
3445  *   - (-ENOSPC) if no more MAC addresses can be added.
3446  *   - (-EINVAL) if MAC address is invalid.
3447  */
3448 int rte_eth_dev_mac_addr_add(uint8_t port, struct ether_addr *mac_addr,
3449                                 uint32_t pool);
3450
3451 /**
3452  * Remove a MAC address from the internal array of addresses.
3453  *
3454  * @param port
3455  *   The port identifier of the Ethernet device.
3456  * @param mac_addr
3457  *   MAC address to remove.
3458  * @return
3459  *   - (0) if successful, or *mac_addr* didn't exist.
3460  *   - (-ENOTSUP) if hardware doesn't support.
3461  *   - (-ENODEV) if *port* invalid.
3462  *   - (-EADDRINUSE) if attempting to remove the default MAC address
3463  */
3464 int rte_eth_dev_mac_addr_remove(uint8_t port, struct ether_addr *mac_addr);
3465
3466 /**
3467  * Set the default MAC address.
3468  *
3469  * @param port
3470  *   The port identifier of the Ethernet device.
3471  * @param mac_addr
3472  *   New default MAC address.
3473  * @return
3474  *   - (0) if successful, or *mac_addr* didn't exist.
3475  *   - (-ENOTSUP) if hardware doesn't support.
3476  *   - (-ENODEV) if *port* invalid.
3477  *   - (-EINVAL) if MAC address is invalid.
3478  */
3479 int rte_eth_dev_default_mac_addr_set(uint8_t port, struct ether_addr *mac_addr);
3480
3481
3482 /**
3483  * Update Redirection Table(RETA) of Receive Side Scaling of Ethernet device.
3484  *
3485  * @param port
3486  *   The port identifier of the Ethernet device.
3487  * @param reta_conf
3488  *   RETA to update.
3489  * @param reta_size
3490  *   Redirection table size. The table size can be queried by
3491  *   rte_eth_dev_info_get().
3492  * @return
3493  *   - (0) if successful.
3494  *   - (-ENOTSUP) if hardware doesn't support.
3495  *   - (-EINVAL) if bad parameter.
3496  */
3497 int rte_eth_dev_rss_reta_update(uint8_t port,
3498                                 struct rte_eth_rss_reta_entry64 *reta_conf,
3499                                 uint16_t reta_size);
3500
3501  /**
3502  * Query Redirection Table(RETA) of Receive Side Scaling of Ethernet device.
3503  *
3504  * @param port
3505  *   The port identifier of the Ethernet device.
3506  * @param reta_conf
3507  *   RETA to query.
3508  * @param reta_size
3509  *   Redirection table size. The table size can be queried by
3510  *   rte_eth_dev_info_get().
3511  * @return
3512  *   - (0) if successful.
3513  *   - (-ENOTSUP) if hardware doesn't support.
3514  *   - (-EINVAL) if bad parameter.
3515  */
3516 int rte_eth_dev_rss_reta_query(uint8_t port,
3517                                struct rte_eth_rss_reta_entry64 *reta_conf,
3518                                uint16_t reta_size);
3519
3520  /**
3521  * Updates unicast hash table for receiving packet with the given destination
3522  * MAC address, and the packet is routed to all VFs for which the RX mode is
3523  * accept packets that match the unicast hash table.
3524  *
3525  * @param port
3526  *   The port identifier of the Ethernet device.
3527  * @param addr
3528  *   Unicast MAC address.
3529  * @param on
3530  *    1 - Set an unicast hash bit for receiving packets with the MAC address.
3531  *    0 - Clear an unicast hash bit.
3532  * @return
3533  *   - (0) if successful.
3534  *   - (-ENOTSUP) if hardware doesn't support.
3535   *  - (-ENODEV) if *port_id* invalid.
3536  *   - (-EINVAL) if bad parameter.
3537  */
3538 int rte_eth_dev_uc_hash_table_set(uint8_t port,struct ether_addr *addr,
3539                                         uint8_t on);
3540
3541  /**
3542  * Updates all unicast hash bitmaps for receiving packet with any Unicast
3543  * Ethernet MAC addresses,the packet is routed to all VFs for which the RX
3544  * mode is accept packets that match the unicast hash table.
3545  *
3546  * @param port
3547  *   The port identifier of the Ethernet device.
3548  * @param on
3549  *    1 - Set all unicast hash bitmaps for receiving all the Ethernet
3550  *         MAC addresses
3551  *    0 - Clear all unicast hash bitmaps
3552  * @return
3553  *   - (0) if successful.
3554  *   - (-ENOTSUP) if hardware doesn't support.
3555   *  - (-ENODEV) if *port_id* invalid.
3556  *   - (-EINVAL) if bad parameter.
3557  */
3558 int rte_eth_dev_uc_all_hash_table_set(uint8_t port,uint8_t on);
3559
3560  /**
3561  * Set RX L2 Filtering mode of a VF of an Ethernet device.
3562  *
3563  * @param port
3564  *   The port identifier of the Ethernet device.
3565  * @param vf
3566  *   VF id.
3567  * @param rx_mode
3568  *    The RX mode mask, which  is one or more of  accepting Untagged Packets,
3569  *    packets that match the PFUTA table, Broadcast and Multicast Promiscuous.
3570  *    ETH_VMDQ_ACCEPT_UNTAG,ETH_VMDQ_ACCEPT_HASH_UC,
3571  *    ETH_VMDQ_ACCEPT_BROADCAST and ETH_VMDQ_ACCEPT_MULTICAST will be used
3572  *    in rx_mode.
3573  * @param on
3574  *    1 - Enable a VF RX mode.
3575  *    0 - Disable a VF RX mode.
3576  * @return
3577  *   - (0) if successful.
3578  *   - (-ENOTSUP) if hardware doesn't support.
3579  *   - (-ENOTSUP) if hardware doesn't support.
3580  *   - (-EINVAL) if bad parameter.
3581  */
3582 int rte_eth_dev_set_vf_rxmode(uint8_t port, uint16_t vf, uint16_t rx_mode,
3583                                 uint8_t on);
3584
3585 /**
3586 * Enable or disable a VF traffic transmit of the Ethernet device.
3587 *
3588 * @param port
3589 *   The port identifier of the Ethernet device.
3590 * @param vf
3591 *   VF id.
3592 * @param on
3593 *    1 - Enable a VF traffic transmit.
3594 *    0 - Disable a VF traffic transmit.
3595 * @return
3596 *   - (0) if successful.
3597 *   - (-ENODEV) if *port_id* invalid.
3598 *   - (-ENOTSUP) if hardware doesn't support.
3599 *   - (-EINVAL) if bad parameter.
3600 */
3601 int
3602 rte_eth_dev_set_vf_tx(uint8_t port,uint16_t vf, uint8_t on);
3603
3604 /**
3605 * Enable or disable a VF traffic receive of an Ethernet device.
3606 *
3607 * @param port
3608 *   The port identifier of the Ethernet device.
3609 * @param vf
3610 *   VF id.
3611 * @param on
3612 *    1 - Enable a VF traffic receive.
3613 *    0 - Disable a VF traffic receive.
3614 * @return
3615 *   - (0) if successful.
3616 *   - (-ENOTSUP) if hardware doesn't support.
3617 *   - (-ENODEV) if *port_id* invalid.
3618 *   - (-EINVAL) if bad parameter.
3619 */
3620 int
3621 rte_eth_dev_set_vf_rx(uint8_t port,uint16_t vf, uint8_t on);
3622
3623 /**
3624 * Enable/Disable hardware VF VLAN filtering by an Ethernet device of
3625 * received VLAN packets tagged with a given VLAN Tag Identifier.
3626 *
3627 * @param port id
3628 *   The port identifier of the Ethernet device.
3629 * @param vlan_id
3630 *   The VLAN Tag Identifier whose filtering must be enabled or disabled.
3631 * @param vf_mask
3632 *    Bitmap listing which VFs participate in the VLAN filtering.
3633 * @param vlan_on
3634 *    1 - Enable VFs VLAN filtering.
3635 *    0 - Disable VFs VLAN filtering.
3636 * @return
3637 *   - (0) if successful.
3638 *   - (-ENOTSUP) if hardware doesn't support.
3639 *   - (-ENODEV) if *port_id* invalid.
3640 *   - (-EINVAL) if bad parameter.
3641 */
3642 int
3643 rte_eth_dev_set_vf_vlan_filter(uint8_t port, uint16_t vlan_id,
3644                                 uint64_t vf_mask,
3645                                 uint8_t vlan_on);
3646
3647 /**
3648  * Set a traffic mirroring rule on an Ethernet device
3649  *
3650  * @param port_id
3651  *   The port identifier of the Ethernet device.
3652  * @param mirror_conf
3653  *   The pointer to the traffic mirroring structure describing the mirroring rule.
3654  *   The *rte_eth_vm_mirror_conf* structure includes the type of mirroring rule,
3655  *   destination pool and the value of rule if enable vlan or pool mirroring.
3656  *
3657  * @param rule_id
3658  *   The index of traffic mirroring rule, we support four separated rules.
3659  * @param on
3660  *   1 - Enable a mirroring rule.
3661  *   0 - Disable a mirroring rule.
3662  * @return
3663  *   - (0) if successful.
3664  *   - (-ENOTSUP) if hardware doesn't support this feature.
3665  *   - (-ENODEV) if *port_id* invalid.
3666  *   - (-EINVAL) if the mr_conf information is not correct.
3667  */
3668 int rte_eth_mirror_rule_set(uint8_t port_id,
3669                         struct rte_eth_mirror_conf *mirror_conf,
3670                         uint8_t rule_id,
3671                         uint8_t on);
3672
3673 /**
3674  * Reset a traffic mirroring rule on an Ethernet device.
3675  *
3676  * @param port_id
3677  *   The port identifier of the Ethernet device.
3678  * @param rule_id
3679  *   The index of traffic mirroring rule, we support four separated rules.
3680  * @return
3681  *   - (0) if successful.
3682  *   - (-ENOTSUP) if hardware doesn't support this feature.
3683  *   - (-ENODEV) if *port_id* invalid.
3684  *   - (-EINVAL) if bad parameter.
3685  */
3686 int rte_eth_mirror_rule_reset(uint8_t port_id,
3687                                          uint8_t rule_id);
3688
3689 /**
3690  * Set the rate limitation for a queue on an Ethernet device.
3691  *
3692  * @param port_id
3693  *   The port identifier of the Ethernet device.
3694  * @param queue_idx
3695  *   The queue id.
3696  * @param tx_rate
3697  *   The tx rate in Mbps. Allocated from the total port link speed.
3698  * @return
3699  *   - (0) if successful.
3700  *   - (-ENOTSUP) if hardware doesn't support this feature.
3701  *   - (-ENODEV) if *port_id* invalid.
3702  *   - (-EINVAL) if bad parameter.
3703  */
3704 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
3705                         uint16_t tx_rate);
3706
3707 /**
3708  * Set the rate limitation for a vf on an Ethernet device.
3709  *
3710  * @param port_id
3711  *   The port identifier of the Ethernet device.
3712  * @param vf
3713  *   VF id.
3714  * @param tx_rate
3715  *   The tx rate allocated from the total link speed for this VF id.
3716  * @param q_msk
3717  *   The queue mask which need to set the rate.
3718  * @return
3719  *   - (0) if successful.
3720  *   - (-ENOTSUP) if hardware doesn't support this feature.
3721  *   - (-ENODEV) if *port_id* invalid.
3722  *   - (-EINVAL) if bad parameter.
3723  */
3724 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf,
3725                         uint16_t tx_rate, uint64_t q_msk);
3726
3727 /**
3728  * Initialize bypass logic. This function needs to be called before
3729  * executing any other bypass API.
3730  *
3731  * @param port
3732  *   The port identifier of the Ethernet device.
3733  * @return
3734  *   - (0) if successful.
3735  *   - (-ENOTSUP) if hardware doesn't support.
3736  *   - (-EINVAL) if bad parameter.
3737  */
3738 int rte_eth_dev_bypass_init(uint8_t port);
3739
3740 /**
3741  * Return bypass state.
3742  *
3743  * @param port
3744  *   The port identifier of the Ethernet device.
3745  * @param state
3746  *   The return bypass state.
3747  *   - (1) Normal mode
3748  *   - (2) Bypass mode
3749  *   - (3) Isolate mode
3750  * @return
3751  *   - (0) if successful.
3752  *   - (-ENOTSUP) if hardware doesn't support.
3753  *   - (-EINVAL) if bad parameter.
3754  */
3755 int rte_eth_dev_bypass_state_show(uint8_t port, uint32_t *state);
3756
3757 /**
3758  * Set bypass state
3759  *
3760  * @param port
3761  *   The port identifier of the Ethernet device.
3762  * @param new_state
3763  *   The current bypass state.
3764  *   - (1) Normal mode
3765  *   - (2) Bypass mode
3766  *   - (3) Isolate mode
3767  * @return
3768  *   - (0) if successful.
3769  *   - (-ENOTSUP) if hardware doesn't support.
3770  *   - (-EINVAL) if bad parameter.
3771  */
3772 int rte_eth_dev_bypass_state_set(uint8_t port, uint32_t *new_state);
3773
3774 /**
3775  * Return bypass state when given event occurs.
3776  *
3777  * @param port
3778  *   The port identifier of the Ethernet device.
3779  * @param event
3780  *   The bypass event
3781  *   - (1) Main power on (power button is pushed)
3782  *   - (2) Auxiliary power on (power supply is being plugged)
3783  *   - (3) Main power off (system shutdown and power supply is left plugged in)
3784  *   - (4) Auxiliary power off (power supply is being unplugged)
3785  *   - (5) Display or set the watchdog timer
3786  * @param state
3787  *   The bypass state when given event occurred.
3788  *   - (1) Normal mode
3789  *   - (2) Bypass mode
3790  *   - (3) Isolate mode
3791  * @return
3792  *   - (0) if successful.
3793  *   - (-ENOTSUP) if hardware doesn't support.
3794  *   - (-EINVAL) if bad parameter.
3795  */
3796 int rte_eth_dev_bypass_event_show(uint8_t port, uint32_t event, uint32_t *state);
3797
3798 /**
3799  * Set bypass state when given event occurs.
3800  *
3801  * @param port
3802  *   The port identifier of the Ethernet device.
3803  * @param event
3804  *   The bypass event
3805  *   - (1) Main power on (power button is pushed)
3806  *   - (2) Auxiliary power on (power supply is being plugged)
3807  *   - (3) Main power off (system shutdown and power supply is left plugged in)
3808  *   - (4) Auxiliary power off (power supply is being unplugged)
3809  *   - (5) Display or set the watchdog timer
3810  * @param state
3811  *   The assigned state when given event occurs.
3812  *   - (1) Normal mode
3813  *   - (2) Bypass mode
3814  *   - (3) Isolate mode
3815  * @return
3816  *   - (0) if successful.
3817  *   - (-ENOTSUP) if hardware doesn't support.
3818  *   - (-EINVAL) if bad parameter.
3819  */
3820 int rte_eth_dev_bypass_event_store(uint8_t port, uint32_t event, uint32_t state);
3821
3822 /**
3823  * Set bypass watchdog timeout count.
3824  *
3825  * @param port
3826  *   The port identifier of the Ethernet device.
3827  * @param timeout
3828  *   The timeout to be set.
3829  *   - (0) 0 seconds (timer is off)
3830  *   - (1) 1.5 seconds
3831  *   - (2) 2 seconds
3832  *   - (3) 3 seconds
3833  *   - (4) 4 seconds
3834  *   - (5) 8 seconds
3835  *   - (6) 16 seconds
3836  *   - (7) 32 seconds
3837  * @return
3838  *   - (0) if successful.
3839  *   - (-ENOTSUP) if hardware doesn't support.
3840  *   - (-EINVAL) if bad parameter.
3841  */
3842 int rte_eth_dev_wd_timeout_store(uint8_t port, uint32_t timeout);
3843
3844 /**
3845  * Get bypass firmware version.
3846  *
3847  * @param port
3848  *   The port identifier of the Ethernet device.
3849  * @param ver
3850  *   The firmware version
3851  * @return
3852  *   - (0) if successful.
3853  *   - (-ENOTSUP) if hardware doesn't support.
3854  *   - (-EINVAL) if bad parameter.
3855  */
3856 int rte_eth_dev_bypass_ver_show(uint8_t port, uint32_t *ver);
3857
3858 /**
3859  * Return bypass watchdog timeout in seconds
3860  *
3861  * @param port
3862  *   The port identifier of the Ethernet device.
3863  * @param wd_timeout
3864  *   The return watchdog timeout. "0" represents timer expired
3865  *   - (0) 0 seconds (timer is off)
3866  *   - (1) 1.5 seconds
3867  *   - (2) 2 seconds
3868  *   - (3) 3 seconds
3869  *   - (4) 4 seconds
3870  *   - (5) 8 seconds
3871  *   - (6) 16 seconds
3872  *   - (7) 32 seconds
3873  * @return
3874  *   - (0) if successful.
3875  *   - (-ENOTSUP) if hardware doesn't support.
3876  *   - (-EINVAL) if bad parameter.
3877  */
3878 int rte_eth_dev_bypass_wd_timeout_show(uint8_t port, uint32_t *wd_timeout);
3879
3880 /**
3881  * Reset bypass watchdog timer
3882  *
3883  * @param port
3884  *   The port identifier of the Ethernet device.
3885  * @return
3886  *   - (0) if successful.
3887  *   - (-ENOTSUP) if hardware doesn't support.
3888  *   - (-EINVAL) if bad parameter.
3889  */
3890 int rte_eth_dev_bypass_wd_reset(uint8_t port);
3891
3892  /**
3893  * Configuration of Receive Side Scaling hash computation of Ethernet device.
3894  *
3895  * @param port_id
3896  *   The port identifier of the Ethernet device.
3897  * @param rss_conf
3898  *   The new configuration to use for RSS hash computation on the port.
3899  * @return
3900  *   - (0) if successful.
3901  *   - (-ENODEV) if port identifier is invalid.
3902  *   - (-ENOTSUP) if hardware doesn't support.
3903  *   - (-EINVAL) if bad parameter.
3904  */
3905 int rte_eth_dev_rss_hash_update(uint8_t port_id,
3906                                 struct rte_eth_rss_conf *rss_conf);
3907
3908  /**
3909  * Retrieve current configuration of Receive Side Scaling hash computation
3910  * of Ethernet device.
3911  *
3912  * @param port_id
3913  *   The port identifier of the Ethernet device.
3914  * @param rss_conf
3915  *   Where to store the current RSS hash configuration of the Ethernet device.
3916  * @return
3917  *   - (0) if successful.
3918  *   - (-ENODEV) if port identifier is invalid.
3919  *   - (-ENOTSUP) if hardware doesn't support RSS.
3920  */
3921 int
3922 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
3923                               struct rte_eth_rss_conf *rss_conf);
3924
3925  /**
3926  * Add UDP tunneling port for a specific type of tunnel.
3927  * The packets with this UDP port will be identified as this type of tunnel.
3928  * Before enabling any offloading function for a tunnel, users can call this API
3929  * to change or add more UDP port for the tunnel. So the offloading function
3930  * can take effect on the packets with the sepcific UDP port.
3931  *
3932  * @param port_id
3933  *   The port identifier of the Ethernet device.
3934  * @param tunnel_udp
3935  *   UDP tunneling configuration.
3936  *
3937  * @return
3938  *   - (0) if successful.
3939  *   - (-ENODEV) if port identifier is invalid.
3940  *   - (-ENOTSUP) if hardware doesn't support tunnel type.
3941  */
3942 int
3943 rte_eth_dev_udp_tunnel_port_add(uint8_t port_id,
3944                                 struct rte_eth_udp_tunnel *tunnel_udp);
3945
3946  /**
3947  * Delete UDP tunneling port a specific type of tunnel.
3948  * The packets with this UDP port will not be identified as this type of tunnel
3949  * any more.
3950  * Before enabling any offloading function for a tunnel, users can call this API
3951  * to delete a UDP port for the tunnel. So the offloading function will not take
3952  * effect on the packets with the sepcific UDP port.
3953  *
3954  * @param port_id
3955  *   The port identifier of the Ethernet device.
3956  * @param tunnel_udp
3957  *   UDP tunneling configuration.
3958  *
3959  * @return
3960  *   - (0) if successful.
3961  *   - (-ENODEV) if port identifier is invalid.
3962  *   - (-ENOTSUP) if hardware doesn't support tunnel type.
3963  */
3964 int
3965 rte_eth_dev_udp_tunnel_port_delete(uint8_t port_id,
3966                                    struct rte_eth_udp_tunnel *tunnel_udp);
3967
3968 /**
3969  * Check whether the filter type is supported on an Ethernet device.
3970  * All the supported filter types are defined in 'rte_eth_ctrl.h'.
3971  *
3972  * @param port_id
3973  *   The port identifier of the Ethernet device.
3974  * @param filter_type
3975  *   Filter type.
3976  * @return
3977  *   - (0) if successful.
3978  *   - (-ENOTSUP) if hardware doesn't support this filter type.
3979  *   - (-ENODEV) if *port_id* invalid.
3980  */
3981 int rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type);
3982
3983 /**
3984  * Take operations to assigned filter type on an Ethernet device.
3985  * All the supported operations and filter types are defined in 'rte_eth_ctrl.h'.
3986  *
3987  * @param port_id
3988  *   The port identifier of the Ethernet device.
3989  * @param filter_type
3990  *   Filter type.
3991  * @param filter_op
3992  *   Type of operation.
3993  * @param arg
3994  *   A pointer to arguments defined specifically for the operation.
3995  * @return
3996  *   - (0) if successful.
3997  *   - (-ENOTSUP) if hardware doesn't support.
3998  *   - (-ENODEV) if *port_id* invalid.
3999  *   - others depends on the specific operations implementation.
4000  */
4001 int rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
4002                         enum rte_filter_op filter_op, void *arg);
4003
4004 /**
4005  * Get DCB information on an Ethernet device.
4006  *
4007  * @param port_id
4008  *   The port identifier of the Ethernet device.
4009  * @param dcb_info
4010  *   dcb information.
4011  * @return
4012  *   - (0) if successful.
4013  *   - (-ENODEV) if port identifier is invalid.
4014  *   - (-ENOTSUP) if hardware doesn't support.
4015  */
4016 int rte_eth_dev_get_dcb_info(uint8_t port_id,
4017                              struct rte_eth_dcb_info *dcb_info);
4018
4019 /**
4020  * Add a callback to be called on packet RX on a given port and queue.
4021  *
4022  * This API configures a function to be called for each burst of
4023  * packets received on a given NIC port queue. The return value is a pointer
4024  * that can be used to later remove the callback using
4025  * rte_eth_remove_rx_callback().
4026  *
4027  * Multiple functions are called in the order that they are added.
4028  *
4029  * @param port_id
4030  *   The port identifier of the Ethernet device.
4031  * @param queue_id
4032  *   The queue on the Ethernet device on which the callback is to be added.
4033  * @param fn
4034  *   The callback function
4035  * @param user_param
4036  *   A generic pointer parameter which will be passed to each invocation of the
4037  *   callback function on this port and queue.
4038  *
4039  * @return
4040  *   NULL on error.
4041  *   On success, a pointer value which can later be used to remove the callback.
4042  */
4043 void *rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
4044                 rte_rx_callback_fn fn, void *user_param);
4045
4046 /*
4047 * Add a callback that must be called first on packet RX on a given port
4048 * and queue.
4049 *
4050 * This API configures a first function to be called for each burst of
4051 * packets received on a given NIC port queue. The return value is a pointer
4052 * that can be used to later remove the callback using
4053 * rte_eth_remove_rx_callback().
4054 *
4055 * Multiple functions are called in the order that they are added.
4056 *
4057 * @param port_id
4058 *   The port identifier of the Ethernet device.
4059 * @param queue_id
4060 *   The queue on the Ethernet device on which the callback is to be added.
4061 * @param fn
4062 *   The callback function
4063 * @param user_param
4064 *   A generic pointer parameter which will be passed to each invocation of the
4065 *   callback function on this port and queue.
4066 *
4067 * @return
4068 *   NULL on error.
4069 *   On success, a pointer value which can later be used to remove the callback.
4070 */
4071 void *rte_eth_add_first_rx_callback(uint8_t port_id, uint16_t queue_id,
4072                 rte_rx_callback_fn fn, void *user_param);
4073
4074 /**
4075  * Add a callback to be called on packet TX on a given port and queue.
4076  *
4077  * This API configures a function to be called for each burst of
4078  * packets sent on a given NIC port queue. The return value is a pointer
4079  * that can be used to later remove the callback using
4080  * rte_eth_remove_tx_callback().
4081  *
4082  * Multiple functions are called in the order that they are added.
4083  *
4084  * @param port_id
4085  *   The port identifier of the Ethernet device.
4086  * @param queue_id
4087  *   The queue on the Ethernet device on which the callback is to be added.
4088  * @param fn
4089  *   The callback function
4090  * @param user_param
4091  *   A generic pointer parameter which will be passed to each invocation of the
4092  *   callback function on this port and queue.
4093  *
4094  * @return
4095  *   NULL on error.
4096  *   On success, a pointer value which can later be used to remove the callback.
4097  */
4098 void *rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
4099                 rte_tx_callback_fn fn, void *user_param);
4100
4101 /**
4102  * Remove an RX packet callback from a given port and queue.
4103  *
4104  * This function is used to removed callbacks that were added to a NIC port
4105  * queue using rte_eth_add_rx_callback().
4106  *
4107  * Note: the callback is removed from the callback list but it isn't freed
4108  * since the it may still be in use. The memory for the callback can be
4109  * subsequently freed back by the application by calling rte_free():
4110  *
4111  * - Immediately - if the port is stopped, or the user knows that no
4112  *   callbacks are in flight e.g. if called from the thread doing RX/TX
4113  *   on that queue.
4114  *
4115  * - After a short delay - where the delay is sufficient to allow any
4116  *   in-flight callbacks to complete.
4117  *
4118  * @param port_id
4119  *   The port identifier of the Ethernet device.
4120  * @param queue_id
4121  *   The queue on the Ethernet device from which the callback is to be removed.
4122  * @param user_cb
4123  *   User supplied callback created via rte_eth_add_rx_callback().
4124  *
4125  * @return
4126  *   - 0: Success. Callback was removed.
4127  *   - -ENOTSUP: Callback support is not available.
4128  *   - -EINVAL:  The port_id or the queue_id is out of range, or the callback
4129  *               is NULL or not found for the port/queue.
4130  */
4131 int rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
4132                 struct rte_eth_rxtx_callback *user_cb);
4133
4134 /**
4135  * Remove a TX packet callback from a given port and queue.
4136  *
4137  * This function is used to removed callbacks that were added to a NIC port
4138  * queue using rte_eth_add_tx_callback().
4139  *
4140  * Note: the callback is removed from the callback list but it isn't freed
4141  * since the it may still be in use. The memory for the callback can be
4142  * subsequently freed back by the application by calling rte_free():
4143  *
4144  * - Immediately - if the port is stopped, or the user knows that no
4145  *   callbacks are in flight e.g. if called from the thread doing RX/TX
4146  *   on that queue.
4147  *
4148  * - After a short delay - where the delay is sufficient to allow any
4149  *   in-flight callbacks to complete.
4150  *
4151  * @param port_id
4152  *   The port identifier of the Ethernet device.
4153  * @param queue_id
4154  *   The queue on the Ethernet device from which the callback is to be removed.
4155  * @param user_cb
4156  *   User supplied callback created via rte_eth_add_tx_callback().
4157  *
4158  * @return
4159  *   - 0: Success. Callback was removed.
4160  *   - -ENOTSUP: Callback support is not available.
4161  *   - -EINVAL:  The port_id or the queue_id is out of range, or the callback
4162  *               is NULL or not found for the port/queue.
4163  */
4164 int rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
4165                 struct rte_eth_rxtx_callback *user_cb);
4166
4167 /**
4168  * Retrieve information about given port's RX queue.
4169  *
4170  * @param port_id
4171  *   The port identifier of the Ethernet device.
4172  * @param queue_id
4173  *   The RX queue on the Ethernet device for which information
4174  *   will be retrieved.
4175  * @param qinfo
4176  *   A pointer to a structure of type *rte_eth_rxq_info_info* to be filled with
4177  *   the information of the Ethernet device.
4178  *
4179  * @return
4180  *   - 0: Success
4181  *   - -ENOTSUP: routine is not supported by the device PMD.
4182  *   - -EINVAL:  The port_id or the queue_id is out of range.
4183  */
4184 int rte_eth_rx_queue_info_get(uint8_t port_id, uint16_t queue_id,
4185         struct rte_eth_rxq_info *qinfo);
4186
4187 /**
4188  * Retrieve information about given port's TX queue.
4189  *
4190  * @param port_id
4191  *   The port identifier of the Ethernet device.
4192  * @param queue_id
4193  *   The TX queue on the Ethernet device for which information
4194  *   will be retrieved.
4195  * @param qinfo
4196  *   A pointer to a structure of type *rte_eth_txq_info_info* to be filled with
4197  *   the information of the Ethernet device.
4198  *
4199  * @return
4200  *   - 0: Success
4201  *   - -ENOTSUP: routine is not supported by the device PMD.
4202  *   - -EINVAL:  The port_id or the queue_id is out of range.
4203  */
4204 int rte_eth_tx_queue_info_get(uint8_t port_id, uint16_t queue_id,
4205         struct rte_eth_txq_info *qinfo);
4206
4207 /**
4208  * Retrieve device registers and register attributes (number of registers and
4209  * register size)
4210  *
4211  * @param port_id
4212  *   The port identifier of the Ethernet device.
4213  * @param info
4214  *   Pointer to rte_dev_reg_info structure to fill in. If info->data is
4215  *   NULL the function fills in the width and length fields. If non-NULL
4216  *   the registers are put into the buffer pointed at by the data field.
4217  * @return
4218  *   - (0) if successful.
4219  *   - (-ENOTSUP) if hardware doesn't support.
4220  *   - (-ENODEV) if *port_id* invalid.
4221  *   - others depends on the specific operations implementation.
4222  */
4223 int rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info);
4224
4225 /**
4226  * Retrieve size of device EEPROM
4227  *
4228  * @param port_id
4229  *   The port identifier of the Ethernet device.
4230  * @return
4231  *   - (>=0) EEPROM size if successful.
4232  *   - (-ENOTSUP) if hardware doesn't support.
4233  *   - (-ENODEV) if *port_id* invalid.
4234  *   - others depends on the specific operations implementation.
4235  */
4236 int rte_eth_dev_get_eeprom_length(uint8_t port_id);
4237
4238 /**
4239  * Retrieve EEPROM and EEPROM attribute
4240  *
4241  * @param port_id
4242  *   The port identifier of the Ethernet device.
4243  * @param info
4244  *   The template includes buffer for return EEPROM data and
4245  *   EEPROM attributes to be filled.
4246  * @return
4247  *   - (0) if successful.
4248  *   - (-ENOTSUP) if hardware doesn't support.
4249  *   - (-ENODEV) if *port_id* invalid.
4250  *   - others depends on the specific operations implementation.
4251  */
4252 int rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info);
4253
4254 /**
4255  * Program EEPROM with provided data
4256  *
4257  * @param port_id
4258  *   The port identifier of the Ethernet device.
4259  * @param info
4260  *   The template includes EEPROM data for programming and
4261  *   EEPROM attributes to be filled
4262  * @return
4263  *   - (0) if successful.
4264  *   - (-ENOTSUP) if hardware doesn't support.
4265  *   - (-ENODEV) if *port_id* invalid.
4266  *   - others depends on the specific operations implementation.
4267  */
4268 int rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info);
4269
4270 /**
4271  * Set the list of multicast addresses to filter on an Ethernet device.
4272  *
4273  * @param port_id
4274  *   The port identifier of the Ethernet device.
4275  * @param mc_addr_set
4276  *   The array of multicast addresses to set. Equal to NULL when the function
4277  *   is invoked to flush the set of filtered addresses.
4278  * @param nb_mc_addr
4279  *   The number of multicast addresses in the *mc_addr_set* array. Equal to 0
4280  *   when the function is invoked to flush the set of filtered addresses.
4281  * @return
4282  *   - (0) if successful.
4283  *   - (-ENODEV) if *port_id* invalid.
4284  *   - (-ENOTSUP) if PMD of *port_id* doesn't support multicast filtering.
4285  *   - (-ENOSPC) if *port_id* has not enough multicast filtering resources.
4286  */
4287 int rte_eth_dev_set_mc_addr_list(uint8_t port_id,
4288                                  struct ether_addr *mc_addr_set,
4289                                  uint32_t nb_mc_addr);
4290
4291 /**
4292  * Enable IEEE1588/802.1AS timestamping for an Ethernet device.
4293  *
4294  * @param port_id
4295  *   The port identifier of the Ethernet device.
4296  *
4297  * @return
4298  *   - 0: Success.
4299  *   - -ENODEV: The port ID is invalid.
4300  *   - -ENOTSUP: The function is not supported by the Ethernet driver.
4301  */
4302 int rte_eth_timesync_enable(uint8_t port_id);
4303
4304 /**
4305  * Disable IEEE1588/802.1AS timestamping for an Ethernet device.
4306  *
4307  * @param port_id
4308  *   The port identifier of the Ethernet device.
4309  *
4310  * @return
4311  *   - 0: Success.
4312  *   - -ENODEV: The port ID is invalid.
4313  *   - -ENOTSUP: The function is not supported by the Ethernet driver.
4314  */
4315 int rte_eth_timesync_disable(uint8_t port_id);
4316
4317 /**
4318  * Read an IEEE1588/802.1AS RX timestamp from an Ethernet device.
4319  *
4320  * @param port_id
4321  *   The port identifier of the Ethernet device.
4322  * @param timestamp
4323  *   Pointer to the timestamp struct.
4324  * @param flags
4325  *   Device specific flags. Used to pass the RX timesync register index to
4326  *   i40e. Unused in igb/ixgbe, pass 0 instead.
4327  *
4328  * @return
4329  *   - 0: Success.
4330  *   - -EINVAL: No timestamp is available.
4331  *   - -ENODEV: The port ID is invalid.
4332  *   - -ENOTSUP: The function is not supported by the Ethernet driver.
4333  */
4334 int rte_eth_timesync_read_rx_timestamp(uint8_t port_id,
4335                 struct timespec *timestamp, uint32_t flags);
4336
4337 /**
4338  * Read an IEEE1588/802.1AS TX timestamp from an Ethernet device.
4339  *
4340  * @param port_id
4341  *   The port identifier of the Ethernet device.
4342  * @param timestamp
4343  *   Pointer to the timestamp struct.
4344  *
4345  * @return
4346  *   - 0: Success.
4347  *   - -EINVAL: No timestamp is available.
4348  *   - -ENODEV: The port ID is invalid.
4349  *   - -ENOTSUP: The function is not supported by the Ethernet driver.
4350  */
4351 int rte_eth_timesync_read_tx_timestamp(uint8_t port_id,
4352                 struct timespec *timestamp);
4353
4354 /**
4355  * Adjust the timesync clock on an Ethernet device.
4356  *
4357  * This is usually used in conjunction with other Ethdev timesync functions to
4358  * synchronize the device time using the IEEE1588/802.1AS protocol.
4359  *
4360  * @param port_id
4361  *   The port identifier of the Ethernet device.
4362  * @param delta
4363  *   The adjustment in nanoseconds.
4364  *
4365  * @return
4366  *   - 0: Success.
4367  *   - -ENODEV: The port ID is invalid.
4368  *   - -ENOTSUP: The function is not supported by the Ethernet driver.
4369  */
4370 int rte_eth_timesync_adjust_time(uint8_t port_id, int64_t delta);
4371
4372 /**
4373  * Read the time from the timesync clock on an Ethernet device.
4374  *
4375  * This is usually used in conjunction with other Ethdev timesync functions to
4376  * synchronize the device time using the IEEE1588/802.1AS protocol.
4377  *
4378  * @param port_id
4379  *   The port identifier of the Ethernet device.
4380  * @param time
4381  *   Pointer to the timespec struct that holds the time.
4382  *
4383  * @return
4384  *   - 0: Success.
4385  */
4386 int rte_eth_timesync_read_time(uint8_t port_id, struct timespec *time);
4387
4388 /**
4389  * Set the time of the timesync clock on an Ethernet device.
4390  *
4391  * This is usually used in conjunction with other Ethdev timesync functions to
4392  * synchronize the device time using the IEEE1588/802.1AS protocol.
4393  *
4394  * @param port_id
4395  *   The port identifier of the Ethernet device.
4396  * @param time
4397  *   Pointer to the timespec struct that holds the time.
4398  *
4399  * @return
4400  *   - 0: Success.
4401  *   - -EINVAL: No timestamp is available.
4402  *   - -ENODEV: The port ID is invalid.
4403  *   - -ENOTSUP: The function is not supported by the Ethernet driver.
4404  */
4405 int rte_eth_timesync_write_time(uint8_t port_id, const struct timespec *time);
4406
4407 /**
4408  * Copy pci device info to the Ethernet device data.
4409  *
4410  * @param eth_dev
4411  * The *eth_dev* pointer is the address of the *rte_eth_dev* structure.
4412  * @param pci_dev
4413  * The *pci_dev* pointer is the address of the *rte_pci_device* structure.
4414  *
4415  * @return
4416  *   - 0 on success, negative on error
4417  */
4418 void rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev,
4419                 struct rte_pci_device *pci_dev);
4420
4421 /**
4422  * Create memzone for HW rings.
4423  * malloc can't be used as the physical address is needed.
4424  * If the memzone is already created, then this function returns a ptr
4425  * to the old one.
4426  *
4427  * @param eth_dev
4428  *   The *eth_dev* pointer is the address of the *rte_eth_dev* structure
4429  * @param name
4430  *   The name of the memory zone
4431  * @param queue_id
4432  *   The index of the queue to add to name
4433  * @param size
4434  *   The sizeof of the memory area
4435  * @param align
4436  *   Alignment for resulting memzone. Must be a power of 2.
4437  * @param socket_id
4438  *   The *socket_id* argument is the socket identifier in case of NUMA.
4439  */
4440 const struct rte_memzone *
4441 rte_eth_dma_zone_reserve(const struct rte_eth_dev *eth_dev, const char *name,
4442                          uint16_t queue_id, size_t size,
4443                          unsigned align, int socket_id);
4444
4445 /**
4446  * Config l2 tunnel ether type of an Ethernet device for filtering specific
4447  * tunnel packets by ether type.
4448  *
4449  * @param port_id
4450  *   The port identifier of the Ethernet device.
4451  * @param l2_tunnel
4452  *   l2 tunnel configuration.
4453  *
4454  * @return
4455  *   - (0) if successful.
4456  *   - (-ENODEV) if port identifier is invalid.
4457  *   - (-ENOTSUP) if hardware doesn't support tunnel type.
4458  */
4459 int
4460 rte_eth_dev_l2_tunnel_eth_type_conf(uint8_t port_id,
4461                                     struct rte_eth_l2_tunnel_conf *l2_tunnel);
4462
4463 /**
4464  * Enable/disable l2 tunnel offload functions. Include,
4465  * 1, The ability of parsing a type of l2 tunnel of an Ethernet device.
4466  *    Filtering, forwarding and offloading this type of tunnel packets depend on
4467  *    this ability.
4468  * 2, Stripping the l2 tunnel tag.
4469  * 3, Insertion of the l2 tunnel tag.
4470  * 4, Forwarding the packets based on the l2 tunnel tag.
4471  *
4472  * @param port_id
4473  *   The port identifier of the Ethernet device.
4474  * @param l2_tunnel
4475  *   l2 tunnel parameters.
4476  * @param mask
4477  *   Indicate the offload function.
4478  * @param en
4479  *   Enable or disable this function.
4480  *
4481  * @return
4482  *   - (0) if successful.
4483  *   - (-ENODEV) if port identifier is invalid.
4484  *   - (-ENOTSUP) if hardware doesn't support tunnel type.
4485  */
4486 int
4487 rte_eth_dev_l2_tunnel_offload_set(uint8_t port_id,
4488                                   struct rte_eth_l2_tunnel_conf *l2_tunnel,
4489                                   uint32_t mask,
4490                                   uint8_t en);
4491
4492 /**
4493 * Get the port id from pci adrress or device name
4494 * Ex: 0000:2:00.0 or vdev name net_pcap0
4495 *
4496 * @param name
4497 *  pci address or name of the device
4498 * @param port_id
4499 *   pointer to port identifier of the device
4500 * @return
4501 *   - (0) if successful.
4502 *   - (-ENODEV or -EINVAL) on failure.
4503 */
4504 int
4505 rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id);
4506
4507 /**
4508 * Get the device name from port id
4509 *
4510 * @param port_id
4511 *   pointer to port identifier of the device
4512 * @param name
4513 *  pci address or name of the device
4514 * @return
4515 *   - (0) if successful.
4516 *   - (-EINVAL) on failure.
4517 */
4518 int
4519 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name);
4520
4521 /**
4522  * @internal
4523  * Wrapper for use by pci drivers as a .probe function to attach to a ethdev
4524  * interface.
4525  */
4526 int rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
4527                           struct rte_pci_device *pci_dev);
4528
4529 /**
4530  * @internal
4531  * Wrapper for use by pci drivers as a .remove function to detach a ethdev
4532  * interface.
4533  */
4534 int rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev);
4535
4536 #ifdef __cplusplus
4537 }
4538 #endif
4539
4540 #endif /* _RTE_ETHDEV_H_ */