4 * Copyright(c) 2010-2016 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>
61 #include <rte_mempool.h>
62 #include <rte_malloc.h>
64 #include <rte_errno.h>
65 #include <rte_spinlock.h>
66 #include <rte_string_fns.h>
68 #include "rte_ether.h"
69 #include "rte_ethdev.h"
71 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
72 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
73 static struct rte_eth_dev_data *rte_eth_dev_data;
74 static uint8_t nb_ports;
76 /* spinlock for eth device callbacks */
77 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
79 /* spinlock for add/remove rx callbacks */
80 static rte_spinlock_t rte_eth_rx_cb_lock = RTE_SPINLOCK_INITIALIZER;
82 /* spinlock for add/remove tx callbacks */
83 static rte_spinlock_t rte_eth_tx_cb_lock = RTE_SPINLOCK_INITIALIZER;
85 /* store statistics names and its offset in stats structure */
86 struct rte_eth_xstats_name_off {
87 char name[RTE_ETH_XSTATS_NAME_SIZE];
91 static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
92 {"rx_good_packets", offsetof(struct rte_eth_stats, ipackets)},
93 {"tx_good_packets", offsetof(struct rte_eth_stats, opackets)},
94 {"rx_good_bytes", offsetof(struct rte_eth_stats, ibytes)},
95 {"tx_good_bytes", offsetof(struct rte_eth_stats, obytes)},
96 {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
97 {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
98 {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats,
102 #define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
104 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
105 {"packets", offsetof(struct rte_eth_stats, q_ipackets)},
106 {"bytes", offsetof(struct rte_eth_stats, q_ibytes)},
107 {"errors", offsetof(struct rte_eth_stats, q_errors)},
110 #define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) / \
111 sizeof(rte_rxq_stats_strings[0]))
113 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
114 {"packets", offsetof(struct rte_eth_stats, q_opackets)},
115 {"bytes", offsetof(struct rte_eth_stats, q_obytes)},
117 #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) / \
118 sizeof(rte_txq_stats_strings[0]))
122 * The user application callback description.
124 * It contains callback address to be registered by user application,
125 * the pointer to the parameters for callback, and the event type.
127 struct rte_eth_dev_callback {
128 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
129 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
130 void *cb_arg; /**< Parameter for callback */
131 enum rte_eth_event_type event; /**< Interrupt event type */
132 uint32_t active; /**< Callback is executing */
146 rte_eth_dev_data_alloc(void)
148 const unsigned flags = 0;
149 const struct rte_memzone *mz;
151 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
152 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
153 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
154 rte_socket_id(), flags);
156 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
158 rte_panic("Cannot allocate memzone for ethernet port data\n");
160 rte_eth_dev_data = mz->addr;
161 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
162 memset(rte_eth_dev_data, 0,
163 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
167 rte_eth_dev_allocated(const char *name)
171 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
172 if ((rte_eth_devices[i].attached == DEV_ATTACHED) &&
173 strcmp(rte_eth_devices[i].data->name, name) == 0)
174 return &rte_eth_devices[i];
180 rte_eth_dev_find_free_port(void)
184 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
185 if (rte_eth_devices[i].attached == DEV_DETACHED)
188 return RTE_MAX_ETHPORTS;
192 rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
195 struct rte_eth_dev *eth_dev;
197 port_id = rte_eth_dev_find_free_port();
198 if (port_id == RTE_MAX_ETHPORTS) {
199 RTE_PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
203 if (rte_eth_dev_data == NULL)
204 rte_eth_dev_data_alloc();
206 if (rte_eth_dev_allocated(name) != NULL) {
207 RTE_PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n",
212 eth_dev = &rte_eth_devices[port_id];
213 eth_dev->data = &rte_eth_dev_data[port_id];
214 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
215 eth_dev->data->port_id = port_id;
216 eth_dev->attached = DEV_ATTACHED;
217 eth_dev->dev_type = type;
223 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
228 eth_dev->attached = DEV_DETACHED;
234 rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
235 struct rte_pci_device *pci_dev)
237 struct eth_driver *eth_drv;
238 struct rte_eth_dev *eth_dev;
239 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
243 eth_drv = (struct eth_driver *)pci_drv;
245 rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
246 sizeof(ethdev_name));
248 eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
252 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
253 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
254 eth_drv->dev_private_size,
255 RTE_CACHE_LINE_SIZE);
256 if (eth_dev->data->dev_private == NULL)
257 rte_panic("Cannot allocate memzone for private port data\n");
259 eth_dev->pci_dev = pci_dev;
260 eth_dev->driver = eth_drv;
261 eth_dev->data->rx_mbuf_alloc_failed = 0;
263 /* init user callbacks */
264 TAILQ_INIT(&(eth_dev->link_intr_cbs));
267 * Set the default MTU.
269 eth_dev->data->mtu = ETHER_MTU;
271 /* Invoke PMD device initialization function */
272 diag = (*eth_drv->eth_dev_init)(eth_dev);
276 RTE_PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x) failed\n",
278 (unsigned) pci_dev->id.vendor_id,
279 (unsigned) pci_dev->id.device_id);
280 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
281 rte_free(eth_dev->data->dev_private);
282 rte_eth_dev_release_port(eth_dev);
287 rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
289 const struct eth_driver *eth_drv;
290 struct rte_eth_dev *eth_dev;
291 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
297 rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
298 sizeof(ethdev_name));
300 eth_dev = rte_eth_dev_allocated(ethdev_name);
304 eth_drv = (const struct eth_driver *)pci_dev->driver;
306 /* Invoke PMD device uninit function */
307 if (*eth_drv->eth_dev_uninit) {
308 ret = (*eth_drv->eth_dev_uninit)(eth_dev);
313 /* free ether device */
314 rte_eth_dev_release_port(eth_dev);
316 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
317 rte_free(eth_dev->data->dev_private);
319 eth_dev->pci_dev = NULL;
320 eth_dev->driver = NULL;
321 eth_dev->data = NULL;
327 rte_eth_dev_is_valid_port(uint8_t port_id)
329 if (port_id >= RTE_MAX_ETHPORTS ||
330 rte_eth_devices[port_id].attached != DEV_ATTACHED)
337 rte_eth_dev_socket_id(uint8_t port_id)
339 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
340 return rte_eth_devices[port_id].data->numa_node;
344 rte_eth_dev_count(void)
349 static enum rte_eth_dev_type
350 rte_eth_dev_get_device_type(uint8_t port_id)
352 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, RTE_ETH_DEV_UNKNOWN);
353 return rte_eth_devices[port_id].dev_type;
357 rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr)
359 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
362 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
366 *addr = rte_eth_devices[port_id].pci_dev->addr;
371 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
375 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
378 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
382 /* shouldn't check 'rte_eth_devices[i].data',
383 * because it might be overwritten by VDEV PMD */
384 tmp = rte_eth_dev_data[port_id].name;
390 rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
395 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
399 *port_id = RTE_MAX_ETHPORTS;
401 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
404 rte_eth_dev_data[i].name, strlen(name))) {
415 rte_eth_dev_get_port_by_addr(const struct rte_pci_addr *addr, uint8_t *port_id)
418 struct rte_pci_device *pci_dev = NULL;
421 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
425 *port_id = RTE_MAX_ETHPORTS;
427 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
429 pci_dev = rte_eth_devices[i].pci_dev;
432 !rte_eal_compare_pci_addr(&pci_dev->addr, addr)) {
443 rte_eth_dev_is_detachable(uint8_t port_id)
447 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
449 switch (rte_eth_devices[port_id].data->kdrv) {
450 case RTE_KDRV_IGB_UIO:
451 case RTE_KDRV_UIO_GENERIC:
452 case RTE_KDRV_NIC_UIO:
459 dev_flags = rte_eth_devices[port_id].data->dev_flags;
460 if ((dev_flags & RTE_ETH_DEV_DETACHABLE) &&
461 (!(dev_flags & RTE_ETH_DEV_BONDED_SLAVE)))
467 /* attach the new physical device, then store port_id of the device */
469 rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
471 /* re-construct pci_device_list */
472 if (rte_eal_pci_scan())
474 /* Invoke probe func of the driver can handle the new device. */
475 if (rte_eal_pci_probe_one(addr))
478 if (rte_eth_dev_get_port_by_addr(addr, port_id))
486 /* detach the new physical device, then store pci_addr of the device */
488 rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
490 struct rte_pci_addr freed_addr;
491 struct rte_pci_addr vp;
493 /* get pci address by port id */
494 if (rte_eth_dev_get_addr_by_port(port_id, &freed_addr))
497 /* Zeroed pci addr means the port comes from virtual device */
498 vp.domain = vp.bus = vp.devid = vp.function = 0;
499 if (rte_eal_compare_pci_addr(&vp, &freed_addr) == 0)
502 /* invoke remove func of the pci driver,
503 * also remove the device from pci_device_list */
504 if (rte_eal_pci_detach(&freed_addr))
513 /* attach the new virtual device, then store port_id of the device */
515 rte_eth_dev_attach_vdev(const char *vdevargs, uint8_t *port_id)
517 char *name = NULL, *args = NULL;
520 /* parse vdevargs, then retrieve device name and args */
521 if (rte_eal_parse_devargs_str(vdevargs, &name, &args))
524 /* walk around dev_driver_list to find the driver of the device,
525 * then invoke probe function of the driver.
526 * rte_eal_vdev_init() updates port_id allocated after
529 if (rte_eal_vdev_init(name, args))
532 if (rte_eth_dev_get_port_by_name(name, port_id))
543 /* detach the new virtual device, then store the name of the device */
545 rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
547 char name[RTE_ETH_NAME_MAX_LEN];
549 /* get device name by port id */
550 if (rte_eth_dev_get_name_by_port(port_id, name))
552 /* walk around dev_driver_list to find the driver of the device,
553 * then invoke uninit function of the driver */
554 if (rte_eal_vdev_uninit(name))
557 strncpy(vdevname, name, sizeof(name));
563 /* attach the new device, then store port_id of the device */
565 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
567 struct rte_pci_addr addr;
570 if ((devargs == NULL) || (port_id == NULL)) {
575 if (eal_parse_pci_DomBDF(devargs, &addr) == 0) {
576 ret = rte_eth_dev_attach_pdev(&addr, port_id);
580 ret = rte_eth_dev_attach_vdev(devargs, port_id);
587 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
591 /* detach the device, then store the name of the device */
593 rte_eth_dev_detach(uint8_t port_id, char *name)
595 struct rte_pci_addr addr;
603 /* check whether the driver supports detach feature, or not */
604 if (rte_eth_dev_is_detachable(port_id))
607 if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {
608 ret = rte_eth_dev_get_addr_by_port(port_id, &addr);
612 ret = rte_eth_dev_detach_pdev(port_id, &addr);
616 snprintf(name, RTE_ETH_NAME_MAX_LEN,
618 addr.domain, addr.bus,
619 addr.devid, addr.function);
621 ret = rte_eth_dev_detach_vdev(port_id, name);
629 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
634 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
636 uint16_t old_nb_queues = dev->data->nb_rx_queues;
640 if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */
641 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
642 sizeof(dev->data->rx_queues[0]) * nb_queues,
643 RTE_CACHE_LINE_SIZE);
644 if (dev->data->rx_queues == NULL) {
645 dev->data->nb_rx_queues = 0;
648 } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */
649 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
651 rxq = dev->data->rx_queues;
653 for (i = nb_queues; i < old_nb_queues; i++)
654 (*dev->dev_ops->rx_queue_release)(rxq[i]);
655 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
656 RTE_CACHE_LINE_SIZE);
659 if (nb_queues > old_nb_queues) {
660 uint16_t new_qs = nb_queues - old_nb_queues;
662 memset(rxq + old_nb_queues, 0,
663 sizeof(rxq[0]) * new_qs);
666 dev->data->rx_queues = rxq;
668 } else if (dev->data->rx_queues != NULL && nb_queues == 0) {
669 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
671 rxq = dev->data->rx_queues;
673 for (i = nb_queues; i < old_nb_queues; i++)
674 (*dev->dev_ops->rx_queue_release)(rxq[i]);
676 dev->data->nb_rx_queues = nb_queues;
681 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
683 struct rte_eth_dev *dev;
685 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
687 dev = &rte_eth_devices[port_id];
688 if (rx_queue_id >= dev->data->nb_rx_queues) {
689 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
693 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
695 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
696 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
697 " already started\n",
698 rx_queue_id, port_id);
702 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
707 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
709 struct rte_eth_dev *dev;
711 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
713 dev = &rte_eth_devices[port_id];
714 if (rx_queue_id >= dev->data->nb_rx_queues) {
715 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
719 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
721 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
722 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
723 " already stopped\n",
724 rx_queue_id, port_id);
728 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
733 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
735 struct rte_eth_dev *dev;
737 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
739 dev = &rte_eth_devices[port_id];
740 if (tx_queue_id >= dev->data->nb_tx_queues) {
741 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
745 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
747 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
748 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
749 " already started\n",
750 tx_queue_id, port_id);
754 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
759 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
761 struct rte_eth_dev *dev;
763 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
765 dev = &rte_eth_devices[port_id];
766 if (tx_queue_id >= dev->data->nb_tx_queues) {
767 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
771 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
773 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
774 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
775 " already stopped\n",
776 tx_queue_id, port_id);
780 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
785 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
787 uint16_t old_nb_queues = dev->data->nb_tx_queues;
791 if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */
792 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
793 sizeof(dev->data->tx_queues[0]) * nb_queues,
794 RTE_CACHE_LINE_SIZE);
795 if (dev->data->tx_queues == NULL) {
796 dev->data->nb_tx_queues = 0;
799 } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */
800 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
802 txq = dev->data->tx_queues;
804 for (i = nb_queues; i < old_nb_queues; i++)
805 (*dev->dev_ops->tx_queue_release)(txq[i]);
806 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
807 RTE_CACHE_LINE_SIZE);
810 if (nb_queues > old_nb_queues) {
811 uint16_t new_qs = nb_queues - old_nb_queues;
813 memset(txq + old_nb_queues, 0,
814 sizeof(txq[0]) * new_qs);
817 dev->data->tx_queues = txq;
819 } else if (dev->data->tx_queues != NULL && nb_queues == 0) {
820 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
822 txq = dev->data->tx_queues;
824 for (i = nb_queues; i < old_nb_queues; i++)
825 (*dev->dev_ops->tx_queue_release)(txq[i]);
827 dev->data->nb_tx_queues = nb_queues;
832 rte_eth_speed_bitflag(uint32_t speed, int duplex)
835 case ETH_SPEED_NUM_10M:
836 return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD;
837 case ETH_SPEED_NUM_100M:
838 return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD;
839 case ETH_SPEED_NUM_1G:
840 return ETH_LINK_SPEED_1G;
841 case ETH_SPEED_NUM_2_5G:
842 return ETH_LINK_SPEED_2_5G;
843 case ETH_SPEED_NUM_5G:
844 return ETH_LINK_SPEED_5G;
845 case ETH_SPEED_NUM_10G:
846 return ETH_LINK_SPEED_10G;
847 case ETH_SPEED_NUM_20G:
848 return ETH_LINK_SPEED_20G;
849 case ETH_SPEED_NUM_25G:
850 return ETH_LINK_SPEED_25G;
851 case ETH_SPEED_NUM_40G:
852 return ETH_LINK_SPEED_40G;
853 case ETH_SPEED_NUM_50G:
854 return ETH_LINK_SPEED_50G;
855 case ETH_SPEED_NUM_56G:
856 return ETH_LINK_SPEED_56G;
857 case ETH_SPEED_NUM_100G:
858 return ETH_LINK_SPEED_100G;
865 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
866 const struct rte_eth_conf *dev_conf)
868 struct rte_eth_dev *dev;
869 struct rte_eth_dev_info dev_info;
872 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
874 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
876 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
877 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
881 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
883 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
884 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
888 dev = &rte_eth_devices[port_id];
890 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
891 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
893 if (dev->data->dev_started) {
895 "port %d must be stopped to allow configuration\n", port_id);
899 /* Copy the dev_conf parameter into the dev structure */
900 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
903 * Check that the numbers of RX and TX queues are not greater
904 * than the maximum number of RX and TX queues supported by the
907 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
909 if (nb_rx_q == 0 && nb_tx_q == 0) {
910 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d both rx and tx queue cannot be 0\n", port_id);
914 if (nb_rx_q > dev_info.max_rx_queues) {
915 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
916 port_id, nb_rx_q, dev_info.max_rx_queues);
920 if (nb_tx_q > dev_info.max_tx_queues) {
921 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
922 port_id, nb_tx_q, dev_info.max_tx_queues);
927 * If link state interrupt is enabled, check that the
928 * device supports it.
930 if ((dev_conf->intr_conf.lsc == 1) &&
931 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
932 RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
933 dev->data->drv_name);
938 * If jumbo frames are enabled, check that the maximum RX packet
939 * length is supported by the configured device.
941 if (dev_conf->rxmode.jumbo_frame == 1) {
942 if (dev_conf->rxmode.max_rx_pkt_len >
943 dev_info.max_rx_pktlen) {
944 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
945 " > max valid value %u\n",
947 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
948 (unsigned)dev_info.max_rx_pktlen);
950 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
951 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
952 " < min valid value %u\n",
954 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
955 (unsigned)ETHER_MIN_LEN);
959 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
960 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
961 /* Use default value */
962 dev->data->dev_conf.rxmode.max_rx_pkt_len =
967 * Setup new number of RX/TX queues and reconfigure device.
969 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
971 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
976 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
978 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
980 rte_eth_dev_rx_queue_config(dev, 0);
984 diag = (*dev->dev_ops->dev_configure)(dev);
986 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
988 rte_eth_dev_rx_queue_config(dev, 0);
989 rte_eth_dev_tx_queue_config(dev, 0);
997 rte_eth_dev_config_restore(uint8_t port_id)
999 struct rte_eth_dev *dev;
1000 struct rte_eth_dev_info dev_info;
1001 struct ether_addr addr;
1005 dev = &rte_eth_devices[port_id];
1007 rte_eth_dev_info_get(port_id, &dev_info);
1009 if (RTE_ETH_DEV_SRIOV(dev).active)
1010 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
1012 /* replay MAC address configuration */
1013 for (i = 0; i < dev_info.max_mac_addrs; i++) {
1014 addr = dev->data->mac_addrs[i];
1016 /* skip zero address */
1017 if (is_zero_ether_addr(&addr))
1020 /* add address to the hardware */
1021 if (*dev->dev_ops->mac_addr_add &&
1022 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
1023 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
1025 RTE_PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
1027 /* exit the loop but not return an error */
1032 /* replay promiscuous configuration */
1033 if (rte_eth_promiscuous_get(port_id) == 1)
1034 rte_eth_promiscuous_enable(port_id);
1035 else if (rte_eth_promiscuous_get(port_id) == 0)
1036 rte_eth_promiscuous_disable(port_id);
1038 /* replay all multicast configuration */
1039 if (rte_eth_allmulticast_get(port_id) == 1)
1040 rte_eth_allmulticast_enable(port_id);
1041 else if (rte_eth_allmulticast_get(port_id) == 0)
1042 rte_eth_allmulticast_disable(port_id);
1046 rte_eth_dev_start(uint8_t port_id)
1048 struct rte_eth_dev *dev;
1051 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1053 dev = &rte_eth_devices[port_id];
1055 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1057 if (dev->data->dev_started != 0) {
1058 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1059 " already started\n",
1064 diag = (*dev->dev_ops->dev_start)(dev);
1066 dev->data->dev_started = 1;
1070 rte_eth_dev_config_restore(port_id);
1072 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1073 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1074 (*dev->dev_ops->link_update)(dev, 0);
1080 rte_eth_dev_stop(uint8_t port_id)
1082 struct rte_eth_dev *dev;
1084 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1085 dev = &rte_eth_devices[port_id];
1087 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1089 if (dev->data->dev_started == 0) {
1090 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1091 " already stopped\n",
1096 dev->data->dev_started = 0;
1097 (*dev->dev_ops->dev_stop)(dev);
1101 rte_eth_dev_set_link_up(uint8_t port_id)
1103 struct rte_eth_dev *dev;
1105 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1107 dev = &rte_eth_devices[port_id];
1109 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1110 return (*dev->dev_ops->dev_set_link_up)(dev);
1114 rte_eth_dev_set_link_down(uint8_t port_id)
1116 struct rte_eth_dev *dev;
1118 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1120 dev = &rte_eth_devices[port_id];
1122 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1123 return (*dev->dev_ops->dev_set_link_down)(dev);
1127 rte_eth_dev_close(uint8_t port_id)
1129 struct rte_eth_dev *dev;
1131 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1132 dev = &rte_eth_devices[port_id];
1134 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1135 dev->data->dev_started = 0;
1136 (*dev->dev_ops->dev_close)(dev);
1138 rte_free(dev->data->rx_queues);
1139 dev->data->rx_queues = NULL;
1140 rte_free(dev->data->tx_queues);
1141 dev->data->tx_queues = NULL;
1145 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1146 uint16_t nb_rx_desc, unsigned int socket_id,
1147 const struct rte_eth_rxconf *rx_conf,
1148 struct rte_mempool *mp)
1151 uint32_t mbp_buf_size;
1152 struct rte_eth_dev *dev;
1153 struct rte_eth_dev_info dev_info;
1155 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1157 dev = &rte_eth_devices[port_id];
1158 if (rx_queue_id >= dev->data->nb_rx_queues) {
1159 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1163 if (dev->data->dev_started) {
1164 RTE_PMD_DEBUG_TRACE(
1165 "port %d must be stopped to allow configuration\n", port_id);
1169 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1170 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1173 * Check the size of the mbuf data buffer.
1174 * This value must be provided in the private data of the memory pool.
1175 * First check that the memory pool has a valid private data.
1177 rte_eth_dev_info_get(port_id, &dev_info);
1178 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1179 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1180 mp->name, (int) mp->private_data_size,
1181 (int) sizeof(struct rte_pktmbuf_pool_private));
1184 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1186 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1187 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1188 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1192 (int)(RTE_PKTMBUF_HEADROOM +
1193 dev_info.min_rx_bufsize),
1194 (int)RTE_PKTMBUF_HEADROOM,
1195 (int)dev_info.min_rx_bufsize);
1199 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1200 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1201 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1203 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1204 "should be: <= %hu, = %hu, and a product of %hu\n",
1206 dev_info.rx_desc_lim.nb_max,
1207 dev_info.rx_desc_lim.nb_min,
1208 dev_info.rx_desc_lim.nb_align);
1212 if (rx_conf == NULL)
1213 rx_conf = &dev_info.default_rxconf;
1215 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1216 socket_id, rx_conf, mp);
1218 if (!dev->data->min_rx_buf_size ||
1219 dev->data->min_rx_buf_size > mbp_buf_size)
1220 dev->data->min_rx_buf_size = mbp_buf_size;
1227 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1228 uint16_t nb_tx_desc, unsigned int socket_id,
1229 const struct rte_eth_txconf *tx_conf)
1231 struct rte_eth_dev *dev;
1232 struct rte_eth_dev_info dev_info;
1234 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1236 dev = &rte_eth_devices[port_id];
1237 if (tx_queue_id >= dev->data->nb_tx_queues) {
1238 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1242 if (dev->data->dev_started) {
1243 RTE_PMD_DEBUG_TRACE(
1244 "port %d must be stopped to allow configuration\n", port_id);
1248 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1249 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1251 rte_eth_dev_info_get(port_id, &dev_info);
1253 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1254 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1255 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1256 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1257 "should be: <= %hu, = %hu, and a product of %hu\n",
1259 dev_info.tx_desc_lim.nb_max,
1260 dev_info.tx_desc_lim.nb_min,
1261 dev_info.tx_desc_lim.nb_align);
1265 if (tx_conf == NULL)
1266 tx_conf = &dev_info.default_txconf;
1268 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1269 socket_id, tx_conf);
1273 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
1274 void *userdata __rte_unused)
1278 for (i = 0; i < unsent; i++)
1279 rte_pktmbuf_free(pkts[i]);
1283 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
1286 uint64_t *count = userdata;
1289 for (i = 0; i < unsent; i++)
1290 rte_pktmbuf_free(pkts[i]);
1296 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
1297 buffer_tx_error_fn cbfn, void *userdata)
1299 buffer->error_callback = cbfn;
1300 buffer->error_userdata = userdata;
1305 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
1312 buffer->size = size;
1313 if (buffer->error_callback == NULL) {
1314 ret = rte_eth_tx_buffer_set_err_callback(
1315 buffer, rte_eth_tx_buffer_drop_callback, NULL);
1322 rte_eth_promiscuous_enable(uint8_t port_id)
1324 struct rte_eth_dev *dev;
1326 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1327 dev = &rte_eth_devices[port_id];
1329 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1330 (*dev->dev_ops->promiscuous_enable)(dev);
1331 dev->data->promiscuous = 1;
1335 rte_eth_promiscuous_disable(uint8_t port_id)
1337 struct rte_eth_dev *dev;
1339 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1340 dev = &rte_eth_devices[port_id];
1342 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1343 dev->data->promiscuous = 0;
1344 (*dev->dev_ops->promiscuous_disable)(dev);
1348 rte_eth_promiscuous_get(uint8_t port_id)
1350 struct rte_eth_dev *dev;
1352 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1354 dev = &rte_eth_devices[port_id];
1355 return dev->data->promiscuous;
1359 rte_eth_allmulticast_enable(uint8_t port_id)
1361 struct rte_eth_dev *dev;
1363 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1364 dev = &rte_eth_devices[port_id];
1366 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1367 (*dev->dev_ops->allmulticast_enable)(dev);
1368 dev->data->all_multicast = 1;
1372 rte_eth_allmulticast_disable(uint8_t port_id)
1374 struct rte_eth_dev *dev;
1376 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1377 dev = &rte_eth_devices[port_id];
1379 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1380 dev->data->all_multicast = 0;
1381 (*dev->dev_ops->allmulticast_disable)(dev);
1385 rte_eth_allmulticast_get(uint8_t port_id)
1387 struct rte_eth_dev *dev;
1389 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1391 dev = &rte_eth_devices[port_id];
1392 return dev->data->all_multicast;
1396 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1397 struct rte_eth_link *link)
1399 struct rte_eth_link *dst = link;
1400 struct rte_eth_link *src = &(dev->data->dev_link);
1402 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1403 *(uint64_t *)src) == 0)
1410 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1412 struct rte_eth_dev *dev;
1414 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1415 dev = &rte_eth_devices[port_id];
1417 if (dev->data->dev_conf.intr_conf.lsc != 0)
1418 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1420 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1421 (*dev->dev_ops->link_update)(dev, 1);
1422 *eth_link = dev->data->dev_link;
1427 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1429 struct rte_eth_dev *dev;
1431 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1432 dev = &rte_eth_devices[port_id];
1434 if (dev->data->dev_conf.intr_conf.lsc != 0)
1435 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1437 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1438 (*dev->dev_ops->link_update)(dev, 0);
1439 *eth_link = dev->data->dev_link;
1444 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1446 struct rte_eth_dev *dev;
1448 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1450 dev = &rte_eth_devices[port_id];
1451 memset(stats, 0, sizeof(*stats));
1453 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1454 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1455 (*dev->dev_ops->stats_get)(dev, stats);
1460 rte_eth_stats_reset(uint8_t port_id)
1462 struct rte_eth_dev *dev;
1464 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1465 dev = &rte_eth_devices[port_id];
1467 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1468 (*dev->dev_ops->stats_reset)(dev);
1469 dev->data->rx_mbuf_alloc_failed = 0;
1473 get_xstats_count(uint8_t port_id)
1475 struct rte_eth_dev *dev;
1478 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1479 dev = &rte_eth_devices[port_id];
1480 if (dev->dev_ops->xstats_get_names != NULL) {
1481 count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0);
1486 count += RTE_NB_STATS;
1487 count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
1488 count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
1493 rte_eth_xstats_get_names(uint8_t port_id,
1494 struct rte_eth_xstat_name *xstats_names,
1497 struct rte_eth_dev *dev;
1498 int cnt_used_entries;
1499 int cnt_expected_entries;
1500 int cnt_driver_entries;
1501 uint32_t idx, id_queue;
1503 cnt_expected_entries = get_xstats_count(port_id);
1504 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1505 (int)size < cnt_expected_entries)
1506 return cnt_expected_entries;
1508 /* port_id checked in get_xstats_count() */
1509 dev = &rte_eth_devices[port_id];
1510 cnt_used_entries = 0;
1512 for (idx = 0; idx < RTE_NB_STATS; idx++) {
1513 snprintf(xstats_names[cnt_used_entries].name,
1514 sizeof(xstats_names[0].name),
1515 "%s", rte_stats_strings[idx].name);
1518 for (id_queue = 0; id_queue < dev->data->nb_rx_queues; id_queue++) {
1519 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1520 snprintf(xstats_names[cnt_used_entries].name,
1521 sizeof(xstats_names[0].name),
1523 id_queue, rte_rxq_stats_strings[idx].name);
1528 for (id_queue = 0; id_queue < dev->data->nb_tx_queues; id_queue++) {
1529 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
1530 snprintf(xstats_names[cnt_used_entries].name,
1531 sizeof(xstats_names[0].name),
1533 id_queue, rte_txq_stats_strings[idx].name);
1538 if (dev->dev_ops->xstats_get_names != NULL) {
1539 /* If there are any driver-specific xstats, append them
1542 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
1544 xstats_names + cnt_used_entries,
1545 size - cnt_used_entries);
1546 if (cnt_driver_entries < 0)
1547 return cnt_driver_entries;
1548 cnt_used_entries += cnt_driver_entries;
1551 return cnt_used_entries;
1554 /* retrieve ethdev extended statistics */
1556 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstat *xstats,
1559 struct rte_eth_stats eth_stats;
1560 struct rte_eth_dev *dev;
1561 unsigned count = 0, i, q;
1563 uint64_t val, *stats_ptr;
1565 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1567 dev = &rte_eth_devices[port_id];
1569 /* Return generic statistics */
1570 count = RTE_NB_STATS + (dev->data->nb_rx_queues * RTE_NB_RXQ_STATS) +
1571 (dev->data->nb_tx_queues * RTE_NB_TXQ_STATS);
1573 /* implemented by the driver */
1574 if (dev->dev_ops->xstats_get != NULL) {
1575 /* Retrieve the xstats from the driver at the end of the
1578 xcount = (*dev->dev_ops->xstats_get)(dev,
1579 xstats ? xstats + count : NULL,
1580 (n > count) ? n - count : 0);
1586 if (n < count + xcount || xstats == NULL)
1587 return count + xcount;
1589 /* now fill the xstats structure */
1591 rte_eth_stats_get(port_id, ð_stats);
1594 for (i = 0; i < RTE_NB_STATS; i++) {
1595 stats_ptr = RTE_PTR_ADD(ð_stats,
1596 rte_stats_strings[i].offset);
1598 xstats[count++].value = val;
1602 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1603 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1604 stats_ptr = RTE_PTR_ADD(ð_stats,
1605 rte_rxq_stats_strings[i].offset +
1606 q * sizeof(uint64_t));
1608 xstats[count++].value = val;
1613 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1614 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1615 stats_ptr = RTE_PTR_ADD(ð_stats,
1616 rte_txq_stats_strings[i].offset +
1617 q * sizeof(uint64_t));
1619 xstats[count++].value = val;
1623 for (i = 0; i < count + xcount; i++)
1626 return count + xcount;
1629 /* reset ethdev extended statistics */
1631 rte_eth_xstats_reset(uint8_t port_id)
1633 struct rte_eth_dev *dev;
1635 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1636 dev = &rte_eth_devices[port_id];
1638 /* implemented by the driver */
1639 if (dev->dev_ops->xstats_reset != NULL) {
1640 (*dev->dev_ops->xstats_reset)(dev);
1644 /* fallback to default */
1645 rte_eth_stats_reset(port_id);
1649 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1652 struct rte_eth_dev *dev;
1654 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1656 dev = &rte_eth_devices[port_id];
1658 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1659 return (*dev->dev_ops->queue_stats_mapping_set)
1660 (dev, queue_id, stat_idx, is_rx);
1665 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1668 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1674 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1677 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1682 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1684 struct rte_eth_dev *dev;
1685 const struct rte_eth_desc_lim lim = {
1686 .nb_max = UINT16_MAX,
1691 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1692 dev = &rte_eth_devices[port_id];
1694 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1695 dev_info->rx_desc_lim = lim;
1696 dev_info->tx_desc_lim = lim;
1698 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1699 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1700 dev_info->pci_dev = dev->pci_dev;
1701 dev_info->driver_name = dev->data->drv_name;
1702 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
1703 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
1707 rte_eth_dev_get_supported_ptypes(uint8_t port_id, uint32_t ptype_mask,
1708 uint32_t *ptypes, int num)
1711 struct rte_eth_dev *dev;
1712 const uint32_t *all_ptypes;
1714 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1715 dev = &rte_eth_devices[port_id];
1716 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
1717 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
1722 for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
1723 if (all_ptypes[i] & ptype_mask) {
1725 ptypes[j] = all_ptypes[i];
1733 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1735 struct rte_eth_dev *dev;
1737 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1738 dev = &rte_eth_devices[port_id];
1739 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1744 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1746 struct rte_eth_dev *dev;
1748 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1750 dev = &rte_eth_devices[port_id];
1751 *mtu = dev->data->mtu;
1756 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1759 struct rte_eth_dev *dev;
1761 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1762 dev = &rte_eth_devices[port_id];
1763 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1765 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1767 dev->data->mtu = mtu;
1773 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1775 struct rte_eth_dev *dev;
1777 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1778 dev = &rte_eth_devices[port_id];
1779 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1780 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1784 if (vlan_id > 4095) {
1785 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1786 port_id, (unsigned) vlan_id);
1789 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1791 return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1795 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1797 struct rte_eth_dev *dev;
1799 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1800 dev = &rte_eth_devices[port_id];
1801 if (rx_queue_id >= dev->data->nb_rx_queues) {
1802 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1806 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1807 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1813 rte_eth_dev_set_vlan_ether_type(uint8_t port_id,
1814 enum rte_vlan_type vlan_type,
1817 struct rte_eth_dev *dev;
1819 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1820 dev = &rte_eth_devices[port_id];
1821 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1823 return (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type, tpid);
1827 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1829 struct rte_eth_dev *dev;
1834 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1835 dev = &rte_eth_devices[port_id];
1837 /*check which option changed by application*/
1838 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1839 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1841 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1842 mask |= ETH_VLAN_STRIP_MASK;
1845 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1846 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1848 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1849 mask |= ETH_VLAN_FILTER_MASK;
1852 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1853 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1855 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1856 mask |= ETH_VLAN_EXTEND_MASK;
1863 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1864 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1870 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1872 struct rte_eth_dev *dev;
1875 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1876 dev = &rte_eth_devices[port_id];
1878 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1879 ret |= ETH_VLAN_STRIP_OFFLOAD;
1881 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1882 ret |= ETH_VLAN_FILTER_OFFLOAD;
1884 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1885 ret |= ETH_VLAN_EXTEND_OFFLOAD;
1891 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1893 struct rte_eth_dev *dev;
1895 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1896 dev = &rte_eth_devices[port_id];
1897 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1898 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1904 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1906 struct rte_eth_dev *dev;
1908 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1909 dev = &rte_eth_devices[port_id];
1910 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1911 memset(fc_conf, 0, sizeof(*fc_conf));
1912 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1916 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1918 struct rte_eth_dev *dev;
1920 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1921 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1922 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1926 dev = &rte_eth_devices[port_id];
1927 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1928 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1932 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1934 struct rte_eth_dev *dev;
1936 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1937 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1938 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1942 dev = &rte_eth_devices[port_id];
1943 /* High water, low water validation are device specific */
1944 if (*dev->dev_ops->priority_flow_ctrl_set)
1945 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1950 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
1958 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
1959 RTE_PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
1960 RTE_RETA_GROUP_SIZE);
1964 num = reta_size / RTE_RETA_GROUP_SIZE;
1965 for (i = 0; i < num; i++) {
1966 if (reta_conf[i].mask)
1974 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
1978 uint16_t i, idx, shift;
1984 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
1988 for (i = 0; i < reta_size; i++) {
1989 idx = i / RTE_RETA_GROUP_SIZE;
1990 shift = i % RTE_RETA_GROUP_SIZE;
1991 if ((reta_conf[idx].mask & (1ULL << shift)) &&
1992 (reta_conf[idx].reta[shift] >= max_rxq)) {
1993 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
1994 "the maximum rxq index: %u\n", idx, shift,
1995 reta_conf[idx].reta[shift], max_rxq);
2004 rte_eth_dev_rss_reta_update(uint8_t port_id,
2005 struct rte_eth_rss_reta_entry64 *reta_conf,
2008 struct rte_eth_dev *dev;
2011 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2012 /* Check mask bits */
2013 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2017 dev = &rte_eth_devices[port_id];
2019 /* Check entry value */
2020 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2021 dev->data->nb_rx_queues);
2025 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2026 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2030 rte_eth_dev_rss_reta_query(uint8_t port_id,
2031 struct rte_eth_rss_reta_entry64 *reta_conf,
2034 struct rte_eth_dev *dev;
2037 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2039 /* Check mask bits */
2040 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2044 dev = &rte_eth_devices[port_id];
2045 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2046 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2050 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2052 struct rte_eth_dev *dev;
2053 uint16_t rss_hash_protos;
2055 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2056 rss_hash_protos = rss_conf->rss_hf;
2057 if ((rss_hash_protos != 0) &&
2058 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2059 RTE_PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2063 dev = &rte_eth_devices[port_id];
2064 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2065 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2069 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2070 struct rte_eth_rss_conf *rss_conf)
2072 struct rte_eth_dev *dev;
2074 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2075 dev = &rte_eth_devices[port_id];
2076 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2077 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2081 rte_eth_dev_udp_tunnel_port_add(uint8_t port_id,
2082 struct rte_eth_udp_tunnel *udp_tunnel)
2084 struct rte_eth_dev *dev;
2086 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2087 if (udp_tunnel == NULL) {
2088 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2092 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2093 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2097 dev = &rte_eth_devices[port_id];
2098 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
2099 return (*dev->dev_ops->udp_tunnel_port_add)(dev, udp_tunnel);
2103 rte_eth_dev_udp_tunnel_port_delete(uint8_t port_id,
2104 struct rte_eth_udp_tunnel *udp_tunnel)
2106 struct rte_eth_dev *dev;
2108 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2109 dev = &rte_eth_devices[port_id];
2111 if (udp_tunnel == NULL) {
2112 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2116 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2117 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2121 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
2122 return (*dev->dev_ops->udp_tunnel_port_del)(dev, udp_tunnel);
2126 rte_eth_led_on(uint8_t port_id)
2128 struct rte_eth_dev *dev;
2130 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2131 dev = &rte_eth_devices[port_id];
2132 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2133 return (*dev->dev_ops->dev_led_on)(dev);
2137 rte_eth_led_off(uint8_t port_id)
2139 struct rte_eth_dev *dev;
2141 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2142 dev = &rte_eth_devices[port_id];
2143 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2144 return (*dev->dev_ops->dev_led_off)(dev);
2148 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2152 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2154 struct rte_eth_dev_info dev_info;
2155 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2158 rte_eth_dev_info_get(port_id, &dev_info);
2160 for (i = 0; i < dev_info.max_mac_addrs; i++)
2161 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2167 static const struct ether_addr null_mac_addr;
2170 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2173 struct rte_eth_dev *dev;
2177 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2178 dev = &rte_eth_devices[port_id];
2179 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2181 if (is_zero_ether_addr(addr)) {
2182 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2186 if (pool >= ETH_64_POOLS) {
2187 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2191 index = get_mac_addr_index(port_id, addr);
2193 index = get_mac_addr_index(port_id, &null_mac_addr);
2195 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2200 pool_mask = dev->data->mac_pool_sel[index];
2202 /* Check if both MAC address and pool is already there, and do nothing */
2203 if (pool_mask & (1ULL << pool))
2208 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2210 /* Update address in NIC data structure */
2211 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2213 /* Update pool bitmap in NIC data structure */
2214 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2220 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2222 struct rte_eth_dev *dev;
2225 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2226 dev = &rte_eth_devices[port_id];
2227 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2229 index = get_mac_addr_index(port_id, addr);
2231 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2233 } else if (index < 0)
2234 return 0; /* Do nothing if address wasn't found */
2237 (*dev->dev_ops->mac_addr_remove)(dev, index);
2239 /* Update address in NIC data structure */
2240 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2242 /* reset pool bitmap */
2243 dev->data->mac_pool_sel[index] = 0;
2249 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2251 struct rte_eth_dev *dev;
2253 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2255 if (!is_valid_assigned_ether_addr(addr))
2258 dev = &rte_eth_devices[port_id];
2259 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2261 /* Update default address in NIC data structure */
2262 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2264 (*dev->dev_ops->mac_addr_set)(dev, addr);
2270 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2271 uint16_t rx_mode, uint8_t on)
2274 struct rte_eth_dev *dev;
2275 struct rte_eth_dev_info dev_info;
2277 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2279 dev = &rte_eth_devices[port_id];
2280 rte_eth_dev_info_get(port_id, &dev_info);
2282 num_vfs = dev_info.max_vfs;
2284 RTE_PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2289 RTE_PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2292 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2293 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2297 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2301 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2303 struct rte_eth_dev_info dev_info;
2304 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2307 rte_eth_dev_info_get(port_id, &dev_info);
2308 if (!dev->data->hash_mac_addrs)
2311 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2312 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2313 ETHER_ADDR_LEN) == 0)
2320 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2325 struct rte_eth_dev *dev;
2327 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2329 dev = &rte_eth_devices[port_id];
2330 if (is_zero_ether_addr(addr)) {
2331 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2336 index = get_hash_mac_addr_index(port_id, addr);
2337 /* Check if it's already there, and do nothing */
2338 if ((index >= 0) && (on))
2343 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2344 "set in UTA\n", port_id);
2348 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2350 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2356 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2357 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2359 /* Update address in NIC data structure */
2361 ether_addr_copy(addr,
2362 &dev->data->hash_mac_addrs[index]);
2364 ether_addr_copy(&null_mac_addr,
2365 &dev->data->hash_mac_addrs[index]);
2372 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2374 struct rte_eth_dev *dev;
2376 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2378 dev = &rte_eth_devices[port_id];
2380 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2381 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2385 rte_eth_dev_set_vf_rx(uint8_t port_id, uint16_t vf, uint8_t on)
2388 struct rte_eth_dev *dev;
2389 struct rte_eth_dev_info dev_info;
2391 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2393 dev = &rte_eth_devices[port_id];
2394 rte_eth_dev_info_get(port_id, &dev_info);
2396 num_vfs = dev_info.max_vfs;
2398 RTE_PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2402 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2403 return (*dev->dev_ops->set_vf_rx)(dev, vf, on);
2407 rte_eth_dev_set_vf_tx(uint8_t port_id, uint16_t vf, uint8_t on)
2410 struct rte_eth_dev *dev;
2411 struct rte_eth_dev_info dev_info;
2413 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2415 dev = &rte_eth_devices[port_id];
2416 rte_eth_dev_info_get(port_id, &dev_info);
2418 num_vfs = dev_info.max_vfs;
2420 RTE_PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2424 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2425 return (*dev->dev_ops->set_vf_tx)(dev, vf, on);
2429 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2430 uint64_t vf_mask, uint8_t vlan_on)
2432 struct rte_eth_dev *dev;
2434 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2436 dev = &rte_eth_devices[port_id];
2438 if (vlan_id > ETHER_MAX_VLAN_ID) {
2439 RTE_PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2445 RTE_PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2449 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2450 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2454 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2457 struct rte_eth_dev *dev;
2458 struct rte_eth_dev_info dev_info;
2459 struct rte_eth_link link;
2461 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2463 dev = &rte_eth_devices[port_id];
2464 rte_eth_dev_info_get(port_id, &dev_info);
2465 link = dev->data->dev_link;
2467 if (queue_idx > dev_info.max_tx_queues) {
2468 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2469 "invalid queue id=%d\n", port_id, queue_idx);
2473 if (tx_rate > link.link_speed) {
2474 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2475 "bigger than link speed= %d\n",
2476 tx_rate, link.link_speed);
2480 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2481 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2484 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2487 struct rte_eth_dev *dev;
2488 struct rte_eth_dev_info dev_info;
2489 struct rte_eth_link link;
2494 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2496 dev = &rte_eth_devices[port_id];
2497 rte_eth_dev_info_get(port_id, &dev_info);
2498 link = dev->data->dev_link;
2500 if (vf > dev_info.max_vfs) {
2501 RTE_PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2502 "invalid vf id=%d\n", port_id, vf);
2506 if (tx_rate > link.link_speed) {
2507 RTE_PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2508 "bigger than link speed= %d\n",
2509 tx_rate, link.link_speed);
2513 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2514 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2518 rte_eth_mirror_rule_set(uint8_t port_id,
2519 struct rte_eth_mirror_conf *mirror_conf,
2520 uint8_t rule_id, uint8_t on)
2522 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2524 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2525 if (mirror_conf->rule_type == 0) {
2526 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2530 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2531 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2536 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2537 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2538 (mirror_conf->pool_mask == 0)) {
2539 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2543 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2544 mirror_conf->vlan.vlan_mask == 0) {
2545 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2549 dev = &rte_eth_devices[port_id];
2550 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2552 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2556 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2558 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2560 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2562 dev = &rte_eth_devices[port_id];
2563 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2565 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2569 rte_eth_dev_callback_register(uint8_t port_id,
2570 enum rte_eth_event_type event,
2571 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2573 struct rte_eth_dev *dev;
2574 struct rte_eth_dev_callback *user_cb;
2579 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2581 dev = &rte_eth_devices[port_id];
2582 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2584 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2585 if (user_cb->cb_fn == cb_fn &&
2586 user_cb->cb_arg == cb_arg &&
2587 user_cb->event == event) {
2592 /* create a new callback. */
2593 if (user_cb == NULL)
2594 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2595 sizeof(struct rte_eth_dev_callback), 0);
2596 if (user_cb != NULL) {
2597 user_cb->cb_fn = cb_fn;
2598 user_cb->cb_arg = cb_arg;
2599 user_cb->event = event;
2600 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2603 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2604 return (user_cb == NULL) ? -ENOMEM : 0;
2608 rte_eth_dev_callback_unregister(uint8_t port_id,
2609 enum rte_eth_event_type event,
2610 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2613 struct rte_eth_dev *dev;
2614 struct rte_eth_dev_callback *cb, *next;
2619 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2621 dev = &rte_eth_devices[port_id];
2622 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2625 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2627 next = TAILQ_NEXT(cb, next);
2629 if (cb->cb_fn != cb_fn || cb->event != event ||
2630 (cb->cb_arg != (void *)-1 &&
2631 cb->cb_arg != cb_arg))
2635 * if this callback is not executing right now,
2638 if (cb->active == 0) {
2639 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2646 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2651 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2652 enum rte_eth_event_type event)
2654 struct rte_eth_dev_callback *cb_lst;
2655 struct rte_eth_dev_callback dev_cb;
2657 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2658 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2659 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2663 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2664 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2666 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2669 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2673 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
2676 struct rte_eth_dev *dev;
2677 struct rte_intr_handle *intr_handle;
2681 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2683 dev = &rte_eth_devices[port_id];
2684 intr_handle = &dev->pci_dev->intr_handle;
2685 if (!intr_handle->intr_vec) {
2686 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2690 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2691 vec = intr_handle->intr_vec[qid];
2692 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2693 if (rc && rc != -EEXIST) {
2694 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2695 " op %d epfd %d vec %u\n",
2696 port_id, qid, op, epfd, vec);
2703 const struct rte_memzone *
2704 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2705 uint16_t queue_id, size_t size, unsigned align,
2708 char z_name[RTE_MEMZONE_NAMESIZE];
2709 const struct rte_memzone *mz;
2711 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2712 dev->driver->pci_drv.name, ring_name,
2713 dev->data->port_id, queue_id);
2715 mz = rte_memzone_lookup(z_name);
2719 if (rte_xen_dom0_supported())
2720 return rte_memzone_reserve_bounded(z_name, size, socket_id,
2721 0, align, RTE_PGSIZE_2M);
2723 return rte_memzone_reserve_aligned(z_name, size, socket_id,
2728 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
2729 int epfd, int op, void *data)
2732 struct rte_eth_dev *dev;
2733 struct rte_intr_handle *intr_handle;
2736 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2738 dev = &rte_eth_devices[port_id];
2739 if (queue_id >= dev->data->nb_rx_queues) {
2740 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
2744 intr_handle = &dev->pci_dev->intr_handle;
2745 if (!intr_handle->intr_vec) {
2746 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2750 vec = intr_handle->intr_vec[queue_id];
2751 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2752 if (rc && rc != -EEXIST) {
2753 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2754 " op %d epfd %d vec %u\n",
2755 port_id, queue_id, op, epfd, vec);
2763 rte_eth_dev_rx_intr_enable(uint8_t port_id,
2766 struct rte_eth_dev *dev;
2768 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2770 dev = &rte_eth_devices[port_id];
2772 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
2773 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
2777 rte_eth_dev_rx_intr_disable(uint8_t port_id,
2780 struct rte_eth_dev *dev;
2782 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2784 dev = &rte_eth_devices[port_id];
2786 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
2787 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
2790 #ifdef RTE_NIC_BYPASS
2791 int rte_eth_dev_bypass_init(uint8_t port_id)
2793 struct rte_eth_dev *dev;
2795 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2797 dev = &rte_eth_devices[port_id];
2798 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2799 (*dev->dev_ops->bypass_init)(dev);
2804 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2806 struct rte_eth_dev *dev;
2808 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2810 dev = &rte_eth_devices[port_id];
2811 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2812 (*dev->dev_ops->bypass_state_show)(dev, state);
2817 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2819 struct rte_eth_dev *dev;
2821 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2823 dev = &rte_eth_devices[port_id];
2824 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2825 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2830 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2832 struct rte_eth_dev *dev;
2834 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2836 dev = &rte_eth_devices[port_id];
2837 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2838 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2843 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2845 struct rte_eth_dev *dev;
2847 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2849 dev = &rte_eth_devices[port_id];
2851 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2852 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2857 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2859 struct rte_eth_dev *dev;
2861 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2863 dev = &rte_eth_devices[port_id];
2865 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2866 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2871 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2873 struct rte_eth_dev *dev;
2875 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2877 dev = &rte_eth_devices[port_id];
2879 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2880 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2885 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2887 struct rte_eth_dev *dev;
2889 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2891 dev = &rte_eth_devices[port_id];
2893 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2894 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2899 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2901 struct rte_eth_dev *dev;
2903 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2905 dev = &rte_eth_devices[port_id];
2907 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2908 (*dev->dev_ops->bypass_wd_reset)(dev);
2914 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
2916 struct rte_eth_dev *dev;
2918 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2920 dev = &rte_eth_devices[port_id];
2921 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2922 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
2923 RTE_ETH_FILTER_NOP, NULL);
2927 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
2928 enum rte_filter_op filter_op, void *arg)
2930 struct rte_eth_dev *dev;
2932 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2934 dev = &rte_eth_devices[port_id];
2935 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2936 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
2940 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
2941 rte_rx_callback_fn fn, void *user_param)
2943 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2944 rte_errno = ENOTSUP;
2947 /* check input parameters */
2948 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2949 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2953 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2961 cb->param = user_param;
2963 rte_spinlock_lock(&rte_eth_rx_cb_lock);
2964 /* Add the callbacks in fifo order. */
2965 struct rte_eth_rxtx_callback *tail =
2966 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2969 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2976 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
2982 rte_eth_add_first_rx_callback(uint8_t port_id, uint16_t queue_id,
2983 rte_rx_callback_fn fn, void *user_param)
2985 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2986 rte_errno = ENOTSUP;
2989 /* check input parameters */
2990 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2991 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2996 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3004 cb->param = user_param;
3006 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3007 /* Add the callbacks at fisrt position*/
3008 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3010 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3011 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3017 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
3018 rte_tx_callback_fn fn, void *user_param)
3020 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3021 rte_errno = ENOTSUP;
3024 /* check input parameters */
3025 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3026 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3031 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3039 cb->param = user_param;
3041 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3042 /* Add the callbacks in fifo order. */
3043 struct rte_eth_rxtx_callback *tail =
3044 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3047 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3054 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3060 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3061 struct rte_eth_rxtx_callback *user_cb)
3063 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3066 /* Check input parameters. */
3067 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3068 if (user_cb == NULL ||
3069 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
3072 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3073 struct rte_eth_rxtx_callback *cb;
3074 struct rte_eth_rxtx_callback **prev_cb;
3077 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3078 prev_cb = &dev->post_rx_burst_cbs[queue_id];
3079 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3081 if (cb == user_cb) {
3082 /* Remove the user cb from the callback list. */
3083 *prev_cb = cb->next;
3088 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3094 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3095 struct rte_eth_rxtx_callback *user_cb)
3097 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3100 /* Check input parameters. */
3101 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3102 if (user_cb == NULL ||
3103 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
3106 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3108 struct rte_eth_rxtx_callback *cb;
3109 struct rte_eth_rxtx_callback **prev_cb;
3111 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3112 prev_cb = &dev->pre_tx_burst_cbs[queue_id];
3113 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3115 if (cb == user_cb) {
3116 /* Remove the user cb from the callback list. */
3117 *prev_cb = cb->next;
3122 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3128 rte_eth_rx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3129 struct rte_eth_rxq_info *qinfo)
3131 struct rte_eth_dev *dev;
3133 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3138 dev = &rte_eth_devices[port_id];
3139 if (queue_id >= dev->data->nb_rx_queues) {
3140 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3144 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3146 memset(qinfo, 0, sizeof(*qinfo));
3147 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3152 rte_eth_tx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3153 struct rte_eth_txq_info *qinfo)
3155 struct rte_eth_dev *dev;
3157 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3162 dev = &rte_eth_devices[port_id];
3163 if (queue_id >= dev->data->nb_tx_queues) {
3164 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3168 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3170 memset(qinfo, 0, sizeof(*qinfo));
3171 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3176 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3177 struct ether_addr *mc_addr_set,
3178 uint32_t nb_mc_addr)
3180 struct rte_eth_dev *dev;
3182 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3184 dev = &rte_eth_devices[port_id];
3185 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3186 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3190 rte_eth_timesync_enable(uint8_t port_id)
3192 struct rte_eth_dev *dev;
3194 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3195 dev = &rte_eth_devices[port_id];
3197 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3198 return (*dev->dev_ops->timesync_enable)(dev);
3202 rte_eth_timesync_disable(uint8_t port_id)
3204 struct rte_eth_dev *dev;
3206 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3207 dev = &rte_eth_devices[port_id];
3209 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3210 return (*dev->dev_ops->timesync_disable)(dev);
3214 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3217 struct rte_eth_dev *dev;
3219 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3220 dev = &rte_eth_devices[port_id];
3222 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3223 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3227 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3229 struct rte_eth_dev *dev;
3231 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3232 dev = &rte_eth_devices[port_id];
3234 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3235 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3239 rte_eth_timesync_adjust_time(uint8_t port_id, int64_t delta)
3241 struct rte_eth_dev *dev;
3243 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3244 dev = &rte_eth_devices[port_id];
3246 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3247 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3251 rte_eth_timesync_read_time(uint8_t port_id, struct timespec *timestamp)
3253 struct rte_eth_dev *dev;
3255 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3256 dev = &rte_eth_devices[port_id];
3258 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3259 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3263 rte_eth_timesync_write_time(uint8_t port_id, const struct timespec *timestamp)
3265 struct rte_eth_dev *dev;
3267 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3268 dev = &rte_eth_devices[port_id];
3270 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3271 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3275 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3277 struct rte_eth_dev *dev;
3279 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3281 dev = &rte_eth_devices[port_id];
3282 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3283 return (*dev->dev_ops->get_reg)(dev, info);
3287 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3289 struct rte_eth_dev *dev;
3291 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3293 dev = &rte_eth_devices[port_id];
3294 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3295 return (*dev->dev_ops->get_eeprom_length)(dev);
3299 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3301 struct rte_eth_dev *dev;
3303 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3305 dev = &rte_eth_devices[port_id];
3306 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3307 return (*dev->dev_ops->get_eeprom)(dev, info);
3311 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3313 struct rte_eth_dev *dev;
3315 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3317 dev = &rte_eth_devices[port_id];
3318 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3319 return (*dev->dev_ops->set_eeprom)(dev, info);
3323 rte_eth_dev_get_dcb_info(uint8_t port_id,
3324 struct rte_eth_dcb_info *dcb_info)
3326 struct rte_eth_dev *dev;
3328 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3330 dev = &rte_eth_devices[port_id];
3331 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3333 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3334 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3338 rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_dev)
3340 if ((eth_dev == NULL) || (pci_dev == NULL)) {
3341 RTE_PMD_DEBUG_TRACE("NULL pointer eth_dev=%p pci_dev=%p\n",
3346 eth_dev->data->dev_flags = 0;
3347 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
3348 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
3349 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_DETACHABLE)
3350 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
3352 eth_dev->data->kdrv = pci_dev->kdrv;
3353 eth_dev->data->numa_node = pci_dev->numa_node;
3354 eth_dev->data->drv_name = pci_dev->driver->name;
3358 rte_eth_dev_l2_tunnel_eth_type_conf(uint8_t port_id,
3359 struct rte_eth_l2_tunnel_conf *l2_tunnel)
3361 struct rte_eth_dev *dev;
3363 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3364 if (l2_tunnel == NULL) {
3365 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3369 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3370 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
3374 dev = &rte_eth_devices[port_id];
3375 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
3377 return (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev, l2_tunnel);
3381 rte_eth_dev_l2_tunnel_offload_set(uint8_t port_id,
3382 struct rte_eth_l2_tunnel_conf *l2_tunnel,
3386 struct rte_eth_dev *dev;
3388 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3390 if (l2_tunnel == NULL) {
3391 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3395 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3396 RTE_PMD_DEBUG_TRACE("Invalid tunnel type.\n");
3401 RTE_PMD_DEBUG_TRACE("Mask should have a value.\n");
3405 dev = &rte_eth_devices[port_id];
3406 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
3408 return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);