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