net/mlx5: support imissed counter on Windows
[dpdk.git] / lib / ethdev / rte_ethdev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2017 Intel Corporation
3  */
4
5 #ifndef _RTE_ETHDEV_H_
6 #define _RTE_ETHDEV_H_
7
8 /**
9  * @file
10  *
11  * RTE Ethernet Device API
12  *
13  * The Ethernet Device API is composed of two parts:
14  *
15  * - The application-oriented Ethernet API that includes functions to setup
16  *   an Ethernet device (configure it, setup its Rx and Tx queues and start it),
17  *   to get its MAC address, the speed and the status of its physical link,
18  *   to receive and to transmit packets, and so on.
19  *
20  * - The driver-oriented Ethernet API that exports functions allowing
21  *   an Ethernet Poll Mode Driver (PMD) to allocate an Ethernet device instance,
22  *   create memzone for HW rings and process registered callbacks, and so on.
23  *   PMDs should include ethdev_driver.h instead of this header.
24  *
25  * By default, all the functions of the Ethernet Device API exported by a PMD
26  * are lock-free functions which assume to not be invoked in parallel on
27  * different logical cores to work on the same target object.  For instance,
28  * the receive function of a PMD cannot be invoked in parallel on two logical
29  * cores to poll the same Rx queue [of the same port]. Of course, this function
30  * can be invoked in parallel by different logical cores on different Rx queues.
31  * It is the responsibility of the upper level application to enforce this rule.
32  *
33  * If needed, parallel accesses by multiple logical cores to shared queues
34  * shall be explicitly protected by dedicated inline lock-aware functions
35  * built on top of their corresponding lock-free functions of the PMD API.
36  *
37  * In all functions of the Ethernet API, the Ethernet device is
38  * designated by an integer >= 0 named the device port identifier.
39  *
40  * At the Ethernet driver level, Ethernet devices are represented by a generic
41  * data structure of type *rte_eth_dev*.
42  *
43  * Ethernet devices are dynamically registered during the PCI probing phase
44  * performed at EAL initialization time.
45  * When an Ethernet device is being probed, an *rte_eth_dev* structure and
46  * a new port identifier are allocated for that device. Then, the eth_dev_init()
47  * function supplied by the Ethernet driver matching the probed PCI
48  * device is invoked to properly initialize the device.
49  *
50  * The role of the device init function consists of resetting the hardware,
51  * checking access to Non-volatile Memory (NVM), reading the MAC address
52  * from NVM etc.
53  *
54  * If the device init operation is successful, the correspondence between
55  * the port identifier assigned to the new device and its associated
56  * *rte_eth_dev* structure is effectively registered.
57  * Otherwise, both the *rte_eth_dev* structure and the port identifier are
58  * freed.
59  *
60  * The functions exported by the application Ethernet API to setup a device
61  * designated by its port identifier must be invoked in the following order:
62  *     - rte_eth_dev_configure()
63  *     - rte_eth_tx_queue_setup()
64  *     - rte_eth_rx_queue_setup()
65  *     - rte_eth_dev_start()
66  *
67  * Then, the network application can invoke, in any order, the functions
68  * exported by the Ethernet API to get the MAC address of a given device, to
69  * get the speed and the status of a device physical link, to receive/transmit
70  * [burst of] packets, and so on.
71  *
72  * If the application wants to change the configuration (i.e. call
73  * rte_eth_dev_configure(), rte_eth_tx_queue_setup(), or
74  * rte_eth_rx_queue_setup()), it must call rte_eth_dev_stop() first to stop the
75  * device and then do the reconfiguration before calling rte_eth_dev_start()
76  * again. The transmit and receive functions should not be invoked when the
77  * device is stopped.
78  *
79  * Please note that some configuration is not stored between calls to
80  * rte_eth_dev_stop()/rte_eth_dev_start(). The following configuration will
81  * be retained:
82  *
83  *     - MTU
84  *     - flow control settings
85  *     - receive mode configuration (promiscuous mode, all-multicast mode,
86  *       hardware checksum mode, RSS/VMDq settings etc.)
87  *     - VLAN filtering configuration
88  *     - default MAC address
89  *     - MAC addresses supplied to MAC address array
90  *     - flow director filtering mode (but not filtering rules)
91  *     - NIC queue statistics mappings
92  *
93  * The following configuration may be retained or not
94  * depending on the device capabilities:
95  *
96  *     - flow rules
97  *     - flow-related shared objects, e.g. indirect actions
98  *
99  * Any other configuration will not be stored and will need to be re-entered
100  * before a call to rte_eth_dev_start().
101  *
102  * Finally, a network application can close an Ethernet device by invoking the
103  * rte_eth_dev_close() function.
104  *
105  * Each function of the application Ethernet API invokes a specific function
106  * of the PMD that controls the target device designated by its port
107  * identifier.
108  * For this purpose, all device-specific functions of an Ethernet driver are
109  * supplied through a set of pointers contained in a generic structure of type
110  * *eth_dev_ops*.
111  * The address of the *eth_dev_ops* structure is stored in the *rte_eth_dev*
112  * structure by the device init function of the Ethernet driver, which is
113  * invoked during the PCI probing phase, as explained earlier.
114  *
115  * In other words, each function of the Ethernet API simply retrieves the
116  * *rte_eth_dev* structure associated with the device port identifier and
117  * performs an indirect invocation of the corresponding driver function
118  * supplied in the *eth_dev_ops* structure of the *rte_eth_dev* structure.
119  *
120  * For performance reasons, the address of the burst-oriented Rx and Tx
121  * functions of the Ethernet driver are not contained in the *eth_dev_ops*
122  * structure. Instead, they are directly stored at the beginning of the
123  * *rte_eth_dev* structure to avoid an extra indirect memory access during
124  * their invocation.
125  *
126  * RTE Ethernet device drivers do not use interrupts for transmitting or
127  * receiving. Instead, Ethernet drivers export Poll-Mode receive and transmit
128  * functions to applications.
129  * Both receive and transmit functions are packet-burst oriented to minimize
130  * their cost per packet through the following optimizations:
131  *
132  * - Sharing among multiple packets the incompressible cost of the
133  *   invocation of receive/transmit functions.
134  *
135  * - Enabling receive/transmit functions to take advantage of burst-oriented
136  *   hardware features (L1 cache, prefetch instructions, NIC head/tail
137  *   registers) to minimize the number of CPU cycles per packet, for instance,
138  *   by avoiding useless read memory accesses to ring descriptors, or by
139  *   systematically using arrays of pointers that exactly fit L1 cache line
140  *   boundaries and sizes.
141  *
142  * The burst-oriented receive function does not provide any error notification,
143  * to avoid the corresponding overhead. As a hint, the upper-level application
144  * might check the status of the device link once being systematically returned
145  * a 0 value by the receive function of the driver for a given number of tries.
146  */
147
148 #ifdef __cplusplus
149 extern "C" {
150 #endif
151
152 #include <stdint.h>
153
154 /* Use this macro to check if LRO API is supported */
155 #define RTE_ETHDEV_HAS_LRO_SUPPORT
156
157 /* Alias RTE_LIBRTE_ETHDEV_DEBUG for backward compatibility. */
158 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
159 #define RTE_ETHDEV_DEBUG_RX
160 #define RTE_ETHDEV_DEBUG_TX
161 #endif
162
163 #include <rte_compat.h>
164 #include <rte_log.h>
165 #include <rte_interrupts.h>
166 #include <rte_dev.h>
167 #include <rte_devargs.h>
168 #include <rte_bitops.h>
169 #include <rte_errno.h>
170 #include <rte_common.h>
171 #include <rte_config.h>
172 #include <rte_ether.h>
173 #include <rte_power_intrinsics.h>
174
175 #include "rte_ethdev_trace_fp.h"
176 #include "rte_dev_info.h"
177
178 extern int rte_eth_dev_logtype;
179
180 #define RTE_ETHDEV_LOG(level, ...) \
181         rte_log(RTE_LOG_ ## level, rte_eth_dev_logtype, "" __VA_ARGS__)
182
183 struct rte_mbuf;
184
185 /**
186  * Initializes a device iterator.
187  *
188  * This iterator allows accessing a list of devices matching some devargs.
189  *
190  * @param iter
191  *   Device iterator handle initialized by the function.
192  *   The fields bus_str and cls_str might be dynamically allocated,
193  *   and could be freed by calling rte_eth_iterator_cleanup().
194  *
195  * @param devargs
196  *   Device description string.
197  *
198  * @return
199  *   0 on successful initialization, negative otherwise.
200  */
201 int rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs);
202
203 /**
204  * Iterates on devices with devargs filter.
205  * The ownership is not checked.
206  *
207  * The next port ID is returned, and the iterator is updated.
208  *
209  * @param iter
210  *   Device iterator handle initialized by rte_eth_iterator_init().
211  *   Some fields bus_str and cls_str might be freed when no more port is found,
212  *   by calling rte_eth_iterator_cleanup().
213  *
214  * @return
215  *   A port ID if found, RTE_MAX_ETHPORTS otherwise.
216  */
217 uint16_t rte_eth_iterator_next(struct rte_dev_iterator *iter);
218
219 /**
220  * Free some allocated fields of the iterator.
221  *
222  * This function is automatically called by rte_eth_iterator_next()
223  * on the last iteration (i.e. when no more matching port is found).
224  *
225  * It is safe to call this function twice; it will do nothing more.
226  *
227  * @param iter
228  *   Device iterator handle initialized by rte_eth_iterator_init().
229  *   The fields bus_str and cls_str are freed if needed.
230  */
231 void rte_eth_iterator_cleanup(struct rte_dev_iterator *iter);
232
233 /**
234  * Macro to iterate over all ethdev ports matching some devargs.
235  *
236  * If a break is done before the end of the loop,
237  * the function rte_eth_iterator_cleanup() must be called.
238  *
239  * @param id
240  *   Iterated port ID of type uint16_t.
241  * @param devargs
242  *   Device parameters input as string of type char*.
243  * @param iter
244  *   Iterator handle of type struct rte_dev_iterator, used internally.
245  */
246 #define RTE_ETH_FOREACH_MATCHING_DEV(id, devargs, iter) \
247         for (rte_eth_iterator_init(iter, devargs), \
248              id = rte_eth_iterator_next(iter); \
249              id != RTE_MAX_ETHPORTS; \
250              id = rte_eth_iterator_next(iter))
251
252 /**
253  * A structure used to retrieve statistics for an Ethernet port.
254  * Not all statistics fields in struct rte_eth_stats are supported
255  * by any type of network interface card (NIC). If any statistics
256  * field is not supported, its value is 0.
257  * All byte-related statistics do not include Ethernet FCS regardless
258  * of whether these bytes have been delivered to the application
259  * (see RTE_ETH_RX_OFFLOAD_KEEP_CRC).
260  */
261 struct rte_eth_stats {
262         uint64_t ipackets;  /**< Total number of successfully received packets. */
263         uint64_t opackets;  /**< Total number of successfully transmitted packets.*/
264         uint64_t ibytes;    /**< Total number of successfully received bytes. */
265         uint64_t obytes;    /**< Total number of successfully transmitted bytes. */
266         /**
267          * Total of Rx packets dropped by the HW,
268          * because there are no available buffer (i.e. Rx queues are full).
269          */
270         uint64_t imissed;
271         uint64_t ierrors;   /**< Total number of erroneous received packets. */
272         uint64_t oerrors;   /**< Total number of failed transmitted packets. */
273         uint64_t rx_nombuf; /**< Total number of Rx mbuf allocation failures. */
274         /* Queue stats are limited to max 256 queues */
275         /** Total number of queue Rx packets. */
276         uint64_t q_ipackets[RTE_ETHDEV_QUEUE_STAT_CNTRS];
277         /** Total number of queue Tx packets. */
278         uint64_t q_opackets[RTE_ETHDEV_QUEUE_STAT_CNTRS];
279         /** Total number of successfully received queue bytes. */
280         uint64_t q_ibytes[RTE_ETHDEV_QUEUE_STAT_CNTRS];
281         /** Total number of successfully transmitted queue bytes. */
282         uint64_t q_obytes[RTE_ETHDEV_QUEUE_STAT_CNTRS];
283         /** Total number of queue packets received that are dropped. */
284         uint64_t q_errors[RTE_ETHDEV_QUEUE_STAT_CNTRS];
285 };
286
287 /**@{@name Link speed capabilities
288  * Device supported speeds bitmap flags
289  */
290 #define RTE_ETH_LINK_SPEED_AUTONEG 0             /**< Autonegotiate (all speeds) */
291 #define ETH_LINK_SPEED_AUTONEG     RTE_ETH_LINK_SPEED_AUTONEG
292 #define RTE_ETH_LINK_SPEED_FIXED   RTE_BIT32(0)  /**< Disable autoneg (fixed speed) */
293 #define ETH_LINK_SPEED_FIXED       RTE_ETH_LINK_SPEED_FIXED
294 #define RTE_ETH_LINK_SPEED_10M_HD  RTE_BIT32(1)  /**<  10 Mbps half-duplex */
295 #define ETH_LINK_SPEED_10M_HD      RTE_ETH_LINK_SPEED_10M_HD
296 #define RTE_ETH_LINK_SPEED_10M     RTE_BIT32(2)  /**<  10 Mbps full-duplex */
297 #define ETH_LINK_SPEED_10M         RTE_ETH_LINK_SPEED_10M
298 #define RTE_ETH_LINK_SPEED_100M_HD RTE_BIT32(3)  /**< 100 Mbps half-duplex */
299 #define ETH_LINK_SPEED_100M_HD     RTE_ETH_LINK_SPEED_100M_HD
300 #define RTE_ETH_LINK_SPEED_100M    RTE_BIT32(4)  /**< 100 Mbps full-duplex */
301 #define ETH_LINK_SPEED_100M        RTE_ETH_LINK_SPEED_100M
302 #define RTE_ETH_LINK_SPEED_1G      RTE_BIT32(5)  /**<   1 Gbps */
303 #define ETH_LINK_SPEED_1G          RTE_ETH_LINK_SPEED_1G
304 #define RTE_ETH_LINK_SPEED_2_5G    RTE_BIT32(6)  /**< 2.5 Gbps */
305 #define ETH_LINK_SPEED_2_5G        RTE_ETH_LINK_SPEED_2_5G
306 #define RTE_ETH_LINK_SPEED_5G      RTE_BIT32(7)  /**<   5 Gbps */
307 #define ETH_LINK_SPEED_5G          RTE_ETH_LINK_SPEED_5G
308 #define RTE_ETH_LINK_SPEED_10G     RTE_BIT32(8)  /**<  10 Gbps */
309 #define ETH_LINK_SPEED_10G         RTE_ETH_LINK_SPEED_10G
310 #define RTE_ETH_LINK_SPEED_20G     RTE_BIT32(9)  /**<  20 Gbps */
311 #define ETH_LINK_SPEED_20G         RTE_ETH_LINK_SPEED_20G
312 #define RTE_ETH_LINK_SPEED_25G     RTE_BIT32(10) /**<  25 Gbps */
313 #define ETH_LINK_SPEED_25G         RTE_ETH_LINK_SPEED_25G
314 #define RTE_ETH_LINK_SPEED_40G     RTE_BIT32(11) /**<  40 Gbps */
315 #define ETH_LINK_SPEED_40G         RTE_ETH_LINK_SPEED_40G
316 #define RTE_ETH_LINK_SPEED_50G     RTE_BIT32(12) /**<  50 Gbps */
317 #define ETH_LINK_SPEED_50G         RTE_ETH_LINK_SPEED_50G
318 #define RTE_ETH_LINK_SPEED_56G     RTE_BIT32(13) /**<  56 Gbps */
319 #define ETH_LINK_SPEED_56G         RTE_ETH_LINK_SPEED_56G
320 #define RTE_ETH_LINK_SPEED_100G    RTE_BIT32(14) /**< 100 Gbps */
321 #define ETH_LINK_SPEED_100G        RTE_ETH_LINK_SPEED_100G
322 #define RTE_ETH_LINK_SPEED_200G    RTE_BIT32(15) /**< 200 Gbps */
323 #define ETH_LINK_SPEED_200G        RTE_ETH_LINK_SPEED_200G
324 /**@}*/
325
326 /**@{@name Link speed
327  * Ethernet numeric link speeds in Mbps
328  */
329 #define RTE_ETH_SPEED_NUM_NONE         0 /**< Not defined */
330 #define ETH_SPEED_NUM_NONE        RTE_ETH_SPEED_NUM_NONE
331 #define RTE_ETH_SPEED_NUM_10M         10 /**<  10 Mbps */
332 #define ETH_SPEED_NUM_10M         RTE_ETH_SPEED_NUM_10M
333 #define RTE_ETH_SPEED_NUM_100M       100 /**< 100 Mbps */
334 #define ETH_SPEED_NUM_100M        RTE_ETH_SPEED_NUM_100M
335 #define RTE_ETH_SPEED_NUM_1G        1000 /**<   1 Gbps */
336 #define ETH_SPEED_NUM_1G          RTE_ETH_SPEED_NUM_1G
337 #define RTE_ETH_SPEED_NUM_2_5G      2500 /**< 2.5 Gbps */
338 #define ETH_SPEED_NUM_2_5G        RTE_ETH_SPEED_NUM_2_5G
339 #define RTE_ETH_SPEED_NUM_5G        5000 /**<   5 Gbps */
340 #define ETH_SPEED_NUM_5G          RTE_ETH_SPEED_NUM_5G
341 #define RTE_ETH_SPEED_NUM_10G      10000 /**<  10 Gbps */
342 #define ETH_SPEED_NUM_10G         RTE_ETH_SPEED_NUM_10G
343 #define RTE_ETH_SPEED_NUM_20G      20000 /**<  20 Gbps */
344 #define ETH_SPEED_NUM_20G         RTE_ETH_SPEED_NUM_20G
345 #define RTE_ETH_SPEED_NUM_25G      25000 /**<  25 Gbps */
346 #define ETH_SPEED_NUM_25G         RTE_ETH_SPEED_NUM_25G
347 #define RTE_ETH_SPEED_NUM_40G      40000 /**<  40 Gbps */
348 #define ETH_SPEED_NUM_40G         RTE_ETH_SPEED_NUM_40G
349 #define RTE_ETH_SPEED_NUM_50G      50000 /**<  50 Gbps */
350 #define ETH_SPEED_NUM_50G         RTE_ETH_SPEED_NUM_50G
351 #define RTE_ETH_SPEED_NUM_56G      56000 /**<  56 Gbps */
352 #define ETH_SPEED_NUM_56G         RTE_ETH_SPEED_NUM_56G
353 #define RTE_ETH_SPEED_NUM_100G    100000 /**< 100 Gbps */
354 #define ETH_SPEED_NUM_100G        RTE_ETH_SPEED_NUM_100G
355 #define RTE_ETH_SPEED_NUM_200G    200000 /**< 200 Gbps */
356 #define ETH_SPEED_NUM_200G        RTE_ETH_SPEED_NUM_200G
357 #define RTE_ETH_SPEED_NUM_UNKNOWN UINT32_MAX /**< Unknown */
358 #define ETH_SPEED_NUM_UNKNOWN     RTE_ETH_SPEED_NUM_UNKNOWN
359 /**@}*/
360
361 /**
362  * A structure used to retrieve link-level information of an Ethernet port.
363  */
364 __extension__
365 struct rte_eth_link {
366         uint32_t link_speed;        /**< RTE_ETH_SPEED_NUM_ */
367         uint16_t link_duplex  : 1;  /**< RTE_ETH_LINK_[HALF/FULL]_DUPLEX */
368         uint16_t link_autoneg : 1;  /**< RTE_ETH_LINK_[AUTONEG/FIXED] */
369         uint16_t link_status  : 1;  /**< RTE_ETH_LINK_[DOWN/UP] */
370 } __rte_aligned(8);      /**< aligned for atomic64 read/write */
371
372 /**@{@name Link negotiation
373  * Constants used in link management.
374  */
375 #define RTE_ETH_LINK_HALF_DUPLEX 0 /**< Half-duplex connection (see link_duplex). */
376 #define ETH_LINK_HALF_DUPLEX     RTE_ETH_LINK_HALF_DUPLEX
377 #define RTE_ETH_LINK_FULL_DUPLEX 1 /**< Full-duplex connection (see link_duplex). */
378 #define ETH_LINK_FULL_DUPLEX     RTE_ETH_LINK_FULL_DUPLEX
379 #define RTE_ETH_LINK_DOWN        0 /**< Link is down (see link_status). */
380 #define ETH_LINK_DOWN            RTE_ETH_LINK_DOWN
381 #define RTE_ETH_LINK_UP          1 /**< Link is up (see link_status). */
382 #define ETH_LINK_UP              RTE_ETH_LINK_UP
383 #define RTE_ETH_LINK_FIXED       0 /**< No autonegotiation (see link_autoneg). */
384 #define ETH_LINK_FIXED           RTE_ETH_LINK_FIXED
385 #define RTE_ETH_LINK_AUTONEG     1 /**< Autonegotiated (see link_autoneg). */
386 #define ETH_LINK_AUTONEG         RTE_ETH_LINK_AUTONEG
387 #define RTE_ETH_LINK_MAX_STR_LEN 40 /**< Max length of default link string. */
388 /**@}*/
389
390 /**
391  * A structure used to configure the ring threshold registers of an Rx/Tx
392  * queue for an Ethernet port.
393  */
394 struct rte_eth_thresh {
395         uint8_t pthresh; /**< Ring prefetch threshold. */
396         uint8_t hthresh; /**< Ring host threshold. */
397         uint8_t wthresh; /**< Ring writeback threshold. */
398 };
399
400 /**@{@name Multi-queue mode
401  * @see rte_eth_conf.rxmode.mq_mode.
402  */
403 #define RTE_ETH_MQ_RX_RSS_FLAG  RTE_BIT32(0) /**< Enable RSS. @see rte_eth_rss_conf */
404 #define ETH_MQ_RX_RSS_FLAG      RTE_ETH_MQ_RX_RSS_FLAG
405 #define RTE_ETH_MQ_RX_DCB_FLAG  RTE_BIT32(1) /**< Enable DCB. */
406 #define ETH_MQ_RX_DCB_FLAG      RTE_ETH_MQ_RX_DCB_FLAG
407 #define RTE_ETH_MQ_RX_VMDQ_FLAG RTE_BIT32(2) /**< Enable VMDq. */
408 #define ETH_MQ_RX_VMDQ_FLAG     RTE_ETH_MQ_RX_VMDQ_FLAG
409 /**@}*/
410
411 /**
412  *  A set of values to identify what method is to be used to route
413  *  packets to multiple queues.
414  */
415 enum rte_eth_rx_mq_mode {
416         /** None of DCB, RSS or VMDq mode */
417         RTE_ETH_MQ_RX_NONE = 0,
418
419         /** For Rx side, only RSS is on */
420         RTE_ETH_MQ_RX_RSS = RTE_ETH_MQ_RX_RSS_FLAG,
421         /** For Rx side,only DCB is on. */
422         RTE_ETH_MQ_RX_DCB = RTE_ETH_MQ_RX_DCB_FLAG,
423         /** Both DCB and RSS enable */
424         RTE_ETH_MQ_RX_DCB_RSS = RTE_ETH_MQ_RX_RSS_FLAG | RTE_ETH_MQ_RX_DCB_FLAG,
425
426         /** Only VMDq, no RSS nor DCB */
427         RTE_ETH_MQ_RX_VMDQ_ONLY = RTE_ETH_MQ_RX_VMDQ_FLAG,
428         /** RSS mode with VMDq */
429         RTE_ETH_MQ_RX_VMDQ_RSS = RTE_ETH_MQ_RX_RSS_FLAG | RTE_ETH_MQ_RX_VMDQ_FLAG,
430         /** Use VMDq+DCB to route traffic to queues */
431         RTE_ETH_MQ_RX_VMDQ_DCB = RTE_ETH_MQ_RX_VMDQ_FLAG | RTE_ETH_MQ_RX_DCB_FLAG,
432         /** Enable both VMDq and DCB in VMDq */
433         RTE_ETH_MQ_RX_VMDQ_DCB_RSS = RTE_ETH_MQ_RX_RSS_FLAG | RTE_ETH_MQ_RX_DCB_FLAG |
434                                  RTE_ETH_MQ_RX_VMDQ_FLAG,
435 };
436
437 #define ETH_MQ_RX_NONE          RTE_ETH_MQ_RX_NONE
438 #define ETH_MQ_RX_RSS           RTE_ETH_MQ_RX_RSS
439 #define ETH_MQ_RX_DCB           RTE_ETH_MQ_RX_DCB
440 #define ETH_MQ_RX_DCB_RSS       RTE_ETH_MQ_RX_DCB_RSS
441 #define ETH_MQ_RX_VMDQ_ONLY     RTE_ETH_MQ_RX_VMDQ_ONLY
442 #define ETH_MQ_RX_VMDQ_RSS      RTE_ETH_MQ_RX_VMDQ_RSS
443 #define ETH_MQ_RX_VMDQ_DCB      RTE_ETH_MQ_RX_VMDQ_DCB
444 #define ETH_MQ_RX_VMDQ_DCB_RSS  RTE_ETH_MQ_RX_VMDQ_DCB_RSS
445
446 /**
447  * A set of values to identify what method is to be used to transmit
448  * packets using multi-TCs.
449  */
450 enum rte_eth_tx_mq_mode {
451         RTE_ETH_MQ_TX_NONE    = 0,  /**< It is in neither DCB nor VT mode. */
452         RTE_ETH_MQ_TX_DCB,          /**< For Tx side,only DCB is on. */
453         RTE_ETH_MQ_TX_VMDQ_DCB,     /**< For Tx side,both DCB and VT is on. */
454         RTE_ETH_MQ_TX_VMDQ_ONLY,    /**< Only VT on, no DCB */
455 };
456 #define ETH_MQ_TX_NONE          RTE_ETH_MQ_TX_NONE
457 #define ETH_MQ_TX_DCB           RTE_ETH_MQ_TX_DCB
458 #define ETH_MQ_TX_VMDQ_DCB      RTE_ETH_MQ_TX_VMDQ_DCB
459 #define ETH_MQ_TX_VMDQ_ONLY     RTE_ETH_MQ_TX_VMDQ_ONLY
460
461 /**
462  * A structure used to configure the Rx features of an Ethernet port.
463  */
464 struct rte_eth_rxmode {
465         /** The multi-queue packet distribution mode to be used, e.g. RSS. */
466         enum rte_eth_rx_mq_mode mq_mode;
467         uint32_t mtu;  /**< Requested MTU. */
468         /** Maximum allowed size of LRO aggregated packet. */
469         uint32_t max_lro_pkt_size;
470         uint16_t split_hdr_size;  /**< hdr buf size (header_split enabled).*/
471         /**
472          * Per-port Rx offloads to be set using RTE_ETH_RX_OFFLOAD_* flags.
473          * Only offloads set on rx_offload_capa field on rte_eth_dev_info
474          * structure are allowed to be set.
475          */
476         uint64_t offloads;
477
478         uint64_t reserved_64s[2]; /**< Reserved for future fields */
479         void *reserved_ptrs[2];   /**< Reserved for future fields */
480 };
481
482 /**
483  * VLAN types to indicate if it is for single VLAN, inner VLAN or outer VLAN.
484  * Note that single VLAN is treated the same as inner VLAN.
485  */
486 enum rte_vlan_type {
487         RTE_ETH_VLAN_TYPE_UNKNOWN = 0,
488         RTE_ETH_VLAN_TYPE_INNER, /**< Inner VLAN. */
489         RTE_ETH_VLAN_TYPE_OUTER, /**< Single VLAN, or outer VLAN. */
490         RTE_ETH_VLAN_TYPE_MAX,
491 };
492
493 #define ETH_VLAN_TYPE_UNKNOWN   RTE_ETH_VLAN_TYPE_UNKNOWN
494 #define ETH_VLAN_TYPE_INNER     RTE_ETH_VLAN_TYPE_INNER
495 #define ETH_VLAN_TYPE_OUTER     RTE_ETH_VLAN_TYPE_OUTER
496 #define ETH_VLAN_TYPE_MAX       RTE_ETH_VLAN_TYPE_MAX
497
498 /**
499  * A structure used to describe a VLAN filter.
500  * If the bit corresponding to a VID is set, such VID is on.
501  */
502 struct rte_vlan_filter_conf {
503         uint64_t ids[64];
504 };
505
506 /**
507  * A structure used to configure the Receive Side Scaling (RSS) feature
508  * of an Ethernet port.
509  * If not NULL, the *rss_key* pointer of the *rss_conf* structure points
510  * to an array holding the RSS key to use for hashing specific header
511  * fields of received packets. The length of this array should be indicated
512  * by *rss_key_len* below. Otherwise, a default random hash key is used by
513  * the device driver.
514  *
515  * The *rss_key_len* field of the *rss_conf* structure indicates the length
516  * in bytes of the array pointed by *rss_key*. To be compatible, this length
517  * will be checked in i40e only. Others assume 40 bytes to be used as before.
518  *
519  * The *rss_hf* field of the *rss_conf* structure indicates the different
520  * types of IPv4/IPv6 packets to which the RSS hashing must be applied.
521  * Supplying an *rss_hf* equal to zero disables the RSS feature.
522  */
523 struct rte_eth_rss_conf {
524         uint8_t *rss_key;    /**< If not NULL, 40-byte hash key. */
525         uint8_t rss_key_len; /**< hash key length in bytes. */
526         uint64_t rss_hf;     /**< Hash functions to apply - see below. */
527 };
528
529 /*
530  * A packet can be identified by hardware as different flow types. Different
531  * NIC hardware may support different flow types.
532  * Basically, the NIC hardware identifies the flow type as deep protocol as
533  * possible, and exclusively. For example, if a packet is identified as
534  * 'RTE_ETH_FLOW_NONFRAG_IPV4_TCP', it will not be any of other flow types,
535  * though it is an actual IPV4 packet.
536  */
537 #define RTE_ETH_FLOW_UNKNOWN             0
538 #define RTE_ETH_FLOW_RAW                 1
539 #define RTE_ETH_FLOW_IPV4                2
540 #define RTE_ETH_FLOW_FRAG_IPV4           3
541 #define RTE_ETH_FLOW_NONFRAG_IPV4_TCP    4
542 #define RTE_ETH_FLOW_NONFRAG_IPV4_UDP    5
543 #define RTE_ETH_FLOW_NONFRAG_IPV4_SCTP   6
544 #define RTE_ETH_FLOW_NONFRAG_IPV4_OTHER  7
545 #define RTE_ETH_FLOW_IPV6                8
546 #define RTE_ETH_FLOW_FRAG_IPV6           9
547 #define RTE_ETH_FLOW_NONFRAG_IPV6_TCP   10
548 #define RTE_ETH_FLOW_NONFRAG_IPV6_UDP   11
549 #define RTE_ETH_FLOW_NONFRAG_IPV6_SCTP  12
550 #define RTE_ETH_FLOW_NONFRAG_IPV6_OTHER 13
551 #define RTE_ETH_FLOW_L2_PAYLOAD         14
552 #define RTE_ETH_FLOW_IPV6_EX            15
553 #define RTE_ETH_FLOW_IPV6_TCP_EX        16
554 #define RTE_ETH_FLOW_IPV6_UDP_EX        17
555 /** Consider device port number as a flow differentiator */
556 #define RTE_ETH_FLOW_PORT               18
557 #define RTE_ETH_FLOW_VXLAN              19 /**< VXLAN protocol based flow */
558 #define RTE_ETH_FLOW_GENEVE             20 /**< GENEVE protocol based flow */
559 #define RTE_ETH_FLOW_NVGRE              21 /**< NVGRE protocol based flow */
560 #define RTE_ETH_FLOW_VXLAN_GPE          22 /**< VXLAN-GPE protocol based flow */
561 #define RTE_ETH_FLOW_GTPU               23 /**< GTPU protocol based flow */
562 #define RTE_ETH_FLOW_MAX                24
563
564 /*
565  * Below macros are defined for RSS offload types, they can be used to
566  * fill rte_eth_rss_conf.rss_hf or rte_flow_action_rss.types.
567  */
568 #define RTE_ETH_RSS_IPV4               RTE_BIT64(2)
569 #define ETH_RSS_IPV4                   RTE_ETH_RSS_IPV4
570 #define RTE_ETH_RSS_FRAG_IPV4          RTE_BIT64(3)
571 #define ETH_RSS_FRAG_IPV4              RTE_ETH_RSS_FRAG_IPV4
572 #define RTE_ETH_RSS_NONFRAG_IPV4_TCP   RTE_BIT64(4)
573 #define ETH_RSS_NONFRAG_IPV4_TCP       RTE_ETH_RSS_NONFRAG_IPV4_TCP
574 #define RTE_ETH_RSS_NONFRAG_IPV4_UDP   RTE_BIT64(5)
575 #define ETH_RSS_NONFRAG_IPV4_UDP       RTE_ETH_RSS_NONFRAG_IPV4_UDP
576 #define RTE_ETH_RSS_NONFRAG_IPV4_SCTP  RTE_BIT64(6)
577 #define ETH_RSS_NONFRAG_IPV4_SCTP      RTE_ETH_RSS_NONFRAG_IPV4_SCTP
578 #define RTE_ETH_RSS_NONFRAG_IPV4_OTHER RTE_BIT64(7)
579 #define ETH_RSS_NONFRAG_IPV4_OTHER     RTE_ETH_RSS_NONFRAG_IPV4_OTHER
580 #define RTE_ETH_RSS_IPV6               RTE_BIT64(8)
581 #define ETH_RSS_IPV6                   RTE_ETH_RSS_IPV6
582 #define RTE_ETH_RSS_FRAG_IPV6          RTE_BIT64(9)
583 #define ETH_RSS_FRAG_IPV6              RTE_ETH_RSS_FRAG_IPV6
584 #define RTE_ETH_RSS_NONFRAG_IPV6_TCP   RTE_BIT64(10)
585 #define ETH_RSS_NONFRAG_IPV6_TCP       RTE_ETH_RSS_NONFRAG_IPV6_TCP
586 #define RTE_ETH_RSS_NONFRAG_IPV6_UDP   RTE_BIT64(11)
587 #define ETH_RSS_NONFRAG_IPV6_UDP       RTE_ETH_RSS_NONFRAG_IPV6_UDP
588 #define RTE_ETH_RSS_NONFRAG_IPV6_SCTP  RTE_BIT64(12)
589 #define ETH_RSS_NONFRAG_IPV6_SCTP      RTE_ETH_RSS_NONFRAG_IPV6_SCTP
590 #define RTE_ETH_RSS_NONFRAG_IPV6_OTHER RTE_BIT64(13)
591 #define ETH_RSS_NONFRAG_IPV6_OTHER     RTE_ETH_RSS_NONFRAG_IPV6_OTHER
592 #define RTE_ETH_RSS_L2_PAYLOAD         RTE_BIT64(14)
593 #define ETH_RSS_L2_PAYLOAD             RTE_ETH_RSS_L2_PAYLOAD
594 #define RTE_ETH_RSS_IPV6_EX            RTE_BIT64(15)
595 #define ETH_RSS_IPV6_EX                RTE_ETH_RSS_IPV6_EX
596 #define RTE_ETH_RSS_IPV6_TCP_EX        RTE_BIT64(16)
597 #define ETH_RSS_IPV6_TCP_EX            RTE_ETH_RSS_IPV6_TCP_EX
598 #define RTE_ETH_RSS_IPV6_UDP_EX        RTE_BIT64(17)
599 #define ETH_RSS_IPV6_UDP_EX            RTE_ETH_RSS_IPV6_UDP_EX
600 #define RTE_ETH_RSS_PORT               RTE_BIT64(18)
601 #define ETH_RSS_PORT                   RTE_ETH_RSS_PORT
602 #define RTE_ETH_RSS_VXLAN              RTE_BIT64(19)
603 #define ETH_RSS_VXLAN                  RTE_ETH_RSS_VXLAN
604 #define RTE_ETH_RSS_GENEVE             RTE_BIT64(20)
605 #define ETH_RSS_GENEVE                 RTE_ETH_RSS_GENEVE
606 #define RTE_ETH_RSS_NVGRE              RTE_BIT64(21)
607 #define ETH_RSS_NVGRE                  RTE_ETH_RSS_NVGRE
608 #define RTE_ETH_RSS_GTPU               RTE_BIT64(23)
609 #define ETH_RSS_GTPU                   RTE_ETH_RSS_GTPU
610 #define RTE_ETH_RSS_ETH                RTE_BIT64(24)
611 #define ETH_RSS_ETH                    RTE_ETH_RSS_ETH
612 #define RTE_ETH_RSS_S_VLAN             RTE_BIT64(25)
613 #define ETH_RSS_S_VLAN                 RTE_ETH_RSS_S_VLAN
614 #define RTE_ETH_RSS_C_VLAN             RTE_BIT64(26)
615 #define ETH_RSS_C_VLAN                 RTE_ETH_RSS_C_VLAN
616 #define RTE_ETH_RSS_ESP                RTE_BIT64(27)
617 #define ETH_RSS_ESP                    RTE_ETH_RSS_ESP
618 #define RTE_ETH_RSS_AH                 RTE_BIT64(28)
619 #define ETH_RSS_AH                     RTE_ETH_RSS_AH
620 #define RTE_ETH_RSS_L2TPV3             RTE_BIT64(29)
621 #define ETH_RSS_L2TPV3                 RTE_ETH_RSS_L2TPV3
622 #define RTE_ETH_RSS_PFCP               RTE_BIT64(30)
623 #define ETH_RSS_PFCP                   RTE_ETH_RSS_PFCP
624 #define RTE_ETH_RSS_PPPOE              RTE_BIT64(31)
625 #define ETH_RSS_PPPOE                  RTE_ETH_RSS_PPPOE
626 #define RTE_ETH_RSS_ECPRI              RTE_BIT64(32)
627 #define ETH_RSS_ECPRI                  RTE_ETH_RSS_ECPRI
628 #define RTE_ETH_RSS_MPLS               RTE_BIT64(33)
629 #define ETH_RSS_MPLS                   RTE_ETH_RSS_MPLS
630 #define RTE_ETH_RSS_IPV4_CHKSUM        RTE_BIT64(34)
631 #define ETH_RSS_IPV4_CHKSUM            RTE_ETH_RSS_IPV4_CHKSUM
632
633 /**
634  * The ETH_RSS_L4_CHKSUM works on checksum field of any L4 header.
635  * It is similar to ETH_RSS_PORT that they don't specify the specific type of
636  * L4 header. This macro is defined to replace some specific L4 (TCP/UDP/SCTP)
637  * checksum type for constructing the use of RSS offload bits.
638  *
639  * Due to above reason, some old APIs (and configuration) don't support
640  * RTE_ETH_RSS_L4_CHKSUM. The rte_flow RSS API supports it.
641  *
642  * For the case that checksum is not used in an UDP header,
643  * it takes the reserved value 0 as input for the hash function.
644  */
645 #define RTE_ETH_RSS_L4_CHKSUM          RTE_BIT64(35)
646 #define ETH_RSS_L4_CHKSUM              RTE_ETH_RSS_L4_CHKSUM
647
648 /*
649  * We use the following macros to combine with above RTE_ETH_RSS_* for
650  * more specific input set selection. These bits are defined starting
651  * from the high end of the 64 bits.
652  * Note: If we use above RTE_ETH_RSS_* without SRC/DST_ONLY, it represents
653  * both SRC and DST are taken into account. If SRC_ONLY and DST_ONLY of
654  * the same level are used simultaneously, it is the same case as none of
655  * them are added.
656  */
657 #define RTE_ETH_RSS_L3_SRC_ONLY        RTE_BIT64(63)
658 #define ETH_RSS_L3_SRC_ONLY            RTE_ETH_RSS_L3_SRC_ONLY
659 #define RTE_ETH_RSS_L3_DST_ONLY        RTE_BIT64(62)
660 #define ETH_RSS_L3_DST_ONLY            RTE_ETH_RSS_L3_DST_ONLY
661 #define RTE_ETH_RSS_L4_SRC_ONLY        RTE_BIT64(61)
662 #define ETH_RSS_L4_SRC_ONLY            RTE_ETH_RSS_L4_SRC_ONLY
663 #define RTE_ETH_RSS_L4_DST_ONLY        RTE_BIT64(60)
664 #define ETH_RSS_L4_DST_ONLY            RTE_ETH_RSS_L4_DST_ONLY
665 #define RTE_ETH_RSS_L2_SRC_ONLY        RTE_BIT64(59)
666 #define ETH_RSS_L2_SRC_ONLY            RTE_ETH_RSS_L2_SRC_ONLY
667 #define RTE_ETH_RSS_L2_DST_ONLY        RTE_BIT64(58)
668 #define ETH_RSS_L2_DST_ONLY            RTE_ETH_RSS_L2_DST_ONLY
669
670 /*
671  * Only select IPV6 address prefix as RSS input set according to
672  * https:tools.ietf.org/html/rfc6052
673  * Must be combined with RTE_ETH_RSS_IPV6, RTE_ETH_RSS_NONFRAG_IPV6_UDP,
674  * RTE_ETH_RSS_NONFRAG_IPV6_TCP, RTE_ETH_RSS_NONFRAG_IPV6_SCTP.
675  */
676 #define RTE_ETH_RSS_L3_PRE32           RTE_BIT64(57)
677 #define RTE_ETH_RSS_L3_PRE40           RTE_BIT64(56)
678 #define RTE_ETH_RSS_L3_PRE48           RTE_BIT64(55)
679 #define RTE_ETH_RSS_L3_PRE56           RTE_BIT64(54)
680 #define RTE_ETH_RSS_L3_PRE64           RTE_BIT64(53)
681 #define RTE_ETH_RSS_L3_PRE96           RTE_BIT64(52)
682
683 /*
684  * Use the following macros to combine with the above layers
685  * to choose inner and outer layers or both for RSS computation.
686  * Bits 50 and 51 are reserved for this.
687  */
688
689 /**
690  * level 0, requests the default behavior.
691  * Depending on the packet type, it can mean outermost, innermost,
692  * anything in between or even no RSS.
693  * It basically stands for the innermost encapsulation level RSS
694  * can be performed on according to PMD and device capabilities.
695  */
696 #define RTE_ETH_RSS_LEVEL_PMD_DEFAULT  (UINT64_C(0) << 50)
697 #define ETH_RSS_LEVEL_PMD_DEFAULT      RTE_ETH_RSS_LEVEL_PMD_DEFAULT
698
699 /**
700  * level 1, requests RSS to be performed on the outermost packet
701  * encapsulation level.
702  */
703 #define RTE_ETH_RSS_LEVEL_OUTERMOST    (UINT64_C(1) << 50)
704 #define ETH_RSS_LEVEL_OUTERMOST        RTE_ETH_RSS_LEVEL_OUTERMOST
705
706 /**
707  * level 2, requests RSS to be performed on the specified inner packet
708  * encapsulation level, from outermost to innermost (lower to higher values).
709  */
710 #define RTE_ETH_RSS_LEVEL_INNERMOST    (UINT64_C(2) << 50)
711 #define ETH_RSS_LEVEL_INNERMOST        RTE_ETH_RSS_LEVEL_INNERMOST
712 #define RTE_ETH_RSS_LEVEL_MASK         (UINT64_C(3) << 50)
713 #define ETH_RSS_LEVEL_MASK             RTE_ETH_RSS_LEVEL_MASK
714
715 #define RTE_ETH_RSS_LEVEL(rss_hf) ((rss_hf & RTE_ETH_RSS_LEVEL_MASK) >> 50)
716 #define ETH_RSS_LEVEL(rss_hf)          RTE_ETH_RSS_LEVEL(rss_hf)
717
718 /**
719  * For input set change of hash filter, if SRC_ONLY and DST_ONLY of
720  * the same level are used simultaneously, it is the same case as
721  * none of them are added.
722  *
723  * @param rss_hf
724  *   RSS types with SRC/DST_ONLY.
725  * @return
726  *   RSS types.
727  */
728 static inline uint64_t
729 rte_eth_rss_hf_refine(uint64_t rss_hf)
730 {
731         if ((rss_hf & RTE_ETH_RSS_L3_SRC_ONLY) && (rss_hf & RTE_ETH_RSS_L3_DST_ONLY))
732                 rss_hf &= ~(RTE_ETH_RSS_L3_SRC_ONLY | RTE_ETH_RSS_L3_DST_ONLY);
733
734         if ((rss_hf & RTE_ETH_RSS_L4_SRC_ONLY) && (rss_hf & RTE_ETH_RSS_L4_DST_ONLY))
735                 rss_hf &= ~(RTE_ETH_RSS_L4_SRC_ONLY | RTE_ETH_RSS_L4_DST_ONLY);
736
737         return rss_hf;
738 }
739
740 #define RTE_ETH_RSS_IPV6_PRE32 ( \
741                 RTE_ETH_RSS_IPV6 | \
742                 RTE_ETH_RSS_L3_PRE32)
743 #define ETH_RSS_IPV6_PRE32      RTE_ETH_RSS_IPV6_PRE32
744
745 #define RTE_ETH_RSS_IPV6_PRE40 ( \
746                 RTE_ETH_RSS_IPV6 | \
747                 RTE_ETH_RSS_L3_PRE40)
748 #define ETH_RSS_IPV6_PRE40      RTE_ETH_RSS_IPV6_PRE40
749
750 #define RTE_ETH_RSS_IPV6_PRE48 ( \
751                 RTE_ETH_RSS_IPV6 | \
752                 RTE_ETH_RSS_L3_PRE48)
753 #define ETH_RSS_IPV6_PRE48      RTE_ETH_RSS_IPV6_PRE48
754
755 #define RTE_ETH_RSS_IPV6_PRE56 ( \
756                 RTE_ETH_RSS_IPV6 | \
757                 RTE_ETH_RSS_L3_PRE56)
758 #define ETH_RSS_IPV6_PRE56      RTE_ETH_RSS_IPV6_PRE56
759
760 #define RTE_ETH_RSS_IPV6_PRE64 ( \
761                 RTE_ETH_RSS_IPV6 | \
762                 RTE_ETH_RSS_L3_PRE64)
763 #define ETH_RSS_IPV6_PRE64      RTE_ETH_RSS_IPV6_PRE64
764
765 #define RTE_ETH_RSS_IPV6_PRE96 ( \
766                 RTE_ETH_RSS_IPV6 | \
767                 RTE_ETH_RSS_L3_PRE96)
768 #define ETH_RSS_IPV6_PRE96      RTE_ETH_RSS_IPV6_PRE96
769
770 #define RTE_ETH_RSS_IPV6_PRE32_UDP ( \
771                 RTE_ETH_RSS_NONFRAG_IPV6_UDP | \
772                 RTE_ETH_RSS_L3_PRE32)
773 #define ETH_RSS_IPV6_PRE32_UDP  RTE_ETH_RSS_IPV6_PRE32_UDP
774
775 #define RTE_ETH_RSS_IPV6_PRE40_UDP ( \
776                 RTE_ETH_RSS_NONFRAG_IPV6_UDP | \
777                 RTE_ETH_RSS_L3_PRE40)
778 #define ETH_RSS_IPV6_PRE40_UDP  RTE_ETH_RSS_IPV6_PRE40_UDP
779
780 #define RTE_ETH_RSS_IPV6_PRE48_UDP ( \
781                 RTE_ETH_RSS_NONFRAG_IPV6_UDP | \
782                 RTE_ETH_RSS_L3_PRE48)
783 #define ETH_RSS_IPV6_PRE48_UDP  RTE_ETH_RSS_IPV6_PRE48_UDP
784
785 #define RTE_ETH_RSS_IPV6_PRE56_UDP ( \
786                 RTE_ETH_RSS_NONFRAG_IPV6_UDP | \
787                 RTE_ETH_RSS_L3_PRE56)
788 #define ETH_RSS_IPV6_PRE56_UDP  RTE_ETH_RSS_IPV6_PRE56_UDP
789
790 #define RTE_ETH_RSS_IPV6_PRE64_UDP ( \
791                 RTE_ETH_RSS_NONFRAG_IPV6_UDP | \
792                 RTE_ETH_RSS_L3_PRE64)
793 #define ETH_RSS_IPV6_PRE64_UDP  RTE_ETH_RSS_IPV6_PRE64_UDP
794
795 #define RTE_ETH_RSS_IPV6_PRE96_UDP ( \
796                 RTE_ETH_RSS_NONFRAG_IPV6_UDP | \
797                 RTE_ETH_RSS_L3_PRE96)
798 #define ETH_RSS_IPV6_PRE96_UDP  RTE_ETH_RSS_IPV6_PRE96_UDP
799
800 #define RTE_ETH_RSS_IPV6_PRE32_TCP ( \
801                 RTE_ETH_RSS_NONFRAG_IPV6_TCP | \
802                 RTE_ETH_RSS_L3_PRE32)
803 #define ETH_RSS_IPV6_PRE32_TCP  RTE_ETH_RSS_IPV6_PRE32_TCP
804
805 #define RTE_ETH_RSS_IPV6_PRE40_TCP ( \
806                 RTE_ETH_RSS_NONFRAG_IPV6_TCP | \
807                 RTE_ETH_RSS_L3_PRE40)
808 #define ETH_RSS_IPV6_PRE40_TCP  RTE_ETH_RSS_IPV6_PRE40_TCP
809
810 #define RTE_ETH_RSS_IPV6_PRE48_TCP ( \
811                 RTE_ETH_RSS_NONFRAG_IPV6_TCP | \
812                 RTE_ETH_RSS_L3_PRE48)
813 #define ETH_RSS_IPV6_PRE48_TCP  RTE_ETH_RSS_IPV6_PRE48_TCP
814
815 #define RTE_ETH_RSS_IPV6_PRE56_TCP ( \
816                 RTE_ETH_RSS_NONFRAG_IPV6_TCP | \
817                 RTE_ETH_RSS_L3_PRE56)
818 #define ETH_RSS_IPV6_PRE56_TCP  RTE_ETH_RSS_IPV6_PRE56_TCP
819
820 #define RTE_ETH_RSS_IPV6_PRE64_TCP ( \
821                 RTE_ETH_RSS_NONFRAG_IPV6_TCP | \
822                 RTE_ETH_RSS_L3_PRE64)
823 #define ETH_RSS_IPV6_PRE64_TCP  RTE_ETH_RSS_IPV6_PRE64_TCP
824
825 #define RTE_ETH_RSS_IPV6_PRE96_TCP ( \
826                 RTE_ETH_RSS_NONFRAG_IPV6_TCP | \
827                 RTE_ETH_RSS_L3_PRE96)
828 #define ETH_RSS_IPV6_PRE96_TCP  RTE_ETH_RSS_IPV6_PRE96_TCP
829
830 #define RTE_ETH_RSS_IPV6_PRE32_SCTP ( \
831                 RTE_ETH_RSS_NONFRAG_IPV6_SCTP | \
832                 RTE_ETH_RSS_L3_PRE32)
833 #define ETH_RSS_IPV6_PRE32_SCTP RTE_ETH_RSS_IPV6_PRE32_SCTP
834
835 #define RTE_ETH_RSS_IPV6_PRE40_SCTP ( \
836                 RTE_ETH_RSS_NONFRAG_IPV6_SCTP | \
837                 RTE_ETH_RSS_L3_PRE40)
838 #define ETH_RSS_IPV6_PRE40_SCTP RTE_ETH_RSS_IPV6_PRE40_SCTP
839
840 #define RTE_ETH_RSS_IPV6_PRE48_SCTP ( \
841                 RTE_ETH_RSS_NONFRAG_IPV6_SCTP | \
842                 RTE_ETH_RSS_L3_PRE48)
843 #define ETH_RSS_IPV6_PRE48_SCTP RTE_ETH_RSS_IPV6_PRE48_SCTP
844
845 #define RTE_ETH_RSS_IPV6_PRE56_SCTP ( \
846                 RTE_ETH_RSS_NONFRAG_IPV6_SCTP | \
847                 RTE_ETH_RSS_L3_PRE56)
848 #define ETH_RSS_IPV6_PRE56_SCTP RTE_ETH_RSS_IPV6_PRE56_SCTP
849
850 #define RTE_ETH_RSS_IPV6_PRE64_SCTP ( \
851                 RTE_ETH_RSS_NONFRAG_IPV6_SCTP | \
852                 RTE_ETH_RSS_L3_PRE64)
853 #define ETH_RSS_IPV6_PRE64_SCTP RTE_ETH_RSS_IPV6_PRE64_SCTP
854
855 #define RTE_ETH_RSS_IPV6_PRE96_SCTP ( \
856                 RTE_ETH_RSS_NONFRAG_IPV6_SCTP | \
857                 RTE_ETH_RSS_L3_PRE96)
858 #define ETH_RSS_IPV6_PRE96_SCTP RTE_ETH_RSS_IPV6_PRE96_SCTP
859
860 #define RTE_ETH_RSS_IP ( \
861         RTE_ETH_RSS_IPV4 | \
862         RTE_ETH_RSS_FRAG_IPV4 | \
863         RTE_ETH_RSS_NONFRAG_IPV4_OTHER | \
864         RTE_ETH_RSS_IPV6 | \
865         RTE_ETH_RSS_FRAG_IPV6 | \
866         RTE_ETH_RSS_NONFRAG_IPV6_OTHER | \
867         RTE_ETH_RSS_IPV6_EX)
868 #define ETH_RSS_IP      RTE_ETH_RSS_IP
869
870 #define RTE_ETH_RSS_UDP ( \
871         RTE_ETH_RSS_NONFRAG_IPV4_UDP | \
872         RTE_ETH_RSS_NONFRAG_IPV6_UDP | \
873         RTE_ETH_RSS_IPV6_UDP_EX)
874 #define ETH_RSS_UDP     RTE_ETH_RSS_UDP
875
876 #define RTE_ETH_RSS_TCP ( \
877         RTE_ETH_RSS_NONFRAG_IPV4_TCP | \
878         RTE_ETH_RSS_NONFRAG_IPV6_TCP | \
879         RTE_ETH_RSS_IPV6_TCP_EX)
880 #define ETH_RSS_TCP     RTE_ETH_RSS_TCP
881
882 #define RTE_ETH_RSS_SCTP ( \
883         RTE_ETH_RSS_NONFRAG_IPV4_SCTP | \
884         RTE_ETH_RSS_NONFRAG_IPV6_SCTP)
885 #define ETH_RSS_SCTP    RTE_ETH_RSS_SCTP
886
887 #define RTE_ETH_RSS_TUNNEL ( \
888         RTE_ETH_RSS_VXLAN  | \
889         RTE_ETH_RSS_GENEVE | \
890         RTE_ETH_RSS_NVGRE)
891 #define ETH_RSS_TUNNEL  RTE_ETH_RSS_TUNNEL
892
893 #define RTE_ETH_RSS_VLAN ( \
894         RTE_ETH_RSS_S_VLAN  | \
895         RTE_ETH_RSS_C_VLAN)
896 #define ETH_RSS_VLAN    RTE_ETH_RSS_VLAN
897
898 /** Mask of valid RSS hash protocols */
899 #define RTE_ETH_RSS_PROTO_MASK ( \
900         RTE_ETH_RSS_IPV4 | \
901         RTE_ETH_RSS_FRAG_IPV4 | \
902         RTE_ETH_RSS_NONFRAG_IPV4_TCP | \
903         RTE_ETH_RSS_NONFRAG_IPV4_UDP | \
904         RTE_ETH_RSS_NONFRAG_IPV4_SCTP | \
905         RTE_ETH_RSS_NONFRAG_IPV4_OTHER | \
906         RTE_ETH_RSS_IPV6 | \
907         RTE_ETH_RSS_FRAG_IPV6 | \
908         RTE_ETH_RSS_NONFRAG_IPV6_TCP | \
909         RTE_ETH_RSS_NONFRAG_IPV6_UDP | \
910         RTE_ETH_RSS_NONFRAG_IPV6_SCTP | \
911         RTE_ETH_RSS_NONFRAG_IPV6_OTHER | \
912         RTE_ETH_RSS_L2_PAYLOAD | \
913         RTE_ETH_RSS_IPV6_EX | \
914         RTE_ETH_RSS_IPV6_TCP_EX | \
915         RTE_ETH_RSS_IPV6_UDP_EX | \
916         RTE_ETH_RSS_PORT  | \
917         RTE_ETH_RSS_VXLAN | \
918         RTE_ETH_RSS_GENEVE | \
919         RTE_ETH_RSS_NVGRE | \
920         RTE_ETH_RSS_MPLS)
921 #define ETH_RSS_PROTO_MASK      RTE_ETH_RSS_PROTO_MASK
922
923 /*
924  * Definitions used for redirection table entry size.
925  * Some RSS RETA sizes may not be supported by some drivers, check the
926  * documentation or the description of relevant functions for more details.
927  */
928 #define RTE_ETH_RSS_RETA_SIZE_64  64
929 #define ETH_RSS_RETA_SIZE_64      RTE_ETH_RSS_RETA_SIZE_64
930 #define RTE_ETH_RSS_RETA_SIZE_128 128
931 #define ETH_RSS_RETA_SIZE_128     RTE_ETH_RSS_RETA_SIZE_128
932 #define RTE_ETH_RSS_RETA_SIZE_256 256
933 #define ETH_RSS_RETA_SIZE_256     RTE_ETH_RSS_RETA_SIZE_256
934 #define RTE_ETH_RSS_RETA_SIZE_512 512
935 #define ETH_RSS_RETA_SIZE_512     RTE_ETH_RSS_RETA_SIZE_512
936 #define RTE_ETH_RETA_GROUP_SIZE   64
937 #define RTE_RETA_GROUP_SIZE       RTE_ETH_RETA_GROUP_SIZE
938
939 /**@{@name VMDq and DCB maximums */
940 #define RTE_ETH_VMDQ_MAX_VLAN_FILTERS   64 /**< Maximum nb. of VMDq VLAN filters. */
941 #define ETH_VMDQ_MAX_VLAN_FILTERS       RTE_ETH_VMDQ_MAX_VLAN_FILTERS
942 #define RTE_ETH_DCB_NUM_USER_PRIORITIES 8  /**< Maximum nb. of DCB priorities. */
943 #define ETH_DCB_NUM_USER_PRIORITIES     RTE_ETH_DCB_NUM_USER_PRIORITIES
944 #define RTE_ETH_VMDQ_DCB_NUM_QUEUES     128 /**< Maximum nb. of VMDq DCB queues. */
945 #define ETH_VMDQ_DCB_NUM_QUEUES         RTE_ETH_VMDQ_DCB_NUM_QUEUES
946 #define RTE_ETH_DCB_NUM_QUEUES          128 /**< Maximum nb. of DCB queues. */
947 #define ETH_DCB_NUM_QUEUES              RTE_ETH_DCB_NUM_QUEUES
948 /**@}*/
949
950 /**@{@name DCB capabilities */
951 #define RTE_ETH_DCB_PG_SUPPORT      RTE_BIT32(0) /**< Priority Group(ETS) support. */
952 #define ETH_DCB_PG_SUPPORT          RTE_ETH_DCB_PG_SUPPORT
953 #define RTE_ETH_DCB_PFC_SUPPORT     RTE_BIT32(1) /**< Priority Flow Control support. */
954 #define ETH_DCB_PFC_SUPPORT         RTE_ETH_DCB_PFC_SUPPORT
955 /**@}*/
956
957 /**@{@name VLAN offload bits */
958 #define RTE_ETH_VLAN_STRIP_OFFLOAD   0x0001 /**< VLAN Strip  On/Off */
959 #define ETH_VLAN_STRIP_OFFLOAD       RTE_ETH_VLAN_STRIP_OFFLOAD
960 #define RTE_ETH_VLAN_FILTER_OFFLOAD  0x0002 /**< VLAN Filter On/Off */
961 #define ETH_VLAN_FILTER_OFFLOAD      RTE_ETH_VLAN_FILTER_OFFLOAD
962 #define RTE_ETH_VLAN_EXTEND_OFFLOAD  0x0004 /**< VLAN Extend On/Off */
963 #define ETH_VLAN_EXTEND_OFFLOAD      RTE_ETH_VLAN_EXTEND_OFFLOAD
964 #define RTE_ETH_QINQ_STRIP_OFFLOAD   0x0008 /**< QINQ Strip On/Off */
965 #define ETH_QINQ_STRIP_OFFLOAD       RTE_ETH_QINQ_STRIP_OFFLOAD
966
967 #define RTE_ETH_VLAN_STRIP_MASK      0x0001 /**< VLAN Strip  setting mask */
968 #define ETH_VLAN_STRIP_MASK          RTE_ETH_VLAN_STRIP_MASK
969 #define RTE_ETH_VLAN_FILTER_MASK     0x0002 /**< VLAN Filter  setting mask*/
970 #define ETH_VLAN_FILTER_MASK         RTE_ETH_VLAN_FILTER_MASK
971 #define RTE_ETH_VLAN_EXTEND_MASK     0x0004 /**< VLAN Extend  setting mask*/
972 #define ETH_VLAN_EXTEND_MASK         RTE_ETH_VLAN_EXTEND_MASK
973 #define RTE_ETH_QINQ_STRIP_MASK      0x0008 /**< QINQ Strip  setting mask */
974 #define ETH_QINQ_STRIP_MASK          RTE_ETH_QINQ_STRIP_MASK
975 #define RTE_ETH_VLAN_ID_MAX          0x0FFF /**< VLAN ID is in lower 12 bits*/
976 #define ETH_VLAN_ID_MAX              RTE_ETH_VLAN_ID_MAX
977 /**@}*/
978
979 /* Definitions used for receive MAC address   */
980 #define RTE_ETH_NUM_RECEIVE_MAC_ADDR   128 /**< Maximum nb. of receive mac addr. */
981 #define ETH_NUM_RECEIVE_MAC_ADDR       RTE_ETH_NUM_RECEIVE_MAC_ADDR
982
983 /* Definitions used for unicast hash  */
984 #define RTE_ETH_VMDQ_NUM_UC_HASH_ARRAY 128 /**< Maximum nb. of UC hash array. */
985 #define ETH_VMDQ_NUM_UC_HASH_ARRAY     RTE_ETH_VMDQ_NUM_UC_HASH_ARRAY
986
987 /**@{@name VMDq Rx mode
988  * @see rte_eth_vmdq_rx_conf.rx_mode
989  */
990 /** Accept untagged packets. */
991 #define RTE_ETH_VMDQ_ACCEPT_UNTAG      RTE_BIT32(0)
992 #define ETH_VMDQ_ACCEPT_UNTAG          RTE_ETH_VMDQ_ACCEPT_UNTAG
993 /** Accept packets in multicast table. */
994 #define RTE_ETH_VMDQ_ACCEPT_HASH_MC    RTE_BIT32(1)
995 #define ETH_VMDQ_ACCEPT_HASH_MC        RTE_ETH_VMDQ_ACCEPT_HASH_MC
996 /** Accept packets in unicast table. */
997 #define RTE_ETH_VMDQ_ACCEPT_HASH_UC    RTE_BIT32(2)
998 #define ETH_VMDQ_ACCEPT_HASH_UC        RTE_ETH_VMDQ_ACCEPT_HASH_UC
999 /** Accept broadcast packets. */
1000 #define RTE_ETH_VMDQ_ACCEPT_BROADCAST  RTE_BIT32(3)
1001 #define ETH_VMDQ_ACCEPT_BROADCAST      RTE_ETH_VMDQ_ACCEPT_BROADCAST
1002 /** Multicast promiscuous. */
1003 #define RTE_ETH_VMDQ_ACCEPT_MULTICAST  RTE_BIT32(4)
1004 #define ETH_VMDQ_ACCEPT_MULTICAST      RTE_ETH_VMDQ_ACCEPT_MULTICAST
1005 /**@}*/
1006
1007 /**
1008  * A structure used to configure 64 entries of Redirection Table of the
1009  * Receive Side Scaling (RSS) feature of an Ethernet port. To configure
1010  * more than 64 entries supported by hardware, an array of this structure
1011  * is needed.
1012  */
1013 struct rte_eth_rss_reta_entry64 {
1014         /** Mask bits indicate which entries need to be updated/queried. */
1015         uint64_t mask;
1016         /** Group of 64 redirection table entries. */
1017         uint16_t reta[RTE_ETH_RETA_GROUP_SIZE];
1018 };
1019
1020 /**
1021  * This enum indicates the possible number of traffic classes
1022  * in DCB configurations
1023  */
1024 enum rte_eth_nb_tcs {
1025         RTE_ETH_4_TCS = 4, /**< 4 TCs with DCB. */
1026         RTE_ETH_8_TCS = 8  /**< 8 TCs with DCB. */
1027 };
1028 #define ETH_4_TCS RTE_ETH_4_TCS
1029 #define ETH_8_TCS RTE_ETH_8_TCS
1030
1031 /**
1032  * This enum indicates the possible number of queue pools
1033  * in VMDq configurations.
1034  */
1035 enum rte_eth_nb_pools {
1036         RTE_ETH_8_POOLS = 8,    /**< 8 VMDq pools. */
1037         RTE_ETH_16_POOLS = 16,  /**< 16 VMDq pools. */
1038         RTE_ETH_32_POOLS = 32,  /**< 32 VMDq pools. */
1039         RTE_ETH_64_POOLS = 64   /**< 64 VMDq pools. */
1040 };
1041 #define ETH_8_POOLS     RTE_ETH_8_POOLS
1042 #define ETH_16_POOLS    RTE_ETH_16_POOLS
1043 #define ETH_32_POOLS    RTE_ETH_32_POOLS
1044 #define ETH_64_POOLS    RTE_ETH_64_POOLS
1045
1046 /* This structure may be extended in future. */
1047 struct rte_eth_dcb_rx_conf {
1048         enum rte_eth_nb_tcs nb_tcs; /**< Possible DCB TCs, 4 or 8 TCs */
1049         /** Traffic class each UP mapped to. */
1050         uint8_t dcb_tc[RTE_ETH_DCB_NUM_USER_PRIORITIES];
1051 };
1052
1053 struct rte_eth_vmdq_dcb_tx_conf {
1054         enum rte_eth_nb_pools nb_queue_pools; /**< With DCB, 16 or 32 pools. */
1055         /** Traffic class each UP mapped to. */
1056         uint8_t dcb_tc[RTE_ETH_DCB_NUM_USER_PRIORITIES];
1057 };
1058
1059 struct rte_eth_dcb_tx_conf {
1060         enum rte_eth_nb_tcs nb_tcs; /**< Possible DCB TCs, 4 or 8 TCs. */
1061         /** Traffic class each UP mapped to. */
1062         uint8_t dcb_tc[RTE_ETH_DCB_NUM_USER_PRIORITIES];
1063 };
1064
1065 struct rte_eth_vmdq_tx_conf {
1066         enum rte_eth_nb_pools nb_queue_pools; /**< VMDq mode, 64 pools. */
1067 };
1068
1069 /**
1070  * A structure used to configure the VMDq+DCB feature
1071  * of an Ethernet port.
1072  *
1073  * Using this feature, packets are routed to a pool of queues, based
1074  * on the VLAN ID in the VLAN tag, and then to a specific queue within
1075  * that pool, using the user priority VLAN tag field.
1076  *
1077  * A default pool may be used, if desired, to route all traffic which
1078  * does not match the VLAN filter rules.
1079  */
1080 struct rte_eth_vmdq_dcb_conf {
1081         enum rte_eth_nb_pools nb_queue_pools; /**< With DCB, 16 or 32 pools */
1082         uint8_t enable_default_pool; /**< If non-zero, use a default pool */
1083         uint8_t default_pool; /**< The default pool, if applicable */
1084         uint8_t nb_pool_maps; /**< We can have up to 64 filters/mappings */
1085         struct {
1086                 uint16_t vlan_id; /**< The VLAN ID of the received frame */
1087                 uint64_t pools;   /**< Bitmask of pools for packet Rx */
1088         } pool_map[RTE_ETH_VMDQ_MAX_VLAN_FILTERS]; /**< VMDq VLAN pool maps. */
1089         /** Selects a queue in a pool */
1090         uint8_t dcb_tc[RTE_ETH_DCB_NUM_USER_PRIORITIES];
1091 };
1092
1093 /**
1094  * A structure used to configure the VMDq feature of an Ethernet port when
1095  * not combined with the DCB feature.
1096  *
1097  * Using this feature, packets are routed to a pool of queues. By default,
1098  * the pool selection is based on the MAC address, the VLAN ID in the
1099  * VLAN tag as specified in the pool_map array.
1100  * Passing the RTE_ETH_VMDQ_ACCEPT_UNTAG in the rx_mode field allows pool
1101  * selection using only the MAC address. MAC address to pool mapping is done
1102  * using the rte_eth_dev_mac_addr_add function, with the pool parameter
1103  * corresponding to the pool ID.
1104  *
1105  * Queue selection within the selected pool will be done using RSS when
1106  * it is enabled or revert to the first queue of the pool if not.
1107  *
1108  * A default pool may be used, if desired, to route all traffic which
1109  * does not match the VLAN filter rules or any pool MAC address.
1110  */
1111 struct rte_eth_vmdq_rx_conf {
1112         enum rte_eth_nb_pools nb_queue_pools; /**< VMDq only mode, 8 or 64 pools */
1113         uint8_t enable_default_pool; /**< If non-zero, use a default pool */
1114         uint8_t default_pool; /**< The default pool, if applicable */
1115         uint8_t enable_loop_back; /**< Enable VT loop back */
1116         uint8_t nb_pool_maps; /**< We can have up to 64 filters/mappings */
1117         uint32_t rx_mode; /**< Flags from ETH_VMDQ_ACCEPT_* */
1118         struct {
1119                 uint16_t vlan_id; /**< The VLAN ID of the received frame */
1120                 uint64_t pools;   /**< Bitmask of pools for packet Rx */
1121         } pool_map[RTE_ETH_VMDQ_MAX_VLAN_FILTERS]; /**< VMDq VLAN pool maps. */
1122 };
1123
1124 /**
1125  * A structure used to configure the Tx features of an Ethernet port.
1126  */
1127 struct rte_eth_txmode {
1128         enum rte_eth_tx_mq_mode mq_mode; /**< Tx multi-queues mode. */
1129         /**
1130          * Per-port Tx offloads to be set using RTE_ETH_TX_OFFLOAD_* flags.
1131          * Only offloads set on tx_offload_capa field on rte_eth_dev_info
1132          * structure are allowed to be set.
1133          */
1134         uint64_t offloads;
1135
1136         uint16_t pvid;
1137         __extension__
1138         uint8_t /** If set, reject sending out tagged pkts */
1139                 hw_vlan_reject_tagged : 1,
1140                 /** If set, reject sending out untagged pkts */
1141                 hw_vlan_reject_untagged : 1,
1142                 /** If set, enable port based VLAN insertion */
1143                 hw_vlan_insert_pvid : 1;
1144
1145         uint64_t reserved_64s[2]; /**< Reserved for future fields */
1146         void *reserved_ptrs[2];   /**< Reserved for future fields */
1147 };
1148
1149 /**
1150  * @warning
1151  * @b EXPERIMENTAL: this structure may change without prior notice.
1152  *
1153  * A structure used to configure an Rx packet segment to split.
1154  *
1155  * If RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT flag is set in offloads field,
1156  * the PMD will split the received packets into multiple segments
1157  * according to the specification in the description array:
1158  *
1159  * - The first network buffer will be allocated from the memory pool,
1160  *   specified in the first array element, the second buffer, from the
1161  *   pool in the second element, and so on.
1162  *
1163  * - The offsets from the segment description elements specify
1164  *   the data offset from the buffer beginning except the first mbuf.
1165  *   The first segment offset is added with RTE_PKTMBUF_HEADROOM.
1166  *
1167  * - The lengths in the elements define the maximal data amount
1168  *   being received to each segment. The receiving starts with filling
1169  *   up the first mbuf data buffer up to specified length. If the
1170  *   there are data remaining (packet is longer than buffer in the first
1171  *   mbuf) the following data will be pushed to the next segment
1172  *   up to its own length, and so on.
1173  *
1174  * - If the length in the segment description element is zero
1175  *   the actual buffer size will be deduced from the appropriate
1176  *   memory pool properties.
1177  *
1178  * - If there is not enough elements to describe the buffer for entire
1179  *   packet of maximal length the following parameters will be used
1180  *   for the all remaining segments:
1181  *     - pool from the last valid element
1182  *     - the buffer size from this pool
1183  *     - zero offset
1184  */
1185 struct rte_eth_rxseg_split {
1186         struct rte_mempool *mp; /**< Memory pool to allocate segment from. */
1187         uint16_t length; /**< Segment data length, configures split point. */
1188         uint16_t offset; /**< Data offset from beginning of mbuf data buffer. */
1189         uint32_t reserved; /**< Reserved field. */
1190 };
1191
1192 /**
1193  * @warning
1194  * @b EXPERIMENTAL: this structure may change without prior notice.
1195  *
1196  * A common structure used to describe Rx packet segment properties.
1197  */
1198 union rte_eth_rxseg {
1199         /* The settings for buffer split offload. */
1200         struct rte_eth_rxseg_split split;
1201         /* The other features settings should be added here. */
1202 };
1203
1204 /**
1205  * A structure used to configure an Rx ring of an Ethernet port.
1206  */
1207 struct rte_eth_rxconf {
1208         struct rte_eth_thresh rx_thresh; /**< Rx ring threshold registers. */
1209         uint16_t rx_free_thresh; /**< Drives the freeing of Rx descriptors. */
1210         uint8_t rx_drop_en; /**< Drop packets if no descriptors are available. */
1211         uint8_t rx_deferred_start; /**< Do not start queue with rte_eth_dev_start(). */
1212         uint16_t rx_nseg; /**< Number of descriptions in rx_seg array. */
1213         /**
1214          * Share group index in Rx domain and switch domain.
1215          * Non-zero value to enable Rx queue share, zero value disable share.
1216          * PMD is responsible for Rx queue consistency checks to avoid member
1217          * port's configuration contradict to each other.
1218          */
1219         uint16_t share_group;
1220         uint16_t share_qid; /**< Shared Rx queue ID in group */
1221         /**
1222          * Per-queue Rx offloads to be set using RTE_ETH_RX_OFFLOAD_* flags.
1223          * Only offloads set on rx_queue_offload_capa or rx_offload_capa
1224          * fields on rte_eth_dev_info structure are allowed to be set.
1225          */
1226         uint64_t offloads;
1227         /**
1228          * Points to the array of segment descriptions for an entire packet.
1229          * Array elements are properties for consecutive Rx segments.
1230          *
1231          * The supported capabilities of receiving segmentation is reported
1232          * in rte_eth_dev_info.rx_seg_capa field.
1233          */
1234         union rte_eth_rxseg *rx_seg;
1235
1236         uint64_t reserved_64s[2]; /**< Reserved for future fields */
1237         void *reserved_ptrs[2];   /**< Reserved for future fields */
1238 };
1239
1240 /**
1241  * A structure used to configure a Tx ring of an Ethernet port.
1242  */
1243 struct rte_eth_txconf {
1244         struct rte_eth_thresh tx_thresh; /**< Tx ring threshold registers. */
1245         uint16_t tx_rs_thresh; /**< Drives the setting of RS bit on TXDs. */
1246         uint16_t tx_free_thresh; /**< Start freeing Tx buffers if there are
1247                                       less free descriptors than this value. */
1248
1249         uint8_t tx_deferred_start; /**< Do not start queue with rte_eth_dev_start(). */
1250         /**
1251          * Per-queue Tx offloads to be set  using RTE_ETH_TX_OFFLOAD_* flags.
1252          * Only offloads set on tx_queue_offload_capa or tx_offload_capa
1253          * fields on rte_eth_dev_info structure are allowed to be set.
1254          */
1255         uint64_t offloads;
1256
1257         uint64_t reserved_64s[2]; /**< Reserved for future fields */
1258         void *reserved_ptrs[2];   /**< Reserved for future fields */
1259 };
1260
1261 /**
1262  * @warning
1263  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
1264  *
1265  * A structure used to return the hairpin capabilities that are supported.
1266  */
1267 struct rte_eth_hairpin_cap {
1268         /** The max number of hairpin queues (different bindings). */
1269         uint16_t max_nb_queues;
1270         /** Max number of Rx queues to be connected to one Tx queue. */
1271         uint16_t max_rx_2_tx;
1272         /** Max number of Tx queues to be connected to one Rx queue. */
1273         uint16_t max_tx_2_rx;
1274         uint16_t max_nb_desc; /**< The max num of descriptors. */
1275 };
1276
1277 #define RTE_ETH_MAX_HAIRPIN_PEERS 32
1278
1279 /**
1280  * @warning
1281  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
1282  *
1283  * A structure used to hold hairpin peer data.
1284  */
1285 struct rte_eth_hairpin_peer {
1286         uint16_t port; /**< Peer port. */
1287         uint16_t queue; /**< Peer queue. */
1288 };
1289
1290 /**
1291  * @warning
1292  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
1293  *
1294  * A structure used to configure hairpin binding.
1295  */
1296 struct rte_eth_hairpin_conf {
1297         uint32_t peer_count:16; /**< The number of peers. */
1298
1299         /**
1300          * Explicit Tx flow rule mode.
1301          * One hairpin pair of queues should have the same attribute.
1302          *
1303          * - When set, the user should be responsible for inserting the hairpin
1304          *   Tx part flows and removing them.
1305          * - When clear, the PMD will try to handle the Tx part of the flows,
1306          *   e.g., by splitting one flow into two parts.
1307          */
1308         uint32_t tx_explicit:1;
1309
1310         /**
1311          * Manually bind hairpin queues.
1312          * One hairpin pair of queues should have the same attribute.
1313          *
1314          * - When set, to enable hairpin, the user should call the hairpin bind
1315          *   function after all the queues are set up properly and the ports are
1316          *   started. Also, the hairpin unbind function should be called
1317          *   accordingly before stopping a port that with hairpin configured.
1318          * - When clear, the PMD will try to enable the hairpin with the queues
1319          *   configured automatically during port start.
1320          */
1321         uint32_t manual_bind:1;
1322         uint32_t reserved:14; /**< Reserved bits. */
1323         struct rte_eth_hairpin_peer peers[RTE_ETH_MAX_HAIRPIN_PEERS];
1324 };
1325
1326 /**
1327  * A structure contains information about HW descriptor ring limitations.
1328  */
1329 struct rte_eth_desc_lim {
1330         uint16_t nb_max;   /**< Max allowed number of descriptors. */
1331         uint16_t nb_min;   /**< Min allowed number of descriptors. */
1332         uint16_t nb_align; /**< Number of descriptors should be aligned to. */
1333
1334         /**
1335          * Max allowed number of segments per whole packet.
1336          *
1337          * - For TSO packet this is the total number of data descriptors allowed
1338          *   by device.
1339          *
1340          * @see nb_mtu_seg_max
1341          */
1342         uint16_t nb_seg_max;
1343
1344         /**
1345          * Max number of segments per one MTU.
1346          *
1347          * - For non-TSO packet, this is the maximum allowed number of segments
1348          *   in a single transmit packet.
1349          *
1350          * - For TSO packet each segment within the TSO may span up to this
1351          *   value.
1352          *
1353          * @see nb_seg_max
1354          */
1355         uint16_t nb_mtu_seg_max;
1356 };
1357
1358 /**
1359  * This enum indicates the flow control mode
1360  */
1361 enum rte_eth_fc_mode {
1362         RTE_ETH_FC_NONE = 0, /**< Disable flow control. */
1363         RTE_ETH_FC_RX_PAUSE, /**< Rx pause frame, enable flowctrl on Tx side. */
1364         RTE_ETH_FC_TX_PAUSE, /**< Tx pause frame, enable flowctrl on Rx side. */
1365         RTE_ETH_FC_FULL      /**< Enable flow control on both side. */
1366 };
1367
1368 #define RTE_FC_NONE     RTE_ETH_FC_NONE
1369 #define RTE_FC_RX_PAUSE RTE_ETH_FC_RX_PAUSE
1370 #define RTE_FC_TX_PAUSE RTE_ETH_FC_TX_PAUSE
1371 #define RTE_FC_FULL     RTE_ETH_FC_FULL
1372
1373 /**
1374  * A structure used to configure Ethernet flow control parameter.
1375  * These parameters will be configured into the register of the NIC.
1376  * Please refer to the corresponding data sheet for proper value.
1377  */
1378 struct rte_eth_fc_conf {
1379         uint32_t high_water;  /**< High threshold value to trigger XOFF */
1380         uint32_t low_water;   /**< Low threshold value to trigger XON */
1381         uint16_t pause_time;  /**< Pause quota in the Pause frame */
1382         uint16_t send_xon;    /**< Is XON frame need be sent */
1383         enum rte_eth_fc_mode mode;  /**< Link flow control mode */
1384         uint8_t mac_ctrl_frame_fwd; /**< Forward MAC control frames */
1385         uint8_t autoneg;      /**< Use Pause autoneg */
1386 };
1387
1388 /**
1389  * A structure used to configure Ethernet priority flow control parameter.
1390  * These parameters will be configured into the register of the NIC.
1391  * Please refer to the corresponding data sheet for proper value.
1392  */
1393 struct rte_eth_pfc_conf {
1394         struct rte_eth_fc_conf fc; /**< General flow control parameter. */
1395         uint8_t priority;          /**< VLAN User Priority. */
1396 };
1397
1398 /**
1399  * Tunnel type for device-specific classifier configuration.
1400  * @see rte_eth_udp_tunnel
1401  */
1402 enum rte_eth_tunnel_type {
1403         RTE_ETH_TUNNEL_TYPE_NONE = 0,
1404         RTE_ETH_TUNNEL_TYPE_VXLAN,
1405         RTE_ETH_TUNNEL_TYPE_GENEVE,
1406         RTE_ETH_TUNNEL_TYPE_TEREDO,
1407         RTE_ETH_TUNNEL_TYPE_NVGRE,
1408         RTE_ETH_TUNNEL_TYPE_IP_IN_GRE,
1409         RTE_ETH_L2_TUNNEL_TYPE_E_TAG,
1410         RTE_ETH_TUNNEL_TYPE_VXLAN_GPE,
1411         RTE_ETH_TUNNEL_TYPE_ECPRI,
1412         RTE_ETH_TUNNEL_TYPE_MAX,
1413 };
1414
1415 #define RTE_TUNNEL_TYPE_NONE            RTE_ETH_TUNNEL_TYPE_NONE
1416 #define RTE_TUNNEL_TYPE_VXLAN           RTE_ETH_TUNNEL_TYPE_VXLAN
1417 #define RTE_TUNNEL_TYPE_GENEVE          RTE_ETH_TUNNEL_TYPE_GENEVE
1418 #define RTE_TUNNEL_TYPE_TEREDO          RTE_ETH_TUNNEL_TYPE_TEREDO
1419 #define RTE_TUNNEL_TYPE_NVGRE           RTE_ETH_TUNNEL_TYPE_NVGRE
1420 #define RTE_TUNNEL_TYPE_IP_IN_GRE       RTE_ETH_TUNNEL_TYPE_IP_IN_GRE
1421 #define RTE_L2_TUNNEL_TYPE_E_TAG        RTE_ETH_L2_TUNNEL_TYPE_E_TAG
1422 #define RTE_TUNNEL_TYPE_VXLAN_GPE       RTE_ETH_TUNNEL_TYPE_VXLAN_GPE
1423 #define RTE_TUNNEL_TYPE_ECPRI           RTE_ETH_TUNNEL_TYPE_ECPRI
1424 #define RTE_TUNNEL_TYPE_MAX             RTE_ETH_TUNNEL_TYPE_MAX
1425
1426 /* Deprecated API file for rte_eth_dev_filter_* functions */
1427 #include "rte_eth_ctrl.h"
1428
1429 /**
1430  *  Memory space that can be configured to store Flow Director filters
1431  *  in the board memory.
1432  */
1433 enum rte_eth_fdir_pballoc_type {
1434         RTE_ETH_FDIR_PBALLOC_64K = 0,  /**< 64k. */
1435         RTE_ETH_FDIR_PBALLOC_128K,     /**< 128k. */
1436         RTE_ETH_FDIR_PBALLOC_256K,     /**< 256k. */
1437 };
1438 #define rte_fdir_pballoc_type   rte_eth_fdir_pballoc_type
1439
1440 #define RTE_FDIR_PBALLOC_64K    RTE_ETH_FDIR_PBALLOC_64K
1441 #define RTE_FDIR_PBALLOC_128K   RTE_ETH_FDIR_PBALLOC_128K
1442 #define RTE_FDIR_PBALLOC_256K   RTE_ETH_FDIR_PBALLOC_256K
1443
1444 /**
1445  *  Select report mode of FDIR hash information in Rx descriptors.
1446  */
1447 enum rte_fdir_status_mode {
1448         RTE_FDIR_NO_REPORT_STATUS = 0, /**< Never report FDIR hash. */
1449         RTE_FDIR_REPORT_STATUS, /**< Only report FDIR hash for matching pkts. */
1450         RTE_FDIR_REPORT_STATUS_ALWAYS, /**< Always report FDIR hash. */
1451 };
1452
1453 /**
1454  * A structure used to configure the Flow Director (FDIR) feature
1455  * of an Ethernet port.
1456  *
1457  * If mode is RTE_FDIR_MODE_NONE, the pballoc value is ignored.
1458  */
1459 struct rte_eth_fdir_conf {
1460         enum rte_fdir_mode mode; /**< Flow Director mode. */
1461         enum rte_eth_fdir_pballoc_type pballoc; /**< Space for FDIR filters. */
1462         enum rte_fdir_status_mode status;  /**< How to report FDIR hash. */
1463         /** Rx queue of packets matching a "drop" filter in perfect mode. */
1464         uint8_t drop_queue;
1465         struct rte_eth_fdir_masks mask;
1466         /** Flex payload configuration. */
1467         struct rte_eth_fdir_flex_conf flex_conf;
1468 };
1469
1470 #define rte_fdir_conf rte_eth_fdir_conf
1471
1472 /**
1473  * UDP tunneling configuration.
1474  *
1475  * Used to configure the classifier of a device,
1476  * associating an UDP port with a type of tunnel.
1477  *
1478  * Some NICs may need such configuration to properly parse a tunnel
1479  * with any standard or custom UDP port.
1480  */
1481 struct rte_eth_udp_tunnel {
1482         uint16_t udp_port; /**< UDP port used for the tunnel. */
1483         uint8_t prot_type; /**< Tunnel type. @see rte_eth_tunnel_type */
1484 };
1485
1486 /**
1487  * A structure used to enable/disable specific device interrupts.
1488  */
1489 struct rte_eth_intr_conf {
1490         /** enable/disable lsc interrupt. 0 (default) - disable, 1 enable */
1491         uint32_t lsc:1;
1492         /** enable/disable rxq interrupt. 0 (default) - disable, 1 enable */
1493         uint32_t rxq:1;
1494         /** enable/disable rmv interrupt. 0 (default) - disable, 1 enable */
1495         uint32_t rmv:1;
1496 };
1497
1498 #define rte_intr_conf rte_eth_intr_conf
1499
1500 /**
1501  * A structure used to configure an Ethernet port.
1502  * Depending upon the Rx multi-queue mode, extra advanced
1503  * configuration settings may be needed.
1504  */
1505 struct rte_eth_conf {
1506         uint32_t link_speeds; /**< bitmap of RTE_ETH_LINK_SPEED_XXX of speeds to be
1507                                 used. RTE_ETH_LINK_SPEED_FIXED disables link
1508                                 autonegotiation, and a unique speed shall be
1509                                 set. Otherwise, the bitmap defines the set of
1510                                 speeds to be advertised. If the special value
1511                                 RTE_ETH_LINK_SPEED_AUTONEG (0) is used, all speeds
1512                                 supported are advertised. */
1513         struct rte_eth_rxmode rxmode; /**< Port Rx configuration. */
1514         struct rte_eth_txmode txmode; /**< Port Tx configuration. */
1515         uint32_t lpbk_mode; /**< Loopback operation mode. By default the value
1516                                  is 0, meaning the loopback mode is disabled.
1517                                  Read the datasheet of given Ethernet controller
1518                                  for details. The possible values of this field
1519                                  are defined in implementation of each driver. */
1520         struct {
1521                 struct rte_eth_rss_conf rss_conf; /**< Port RSS configuration */
1522                 /** Port VMDq+DCB configuration. */
1523                 struct rte_eth_vmdq_dcb_conf vmdq_dcb_conf;
1524                 /** Port DCB Rx configuration. */
1525                 struct rte_eth_dcb_rx_conf dcb_rx_conf;
1526                 /** Port VMDq Rx configuration. */
1527                 struct rte_eth_vmdq_rx_conf vmdq_rx_conf;
1528         } rx_adv_conf; /**< Port Rx filtering configuration. */
1529         union {
1530                 /** Port VMDq+DCB Tx configuration. */
1531                 struct rte_eth_vmdq_dcb_tx_conf vmdq_dcb_tx_conf;
1532                 /** Port DCB Tx configuration. */
1533                 struct rte_eth_dcb_tx_conf dcb_tx_conf;
1534                 /** Port VMDq Tx configuration. */
1535                 struct rte_eth_vmdq_tx_conf vmdq_tx_conf;
1536         } tx_adv_conf; /**< Port Tx DCB configuration (union). */
1537         /** Currently,Priority Flow Control(PFC) are supported,if DCB with PFC
1538             is needed,and the variable must be set RTE_ETH_DCB_PFC_SUPPORT. */
1539         uint32_t dcb_capability_en;
1540         struct rte_eth_fdir_conf fdir_conf; /**< FDIR configuration. DEPRECATED */
1541         struct rte_eth_intr_conf intr_conf; /**< Interrupt mode configuration. */
1542 };
1543
1544 /**
1545  * Rx offload capabilities of a device.
1546  */
1547 #define RTE_ETH_RX_OFFLOAD_VLAN_STRIP       RTE_BIT64(0)
1548 #define DEV_RX_OFFLOAD_VLAN_STRIP           RTE_ETH_RX_OFFLOAD_VLAN_STRIP
1549 #define RTE_ETH_RX_OFFLOAD_IPV4_CKSUM       RTE_BIT64(1)
1550 #define DEV_RX_OFFLOAD_IPV4_CKSUM           RTE_ETH_RX_OFFLOAD_IPV4_CKSUM
1551 #define RTE_ETH_RX_OFFLOAD_UDP_CKSUM        RTE_BIT64(2)
1552 #define DEV_RX_OFFLOAD_UDP_CKSUM            RTE_ETH_RX_OFFLOAD_UDP_CKSUM
1553 #define RTE_ETH_RX_OFFLOAD_TCP_CKSUM        RTE_BIT64(3)
1554 #define DEV_RX_OFFLOAD_TCP_CKSUM            RTE_ETH_RX_OFFLOAD_TCP_CKSUM
1555 #define RTE_ETH_RX_OFFLOAD_TCP_LRO          RTE_BIT64(4)
1556 #define DEV_RX_OFFLOAD_TCP_LRO              RTE_ETH_RX_OFFLOAD_TCP_LRO
1557 #define RTE_ETH_RX_OFFLOAD_QINQ_STRIP       RTE_BIT64(5)
1558 #define DEV_RX_OFFLOAD_QINQ_STRIP           RTE_ETH_RX_OFFLOAD_QINQ_STRIP
1559 #define RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM RTE_BIT64(6)
1560 #define DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM     RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM
1561 #define RTE_ETH_RX_OFFLOAD_MACSEC_STRIP     RTE_BIT64(7)
1562 #define DEV_RX_OFFLOAD_MACSEC_STRIP         RTE_ETH_RX_OFFLOAD_MACSEC_STRIP
1563 #define RTE_ETH_RX_OFFLOAD_HEADER_SPLIT     RTE_BIT64(8)
1564 #define DEV_RX_OFFLOAD_HEADER_SPLIT         RTE_ETH_RX_OFFLOAD_HEADER_SPLIT
1565 #define RTE_ETH_RX_OFFLOAD_VLAN_FILTER      RTE_BIT64(9)
1566 #define DEV_RX_OFFLOAD_VLAN_FILTER          RTE_ETH_RX_OFFLOAD_VLAN_FILTER
1567 #define RTE_ETH_RX_OFFLOAD_VLAN_EXTEND      RTE_BIT64(10)
1568 #define DEV_RX_OFFLOAD_VLAN_EXTEND          RTE_ETH_RX_OFFLOAD_VLAN_EXTEND
1569 #define RTE_ETH_RX_OFFLOAD_SCATTER          RTE_BIT64(13)
1570 #define DEV_RX_OFFLOAD_SCATTER              RTE_ETH_RX_OFFLOAD_SCATTER
1571 /**
1572  * Timestamp is set by the driver in RTE_MBUF_DYNFIELD_TIMESTAMP_NAME
1573  * and RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME is set in ol_flags.
1574  * The mbuf field and flag are registered when the offload is configured.
1575  */
1576 #define RTE_ETH_RX_OFFLOAD_TIMESTAMP        RTE_BIT64(14)
1577 #define DEV_RX_OFFLOAD_TIMESTAMP            RTE_ETH_RX_OFFLOAD_TIMESTAMP
1578 #define RTE_ETH_RX_OFFLOAD_SECURITY         RTE_BIT64(15)
1579 #define DEV_RX_OFFLOAD_SECURITY             RTE_ETH_RX_OFFLOAD_SECURITY
1580 #define RTE_ETH_RX_OFFLOAD_KEEP_CRC         RTE_BIT64(16)
1581 #define DEV_RX_OFFLOAD_KEEP_CRC             RTE_ETH_RX_OFFLOAD_KEEP_CRC
1582 #define RTE_ETH_RX_OFFLOAD_SCTP_CKSUM       RTE_BIT64(17)
1583 #define DEV_RX_OFFLOAD_SCTP_CKSUM           RTE_ETH_RX_OFFLOAD_SCTP_CKSUM
1584 #define RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM  RTE_BIT64(18)
1585 #define DEV_RX_OFFLOAD_OUTER_UDP_CKSUM      RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM
1586 #define RTE_ETH_RX_OFFLOAD_RSS_HASH         RTE_BIT64(19)
1587 #define DEV_RX_OFFLOAD_RSS_HASH             RTE_ETH_RX_OFFLOAD_RSS_HASH
1588 #define RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT     RTE_BIT64(20)
1589
1590 #define RTE_ETH_RX_OFFLOAD_CHECKSUM (RTE_ETH_RX_OFFLOAD_IPV4_CKSUM | \
1591                                  RTE_ETH_RX_OFFLOAD_UDP_CKSUM | \
1592                                  RTE_ETH_RX_OFFLOAD_TCP_CKSUM)
1593 #define DEV_RX_OFFLOAD_CHECKSUM RTE_ETH_RX_OFFLOAD_CHECKSUM
1594 #define RTE_ETH_RX_OFFLOAD_VLAN (RTE_ETH_RX_OFFLOAD_VLAN_STRIP | \
1595                              RTE_ETH_RX_OFFLOAD_VLAN_FILTER | \
1596                              RTE_ETH_RX_OFFLOAD_VLAN_EXTEND | \
1597                              RTE_ETH_RX_OFFLOAD_QINQ_STRIP)
1598 #define DEV_RX_OFFLOAD_VLAN     RTE_ETH_RX_OFFLOAD_VLAN
1599
1600 /*
1601  * If new Rx offload capabilities are defined, they also must be
1602  * mentioned in rte_rx_offload_names in rte_ethdev.c file.
1603  */
1604
1605 /**
1606  * Tx offload capabilities of a device.
1607  */
1608 #define RTE_ETH_TX_OFFLOAD_VLAN_INSERT      RTE_BIT64(0)
1609 #define DEV_TX_OFFLOAD_VLAN_INSERT          RTE_ETH_TX_OFFLOAD_VLAN_INSERT
1610 #define RTE_ETH_TX_OFFLOAD_IPV4_CKSUM       RTE_BIT64(1)
1611 #define DEV_TX_OFFLOAD_IPV4_CKSUM           RTE_ETH_TX_OFFLOAD_IPV4_CKSUM
1612 #define RTE_ETH_TX_OFFLOAD_UDP_CKSUM        RTE_BIT64(2)
1613 #define DEV_TX_OFFLOAD_UDP_CKSUM            RTE_ETH_TX_OFFLOAD_UDP_CKSUM
1614 #define RTE_ETH_TX_OFFLOAD_TCP_CKSUM        RTE_BIT64(3)
1615 #define DEV_TX_OFFLOAD_TCP_CKSUM            RTE_ETH_TX_OFFLOAD_TCP_CKSUM
1616 #define RTE_ETH_TX_OFFLOAD_SCTP_CKSUM       RTE_BIT64(4)
1617 #define DEV_TX_OFFLOAD_SCTP_CKSUM           RTE_ETH_TX_OFFLOAD_SCTP_CKSUM
1618 #define RTE_ETH_TX_OFFLOAD_TCP_TSO          RTE_BIT64(5)
1619 #define DEV_TX_OFFLOAD_TCP_TSO              RTE_ETH_TX_OFFLOAD_TCP_TSO
1620 #define RTE_ETH_TX_OFFLOAD_UDP_TSO          RTE_BIT64(6)
1621 #define DEV_TX_OFFLOAD_UDP_TSO              RTE_ETH_TX_OFFLOAD_UDP_TSO
1622 #define RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM RTE_BIT64(7)  /**< Used for tunneling packet. */
1623 #define DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM     RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM
1624 #define RTE_ETH_TX_OFFLOAD_QINQ_INSERT      RTE_BIT64(8)
1625 #define DEV_TX_OFFLOAD_QINQ_INSERT          RTE_ETH_TX_OFFLOAD_QINQ_INSERT
1626 #define RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO    RTE_BIT64(9)  /**< Used for tunneling packet. */
1627 #define DEV_TX_OFFLOAD_VXLAN_TNL_TSO        RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO
1628 #define RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO      RTE_BIT64(10) /**< Used for tunneling packet. */
1629 #define DEV_TX_OFFLOAD_GRE_TNL_TSO          RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO
1630 #define RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO     RTE_BIT64(11) /**< Used for tunneling packet. */
1631 #define DEV_TX_OFFLOAD_IPIP_TNL_TSO         RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO
1632 #define RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO   RTE_BIT64(12) /**< Used for tunneling packet. */
1633 #define DEV_TX_OFFLOAD_GENEVE_TNL_TSO       RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO
1634 #define RTE_ETH_TX_OFFLOAD_MACSEC_INSERT    RTE_BIT64(13)
1635 #define DEV_TX_OFFLOAD_MACSEC_INSERT        RTE_ETH_TX_OFFLOAD_MACSEC_INSERT
1636 /**
1637  * Multiple threads can invoke rte_eth_tx_burst() concurrently on the same
1638  * Tx queue without SW lock.
1639  */
1640 #define RTE_ETH_TX_OFFLOAD_MT_LOCKFREE      RTE_BIT64(14)
1641 #define DEV_TX_OFFLOAD_MT_LOCKFREE          RTE_ETH_TX_OFFLOAD_MT_LOCKFREE
1642 /** Device supports multi segment send. */
1643 #define RTE_ETH_TX_OFFLOAD_MULTI_SEGS       RTE_BIT64(15)
1644 #define DEV_TX_OFFLOAD_MULTI_SEGS           RTE_ETH_TX_OFFLOAD_MULTI_SEGS
1645 /**
1646  * Device supports optimization for fast release of mbufs.
1647  * When set application must guarantee that per-queue all mbufs comes from
1648  * the same mempool and has refcnt = 1.
1649  */
1650 #define RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE   RTE_BIT64(16)
1651 #define DEV_TX_OFFLOAD_MBUF_FAST_FREE       RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE
1652 #define RTE_ETH_TX_OFFLOAD_SECURITY         RTE_BIT64(17)
1653 #define DEV_TX_OFFLOAD_SECURITY             RTE_ETH_TX_OFFLOAD_SECURITY
1654 /**
1655  * Device supports generic UDP tunneled packet TSO.
1656  * Application must set RTE_MBUF_F_TX_TUNNEL_UDP and other mbuf fields required
1657  * for tunnel TSO.
1658  */
1659 #define RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO      RTE_BIT64(18)
1660 #define DEV_TX_OFFLOAD_UDP_TNL_TSO          RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO
1661 /**
1662  * Device supports generic IP tunneled packet TSO.
1663  * Application must set RTE_MBUF_F_TX_TUNNEL_IP and other mbuf fields required
1664  * for tunnel TSO.
1665  */
1666 #define RTE_ETH_TX_OFFLOAD_IP_TNL_TSO       RTE_BIT64(19)
1667 #define DEV_TX_OFFLOAD_IP_TNL_TSO           RTE_ETH_TX_OFFLOAD_IP_TNL_TSO
1668 /** Device supports outer UDP checksum */
1669 #define RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM  RTE_BIT64(20)
1670 #define DEV_TX_OFFLOAD_OUTER_UDP_CKSUM      RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM
1671 /**
1672  * Device sends on time read from RTE_MBUF_DYNFIELD_TIMESTAMP_NAME
1673  * if RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME is set in ol_flags.
1674  * The mbuf field and flag are registered when the offload is configured.
1675  */
1676 #define RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP RTE_BIT64(21)
1677 #define DEV_TX_OFFLOAD_SEND_ON_TIMESTAMP     RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP
1678 /*
1679  * If new Tx offload capabilities are defined, they also must be
1680  * mentioned in rte_tx_offload_names in rte_ethdev.c file.
1681  */
1682
1683 /**@{@name Device capabilities
1684  * Non-offload capabilities reported in rte_eth_dev_info.dev_capa.
1685  */
1686 /** Device supports Rx queue setup after device started. */
1687 #define RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP RTE_BIT64(0)
1688 /** Device supports Tx queue setup after device started. */
1689 #define RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP RTE_BIT64(1)
1690 /**
1691  * Device supports shared Rx queue among ports within Rx domain and
1692  * switch domain. Mbufs are consumed by shared Rx queue instead of
1693  * each queue. Multiple groups are supported by share_group of Rx
1694  * queue configuration. Shared Rx queue is identified by PMD using
1695  * share_qid of Rx queue configuration. Polling any port in the group
1696  * receive packets of all member ports, source port identified by
1697  * mbuf->port field.
1698  */
1699 #define RTE_ETH_DEV_CAPA_RXQ_SHARE              RTE_BIT64(2)
1700 /** Device supports keeping flow rules across restart. */
1701 #define RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP         RTE_BIT64(3)
1702 /** Device supports keeping shared flow objects across restart. */
1703 #define RTE_ETH_DEV_CAPA_FLOW_SHARED_OBJECT_KEEP RTE_BIT64(4)
1704 /**@}*/
1705
1706 /*
1707  * Fallback default preferred Rx/Tx port parameters.
1708  * These are used if an application requests default parameters
1709  * but the PMD does not provide preferred values.
1710  */
1711 #define RTE_ETH_DEV_FALLBACK_RX_RINGSIZE 512
1712 #define RTE_ETH_DEV_FALLBACK_TX_RINGSIZE 512
1713 #define RTE_ETH_DEV_FALLBACK_RX_NBQUEUES 1
1714 #define RTE_ETH_DEV_FALLBACK_TX_NBQUEUES 1
1715
1716 /**
1717  * Preferred Rx/Tx port parameters.
1718  * There are separate instances of this structure for transmission
1719  * and reception respectively.
1720  */
1721 struct rte_eth_dev_portconf {
1722         uint16_t burst_size; /**< Device-preferred burst size */
1723         uint16_t ring_size; /**< Device-preferred size of queue rings */
1724         uint16_t nb_queues; /**< Device-preferred number of queues */
1725 };
1726
1727 /**
1728  * Default values for switch domain ID when ethdev does not support switch
1729  * domain definitions.
1730  */
1731 #define RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID    (UINT16_MAX)
1732
1733 /**
1734  * Ethernet device associated switch information
1735  */
1736 struct rte_eth_switch_info {
1737         const char *name;       /**< switch name */
1738         uint16_t domain_id;     /**< switch domain ID */
1739         /**
1740          * Mapping to the devices physical switch port as enumerated from the
1741          * perspective of the embedded interconnect/switch. For SR-IOV enabled
1742          * device this may correspond to the VF_ID of each virtual function,
1743          * but each driver should explicitly define the mapping of switch
1744          * port identifier to that physical interconnect/switch
1745          */
1746         uint16_t port_id;
1747         /**
1748          * Shared Rx queue sub-domain boundary. Only ports in same Rx domain
1749          * and switch domain can share Rx queue. Valid only if device advertised
1750          * RTE_ETH_DEV_CAPA_RXQ_SHARE capability.
1751          */
1752         uint16_t rx_domain;
1753 };
1754
1755 /**
1756  * @warning
1757  * @b EXPERIMENTAL: this structure may change without prior notice.
1758  *
1759  * Ethernet device Rx buffer segmentation capabilities.
1760  */
1761 struct rte_eth_rxseg_capa {
1762         __extension__
1763         uint32_t multi_pools:1; /**< Supports receiving to multiple pools.*/
1764         uint32_t offset_allowed:1; /**< Supports buffer offsets. */
1765         uint32_t offset_align_log2:4; /**< Required offset alignment. */
1766         uint16_t max_nseg; /**< Maximum amount of segments to split. */
1767         uint16_t reserved; /**< Reserved field. */
1768 };
1769
1770 /**
1771  * Ethernet device information
1772  */
1773
1774 /**
1775  * Ethernet device representor port type.
1776  */
1777 enum rte_eth_representor_type {
1778         RTE_ETH_REPRESENTOR_NONE, /**< not a representor. */
1779         RTE_ETH_REPRESENTOR_VF,   /**< representor of Virtual Function. */
1780         RTE_ETH_REPRESENTOR_SF,   /**< representor of Sub Function. */
1781         RTE_ETH_REPRESENTOR_PF,   /**< representor of Physical Function. */
1782 };
1783
1784 /**
1785  * A structure used to retrieve the contextual information of
1786  * an Ethernet device, such as the controlling driver of the
1787  * device, etc...
1788  */
1789 struct rte_eth_dev_info {
1790         struct rte_device *device; /** Generic device information */
1791         const char *driver_name; /**< Device Driver name. */
1792         unsigned int if_index; /**< Index to bound host interface, or 0 if none.
1793                 Use if_indextoname() to translate into an interface name. */
1794         uint16_t min_mtu;       /**< Minimum MTU allowed */
1795         uint16_t max_mtu;       /**< Maximum MTU allowed */
1796         const uint32_t *dev_flags; /**< Device flags */
1797         uint32_t min_rx_bufsize; /**< Minimum size of Rx buffer. */
1798         uint32_t max_rx_pktlen; /**< Maximum configurable length of Rx pkt. */
1799         /** Maximum configurable size of LRO aggregated packet. */
1800         uint32_t max_lro_pkt_size;
1801         uint16_t max_rx_queues; /**< Maximum number of Rx queues. */
1802         uint16_t max_tx_queues; /**< Maximum number of Tx queues. */
1803         uint32_t max_mac_addrs; /**< Maximum number of MAC addresses. */
1804         uint32_t max_hash_mac_addrs;
1805         /** Maximum number of hash MAC addresses for MTA and UTA. */
1806         uint16_t max_vfs; /**< Maximum number of VFs. */
1807         uint16_t max_vmdq_pools; /**< Maximum number of VMDq pools. */
1808         struct rte_eth_rxseg_capa rx_seg_capa; /**< Segmentation capability.*/
1809         /** All Rx offload capabilities including all per-queue ones */
1810         uint64_t rx_offload_capa;
1811         /** All Tx offload capabilities including all per-queue ones */
1812         uint64_t tx_offload_capa;
1813         /** Device per-queue Rx offload capabilities. */
1814         uint64_t rx_queue_offload_capa;
1815         /** Device per-queue Tx offload capabilities. */
1816         uint64_t tx_queue_offload_capa;
1817         /** Device redirection table size, the total number of entries. */
1818         uint16_t reta_size;
1819         uint8_t hash_key_size; /**< Hash key size in bytes */
1820         /** Bit mask of RSS offloads, the bit offset also means flow type */
1821         uint64_t flow_type_rss_offloads;
1822         struct rte_eth_rxconf default_rxconf; /**< Default Rx configuration */
1823         struct rte_eth_txconf default_txconf; /**< Default Tx configuration */
1824         uint16_t vmdq_queue_base; /**< First queue ID for VMDq pools. */
1825         uint16_t vmdq_queue_num;  /**< Queue number for VMDq pools. */
1826         uint16_t vmdq_pool_base;  /**< First ID of VMDq pools. */
1827         struct rte_eth_desc_lim rx_desc_lim;  /**< Rx descriptors limits */
1828         struct rte_eth_desc_lim tx_desc_lim;  /**< Tx descriptors limits */
1829         uint32_t speed_capa;  /**< Supported speeds bitmap (RTE_ETH_LINK_SPEED_). */
1830         /** Configured number of Rx/Tx queues */
1831         uint16_t nb_rx_queues; /**< Number of Rx queues. */
1832         uint16_t nb_tx_queues; /**< Number of Tx queues. */
1833         /** Rx parameter recommendations */
1834         struct rte_eth_dev_portconf default_rxportconf;
1835         /** Tx parameter recommendations */
1836         struct rte_eth_dev_portconf default_txportconf;
1837         /** Generic device capabilities (RTE_ETH_DEV_CAPA_). */
1838         uint64_t dev_capa;
1839         /**
1840          * Switching information for ports on a device with a
1841          * embedded managed interconnect/switch.
1842          */
1843         struct rte_eth_switch_info switch_info;
1844
1845         uint64_t reserved_64s[2]; /**< Reserved for future fields */
1846         void *reserved_ptrs[2];   /**< Reserved for future fields */
1847 };
1848
1849 /**@{@name Rx/Tx queue states */
1850 #define RTE_ETH_QUEUE_STATE_STOPPED 0 /**< Queue stopped. */
1851 #define RTE_ETH_QUEUE_STATE_STARTED 1 /**< Queue started. */
1852 #define RTE_ETH_QUEUE_STATE_HAIRPIN 2 /**< Queue used for hairpin. */
1853 /**@}*/
1854
1855 /**
1856  * Ethernet device Rx queue information structure.
1857  * Used to retrieve information about configured queue.
1858  */
1859 struct rte_eth_rxq_info {
1860         struct rte_mempool *mp;     /**< mempool used by that queue. */
1861         struct rte_eth_rxconf conf; /**< queue config parameters. */
1862         uint8_t scattered_rx;       /**< scattered packets Rx supported. */
1863         uint8_t queue_state;        /**< one of RTE_ETH_QUEUE_STATE_*. */
1864         uint16_t nb_desc;           /**< configured number of RXDs. */
1865         uint16_t rx_buf_size;       /**< hardware receive buffer size. */
1866 } __rte_cache_min_aligned;
1867
1868 /**
1869  * Ethernet device Tx queue information structure.
1870  * Used to retrieve information about configured queue.
1871  */
1872 struct rte_eth_txq_info {
1873         struct rte_eth_txconf conf; /**< queue config parameters. */
1874         uint16_t nb_desc;           /**< configured number of TXDs. */
1875         uint8_t queue_state;        /**< one of RTE_ETH_QUEUE_STATE_*. */
1876 } __rte_cache_min_aligned;
1877
1878 /* Generic Burst mode flag definition, values can be ORed. */
1879
1880 /**
1881  * If the queues have different burst mode description, this bit will be set
1882  * by PMD, then the application can iterate to retrieve burst description for
1883  * all other queues.
1884  */
1885 #define RTE_ETH_BURST_FLAG_PER_QUEUE RTE_BIT64(0)
1886
1887 /**
1888  * Ethernet device Rx/Tx queue packet burst mode information structure.
1889  * Used to retrieve information about packet burst mode setting.
1890  */
1891 struct rte_eth_burst_mode {
1892         uint64_t flags; /**< The ORed values of RTE_ETH_BURST_FLAG_xxx */
1893
1894 #define RTE_ETH_BURST_MODE_INFO_SIZE 1024 /**< Maximum size for information */
1895         char info[RTE_ETH_BURST_MODE_INFO_SIZE]; /**< burst mode information */
1896 };
1897
1898 /** Maximum name length for extended statistics counters */
1899 #define RTE_ETH_XSTATS_NAME_SIZE 64
1900
1901 /**
1902  * An Ethernet device extended statistic structure
1903  *
1904  * This structure is used by rte_eth_xstats_get() to provide
1905  * statistics that are not provided in the generic *rte_eth_stats*
1906  * structure.
1907  * It maps a name ID, corresponding to an index in the array returned
1908  * by rte_eth_xstats_get_names(), to a statistic value.
1909  */
1910 struct rte_eth_xstat {
1911         uint64_t id;        /**< The index in xstats name array. */
1912         uint64_t value;     /**< The statistic counter value. */
1913 };
1914
1915 /**
1916  * A name element for extended statistics.
1917  *
1918  * An array of this structure is returned by rte_eth_xstats_get_names().
1919  * It lists the names of extended statistics for a PMD. The *rte_eth_xstat*
1920  * structure references these names by their array index.
1921  *
1922  * The xstats should follow a common naming scheme.
1923  * Some names are standardized in rte_stats_strings.
1924  * Examples:
1925  *     - rx_missed_errors
1926  *     - tx_q3_bytes
1927  *     - tx_size_128_to_255_packets
1928  */
1929 struct rte_eth_xstat_name {
1930         char name[RTE_ETH_XSTATS_NAME_SIZE]; /**< The statistic name. */
1931 };
1932
1933 #define RTE_ETH_DCB_NUM_TCS    8
1934 #define ETH_DCB_NUM_TCS        RTE_ETH_DCB_NUM_TCS
1935 #define RTE_ETH_MAX_VMDQ_POOL  64
1936 #define ETH_MAX_VMDQ_POOL      RTE_ETH_MAX_VMDQ_POOL
1937
1938 /**
1939  * A structure used to get the information of queue and
1940  * TC mapping on both Tx and Rx paths.
1941  */
1942 struct rte_eth_dcb_tc_queue_mapping {
1943         /** Rx queues assigned to tc per Pool */
1944         struct {
1945                 uint16_t base;
1946                 uint16_t nb_queue;
1947         } tc_rxq[RTE_ETH_MAX_VMDQ_POOL][RTE_ETH_DCB_NUM_TCS];
1948         /** Rx queues assigned to tc per Pool */
1949         struct {
1950                 uint16_t base;
1951                 uint16_t nb_queue;
1952         } tc_txq[RTE_ETH_MAX_VMDQ_POOL][RTE_ETH_DCB_NUM_TCS];
1953 };
1954
1955 /**
1956  * A structure used to get the information of DCB.
1957  * It includes TC UP mapping and queue TC mapping.
1958  */
1959 struct rte_eth_dcb_info {
1960         uint8_t nb_tcs;        /**< number of TCs */
1961         uint8_t prio_tc[RTE_ETH_DCB_NUM_USER_PRIORITIES]; /**< Priority to tc */
1962         uint8_t tc_bws[RTE_ETH_DCB_NUM_TCS]; /**< Tx BW percentage for each TC */
1963         /** Rx queues assigned to tc */
1964         struct rte_eth_dcb_tc_queue_mapping tc_queue;
1965 };
1966
1967 /**
1968  * This enum indicates the possible Forward Error Correction (FEC) modes
1969  * of an ethdev port.
1970  */
1971 enum rte_eth_fec_mode {
1972         RTE_ETH_FEC_NOFEC = 0,      /**< FEC is off */
1973         RTE_ETH_FEC_AUTO,           /**< FEC autonegotiation modes */
1974         RTE_ETH_FEC_BASER,          /**< FEC using common algorithm */
1975         RTE_ETH_FEC_RS,             /**< FEC using RS algorithm */
1976 };
1977
1978 /* Translate from FEC mode to FEC capa */
1979 #define RTE_ETH_FEC_MODE_TO_CAPA(x) RTE_BIT32(x)
1980
1981 /* This macro indicates FEC capa mask */
1982 #define RTE_ETH_FEC_MODE_CAPA_MASK(x) RTE_BIT32(RTE_ETH_FEC_ ## x)
1983
1984 /* A structure used to get capabilities per link speed */
1985 struct rte_eth_fec_capa {
1986         uint32_t speed; /**< Link speed (see RTE_ETH_SPEED_NUM_*) */
1987         uint32_t capa;  /**< FEC capabilities bitmask */
1988 };
1989
1990 #define RTE_ETH_ALL RTE_MAX_ETHPORTS
1991
1992 /* Macros to check for valid port */
1993 #define RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, retval) do { \
1994         if (!rte_eth_dev_is_valid_port(port_id)) { \
1995                 RTE_ETHDEV_LOG(ERR, "Invalid port_id=%u\n", port_id); \
1996                 return retval; \
1997         } \
1998 } while (0)
1999
2000 #define RTE_ETH_VALID_PORTID_OR_RET(port_id) do { \
2001         if (!rte_eth_dev_is_valid_port(port_id)) { \
2002                 RTE_ETHDEV_LOG(ERR, "Invalid port_id=%u\n", port_id); \
2003                 return; \
2004         } \
2005 } while (0)
2006
2007 /**
2008  * Function type used for Rx packet processing packet callbacks.
2009  *
2010  * The callback function is called on Rx with a burst of packets that have
2011  * been received on the given port and queue.
2012  *
2013  * @param port_id
2014  *   The Ethernet port on which Rx is being performed.
2015  * @param queue
2016  *   The queue on the Ethernet port which is being used to receive the packets.
2017  * @param pkts
2018  *   The burst of packets that have just been received.
2019  * @param nb_pkts
2020  *   The number of packets in the burst pointed to by "pkts".
2021  * @param max_pkts
2022  *   The max number of packets that can be stored in the "pkts" array.
2023  * @param user_param
2024  *   The arbitrary user parameter passed in by the application when the callback
2025  *   was originally configured.
2026  * @return
2027  *   The number of packets returned to the user.
2028  */
2029 typedef uint16_t (*rte_rx_callback_fn)(uint16_t port_id, uint16_t queue,
2030         struct rte_mbuf *pkts[], uint16_t nb_pkts, uint16_t max_pkts,
2031         void *user_param);
2032
2033 /**
2034  * Function type used for Tx packet processing packet callbacks.
2035  *
2036  * The callback function is called on Tx with a burst of packets immediately
2037  * before the packets are put onto the hardware queue for transmission.
2038  *
2039  * @param port_id
2040  *   The Ethernet port on which Tx is being performed.
2041  * @param queue
2042  *   The queue on the Ethernet port which is being used to transmit the packets.
2043  * @param pkts
2044  *   The burst of packets that are about to be transmitted.
2045  * @param nb_pkts
2046  *   The number of packets in the burst pointed to by "pkts".
2047  * @param user_param
2048  *   The arbitrary user parameter passed in by the application when the callback
2049  *   was originally configured.
2050  * @return
2051  *   The number of packets to be written to the NIC.
2052  */
2053 typedef uint16_t (*rte_tx_callback_fn)(uint16_t port_id, uint16_t queue,
2054         struct rte_mbuf *pkts[], uint16_t nb_pkts, void *user_param);
2055
2056 /**
2057  * Possible states of an ethdev port.
2058  */
2059 enum rte_eth_dev_state {
2060         /** Device is unused before being probed. */
2061         RTE_ETH_DEV_UNUSED = 0,
2062         /** Device is attached when allocated in probing. */
2063         RTE_ETH_DEV_ATTACHED,
2064         /** Device is in removed state when plug-out is detected. */
2065         RTE_ETH_DEV_REMOVED,
2066 };
2067
2068 struct rte_eth_dev_sriov {
2069         uint8_t active;               /**< SRIOV is active with 16, 32 or 64 pools */
2070         uint8_t nb_q_per_pool;        /**< Rx queue number per pool */
2071         uint16_t def_vmdq_idx;        /**< Default pool num used for PF */
2072         uint16_t def_pool_q_idx;      /**< Default pool queue start reg index */
2073 };
2074 #define RTE_ETH_DEV_SRIOV(dev)         ((dev)->data->sriov)
2075
2076 #define RTE_ETH_NAME_MAX_LEN RTE_DEV_NAME_MAX_LEN
2077
2078 #define RTE_ETH_DEV_NO_OWNER 0
2079
2080 #define RTE_ETH_MAX_OWNER_NAME_LEN 64
2081
2082 struct rte_eth_dev_owner {
2083         uint64_t id; /**< The owner unique identifier. */
2084         char name[RTE_ETH_MAX_OWNER_NAME_LEN]; /**< The owner name. */
2085 };
2086
2087 /**@{@name Device flags
2088  * Flags internally saved in rte_eth_dev_data.dev_flags
2089  * and reported in rte_eth_dev_info.dev_flags.
2090  */
2091 /** PMD supports thread-safe flow operations */
2092 #define RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE  RTE_BIT32(0)
2093 /** Device supports link state interrupt */
2094 #define RTE_ETH_DEV_INTR_LSC              RTE_BIT32(1)
2095 /** Device is a bonded slave */
2096 #define RTE_ETH_DEV_BONDED_SLAVE          RTE_BIT32(2)
2097 /** Device supports device removal interrupt */
2098 #define RTE_ETH_DEV_INTR_RMV              RTE_BIT32(3)
2099 /** Device is port representor */
2100 #define RTE_ETH_DEV_REPRESENTOR           RTE_BIT32(4)
2101 /** Device does not support MAC change after started */
2102 #define RTE_ETH_DEV_NOLIVE_MAC_ADDR       RTE_BIT32(5)
2103 /**
2104  * Queue xstats filled automatically by ethdev layer.
2105  * PMDs filling the queue xstats themselves should not set this flag
2106  */
2107 #define RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS RTE_BIT32(6)
2108 /**@}*/
2109
2110 /**
2111  * Iterates over valid ethdev ports owned by a specific owner.
2112  *
2113  * @param port_id
2114  *   The ID of the next possible valid owned port.
2115  * @param       owner_id
2116  *  The owner identifier.
2117  *  RTE_ETH_DEV_NO_OWNER means iterate over all valid ownerless ports.
2118  * @return
2119  *   Next valid port ID owned by owner_id, RTE_MAX_ETHPORTS if there is none.
2120  */
2121 uint64_t rte_eth_find_next_owned_by(uint16_t port_id,
2122                 const uint64_t owner_id);
2123
2124 /**
2125  * Macro to iterate over all enabled ethdev ports owned by a specific owner.
2126  */
2127 #define RTE_ETH_FOREACH_DEV_OWNED_BY(p, o) \
2128         for (p = rte_eth_find_next_owned_by(0, o); \
2129              (unsigned int)p < (unsigned int)RTE_MAX_ETHPORTS; \
2130              p = rte_eth_find_next_owned_by(p + 1, o))
2131
2132 /**
2133  * Iterates over valid ethdev ports.
2134  *
2135  * @param port_id
2136  *   The ID of the next possible valid port.
2137  * @return
2138  *   Next valid port ID, RTE_MAX_ETHPORTS if there is none.
2139  */
2140 uint16_t rte_eth_find_next(uint16_t port_id);
2141
2142 /**
2143  * Macro to iterate over all enabled and ownerless ethdev ports.
2144  */
2145 #define RTE_ETH_FOREACH_DEV(p) \
2146         RTE_ETH_FOREACH_DEV_OWNED_BY(p, RTE_ETH_DEV_NO_OWNER)
2147
2148 /**
2149  * Iterates over ethdev ports of a specified device.
2150  *
2151  * @param port_id_start
2152  *   The ID of the next possible valid port.
2153  * @param parent
2154  *   The generic device behind the ports to iterate.
2155  * @return
2156  *   Next port ID of the device, possibly port_id_start,
2157  *   RTE_MAX_ETHPORTS if there is none.
2158  */
2159 uint16_t
2160 rte_eth_find_next_of(uint16_t port_id_start,
2161                 const struct rte_device *parent);
2162
2163 /**
2164  * Macro to iterate over all ethdev ports of a specified device.
2165  *
2166  * @param port_id
2167  *   The ID of the matching port being iterated.
2168  * @param parent
2169  *   The rte_device pointer matching the iterated ports.
2170  */
2171 #define RTE_ETH_FOREACH_DEV_OF(port_id, parent) \
2172         for (port_id = rte_eth_find_next_of(0, parent); \
2173                 port_id < RTE_MAX_ETHPORTS; \
2174                 port_id = rte_eth_find_next_of(port_id + 1, parent))
2175
2176 /**
2177  * Iterates over sibling ethdev ports (i.e. sharing the same rte_device).
2178  *
2179  * @param port_id_start
2180  *   The ID of the next possible valid sibling port.
2181  * @param ref_port_id
2182  *   The ID of a reference port to compare rte_device with.
2183  * @return
2184  *   Next sibling port ID, possibly port_id_start or ref_port_id itself,
2185  *   RTE_MAX_ETHPORTS if there is none.
2186  */
2187 uint16_t
2188 rte_eth_find_next_sibling(uint16_t port_id_start, uint16_t ref_port_id);
2189
2190 /**
2191  * Macro to iterate over all ethdev ports sharing the same rte_device
2192  * as the specified port.
2193  * Note: the specified reference port is part of the loop iterations.
2194  *
2195  * @param port_id
2196  *   The ID of the matching port being iterated.
2197  * @param ref_port_id
2198  *   The ID of the port being compared.
2199  */
2200 #define RTE_ETH_FOREACH_DEV_SIBLING(port_id, ref_port_id) \
2201         for (port_id = rte_eth_find_next_sibling(0, ref_port_id); \
2202                 port_id < RTE_MAX_ETHPORTS; \
2203                 port_id = rte_eth_find_next_sibling(port_id + 1, ref_port_id))
2204
2205 /**
2206  * @warning
2207  * @b EXPERIMENTAL: this API may change without prior notice.
2208  *
2209  * Get a new unique owner identifier.
2210  * An owner identifier is used to owns Ethernet devices by only one DPDK entity
2211  * to avoid multiple management of device by different entities.
2212  *
2213  * @param       owner_id
2214  *   Owner identifier pointer.
2215  * @return
2216  *   Negative errno value on error, 0 on success.
2217  */
2218 __rte_experimental
2219 int rte_eth_dev_owner_new(uint64_t *owner_id);
2220
2221 /**
2222  * @warning
2223  * @b EXPERIMENTAL: this API may change without prior notice.
2224  *
2225  * Set an Ethernet device owner.
2226  *
2227  * @param       port_id
2228  *  The identifier of the port to own.
2229  * @param       owner
2230  *  The owner pointer.
2231  * @return
2232  *  Negative errno value on error, 0 on success.
2233  */
2234 __rte_experimental
2235 int rte_eth_dev_owner_set(const uint16_t port_id,
2236                 const struct rte_eth_dev_owner *owner);
2237
2238 /**
2239  * @warning
2240  * @b EXPERIMENTAL: this API may change without prior notice.
2241  *
2242  * Unset Ethernet device owner to make the device ownerless.
2243  *
2244  * @param       port_id
2245  *  The identifier of port to make ownerless.
2246  * @param       owner_id
2247  *  The owner identifier.
2248  * @return
2249  *  0 on success, negative errno value on error.
2250  */
2251 __rte_experimental
2252 int rte_eth_dev_owner_unset(const uint16_t port_id,
2253                 const uint64_t owner_id);
2254
2255 /**
2256  * @warning
2257  * @b EXPERIMENTAL: this API may change without prior notice.
2258  *
2259  * Remove owner from all Ethernet devices owned by a specific owner.
2260  *
2261  * @param       owner_id
2262  *  The owner identifier.
2263  * @return
2264  *  0 on success, negative errno value on error.
2265  */
2266 __rte_experimental
2267 int rte_eth_dev_owner_delete(const uint64_t owner_id);
2268
2269 /**
2270  * @warning
2271  * @b EXPERIMENTAL: this API may change without prior notice.
2272  *
2273  * Get the owner of an Ethernet device.
2274  *
2275  * @param       port_id
2276  *  The port identifier.
2277  * @param       owner
2278  *  The owner structure pointer to fill.
2279  * @return
2280  *  0 on success, negative errno value on error..
2281  */
2282 __rte_experimental
2283 int rte_eth_dev_owner_get(const uint16_t port_id,
2284                 struct rte_eth_dev_owner *owner);
2285
2286 /**
2287  * Get the number of ports which are usable for the application.
2288  *
2289  * These devices must be iterated by using the macro
2290  * ``RTE_ETH_FOREACH_DEV`` or ``RTE_ETH_FOREACH_DEV_OWNED_BY``
2291  * to deal with non-contiguous ranges of devices.
2292  *
2293  * @return
2294  *   The count of available Ethernet devices.
2295  */
2296 uint16_t rte_eth_dev_count_avail(void);
2297
2298 /**
2299  * Get the total number of ports which are allocated.
2300  *
2301  * Some devices may not be available for the application.
2302  *
2303  * @return
2304  *   The total count of Ethernet devices.
2305  */
2306 uint16_t rte_eth_dev_count_total(void);
2307
2308 /**
2309  * Convert a numerical speed in Mbps to a bitmap flag that can be used in
2310  * the bitmap link_speeds of the struct rte_eth_conf
2311  *
2312  * @param speed
2313  *   Numerical speed value in Mbps
2314  * @param duplex
2315  *   RTE_ETH_LINK_[HALF/FULL]_DUPLEX (only for 10/100M speeds)
2316  * @return
2317  *   0 if the speed cannot be mapped
2318  */
2319 uint32_t rte_eth_speed_bitflag(uint32_t speed, int duplex);
2320
2321 /**
2322  * Get RTE_ETH_RX_OFFLOAD_* flag name.
2323  *
2324  * @param offload
2325  *   Offload flag.
2326  * @return
2327  *   Offload name or 'UNKNOWN' if the flag cannot be recognised.
2328  */
2329 const char *rte_eth_dev_rx_offload_name(uint64_t offload);
2330
2331 /**
2332  * Get RTE_ETH_TX_OFFLOAD_* flag name.
2333  *
2334  * @param offload
2335  *   Offload flag.
2336  * @return
2337  *   Offload name or 'UNKNOWN' if the flag cannot be recognised.
2338  */
2339 const char *rte_eth_dev_tx_offload_name(uint64_t offload);
2340
2341 /**
2342  * @warning
2343  * @b EXPERIMENTAL: this API may change without prior notice.
2344  *
2345  * Get RTE_ETH_DEV_CAPA_* flag name.
2346  *
2347  * @param capability
2348  *   Capability flag.
2349  * @return
2350  *   Capability name or 'UNKNOWN' if the flag cannot be recognized.
2351  */
2352 __rte_experimental
2353 const char *rte_eth_dev_capability_name(uint64_t capability);
2354
2355 /**
2356  * Configure an Ethernet device.
2357  * This function must be invoked first before any other function in the
2358  * Ethernet API. This function can also be re-invoked when a device is in the
2359  * stopped state.
2360  *
2361  * @param port_id
2362  *   The port identifier of the Ethernet device to configure.
2363  * @param nb_rx_queue
2364  *   The number of receive queues to set up for the Ethernet device.
2365  * @param nb_tx_queue
2366  *   The number of transmit queues to set up for the Ethernet device.
2367  * @param eth_conf
2368  *   The pointer to the configuration data to be used for the Ethernet device.
2369  *   The *rte_eth_conf* structure includes:
2370  *     -  the hardware offload features to activate, with dedicated fields for
2371  *        each statically configurable offload hardware feature provided by
2372  *        Ethernet devices, such as IP checksum or VLAN tag stripping for
2373  *        example.
2374  *        The Rx offload bitfield API is obsolete and will be deprecated.
2375  *        Applications should set the ignore_bitfield_offloads bit on *rxmode*
2376  *        structure and use offloads field to set per-port offloads instead.
2377  *     -  Any offloading set in eth_conf->[rt]xmode.offloads must be within
2378  *        the [rt]x_offload_capa returned from rte_eth_dev_info_get().
2379  *        Any type of device supported offloading set in the input argument
2380  *        eth_conf->[rt]xmode.offloads to rte_eth_dev_configure() is enabled
2381  *        on all queues and it can't be disabled in rte_eth_[rt]x_queue_setup()
2382  *     -  the Receive Side Scaling (RSS) configuration when using multiple Rx
2383  *        queues per port. Any RSS hash function set in eth_conf->rss_conf.rss_hf
2384  *        must be within the flow_type_rss_offloads provided by drivers via
2385  *        rte_eth_dev_info_get() API.
2386  *
2387  *   Embedding all configuration information in a single data structure
2388  *   is the more flexible method that allows the addition of new features
2389  *   without changing the syntax of the API.
2390  * @return
2391  *   - 0: Success, device configured.
2392  *   - <0: Error code returned by the driver configuration function.
2393  */
2394 int rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_queue,
2395                 uint16_t nb_tx_queue, const struct rte_eth_conf *eth_conf);
2396
2397 /**
2398  * Check if an Ethernet device was physically removed.
2399  *
2400  * @param port_id
2401  *   The port identifier of the Ethernet device.
2402  * @return
2403  *   1 when the Ethernet device is removed, otherwise 0.
2404  */
2405 int
2406 rte_eth_dev_is_removed(uint16_t port_id);
2407
2408 /**
2409  * Allocate and set up a receive queue for an Ethernet device.
2410  *
2411  * The function allocates a contiguous block of memory for *nb_rx_desc*
2412  * receive descriptors from a memory zone associated with *socket_id*
2413  * and initializes each receive descriptor with a network buffer allocated
2414  * from the memory pool *mb_pool*.
2415  *
2416  * @param port_id
2417  *   The port identifier of the Ethernet device.
2418  * @param rx_queue_id
2419  *   The index of the receive queue to set up.
2420  *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
2421  *   to rte_eth_dev_configure().
2422  * @param nb_rx_desc
2423  *   The number of receive descriptors to allocate for the receive ring.
2424  * @param socket_id
2425  *   The *socket_id* argument is the socket identifier in case of NUMA.
2426  *   The value can be *SOCKET_ID_ANY* if there is no NUMA constraint for
2427  *   the DMA memory allocated for the receive descriptors of the ring.
2428  * @param rx_conf
2429  *   The pointer to the configuration data to be used for the receive queue.
2430  *   NULL value is allowed, in which case default Rx configuration
2431  *   will be used.
2432  *   The *rx_conf* structure contains an *rx_thresh* structure with the values
2433  *   of the Prefetch, Host, and Write-Back threshold registers of the receive
2434  *   ring.
2435  *   In addition it contains the hardware offloads features to activate using
2436  *   the RTE_ETH_RX_OFFLOAD_* flags.
2437  *   If an offloading set in rx_conf->offloads
2438  *   hasn't been set in the input argument eth_conf->rxmode.offloads
2439  *   to rte_eth_dev_configure(), it is a new added offloading, it must be
2440  *   per-queue type and it is enabled for the queue.
2441  *   No need to repeat any bit in rx_conf->offloads which has already been
2442  *   enabled in rte_eth_dev_configure() at port level. An offloading enabled
2443  *   at port level can't be disabled at queue level.
2444  *   The configuration structure also contains the pointer to the array
2445  *   of the receiving buffer segment descriptions, see rx_seg and rx_nseg
2446  *   fields, this extended configuration might be used by split offloads like
2447  *   RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT. If mb_pool is not NULL,
2448  *   the extended configuration fields must be set to NULL and zero.
2449  * @param mb_pool
2450  *   The pointer to the memory pool from which to allocate *rte_mbuf* network
2451  *   memory buffers to populate each descriptor of the receive ring. There are
2452  *   two options to provide Rx buffer configuration:
2453  *   - single pool:
2454  *     mb_pool is not NULL, rx_conf.rx_nseg is 0.
2455  *   - multiple segments description:
2456  *     mb_pool is NULL, rx_conf.rx_seg is not NULL, rx_conf.rx_nseg is not 0.
2457  *     Taken only if flag RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT is set in offloads.
2458  *
2459  * @return
2460  *   - 0: Success, receive queue correctly set up.
2461  *   - -EIO: if device is removed.
2462  *   - -ENODEV: if *port_id* is invalid.
2463  *   - -EINVAL: The memory pool pointer is null or the size of network buffers
2464  *      which can be allocated from this memory pool does not fit the various
2465  *      buffer sizes allowed by the device controller.
2466  *   - -ENOMEM: Unable to allocate the receive ring descriptors or to
2467  *      allocate network memory buffers from the memory pool when
2468  *      initializing receive descriptors.
2469  */
2470 int rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
2471                 uint16_t nb_rx_desc, unsigned int socket_id,
2472                 const struct rte_eth_rxconf *rx_conf,
2473                 struct rte_mempool *mb_pool);
2474
2475 /**
2476  * @warning
2477  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
2478  *
2479  * Allocate and set up a hairpin receive queue for an Ethernet device.
2480  *
2481  * The function set up the selected queue to be used in hairpin.
2482  *
2483  * @param port_id
2484  *   The port identifier of the Ethernet device.
2485  * @param rx_queue_id
2486  *   The index of the receive queue to set up.
2487  *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
2488  *   to rte_eth_dev_configure().
2489  * @param nb_rx_desc
2490  *   The number of receive descriptors to allocate for the receive ring.
2491  *   0 means the PMD will use default value.
2492  * @param conf
2493  *   The pointer to the hairpin configuration.
2494  *
2495  * @return
2496  *   - (0) if successful.
2497  *   - (-ENODEV) if *port_id* is invalid.
2498  *   - (-ENOTSUP) if hardware doesn't support.
2499  *   - (-EINVAL) if bad parameter.
2500  *   - (-ENOMEM) if unable to allocate the resources.
2501  */
2502 __rte_experimental
2503 int rte_eth_rx_hairpin_queue_setup
2504         (uint16_t port_id, uint16_t rx_queue_id, uint16_t nb_rx_desc,
2505          const struct rte_eth_hairpin_conf *conf);
2506
2507 /**
2508  * Allocate and set up a transmit queue for an Ethernet device.
2509  *
2510  * @param port_id
2511  *   The port identifier of the Ethernet device.
2512  * @param tx_queue_id
2513  *   The index of the transmit queue to set up.
2514  *   The value must be in the range [0, nb_tx_queue - 1] previously supplied
2515  *   to rte_eth_dev_configure().
2516  * @param nb_tx_desc
2517  *   The number of transmit descriptors to allocate for the transmit ring.
2518  * @param socket_id
2519  *   The *socket_id* argument is the socket identifier in case of NUMA.
2520  *   Its value can be *SOCKET_ID_ANY* if there is no NUMA constraint for
2521  *   the DMA memory allocated for the transmit descriptors of the ring.
2522  * @param tx_conf
2523  *   The pointer to the configuration data to be used for the transmit queue.
2524  *   NULL value is allowed, in which case default Tx configuration
2525  *   will be used.
2526  *   The *tx_conf* structure contains the following data:
2527  *   - The *tx_thresh* structure with the values of the Prefetch, Host, and
2528  *     Write-Back threshold registers of the transmit ring.
2529  *     When setting Write-Back threshold to the value greater then zero,
2530  *     *tx_rs_thresh* value should be explicitly set to one.
2531  *   - The *tx_free_thresh* value indicates the [minimum] number of network
2532  *     buffers that must be pending in the transmit ring to trigger their
2533  *     [implicit] freeing by the driver transmit function.
2534  *   - The *tx_rs_thresh* value indicates the [minimum] number of transmit
2535  *     descriptors that must be pending in the transmit ring before setting the
2536  *     RS bit on a descriptor by the driver transmit function.
2537  *     The *tx_rs_thresh* value should be less or equal then
2538  *     *tx_free_thresh* value, and both of them should be less then
2539  *     *nb_tx_desc* - 3.
2540  *   - The *offloads* member contains Tx offloads to be enabled.
2541  *     If an offloading set in tx_conf->offloads
2542  *     hasn't been set in the input argument eth_conf->txmode.offloads
2543  *     to rte_eth_dev_configure(), it is a new added offloading, it must be
2544  *     per-queue type and it is enabled for the queue.
2545  *     No need to repeat any bit in tx_conf->offloads which has already been
2546  *     enabled in rte_eth_dev_configure() at port level. An offloading enabled
2547  *     at port level can't be disabled at queue level.
2548  *
2549  *     Note that setting *tx_free_thresh* or *tx_rs_thresh* value to 0 forces
2550  *     the transmit function to use default values.
2551  * @return
2552  *   - 0: Success, the transmit queue is correctly set up.
2553  *   - -ENOMEM: Unable to allocate the transmit ring descriptors.
2554  */
2555 int rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
2556                 uint16_t nb_tx_desc, unsigned int socket_id,
2557                 const struct rte_eth_txconf *tx_conf);
2558
2559 /**
2560  * @warning
2561  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
2562  *
2563  * Allocate and set up a transmit hairpin queue for an Ethernet device.
2564  *
2565  * @param port_id
2566  *   The port identifier of the Ethernet device.
2567  * @param tx_queue_id
2568  *   The index of the transmit queue to set up.
2569  *   The value must be in the range [0, nb_tx_queue - 1] previously supplied
2570  *   to rte_eth_dev_configure().
2571  * @param nb_tx_desc
2572  *   The number of transmit descriptors to allocate for the transmit ring.
2573  *   0 to set default PMD value.
2574  * @param conf
2575  *   The hairpin configuration.
2576  *
2577  * @return
2578  *   - (0) if successful.
2579  *   - (-ENODEV) if *port_id* is invalid.
2580  *   - (-ENOTSUP) if hardware doesn't support.
2581  *   - (-EINVAL) if bad parameter.
2582  *   - (-ENOMEM) if unable to allocate the resources.
2583  */
2584 __rte_experimental
2585 int rte_eth_tx_hairpin_queue_setup
2586         (uint16_t port_id, uint16_t tx_queue_id, uint16_t nb_tx_desc,
2587          const struct rte_eth_hairpin_conf *conf);
2588
2589 /**
2590  * @warning
2591  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
2592  *
2593  * Get all the hairpin peer Rx / Tx ports of the current port.
2594  * The caller should ensure that the array is large enough to save the ports
2595  * list.
2596  *
2597  * @param port_id
2598  *   The port identifier of the Ethernet device.
2599  * @param peer_ports
2600  *   Pointer to the array to store the peer ports list.
2601  * @param len
2602  *   Length of the array to store the port identifiers.
2603  * @param direction
2604  *   Current port to peer port direction
2605  *   positive - current used as Tx to get all peer Rx ports.
2606  *   zero - current used as Rx to get all peer Tx ports.
2607  *
2608  * @return
2609  *   - (0 or positive) actual peer ports number.
2610  *   - (-EINVAL) if bad parameter.
2611  *   - (-ENODEV) if *port_id* invalid
2612  *   - (-ENOTSUP) if hardware doesn't support.
2613  *   - Others detailed errors from PMDs.
2614  */
2615 __rte_experimental
2616 int rte_eth_hairpin_get_peer_ports(uint16_t port_id, uint16_t *peer_ports,
2617                                    size_t len, uint32_t direction);
2618
2619 /**
2620  * @warning
2621  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
2622  *
2623  * Bind all hairpin Tx queues of one port to the Rx queues of the peer port.
2624  * It is only allowed to call this function after all hairpin queues are
2625  * configured properly and the devices are in started state.
2626  *
2627  * @param tx_port
2628  *   The identifier of the Tx port.
2629  * @param rx_port
2630  *   The identifier of peer Rx port.
2631  *   RTE_MAX_ETHPORTS is allowed for the traversal of all devices.
2632  *   Rx port ID could have the same value as Tx port ID.
2633  *
2634  * @return
2635  *   - (0) if successful.
2636  *   - (-ENODEV) if Tx port ID is invalid.
2637  *   - (-EBUSY) if device is not in started state.
2638  *   - (-ENOTSUP) if hardware doesn't support.
2639  *   - Others detailed errors from PMDs.
2640  */
2641 __rte_experimental
2642 int rte_eth_hairpin_bind(uint16_t tx_port, uint16_t rx_port);
2643
2644 /**
2645  * @warning
2646  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
2647  *
2648  * Unbind all hairpin Tx queues of one port from the Rx queues of the peer port.
2649  * This should be called before closing the Tx or Rx devices, if the bind
2650  * function is called before.
2651  * After unbinding the hairpin ports pair, it is allowed to bind them again.
2652  * Changing queues configuration should be after stopping the device(s).
2653  *
2654  * @param tx_port
2655  *   The identifier of the Tx port.
2656  * @param rx_port
2657  *   The identifier of peer Rx port.
2658  *   RTE_MAX_ETHPORTS is allowed for traversal of all devices.
2659  *   Rx port ID could have the same value as Tx port ID.
2660  *
2661  * @return
2662  *   - (0) if successful.
2663  *   - (-ENODEV) if Tx port ID is invalid.
2664  *   - (-EBUSY) if device is in stopped state.
2665  *   - (-ENOTSUP) if hardware doesn't support.
2666  *   - Others detailed errors from PMDs.
2667  */
2668 __rte_experimental
2669 int rte_eth_hairpin_unbind(uint16_t tx_port, uint16_t rx_port);
2670
2671 /**
2672  * Return the NUMA socket to which an Ethernet device is connected
2673  *
2674  * @param port_id
2675  *   The port identifier of the Ethernet device
2676  * @return
2677  *   The NUMA socket ID to which the Ethernet device is connected or
2678  *   a default of zero if the socket could not be determined.
2679  *   -1 is returned is the port_id value is out of range.
2680  */
2681 int rte_eth_dev_socket_id(uint16_t port_id);
2682
2683 /**
2684  * Check if port_id of device is attached
2685  *
2686  * @param port_id
2687  *   The port identifier of the Ethernet device
2688  * @return
2689  *   - 0 if port is out of range or not attached
2690  *   - 1 if device is attached
2691  */
2692 int rte_eth_dev_is_valid_port(uint16_t port_id);
2693
2694 /**
2695  * Start specified Rx queue of a port. It is used when rx_deferred_start
2696  * flag of the specified queue is true.
2697  *
2698  * @param port_id
2699  *   The port identifier of the Ethernet device
2700  * @param rx_queue_id
2701  *   The index of the Rx queue to update the ring.
2702  *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
2703  *   to rte_eth_dev_configure().
2704  * @return
2705  *   - 0: Success, the receive queue is started.
2706  *   - -ENODEV: if *port_id* is invalid.
2707  *   - -EINVAL: The queue_id out of range or belong to hairpin.
2708  *   - -EIO: if device is removed.
2709  *   - -ENOTSUP: The function not supported in PMD.
2710  */
2711 int rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id);
2712
2713 /**
2714  * Stop specified Rx queue of a port
2715  *
2716  * @param port_id
2717  *   The port identifier of the Ethernet device
2718  * @param rx_queue_id
2719  *   The index of the Rx queue to update the ring.
2720  *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
2721  *   to rte_eth_dev_configure().
2722  * @return
2723  *   - 0: Success, the receive queue is stopped.
2724  *   - -ENODEV: if *port_id* is invalid.
2725  *   - -EINVAL: The queue_id out of range or belong to hairpin.
2726  *   - -EIO: if device is removed.
2727  *   - -ENOTSUP: The function not supported in PMD.
2728  */
2729 int rte_eth_dev_rx_queue_stop(uint16_t port_id, uint16_t rx_queue_id);
2730
2731 /**
2732  * Start Tx for specified queue of a port. It is used when tx_deferred_start
2733  * flag of the specified queue is true.
2734  *
2735  * @param port_id
2736  *   The port identifier of the Ethernet device
2737  * @param tx_queue_id
2738  *   The index of the Tx queue to update the ring.
2739  *   The value must be in the range [0, nb_tx_queue - 1] previously supplied
2740  *   to rte_eth_dev_configure().
2741  * @return
2742  *   - 0: Success, the transmit queue is started.
2743  *   - -ENODEV: if *port_id* is invalid.
2744  *   - -EINVAL: The queue_id out of range or belong to hairpin.
2745  *   - -EIO: if device is removed.
2746  *   - -ENOTSUP: The function not supported in PMD.
2747  */
2748 int rte_eth_dev_tx_queue_start(uint16_t port_id, uint16_t tx_queue_id);
2749
2750 /**
2751  * Stop specified Tx queue of a port
2752  *
2753  * @param port_id
2754  *   The port identifier of the Ethernet device
2755  * @param tx_queue_id
2756  *   The index of the Tx queue to update the ring.
2757  *   The value must be in the range [0, nb_tx_queue - 1] previously supplied
2758  *   to rte_eth_dev_configure().
2759  * @return
2760  *   - 0: Success, the transmit queue is stopped.
2761  *   - -ENODEV: if *port_id* is invalid.
2762  *   - -EINVAL: The queue_id out of range or belong to hairpin.
2763  *   - -EIO: if device is removed.
2764  *   - -ENOTSUP: The function not supported in PMD.
2765  */
2766 int rte_eth_dev_tx_queue_stop(uint16_t port_id, uint16_t tx_queue_id);
2767
2768 /**
2769  * Start an Ethernet device.
2770  *
2771  * The device start step is the last one and consists of setting the configured
2772  * offload features and in starting the transmit and the receive units of the
2773  * device.
2774  *
2775  * Device RTE_ETH_DEV_NOLIVE_MAC_ADDR flag causes MAC address to be set before
2776  * PMD port start callback function is invoked.
2777  *
2778  * On success, all basic functions exported by the Ethernet API (link status,
2779  * receive/transmit, and so on) can be invoked.
2780  *
2781  * @param port_id
2782  *   The port identifier of the Ethernet device.
2783  * @return
2784  *   - 0: Success, Ethernet device started.
2785  *   - <0: Error code of the driver device start function.
2786  */
2787 int rte_eth_dev_start(uint16_t port_id);
2788
2789 /**
2790  * Stop an Ethernet device. The device can be restarted with a call to
2791  * rte_eth_dev_start()
2792  *
2793  * @param port_id
2794  *   The port identifier of the Ethernet device.
2795  * @return
2796  *   - 0: Success, Ethernet device stopped.
2797  *   - <0: Error code of the driver device stop function.
2798  */
2799 int rte_eth_dev_stop(uint16_t port_id);
2800
2801 /**
2802  * Link up an Ethernet device.
2803  *
2804  * Set device link up will re-enable the device Rx/Tx
2805  * functionality after it is previously set device linked down.
2806  *
2807  * @param port_id
2808  *   The port identifier of the Ethernet device.
2809  * @return
2810  *   - 0: Success, Ethernet device linked up.
2811  *   - <0: Error code of the driver device link up function.
2812  */
2813 int rte_eth_dev_set_link_up(uint16_t port_id);
2814
2815 /**
2816  * Link down an Ethernet device.
2817  * The device Rx/Tx functionality will be disabled if success,
2818  * and it can be re-enabled with a call to
2819  * rte_eth_dev_set_link_up()
2820  *
2821  * @param port_id
2822  *   The port identifier of the Ethernet device.
2823  */
2824 int rte_eth_dev_set_link_down(uint16_t port_id);
2825
2826 /**
2827  * Close a stopped Ethernet device. The device cannot be restarted!
2828  * The function frees all port resources.
2829  *
2830  * @param port_id
2831  *   The port identifier of the Ethernet device.
2832  * @return
2833  *   - Zero if the port is closed successfully.
2834  *   - Negative if something went wrong.
2835  */
2836 int rte_eth_dev_close(uint16_t port_id);
2837
2838 /**
2839  * Reset a Ethernet device and keep its port ID.
2840  *
2841  * When a port has to be reset passively, the DPDK application can invoke
2842  * this function. For example when a PF is reset, all its VFs should also
2843  * be reset. Normally a DPDK application can invoke this function when
2844  * RTE_ETH_EVENT_INTR_RESET event is detected, but can also use it to start
2845  * a port reset in other circumstances.
2846  *
2847  * When this function is called, it first stops the port and then calls the
2848  * PMD specific dev_uninit( ) and dev_init( ) to return the port to initial
2849  * state, in which no Tx and Rx queues are setup, as if the port has been
2850  * reset and not started. The port keeps the port ID it had before the
2851  * function call.
2852  *
2853  * After calling rte_eth_dev_reset( ), the application should use
2854  * rte_eth_dev_configure( ), rte_eth_rx_queue_setup( ),
2855  * rte_eth_tx_queue_setup( ), and rte_eth_dev_start( )
2856  * to reconfigure the device as appropriate.
2857  *
2858  * Note: To avoid unexpected behavior, the application should stop calling
2859  * Tx and Rx functions before calling rte_eth_dev_reset( ). For thread
2860  * safety, all these controlling functions should be called from the same
2861  * thread.
2862  *
2863  * @param port_id
2864  *   The port identifier of the Ethernet device.
2865  *
2866  * @return
2867  *   - (0) if successful.
2868  *   - (-ENODEV) if *port_id* is invalid.
2869  *   - (-ENOTSUP) if hardware doesn't support this function.
2870  *   - (-EPERM) if not ran from the primary process.
2871  *   - (-EIO) if re-initialisation failed or device is removed.
2872  *   - (-ENOMEM) if the reset failed due to OOM.
2873  *   - (-EAGAIN) if the reset temporarily failed and should be retried later.
2874  */
2875 int rte_eth_dev_reset(uint16_t port_id);
2876
2877 /**
2878  * Enable receipt in promiscuous mode for an Ethernet device.
2879  *
2880  * @param port_id
2881  *   The port identifier of the Ethernet device.
2882  * @return
2883  *   - (0) if successful.
2884  *   - (-ENOTSUP) if support for promiscuous_enable() does not exist
2885  *     for the device.
2886  *   - (-ENODEV) if *port_id* invalid.
2887  */
2888 int rte_eth_promiscuous_enable(uint16_t port_id);
2889
2890 /**
2891  * Disable receipt in promiscuous mode for an Ethernet device.
2892  *
2893  * @param port_id
2894  *   The port identifier of the Ethernet device.
2895  * @return
2896  *   - (0) if successful.
2897  *   - (-ENOTSUP) if support for promiscuous_disable() does not exist
2898  *     for the device.
2899  *   - (-ENODEV) if *port_id* invalid.
2900  */
2901 int rte_eth_promiscuous_disable(uint16_t port_id);
2902
2903 /**
2904  * Return the value of promiscuous mode for an Ethernet device.
2905  *
2906  * @param port_id
2907  *   The port identifier of the Ethernet device.
2908  * @return
2909  *   - (1) if promiscuous is enabled
2910  *   - (0) if promiscuous is disabled.
2911  *   - (-1) on error
2912  */
2913 int rte_eth_promiscuous_get(uint16_t port_id);
2914
2915 /**
2916  * Enable the receipt of any multicast frame by an Ethernet device.
2917  *
2918  * @param port_id
2919  *   The port identifier of the Ethernet device.
2920  * @return
2921  *   - (0) if successful.
2922  *   - (-ENOTSUP) if support for allmulticast_enable() does not exist
2923  *     for the device.
2924  *   - (-ENODEV) if *port_id* invalid.
2925  */
2926 int rte_eth_allmulticast_enable(uint16_t port_id);
2927
2928 /**
2929  * Disable the receipt of all multicast frames by an Ethernet device.
2930  *
2931  * @param port_id
2932  *   The port identifier of the Ethernet device.
2933  * @return
2934  *   - (0) if successful.
2935  *   - (-ENOTSUP) if support for allmulticast_disable() does not exist
2936  *     for the device.
2937  *   - (-ENODEV) if *port_id* invalid.
2938  */
2939 int rte_eth_allmulticast_disable(uint16_t port_id);
2940
2941 /**
2942  * Return the value of allmulticast mode for an Ethernet device.
2943  *
2944  * @param port_id
2945  *   The port identifier of the Ethernet device.
2946  * @return
2947  *   - (1) if allmulticast is enabled
2948  *   - (0) if allmulticast is disabled.
2949  *   - (-1) on error
2950  */
2951 int rte_eth_allmulticast_get(uint16_t port_id);
2952
2953 /**
2954  * Retrieve the link status (up/down), the duplex mode (half/full),
2955  * the negotiation (auto/fixed), and if available, the speed (Mbps).
2956  *
2957  * It might need to wait up to 9 seconds.
2958  * @see rte_eth_link_get_nowait.
2959  *
2960  * @param port_id
2961  *   The port identifier of the Ethernet device.
2962  * @param link
2963  *   Link information written back.
2964  * @return
2965  *   - (0) if successful.
2966  *   - (-ENOTSUP) if the function is not supported in PMD.
2967  *   - (-ENODEV) if *port_id* invalid.
2968  *   - (-EINVAL) if bad parameter.
2969  */
2970 int rte_eth_link_get(uint16_t port_id, struct rte_eth_link *link);
2971
2972 /**
2973  * Retrieve the link status (up/down), the duplex mode (half/full),
2974  * the negotiation (auto/fixed), and if available, the speed (Mbps).
2975  *
2976  * @param port_id
2977  *   The port identifier of the Ethernet device.
2978  * @param link
2979  *   Link information written back.
2980  * @return
2981  *   - (0) if successful.
2982  *   - (-ENOTSUP) if the function is not supported in PMD.
2983  *   - (-ENODEV) if *port_id* invalid.
2984  *   - (-EINVAL) if bad parameter.
2985  */
2986 int rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *link);
2987
2988 /**
2989  * @warning
2990  * @b EXPERIMENTAL: this API may change without prior notice.
2991  *
2992  * The function converts a link_speed to a string. It handles all special
2993  * values like unknown or none speed.
2994  *
2995  * @param link_speed
2996  *   link_speed of rte_eth_link struct
2997  * @return
2998  *   Link speed in textual format. It's pointer to immutable memory.
2999  *   No free is required.
3000  */
3001 __rte_experimental
3002 const char *rte_eth_link_speed_to_str(uint32_t link_speed);
3003
3004 /**
3005  * @warning
3006  * @b EXPERIMENTAL: this API may change without prior notice.
3007  *
3008  * The function converts a rte_eth_link struct representing a link status to
3009  * a string.
3010  *
3011  * @param str
3012  *   A pointer to a string to be filled with textual representation of
3013  *   device status. At least RTE_ETH_LINK_MAX_STR_LEN bytes should be allocated to
3014  *   store default link status text.
3015  * @param len
3016  *   Length of available memory at 'str' string.
3017  * @param eth_link
3018  *   Link status returned by rte_eth_link_get function
3019  * @return
3020  *   Number of bytes written to str array or -EINVAL if bad parameter.
3021  */
3022 __rte_experimental
3023 int rte_eth_link_to_str(char *str, size_t len,
3024                         const struct rte_eth_link *eth_link);
3025
3026 /**
3027  * Retrieve the general I/O statistics of an Ethernet device.
3028  *
3029  * @param port_id
3030  *   The port identifier of the Ethernet device.
3031  * @param stats
3032  *   A pointer to a structure of type *rte_eth_stats* to be filled with
3033  *   the values of device counters for the following set of statistics:
3034  *   - *ipackets* with the total of successfully received packets.
3035  *   - *opackets* with the total of successfully transmitted packets.
3036  *   - *ibytes*   with the total of successfully received bytes.
3037  *   - *obytes*   with the total of successfully transmitted bytes.
3038  *   - *ierrors*  with the total of erroneous received packets.
3039  *   - *oerrors*  with the total of failed transmitted packets.
3040  * @return
3041  *   Zero if successful. Non-zero otherwise.
3042  */
3043 int rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats);
3044
3045 /**
3046  * Reset the general I/O statistics of an Ethernet device.
3047  *
3048  * @param port_id
3049  *   The port identifier of the Ethernet device.
3050  * @return
3051  *   - (0) if device notified to reset stats.
3052  *   - (-ENOTSUP) if hardware doesn't support.
3053  *   - (-ENODEV) if *port_id* invalid.
3054  *   - (<0): Error code of the driver stats reset function.
3055  */
3056 int rte_eth_stats_reset(uint16_t port_id);
3057
3058 /**
3059  * Retrieve names of extended statistics of an Ethernet device.
3060  *
3061  * There is an assumption that 'xstat_names' and 'xstats' arrays are matched
3062  * by array index:
3063  *  xstats_names[i].name => xstats[i].value
3064  *
3065  * And the array index is same with id field of 'struct rte_eth_xstat':
3066  *  xstats[i].id == i
3067  *
3068  * This assumption makes key-value pair matching less flexible but simpler.
3069  *
3070  * @param port_id
3071  *   The port identifier of the Ethernet device.
3072  * @param xstats_names
3073  *   An rte_eth_xstat_name array of at least *size* elements to
3074  *   be filled. If set to NULL, the function returns the required number
3075  *   of elements.
3076  * @param size
3077  *   The size of the xstats_names array (number of elements).
3078  * @return
3079  *   - A positive value lower or equal to size: success. The return value
3080  *     is the number of entries filled in the stats table.
3081  *   - A positive value higher than size: error, the given statistics table
3082  *     is too small. The return value corresponds to the size that should
3083  *     be given to succeed. The entries in the table are not valid and
3084  *     shall not be used by the caller.
3085  *   - A negative value on error (invalid port ID).
3086  */
3087 int rte_eth_xstats_get_names(uint16_t port_id,
3088                 struct rte_eth_xstat_name *xstats_names,
3089                 unsigned int size);
3090
3091 /**
3092  * Retrieve extended statistics of an Ethernet device.
3093  *
3094  * There is an assumption that 'xstat_names' and 'xstats' arrays are matched
3095  * by array index:
3096  *  xstats_names[i].name => xstats[i].value
3097  *
3098  * And the array index is same with id field of 'struct rte_eth_xstat':
3099  *  xstats[i].id == i
3100  *
3101  * This assumption makes key-value pair matching less flexible but simpler.
3102  *
3103  * @param port_id
3104  *   The port identifier of the Ethernet device.
3105  * @param xstats
3106  *   A pointer to a table of structure of type *rte_eth_xstat*
3107  *   to be filled with device statistics ids and values.
3108  *   This parameter can be set to NULL if n is 0.
3109  * @param n
3110  *   The size of the xstats array (number of elements).
3111  * @return
3112  *   - A positive value lower or equal to n: success. The return value
3113  *     is the number of entries filled in the stats table.
3114  *   - A positive value higher than n: error, the given statistics table
3115  *     is too small. The return value corresponds to the size that should
3116  *     be given to succeed. The entries in the table are not valid and
3117  *     shall not be used by the caller.
3118  *   - A negative value on error (invalid port ID).
3119  */
3120 int rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats,
3121                 unsigned int n);
3122
3123 /**
3124  * Retrieve names of extended statistics of an Ethernet device.
3125  *
3126  * @param port_id
3127  *   The port identifier of the Ethernet device.
3128  * @param xstats_names
3129  *   Array to be filled in with names of requested device statistics.
3130  *   Must not be NULL if @p ids are specified (not NULL).
3131  * @param size
3132  *   Number of elements in @p xstats_names array (if not NULL) and in
3133  *   @p ids array (if not NULL). Must be 0 if both array pointers are NULL.
3134  * @param ids
3135  *   IDs array given by app to retrieve specific statistics. May be NULL to
3136  *   retrieve names of all available statistics or, if @p xstats_names is
3137  *   NULL as well, just the number of available statistics.
3138  * @return
3139  *   - A positive value lower or equal to size: success. The return value
3140  *     is the number of entries filled in the stats table.
3141  *   - A positive value higher than size: success. The given statistics table
3142  *     is too small. The return value corresponds to the size that should
3143  *     be given to succeed. The entries in the table are not valid and
3144  *     shall not be used by the caller.
3145  *   - A negative value on error.
3146  */
3147 int
3148 rte_eth_xstats_get_names_by_id(uint16_t port_id,
3149         struct rte_eth_xstat_name *xstats_names, unsigned int size,
3150         uint64_t *ids);
3151
3152 /**
3153  * Retrieve extended statistics of an Ethernet device.
3154  *
3155  * @param port_id
3156  *   The port identifier of the Ethernet device.
3157  * @param ids
3158  *   IDs array given by app to retrieve specific statistics. May be NULL to
3159  *   retrieve all available statistics or, if @p values is NULL as well,
3160  *   just the number of available statistics.
3161  * @param values
3162  *   Array to be filled in with requested device statistics.
3163  *   Must not be NULL if ids are specified (not NULL).
3164  * @param size
3165  *   Number of elements in @p values array (if not NULL) and in @p ids
3166  *   array (if not NULL). Must be 0 if both array pointers are NULL.
3167  * @return
3168  *   - A positive value lower or equal to size: success. The return value
3169  *     is the number of entries filled in the stats table.
3170  *   - A positive value higher than size: success: The given statistics table
3171  *     is too small. The return value corresponds to the size that should
3172  *     be given to succeed. The entries in the table are not valid and
3173  *     shall not be used by the caller.
3174  *   - A negative value on error.
3175  */
3176 int rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
3177                              uint64_t *values, unsigned int size);
3178
3179 /**
3180  * Gets the ID of a statistic from its name.
3181  *
3182  * This function searches for the statistics using string compares, and
3183  * as such should not be used on the fast-path. For fast-path retrieval of
3184  * specific statistics, store the ID as provided in *id* from this function,
3185  * and pass the ID to rte_eth_xstats_get()
3186  *
3187  * @param port_id The port to look up statistics from
3188  * @param xstat_name The name of the statistic to return
3189  * @param[out] id A pointer to an app-supplied uint64_t which should be
3190  *                set to the ID of the stat if the stat exists.
3191  * @return
3192  *    0 on success
3193  *    -ENODEV for invalid port_id,
3194  *    -EIO if device is removed,
3195  *    -EINVAL if the xstat_name doesn't exist in port_id
3196  *    -ENOMEM if bad parameter.
3197  */
3198 int rte_eth_xstats_get_id_by_name(uint16_t port_id, const char *xstat_name,
3199                 uint64_t *id);
3200
3201 /**
3202  * Reset extended statistics of an Ethernet device.
3203  *
3204  * @param port_id
3205  *   The port identifier of the Ethernet device.
3206  * @return
3207  *   - (0) if device notified to reset extended stats.
3208  *   - (-ENOTSUP) if pmd doesn't support both
3209  *     extended stats and basic stats reset.
3210  *   - (-ENODEV) if *port_id* invalid.
3211  *   - (<0): Error code of the driver xstats reset function.
3212  */
3213 int rte_eth_xstats_reset(uint16_t port_id);
3214
3215 /**
3216  *  Set a mapping for the specified transmit queue to the specified per-queue
3217  *  statistics counter.
3218  *
3219  * @param port_id
3220  *   The port identifier of the Ethernet device.
3221  * @param tx_queue_id
3222  *   The index of the transmit queue for which a queue stats mapping is required.
3223  *   The value must be in the range [0, nb_tx_queue - 1] previously supplied
3224  *   to rte_eth_dev_configure().
3225  * @param stat_idx
3226  *   The per-queue packet statistics functionality number that the transmit
3227  *   queue is to be assigned.
3228  *   The value must be in the range [0, RTE_ETHDEV_QUEUE_STAT_CNTRS - 1].
3229  *   Max RTE_ETHDEV_QUEUE_STAT_CNTRS being 256.
3230  * @return
3231  *   Zero if successful. Non-zero otherwise.
3232  */
3233 int rte_eth_dev_set_tx_queue_stats_mapping(uint16_t port_id,
3234                 uint16_t tx_queue_id, uint8_t stat_idx);
3235
3236 /**
3237  *  Set a mapping for the specified receive queue to the specified per-queue
3238  *  statistics counter.
3239  *
3240  * @param port_id
3241  *   The port identifier of the Ethernet device.
3242  * @param rx_queue_id
3243  *   The index of the receive queue for which a queue stats mapping is required.
3244  *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
3245  *   to rte_eth_dev_configure().
3246  * @param stat_idx
3247  *   The per-queue packet statistics functionality number that the receive
3248  *   queue is to be assigned.
3249  *   The value must be in the range [0, RTE_ETHDEV_QUEUE_STAT_CNTRS - 1].
3250  *   Max RTE_ETHDEV_QUEUE_STAT_CNTRS being 256.
3251  * @return
3252  *   Zero if successful. Non-zero otherwise.
3253  */
3254 int rte_eth_dev_set_rx_queue_stats_mapping(uint16_t port_id,
3255                                            uint16_t rx_queue_id,
3256                                            uint8_t stat_idx);
3257
3258 /**
3259  * Retrieve the Ethernet address of an Ethernet device.
3260  *
3261  * @param port_id
3262  *   The port identifier of the Ethernet device.
3263  * @param mac_addr
3264  *   A pointer to a structure of type *ether_addr* to be filled with
3265  *   the Ethernet address of the Ethernet device.
3266  * @return
3267  *   - (0) if successful
3268  *   - (-ENODEV) if *port_id* invalid.
3269  *   - (-EINVAL) if bad parameter.
3270  */
3271 int rte_eth_macaddr_get(uint16_t port_id, struct rte_ether_addr *mac_addr);
3272
3273 /**
3274  * @warning
3275  * @b EXPERIMENTAL: this API may change without prior notice
3276  *
3277  * Retrieve the Ethernet addresses of an Ethernet device.
3278  *
3279  * @param port_id
3280  *   The port identifier of the Ethernet device.
3281  * @param ma
3282  *   A pointer to an array of structures of type *ether_addr* to be filled with
3283  *   the Ethernet addresses of the Ethernet device.
3284  * @param num
3285  *   Number of elements in the @p ma array.
3286  *   Note that  rte_eth_dev_info::max_mac_addrs can be used to retrieve
3287  *   max number of Ethernet addresses for given port.
3288  * @return
3289  *   - number of retrieved addresses if successful
3290  *   - (-ENODEV) if *port_id* invalid.
3291  *   - (-EINVAL) if bad parameter.
3292  */
3293 __rte_experimental
3294 int rte_eth_macaddrs_get(uint16_t port_id, struct rte_ether_addr *ma,
3295         unsigned int num);
3296
3297 /**
3298  * Retrieve the contextual information of an Ethernet device.
3299  *
3300  * As part of this function, a number of of fields in dev_info will be
3301  * initialized as follows:
3302  *
3303  * rx_desc_lim = lim
3304  * tx_desc_lim = lim
3305  *
3306  * Where lim is defined within the rte_eth_dev_info_get as
3307  *
3308  *  const struct rte_eth_desc_lim lim = {
3309  *      .nb_max = UINT16_MAX,
3310  *      .nb_min = 0,
3311  *      .nb_align = 1,
3312  *      .nb_seg_max = UINT16_MAX,
3313  *      .nb_mtu_seg_max = UINT16_MAX,
3314  *  };
3315  *
3316  * device = dev->device
3317  * min_mtu = RTE_ETHER_MIN_LEN - RTE_ETHER_HDR_LEN - RTE_ETHER_CRC_LEN
3318  * max_mtu = UINT16_MAX
3319  *
3320  * The following fields will be populated if support for dev_infos_get()
3321  * exists for the device and the rte_eth_dev 'dev' has been populated
3322  * successfully with a call to it:
3323  *
3324  * driver_name = dev->device->driver->name
3325  * nb_rx_queues = dev->data->nb_rx_queues
3326  * nb_tx_queues = dev->data->nb_tx_queues
3327  * dev_flags = &dev->data->dev_flags
3328  *
3329  * @param port_id
3330  *   The port identifier of the Ethernet device.
3331  * @param dev_info
3332  *   A pointer to a structure of type *rte_eth_dev_info* to be filled with
3333  *   the contextual information of the Ethernet device.
3334  * @return
3335  *   - (0) if successful.
3336  *   - (-ENOTSUP) if support for dev_infos_get() does not exist for the device.
3337  *   - (-ENODEV) if *port_id* invalid.
3338  *   - (-EINVAL) if bad parameter.
3339  */
3340 int rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info);
3341
3342 /**
3343  * @warning
3344  * @b EXPERIMENTAL: this API may change without prior notice.
3345  *
3346  * Retrieve the configuration of an Ethernet device.
3347  *
3348  * @param port_id
3349  *   The port identifier of the Ethernet device.
3350  * @param dev_conf
3351  *   Location for Ethernet device configuration to be filled in.
3352  * @return
3353  *   - (0) if successful.
3354  *   - (-ENODEV) if *port_id* invalid.
3355  *   - (-EINVAL) if bad parameter.
3356  */
3357 __rte_experimental
3358 int rte_eth_dev_conf_get(uint16_t port_id, struct rte_eth_conf *dev_conf);
3359
3360 /**
3361  * Retrieve the firmware version of a device.
3362  *
3363  * @param port_id
3364  *   The port identifier of the device.
3365  * @param fw_version
3366  *   A pointer to a string array storing the firmware version of a device,
3367  *   the string includes terminating null. This pointer is allocated by caller.
3368  * @param fw_size
3369  *   The size of the string array pointed by fw_version, which should be
3370  *   large enough to store firmware version of the device.
3371  * @return
3372  *   - (0) if successful.
3373  *   - (-ENOTSUP) if operation is not supported.
3374  *   - (-ENODEV) if *port_id* invalid.
3375  *   - (-EIO) if device is removed.
3376  *   - (-EINVAL) if bad parameter.
3377  *   - (>0) if *fw_size* is not enough to store firmware version, return
3378  *          the size of the non truncated string.
3379  */
3380 int rte_eth_dev_fw_version_get(uint16_t port_id,
3381                                char *fw_version, size_t fw_size);
3382
3383 /**
3384  * Retrieve the supported packet types of an Ethernet device.
3385  *
3386  * When a packet type is announced as supported, it *must* be recognized by
3387  * the PMD. For instance, if RTE_PTYPE_L2_ETHER, RTE_PTYPE_L2_ETHER_VLAN
3388  * and RTE_PTYPE_L3_IPV4 are announced, the PMD must return the following
3389  * packet types for these packets:
3390  * - Ether/IPv4              -> RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4
3391  * - Ether/VLAN/IPv4         -> RTE_PTYPE_L2_ETHER_VLAN | RTE_PTYPE_L3_IPV4
3392  * - Ether/[anything else]   -> RTE_PTYPE_L2_ETHER
3393  * - Ether/VLAN/[anything else] -> RTE_PTYPE_L2_ETHER_VLAN
3394  *
3395  * When a packet is received by a PMD, the most precise type must be
3396  * returned among the ones supported. However a PMD is allowed to set
3397  * packet type that is not in the supported list, at the condition that it
3398  * is more precise. Therefore, a PMD announcing no supported packet types
3399  * can still set a matching packet type in a received packet.
3400  *
3401  * @note
3402  *   Better to invoke this API after the device is already started or Rx burst
3403  *   function is decided, to obtain correct supported ptypes.
3404  * @note
3405  *   if a given PMD does not report what ptypes it supports, then the supported
3406  *   ptype count is reported as 0.
3407  * @param port_id
3408  *   The port identifier of the Ethernet device.
3409  * @param ptype_mask
3410  *   A hint of what kind of packet type which the caller is interested in.
3411  * @param ptypes
3412  *   An array pointer to store adequate packet types, allocated by caller.
3413  * @param num
3414  *  Size of the array pointed by param ptypes.
3415  * @return
3416  *   - (>=0) Number of supported ptypes. If the number of types exceeds num,
3417  *           only num entries will be filled into the ptypes array, but the full
3418  *           count of supported ptypes will be returned.
3419  *   - (-ENODEV) if *port_id* invalid.
3420  *   - (-EINVAL) if bad parameter.
3421  */
3422 int rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
3423                                      uint32_t *ptypes, int num);
3424 /**
3425  * Inform Ethernet device about reduced range of packet types to handle.
3426  *
3427  * Application can use this function to set only specific ptypes that it's
3428  * interested. This information can be used by the PMD to optimize Rx path.
3429  *
3430  * The function accepts an array `set_ptypes` allocated by the caller to
3431  * store the packet types set by the driver, the last element of the array
3432  * is set to RTE_PTYPE_UNKNOWN. The size of the `set_ptype` array should be
3433  * `rte_eth_dev_get_supported_ptypes() + 1` else it might only be filled
3434  * partially.
3435  *
3436  * @param port_id
3437  *   The port identifier of the Ethernet device.
3438  * @param ptype_mask
3439  *   The ptype family that application is interested in should be bitwise OR of
3440  *   RTE_PTYPE_*_MASK or 0.
3441  * @param set_ptypes
3442  *   An array pointer to store set packet types, allocated by caller. The
3443  *   function marks the end of array with RTE_PTYPE_UNKNOWN.
3444  * @param num
3445  *   Size of the array pointed by param ptypes.
3446  *   Should be rte_eth_dev_get_supported_ptypes() + 1 to accommodate the
3447  *   set ptypes.
3448  * @return
3449  *   - (0) if Success.
3450  *   - (-ENODEV) if *port_id* invalid.
3451  *   - (-EINVAL) if *ptype_mask* is invalid (or) set_ptypes is NULL and
3452  *     num > 0.
3453  */
3454 int rte_eth_dev_set_ptypes(uint16_t port_id, uint32_t ptype_mask,
3455                            uint32_t *set_ptypes, unsigned int num);
3456
3457 /**
3458  * Retrieve the MTU of an Ethernet device.
3459  *
3460  * @param port_id
3461  *   The port identifier of the Ethernet device.
3462  * @param mtu
3463  *   A pointer to a uint16_t where the retrieved MTU is to be stored.
3464  * @return
3465  *   - (0) if successful.
3466  *   - (-ENODEV) if *port_id* invalid.
3467  *   - (-EINVAL) if bad parameter.
3468  */
3469 int rte_eth_dev_get_mtu(uint16_t port_id, uint16_t *mtu);
3470
3471 /**
3472  * Change the MTU of an Ethernet device.
3473  *
3474  * @param port_id
3475  *   The port identifier of the Ethernet device.
3476  * @param mtu
3477  *   A uint16_t for the MTU to be applied.
3478  * @return
3479  *   - (0) if successful.
3480  *   - (-ENOTSUP) if operation is not supported.
3481  *   - (-ENODEV) if *port_id* invalid.
3482  *   - (-EIO) if device is removed.
3483  *   - (-EINVAL) if *mtu* invalid, validation of mtu can occur within
3484  *     rte_eth_dev_set_mtu if dev_infos_get is supported by the device or
3485  *     when the mtu is set using dev->dev_ops->mtu_set.
3486  *   - (-EBUSY) if operation is not allowed when the port is running
3487  */
3488 int rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu);
3489
3490 /**
3491  * Enable/Disable hardware filtering by an Ethernet device of received
3492  * VLAN packets tagged with a given VLAN Tag Identifier.
3493  *
3494  * @param port_id
3495  *   The port identifier of the Ethernet device.
3496  * @param vlan_id
3497  *   The VLAN Tag Identifier whose filtering must be enabled or disabled.
3498  * @param on
3499  *   If > 0, enable VLAN filtering of VLAN packets tagged with *vlan_id*.
3500  *   Otherwise, disable VLAN filtering of VLAN packets tagged with *vlan_id*.
3501  * @return
3502  *   - (0) if successful.
3503  *   - (-ENOTSUP) if hardware-assisted VLAN filtering not configured.
3504  *   - (-ENODEV) if *port_id* invalid.
3505  *   - (-EIO) if device is removed.
3506  *   - (-ENOSYS) if VLAN filtering on *port_id* disabled.
3507  *   - (-EINVAL) if *vlan_id* > 4095.
3508  */
3509 int rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on);
3510
3511 /**
3512  * Enable/Disable hardware VLAN Strip by a Rx queue of an Ethernet device.
3513  *
3514  * @param port_id
3515  *   The port identifier of the Ethernet device.
3516  * @param rx_queue_id
3517  *   The index of the receive queue for which a queue stats mapping is required.
3518  *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
3519  *   to rte_eth_dev_configure().
3520  * @param on
3521  *   If 1, Enable VLAN Stripping of the receive queue of the Ethernet port.
3522  *   If 0, Disable VLAN Stripping of the receive queue of the Ethernet port.
3523  * @return
3524  *   - (0) if successful.
3525  *   - (-ENOTSUP) if hardware-assisted VLAN stripping not configured.
3526  *   - (-ENODEV) if *port_id* invalid.
3527  *   - (-EINVAL) if *rx_queue_id* invalid.
3528  */
3529 int rte_eth_dev_set_vlan_strip_on_queue(uint16_t port_id, uint16_t rx_queue_id,
3530                 int on);
3531
3532 /**
3533  * Set the Outer VLAN Ether Type by an Ethernet device, it can be inserted to
3534  * the VLAN header.
3535  *
3536  * @param port_id
3537  *   The port identifier of the Ethernet device.
3538  * @param vlan_type
3539  *   The VLAN type.
3540  * @param tag_type
3541  *   The Tag Protocol ID
3542  * @return
3543  *   - (0) if successful.
3544  *   - (-ENOTSUP) if hardware-assisted VLAN TPID setup is not supported.
3545  *   - (-ENODEV) if *port_id* invalid.
3546  *   - (-EIO) if device is removed.
3547  */
3548 int rte_eth_dev_set_vlan_ether_type(uint16_t port_id,
3549                                     enum rte_vlan_type vlan_type,
3550                                     uint16_t tag_type);
3551
3552 /**
3553  * Set VLAN offload configuration on an Ethernet device.
3554  *
3555  * @param port_id
3556  *   The port identifier of the Ethernet device.
3557  * @param offload_mask
3558  *   The VLAN Offload bit mask can be mixed use with "OR"
3559  *       RTE_ETH_VLAN_STRIP_OFFLOAD
3560  *       RTE_ETH_VLAN_FILTER_OFFLOAD
3561  *       RTE_ETH_VLAN_EXTEND_OFFLOAD
3562  *       RTE_ETH_QINQ_STRIP_OFFLOAD
3563  * @return
3564  *   - (0) if successful.
3565  *   - (-ENOTSUP) if hardware-assisted VLAN filtering not configured.
3566  *   - (-ENODEV) if *port_id* invalid.
3567  *   - (-EIO) if device is removed.
3568  */
3569 int rte_eth_dev_set_vlan_offload(uint16_t port_id, int offload_mask);
3570
3571 /**
3572  * Read VLAN Offload configuration from an Ethernet device
3573  *
3574  * @param port_id
3575  *   The port identifier of the Ethernet device.
3576  * @return
3577  *   - (>0) if successful. Bit mask to indicate
3578  *       RTE_ETH_VLAN_STRIP_OFFLOAD
3579  *       RTE_ETH_VLAN_FILTER_OFFLOAD
3580  *       RTE_ETH_VLAN_EXTEND_OFFLOAD
3581  *       RTE_ETH_QINQ_STRIP_OFFLOAD
3582  *   - (-ENODEV) if *port_id* invalid.
3583  */
3584 int rte_eth_dev_get_vlan_offload(uint16_t port_id);
3585
3586 /**
3587  * Set port based Tx VLAN insertion on or off.
3588  *
3589  * @param port_id
3590  *  The port identifier of the Ethernet device.
3591  * @param pvid
3592  *  Port based Tx VLAN identifier together with user priority.
3593  * @param on
3594  *  Turn on or off the port based Tx VLAN insertion.
3595  *
3596  * @return
3597  *   - (0) if successful.
3598  *   - negative if failed.
3599  */
3600 int rte_eth_dev_set_vlan_pvid(uint16_t port_id, uint16_t pvid, int on);
3601
3602 typedef void (*buffer_tx_error_fn)(struct rte_mbuf **unsent, uint16_t count,
3603                 void *userdata);
3604
3605 /**
3606  * Structure used to buffer packets for future Tx
3607  * Used by APIs rte_eth_tx_buffer and rte_eth_tx_buffer_flush
3608  */
3609 struct rte_eth_dev_tx_buffer {
3610         buffer_tx_error_fn error_callback;
3611         void *error_userdata;
3612         uint16_t size;           /**< Size of buffer for buffered Tx */
3613         uint16_t length;         /**< Number of packets in the array */
3614         /** Pending packets to be sent on explicit flush or when full */
3615         struct rte_mbuf *pkts[];
3616 };
3617
3618 /**
3619  * Calculate the size of the Tx buffer.
3620  *
3621  * @param sz
3622  *   Number of stored packets.
3623  */
3624 #define RTE_ETH_TX_BUFFER_SIZE(sz) \
3625         (sizeof(struct rte_eth_dev_tx_buffer) + (sz) * sizeof(struct rte_mbuf *))
3626
3627 /**
3628  * Initialize default values for buffered transmitting
3629  *
3630  * @param buffer
3631  *   Tx buffer to be initialized.
3632  * @param size
3633  *   Buffer size
3634  * @return
3635  *   0 if no error
3636  */
3637 int
3638 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size);
3639
3640 /**
3641  * Configure a callback for buffered packets which cannot be sent
3642  *
3643  * Register a specific callback to be called when an attempt is made to send
3644  * all packets buffered on an Ethernet port, but not all packets can
3645  * successfully be sent. The callback registered here will be called only
3646  * from calls to rte_eth_tx_buffer() and rte_eth_tx_buffer_flush() APIs.
3647  * The default callback configured for each queue by default just frees the
3648  * packets back to the calling mempool. If additional behaviour is required,
3649  * for example, to count dropped packets, or to retry transmission of packets
3650  * which cannot be sent, this function should be used to register a suitable
3651  * callback function to implement the desired behaviour.
3652  * The example callback "rte_eth_count_unsent_packet_callback()" is also
3653  * provided as reference.
3654  *
3655  * @param buffer
3656  *   The port identifier of the Ethernet device.
3657  * @param callback
3658  *   The function to be used as the callback.
3659  * @param userdata
3660  *   Arbitrary parameter to be passed to the callback function
3661  * @return
3662  *   0 on success, or -EINVAL if bad parameter
3663  */
3664 int
3665 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
3666                 buffer_tx_error_fn callback, void *userdata);
3667
3668 /**
3669  * Callback function for silently dropping unsent buffered packets.
3670  *
3671  * This function can be passed to rte_eth_tx_buffer_set_err_callback() to
3672  * adjust the default behavior when buffered packets cannot be sent. This
3673  * function drops any unsent packets silently and is used by Tx buffered
3674  * operations as default behavior.
3675  *
3676  * NOTE: this function should not be called directly, instead it should be used
3677  *       as a callback for packet buffering.
3678  *
3679  * NOTE: when configuring this function as a callback with
3680  *       rte_eth_tx_buffer_set_err_callback(), the final, userdata parameter
3681  *       should point to an uint64_t value.
3682  *
3683  * @param pkts
3684  *   The previously buffered packets which could not be sent
3685  * @param unsent
3686  *   The number of unsent packets in the pkts array
3687  * @param userdata
3688  *   Not used
3689  */
3690 void
3691 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
3692                 void *userdata);
3693
3694 /**
3695  * Callback function for tracking unsent buffered packets.
3696  *
3697  * This function can be passed to rte_eth_tx_buffer_set_err_callback() to
3698  * adjust the default behavior when buffered packets cannot be sent. This
3699  * function drops any unsent packets, but also updates a user-supplied counter
3700  * to track the overall number of packets dropped. The counter should be an
3701  * uint64_t variable.
3702  *
3703  * NOTE: this function should not be called directly, instead it should be used
3704  *       as a callback for packet buffering.
3705  *
3706  * NOTE: when configuring this function as a callback with
3707  *       rte_eth_tx_buffer_set_err_callback(), the final, userdata parameter
3708  *       should point to an uint64_t value.
3709  *
3710  * @param pkts
3711  *   The previously buffered packets which could not be sent
3712  * @param unsent
3713  *   The number of unsent packets in the pkts array
3714  * @param userdata
3715  *   Pointer to an uint64_t value, which will be incremented by unsent
3716  */
3717 void
3718 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
3719                 void *userdata);
3720
3721 /**
3722  * Request the driver to free mbufs currently cached by the driver. The
3723  * driver will only free the mbuf if it is no longer in use. It is the
3724  * application's responsibility to ensure rte_eth_tx_buffer_flush(..) is
3725  * called if needed.
3726  *
3727  * @param port_id
3728  *   The port identifier of the Ethernet device.
3729  * @param queue_id
3730  *   The index of the transmit queue through which output packets must be
3731  *   sent.
3732  *   The value must be in the range [0, nb_tx_queue - 1] previously supplied
3733  *   to rte_eth_dev_configure().
3734  * @param free_cnt
3735  *   Maximum number of packets to free. Use 0 to indicate all possible packets
3736  *   should be freed. Note that a packet may be using multiple mbufs.
3737  * @return
3738  *   Failure: < 0
3739  *     -ENODEV: Invalid interface
3740  *     -EIO: device is removed
3741  *     -ENOTSUP: Driver does not support function
3742  *   Success: >= 0
3743  *     0-n: Number of packets freed. More packets may still remain in ring that
3744  *     are in use.
3745  */
3746 int
3747 rte_eth_tx_done_cleanup(uint16_t port_id, uint16_t queue_id, uint32_t free_cnt);
3748
3749 /**
3750  * Subtypes for IPsec offload event(@ref RTE_ETH_EVENT_IPSEC) raised by
3751  * eth device.
3752  */
3753 enum rte_eth_event_ipsec_subtype {
3754         /** Unknown event type */
3755         RTE_ETH_EVENT_IPSEC_UNKNOWN = 0,
3756         /** Sequence number overflow */
3757         RTE_ETH_EVENT_IPSEC_ESN_OVERFLOW,
3758         /** Soft time expiry of SA */
3759         RTE_ETH_EVENT_IPSEC_SA_TIME_EXPIRY,
3760         /** Soft byte expiry of SA */
3761         RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY,
3762         /** Max value of this enum */
3763         RTE_ETH_EVENT_IPSEC_MAX
3764 };
3765
3766 /**
3767  * Descriptor for @ref RTE_ETH_EVENT_IPSEC event. Used by eth dev to send extra
3768  * information of the IPsec offload event.
3769  */
3770 struct rte_eth_event_ipsec_desc {
3771         /** Type of RTE_ETH_EVENT_IPSEC_* event */
3772         enum rte_eth_event_ipsec_subtype subtype;
3773         /**
3774          * Event specific metadata.
3775          *
3776          * For the following events, *userdata* registered
3777          * with the *rte_security_session* would be returned
3778          * as metadata,
3779          *
3780          * - @ref RTE_ETH_EVENT_IPSEC_ESN_OVERFLOW
3781          * - @ref RTE_ETH_EVENT_IPSEC_SA_TIME_EXPIRY
3782          * - @ref RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY
3783          *
3784          * @see struct rte_security_session_conf
3785          *
3786          */
3787         uint64_t metadata;
3788 };
3789
3790 /**
3791  * The eth device event type for interrupt, and maybe others in the future.
3792  */
3793 enum rte_eth_event_type {
3794         RTE_ETH_EVENT_UNKNOWN,  /**< unknown event type */
3795         RTE_ETH_EVENT_INTR_LSC, /**< lsc interrupt event */
3796         /** queue state event (enabled/disabled) */
3797         RTE_ETH_EVENT_QUEUE_STATE,
3798         /** reset interrupt event, sent to VF on PF reset */
3799         RTE_ETH_EVENT_INTR_RESET,
3800         RTE_ETH_EVENT_VF_MBOX,  /**< message from the VF received by PF */
3801         RTE_ETH_EVENT_MACSEC,   /**< MACsec offload related event */
3802         RTE_ETH_EVENT_INTR_RMV, /**< device removal event */
3803         RTE_ETH_EVENT_NEW,      /**< port is probed */
3804         RTE_ETH_EVENT_DESTROY,  /**< port is released */
3805         RTE_ETH_EVENT_IPSEC,    /**< IPsec offload related event */
3806         RTE_ETH_EVENT_FLOW_AGED,/**< New aged-out flows is detected */
3807         RTE_ETH_EVENT_MAX       /**< max value of this enum */
3808 };
3809
3810 /** User application callback to be registered for interrupts. */
3811 typedef int (*rte_eth_dev_cb_fn)(uint16_t port_id,
3812                 enum rte_eth_event_type event, void *cb_arg, void *ret_param);
3813
3814 /**
3815  * Register a callback function for port event.
3816  *
3817  * @param port_id
3818  *  Port ID.
3819  *  RTE_ETH_ALL means register the event for all port ids.
3820  * @param event
3821  *  Event interested.
3822  * @param cb_fn
3823  *  User supplied callback function to be called.
3824  * @param cb_arg
3825  *  Pointer to the parameters for the registered callback.
3826  *
3827  * @return
3828  *  - On success, zero.
3829  *  - On failure, a negative value.
3830  */
3831 int rte_eth_dev_callback_register(uint16_t port_id,
3832                         enum rte_eth_event_type event,
3833                 rte_eth_dev_cb_fn cb_fn, void *cb_arg);
3834
3835 /**
3836  * Unregister a callback function for port event.
3837  *
3838  * @param port_id
3839  *  Port ID.
3840  *  RTE_ETH_ALL means unregister the event for all port ids.
3841  * @param event
3842  *  Event interested.
3843  * @param cb_fn
3844  *  User supplied callback function to be called.
3845  * @param cb_arg
3846  *  Pointer to the parameters for the registered callback. -1 means to
3847  *  remove all for the same callback address and same event.
3848  *
3849  * @return
3850  *  - On success, zero.
3851  *  - On failure, a negative value.
3852  */
3853 int rte_eth_dev_callback_unregister(uint16_t port_id,
3854                         enum rte_eth_event_type event,
3855                 rte_eth_dev_cb_fn cb_fn, void *cb_arg);
3856
3857 /**
3858  * When there is no Rx packet coming in Rx Queue for a long time, we can
3859  * sleep lcore related to Rx Queue for power saving, and enable Rx interrupt
3860  * to be triggered when Rx packet arrives.
3861  *
3862  * The rte_eth_dev_rx_intr_enable() function enables Rx queue
3863  * interrupt on specific Rx queue of a port.
3864  *
3865  * @param port_id
3866  *   The port identifier of the Ethernet device.
3867  * @param queue_id
3868  *   The index of the receive queue from which to retrieve input packets.
3869  *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
3870  *   to rte_eth_dev_configure().
3871  * @return
3872  *   - (0) if successful.
3873  *   - (-ENOTSUP) if underlying hardware OR driver doesn't support
3874  *     that operation.
3875  *   - (-ENODEV) if *port_id* invalid.
3876  *   - (-EIO) if device is removed.
3877  */
3878 int rte_eth_dev_rx_intr_enable(uint16_t port_id, uint16_t queue_id);
3879
3880 /**
3881  * When lcore wakes up from Rx interrupt indicating packet coming, disable Rx
3882  * interrupt and returns to polling mode.
3883  *
3884  * The rte_eth_dev_rx_intr_disable() function disables Rx queue
3885  * interrupt on specific Rx queue of a port.
3886  *
3887  * @param port_id
3888  *   The port identifier of the Ethernet device.
3889  * @param queue_id
3890  *   The index of the receive queue from which to retrieve input packets.
3891  *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
3892  *   to rte_eth_dev_configure().
3893  * @return
3894  *   - (0) if successful.
3895  *   - (-ENOTSUP) if underlying hardware OR driver doesn't support
3896  *     that operation.
3897  *   - (-ENODEV) if *port_id* invalid.
3898  *   - (-EIO) if device is removed.
3899  */
3900 int rte_eth_dev_rx_intr_disable(uint16_t port_id, uint16_t queue_id);
3901
3902 /**
3903  * Rx Interrupt control per port.
3904  *
3905  * @param port_id
3906  *   The port identifier of the Ethernet device.
3907  * @param epfd
3908  *   Epoll instance fd which the intr vector associated to.
3909  *   Using RTE_EPOLL_PER_THREAD allows to use per thread epoll instance.
3910  * @param op
3911  *   The operation be performed for the vector.
3912  *   Operation type of {RTE_INTR_EVENT_ADD, RTE_INTR_EVENT_DEL}.
3913  * @param data
3914  *   User raw data.
3915  * @return
3916  *   - On success, zero.
3917  *   - On failure, a negative value.
3918  */
3919 int rte_eth_dev_rx_intr_ctl(uint16_t port_id, int epfd, int op, void *data);
3920
3921 /**
3922  * Rx Interrupt control per queue.
3923  *
3924  * @param port_id
3925  *   The port identifier of the Ethernet device.
3926  * @param queue_id
3927  *   The index of the receive queue from which to retrieve input packets.
3928  *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
3929  *   to rte_eth_dev_configure().
3930  * @param epfd
3931  *   Epoll instance fd which the intr vector associated to.
3932  *   Using RTE_EPOLL_PER_THREAD allows to use per thread epoll instance.
3933  * @param op
3934  *   The operation be performed for the vector.
3935  *   Operation type of {RTE_INTR_EVENT_ADD, RTE_INTR_EVENT_DEL}.
3936  * @param data
3937  *   User raw data.
3938  * @return
3939  *   - On success, zero.
3940  *   - On failure, a negative value.
3941  */
3942 int rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id,
3943                               int epfd, int op, void *data);
3944
3945 /**
3946  * Get interrupt fd per Rx queue.
3947  *
3948  * @param port_id
3949  *   The port identifier of the Ethernet device.
3950  * @param queue_id
3951  *   The index of the receive queue from which to retrieve input packets.
3952  *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
3953  *   to rte_eth_dev_configure().
3954  * @return
3955  *   - (>=0) the interrupt fd associated to the requested Rx queue if
3956  *           successful.
3957  *   - (-1) on error.
3958  */
3959 int
3960 rte_eth_dev_rx_intr_ctl_q_get_fd(uint16_t port_id, uint16_t queue_id);
3961
3962 /**
3963  * Turn on the LED on the Ethernet device.
3964  * This function turns on the LED on the Ethernet device.
3965  *
3966  * @param port_id
3967  *   The port identifier of the Ethernet device.
3968  * @return
3969  *   - (0) if successful.
3970  *   - (-ENOTSUP) if underlying hardware OR driver doesn't support
3971  *     that operation.
3972  *   - (-ENODEV) if *port_id* invalid.
3973  *   - (-EIO) if device is removed.
3974  */
3975 int  rte_eth_led_on(uint16_t port_id);
3976
3977 /**
3978  * Turn off the LED on the Ethernet device.
3979  * This function turns off the LED on the Ethernet device.
3980  *
3981  * @param port_id
3982  *   The port identifier of the Ethernet device.
3983  * @return
3984  *   - (0) if successful.
3985  *   - (-ENOTSUP) if underlying hardware OR driver doesn't support
3986  *     that operation.
3987  *   - (-ENODEV) if *port_id* invalid.
3988  *   - (-EIO) if device is removed.
3989  */
3990 int  rte_eth_led_off(uint16_t port_id);
3991
3992 /**
3993  * @warning
3994  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
3995  *
3996  * Get Forward Error Correction(FEC) capability.
3997  *
3998  * @param port_id
3999  *   The port identifier of the Ethernet device.
4000  * @param speed_fec_capa
4001  *   speed_fec_capa is out only with per-speed capabilities.
4002  *   If set to NULL, the function returns the required number
4003  *   of required array entries.
4004  * @param num
4005  *   a number of elements in an speed_fec_capa array.
4006  *
4007  * @return
4008  *   - A non-negative value lower or equal to num: success. The return value
4009  *     is the number of entries filled in the fec capa array.
4010  *   - A non-negative value higher than num: error, the given fec capa array
4011  *     is too small. The return value corresponds to the num that should
4012  *     be given to succeed. The entries in fec capa array are not valid and
4013  *     shall not be used by the caller.
4014  *   - (-ENOTSUP) if underlying hardware OR driver doesn't support.
4015  *     that operation.
4016  *   - (-EIO) if device is removed.
4017  *   - (-ENODEV)  if *port_id* invalid.
4018  *   - (-EINVAL)  if *num* or *speed_fec_capa* invalid
4019  */
4020 __rte_experimental
4021 int rte_eth_fec_get_capability(uint16_t port_id,
4022                                struct rte_eth_fec_capa *speed_fec_capa,
4023                                unsigned int num);
4024
4025 /**
4026  * @warning
4027  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
4028  *
4029  * Get current Forward Error Correction(FEC) mode.
4030  * If link is down and AUTO is enabled, AUTO is returned, otherwise,
4031  * configured FEC mode is returned.
4032  * If link is up, current FEC mode is returned.
4033  *
4034  * @param port_id
4035  *   The port identifier of the Ethernet device.
4036  * @param fec_capa
4037  *   A bitmask of enabled FEC modes. If AUTO bit is set, other
4038  *   bits specify FEC modes which may be negotiated. If AUTO
4039  *   bit is clear, specify FEC modes to be used (only one valid
4040  *   mode per speed may be set).
4041  * @return
4042  *   - (0) if successful.
4043  *   - (-ENOTSUP) if underlying hardware OR driver doesn't support.
4044  *     that operation.
4045  *   - (-EIO) if device is removed.
4046  *   - (-ENODEV)  if *port_id* invalid.
4047  */
4048 __rte_experimental
4049 int rte_eth_fec_get(uint16_t port_id, uint32_t *fec_capa);
4050
4051 /**
4052  * @warning
4053  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
4054  *
4055  * Set Forward Error Correction(FEC) mode.
4056  *
4057  * @param port_id
4058  *   The port identifier of the Ethernet device.
4059  * @param fec_capa
4060  *   A bitmask of allowed FEC modes. If AUTO bit is set, other
4061  *   bits specify FEC modes which may be negotiated. If AUTO
4062  *   bit is clear, specify FEC modes to be used (only one valid
4063  *   mode per speed may be set).
4064  * @return
4065  *   - (0) if successful.
4066  *   - (-EINVAL) if the FEC mode is not valid.
4067  *   - (-ENOTSUP) if underlying hardware OR driver doesn't support.
4068  *   - (-EIO) if device is removed.
4069  *   - (-ENODEV)  if *port_id* invalid.
4070  */
4071 __rte_experimental
4072 int rte_eth_fec_set(uint16_t port_id, uint32_t fec_capa);
4073
4074 /**
4075  * Get current status of the Ethernet link flow control for Ethernet device
4076  *
4077  * @param port_id
4078  *   The port identifier of the Ethernet device.
4079  * @param fc_conf
4080  *   The pointer to the structure where to store the flow control parameters.
4081  * @return
4082  *   - (0) if successful.
4083  *   - (-ENOTSUP) if hardware doesn't support flow control.
4084  *   - (-ENODEV)  if *port_id* invalid.
4085  *   - (-EIO)  if device is removed.
4086  *   - (-EINVAL) if bad parameter.
4087  */
4088 int rte_eth_dev_flow_ctrl_get(uint16_t port_id,
4089                               struct rte_eth_fc_conf *fc_conf);
4090
4091 /**
4092  * Configure the Ethernet link flow control for Ethernet device
4093  *
4094  * @param port_id
4095  *   The port identifier of the Ethernet device.
4096  * @param fc_conf
4097  *   The pointer to the structure of the flow control parameters.
4098  * @return
4099  *   - (0) if successful.
4100  *   - (-ENOTSUP) if hardware doesn't support flow control mode.
4101  *   - (-ENODEV)  if *port_id* invalid.
4102  *   - (-EINVAL)  if bad parameter
4103  *   - (-EIO)     if flow control setup failure or device is removed.
4104  */
4105 int rte_eth_dev_flow_ctrl_set(uint16_t port_id,
4106                               struct rte_eth_fc_conf *fc_conf);
4107
4108 /**
4109  * Configure the Ethernet priority flow control under DCB environment
4110  * for Ethernet device.
4111  *
4112  * @param port_id
4113  * The port identifier of the Ethernet device.
4114  * @param pfc_conf
4115  * The pointer to the structure of the priority flow control parameters.
4116  * @return
4117  *   - (0) if successful.
4118  *   - (-ENOTSUP) if hardware doesn't support priority flow control mode.
4119  *   - (-ENODEV)  if *port_id* invalid.
4120  *   - (-EINVAL)  if bad parameter
4121  *   - (-EIO)     if flow control setup failure or device is removed.
4122  */
4123 int rte_eth_dev_priority_flow_ctrl_set(uint16_t port_id,
4124                                 struct rte_eth_pfc_conf *pfc_conf);
4125
4126 /**
4127  * Add a MAC address to the set used for filtering incoming packets.
4128  *
4129  * @param port_id
4130  *   The port identifier of the Ethernet device.
4131  * @param mac_addr
4132  *   The MAC address to add.
4133  * @param pool
4134  *   VMDq pool index to associate address with (if VMDq is enabled). If VMDq is
4135  *   not enabled, this should be set to 0.
4136  * @return
4137  *   - (0) if successfully added or *mac_addr* was already added.
4138  *   - (-ENOTSUP) if hardware doesn't support this feature.
4139  *   - (-ENODEV) if *port* is invalid.
4140  *   - (-EIO) if device is removed.
4141  *   - (-ENOSPC) if no more MAC addresses can be added.
4142  *   - (-EINVAL) if MAC address is invalid.
4143  */
4144 int rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *mac_addr,
4145                                 uint32_t pool);
4146
4147 /**
4148  * Remove a MAC address from the internal array of addresses.
4149  *
4150  * @param port_id
4151  *   The port identifier of the Ethernet device.
4152  * @param mac_addr
4153  *   MAC address to remove.
4154  * @return
4155  *   - (0) if successful, or *mac_addr* didn't exist.
4156  *   - (-ENOTSUP) if hardware doesn't support.
4157  *   - (-ENODEV) if *port* invalid.
4158  *   - (-EADDRINUSE) if attempting to remove the default MAC address.
4159  *   - (-EINVAL) if MAC address is invalid.
4160  */
4161 int rte_eth_dev_mac_addr_remove(uint16_t port_id,
4162                                 struct rte_ether_addr *mac_addr);
4163
4164 /**
4165  * Set the default MAC address.
4166  *
4167  * @param port_id
4168  *   The port identifier of the Ethernet device.
4169  * @param mac_addr
4170  *   New default MAC address.
4171  * @return
4172  *   - (0) if successful, or *mac_addr* didn't exist.
4173  *   - (-ENOTSUP) if hardware doesn't support.
4174  *   - (-ENODEV) if *port* invalid.
4175  *   - (-EINVAL) if MAC address is invalid.
4176  */
4177 int rte_eth_dev_default_mac_addr_set(uint16_t port_id,
4178                 struct rte_ether_addr *mac_addr);
4179
4180 /**
4181  * Update Redirection Table(RETA) of Receive Side Scaling of Ethernet device.
4182  *
4183  * @param port_id
4184  *   The port identifier of the Ethernet device.
4185  * @param reta_conf
4186  *   RETA to update.
4187  * @param reta_size
4188  *   Redirection table size. The table size can be queried by
4189  *   rte_eth_dev_info_get().
4190  * @return
4191  *   - (0) if successful.
4192  *   - (-ENODEV) if *port_id* is invalid.
4193  *   - (-ENOTSUP) if hardware doesn't support.
4194  *   - (-EINVAL) if bad parameter.
4195  *   - (-EIO) if device is removed.
4196  */
4197 int rte_eth_dev_rss_reta_update(uint16_t port_id,
4198                                 struct rte_eth_rss_reta_entry64 *reta_conf,
4199                                 uint16_t reta_size);
4200
4201 /**
4202  * Query Redirection Table(RETA) of Receive Side Scaling of Ethernet device.
4203  *
4204  * @param port_id
4205  *   The port identifier of the Ethernet device.
4206  * @param reta_conf
4207  *   RETA to query. For each requested reta entry, corresponding bit
4208  *   in mask must be set.
4209  * @param reta_size
4210  *   Redirection table size. The table size can be queried by
4211  *   rte_eth_dev_info_get().
4212  * @return
4213  *   - (0) if successful.
4214  *   - (-ENODEV) if *port_id* is invalid.
4215  *   - (-ENOTSUP) if hardware doesn't support.
4216  *   - (-EINVAL) if bad parameter.
4217  *   - (-EIO) if device is removed.
4218  */
4219 int rte_eth_dev_rss_reta_query(uint16_t port_id,
4220                                struct rte_eth_rss_reta_entry64 *reta_conf,
4221                                uint16_t reta_size);
4222
4223 /**
4224  * Updates unicast hash table for receiving packet with the given destination
4225  * MAC address, and the packet is routed to all VFs for which the Rx mode is
4226  * accept packets that match the unicast hash table.
4227  *
4228  * @param port_id
4229  *   The port identifier of the Ethernet device.
4230  * @param addr
4231  *   Unicast MAC address.
4232  * @param on
4233  *    1 - Set an unicast hash bit for receiving packets with the MAC address.
4234  *    0 - Clear an unicast hash bit.
4235  * @return
4236  *   - (0) if successful.
4237  *   - (-ENOTSUP) if hardware doesn't support.
4238   *  - (-ENODEV) if *port_id* invalid.
4239  *   - (-EIO) if device is removed.
4240  *   - (-EINVAL) if bad parameter.
4241  */
4242 int rte_eth_dev_uc_hash_table_set(uint16_t port_id, struct rte_ether_addr *addr,
4243                                   uint8_t on);
4244
4245 /**
4246  * Updates all unicast hash bitmaps for receiving packet with any Unicast
4247  * Ethernet MAC addresses,the packet is routed to all VFs for which the Rx
4248  * mode is accept packets that match the unicast hash table.
4249  *
4250  * @param port_id
4251  *   The port identifier of the Ethernet device.
4252  * @param on
4253  *    1 - Set all unicast hash bitmaps for receiving all the Ethernet
4254  *         MAC addresses
4255  *    0 - Clear all unicast hash bitmaps
4256  * @return
4257  *   - (0) if successful.
4258  *   - (-ENOTSUP) if hardware doesn't support.
4259   *  - (-ENODEV) if *port_id* invalid.
4260  *   - (-EIO) if device is removed.
4261  *   - (-EINVAL) if bad parameter.
4262  */
4263 int rte_eth_dev_uc_all_hash_table_set(uint16_t port_id, uint8_t on);
4264
4265 /**
4266  * Set the rate limitation for a queue on an Ethernet device.
4267  *
4268  * @param port_id
4269  *   The port identifier of the Ethernet device.
4270  * @param queue_idx
4271  *   The queue ID.
4272  * @param tx_rate
4273  *   The Tx rate in Mbps. Allocated from the total port link speed.
4274  * @return
4275  *   - (0) if successful.
4276  *   - (-ENOTSUP) if hardware doesn't support this feature.
4277  *   - (-ENODEV) if *port_id* invalid.
4278  *   - (-EIO) if device is removed.
4279  *   - (-EINVAL) if bad parameter.
4280  */
4281 int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx,
4282                         uint16_t tx_rate);
4283
4284 /**
4285  * Configuration of Receive Side Scaling hash computation of Ethernet device.
4286  *
4287  * @param port_id
4288  *   The port identifier of the Ethernet device.
4289  * @param rss_conf
4290  *   The new configuration to use for RSS hash computation on the port.
4291  * @return
4292  *   - (0) if successful.
4293  *   - (-ENODEV) if port identifier is invalid.
4294  *   - (-EIO) if device is removed.
4295  *   - (-ENOTSUP) if hardware doesn't support.
4296  *   - (-EINVAL) if bad parameter.
4297  */
4298 int rte_eth_dev_rss_hash_update(uint16_t port_id,
4299                                 struct rte_eth_rss_conf *rss_conf);
4300
4301 /**
4302  * Retrieve current configuration of Receive Side Scaling hash computation
4303  * of Ethernet device.
4304  *
4305  * @param port_id
4306  *   The port identifier of the Ethernet device.
4307  * @param rss_conf
4308  *   Where to store the current RSS hash configuration of the Ethernet device.
4309  * @return
4310  *   - (0) if successful.
4311  *   - (-ENODEV) if port identifier is invalid.
4312  *   - (-EIO) if device is removed.
4313  *   - (-ENOTSUP) if hardware doesn't support RSS.
4314  *   - (-EINVAL) if bad parameter.
4315  */
4316 int
4317 rte_eth_dev_rss_hash_conf_get(uint16_t port_id,
4318                               struct rte_eth_rss_conf *rss_conf);
4319
4320 /**
4321  * Add UDP tunneling port for a type of tunnel.
4322  *
4323  * Some NICs may require such configuration to properly parse a tunnel
4324  * with any standard or custom UDP port.
4325  * The packets with this UDP port will be parsed for this type of tunnel.
4326  * The device parser will also check the rest of the tunnel headers
4327  * before classifying the packet.
4328  *
4329  * With some devices, this API will affect packet classification, i.e.:
4330  *     - mbuf.packet_type reported on Rx
4331  *     - rte_flow rules with tunnel items
4332  *
4333  * @param port_id
4334  *   The port identifier of the Ethernet device.
4335  * @param tunnel_udp
4336  *   UDP tunneling configuration.
4337  *
4338  * @return
4339  *   - (0) if successful.
4340  *   - (-ENODEV) if port identifier is invalid.
4341  *   - (-EIO) if device is removed.
4342  *   - (-ENOTSUP) if hardware doesn't support tunnel type.
4343  */
4344 int
4345 rte_eth_dev_udp_tunnel_port_add(uint16_t port_id,
4346                                 struct rte_eth_udp_tunnel *tunnel_udp);
4347
4348 /**
4349  * Delete UDP tunneling port for a type of tunnel.
4350  *
4351  * The packets with this UDP port will not be classified as this type of tunnel
4352  * anymore if the device use such mapping for tunnel packet classification.
4353  *
4354  * @see rte_eth_dev_udp_tunnel_port_add
4355  *
4356  * @param port_id
4357  *   The port identifier of the Ethernet device.
4358  * @param tunnel_udp
4359  *   UDP tunneling configuration.
4360  *
4361  * @return
4362  *   - (0) if successful.
4363  *   - (-ENODEV) if port identifier is invalid.
4364  *   - (-EIO) if device is removed.
4365  *   - (-ENOTSUP) if hardware doesn't support tunnel type.
4366  */
4367 int
4368 rte_eth_dev_udp_tunnel_port_delete(uint16_t port_id,
4369                                    struct rte_eth_udp_tunnel *tunnel_udp);
4370
4371 /**
4372  * Get DCB information on an Ethernet device.
4373  *
4374  * @param port_id
4375  *   The port identifier of the Ethernet device.
4376  * @param dcb_info
4377  *   DCB information.
4378  * @return
4379  *   - (0) if successful.
4380  *   - (-ENODEV) if port identifier is invalid.
4381  *   - (-EIO) if device is removed.
4382  *   - (-ENOTSUP) if hardware doesn't support.
4383  *   - (-EINVAL) if bad parameter.
4384  */
4385 int rte_eth_dev_get_dcb_info(uint16_t port_id,
4386                              struct rte_eth_dcb_info *dcb_info);
4387
4388 struct rte_eth_rxtx_callback;
4389
4390 /**
4391  * Add a callback to be called on packet Rx on a given port and queue.
4392  *
4393  * This API configures a function to be called for each burst of
4394  * packets received on a given NIC port queue. The return value is a pointer
4395  * that can be used to later remove the callback using
4396  * rte_eth_remove_rx_callback().
4397  *
4398  * Multiple functions are called in the order that they are added.
4399  *
4400  * @param port_id
4401  *   The port identifier of the Ethernet device.
4402  * @param queue_id
4403  *   The queue on the Ethernet device on which the callback is to be added.
4404  * @param fn
4405  *   The callback function
4406  * @param user_param
4407  *   A generic pointer parameter which will be passed to each invocation of the
4408  *   callback function on this port and queue. Inter-thread synchronization
4409  *   of any user data changes is the responsibility of the user.
4410  *
4411  * @return
4412  *   NULL on error.
4413  *   On success, a pointer value which can later be used to remove the callback.
4414  */
4415 const struct rte_eth_rxtx_callback *
4416 rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
4417                 rte_rx_callback_fn fn, void *user_param);
4418
4419 /**
4420  * Add a callback that must be called first on packet Rx on a given port
4421  * and queue.
4422  *
4423  * This API configures a first function to be called for each burst of
4424  * packets received on a given NIC port queue. The return value is a pointer
4425  * that can be used to later remove the callback using
4426  * rte_eth_remove_rx_callback().
4427  *
4428  * Multiple functions are called in the order that they are added.
4429  *
4430  * @param port_id
4431  *   The port identifier of the Ethernet device.
4432  * @param queue_id
4433  *   The queue on the Ethernet device on which the callback is to be added.
4434  * @param fn
4435  *   The callback function
4436  * @param user_param
4437  *   A generic pointer parameter which will be passed to each invocation of the
4438  *   callback function on this port and queue. Inter-thread synchronization
4439  *   of any user data changes is the responsibility of the user.
4440  *
4441  * @return
4442  *   NULL on error.
4443  *   On success, a pointer value which can later be used to remove the callback.
4444  */
4445 const struct rte_eth_rxtx_callback *
4446 rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
4447                 rte_rx_callback_fn fn, void *user_param);
4448
4449 /**
4450  * Add a callback to be called on packet Tx on a given port and queue.
4451  *
4452  * This API configures a function to be called for each burst of
4453  * packets sent on a given NIC port queue. The return value is a pointer
4454  * that can be used to later remove the callback using
4455  * rte_eth_remove_tx_callback().
4456  *
4457  * Multiple functions are called in the order that they are added.
4458  *
4459  * @param port_id
4460  *   The port identifier of the Ethernet device.
4461  * @param queue_id
4462  *   The queue on the Ethernet device on which the callback is to be added.
4463  * @param fn
4464  *   The callback function
4465  * @param user_param
4466  *   A generic pointer parameter which will be passed to each invocation of the
4467  *   callback function on this port and queue. Inter-thread synchronization
4468  *   of any user data changes is the responsibility of the user.
4469  *
4470  * @return
4471  *   NULL on error.
4472  *   On success, a pointer value which can later be used to remove the callback.
4473  */
4474 const struct rte_eth_rxtx_callback *
4475 rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
4476                 rte_tx_callback_fn fn, void *user_param);
4477
4478 /**
4479  * Remove an Rx packet callback from a given port and queue.
4480  *
4481  * This function is used to removed callbacks that were added to a NIC port
4482  * queue using rte_eth_add_rx_callback().
4483  *
4484  * Note: the callback is removed from the callback list but it isn't freed
4485  * since the it may still be in use. The memory for the callback can be
4486  * subsequently freed back by the application by calling rte_free():
4487  *
4488  * - Immediately - if the port is stopped, or the user knows that no
4489  *   callbacks are in flight e.g. if called from the thread doing Rx/Tx
4490  *   on that queue.
4491  *
4492  * - After a short delay - where the delay is sufficient to allow any
4493  *   in-flight callbacks to complete. Alternately, the RCU mechanism can be
4494  *   used to detect when data plane threads have ceased referencing the
4495  *   callback memory.
4496  *
4497  * @param port_id
4498  *   The port identifier of the Ethernet device.
4499  * @param queue_id
4500  *   The queue on the Ethernet device from which the callback is to be removed.
4501  * @param user_cb
4502  *   User supplied callback created via rte_eth_add_rx_callback().
4503  *
4504  * @return
4505  *   - 0: Success. Callback was removed.
4506  *   - -ENODEV:  If *port_id* is invalid.
4507  *   - -ENOTSUP: Callback support is not available.
4508  *   - -EINVAL:  The queue_id is out of range, or the callback
4509  *               is NULL or not found for the port/queue.
4510  */
4511 int rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
4512                 const struct rte_eth_rxtx_callback *user_cb);
4513
4514 /**
4515  * Remove a Tx packet callback from a given port and queue.
4516  *
4517  * This function is used to removed callbacks that were added to a NIC port
4518  * queue using rte_eth_add_tx_callback().
4519  *
4520  * Note: the callback is removed from the callback list but it isn't freed
4521  * since the it may still be in use. The memory for the callback can be
4522  * subsequently freed back by the application by calling rte_free():
4523  *
4524  * - Immediately - if the port is stopped, or the user knows that no
4525  *   callbacks are in flight e.g. if called from the thread doing Rx/Tx
4526  *   on that queue.
4527  *
4528  * - After a short delay - where the delay is sufficient to allow any
4529  *   in-flight callbacks to complete. Alternately, the RCU mechanism can be
4530  *   used to detect when data plane threads have ceased referencing the
4531  *   callback memory.
4532  *
4533  * @param port_id
4534  *   The port identifier of the Ethernet device.
4535  * @param queue_id
4536  *   The queue on the Ethernet device from which the callback is to be removed.
4537  * @param user_cb
4538  *   User supplied callback created via rte_eth_add_tx_callback().
4539  *
4540  * @return
4541  *   - 0: Success. Callback was removed.
4542  *   - -ENODEV:  If *port_id* is invalid.
4543  *   - -ENOTSUP: Callback support is not available.
4544  *   - -EINVAL:  The queue_id is out of range, or the callback
4545  *               is NULL or not found for the port/queue.
4546  */
4547 int rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
4548                 const struct rte_eth_rxtx_callback *user_cb);
4549
4550 /**
4551  * Retrieve information about given port's Rx queue.
4552  *
4553  * @param port_id
4554  *   The port identifier of the Ethernet device.
4555  * @param queue_id
4556  *   The Rx queue on the Ethernet device for which information
4557  *   will be retrieved.
4558  * @param qinfo
4559  *   A pointer to a structure of type *rte_eth_rxq_info_info* to be filled with
4560  *   the information of the Ethernet device.
4561  *
4562  * @return
4563  *   - 0: Success
4564  *   - -ENODEV:  If *port_id* is invalid.
4565  *   - -ENOTSUP: routine is not supported by the device PMD.
4566  *   - -EINVAL:  The queue_id is out of range, or the queue
4567  *               is hairpin queue.
4568  */
4569 int rte_eth_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
4570         struct rte_eth_rxq_info *qinfo);
4571
4572 /**
4573  * Retrieve information about given port's Tx queue.
4574  *
4575  * @param port_id
4576  *   The port identifier of the Ethernet device.
4577  * @param queue_id
4578  *   The Tx queue on the Ethernet device for which information
4579  *   will be retrieved.
4580  * @param qinfo
4581  *   A pointer to a structure of type *rte_eth_txq_info_info* to be filled with
4582  *   the information of the Ethernet device.
4583  *
4584  * @return
4585  *   - 0: Success
4586  *   - -ENODEV:  If *port_id* is invalid.
4587  *   - -ENOTSUP: routine is not supported by the device PMD.
4588  *   - -EINVAL:  The queue_id is out of range, or the queue
4589  *               is hairpin queue.
4590  */
4591 int rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,
4592         struct rte_eth_txq_info *qinfo);
4593
4594 /**
4595  * Retrieve information about the Rx packet burst mode.
4596  *
4597  * @param port_id
4598  *   The port identifier of the Ethernet device.
4599  * @param queue_id
4600  *   The Rx queue on the Ethernet device for which information
4601  *   will be retrieved.
4602  * @param mode
4603  *   A pointer to a structure of type *rte_eth_burst_mode* to be filled
4604  *   with the information of the packet burst mode.
4605  *
4606  * @return
4607  *   - 0: Success
4608  *   - -ENODEV:  If *port_id* is invalid.
4609  *   - -ENOTSUP: routine is not supported by the device PMD.
4610  *   - -EINVAL:  The queue_id is out of range.
4611  */
4612 int rte_eth_rx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
4613         struct rte_eth_burst_mode *mode);
4614
4615 /**
4616  * Retrieve information about the Tx packet burst mode.
4617  *
4618  * @param port_id
4619  *   The port identifier of the Ethernet device.
4620  * @param queue_id
4621  *   The Tx queue on the Ethernet device for which information
4622  *   will be retrieved.
4623  * @param mode
4624  *   A pointer to a structure of type *rte_eth_burst_mode* to be filled
4625  *   with the information of the packet burst mode.
4626  *
4627  * @return
4628  *   - 0: Success
4629  *   - -ENODEV:  If *port_id* is invalid.
4630  *   - -ENOTSUP: routine is not supported by the device PMD.
4631  *   - -EINVAL:  The queue_id is out of range.
4632  */
4633 int rte_eth_tx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
4634         struct rte_eth_burst_mode *mode);
4635
4636 /**
4637  * @warning
4638  * @b EXPERIMENTAL: this API may change without prior notice.
4639  *
4640  * Retrieve the monitor condition for a given receive queue.
4641  *
4642  * @param port_id
4643  *   The port identifier of the Ethernet device.
4644  * @param queue_id
4645  *   The Rx queue on the Ethernet device for which information
4646  *   will be retrieved.
4647  * @param pmc
4648  *   The pointer to power-optimized monitoring condition structure.
4649  *
4650  * @return
4651  *   - 0: Success.
4652  *   -ENOTSUP: Operation not supported.
4653  *   -EINVAL: Invalid parameters.
4654  *   -ENODEV: Invalid port ID.
4655  */
4656 __rte_experimental
4657 int rte_eth_get_monitor_addr(uint16_t port_id, uint16_t queue_id,
4658                 struct rte_power_monitor_cond *pmc);
4659
4660 /**
4661  * Retrieve device registers and register attributes (number of registers and
4662  * register size)
4663  *
4664  * @param port_id
4665  *   The port identifier of the Ethernet device.
4666  * @param info
4667  *   Pointer to rte_dev_reg_info structure to fill in. If info->data is
4668  *   NULL the function fills in the width and length fields. If non-NULL
4669  *   the registers are put into the buffer pointed at by the data field.
4670  * @return
4671  *   - (0) if successful.
4672  *   - (-ENOTSUP) if hardware doesn't support.
4673  *   - (-EINVAL) if bad parameter.
4674  *   - (-ENODEV) if *port_id* invalid.
4675  *   - (-EIO) if device is removed.
4676  *   - others depends on the specific operations implementation.
4677  */
4678 int rte_eth_dev_get_reg_info(uint16_t port_id, struct rte_dev_reg_info *info);
4679
4680 /**
4681  * Retrieve size of device EEPROM
4682  *
4683  * @param port_id
4684  *   The port identifier of the Ethernet device.
4685  * @return
4686  *   - (>=0) EEPROM size if successful.
4687  *   - (-ENOTSUP) if hardware doesn't support.
4688  *   - (-ENODEV) if *port_id* invalid.
4689  *   - (-EIO) if device is removed.
4690  *   - others depends on the specific operations implementation.
4691  */
4692 int rte_eth_dev_get_eeprom_length(uint16_t port_id);
4693
4694 /**
4695  * Retrieve EEPROM and EEPROM attribute
4696  *
4697  * @param port_id
4698  *   The port identifier of the Ethernet device.
4699  * @param info
4700  *   The template includes buffer for return EEPROM data and
4701  *   EEPROM attributes to be filled.
4702  * @return
4703  *   - (0) if successful.
4704  *   - (-ENOTSUP) if hardware doesn't support.
4705  *   - (-EINVAL) if bad parameter.
4706  *   - (-ENODEV) if *port_id* invalid.
4707  *   - (-EIO) if device is removed.
4708  *   - others depends on the specific operations implementation.
4709  */
4710 int rte_eth_dev_get_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info);
4711
4712 /**
4713  * Program EEPROM with provided data
4714  *
4715  * @param port_id
4716  *   The port identifier of the Ethernet device.
4717  * @param info
4718  *   The template includes EEPROM data for programming and
4719  *   EEPROM attributes to be filled
4720  * @return
4721  *   - (0) if successful.
4722  *   - (-ENOTSUP) if hardware doesn't support.
4723  *   - (-ENODEV) if *port_id* invalid.
4724  *   - (-EINVAL) if bad parameter.
4725  *   - (-EIO) if device is removed.
4726  *   - others depends on the specific operations implementation.
4727  */
4728 int rte_eth_dev_set_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info);
4729
4730 /**
4731  * @warning
4732  * @b EXPERIMENTAL: this API may change without prior notice.
4733  *
4734  * Retrieve the type and size of plugin module EEPROM
4735  *
4736  * @param port_id
4737  *   The port identifier of the Ethernet device.
4738  * @param modinfo
4739  *   The type and size of plugin module EEPROM.
4740  * @return
4741  *   - (0) if successful.
4742  *   - (-ENOTSUP) if hardware doesn't support.
4743  *   - (-ENODEV) if *port_id* invalid.
4744  *   - (-EINVAL) if bad parameter.
4745  *   - (-EIO) if device is removed.
4746  *   - others depends on the specific operations implementation.
4747  */
4748 __rte_experimental
4749 int
4750 rte_eth_dev_get_module_info(uint16_t port_id,
4751                             struct rte_eth_dev_module_info *modinfo);
4752
4753 /**
4754  * @warning
4755  * @b EXPERIMENTAL: this API may change without prior notice.
4756  *
4757  * Retrieve the data of plugin module EEPROM
4758  *
4759  * @param port_id
4760  *   The port identifier of the Ethernet device.
4761  * @param info
4762  *   The template includes the plugin module EEPROM attributes, and the
4763  *   buffer for return plugin module EEPROM data.
4764  * @return
4765  *   - (0) if successful.
4766  *   - (-ENOTSUP) if hardware doesn't support.
4767  *   - (-EINVAL) if bad parameter.
4768  *   - (-ENODEV) if *port_id* invalid.
4769  *   - (-EIO) if device is removed.
4770  *   - others depends on the specific operations implementation.
4771  */
4772 __rte_experimental
4773 int
4774 rte_eth_dev_get_module_eeprom(uint16_t port_id,
4775                               struct rte_dev_eeprom_info *info);
4776
4777 /**
4778  * Set the list of multicast addresses to filter on an Ethernet device.
4779  *
4780  * @param port_id
4781  *   The port identifier of the Ethernet device.
4782  * @param mc_addr_set
4783  *   The array of multicast addresses to set. Equal to NULL when the function
4784  *   is invoked to flush the set of filtered addresses.
4785  * @param nb_mc_addr
4786  *   The number of multicast addresses in the *mc_addr_set* array. Equal to 0
4787  *   when the function is invoked to flush the set of filtered addresses.
4788  * @return
4789  *   - (0) if successful.
4790  *   - (-ENODEV) if *port_id* invalid.
4791  *   - (-EIO) if device is removed.
4792  *   - (-ENOTSUP) if PMD of *port_id* doesn't support multicast filtering.
4793  *   - (-ENOSPC) if *port_id* has not enough multicast filtering resources.
4794  *   - (-EINVAL) if bad parameter.
4795  */
4796 int rte_eth_dev_set_mc_addr_list(uint16_t port_id,
4797                                  struct rte_ether_addr *mc_addr_set,
4798                                  uint32_t nb_mc_addr);
4799
4800 /**
4801  * Enable IEEE1588/802.1AS timestamping for an Ethernet device.
4802  *
4803  * @param port_id
4804  *   The port identifier of the Ethernet device.
4805  *
4806  * @return
4807  *   - 0: Success.
4808  *   - -ENODEV: The port ID is invalid.
4809  *   - -EIO: if device is removed.
4810  *   - -ENOTSUP: The function is not supported by the Ethernet driver.
4811  */
4812 int rte_eth_timesync_enable(uint16_t port_id);
4813
4814 /**
4815  * Disable IEEE1588/802.1AS timestamping for an Ethernet device.
4816  *
4817  * @param port_id
4818  *   The port identifier of the Ethernet device.
4819  *
4820  * @return
4821  *   - 0: Success.
4822  *   - -ENODEV: The port ID is invalid.
4823  *   - -EIO: if device is removed.
4824  *   - -ENOTSUP: The function is not supported by the Ethernet driver.
4825  */
4826 int rte_eth_timesync_disable(uint16_t port_id);
4827
4828 /**
4829  * Read an IEEE1588/802.1AS Rx timestamp from an Ethernet device.
4830  *
4831  * @param port_id
4832  *   The port identifier of the Ethernet device.
4833  * @param timestamp
4834  *   Pointer to the timestamp struct.
4835  * @param flags
4836  *   Device specific flags. Used to pass the Rx timesync register index to
4837  *   i40e. Unused in igb/ixgbe, pass 0 instead.
4838  *
4839  * @return
4840  *   - 0: Success.
4841  *   - -EINVAL: No timestamp is available.
4842  *   - -ENODEV: The port ID is invalid.
4843  *   - -EIO: if device is removed.
4844  *   - -ENOTSUP: The function is not supported by the Ethernet driver.
4845  */
4846 int rte_eth_timesync_read_rx_timestamp(uint16_t port_id,
4847                 struct timespec *timestamp, uint32_t flags);
4848
4849 /**
4850  * Read an IEEE1588/802.1AS Tx timestamp from an Ethernet device.
4851  *
4852  * @param port_id
4853  *   The port identifier of the Ethernet device.
4854  * @param timestamp
4855  *   Pointer to the timestamp struct.
4856  *
4857  * @return
4858  *   - 0: Success.
4859  *   - -EINVAL: No timestamp is available.
4860  *   - -ENODEV: The port ID is invalid.
4861  *   - -EIO: if device is removed.
4862  *   - -ENOTSUP: The function is not supported by the Ethernet driver.
4863  */
4864 int rte_eth_timesync_read_tx_timestamp(uint16_t port_id,
4865                 struct timespec *timestamp);
4866
4867 /**
4868  * Adjust the timesync clock on an Ethernet device.
4869  *
4870  * This is usually used in conjunction with other Ethdev timesync functions to
4871  * synchronize the device time using the IEEE1588/802.1AS protocol.
4872  *
4873  * @param port_id
4874  *   The port identifier of the Ethernet device.
4875  * @param delta
4876  *   The adjustment in nanoseconds.
4877  *
4878  * @return
4879  *   - 0: Success.
4880  *   - -ENODEV: The port ID is invalid.
4881  *   - -EIO: if device is removed.
4882  *   - -ENOTSUP: The function is not supported by the Ethernet driver.
4883  */
4884 int rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta);
4885
4886 /**
4887  * Read the time from the timesync clock on an Ethernet device.
4888  *
4889  * This is usually used in conjunction with other Ethdev timesync functions to
4890  * synchronize the device time using the IEEE1588/802.1AS protocol.
4891  *
4892  * @param port_id
4893  *   The port identifier of the Ethernet device.
4894  * @param time
4895  *   Pointer to the timespec struct that holds the time.
4896  *
4897  * @return
4898  *   - 0: Success.
4899  *   - -EINVAL: Bad parameter.
4900  */
4901 int rte_eth_timesync_read_time(uint16_t port_id, struct timespec *time);
4902
4903 /**
4904  * Set the time of the timesync clock on an Ethernet device.
4905  *
4906  * This is usually used in conjunction with other Ethdev timesync functions to
4907  * synchronize the device time using the IEEE1588/802.1AS protocol.
4908  *
4909  * @param port_id
4910  *   The port identifier of the Ethernet device.
4911  * @param time
4912  *   Pointer to the timespec struct that holds the time.
4913  *
4914  * @return
4915  *   - 0: Success.
4916  *   - -EINVAL: No timestamp is available.
4917  *   - -ENODEV: The port ID is invalid.
4918  *   - -EIO: if device is removed.
4919  *   - -ENOTSUP: The function is not supported by the Ethernet driver.
4920  */
4921 int rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *time);
4922
4923 /**
4924  * @warning
4925  * @b EXPERIMENTAL: this API may change without prior notice.
4926  *
4927  * Read the current clock counter of an Ethernet device
4928  *
4929  * This returns the current raw clock value of an Ethernet device. It is
4930  * a raw amount of ticks, with no given time reference.
4931  * The value returned here is from the same clock than the one
4932  * filling timestamp field of Rx packets when using hardware timestamp
4933  * offload. Therefore it can be used to compute a precise conversion of
4934  * the device clock to the real time.
4935  *
4936  * E.g, a simple heuristic to derivate the frequency would be:
4937  * uint64_t start, end;
4938  * rte_eth_read_clock(port, start);
4939  * rte_delay_ms(100);
4940  * rte_eth_read_clock(port, end);
4941  * double freq = (end - start) * 10;
4942  *
4943  * Compute a common reference with:
4944  * uint64_t base_time_sec = current_time();
4945  * uint64_t base_clock;
4946  * rte_eth_read_clock(port, base_clock);
4947  *
4948  * Then, convert the raw mbuf timestamp with:
4949  * base_time_sec + (double)(*timestamp_dynfield(mbuf) - base_clock) / freq;
4950  *
4951  * This simple example will not provide a very good accuracy. One must
4952  * at least measure multiple times the frequency and do a regression.
4953  * To avoid deviation from the system time, the common reference can
4954  * be repeated from time to time. The integer division can also be
4955  * converted by a multiplication and a shift for better performance.
4956  *
4957  * @param port_id
4958  *   The port identifier of the Ethernet device.
4959  * @param clock
4960  *   Pointer to the uint64_t that holds the raw clock value.
4961  *
4962  * @return
4963  *   - 0: Success.
4964  *   - -ENODEV: The port ID is invalid.
4965  *   - -ENOTSUP: The function is not supported by the Ethernet driver.
4966  *   - -EINVAL: if bad parameter.
4967  */
4968 __rte_experimental
4969 int
4970 rte_eth_read_clock(uint16_t port_id, uint64_t *clock);
4971
4972 /**
4973 * Get the port ID from device name. The device name should be specified
4974 * as below:
4975 * - PCIe address (Domain:Bus:Device.Function), for example- 0000:2:00.0
4976 * - SoC device name, for example- fsl-gmac0
4977 * - vdev dpdk name, for example- net_[pcap0|null0|tap0]
4978 *
4979 * @param name
4980 *  pci address or name of the device
4981 * @param port_id
4982 *   pointer to port identifier of the device
4983 * @return
4984 *   - (0) if successful and port_id is filled.
4985 *   - (-ENODEV or -EINVAL) on failure.
4986 */
4987 int
4988 rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id);
4989
4990 /**
4991 * Get the device name from port ID. The device name is specified as below:
4992 * - PCIe address (Domain:Bus:Device.Function), for example- 0000:02:00.0
4993 * - SoC device name, for example- fsl-gmac0
4994 * - vdev dpdk name, for example- net_[pcap0|null0|tun0|tap0]
4995 *
4996 * @param port_id
4997 *   Port identifier of the device.
4998 * @param name
4999 *   Buffer of size RTE_ETH_NAME_MAX_LEN to store the name.
5000 * @return
5001 *   - (0) if successful.
5002 *   - (-ENODEV) if *port_id* is invalid.
5003 *   - (-EINVAL) on failure.
5004 */
5005 int
5006 rte_eth_dev_get_name_by_port(uint16_t port_id, char *name);
5007
5008 /**
5009  * Check that numbers of Rx and Tx descriptors satisfy descriptors limits from
5010  * the Ethernet device information, otherwise adjust them to boundaries.
5011  *
5012  * @param port_id
5013  *   The port identifier of the Ethernet device.
5014  * @param nb_rx_desc
5015  *   A pointer to a uint16_t where the number of receive
5016  *   descriptors stored.
5017  * @param nb_tx_desc
5018  *   A pointer to a uint16_t where the number of transmit
5019  *   descriptors stored.
5020  * @return
5021  *   - (0) if successful.
5022  *   - (-ENOTSUP, -ENODEV or -EINVAL) on failure.
5023  */
5024 int rte_eth_dev_adjust_nb_rx_tx_desc(uint16_t port_id,
5025                                      uint16_t *nb_rx_desc,
5026                                      uint16_t *nb_tx_desc);
5027
5028 /**
5029  * Test if a port supports specific mempool ops.
5030  *
5031  * @param port_id
5032  *   Port identifier of the Ethernet device.
5033  * @param [in] pool
5034  *   The name of the pool operations to test.
5035  * @return
5036  *   - 0: best mempool ops choice for this port.
5037  *   - 1: mempool ops are supported for this port.
5038  *   - -ENOTSUP: mempool ops not supported for this port.
5039  *   - -ENODEV: Invalid port Identifier.
5040  *   - -EINVAL: Pool param is null.
5041  */
5042 int
5043 rte_eth_dev_pool_ops_supported(uint16_t port_id, const char *pool);
5044
5045 /**
5046  * Get the security context for the Ethernet device.
5047  *
5048  * @param port_id
5049  *   Port identifier of the Ethernet device
5050  * @return
5051  *   - NULL on error.
5052  *   - pointer to security context on success.
5053  */
5054 void *
5055 rte_eth_dev_get_sec_ctx(uint16_t port_id);
5056
5057 /**
5058  * @warning
5059  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
5060  *
5061  * Query the device hairpin capabilities.
5062  *
5063  * @param port_id
5064  *   The port identifier of the Ethernet device.
5065  * @param cap
5066  *   Pointer to a structure that will hold the hairpin capabilities.
5067  * @return
5068  *   - (0) if successful.
5069  *   - (-ENOTSUP) if hardware doesn't support.
5070  *   - (-EINVAL) if bad parameter.
5071  */
5072 __rte_experimental
5073 int rte_eth_dev_hairpin_capability_get(uint16_t port_id,
5074                                        struct rte_eth_hairpin_cap *cap);
5075
5076 /**
5077  * @warning
5078  * @b EXPERIMENTAL: this structure may change without prior notice.
5079  *
5080  * Ethernet device representor ID range entry
5081  */
5082 struct rte_eth_representor_range {
5083         enum rte_eth_representor_type type; /**< Representor type */
5084         int controller; /**< Controller index */
5085         int pf; /**< Physical function index */
5086         __extension__
5087         union {
5088                 int vf; /**< VF start index */
5089                 int sf; /**< SF start index */
5090         };
5091         uint32_t id_base; /**< Representor ID start index */
5092         uint32_t id_end;  /**< Representor ID end index */
5093         char name[RTE_DEV_NAME_MAX_LEN]; /**< Representor name */
5094 };
5095
5096 /**
5097  * @warning
5098  * @b EXPERIMENTAL: this structure may change without prior notice.
5099  *
5100  * Ethernet device representor information
5101  */
5102 struct rte_eth_representor_info {
5103         uint16_t controller; /**< Controller ID of caller device. */
5104         uint16_t pf; /**< Physical function ID of caller device. */
5105         uint32_t nb_ranges_alloc; /**< Size of the ranges array. */
5106         uint32_t nb_ranges; /**< Number of initialized ranges. */
5107         struct rte_eth_representor_range ranges[];/**< Representor ID range. */
5108 };
5109
5110 /**
5111  * Retrieve the representor info of the device.
5112  *
5113  * Get device representor info to be able to calculate a unique
5114  * representor ID. @see rte_eth_representor_id_get helper.
5115  *
5116  * @param port_id
5117  *   The port identifier of the device.
5118  * @param info
5119  *   A pointer to a representor info structure.
5120  *   NULL to return number of range entries and allocate memory
5121  *   for next call to store detail.
5122  *   The number of ranges that were written into this structure
5123  *   will be placed into its nb_ranges field. This number cannot be
5124  *   larger than the nb_ranges_alloc that by the user before calling
5125  *   this function. It can be smaller than the value returned by the
5126  *   function, however.
5127  * @return
5128  *   - (-ENOTSUP) if operation is not supported.
5129  *   - (-ENODEV) if *port_id* invalid.
5130  *   - (-EIO) if device is removed.
5131  *   - (>=0) number of available representor range entries.
5132  */
5133 __rte_experimental
5134 int rte_eth_representor_info_get(uint16_t port_id,
5135                                  struct rte_eth_representor_info *info);
5136
5137 /** The NIC is able to deliver flag (if set) with packets to the PMD. */
5138 #define RTE_ETH_RX_METADATA_USER_FLAG RTE_BIT64(0)
5139
5140 /** The NIC is able to deliver mark ID with packets to the PMD. */
5141 #define RTE_ETH_RX_METADATA_USER_MARK RTE_BIT64(1)
5142
5143 /** The NIC is able to deliver tunnel ID with packets to the PMD. */
5144 #define RTE_ETH_RX_METADATA_TUNNEL_ID RTE_BIT64(2)
5145
5146 /**
5147  * @warning
5148  * @b EXPERIMENTAL: this API may change without prior notice
5149  *
5150  * Negotiate the NIC's ability to deliver specific kinds of metadata to the PMD.
5151  *
5152  * Invoke this API before the first rte_eth_dev_configure() invocation
5153  * to let the PMD make preparations that are inconvenient to do later.
5154  *
5155  * The negotiation process is as follows:
5156  *
5157  * - the application requests features intending to use at least some of them;
5158  * - the PMD responds with the guaranteed subset of the requested feature set;
5159  * - the application can retry negotiation with another set of features;
5160  * - the application can pass zero to clear the negotiation result;
5161  * - the last negotiated result takes effect upon
5162  *   the ethdev configure and start.
5163  *
5164  * @note
5165  *   The PMD is supposed to first consider enabling the requested feature set
5166  *   in its entirety. Only if it fails to do so, does it have the right to
5167  *   respond with a smaller set of the originally requested features.
5168  *
5169  * @note
5170  *   Return code (-ENOTSUP) does not necessarily mean that the requested
5171  *   features are unsupported. In this case, the application should just
5172  *   assume that these features can be used without prior negotiations.
5173  *
5174  * @param port_id
5175  *   Port (ethdev) identifier
5176  *
5177  * @param[inout] features
5178  *   Feature selection buffer
5179  *
5180  * @return
5181  *   - (-EBUSY) if the port can't handle this in its current state;
5182  *   - (-ENOTSUP) if the method itself is not supported by the PMD;
5183  *   - (-ENODEV) if *port_id* is invalid;
5184  *   - (-EINVAL) if *features* is NULL;
5185  *   - (-EIO) if the device is removed;
5186  *   - (0) on success
5187  */
5188 __rte_experimental
5189 int rte_eth_rx_metadata_negotiate(uint16_t port_id, uint64_t *features);
5190
5191 #include <rte_ethdev_core.h>
5192
5193 /**
5194  * @internal
5195  * Helper routine for rte_eth_rx_burst().
5196  * Should be called at exit from PMD's rte_eth_rx_bulk implementation.
5197  * Does necessary post-processing - invokes Rx callbacks if any, etc.
5198  *
5199  * @param port_id
5200  *  The port identifier of the Ethernet device.
5201  * @param queue_id
5202  *  The index of the receive queue from which to retrieve input packets.
5203  * @param rx_pkts
5204  *   The address of an array of pointers to *rte_mbuf* structures that
5205  *   have been retrieved from the device.
5206  * @param nb_rx
5207  *   The number of packets that were retrieved from the device.
5208  * @param nb_pkts
5209  *   The number of elements in @p rx_pkts array.
5210  * @param opaque
5211  *   Opaque pointer of Rx queue callback related data.
5212  *
5213  * @return
5214  *  The number of packets effectively supplied to the @p rx_pkts array.
5215  */
5216 uint16_t rte_eth_call_rx_callbacks(uint16_t port_id, uint16_t queue_id,
5217                 struct rte_mbuf **rx_pkts, uint16_t nb_rx, uint16_t nb_pkts,
5218                 void *opaque);
5219
5220 /**
5221  *
5222  * Retrieve a burst of input packets from a receive queue of an Ethernet
5223  * device. The retrieved packets are stored in *rte_mbuf* structures whose
5224  * pointers are supplied in the *rx_pkts* array.
5225  *
5226  * The rte_eth_rx_burst() function loops, parsing the Rx ring of the
5227  * receive queue, up to *nb_pkts* packets, and for each completed Rx
5228  * descriptor in the ring, it performs the following operations:
5229  *
5230  * - Initialize the *rte_mbuf* data structure associated with the
5231  *   Rx descriptor according to the information provided by the NIC into
5232  *   that Rx descriptor.
5233  *
5234  * - Store the *rte_mbuf* data structure into the next entry of the
5235  *   *rx_pkts* array.
5236  *
5237  * - Replenish the Rx descriptor with a new *rte_mbuf* buffer
5238  *   allocated from the memory pool associated with the receive queue at
5239  *   initialization time.
5240  *
5241  * When retrieving an input packet that was scattered by the controller
5242  * into multiple receive descriptors, the rte_eth_rx_burst() function
5243  * appends the associated *rte_mbuf* buffers to the first buffer of the
5244  * packet.
5245  *
5246  * The rte_eth_rx_burst() function returns the number of packets
5247  * actually retrieved, which is the number of *rte_mbuf* data structures
5248  * effectively supplied into the *rx_pkts* array.
5249  * A return value equal to *nb_pkts* indicates that the Rx queue contained
5250  * at least *rx_pkts* packets, and this is likely to signify that other
5251  * received packets remain in the input queue. Applications implementing
5252  * a "retrieve as much received packets as possible" policy can check this
5253  * specific case and keep invoking the rte_eth_rx_burst() function until
5254  * a value less than *nb_pkts* is returned.
5255  *
5256  * This receive method has the following advantages:
5257  *
5258  * - It allows a run-to-completion network stack engine to retrieve and
5259  *   to immediately process received packets in a fast burst-oriented
5260  *   approach, avoiding the overhead of unnecessary intermediate packet
5261  *   queue/dequeue operations.
5262  *
5263  * - Conversely, it also allows an asynchronous-oriented processing
5264  *   method to retrieve bursts of received packets and to immediately
5265  *   queue them for further parallel processing by another logical core,
5266  *   for instance. However, instead of having received packets being
5267  *   individually queued by the driver, this approach allows the caller
5268  *   of the rte_eth_rx_burst() function to queue a burst of retrieved
5269  *   packets at a time and therefore dramatically reduce the cost of
5270  *   enqueue/dequeue operations per packet.
5271  *
5272  * - It allows the rte_eth_rx_burst() function of the driver to take
5273  *   advantage of burst-oriented hardware features (CPU cache,
5274  *   prefetch instructions, and so on) to minimize the number of CPU
5275  *   cycles per packet.
5276  *
5277  * To summarize, the proposed receive API enables many
5278  * burst-oriented optimizations in both synchronous and asynchronous
5279  * packet processing environments with no overhead in both cases.
5280  *
5281  * @note
5282  *   Some drivers using vector instructions require that *nb_pkts* is
5283  *   divisible by 4 or 8, depending on the driver implementation.
5284  *
5285  * The rte_eth_rx_burst() function does not provide any error
5286  * notification to avoid the corresponding overhead. As a hint, the
5287  * upper-level application might check the status of the device link once
5288  * being systematically returned a 0 value for a given number of tries.
5289  *
5290  * @param port_id
5291  *   The port identifier of the Ethernet device.
5292  * @param queue_id
5293  *   The index of the receive queue from which to retrieve input packets.
5294  *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
5295  *   to rte_eth_dev_configure().
5296  * @param rx_pkts
5297  *   The address of an array of pointers to *rte_mbuf* structures that
5298  *   must be large enough to store *nb_pkts* pointers in it.
5299  * @param nb_pkts
5300  *   The maximum number of packets to retrieve.
5301  *   The value must be divisible by 8 in order to work with any driver.
5302  * @return
5303  *   The number of packets actually retrieved, which is the number
5304  *   of pointers to *rte_mbuf* structures effectively supplied to the
5305  *   *rx_pkts* array.
5306  */
5307 static inline uint16_t
5308 rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id,
5309                  struct rte_mbuf **rx_pkts, const uint16_t nb_pkts)
5310 {
5311         uint16_t nb_rx;
5312         struct rte_eth_fp_ops *p;
5313         void *qd;
5314
5315 #ifdef RTE_ETHDEV_DEBUG_RX
5316         if (port_id >= RTE_MAX_ETHPORTS ||
5317                         queue_id >= RTE_MAX_QUEUES_PER_PORT) {
5318                 RTE_ETHDEV_LOG(ERR,
5319                         "Invalid port_id=%u or queue_id=%u\n",
5320                         port_id, queue_id);
5321                 return 0;
5322         }
5323 #endif
5324
5325         /* fetch pointer to queue data */
5326         p = &rte_eth_fp_ops[port_id];
5327         qd = p->rxq.data[queue_id];
5328
5329 #ifdef RTE_ETHDEV_DEBUG_RX
5330         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0);
5331
5332         if (qd == NULL) {
5333                 RTE_ETHDEV_LOG(ERR, "Invalid Rx queue_id=%u for port_id=%u\n",
5334                         queue_id, port_id);
5335                 return 0;
5336         }
5337 #endif
5338
5339         nb_rx = p->rx_pkt_burst(qd, rx_pkts, nb_pkts);
5340
5341 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
5342         {
5343                 void *cb;
5344
5345                 /* __ATOMIC_RELEASE memory order was used when the
5346                  * call back was inserted into the list.
5347                  * Since there is a clear dependency between loading
5348                  * cb and cb->fn/cb->next, __ATOMIC_ACQUIRE memory order is
5349                  * not required.
5350                  */
5351                 cb = __atomic_load_n((void **)&p->rxq.clbk[queue_id],
5352                                 __ATOMIC_RELAXED);
5353                 if (unlikely(cb != NULL))
5354                         nb_rx = rte_eth_call_rx_callbacks(port_id, queue_id,
5355                                         rx_pkts, nb_rx, nb_pkts, cb);
5356         }
5357 #endif
5358
5359         rte_ethdev_trace_rx_burst(port_id, queue_id, (void **)rx_pkts, nb_rx);
5360         return nb_rx;
5361 }
5362
5363 /**
5364  * Get the number of used descriptors of a Rx queue
5365  *
5366  * @param port_id
5367  *  The port identifier of the Ethernet device.
5368  * @param queue_id
5369  *  The queue ID on the specific port.
5370  * @return
5371  *  The number of used descriptors in the specific queue, or:
5372  *   - (-ENODEV) if *port_id* is invalid.
5373  *     (-EINVAL) if *queue_id* is invalid
5374  *     (-ENOTSUP) if the device does not support this function
5375  */
5376 static inline int
5377 rte_eth_rx_queue_count(uint16_t port_id, uint16_t queue_id)
5378 {
5379         struct rte_eth_fp_ops *p;
5380         void *qd;
5381
5382         if (port_id >= RTE_MAX_ETHPORTS ||
5383                         queue_id >= RTE_MAX_QUEUES_PER_PORT) {
5384                 RTE_ETHDEV_LOG(ERR,
5385                         "Invalid port_id=%u or queue_id=%u\n",
5386                         port_id, queue_id);
5387                 return -EINVAL;
5388         }
5389
5390         /* fetch pointer to queue data */
5391         p = &rte_eth_fp_ops[port_id];
5392         qd = p->rxq.data[queue_id];
5393
5394         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5395         RTE_FUNC_PTR_OR_ERR_RET(*p->rx_queue_count, -ENOTSUP);
5396         if (qd == NULL)
5397                 return -EINVAL;
5398
5399         return (int)(*p->rx_queue_count)(qd);
5400 }
5401
5402 /**@{@name Rx hardware descriptor states
5403  * @see rte_eth_rx_descriptor_status
5404  */
5405 #define RTE_ETH_RX_DESC_AVAIL    0 /**< Desc available for hw. */
5406 #define RTE_ETH_RX_DESC_DONE     1 /**< Desc done, filled by hw. */
5407 #define RTE_ETH_RX_DESC_UNAVAIL  2 /**< Desc used by driver or hw. */
5408 /**@}*/
5409
5410 /**
5411  * Check the status of a Rx descriptor in the queue
5412  *
5413  * It should be called in a similar context than the Rx function:
5414  * - on a dataplane core
5415  * - not concurrently on the same queue
5416  *
5417  * Since it's a dataplane function, no check is performed on port_id and
5418  * queue_id. The caller must therefore ensure that the port is enabled
5419  * and the queue is configured and running.
5420  *
5421  * Note: accessing to a random descriptor in the ring may trigger cache
5422  * misses and have a performance impact.
5423  *
5424  * @param port_id
5425  *  A valid port identifier of the Ethernet device which.
5426  * @param queue_id
5427  *  A valid Rx queue identifier on this port.
5428  * @param offset
5429  *  The offset of the descriptor starting from tail (0 is the next
5430  *  packet to be received by the driver).
5431  *
5432  * @return
5433  *  - (RTE_ETH_RX_DESC_AVAIL): Descriptor is available for the hardware to
5434  *    receive a packet.
5435  *  - (RTE_ETH_RX_DESC_DONE): Descriptor is done, it is filled by hw, but
5436  *    not yet processed by the driver (i.e. in the receive queue).
5437  *  - (RTE_ETH_RX_DESC_UNAVAIL): Descriptor is unavailable, either hold by
5438  *    the driver and not yet returned to hw, or reserved by the hw.
5439  *  - (-EINVAL) bad descriptor offset.
5440  *  - (-ENOTSUP) if the device does not support this function.
5441  *  - (-ENODEV) bad port or queue (only if compiled with debug).
5442  */
5443 static inline int
5444 rte_eth_rx_descriptor_status(uint16_t port_id, uint16_t queue_id,
5445         uint16_t offset)
5446 {
5447         struct rte_eth_fp_ops *p;
5448         void *qd;
5449
5450 #ifdef RTE_ETHDEV_DEBUG_RX
5451         if (port_id >= RTE_MAX_ETHPORTS ||
5452                         queue_id >= RTE_MAX_QUEUES_PER_PORT) {
5453                 RTE_ETHDEV_LOG(ERR,
5454                         "Invalid port_id=%u or queue_id=%u\n",
5455                         port_id, queue_id);
5456                 return -EINVAL;
5457         }
5458 #endif
5459
5460         /* fetch pointer to queue data */
5461         p = &rte_eth_fp_ops[port_id];
5462         qd = p->rxq.data[queue_id];
5463
5464 #ifdef RTE_ETHDEV_DEBUG_RX
5465         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5466         if (qd == NULL)
5467                 return -ENODEV;
5468 #endif
5469         RTE_FUNC_PTR_OR_ERR_RET(*p->rx_descriptor_status, -ENOTSUP);
5470         return (*p->rx_descriptor_status)(qd, offset);
5471 }
5472
5473 /**@{@name Tx hardware descriptor states
5474  * @see rte_eth_tx_descriptor_status
5475  */
5476 #define RTE_ETH_TX_DESC_FULL    0 /**< Desc filled for hw, waiting xmit. */
5477 #define RTE_ETH_TX_DESC_DONE    1 /**< Desc done, packet is transmitted. */
5478 #define RTE_ETH_TX_DESC_UNAVAIL 2 /**< Desc used by driver or hw. */
5479 /**@}*/
5480
5481 /**
5482  * Check the status of a Tx descriptor in the queue.
5483  *
5484  * It should be called in a similar context than the Tx function:
5485  * - on a dataplane core
5486  * - not concurrently on the same queue
5487  *
5488  * Since it's a dataplane function, no check is performed on port_id and
5489  * queue_id. The caller must therefore ensure that the port is enabled
5490  * and the queue is configured and running.
5491  *
5492  * Note: accessing to a random descriptor in the ring may trigger cache
5493  * misses and have a performance impact.
5494  *
5495  * @param port_id
5496  *  A valid port identifier of the Ethernet device which.
5497  * @param queue_id
5498  *  A valid Tx queue identifier on this port.
5499  * @param offset
5500  *  The offset of the descriptor starting from tail (0 is the place where
5501  *  the next packet will be send).
5502  *
5503  * @return
5504  *  - (RTE_ETH_TX_DESC_FULL) Descriptor is being processed by the hw, i.e.
5505  *    in the transmit queue.
5506  *  - (RTE_ETH_TX_DESC_DONE) Hardware is done with this descriptor, it can
5507  *    be reused by the driver.
5508  *  - (RTE_ETH_TX_DESC_UNAVAIL): Descriptor is unavailable, reserved by the
5509  *    driver or the hardware.
5510  *  - (-EINVAL) bad descriptor offset.
5511  *  - (-ENOTSUP) if the device does not support this function.
5512  *  - (-ENODEV) bad port or queue (only if compiled with debug).
5513  */
5514 static inline int rte_eth_tx_descriptor_status(uint16_t port_id,
5515         uint16_t queue_id, uint16_t offset)
5516 {
5517         struct rte_eth_fp_ops *p;
5518         void *qd;
5519
5520 #ifdef RTE_ETHDEV_DEBUG_TX
5521         if (port_id >= RTE_MAX_ETHPORTS ||
5522                         queue_id >= RTE_MAX_QUEUES_PER_PORT) {
5523                 RTE_ETHDEV_LOG(ERR,
5524                         "Invalid port_id=%u or queue_id=%u\n",
5525                         port_id, queue_id);
5526                 return -EINVAL;
5527         }
5528 #endif
5529
5530         /* fetch pointer to queue data */
5531         p = &rte_eth_fp_ops[port_id];
5532         qd = p->txq.data[queue_id];
5533
5534 #ifdef RTE_ETHDEV_DEBUG_TX
5535         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5536         if (qd == NULL)
5537                 return -ENODEV;
5538 #endif
5539         RTE_FUNC_PTR_OR_ERR_RET(*p->tx_descriptor_status, -ENOTSUP);
5540         return (*p->tx_descriptor_status)(qd, offset);
5541 }
5542
5543 /**
5544  * @internal
5545  * Helper routine for rte_eth_tx_burst().
5546  * Should be called before entry PMD's rte_eth_tx_bulk implementation.
5547  * Does necessary pre-processing - invokes Tx callbacks if any, etc.
5548  *
5549  * @param port_id
5550  *   The port identifier of the Ethernet device.
5551  * @param queue_id
5552  *   The index of the transmit queue through which output packets must be
5553  *   sent.
5554  * @param tx_pkts
5555  *   The address of an array of *nb_pkts* pointers to *rte_mbuf* structures
5556  *   which contain the output packets.
5557  * @param nb_pkts
5558  *   The maximum number of packets to transmit.
5559  * @return
5560  *   The number of output packets to transmit.
5561  */
5562 uint16_t rte_eth_call_tx_callbacks(uint16_t port_id, uint16_t queue_id,
5563         struct rte_mbuf **tx_pkts, uint16_t nb_pkts, void *opaque);
5564
5565 /**
5566  * Send a burst of output packets on a transmit queue of an Ethernet device.
5567  *
5568  * The rte_eth_tx_burst() function is invoked to transmit output packets
5569  * on the output queue *queue_id* of the Ethernet device designated by its
5570  * *port_id*.
5571  * The *nb_pkts* parameter is the number of packets to send which are
5572  * supplied in the *tx_pkts* array of *rte_mbuf* structures, each of them
5573  * allocated from a pool created with rte_pktmbuf_pool_create().
5574  * The rte_eth_tx_burst() function loops, sending *nb_pkts* packets,
5575  * up to the number of transmit descriptors available in the Tx ring of the
5576  * transmit queue.
5577  * For each packet to send, the rte_eth_tx_burst() function performs
5578  * the following operations:
5579  *
5580  * - Pick up the next available descriptor in the transmit ring.
5581  *
5582  * - Free the network buffer previously sent with that descriptor, if any.
5583  *
5584  * - Initialize the transmit descriptor with the information provided
5585  *   in the *rte_mbuf data structure.
5586  *
5587  * In the case of a segmented packet composed of a list of *rte_mbuf* buffers,
5588  * the rte_eth_tx_burst() function uses several transmit descriptors
5589  * of the ring.
5590  *
5591  * The rte_eth_tx_burst() function returns the number of packets it
5592  * actually sent. A return value equal to *nb_pkts* means that all packets
5593  * have been sent, and this is likely to signify that other output packets
5594  * could be immediately transmitted again. Applications that implement a
5595  * "send as many packets to transmit as possible" policy can check this
5596  * specific case and keep invoking the rte_eth_tx_burst() function until
5597  * a value less than *nb_pkts* is returned.
5598  *
5599  * It is the responsibility of the rte_eth_tx_burst() function to
5600  * transparently free the memory buffers of packets previously sent.
5601  * This feature is driven by the *tx_free_thresh* value supplied to the
5602  * rte_eth_dev_configure() function at device configuration time.
5603  * When the number of free Tx descriptors drops below this threshold, the
5604  * rte_eth_tx_burst() function must [attempt to] free the *rte_mbuf*  buffers
5605  * of those packets whose transmission was effectively completed.
5606  *
5607  * If the PMD is RTE_ETH_TX_OFFLOAD_MT_LOCKFREE capable, multiple threads can
5608  * invoke this function concurrently on the same Tx queue without SW lock.
5609  * @see rte_eth_dev_info_get, struct rte_eth_txconf::offloads
5610  *
5611  * @see rte_eth_tx_prepare to perform some prior checks or adjustments
5612  * for offloads.
5613  *
5614  * @param port_id
5615  *   The port identifier of the Ethernet device.
5616  * @param queue_id
5617  *   The index of the transmit queue through which output packets must be
5618  *   sent.
5619  *   The value must be in the range [0, nb_tx_queue - 1] previously supplied
5620  *   to rte_eth_dev_configure().
5621  * @param tx_pkts
5622  *   The address of an array of *nb_pkts* pointers to *rte_mbuf* structures
5623  *   which contain the output packets.
5624  * @param nb_pkts
5625  *   The maximum number of packets to transmit.
5626  * @return
5627  *   The number of output packets actually stored in transmit descriptors of
5628  *   the transmit ring. The return value can be less than the value of the
5629  *   *tx_pkts* parameter when the transmit ring is full or has been filled up.
5630  */
5631 static inline uint16_t
5632 rte_eth_tx_burst(uint16_t port_id, uint16_t queue_id,
5633                  struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
5634 {
5635         struct rte_eth_fp_ops *p;
5636         void *qd;
5637
5638 #ifdef RTE_ETHDEV_DEBUG_TX
5639         if (port_id >= RTE_MAX_ETHPORTS ||
5640                         queue_id >= RTE_MAX_QUEUES_PER_PORT) {
5641                 RTE_ETHDEV_LOG(ERR,
5642                         "Invalid port_id=%u or queue_id=%u\n",
5643                         port_id, queue_id);
5644                 return 0;
5645         }
5646 #endif
5647
5648         /* fetch pointer to queue data */
5649         p = &rte_eth_fp_ops[port_id];
5650         qd = p->txq.data[queue_id];
5651
5652 #ifdef RTE_ETHDEV_DEBUG_TX
5653         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0);
5654
5655         if (qd == NULL) {
5656                 RTE_ETHDEV_LOG(ERR, "Invalid Tx queue_id=%u for port_id=%u\n",
5657                         queue_id, port_id);
5658                 return 0;
5659         }
5660 #endif
5661
5662 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
5663         {
5664                 void *cb;
5665
5666                 /* __ATOMIC_RELEASE memory order was used when the
5667                  * call back was inserted into the list.
5668                  * Since there is a clear dependency between loading
5669                  * cb and cb->fn/cb->next, __ATOMIC_ACQUIRE memory order is
5670                  * not required.
5671                  */
5672                 cb = __atomic_load_n((void **)&p->txq.clbk[queue_id],
5673                                 __ATOMIC_RELAXED);
5674                 if (unlikely(cb != NULL))
5675                         nb_pkts = rte_eth_call_tx_callbacks(port_id, queue_id,
5676                                         tx_pkts, nb_pkts, cb);
5677         }
5678 #endif
5679
5680         nb_pkts = p->tx_pkt_burst(qd, tx_pkts, nb_pkts);
5681
5682         rte_ethdev_trace_tx_burst(port_id, queue_id, (void **)tx_pkts, nb_pkts);
5683         return nb_pkts;
5684 }
5685
5686 /**
5687  * Process a burst of output packets on a transmit queue of an Ethernet device.
5688  *
5689  * The rte_eth_tx_prepare() function is invoked to prepare output packets to be
5690  * transmitted on the output queue *queue_id* of the Ethernet device designated
5691  * by its *port_id*.
5692  * The *nb_pkts* parameter is the number of packets to be prepared which are
5693  * supplied in the *tx_pkts* array of *rte_mbuf* structures, each of them
5694  * allocated from a pool created with rte_pktmbuf_pool_create().
5695  * For each packet to send, the rte_eth_tx_prepare() function performs
5696  * the following operations:
5697  *
5698  * - Check if packet meets devices requirements for Tx offloads.
5699  *
5700  * - Check limitations about number of segments.
5701  *
5702  * - Check additional requirements when debug is enabled.
5703  *
5704  * - Update and/or reset required checksums when Tx offload is set for packet.
5705  *
5706  * Since this function can modify packet data, provided mbufs must be safely
5707  * writable (e.g. modified data cannot be in shared segment).
5708  *
5709  * The rte_eth_tx_prepare() function returns the number of packets ready to be
5710  * sent. A return value equal to *nb_pkts* means that all packets are valid and
5711  * ready to be sent, otherwise stops processing on the first invalid packet and
5712  * leaves the rest packets untouched.
5713  *
5714  * When this functionality is not implemented in the driver, all packets are
5715  * are returned untouched.
5716  *
5717  * @param port_id
5718  *   The port identifier of the Ethernet device.
5719  *   The value must be a valid port ID.
5720  * @param queue_id
5721  *   The index of the transmit queue through which output packets must be
5722  *   sent.
5723  *   The value must be in the range [0, nb_tx_queue - 1] previously supplied
5724  *   to rte_eth_dev_configure().
5725  * @param tx_pkts
5726  *   The address of an array of *nb_pkts* pointers to *rte_mbuf* structures
5727  *   which contain the output packets.
5728  * @param nb_pkts
5729  *   The maximum number of packets to process.
5730  * @return
5731  *   The number of packets correct and ready to be sent. The return value can be
5732  *   less than the value of the *tx_pkts* parameter when some packet doesn't
5733  *   meet devices requirements with rte_errno set appropriately:
5734  *   - EINVAL: offload flags are not correctly set
5735  *   - ENOTSUP: the offload feature is not supported by the hardware
5736  *   - ENODEV: if *port_id* is invalid (with debug enabled only)
5737  *
5738  */
5739
5740 #ifndef RTE_ETHDEV_TX_PREPARE_NOOP
5741
5742 static inline uint16_t
5743 rte_eth_tx_prepare(uint16_t port_id, uint16_t queue_id,
5744                 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
5745 {
5746         struct rte_eth_fp_ops *p;
5747         void *qd;
5748
5749 #ifdef RTE_ETHDEV_DEBUG_TX
5750         if (port_id >= RTE_MAX_ETHPORTS ||
5751                         queue_id >= RTE_MAX_QUEUES_PER_PORT) {
5752                 RTE_ETHDEV_LOG(ERR,
5753                         "Invalid port_id=%u or queue_id=%u\n",
5754                         port_id, queue_id);
5755                 rte_errno = ENODEV;
5756                 return 0;
5757         }
5758 #endif
5759
5760         /* fetch pointer to queue data */
5761         p = &rte_eth_fp_ops[port_id];
5762         qd = p->txq.data[queue_id];
5763
5764 #ifdef RTE_ETHDEV_DEBUG_TX
5765         if (!rte_eth_dev_is_valid_port(port_id)) {
5766                 RTE_ETHDEV_LOG(ERR, "Invalid Tx port_id=%u\n", port_id);
5767                 rte_errno = ENODEV;
5768                 return 0;
5769         }
5770         if (qd == NULL) {
5771                 RTE_ETHDEV_LOG(ERR, "Invalid Tx queue_id=%u for port_id=%u\n",
5772                         queue_id, port_id);
5773                 rte_errno = EINVAL;
5774                 return 0;
5775         }
5776 #endif
5777
5778         if (!p->tx_pkt_prepare)
5779                 return nb_pkts;
5780
5781         return p->tx_pkt_prepare(qd, tx_pkts, nb_pkts);
5782 }
5783
5784 #else
5785
5786 /*
5787  * Native NOOP operation for compilation targets which doesn't require any
5788  * preparations steps, and functional NOOP may introduce unnecessary performance
5789  * drop.
5790  *
5791  * Generally this is not a good idea to turn it on globally and didn't should
5792  * be used if behavior of tx_preparation can change.
5793  */
5794
5795 static inline uint16_t
5796 rte_eth_tx_prepare(__rte_unused uint16_t port_id,
5797                 __rte_unused uint16_t queue_id,
5798                 __rte_unused struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
5799 {
5800         return nb_pkts;
5801 }
5802
5803 #endif
5804
5805 /**
5806  * Send any packets queued up for transmission on a port and HW queue
5807  *
5808  * This causes an explicit flush of packets previously buffered via the
5809  * rte_eth_tx_buffer() function. It returns the number of packets successfully
5810  * sent to the NIC, and calls the error callback for any unsent packets. Unless
5811  * explicitly set up otherwise, the default callback simply frees the unsent
5812  * packets back to the owning mempool.
5813  *
5814  * @param port_id
5815  *   The port identifier of the Ethernet device.
5816  * @param queue_id
5817  *   The index of the transmit queue through which output packets must be
5818  *   sent.
5819  *   The value must be in the range [0, nb_tx_queue - 1] previously supplied
5820  *   to rte_eth_dev_configure().
5821  * @param buffer
5822  *   Buffer of packets to be transmit.
5823  * @return
5824  *   The number of packets successfully sent to the Ethernet device. The error
5825  *   callback is called for any packets which could not be sent.
5826  */
5827 static inline uint16_t
5828 rte_eth_tx_buffer_flush(uint16_t port_id, uint16_t queue_id,
5829                 struct rte_eth_dev_tx_buffer *buffer)
5830 {
5831         uint16_t sent;
5832         uint16_t to_send = buffer->length;
5833
5834         if (to_send == 0)
5835                 return 0;
5836
5837         sent = rte_eth_tx_burst(port_id, queue_id, buffer->pkts, to_send);
5838
5839         buffer->length = 0;
5840
5841         /* All packets sent, or to be dealt with by callback below */
5842         if (unlikely(sent != to_send))
5843                 buffer->error_callback(&buffer->pkts[sent],
5844                                        (uint16_t)(to_send - sent),
5845                                        buffer->error_userdata);
5846
5847         return sent;
5848 }
5849
5850 /**
5851  * Buffer a single packet for future transmission on a port and queue
5852  *
5853  * This function takes a single mbuf/packet and buffers it for later
5854  * transmission on the particular port and queue specified. Once the buffer is
5855  * full of packets, an attempt will be made to transmit all the buffered
5856  * packets. In case of error, where not all packets can be transmitted, a
5857  * callback is called with the unsent packets as a parameter. If no callback
5858  * is explicitly set up, the unsent packets are just freed back to the owning
5859  * mempool. The function returns the number of packets actually sent i.e.
5860  * 0 if no buffer flush occurred, otherwise the number of packets successfully
5861  * flushed
5862  *
5863  * @param port_id
5864  *   The port identifier of the Ethernet device.
5865  * @param queue_id
5866  *   The index of the transmit queue through which output packets must be
5867  *   sent.
5868  *   The value must be in the range [0, nb_tx_queue - 1] previously supplied
5869  *   to rte_eth_dev_configure().
5870  * @param buffer
5871  *   Buffer used to collect packets to be sent.
5872  * @param tx_pkt
5873  *   Pointer to the packet mbuf to be sent.
5874  * @return
5875  *   0 = packet has been buffered for later transmission
5876  *   N > 0 = packet has been buffered, and the buffer was subsequently flushed,
5877  *     causing N packets to be sent, and the error callback to be called for
5878  *     the rest.
5879  */
5880 static __rte_always_inline uint16_t
5881 rte_eth_tx_buffer(uint16_t port_id, uint16_t queue_id,
5882                 struct rte_eth_dev_tx_buffer *buffer, struct rte_mbuf *tx_pkt)
5883 {
5884         buffer->pkts[buffer->length++] = tx_pkt;
5885         if (buffer->length < buffer->size)
5886                 return 0;
5887
5888         return rte_eth_tx_buffer_flush(port_id, queue_id, buffer);
5889 }
5890
5891 #ifdef __cplusplus
5892 }
5893 #endif
5894
5895 #endif /* _RTE_ETHDEV_H_ */