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