4 * Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/types.h>
35 #include <sys/queue.h>
44 #include <netinet/in.h>
46 #include <rte_byteorder.h>
48 #include <rte_debug.h>
49 #include <rte_interrupts.h>
51 #include <rte_memory.h>
52 #include <rte_memcpy.h>
53 #include <rte_memzone.h>
54 #include <rte_launch.h>
56 #include <rte_per_lcore.h>
57 #include <rte_lcore.h>
58 #include <rte_atomic.h>
59 #include <rte_branch_prediction.h>
60 #include <rte_common.h>
62 #include <rte_mempool.h>
63 #include <rte_malloc.h>
65 #include <rte_errno.h>
66 #include <rte_spinlock.h>
67 #include <rte_string_fns.h>
69 #include "rte_ether.h"
70 #include "rte_ethdev.h"
72 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
73 #define PMD_DEBUG_TRACE(fmt, args...) do { \
74 RTE_LOG(ERR, PMD, "%s: " fmt, __func__, ## args); \
77 #define PMD_DEBUG_TRACE(fmt, args...)
80 /* Macros for checking for restricting functions to primary instance only */
81 #define PROC_PRIMARY_OR_ERR_RET(retval) do { \
82 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
83 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
88 #define PROC_PRIMARY_OR_RET() do { \
89 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
90 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
95 /* Macros to check for invalid function pointers in dev_ops structure */
96 #define FUNC_PTR_OR_ERR_RET(func, retval) do { \
97 if ((func) == NULL) { \
98 PMD_DEBUG_TRACE("Function not supported\n"); \
103 #define FUNC_PTR_OR_RET(func) do { \
104 if ((func) == NULL) { \
105 PMD_DEBUG_TRACE("Function not supported\n"); \
110 /* Macros to check for valid port */
111 #define VALID_PORTID_OR_ERR_RET(port_id, retval) do { \
112 if (!rte_eth_dev_is_valid_port(port_id)) { \
113 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); \
118 #define VALID_PORTID_OR_RET(port_id) do { \
119 if (!rte_eth_dev_is_valid_port(port_id)) { \
120 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); \
125 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
126 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
127 static struct rte_eth_dev_data *rte_eth_dev_data;
128 static uint8_t nb_ports;
130 /* spinlock for eth device callbacks */
131 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
133 /* store statistics names and its offset in stats structure */
134 struct rte_eth_xstats_name_off {
135 char name[RTE_ETH_XSTATS_NAME_SIZE];
139 static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
140 {"rx_packets", offsetof(struct rte_eth_stats, ipackets)},
141 {"tx_packets", offsetof(struct rte_eth_stats, opackets)},
142 {"rx_bytes", offsetof(struct rte_eth_stats, ibytes)},
143 {"tx_bytes", offsetof(struct rte_eth_stats, obytes)},
144 {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
145 {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
146 {"alloc_rx_buff_failed", offsetof(struct rte_eth_stats, rx_nombuf)},
148 #define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
150 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
151 {"rx_packets", offsetof(struct rte_eth_stats, q_ipackets)},
152 {"rx_bytes", offsetof(struct rte_eth_stats, q_ibytes)},
154 #define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) / \
155 sizeof(rte_rxq_stats_strings[0]))
157 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
158 {"tx_packets", offsetof(struct rte_eth_stats, q_opackets)},
159 {"tx_bytes", offsetof(struct rte_eth_stats, q_obytes)},
160 {"tx_errors", offsetof(struct rte_eth_stats, q_errors)},
162 #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) / \
163 sizeof(rte_txq_stats_strings[0]))
167 * The user application callback description.
169 * It contains callback address to be registered by user application,
170 * the pointer to the parameters for callback, and the event type.
172 struct rte_eth_dev_callback {
173 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
174 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
175 void *cb_arg; /**< Parameter for callback */
176 enum rte_eth_event_type event; /**< Interrupt event type */
177 uint32_t active; /**< Callback is executing */
191 rte_eth_dev_data_alloc(void)
193 const unsigned flags = 0;
194 const struct rte_memzone *mz;
196 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
197 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
198 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
199 rte_socket_id(), flags);
201 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
203 rte_panic("Cannot allocate memzone for ethernet port data\n");
205 rte_eth_dev_data = mz->addr;
206 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
207 memset(rte_eth_dev_data, 0,
208 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
212 rte_eth_dev_allocated(const char *name)
216 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
217 if ((rte_eth_devices[i].attached == DEV_ATTACHED) &&
218 strcmp(rte_eth_devices[i].data->name, name) == 0)
219 return &rte_eth_devices[i];
225 rte_eth_dev_find_free_port(void)
229 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
230 if (rte_eth_devices[i].attached == DEV_DETACHED)
233 return RTE_MAX_ETHPORTS;
237 rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
240 struct rte_eth_dev *eth_dev;
242 port_id = rte_eth_dev_find_free_port();
243 if (port_id == RTE_MAX_ETHPORTS) {
244 PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
248 if (rte_eth_dev_data == NULL)
249 rte_eth_dev_data_alloc();
251 if (rte_eth_dev_allocated(name) != NULL) {
252 PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n",
257 eth_dev = &rte_eth_devices[port_id];
258 eth_dev->data = &rte_eth_dev_data[port_id];
259 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
260 eth_dev->data->port_id = port_id;
261 eth_dev->attached = DEV_ATTACHED;
262 eth_dev->dev_type = type;
268 rte_eth_dev_create_unique_device_name(char *name, size_t size,
269 struct rte_pci_device *pci_dev)
273 if ((name == NULL) || (pci_dev == NULL))
276 ret = snprintf(name, size, "%d:%d.%d",
277 pci_dev->addr.bus, pci_dev->addr.devid,
278 pci_dev->addr.function);
285 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
290 eth_dev->attached = DEV_DETACHED;
296 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
297 struct rte_pci_device *pci_dev)
299 struct eth_driver *eth_drv;
300 struct rte_eth_dev *eth_dev;
301 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
305 eth_drv = (struct eth_driver *)pci_drv;
307 /* Create unique Ethernet device name using PCI address */
308 rte_eth_dev_create_unique_device_name(ethdev_name,
309 sizeof(ethdev_name), pci_dev);
311 eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
315 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
316 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
317 eth_drv->dev_private_size,
318 RTE_CACHE_LINE_SIZE);
319 if (eth_dev->data->dev_private == NULL)
320 rte_panic("Cannot allocate memzone for private port data\n");
322 eth_dev->pci_dev = pci_dev;
323 eth_dev->driver = eth_drv;
324 eth_dev->data->rx_mbuf_alloc_failed = 0;
326 /* init user callbacks */
327 TAILQ_INIT(&(eth_dev->link_intr_cbs));
330 * Set the default MTU.
332 eth_dev->data->mtu = ETHER_MTU;
334 /* Invoke PMD device initialization function */
335 diag = (*eth_drv->eth_dev_init)(eth_dev);
339 PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x) failed\n",
341 (unsigned) pci_dev->id.vendor_id,
342 (unsigned) pci_dev->id.device_id);
343 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
344 rte_free(eth_dev->data->dev_private);
345 rte_eth_dev_release_port(eth_dev);
350 rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
352 const struct eth_driver *eth_drv;
353 struct rte_eth_dev *eth_dev;
354 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
360 /* Create unique Ethernet device name using PCI address */
361 rte_eth_dev_create_unique_device_name(ethdev_name,
362 sizeof(ethdev_name), pci_dev);
364 eth_dev = rte_eth_dev_allocated(ethdev_name);
368 eth_drv = (const struct eth_driver *)pci_dev->driver;
370 /* Invoke PMD device uninit function */
371 if (*eth_drv->eth_dev_uninit) {
372 ret = (*eth_drv->eth_dev_uninit)(eth_dev);
377 /* free ether device */
378 rte_eth_dev_release_port(eth_dev);
380 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
381 rte_free(eth_dev->data->dev_private);
383 eth_dev->pci_dev = NULL;
384 eth_dev->driver = NULL;
385 eth_dev->data = NULL;
391 * Register an Ethernet [Poll Mode] driver.
393 * Function invoked by the initialization function of an Ethernet driver
394 * to simultaneously register itself as a PCI driver and as an Ethernet
396 * Invokes the rte_eal_pci_register() function to register the *pci_drv*
397 * structure embedded in the *eth_drv* structure, after having stored the
398 * address of the rte_eth_dev_init() function in the *devinit* field of
399 * the *pci_drv* structure.
400 * During the PCI probing phase, the rte_eth_dev_init() function is
401 * invoked for each PCI [Ethernet device] matching the embedded PCI
402 * identifiers provided by the driver.
405 rte_eth_driver_register(struct eth_driver *eth_drv)
407 eth_drv->pci_drv.devinit = rte_eth_dev_init;
408 eth_drv->pci_drv.devuninit = rte_eth_dev_uninit;
409 rte_eal_pci_register(ð_drv->pci_drv);
413 rte_eth_dev_is_valid_port(uint8_t port_id)
415 if (port_id >= RTE_MAX_ETHPORTS ||
416 rte_eth_devices[port_id].attached != DEV_ATTACHED)
423 rte_eth_dev_socket_id(uint8_t port_id)
425 if (!rte_eth_dev_is_valid_port(port_id))
427 return rte_eth_devices[port_id].pci_dev->numa_node;
431 rte_eth_dev_count(void)
436 static enum rte_eth_dev_type
437 rte_eth_dev_get_device_type(uint8_t port_id)
439 if (!rte_eth_dev_is_valid_port(port_id))
440 return RTE_ETH_DEV_UNKNOWN;
441 return rte_eth_devices[port_id].dev_type;
445 rte_eth_dev_save(struct rte_eth_dev *devs, size_t size)
447 if ((devs == NULL) ||
448 (size != sizeof(struct rte_eth_dev) * RTE_MAX_ETHPORTS))
451 /* save current rte_eth_devices */
452 memcpy(devs, rte_eth_devices, size);
457 rte_eth_dev_get_changed_port(struct rte_eth_dev *devs, uint8_t *port_id)
459 if ((devs == NULL) || (port_id == NULL))
462 /* check which port was attached or detached */
463 for (*port_id = 0; *port_id < RTE_MAX_ETHPORTS; (*port_id)++, devs++) {
464 if (rte_eth_devices[*port_id].attached ^ devs->attached)
471 rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr)
473 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
476 PMD_DEBUG_TRACE("Null pointer is specified\n");
480 *addr = rte_eth_devices[port_id].pci_dev->addr;
485 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
489 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
492 PMD_DEBUG_TRACE("Null pointer is specified\n");
496 /* shouldn't check 'rte_eth_devices[i].data',
497 * because it might be overwritten by VDEV PMD */
498 tmp = rte_eth_dev_data[port_id].name;
504 rte_eth_dev_is_detachable(uint8_t port_id)
508 if (port_id >= RTE_MAX_ETHPORTS) {
509 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
513 if (rte_eth_devices[port_id].dev_type == RTE_ETH_DEV_PCI) {
514 switch (rte_eth_devices[port_id].pci_dev->kdrv) {
515 case RTE_KDRV_IGB_UIO:
516 case RTE_KDRV_UIO_GENERIC:
517 case RTE_KDRV_NIC_UIO:
525 drv_flags = rte_eth_devices[port_id].driver->pci_drv.drv_flags;
526 return !(drv_flags & RTE_PCI_DRV_DETACHABLE);
529 /* attach the new physical device, then store port_id of the device */
531 rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
534 struct rte_eth_dev devs[RTE_MAX_ETHPORTS];
536 if ((addr == NULL) || (port_id == NULL))
539 /* save current port status */
540 if (rte_eth_dev_save(devs, sizeof(devs)))
542 /* re-construct pci_device_list */
543 if (rte_eal_pci_scan())
545 /* invoke probe func of the driver can handle the new device.
547 * rte_eal_pci_probe_one() should return port_id.
548 * And rte_eth_dev_save() and rte_eth_dev_get_changed_port()
549 * should be removed. */
550 if (rte_eal_pci_probe_one(addr))
552 /* get port_id enabled by above procedures */
553 if (rte_eth_dev_get_changed_port(devs, &new_port_id))
556 *port_id = new_port_id;
559 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
563 /* detach the new physical device, then store pci_addr of the device */
565 rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
567 struct rte_pci_addr freed_addr;
568 struct rte_pci_addr vp;
573 /* check whether the driver supports detach feature, or not */
574 if (rte_eth_dev_is_detachable(port_id))
577 /* get pci address by port id */
578 if (rte_eth_dev_get_addr_by_port(port_id, &freed_addr))
581 /* Zeroed pci addr means the port comes from virtual device */
582 vp.domain = vp.bus = vp.devid = vp.function = 0;
583 if (rte_eal_compare_pci_addr(&vp, &freed_addr) == 0)
586 /* invoke devuninit func of the pci driver,
587 * also remove the device from pci_device_list */
588 if (rte_eal_pci_detach(&freed_addr))
594 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
598 /* attach the new virtual device, then store port_id of the device */
600 rte_eth_dev_attach_vdev(const char *vdevargs, uint8_t *port_id)
602 char *name = NULL, *args = NULL;
604 struct rte_eth_dev devs[RTE_MAX_ETHPORTS];
607 if ((vdevargs == NULL) || (port_id == NULL))
610 /* parse vdevargs, then retrieve device name and args */
611 if (rte_eal_parse_devargs_str(vdevargs, &name, &args))
614 /* save current port status */
615 if (rte_eth_dev_save(devs, sizeof(devs)))
617 /* walk around dev_driver_list to find the driver of the device,
618 * then invoke probe function o the driver.
620 * rte_eal_vdev_init() should return port_id,
621 * And rte_eth_dev_save() and rte_eth_dev_get_changed_port()
622 * should be removed. */
623 if (rte_eal_vdev_init(name, args))
625 /* get port_id enabled by above procedures */
626 if (rte_eth_dev_get_changed_port(devs, &new_port_id))
629 *port_id = new_port_id;
637 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
641 /* detach the new virtual device, then store the name of the device */
643 rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
645 char name[RTE_ETH_NAME_MAX_LEN];
647 if (vdevname == NULL)
650 /* check whether the driver supports detach feature, or not */
651 if (rte_eth_dev_is_detachable(port_id))
654 /* get device name by port id */
655 if (rte_eth_dev_get_name_by_port(port_id, name))
657 /* walk around dev_driver_list to find the driver of the device,
658 * then invoke uninit function of the driver */
659 if (rte_eal_vdev_uninit(name))
662 strncpy(vdevname, name, sizeof(name));
665 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
669 /* attach the new device, then store port_id of the device */
671 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
673 struct rte_pci_addr addr;
675 if ((devargs == NULL) || (port_id == NULL))
678 if (eal_parse_pci_DomBDF(devargs, &addr) == 0)
679 return rte_eth_dev_attach_pdev(&addr, port_id);
681 return rte_eth_dev_attach_vdev(devargs, port_id);
684 /* detach the device, then store the name of the device */
686 rte_eth_dev_detach(uint8_t port_id, char *name)
688 struct rte_pci_addr addr;
694 if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {
695 ret = rte_eth_dev_get_addr_by_port(port_id, &addr);
699 ret = rte_eth_dev_detach_pdev(port_id, &addr);
701 snprintf(name, RTE_ETH_NAME_MAX_LEN,
703 addr.domain, addr.bus,
704 addr.devid, addr.function);
708 return rte_eth_dev_detach_vdev(port_id, name);
712 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
714 uint16_t old_nb_queues = dev->data->nb_rx_queues;
718 if (dev->data->rx_queues == NULL) { /* first time configuration */
719 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
720 sizeof(dev->data->rx_queues[0]) * nb_queues,
721 RTE_CACHE_LINE_SIZE);
722 if (dev->data->rx_queues == NULL) {
723 dev->data->nb_rx_queues = 0;
726 } else { /* re-configure */
727 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
729 rxq = dev->data->rx_queues;
731 for (i = nb_queues; i < old_nb_queues; i++)
732 (*dev->dev_ops->rx_queue_release)(rxq[i]);
733 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
734 RTE_CACHE_LINE_SIZE);
737 if (nb_queues > old_nb_queues) {
738 uint16_t new_qs = nb_queues - old_nb_queues;
740 memset(rxq + old_nb_queues, 0,
741 sizeof(rxq[0]) * new_qs);
744 dev->data->rx_queues = rxq;
747 dev->data->nb_rx_queues = nb_queues;
752 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
754 struct rte_eth_dev *dev;
756 /* This function is only safe when called from the primary process
757 * in a multi-process setup*/
758 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
760 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
762 dev = &rte_eth_devices[port_id];
763 if (rx_queue_id >= dev->data->nb_rx_queues) {
764 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
768 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
770 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
775 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
777 struct rte_eth_dev *dev;
779 /* This function is only safe when called from the primary process
780 * in a multi-process setup*/
781 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
783 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
785 dev = &rte_eth_devices[port_id];
786 if (rx_queue_id >= dev->data->nb_rx_queues) {
787 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
791 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
793 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
798 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
800 struct rte_eth_dev *dev;
802 /* This function is only safe when called from the primary process
803 * in a multi-process setup*/
804 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
806 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
808 dev = &rte_eth_devices[port_id];
809 if (tx_queue_id >= dev->data->nb_tx_queues) {
810 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
814 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
816 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
821 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
823 struct rte_eth_dev *dev;
825 /* This function is only safe when called from the primary process
826 * in a multi-process setup*/
827 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
829 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
831 dev = &rte_eth_devices[port_id];
832 if (tx_queue_id >= dev->data->nb_tx_queues) {
833 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
837 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
839 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
844 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
846 uint16_t old_nb_queues = dev->data->nb_tx_queues;
850 if (dev->data->tx_queues == NULL) { /* first time configuration */
851 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
852 sizeof(dev->data->tx_queues[0]) * nb_queues,
853 RTE_CACHE_LINE_SIZE);
854 if (dev->data->tx_queues == NULL) {
855 dev->data->nb_tx_queues = 0;
858 } else { /* re-configure */
859 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
861 txq = dev->data->tx_queues;
863 for (i = nb_queues; i < old_nb_queues; i++)
864 (*dev->dev_ops->tx_queue_release)(txq[i]);
865 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
866 RTE_CACHE_LINE_SIZE);
869 if (nb_queues > old_nb_queues) {
870 uint16_t new_qs = nb_queues - old_nb_queues;
872 memset(txq + old_nb_queues, 0,
873 sizeof(txq[0]) * new_qs);
876 dev->data->tx_queues = txq;
879 dev->data->nb_tx_queues = nb_queues;
884 rte_eth_dev_check_vf_rss_rxq_num(uint8_t port_id, uint16_t nb_rx_q)
886 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
891 RTE_ETH_DEV_SRIOV(dev).active =
895 RTE_ETH_DEV_SRIOV(dev).active =
902 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = nb_rx_q;
903 RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx =
904 dev->pci_dev->max_vfs * nb_rx_q;
910 rte_eth_dev_check_mq_mode(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
911 const struct rte_eth_conf *dev_conf)
913 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
915 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
916 /* check multi-queue mode */
917 if ((dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) ||
918 (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB_RSS) ||
919 (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB)) {
920 /* SRIOV only works in VMDq enable mode */
921 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
923 "wrong VMDQ mq_mode rx %u tx %u\n",
925 dev_conf->rxmode.mq_mode,
926 dev_conf->txmode.mq_mode);
930 switch (dev_conf->rxmode.mq_mode) {
931 case ETH_MQ_RX_VMDQ_DCB:
932 case ETH_MQ_RX_VMDQ_DCB_RSS:
933 /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
934 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
936 "unsupported VMDQ mq_mode rx %u\n",
937 port_id, dev_conf->rxmode.mq_mode);
940 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
942 "Rx mq mode is changed from:"
943 "mq_mode %u into VMDQ mq_mode %u\n",
945 dev_conf->rxmode.mq_mode,
946 dev->data->dev_conf.rxmode.mq_mode);
947 case ETH_MQ_RX_VMDQ_RSS:
948 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_RSS;
949 if (nb_rx_q <= RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)
950 if (rte_eth_dev_check_vf_rss_rxq_num(port_id, nb_rx_q) != 0) {
951 PMD_DEBUG_TRACE("ethdev port_id=%d"
952 " SRIOV active, invalid queue"
953 " number for VMDQ RSS, allowed"
954 " value are 1, 2 or 4\n",
959 default: /* ETH_MQ_RX_VMDQ_ONLY or ETH_MQ_RX_NONE */
960 /* if nothing mq mode configure, use default scheme */
961 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
962 if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
963 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
967 switch (dev_conf->txmode.mq_mode) {
968 case ETH_MQ_TX_VMDQ_DCB:
969 /* DCB VMDQ in SRIOV mode, not implement yet */
970 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
972 "unsupported VMDQ mq_mode tx %u\n",
973 port_id, dev_conf->txmode.mq_mode);
975 default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
976 /* if nothing mq mode configure, use default scheme */
977 dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
981 /* check valid queue number */
982 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
983 (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
984 PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
985 "queue number must less equal to %d\n",
987 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
991 /* For vmdb+dcb mode check our configuration before we go further */
992 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB) {
993 const struct rte_eth_vmdq_dcb_conf *conf;
995 if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
996 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
998 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
1001 conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
1002 if (!(conf->nb_queue_pools == ETH_16_POOLS ||
1003 conf->nb_queue_pools == ETH_32_POOLS)) {
1004 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
1005 "nb_queue_pools must be %d or %d\n",
1006 port_id, ETH_16_POOLS, ETH_32_POOLS);
1010 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
1011 const struct rte_eth_vmdq_dcb_tx_conf *conf;
1013 if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
1014 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
1016 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
1019 conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
1020 if (!(conf->nb_queue_pools == ETH_16_POOLS ||
1021 conf->nb_queue_pools == ETH_32_POOLS)) {
1022 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
1023 "nb_queue_pools != %d or nb_queue_pools "
1025 port_id, ETH_16_POOLS, ETH_32_POOLS);
1030 /* For DCB mode check our configuration before we go further */
1031 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) {
1032 const struct rte_eth_dcb_rx_conf *conf;
1034 if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
1035 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
1037 port_id, ETH_DCB_NUM_QUEUES);
1040 conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
1041 if (!(conf->nb_tcs == ETH_4_TCS ||
1042 conf->nb_tcs == ETH_8_TCS)) {
1043 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
1044 "nb_tcs != %d or nb_tcs "
1046 port_id, ETH_4_TCS, ETH_8_TCS);
1051 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
1052 const struct rte_eth_dcb_tx_conf *conf;
1054 if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
1055 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
1057 port_id, ETH_DCB_NUM_QUEUES);
1060 conf = &(dev_conf->tx_adv_conf.dcb_tx_conf);
1061 if (!(conf->nb_tcs == ETH_4_TCS ||
1062 conf->nb_tcs == ETH_8_TCS)) {
1063 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
1064 "nb_tcs != %d or nb_tcs "
1066 port_id, ETH_4_TCS, ETH_8_TCS);
1075 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
1076 const struct rte_eth_conf *dev_conf)
1078 struct rte_eth_dev *dev;
1079 struct rte_eth_dev_info dev_info;
1082 /* This function is only safe when called from the primary process
1083 * in a multi-process setup*/
1084 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1086 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1088 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
1090 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
1091 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
1095 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
1097 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
1098 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
1102 dev = &rte_eth_devices[port_id];
1104 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1105 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
1107 if (dev->data->dev_started) {
1109 "port %d must be stopped to allow configuration\n", port_id);
1114 * Check that the numbers of RX and TX queues are not greater
1115 * than the maximum number of RX and TX queues supported by the
1116 * configured device.
1118 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
1119 if (nb_rx_q > dev_info.max_rx_queues) {
1120 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
1121 port_id, nb_rx_q, dev_info.max_rx_queues);
1125 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
1129 if (nb_tx_q > dev_info.max_tx_queues) {
1130 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
1131 port_id, nb_tx_q, dev_info.max_tx_queues);
1135 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
1139 /* Copy the dev_conf parameter into the dev structure */
1140 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
1143 * If link state interrupt is enabled, check that the
1144 * device supports it.
1146 if (dev_conf->intr_conf.lsc == 1) {
1147 const struct rte_pci_driver *pci_drv = &dev->driver->pci_drv;
1149 if (!(pci_drv->drv_flags & RTE_PCI_DRV_INTR_LSC)) {
1150 PMD_DEBUG_TRACE("driver %s does not support lsc\n",
1157 * If jumbo frames are enabled, check that the maximum RX packet
1158 * length is supported by the configured device.
1160 if (dev_conf->rxmode.jumbo_frame == 1) {
1161 if (dev_conf->rxmode.max_rx_pkt_len >
1162 dev_info.max_rx_pktlen) {
1163 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
1164 " > max valid value %u\n",
1166 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
1167 (unsigned)dev_info.max_rx_pktlen);
1169 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
1170 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
1171 " < min valid value %u\n",
1173 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
1174 (unsigned)ETHER_MIN_LEN);
1178 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
1179 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
1180 /* Use default value */
1181 dev->data->dev_conf.rxmode.max_rx_pkt_len =
1185 /* multiple queue mode checking */
1186 diag = rte_eth_dev_check_mq_mode(port_id, nb_rx_q, nb_tx_q, dev_conf);
1188 PMD_DEBUG_TRACE("port%d rte_eth_dev_check_mq_mode = %d\n",
1194 * Setup new number of RX/TX queues and reconfigure device.
1196 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
1198 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
1203 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
1205 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
1207 rte_eth_dev_rx_queue_config(dev, 0);
1211 diag = (*dev->dev_ops->dev_configure)(dev);
1213 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
1215 rte_eth_dev_rx_queue_config(dev, 0);
1216 rte_eth_dev_tx_queue_config(dev, 0);
1224 rte_eth_dev_config_restore(uint8_t port_id)
1226 struct rte_eth_dev *dev;
1227 struct rte_eth_dev_info dev_info;
1228 struct ether_addr addr;
1232 dev = &rte_eth_devices[port_id];
1234 rte_eth_dev_info_get(port_id, &dev_info);
1236 if (RTE_ETH_DEV_SRIOV(dev).active)
1237 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
1239 /* replay MAC address configuration */
1240 for (i = 0; i < dev_info.max_mac_addrs; i++) {
1241 addr = dev->data->mac_addrs[i];
1243 /* skip zero address */
1244 if (is_zero_ether_addr(&addr))
1247 /* add address to the hardware */
1248 if (*dev->dev_ops->mac_addr_add &&
1249 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
1250 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
1252 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
1254 /* exit the loop but not return an error */
1259 /* replay promiscuous configuration */
1260 if (rte_eth_promiscuous_get(port_id) == 1)
1261 rte_eth_promiscuous_enable(port_id);
1262 else if (rte_eth_promiscuous_get(port_id) == 0)
1263 rte_eth_promiscuous_disable(port_id);
1265 /* replay all multicast configuration */
1266 if (rte_eth_allmulticast_get(port_id) == 1)
1267 rte_eth_allmulticast_enable(port_id);
1268 else if (rte_eth_allmulticast_get(port_id) == 0)
1269 rte_eth_allmulticast_disable(port_id);
1273 rte_eth_dev_start(uint8_t port_id)
1275 struct rte_eth_dev *dev;
1278 /* This function is only safe when called from the primary process
1279 * in a multi-process setup*/
1280 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1282 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1284 dev = &rte_eth_devices[port_id];
1286 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1288 if (dev->data->dev_started != 0) {
1289 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1290 " already started\n",
1295 diag = (*dev->dev_ops->dev_start)(dev);
1297 dev->data->dev_started = 1;
1301 rte_eth_dev_config_restore(port_id);
1303 if (dev->data->dev_conf.intr_conf.lsc != 0) {
1304 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1305 (*dev->dev_ops->link_update)(dev, 0);
1311 rte_eth_dev_stop(uint8_t port_id)
1313 struct rte_eth_dev *dev;
1315 /* This function is only safe when called from the primary process
1316 * in a multi-process setup*/
1317 PROC_PRIMARY_OR_RET();
1319 VALID_PORTID_OR_RET(port_id);
1320 dev = &rte_eth_devices[port_id];
1322 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1324 if (dev->data->dev_started == 0) {
1325 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1326 " already stopped\n",
1331 dev->data->dev_started = 0;
1332 (*dev->dev_ops->dev_stop)(dev);
1336 rte_eth_dev_set_link_up(uint8_t port_id)
1338 struct rte_eth_dev *dev;
1340 /* This function is only safe when called from the primary process
1341 * in a multi-process setup*/
1342 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1344 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1346 dev = &rte_eth_devices[port_id];
1348 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1349 return (*dev->dev_ops->dev_set_link_up)(dev);
1353 rte_eth_dev_set_link_down(uint8_t port_id)
1355 struct rte_eth_dev *dev;
1357 /* This function is only safe when called from the primary process
1358 * in a multi-process setup*/
1359 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1361 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1363 dev = &rte_eth_devices[port_id];
1365 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1366 return (*dev->dev_ops->dev_set_link_down)(dev);
1370 rte_eth_dev_close(uint8_t port_id)
1372 struct rte_eth_dev *dev;
1374 /* This function is only safe when called from the primary process
1375 * in a multi-process setup*/
1376 PROC_PRIMARY_OR_RET();
1378 VALID_PORTID_OR_RET(port_id);
1379 dev = &rte_eth_devices[port_id];
1381 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1382 dev->data->dev_started = 0;
1383 (*dev->dev_ops->dev_close)(dev);
1387 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1388 uint16_t nb_rx_desc, unsigned int socket_id,
1389 const struct rte_eth_rxconf *rx_conf,
1390 struct rte_mempool *mp)
1393 uint32_t mbp_buf_size;
1394 struct rte_eth_dev *dev;
1395 struct rte_eth_dev_info dev_info;
1397 /* This function is only safe when called from the primary process
1398 * in a multi-process setup*/
1399 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1401 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1403 dev = &rte_eth_devices[port_id];
1404 if (rx_queue_id >= dev->data->nb_rx_queues) {
1405 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1409 if (dev->data->dev_started) {
1411 "port %d must be stopped to allow configuration\n", port_id);
1415 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1416 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1419 * Check the size of the mbuf data buffer.
1420 * This value must be provided in the private data of the memory pool.
1421 * First check that the memory pool has a valid private data.
1423 rte_eth_dev_info_get(port_id, &dev_info);
1424 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1425 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1426 mp->name, (int) mp->private_data_size,
1427 (int) sizeof(struct rte_pktmbuf_pool_private));
1430 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1432 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1433 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1434 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1438 (int)(RTE_PKTMBUF_HEADROOM +
1439 dev_info.min_rx_bufsize),
1440 (int)RTE_PKTMBUF_HEADROOM,
1441 (int)dev_info.min_rx_bufsize);
1445 if (rx_conf == NULL)
1446 rx_conf = &dev_info.default_rxconf;
1448 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1449 socket_id, rx_conf, mp);
1451 if (!dev->data->min_rx_buf_size ||
1452 dev->data->min_rx_buf_size > mbp_buf_size)
1453 dev->data->min_rx_buf_size = mbp_buf_size;
1460 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1461 uint16_t nb_tx_desc, unsigned int socket_id,
1462 const struct rte_eth_txconf *tx_conf)
1464 struct rte_eth_dev *dev;
1465 struct rte_eth_dev_info dev_info;
1467 /* This function is only safe when called from the primary process
1468 * in a multi-process setup*/
1469 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1471 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1473 dev = &rte_eth_devices[port_id];
1474 if (tx_queue_id >= dev->data->nb_tx_queues) {
1475 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1479 if (dev->data->dev_started) {
1481 "port %d must be stopped to allow configuration\n", port_id);
1485 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1486 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1488 rte_eth_dev_info_get(port_id, &dev_info);
1490 if (tx_conf == NULL)
1491 tx_conf = &dev_info.default_txconf;
1493 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1494 socket_id, tx_conf);
1498 rte_eth_promiscuous_enable(uint8_t port_id)
1500 struct rte_eth_dev *dev;
1502 VALID_PORTID_OR_RET(port_id);
1503 dev = &rte_eth_devices[port_id];
1505 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1506 (*dev->dev_ops->promiscuous_enable)(dev);
1507 dev->data->promiscuous = 1;
1511 rte_eth_promiscuous_disable(uint8_t port_id)
1513 struct rte_eth_dev *dev;
1515 VALID_PORTID_OR_RET(port_id);
1516 dev = &rte_eth_devices[port_id];
1518 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1519 dev->data->promiscuous = 0;
1520 (*dev->dev_ops->promiscuous_disable)(dev);
1524 rte_eth_promiscuous_get(uint8_t port_id)
1526 struct rte_eth_dev *dev;
1528 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1530 dev = &rte_eth_devices[port_id];
1531 return dev->data->promiscuous;
1535 rte_eth_allmulticast_enable(uint8_t port_id)
1537 struct rte_eth_dev *dev;
1539 VALID_PORTID_OR_RET(port_id);
1540 dev = &rte_eth_devices[port_id];
1542 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1543 (*dev->dev_ops->allmulticast_enable)(dev);
1544 dev->data->all_multicast = 1;
1548 rte_eth_allmulticast_disable(uint8_t port_id)
1550 struct rte_eth_dev *dev;
1552 VALID_PORTID_OR_RET(port_id);
1553 dev = &rte_eth_devices[port_id];
1555 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1556 dev->data->all_multicast = 0;
1557 (*dev->dev_ops->allmulticast_disable)(dev);
1561 rte_eth_allmulticast_get(uint8_t port_id)
1563 struct rte_eth_dev *dev;
1565 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1567 dev = &rte_eth_devices[port_id];
1568 return dev->data->all_multicast;
1572 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1573 struct rte_eth_link *link)
1575 struct rte_eth_link *dst = link;
1576 struct rte_eth_link *src = &(dev->data->dev_link);
1578 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1579 *(uint64_t *)src) == 0)
1586 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1588 struct rte_eth_dev *dev;
1590 VALID_PORTID_OR_RET(port_id);
1591 dev = &rte_eth_devices[port_id];
1593 if (dev->data->dev_conf.intr_conf.lsc != 0)
1594 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1596 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1597 (*dev->dev_ops->link_update)(dev, 1);
1598 *eth_link = dev->data->dev_link;
1603 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1605 struct rte_eth_dev *dev;
1607 VALID_PORTID_OR_RET(port_id);
1608 dev = &rte_eth_devices[port_id];
1610 if (dev->data->dev_conf.intr_conf.lsc != 0)
1611 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1613 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1614 (*dev->dev_ops->link_update)(dev, 0);
1615 *eth_link = dev->data->dev_link;
1620 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1622 struct rte_eth_dev *dev;
1624 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1626 dev = &rte_eth_devices[port_id];
1627 memset(stats, 0, sizeof(*stats));
1629 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1630 (*dev->dev_ops->stats_get)(dev, stats);
1631 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1636 rte_eth_stats_reset(uint8_t port_id)
1638 struct rte_eth_dev *dev;
1640 VALID_PORTID_OR_RET(port_id);
1641 dev = &rte_eth_devices[port_id];
1643 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1644 (*dev->dev_ops->stats_reset)(dev);
1647 /* retrieve ethdev extended statistics */
1649 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1652 struct rte_eth_stats eth_stats;
1653 struct rte_eth_dev *dev;
1654 unsigned count = 0, i, q;
1656 uint64_t val, *stats_ptr;
1658 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1660 dev = &rte_eth_devices[port_id];
1662 /* Return generic statistics */
1663 count = RTE_NB_STATS;
1664 count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
1665 count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
1667 /* implemented by the driver */
1668 if (dev->dev_ops->xstats_get != NULL) {
1669 /* Retrieve the xstats from the driver at the end of the
1672 xcount = (*dev->dev_ops->xstats_get)(dev, &xstats[count],
1673 (n > count) ? n - count : 0);
1679 if (n < count + xcount)
1680 return count + xcount;
1682 /* now fill the xstats structure */
1684 rte_eth_stats_get(port_id, ð_stats);
1687 for (i = 0; i < RTE_NB_STATS; i++) {
1688 stats_ptr = RTE_PTR_ADD(ð_stats,
1689 rte_stats_strings[i].offset);
1691 snprintf(xstats[count].name, sizeof(xstats[count].name),
1692 "%s", rte_stats_strings[i].name);
1693 xstats[count++].value = val;
1697 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1698 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1699 stats_ptr = RTE_PTR_ADD(ð_stats,
1700 rte_rxq_stats_strings[i].offset +
1701 q * sizeof(uint64_t));
1703 snprintf(xstats[count].name, sizeof(xstats[count].name),
1704 "rx_queue_%u_%s", q,
1705 rte_rxq_stats_strings[i].name);
1706 xstats[count++].value = val;
1711 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1712 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1713 stats_ptr = RTE_PTR_ADD(ð_stats,
1714 rte_txq_stats_strings[i].offset +
1715 q * sizeof(uint64_t));
1717 snprintf(xstats[count].name, sizeof(xstats[count].name),
1718 "tx_queue_%u_%s", q,
1719 rte_txq_stats_strings[i].name);
1720 xstats[count++].value = val;
1724 return count + xcount;
1727 /* reset ethdev extended statistics */
1729 rte_eth_xstats_reset(uint8_t port_id)
1731 struct rte_eth_dev *dev;
1733 VALID_PORTID_OR_RET(port_id);
1734 dev = &rte_eth_devices[port_id];
1736 /* implemented by the driver */
1737 if (dev->dev_ops->xstats_reset != NULL) {
1738 (*dev->dev_ops->xstats_reset)(dev);
1742 /* fallback to default */
1743 rte_eth_stats_reset(port_id);
1747 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1750 struct rte_eth_dev *dev;
1752 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1754 dev = &rte_eth_devices[port_id];
1756 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1757 return (*dev->dev_ops->queue_stats_mapping_set)
1758 (dev, queue_id, stat_idx, is_rx);
1763 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1766 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1772 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1775 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1781 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1783 struct rte_eth_dev *dev;
1785 VALID_PORTID_OR_RET(port_id);
1786 dev = &rte_eth_devices[port_id];
1788 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1790 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1791 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1792 dev_info->pci_dev = dev->pci_dev;
1794 dev_info->driver_name = dev->driver->pci_drv.name;
1798 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1800 struct rte_eth_dev *dev;
1802 VALID_PORTID_OR_RET(port_id);
1803 dev = &rte_eth_devices[port_id];
1804 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1809 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1811 struct rte_eth_dev *dev;
1813 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1815 dev = &rte_eth_devices[port_id];
1816 *mtu = dev->data->mtu;
1821 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1824 struct rte_eth_dev *dev;
1826 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1827 dev = &rte_eth_devices[port_id];
1828 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1830 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1832 dev->data->mtu = mtu;
1838 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1840 struct rte_eth_dev *dev;
1842 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1843 dev = &rte_eth_devices[port_id];
1844 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1845 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1849 if (vlan_id > 4095) {
1850 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1851 port_id, (unsigned) vlan_id);
1854 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1856 return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1860 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1862 struct rte_eth_dev *dev;
1864 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1865 dev = &rte_eth_devices[port_id];
1866 if (rx_queue_id >= dev->data->nb_rx_queues) {
1867 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1871 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1872 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1878 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1880 struct rte_eth_dev *dev;
1882 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1883 dev = &rte_eth_devices[port_id];
1884 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1885 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1891 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1893 struct rte_eth_dev *dev;
1898 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1899 dev = &rte_eth_devices[port_id];
1901 /*check which option changed by application*/
1902 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1903 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1905 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1906 mask |= ETH_VLAN_STRIP_MASK;
1909 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1910 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1912 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1913 mask |= ETH_VLAN_FILTER_MASK;
1916 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1917 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1919 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1920 mask |= ETH_VLAN_EXTEND_MASK;
1927 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1928 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1934 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1936 struct rte_eth_dev *dev;
1939 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1940 dev = &rte_eth_devices[port_id];
1942 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1943 ret |= ETH_VLAN_STRIP_OFFLOAD;
1945 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1946 ret |= ETH_VLAN_FILTER_OFFLOAD;
1948 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1949 ret |= ETH_VLAN_EXTEND_OFFLOAD;
1955 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1957 struct rte_eth_dev *dev;
1959 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1960 dev = &rte_eth_devices[port_id];
1961 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1962 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1968 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1969 struct rte_fdir_filter *fdir_filter,
1972 struct rte_eth_dev *dev;
1974 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1975 dev = &rte_eth_devices[port_id];
1977 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1978 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1979 port_id, dev->data->dev_conf.fdir_conf.mode);
1983 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1984 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1985 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1986 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
1987 "None l4type, source & destinations ports "
1988 "should be null!\n");
1992 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1993 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1998 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1999 struct rte_fdir_filter *fdir_filter,
2002 struct rte_eth_dev *dev;
2004 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2005 dev = &rte_eth_devices[port_id];
2007 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
2008 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2009 port_id, dev->data->dev_conf.fdir_conf.mode);
2013 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2014 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2015 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2016 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
2017 "None l4type, source & destinations ports "
2018 "should be null!\n");
2022 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
2023 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
2029 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
2030 struct rte_fdir_filter *fdir_filter)
2032 struct rte_eth_dev *dev;
2034 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2035 dev = &rte_eth_devices[port_id];
2037 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
2038 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2039 port_id, dev->data->dev_conf.fdir_conf.mode);
2043 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2044 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2045 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2046 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
2047 "None l4type source & destinations ports "
2048 "should be null!\n");
2052 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
2053 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
2057 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
2059 struct rte_eth_dev *dev;
2061 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2062 dev = &rte_eth_devices[port_id];
2063 if (!(dev->data->dev_conf.fdir_conf.mode)) {
2064 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
2068 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
2070 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
2075 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
2076 struct rte_fdir_filter *fdir_filter,
2077 uint16_t soft_id, uint8_t queue,
2080 struct rte_eth_dev *dev;
2082 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2083 dev = &rte_eth_devices[port_id];
2085 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
2086 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2087 port_id, dev->data->dev_conf.fdir_conf.mode);
2091 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2092 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2093 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2094 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
2095 "None l4type, source & destinations ports "
2096 "should be null!\n");
2100 /* For now IPv6 is not supported with perfect filter */
2101 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2104 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
2105 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
2111 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
2112 struct rte_fdir_filter *fdir_filter,
2113 uint16_t soft_id, uint8_t queue,
2116 struct rte_eth_dev *dev;
2118 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2119 dev = &rte_eth_devices[port_id];
2121 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
2122 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2123 port_id, dev->data->dev_conf.fdir_conf.mode);
2127 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2128 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2129 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2130 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
2131 "None l4type, source & destinations ports "
2132 "should be null!\n");
2136 /* For now IPv6 is not supported with perfect filter */
2137 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2140 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
2141 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
2142 soft_id, queue, drop);
2146 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
2147 struct rte_fdir_filter *fdir_filter,
2150 struct rte_eth_dev *dev;
2152 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2153 dev = &rte_eth_devices[port_id];
2155 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
2156 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2157 port_id, dev->data->dev_conf.fdir_conf.mode);
2161 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2162 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2163 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2164 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
2165 "None l4type, source & destinations ports "
2166 "should be null!\n");
2170 /* For now IPv6 is not supported with perfect filter */
2171 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2174 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
2175 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
2180 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
2182 struct rte_eth_dev *dev;
2184 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2185 dev = &rte_eth_devices[port_id];
2186 if (!(dev->data->dev_conf.fdir_conf.mode)) {
2187 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
2191 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
2192 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
2196 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2198 struct rte_eth_dev *dev;
2200 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2201 dev = &rte_eth_devices[port_id];
2202 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2203 memset(fc_conf, 0, sizeof(*fc_conf));
2204 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
2208 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2210 struct rte_eth_dev *dev;
2212 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2213 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2214 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2218 dev = &rte_eth_devices[port_id];
2219 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2220 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
2224 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
2226 struct rte_eth_dev *dev;
2228 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2229 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2230 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2234 dev = &rte_eth_devices[port_id];
2235 /* High water, low water validation are device specific */
2236 if (*dev->dev_ops->priority_flow_ctrl_set)
2237 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
2242 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2250 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
2251 PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
2252 RTE_RETA_GROUP_SIZE);
2256 num = reta_size / RTE_RETA_GROUP_SIZE;
2257 for (i = 0; i < num; i++) {
2258 if (reta_conf[i].mask)
2266 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2270 uint16_t i, idx, shift;
2276 PMD_DEBUG_TRACE("No receive queue is available\n");
2280 for (i = 0; i < reta_size; i++) {
2281 idx = i / RTE_RETA_GROUP_SIZE;
2282 shift = i % RTE_RETA_GROUP_SIZE;
2283 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2284 (reta_conf[idx].reta[shift] >= max_rxq)) {
2285 PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2286 "the maximum rxq index: %u\n", idx, shift,
2287 reta_conf[idx].reta[shift], max_rxq);
2296 rte_eth_dev_rss_reta_update(uint8_t port_id,
2297 struct rte_eth_rss_reta_entry64 *reta_conf,
2300 struct rte_eth_dev *dev;
2303 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2304 /* Check mask bits */
2305 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2309 dev = &rte_eth_devices[port_id];
2311 /* Check entry value */
2312 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2313 dev->data->nb_rx_queues);
2317 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2318 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2322 rte_eth_dev_rss_reta_query(uint8_t port_id,
2323 struct rte_eth_rss_reta_entry64 *reta_conf,
2326 struct rte_eth_dev *dev;
2329 if (port_id >= nb_ports) {
2330 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2334 /* Check mask bits */
2335 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2339 dev = &rte_eth_devices[port_id];
2340 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2341 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2345 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2347 struct rte_eth_dev *dev;
2348 uint16_t rss_hash_protos;
2350 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2351 rss_hash_protos = rss_conf->rss_hf;
2352 if ((rss_hash_protos != 0) &&
2353 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2354 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2358 dev = &rte_eth_devices[port_id];
2359 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2360 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2364 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2365 struct rte_eth_rss_conf *rss_conf)
2367 struct rte_eth_dev *dev;
2369 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2370 dev = &rte_eth_devices[port_id];
2371 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2372 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2376 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
2377 struct rte_eth_udp_tunnel *udp_tunnel)
2379 struct rte_eth_dev *dev;
2381 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2382 if (udp_tunnel == NULL) {
2383 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2387 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2388 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2392 dev = &rte_eth_devices[port_id];
2393 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
2394 return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
2398 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
2399 struct rte_eth_udp_tunnel *udp_tunnel)
2401 struct rte_eth_dev *dev;
2403 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2404 dev = &rte_eth_devices[port_id];
2406 if (udp_tunnel == NULL) {
2407 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2411 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2412 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2416 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2417 return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2421 rte_eth_led_on(uint8_t port_id)
2423 struct rte_eth_dev *dev;
2425 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2426 dev = &rte_eth_devices[port_id];
2427 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2428 return (*dev->dev_ops->dev_led_on)(dev);
2432 rte_eth_led_off(uint8_t port_id)
2434 struct rte_eth_dev *dev;
2436 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2437 dev = &rte_eth_devices[port_id];
2438 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2439 return (*dev->dev_ops->dev_led_off)(dev);
2443 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2447 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2449 struct rte_eth_dev_info dev_info;
2450 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2453 rte_eth_dev_info_get(port_id, &dev_info);
2455 for (i = 0; i < dev_info.max_mac_addrs; i++)
2456 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2462 static const struct ether_addr null_mac_addr;
2465 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2468 struct rte_eth_dev *dev;
2472 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2473 dev = &rte_eth_devices[port_id];
2474 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2476 if (is_zero_ether_addr(addr)) {
2477 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2481 if (pool >= ETH_64_POOLS) {
2482 PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2486 index = get_mac_addr_index(port_id, addr);
2488 index = get_mac_addr_index(port_id, &null_mac_addr);
2490 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2495 pool_mask = dev->data->mac_pool_sel[index];
2497 /* Check if both MAC address and pool is already there, and do nothing */
2498 if (pool_mask & (1ULL << pool))
2503 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2505 /* Update address in NIC data structure */
2506 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2508 /* Update pool bitmap in NIC data structure */
2509 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2515 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2517 struct rte_eth_dev *dev;
2520 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2521 dev = &rte_eth_devices[port_id];
2522 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2524 index = get_mac_addr_index(port_id, addr);
2526 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2528 } else if (index < 0)
2529 return 0; /* Do nothing if address wasn't found */
2532 (*dev->dev_ops->mac_addr_remove)(dev, index);
2534 /* Update address in NIC data structure */
2535 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2537 /* reset pool bitmap */
2538 dev->data->mac_pool_sel[index] = 0;
2544 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2546 struct rte_eth_dev *dev;
2548 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2550 if (!is_valid_assigned_ether_addr(addr))
2553 dev = &rte_eth_devices[port_id];
2554 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2556 /* Update default address in NIC data structure */
2557 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2559 (*dev->dev_ops->mac_addr_set)(dev, addr);
2565 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2566 uint16_t rx_mode, uint8_t on)
2569 struct rte_eth_dev *dev;
2570 struct rte_eth_dev_info dev_info;
2572 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2574 dev = &rte_eth_devices[port_id];
2575 rte_eth_dev_info_get(port_id, &dev_info);
2577 num_vfs = dev_info.max_vfs;
2579 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2584 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2587 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2588 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2592 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2596 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2598 struct rte_eth_dev_info dev_info;
2599 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2602 rte_eth_dev_info_get(port_id, &dev_info);
2603 if (!dev->data->hash_mac_addrs)
2606 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2607 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2608 ETHER_ADDR_LEN) == 0)
2615 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2620 struct rte_eth_dev *dev;
2622 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2624 dev = &rte_eth_devices[port_id];
2625 if (is_zero_ether_addr(addr)) {
2626 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2631 index = get_hash_mac_addr_index(port_id, addr);
2632 /* Check if it's already there, and do nothing */
2633 if ((index >= 0) && (on))
2638 PMD_DEBUG_TRACE("port %d: the MAC address was not "
2639 "set in UTA\n", port_id);
2643 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2645 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2651 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2652 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2654 /* Update address in NIC data structure */
2656 ether_addr_copy(addr,
2657 &dev->data->hash_mac_addrs[index]);
2659 ether_addr_copy(&null_mac_addr,
2660 &dev->data->hash_mac_addrs[index]);
2667 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2669 struct rte_eth_dev *dev;
2671 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2673 dev = &rte_eth_devices[port_id];
2675 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2676 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2680 rte_eth_dev_set_vf_rx(uint8_t port_id, uint16_t vf, uint8_t on)
2683 struct rte_eth_dev *dev;
2684 struct rte_eth_dev_info dev_info;
2686 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2688 dev = &rte_eth_devices[port_id];
2689 rte_eth_dev_info_get(port_id, &dev_info);
2691 num_vfs = dev_info.max_vfs;
2693 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2697 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2698 return (*dev->dev_ops->set_vf_rx)(dev, vf, on);
2702 rte_eth_dev_set_vf_tx(uint8_t port_id, uint16_t vf, uint8_t on)
2705 struct rte_eth_dev *dev;
2706 struct rte_eth_dev_info dev_info;
2708 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2710 dev = &rte_eth_devices[port_id];
2711 rte_eth_dev_info_get(port_id, &dev_info);
2713 num_vfs = dev_info.max_vfs;
2715 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2719 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2720 return (*dev->dev_ops->set_vf_tx)(dev, vf, on);
2724 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2725 uint64_t vf_mask, uint8_t vlan_on)
2727 struct rte_eth_dev *dev;
2729 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2731 dev = &rte_eth_devices[port_id];
2733 if (vlan_id > ETHER_MAX_VLAN_ID) {
2734 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2740 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2744 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2745 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2749 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2752 struct rte_eth_dev *dev;
2753 struct rte_eth_dev_info dev_info;
2754 struct rte_eth_link link;
2756 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2758 dev = &rte_eth_devices[port_id];
2759 rte_eth_dev_info_get(port_id, &dev_info);
2760 link = dev->data->dev_link;
2762 if (queue_idx > dev_info.max_tx_queues) {
2763 PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2764 "invalid queue id=%d\n", port_id, queue_idx);
2768 if (tx_rate > link.link_speed) {
2769 PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2770 "bigger than link speed= %d\n",
2771 tx_rate, link.link_speed);
2775 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2776 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2779 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2782 struct rte_eth_dev *dev;
2783 struct rte_eth_dev_info dev_info;
2784 struct rte_eth_link link;
2789 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2791 dev = &rte_eth_devices[port_id];
2792 rte_eth_dev_info_get(port_id, &dev_info);
2793 link = dev->data->dev_link;
2795 if (vf > dev_info.max_vfs) {
2796 PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2797 "invalid vf id=%d\n", port_id, vf);
2801 if (tx_rate > link.link_speed) {
2802 PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2803 "bigger than link speed= %d\n",
2804 tx_rate, link.link_speed);
2808 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2809 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2813 rte_eth_mirror_rule_set(uint8_t port_id,
2814 struct rte_eth_mirror_conf *mirror_conf,
2815 uint8_t rule_id, uint8_t on)
2817 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2819 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2820 if (mirror_conf->rule_type == 0) {
2821 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2825 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2826 PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2831 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2832 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2833 (mirror_conf->pool_mask == 0)) {
2834 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2838 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2839 mirror_conf->vlan.vlan_mask == 0) {
2840 PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2844 dev = &rte_eth_devices[port_id];
2845 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2847 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2851 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2853 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2855 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2857 dev = &rte_eth_devices[port_id];
2858 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2860 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2863 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2865 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2866 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2868 struct rte_eth_dev *dev;
2870 VALID_PORTID_OR_ERR_RET(port_id, 0);
2872 dev = &rte_eth_devices[port_id];
2873 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);
2874 if (queue_id >= dev->data->nb_rx_queues) {
2875 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2878 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2883 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2884 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2886 struct rte_eth_dev *dev;
2888 VALID_PORTID_OR_ERR_RET(port_id, 0);
2890 dev = &rte_eth_devices[port_id];
2892 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0);
2893 if (queue_id >= dev->data->nb_tx_queues) {
2894 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2897 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2902 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2904 struct rte_eth_dev *dev;
2906 VALID_PORTID_OR_ERR_RET(port_id, 0);
2908 dev = &rte_eth_devices[port_id];
2909 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0);
2910 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2914 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2916 struct rte_eth_dev *dev;
2918 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2920 dev = &rte_eth_devices[port_id];
2921 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2922 return (*dev->dev_ops->rx_descriptor_done)(dev->data->rx_queues[queue_id],
2928 rte_eth_dev_callback_register(uint8_t port_id,
2929 enum rte_eth_event_type event,
2930 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2932 struct rte_eth_dev *dev;
2933 struct rte_eth_dev_callback *user_cb;
2938 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2940 dev = &rte_eth_devices[port_id];
2941 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2943 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2944 if (user_cb->cb_fn == cb_fn &&
2945 user_cb->cb_arg == cb_arg &&
2946 user_cb->event == event) {
2951 /* create a new callback. */
2952 if (user_cb == NULL &&
2953 (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2954 sizeof(struct rte_eth_dev_callback), 0))) {
2955 user_cb->cb_fn = cb_fn;
2956 user_cb->cb_arg = cb_arg;
2957 user_cb->event = event;
2958 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2961 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2962 return (user_cb == NULL) ? -ENOMEM : 0;
2966 rte_eth_dev_callback_unregister(uint8_t port_id,
2967 enum rte_eth_event_type event,
2968 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2971 struct rte_eth_dev *dev;
2972 struct rte_eth_dev_callback *cb, *next;
2977 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2979 dev = &rte_eth_devices[port_id];
2980 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2983 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2985 next = TAILQ_NEXT(cb, next);
2987 if (cb->cb_fn != cb_fn || cb->event != event ||
2988 (cb->cb_arg != (void *)-1 &&
2989 cb->cb_arg != cb_arg))
2993 * if this callback is not executing right now,
2996 if (cb->active == 0) {
2997 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
3004 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3009 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
3010 enum rte_eth_event_type event)
3012 struct rte_eth_dev_callback *cb_lst;
3013 struct rte_eth_dev_callback dev_cb;
3015 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3016 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
3017 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
3021 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3022 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
3024 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3027 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3029 #ifdef RTE_NIC_BYPASS
3030 int rte_eth_dev_bypass_init(uint8_t port_id)
3032 struct rte_eth_dev *dev;
3034 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3036 dev = &rte_eth_devices[port_id];
3037 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
3038 (*dev->dev_ops->bypass_init)(dev);
3043 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
3045 struct rte_eth_dev *dev;
3047 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3049 dev = &rte_eth_devices[port_id];
3050 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
3051 (*dev->dev_ops->bypass_state_show)(dev, state);
3056 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
3058 struct rte_eth_dev *dev;
3060 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3062 dev = &rte_eth_devices[port_id];
3063 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
3064 (*dev->dev_ops->bypass_state_set)(dev, new_state);
3069 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
3071 struct rte_eth_dev *dev;
3073 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3075 dev = &rte_eth_devices[port_id];
3076 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
3077 (*dev->dev_ops->bypass_event_show)(dev, event, state);
3082 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
3084 struct rte_eth_dev *dev;
3086 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3088 dev = &rte_eth_devices[port_id];
3090 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
3091 (*dev->dev_ops->bypass_event_set)(dev, event, state);
3096 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
3098 struct rte_eth_dev *dev;
3100 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3102 dev = &rte_eth_devices[port_id];
3104 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
3105 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
3110 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
3112 struct rte_eth_dev *dev;
3114 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3116 dev = &rte_eth_devices[port_id];
3118 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
3119 (*dev->dev_ops->bypass_ver_show)(dev, ver);
3124 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
3126 struct rte_eth_dev *dev;
3128 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3130 dev = &rte_eth_devices[port_id];
3132 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
3133 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
3138 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
3140 struct rte_eth_dev *dev;
3142 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3144 dev = &rte_eth_devices[port_id];
3146 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
3147 (*dev->dev_ops->bypass_wd_reset)(dev);
3153 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
3155 struct rte_eth_dev *dev;
3157 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3159 dev = &rte_eth_devices[port_id];
3160 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3161 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3162 RTE_ETH_FILTER_NOP, NULL);
3166 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
3167 enum rte_filter_op filter_op, void *arg)
3169 struct rte_eth_dev *dev;
3171 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3173 dev = &rte_eth_devices[port_id];
3174 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3175 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
3179 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
3180 rte_rx_callback_fn fn, void *user_param)
3182 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3183 rte_errno = ENOTSUP;
3186 /* check input parameters */
3187 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3188 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3193 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3201 cb->param = user_param;
3203 /* Add the callbacks in fifo order. */
3204 struct rte_eth_rxtx_callback *tail =
3205 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3208 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3220 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
3221 rte_tx_callback_fn fn, void *user_param)
3223 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3224 rte_errno = ENOTSUP;
3227 /* check input parameters */
3228 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3229 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3234 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3242 cb->param = user_param;
3244 /* Add the callbacks in fifo order. */
3245 struct rte_eth_rxtx_callback *tail =
3246 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3249 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3261 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3262 struct rte_eth_rxtx_callback *user_cb)
3264 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3267 /* Check input parameters. */
3268 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
3269 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3273 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3274 struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
3275 struct rte_eth_rxtx_callback *prev_cb;
3277 /* Reset head pointer and remove user cb if first in the list. */
3278 if (cb == user_cb) {
3279 dev->post_rx_burst_cbs[queue_id] = user_cb->next;
3283 /* Remove the user cb from the callback list. */
3288 if (cb == user_cb) {
3289 prev_cb->next = user_cb->next;
3293 } while (cb != NULL);
3295 /* Callback wasn't found. */
3300 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3301 struct rte_eth_rxtx_callback *user_cb)
3303 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3306 /* Check input parameters. */
3307 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
3308 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3312 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3313 struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
3314 struct rte_eth_rxtx_callback *prev_cb;
3316 /* Reset head pointer and remove user cb if first in the list. */
3317 if (cb == user_cb) {
3318 dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
3322 /* Remove the user cb from the callback list. */
3327 if (cb == user_cb) {
3328 prev_cb->next = user_cb->next;
3332 } while (cb != NULL);
3334 /* Callback wasn't found. */
3339 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3340 struct ether_addr *mc_addr_set,
3341 uint32_t nb_mc_addr)
3343 struct rte_eth_dev *dev;
3345 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3347 dev = &rte_eth_devices[port_id];
3348 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3349 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3353 rte_eth_timesync_enable(uint8_t port_id)
3355 struct rte_eth_dev *dev;
3357 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3358 dev = &rte_eth_devices[port_id];
3360 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3361 return (*dev->dev_ops->timesync_enable)(dev);
3365 rte_eth_timesync_disable(uint8_t port_id)
3367 struct rte_eth_dev *dev;
3369 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3370 dev = &rte_eth_devices[port_id];
3372 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3373 return (*dev->dev_ops->timesync_disable)(dev);
3377 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3380 struct rte_eth_dev *dev;
3382 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3383 dev = &rte_eth_devices[port_id];
3385 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3386 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3390 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3392 struct rte_eth_dev *dev;
3394 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3395 dev = &rte_eth_devices[port_id];
3397 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3398 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3402 rte_eth_dev_get_reg_length(uint8_t port_id)
3404 struct rte_eth_dev *dev;
3406 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3408 dev = &rte_eth_devices[port_id];
3409 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg_length, -ENOTSUP);
3410 return (*dev->dev_ops->get_reg_length)(dev);
3414 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3416 struct rte_eth_dev *dev;
3418 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3420 dev = &rte_eth_devices[port_id];
3421 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3422 return (*dev->dev_ops->get_reg)(dev, info);
3426 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3428 struct rte_eth_dev *dev;
3430 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3432 dev = &rte_eth_devices[port_id];
3433 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3434 return (*dev->dev_ops->get_eeprom_length)(dev);
3438 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3440 struct rte_eth_dev *dev;
3442 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3444 dev = &rte_eth_devices[port_id];
3445 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3446 return (*dev->dev_ops->get_eeprom)(dev, info);
3450 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3452 struct rte_eth_dev *dev;
3454 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3456 dev = &rte_eth_devices[port_id];
3457 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3458 return (*dev->dev_ops->set_eeprom)(dev, info);