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_create_unique_device_name(char *name, size_t size,
224 struct rte_pci_device *pci_dev)
228 ret = snprintf(name, size, "%d:%d.%d",
229 pci_dev->addr.bus, pci_dev->addr.devid,
230 pci_dev->addr.function);
237 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
242 eth_dev->attached = DEV_DETACHED;
248 rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
249 struct rte_pci_device *pci_dev)
251 struct eth_driver *eth_drv;
252 struct rte_eth_dev *eth_dev;
253 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
257 eth_drv = (struct eth_driver *)pci_drv;
259 /* Create unique Ethernet device name using PCI address */
260 rte_eth_dev_create_unique_device_name(ethdev_name,
261 sizeof(ethdev_name), pci_dev);
263 eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
267 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
268 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
269 eth_drv->dev_private_size,
270 RTE_CACHE_LINE_SIZE);
271 if (eth_dev->data->dev_private == NULL)
272 rte_panic("Cannot allocate memzone for private port data\n");
274 eth_dev->pci_dev = pci_dev;
275 eth_dev->driver = eth_drv;
276 eth_dev->data->rx_mbuf_alloc_failed = 0;
278 /* init user callbacks */
279 TAILQ_INIT(&(eth_dev->link_intr_cbs));
282 * Set the default MTU.
284 eth_dev->data->mtu = ETHER_MTU;
286 /* Invoke PMD device initialization function */
287 diag = (*eth_drv->eth_dev_init)(eth_dev);
291 RTE_PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x) failed\n",
293 (unsigned) pci_dev->id.vendor_id,
294 (unsigned) pci_dev->id.device_id);
295 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
296 rte_free(eth_dev->data->dev_private);
297 rte_eth_dev_release_port(eth_dev);
302 rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
304 const struct eth_driver *eth_drv;
305 struct rte_eth_dev *eth_dev;
306 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
312 /* Create unique Ethernet device name using PCI address */
313 rte_eth_dev_create_unique_device_name(ethdev_name,
314 sizeof(ethdev_name), pci_dev);
316 eth_dev = rte_eth_dev_allocated(ethdev_name);
320 eth_drv = (const struct eth_driver *)pci_dev->driver;
322 /* Invoke PMD device uninit function */
323 if (*eth_drv->eth_dev_uninit) {
324 ret = (*eth_drv->eth_dev_uninit)(eth_dev);
329 /* free ether device */
330 rte_eth_dev_release_port(eth_dev);
332 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
333 rte_free(eth_dev->data->dev_private);
335 eth_dev->pci_dev = NULL;
336 eth_dev->driver = NULL;
337 eth_dev->data = NULL;
343 rte_eth_dev_is_valid_port(uint8_t port_id)
345 if (port_id >= RTE_MAX_ETHPORTS ||
346 rte_eth_devices[port_id].attached != DEV_ATTACHED)
353 rte_eth_dev_socket_id(uint8_t port_id)
355 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
356 return rte_eth_devices[port_id].data->numa_node;
360 rte_eth_dev_count(void)
365 static enum rte_eth_dev_type
366 rte_eth_dev_get_device_type(uint8_t port_id)
368 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, RTE_ETH_DEV_UNKNOWN);
369 return rte_eth_devices[port_id].dev_type;
373 rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr)
375 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
378 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
382 *addr = rte_eth_devices[port_id].pci_dev->addr;
387 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
391 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
394 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
398 /* shouldn't check 'rte_eth_devices[i].data',
399 * because it might be overwritten by VDEV PMD */
400 tmp = rte_eth_dev_data[port_id].name;
406 rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
411 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
415 *port_id = RTE_MAX_ETHPORTS;
417 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
420 rte_eth_dev_data[i].name, strlen(name))) {
431 rte_eth_dev_get_port_by_addr(const struct rte_pci_addr *addr, uint8_t *port_id)
434 struct rte_pci_device *pci_dev = NULL;
437 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
441 *port_id = RTE_MAX_ETHPORTS;
443 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
445 pci_dev = rte_eth_devices[i].pci_dev;
448 !rte_eal_compare_pci_addr(&pci_dev->addr, addr)) {
459 rte_eth_dev_is_detachable(uint8_t port_id)
463 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
465 switch (rte_eth_devices[port_id].data->kdrv) {
466 case RTE_KDRV_IGB_UIO:
467 case RTE_KDRV_UIO_GENERIC:
468 case RTE_KDRV_NIC_UIO:
475 dev_flags = rte_eth_devices[port_id].data->dev_flags;
476 if ((dev_flags & RTE_ETH_DEV_DETACHABLE) &&
477 (!(dev_flags & RTE_ETH_DEV_BONDED_SLAVE)))
483 /* attach the new physical device, then store port_id of the device */
485 rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
487 /* re-construct pci_device_list */
488 if (rte_eal_pci_scan())
490 /* Invoke probe func of the driver can handle the new device. */
491 if (rte_eal_pci_probe_one(addr))
494 if (rte_eth_dev_get_port_by_addr(addr, port_id))
502 /* detach the new physical device, then store pci_addr of the device */
504 rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
506 struct rte_pci_addr freed_addr;
507 struct rte_pci_addr vp;
509 /* get pci address by port id */
510 if (rte_eth_dev_get_addr_by_port(port_id, &freed_addr))
513 /* Zeroed pci addr means the port comes from virtual device */
514 vp.domain = vp.bus = vp.devid = vp.function = 0;
515 if (rte_eal_compare_pci_addr(&vp, &freed_addr) == 0)
518 /* invoke remove func of the pci driver,
519 * also remove the device from pci_device_list */
520 if (rte_eal_pci_detach(&freed_addr))
529 /* attach the new virtual device, then store port_id of the device */
531 rte_eth_dev_attach_vdev(const char *vdevargs, uint8_t *port_id)
533 char *name = NULL, *args = NULL;
536 /* parse vdevargs, then retrieve device name and args */
537 if (rte_eal_parse_devargs_str(vdevargs, &name, &args))
540 /* walk around dev_driver_list to find the driver of the device,
541 * then invoke probe function of the driver.
542 * rte_eal_vdev_init() updates port_id allocated after
545 if (rte_eal_vdev_init(name, args))
548 if (rte_eth_dev_get_port_by_name(name, port_id))
559 /* detach the new virtual device, then store the name of the device */
561 rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
563 char name[RTE_ETH_NAME_MAX_LEN];
565 /* get device name by port id */
566 if (rte_eth_dev_get_name_by_port(port_id, name))
568 /* walk around dev_driver_list to find the driver of the device,
569 * then invoke uninit function of the driver */
570 if (rte_eal_vdev_uninit(name))
573 strncpy(vdevname, name, sizeof(name));
579 /* attach the new device, then store port_id of the device */
581 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
583 struct rte_pci_addr addr;
586 if ((devargs == NULL) || (port_id == NULL)) {
591 if (eal_parse_pci_DomBDF(devargs, &addr) == 0) {
592 ret = rte_eth_dev_attach_pdev(&addr, port_id);
596 ret = rte_eth_dev_attach_vdev(devargs, port_id);
603 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
607 /* detach the device, then store the name of the device */
609 rte_eth_dev_detach(uint8_t port_id, char *name)
611 struct rte_pci_addr addr;
619 /* check whether the driver supports detach feature, or not */
620 if (rte_eth_dev_is_detachable(port_id))
623 if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {
624 ret = rte_eth_dev_get_addr_by_port(port_id, &addr);
628 ret = rte_eth_dev_detach_pdev(port_id, &addr);
632 snprintf(name, RTE_ETH_NAME_MAX_LEN,
634 addr.domain, addr.bus,
635 addr.devid, addr.function);
637 ret = rte_eth_dev_detach_vdev(port_id, name);
645 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
650 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
652 uint16_t old_nb_queues = dev->data->nb_rx_queues;
656 if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */
657 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
658 sizeof(dev->data->rx_queues[0]) * nb_queues,
659 RTE_CACHE_LINE_SIZE);
660 if (dev->data->rx_queues == NULL) {
661 dev->data->nb_rx_queues = 0;
664 } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */
665 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
667 rxq = dev->data->rx_queues;
669 for (i = nb_queues; i < old_nb_queues; i++)
670 (*dev->dev_ops->rx_queue_release)(rxq[i]);
671 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
672 RTE_CACHE_LINE_SIZE);
675 if (nb_queues > old_nb_queues) {
676 uint16_t new_qs = nb_queues - old_nb_queues;
678 memset(rxq + old_nb_queues, 0,
679 sizeof(rxq[0]) * new_qs);
682 dev->data->rx_queues = rxq;
684 } else if (dev->data->rx_queues != NULL && nb_queues == 0) {
685 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
687 rxq = dev->data->rx_queues;
689 for (i = nb_queues; i < old_nb_queues; i++)
690 (*dev->dev_ops->rx_queue_release)(rxq[i]);
692 dev->data->nb_rx_queues = nb_queues;
697 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
699 struct rte_eth_dev *dev;
701 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
703 dev = &rte_eth_devices[port_id];
704 if (rx_queue_id >= dev->data->nb_rx_queues) {
705 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
709 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
711 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
712 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
713 " already started\n",
714 rx_queue_id, port_id);
718 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
723 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
725 struct rte_eth_dev *dev;
727 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
729 dev = &rte_eth_devices[port_id];
730 if (rx_queue_id >= dev->data->nb_rx_queues) {
731 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
735 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
737 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
738 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
739 " already stopped\n",
740 rx_queue_id, port_id);
744 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
749 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
751 struct rte_eth_dev *dev;
753 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
755 dev = &rte_eth_devices[port_id];
756 if (tx_queue_id >= dev->data->nb_tx_queues) {
757 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
761 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
763 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
764 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
765 " already started\n",
766 tx_queue_id, port_id);
770 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
775 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
777 struct rte_eth_dev *dev;
779 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
781 dev = &rte_eth_devices[port_id];
782 if (tx_queue_id >= dev->data->nb_tx_queues) {
783 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
787 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
789 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
790 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
791 " already stopped\n",
792 tx_queue_id, port_id);
796 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
801 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
803 uint16_t old_nb_queues = dev->data->nb_tx_queues;
807 if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */
808 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
809 sizeof(dev->data->tx_queues[0]) * nb_queues,
810 RTE_CACHE_LINE_SIZE);
811 if (dev->data->tx_queues == NULL) {
812 dev->data->nb_tx_queues = 0;
815 } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */
816 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
818 txq = dev->data->tx_queues;
820 for (i = nb_queues; i < old_nb_queues; i++)
821 (*dev->dev_ops->tx_queue_release)(txq[i]);
822 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
823 RTE_CACHE_LINE_SIZE);
826 if (nb_queues > old_nb_queues) {
827 uint16_t new_qs = nb_queues - old_nb_queues;
829 memset(txq + old_nb_queues, 0,
830 sizeof(txq[0]) * new_qs);
833 dev->data->tx_queues = txq;
835 } else if (dev->data->tx_queues != NULL && nb_queues == 0) {
836 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
838 txq = dev->data->tx_queues;
840 for (i = nb_queues; i < old_nb_queues; i++)
841 (*dev->dev_ops->tx_queue_release)(txq[i]);
843 dev->data->nb_tx_queues = nb_queues;
848 rte_eth_speed_bitflag(uint32_t speed, int duplex)
851 case ETH_SPEED_NUM_10M:
852 return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD;
853 case ETH_SPEED_NUM_100M:
854 return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD;
855 case ETH_SPEED_NUM_1G:
856 return ETH_LINK_SPEED_1G;
857 case ETH_SPEED_NUM_2_5G:
858 return ETH_LINK_SPEED_2_5G;
859 case ETH_SPEED_NUM_5G:
860 return ETH_LINK_SPEED_5G;
861 case ETH_SPEED_NUM_10G:
862 return ETH_LINK_SPEED_10G;
863 case ETH_SPEED_NUM_20G:
864 return ETH_LINK_SPEED_20G;
865 case ETH_SPEED_NUM_25G:
866 return ETH_LINK_SPEED_25G;
867 case ETH_SPEED_NUM_40G:
868 return ETH_LINK_SPEED_40G;
869 case ETH_SPEED_NUM_50G:
870 return ETH_LINK_SPEED_50G;
871 case ETH_SPEED_NUM_56G:
872 return ETH_LINK_SPEED_56G;
873 case ETH_SPEED_NUM_100G:
874 return ETH_LINK_SPEED_100G;
881 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
882 const struct rte_eth_conf *dev_conf)
884 struct rte_eth_dev *dev;
885 struct rte_eth_dev_info dev_info;
888 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
890 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
892 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
893 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
897 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
899 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
900 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
904 dev = &rte_eth_devices[port_id];
906 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
907 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
909 if (dev->data->dev_started) {
911 "port %d must be stopped to allow configuration\n", port_id);
915 /* Copy the dev_conf parameter into the dev structure */
916 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
919 * Check that the numbers of RX and TX queues are not greater
920 * than the maximum number of RX and TX queues supported by the
923 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
925 if (nb_rx_q == 0 && nb_tx_q == 0) {
926 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d both rx and tx queue cannot be 0\n", port_id);
930 if (nb_rx_q > dev_info.max_rx_queues) {
931 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
932 port_id, nb_rx_q, dev_info.max_rx_queues);
936 if (nb_tx_q > dev_info.max_tx_queues) {
937 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
938 port_id, nb_tx_q, dev_info.max_tx_queues);
943 * If link state interrupt is enabled, check that the
944 * device supports it.
946 if ((dev_conf->intr_conf.lsc == 1) &&
947 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
948 RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
949 dev->data->drv_name);
954 * If jumbo frames are enabled, check that the maximum RX packet
955 * length is supported by the configured device.
957 if (dev_conf->rxmode.jumbo_frame == 1) {
958 if (dev_conf->rxmode.max_rx_pkt_len >
959 dev_info.max_rx_pktlen) {
960 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
961 " > max valid value %u\n",
963 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
964 (unsigned)dev_info.max_rx_pktlen);
966 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
967 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
968 " < min valid value %u\n",
970 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
971 (unsigned)ETHER_MIN_LEN);
975 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
976 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
977 /* Use default value */
978 dev->data->dev_conf.rxmode.max_rx_pkt_len =
983 * Setup new number of RX/TX queues and reconfigure device.
985 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
987 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
992 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
994 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
996 rte_eth_dev_rx_queue_config(dev, 0);
1000 diag = (*dev->dev_ops->dev_configure)(dev);
1002 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
1004 rte_eth_dev_rx_queue_config(dev, 0);
1005 rte_eth_dev_tx_queue_config(dev, 0);
1013 rte_eth_dev_config_restore(uint8_t port_id)
1015 struct rte_eth_dev *dev;
1016 struct rte_eth_dev_info dev_info;
1017 struct ether_addr addr;
1021 dev = &rte_eth_devices[port_id];
1023 rte_eth_dev_info_get(port_id, &dev_info);
1025 if (RTE_ETH_DEV_SRIOV(dev).active)
1026 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
1028 /* replay MAC address configuration */
1029 for (i = 0; i < dev_info.max_mac_addrs; i++) {
1030 addr = dev->data->mac_addrs[i];
1032 /* skip zero address */
1033 if (is_zero_ether_addr(&addr))
1036 /* add address to the hardware */
1037 if (*dev->dev_ops->mac_addr_add &&
1038 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
1039 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
1041 RTE_PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
1043 /* exit the loop but not return an error */
1048 /* replay promiscuous configuration */
1049 if (rte_eth_promiscuous_get(port_id) == 1)
1050 rte_eth_promiscuous_enable(port_id);
1051 else if (rte_eth_promiscuous_get(port_id) == 0)
1052 rte_eth_promiscuous_disable(port_id);
1054 /* replay all multicast configuration */
1055 if (rte_eth_allmulticast_get(port_id) == 1)
1056 rte_eth_allmulticast_enable(port_id);
1057 else if (rte_eth_allmulticast_get(port_id) == 0)
1058 rte_eth_allmulticast_disable(port_id);
1062 rte_eth_dev_start(uint8_t port_id)
1064 struct rte_eth_dev *dev;
1067 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1069 dev = &rte_eth_devices[port_id];
1071 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1073 if (dev->data->dev_started != 0) {
1074 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1075 " already started\n",
1080 diag = (*dev->dev_ops->dev_start)(dev);
1082 dev->data->dev_started = 1;
1086 rte_eth_dev_config_restore(port_id);
1088 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1089 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1090 (*dev->dev_ops->link_update)(dev, 0);
1096 rte_eth_dev_stop(uint8_t port_id)
1098 struct rte_eth_dev *dev;
1100 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1101 dev = &rte_eth_devices[port_id];
1103 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1105 if (dev->data->dev_started == 0) {
1106 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1107 " already stopped\n",
1112 dev->data->dev_started = 0;
1113 (*dev->dev_ops->dev_stop)(dev);
1117 rte_eth_dev_set_link_up(uint8_t port_id)
1119 struct rte_eth_dev *dev;
1121 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1123 dev = &rte_eth_devices[port_id];
1125 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1126 return (*dev->dev_ops->dev_set_link_up)(dev);
1130 rte_eth_dev_set_link_down(uint8_t port_id)
1132 struct rte_eth_dev *dev;
1134 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1136 dev = &rte_eth_devices[port_id];
1138 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1139 return (*dev->dev_ops->dev_set_link_down)(dev);
1143 rte_eth_dev_close(uint8_t port_id)
1145 struct rte_eth_dev *dev;
1147 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1148 dev = &rte_eth_devices[port_id];
1150 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1151 dev->data->dev_started = 0;
1152 (*dev->dev_ops->dev_close)(dev);
1154 rte_free(dev->data->rx_queues);
1155 dev->data->rx_queues = NULL;
1156 rte_free(dev->data->tx_queues);
1157 dev->data->tx_queues = NULL;
1161 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1162 uint16_t nb_rx_desc, unsigned int socket_id,
1163 const struct rte_eth_rxconf *rx_conf,
1164 struct rte_mempool *mp)
1167 uint32_t mbp_buf_size;
1168 struct rte_eth_dev *dev;
1169 struct rte_eth_dev_info dev_info;
1171 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1173 dev = &rte_eth_devices[port_id];
1174 if (rx_queue_id >= dev->data->nb_rx_queues) {
1175 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1179 if (dev->data->dev_started) {
1180 RTE_PMD_DEBUG_TRACE(
1181 "port %d must be stopped to allow configuration\n", port_id);
1185 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1186 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1189 * Check the size of the mbuf data buffer.
1190 * This value must be provided in the private data of the memory pool.
1191 * First check that the memory pool has a valid private data.
1193 rte_eth_dev_info_get(port_id, &dev_info);
1194 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1195 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1196 mp->name, (int) mp->private_data_size,
1197 (int) sizeof(struct rte_pktmbuf_pool_private));
1200 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1202 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1203 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1204 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1208 (int)(RTE_PKTMBUF_HEADROOM +
1209 dev_info.min_rx_bufsize),
1210 (int)RTE_PKTMBUF_HEADROOM,
1211 (int)dev_info.min_rx_bufsize);
1215 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1216 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1217 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1219 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1220 "should be: <= %hu, = %hu, and a product of %hu\n",
1222 dev_info.rx_desc_lim.nb_max,
1223 dev_info.rx_desc_lim.nb_min,
1224 dev_info.rx_desc_lim.nb_align);
1228 if (rx_conf == NULL)
1229 rx_conf = &dev_info.default_rxconf;
1231 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1232 socket_id, rx_conf, mp);
1234 if (!dev->data->min_rx_buf_size ||
1235 dev->data->min_rx_buf_size > mbp_buf_size)
1236 dev->data->min_rx_buf_size = mbp_buf_size;
1243 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1244 uint16_t nb_tx_desc, unsigned int socket_id,
1245 const struct rte_eth_txconf *tx_conf)
1247 struct rte_eth_dev *dev;
1248 struct rte_eth_dev_info dev_info;
1250 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1252 dev = &rte_eth_devices[port_id];
1253 if (tx_queue_id >= dev->data->nb_tx_queues) {
1254 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1258 if (dev->data->dev_started) {
1259 RTE_PMD_DEBUG_TRACE(
1260 "port %d must be stopped to allow configuration\n", port_id);
1264 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1265 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1267 rte_eth_dev_info_get(port_id, &dev_info);
1269 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1270 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1271 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1272 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1273 "should be: <= %hu, = %hu, and a product of %hu\n",
1275 dev_info.tx_desc_lim.nb_max,
1276 dev_info.tx_desc_lim.nb_min,
1277 dev_info.tx_desc_lim.nb_align);
1281 if (tx_conf == NULL)
1282 tx_conf = &dev_info.default_txconf;
1284 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1285 socket_id, tx_conf);
1289 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
1290 void *userdata __rte_unused)
1294 for (i = 0; i < unsent; i++)
1295 rte_pktmbuf_free(pkts[i]);
1299 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
1302 uint64_t *count = userdata;
1305 for (i = 0; i < unsent; i++)
1306 rte_pktmbuf_free(pkts[i]);
1312 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
1313 buffer_tx_error_fn cbfn, void *userdata)
1315 buffer->error_callback = cbfn;
1316 buffer->error_userdata = userdata;
1321 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
1328 buffer->size = size;
1329 if (buffer->error_callback == NULL) {
1330 ret = rte_eth_tx_buffer_set_err_callback(
1331 buffer, rte_eth_tx_buffer_drop_callback, NULL);
1338 rte_eth_promiscuous_enable(uint8_t port_id)
1340 struct rte_eth_dev *dev;
1342 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1343 dev = &rte_eth_devices[port_id];
1345 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1346 (*dev->dev_ops->promiscuous_enable)(dev);
1347 dev->data->promiscuous = 1;
1351 rte_eth_promiscuous_disable(uint8_t port_id)
1353 struct rte_eth_dev *dev;
1355 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1356 dev = &rte_eth_devices[port_id];
1358 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1359 dev->data->promiscuous = 0;
1360 (*dev->dev_ops->promiscuous_disable)(dev);
1364 rte_eth_promiscuous_get(uint8_t port_id)
1366 struct rte_eth_dev *dev;
1368 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1370 dev = &rte_eth_devices[port_id];
1371 return dev->data->promiscuous;
1375 rte_eth_allmulticast_enable(uint8_t port_id)
1377 struct rte_eth_dev *dev;
1379 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1380 dev = &rte_eth_devices[port_id];
1382 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1383 (*dev->dev_ops->allmulticast_enable)(dev);
1384 dev->data->all_multicast = 1;
1388 rte_eth_allmulticast_disable(uint8_t port_id)
1390 struct rte_eth_dev *dev;
1392 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1393 dev = &rte_eth_devices[port_id];
1395 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1396 dev->data->all_multicast = 0;
1397 (*dev->dev_ops->allmulticast_disable)(dev);
1401 rte_eth_allmulticast_get(uint8_t port_id)
1403 struct rte_eth_dev *dev;
1405 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1407 dev = &rte_eth_devices[port_id];
1408 return dev->data->all_multicast;
1412 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1413 struct rte_eth_link *link)
1415 struct rte_eth_link *dst = link;
1416 struct rte_eth_link *src = &(dev->data->dev_link);
1418 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1419 *(uint64_t *)src) == 0)
1426 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1428 struct rte_eth_dev *dev;
1430 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1431 dev = &rte_eth_devices[port_id];
1433 if (dev->data->dev_conf.intr_conf.lsc != 0)
1434 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1436 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1437 (*dev->dev_ops->link_update)(dev, 1);
1438 *eth_link = dev->data->dev_link;
1443 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1445 struct rte_eth_dev *dev;
1447 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1448 dev = &rte_eth_devices[port_id];
1450 if (dev->data->dev_conf.intr_conf.lsc != 0)
1451 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1453 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1454 (*dev->dev_ops->link_update)(dev, 0);
1455 *eth_link = dev->data->dev_link;
1460 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1462 struct rte_eth_dev *dev;
1464 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1466 dev = &rte_eth_devices[port_id];
1467 memset(stats, 0, sizeof(*stats));
1469 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1470 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1471 (*dev->dev_ops->stats_get)(dev, stats);
1476 rte_eth_stats_reset(uint8_t port_id)
1478 struct rte_eth_dev *dev;
1480 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1481 dev = &rte_eth_devices[port_id];
1483 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1484 (*dev->dev_ops->stats_reset)(dev);
1485 dev->data->rx_mbuf_alloc_failed = 0;
1489 get_xstats_count(uint8_t port_id)
1491 struct rte_eth_dev *dev;
1494 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1495 dev = &rte_eth_devices[port_id];
1496 if (dev->dev_ops->xstats_get_names != NULL) {
1497 count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0);
1502 count += RTE_NB_STATS;
1503 count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
1504 count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
1509 rte_eth_xstats_get_names(uint8_t port_id,
1510 struct rte_eth_xstat_name *xstats_names,
1513 struct rte_eth_dev *dev;
1514 int cnt_used_entries;
1515 int cnt_expected_entries;
1516 int cnt_driver_entries;
1517 uint32_t idx, id_queue;
1519 cnt_expected_entries = get_xstats_count(port_id);
1520 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1521 (int)size < cnt_expected_entries)
1522 return cnt_expected_entries;
1524 /* port_id checked in get_xstats_count() */
1525 dev = &rte_eth_devices[port_id];
1526 cnt_used_entries = 0;
1528 for (idx = 0; idx < RTE_NB_STATS; idx++) {
1529 snprintf(xstats_names[cnt_used_entries].name,
1530 sizeof(xstats_names[0].name),
1531 "%s", rte_stats_strings[idx].name);
1534 for (id_queue = 0; id_queue < dev->data->nb_rx_queues; id_queue++) {
1535 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1536 snprintf(xstats_names[cnt_used_entries].name,
1537 sizeof(xstats_names[0].name),
1539 id_queue, rte_rxq_stats_strings[idx].name);
1544 for (id_queue = 0; id_queue < dev->data->nb_tx_queues; id_queue++) {
1545 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
1546 snprintf(xstats_names[cnt_used_entries].name,
1547 sizeof(xstats_names[0].name),
1549 id_queue, rte_txq_stats_strings[idx].name);
1554 if (dev->dev_ops->xstats_get_names != NULL) {
1555 /* If there are any driver-specific xstats, append them
1558 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
1560 xstats_names + cnt_used_entries,
1561 size - cnt_used_entries);
1562 if (cnt_driver_entries < 0)
1563 return cnt_driver_entries;
1564 cnt_used_entries += cnt_driver_entries;
1567 return cnt_used_entries;
1570 /* retrieve ethdev extended statistics */
1572 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstat *xstats,
1575 struct rte_eth_stats eth_stats;
1576 struct rte_eth_dev *dev;
1577 unsigned count = 0, i, q;
1579 uint64_t val, *stats_ptr;
1581 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1583 dev = &rte_eth_devices[port_id];
1585 /* Return generic statistics */
1586 count = RTE_NB_STATS + (dev->data->nb_rx_queues * RTE_NB_RXQ_STATS) +
1587 (dev->data->nb_tx_queues * RTE_NB_TXQ_STATS);
1589 /* implemented by the driver */
1590 if (dev->dev_ops->xstats_get != NULL) {
1591 /* Retrieve the xstats from the driver at the end of the
1594 xcount = (*dev->dev_ops->xstats_get)(dev,
1595 xstats ? xstats + count : NULL,
1596 (n > count) ? n - count : 0);
1602 if (n < count + xcount || xstats == NULL)
1603 return count + xcount;
1605 /* now fill the xstats structure */
1607 rte_eth_stats_get(port_id, ð_stats);
1610 for (i = 0; i < RTE_NB_STATS; i++) {
1611 stats_ptr = RTE_PTR_ADD(ð_stats,
1612 rte_stats_strings[i].offset);
1614 xstats[count++].value = val;
1618 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1619 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1620 stats_ptr = RTE_PTR_ADD(ð_stats,
1621 rte_rxq_stats_strings[i].offset +
1622 q * sizeof(uint64_t));
1624 xstats[count++].value = val;
1629 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1630 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1631 stats_ptr = RTE_PTR_ADD(ð_stats,
1632 rte_txq_stats_strings[i].offset +
1633 q * sizeof(uint64_t));
1635 xstats[count++].value = val;
1639 for (i = 0; i < count + xcount; i++)
1642 return count + xcount;
1645 /* reset ethdev extended statistics */
1647 rte_eth_xstats_reset(uint8_t port_id)
1649 struct rte_eth_dev *dev;
1651 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1652 dev = &rte_eth_devices[port_id];
1654 /* implemented by the driver */
1655 if (dev->dev_ops->xstats_reset != NULL) {
1656 (*dev->dev_ops->xstats_reset)(dev);
1660 /* fallback to default */
1661 rte_eth_stats_reset(port_id);
1665 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1668 struct rte_eth_dev *dev;
1670 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1672 dev = &rte_eth_devices[port_id];
1674 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1675 return (*dev->dev_ops->queue_stats_mapping_set)
1676 (dev, queue_id, stat_idx, is_rx);
1681 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1684 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1690 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1693 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1698 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1700 struct rte_eth_dev *dev;
1701 const struct rte_eth_desc_lim lim = {
1702 .nb_max = UINT16_MAX,
1707 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1708 dev = &rte_eth_devices[port_id];
1710 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1711 dev_info->rx_desc_lim = lim;
1712 dev_info->tx_desc_lim = lim;
1714 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1715 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1716 dev_info->pci_dev = dev->pci_dev;
1717 dev_info->driver_name = dev->data->drv_name;
1718 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
1719 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
1723 rte_eth_dev_get_supported_ptypes(uint8_t port_id, uint32_t ptype_mask,
1724 uint32_t *ptypes, int num)
1727 struct rte_eth_dev *dev;
1728 const uint32_t *all_ptypes;
1730 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1731 dev = &rte_eth_devices[port_id];
1732 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
1733 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
1738 for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
1739 if (all_ptypes[i] & ptype_mask) {
1741 ptypes[j] = all_ptypes[i];
1749 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1751 struct rte_eth_dev *dev;
1753 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1754 dev = &rte_eth_devices[port_id];
1755 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1760 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1762 struct rte_eth_dev *dev;
1764 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1766 dev = &rte_eth_devices[port_id];
1767 *mtu = dev->data->mtu;
1772 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
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 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1781 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1783 dev->data->mtu = mtu;
1789 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1791 struct rte_eth_dev *dev;
1793 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1794 dev = &rte_eth_devices[port_id];
1795 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1796 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1800 if (vlan_id > 4095) {
1801 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1802 port_id, (unsigned) vlan_id);
1805 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1807 return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1811 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1813 struct rte_eth_dev *dev;
1815 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1816 dev = &rte_eth_devices[port_id];
1817 if (rx_queue_id >= dev->data->nb_rx_queues) {
1818 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1822 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1823 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1829 rte_eth_dev_set_vlan_ether_type(uint8_t port_id,
1830 enum rte_vlan_type vlan_type,
1833 struct rte_eth_dev *dev;
1835 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1836 dev = &rte_eth_devices[port_id];
1837 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1839 return (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type, tpid);
1843 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1845 struct rte_eth_dev *dev;
1850 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1851 dev = &rte_eth_devices[port_id];
1853 /*check which option changed by application*/
1854 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1855 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1857 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1858 mask |= ETH_VLAN_STRIP_MASK;
1861 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1862 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1864 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1865 mask |= ETH_VLAN_FILTER_MASK;
1868 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1869 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1871 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1872 mask |= ETH_VLAN_EXTEND_MASK;
1879 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1880 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1886 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1888 struct rte_eth_dev *dev;
1891 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1892 dev = &rte_eth_devices[port_id];
1894 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1895 ret |= ETH_VLAN_STRIP_OFFLOAD;
1897 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1898 ret |= ETH_VLAN_FILTER_OFFLOAD;
1900 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1901 ret |= ETH_VLAN_EXTEND_OFFLOAD;
1907 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1909 struct rte_eth_dev *dev;
1911 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1912 dev = &rte_eth_devices[port_id];
1913 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1914 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1920 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1922 struct rte_eth_dev *dev;
1924 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1925 dev = &rte_eth_devices[port_id];
1926 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1927 memset(fc_conf, 0, sizeof(*fc_conf));
1928 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1932 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1934 struct rte_eth_dev *dev;
1936 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1937 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1938 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1942 dev = &rte_eth_devices[port_id];
1943 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1944 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1948 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1950 struct rte_eth_dev *dev;
1952 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1953 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1954 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1958 dev = &rte_eth_devices[port_id];
1959 /* High water, low water validation are device specific */
1960 if (*dev->dev_ops->priority_flow_ctrl_set)
1961 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1966 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
1974 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
1975 RTE_PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
1976 RTE_RETA_GROUP_SIZE);
1980 num = reta_size / RTE_RETA_GROUP_SIZE;
1981 for (i = 0; i < num; i++) {
1982 if (reta_conf[i].mask)
1990 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
1994 uint16_t i, idx, shift;
2000 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
2004 for (i = 0; i < reta_size; i++) {
2005 idx = i / RTE_RETA_GROUP_SIZE;
2006 shift = i % RTE_RETA_GROUP_SIZE;
2007 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2008 (reta_conf[idx].reta[shift] >= max_rxq)) {
2009 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2010 "the maximum rxq index: %u\n", idx, shift,
2011 reta_conf[idx].reta[shift], max_rxq);
2020 rte_eth_dev_rss_reta_update(uint8_t port_id,
2021 struct rte_eth_rss_reta_entry64 *reta_conf,
2024 struct rte_eth_dev *dev;
2027 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2028 /* Check mask bits */
2029 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2033 dev = &rte_eth_devices[port_id];
2035 /* Check entry value */
2036 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2037 dev->data->nb_rx_queues);
2041 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2042 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2046 rte_eth_dev_rss_reta_query(uint8_t port_id,
2047 struct rte_eth_rss_reta_entry64 *reta_conf,
2050 struct rte_eth_dev *dev;
2053 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2055 /* Check mask bits */
2056 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2060 dev = &rte_eth_devices[port_id];
2061 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2062 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2066 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2068 struct rte_eth_dev *dev;
2069 uint16_t rss_hash_protos;
2071 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2072 rss_hash_protos = rss_conf->rss_hf;
2073 if ((rss_hash_protos != 0) &&
2074 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2075 RTE_PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2079 dev = &rte_eth_devices[port_id];
2080 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2081 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2085 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2086 struct rte_eth_rss_conf *rss_conf)
2088 struct rte_eth_dev *dev;
2090 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2091 dev = &rte_eth_devices[port_id];
2092 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2093 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2097 rte_eth_dev_udp_tunnel_port_add(uint8_t port_id,
2098 struct rte_eth_udp_tunnel *udp_tunnel)
2100 struct rte_eth_dev *dev;
2102 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2103 if (udp_tunnel == NULL) {
2104 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2108 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2109 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2113 dev = &rte_eth_devices[port_id];
2114 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
2115 return (*dev->dev_ops->udp_tunnel_port_add)(dev, udp_tunnel);
2119 rte_eth_dev_udp_tunnel_port_delete(uint8_t port_id,
2120 struct rte_eth_udp_tunnel *udp_tunnel)
2122 struct rte_eth_dev *dev;
2124 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2125 dev = &rte_eth_devices[port_id];
2127 if (udp_tunnel == NULL) {
2128 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2132 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2133 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2137 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
2138 return (*dev->dev_ops->udp_tunnel_port_del)(dev, udp_tunnel);
2142 rte_eth_led_on(uint8_t port_id)
2144 struct rte_eth_dev *dev;
2146 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2147 dev = &rte_eth_devices[port_id];
2148 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2149 return (*dev->dev_ops->dev_led_on)(dev);
2153 rte_eth_led_off(uint8_t port_id)
2155 struct rte_eth_dev *dev;
2157 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2158 dev = &rte_eth_devices[port_id];
2159 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2160 return (*dev->dev_ops->dev_led_off)(dev);
2164 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2168 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2170 struct rte_eth_dev_info dev_info;
2171 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2174 rte_eth_dev_info_get(port_id, &dev_info);
2176 for (i = 0; i < dev_info.max_mac_addrs; i++)
2177 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2183 static const struct ether_addr null_mac_addr;
2186 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2189 struct rte_eth_dev *dev;
2193 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2194 dev = &rte_eth_devices[port_id];
2195 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2197 if (is_zero_ether_addr(addr)) {
2198 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2202 if (pool >= ETH_64_POOLS) {
2203 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2207 index = get_mac_addr_index(port_id, addr);
2209 index = get_mac_addr_index(port_id, &null_mac_addr);
2211 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2216 pool_mask = dev->data->mac_pool_sel[index];
2218 /* Check if both MAC address and pool is already there, and do nothing */
2219 if (pool_mask & (1ULL << pool))
2224 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2226 /* Update address in NIC data structure */
2227 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2229 /* Update pool bitmap in NIC data structure */
2230 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2236 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2238 struct rte_eth_dev *dev;
2241 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2242 dev = &rte_eth_devices[port_id];
2243 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2245 index = get_mac_addr_index(port_id, addr);
2247 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2249 } else if (index < 0)
2250 return 0; /* Do nothing if address wasn't found */
2253 (*dev->dev_ops->mac_addr_remove)(dev, index);
2255 /* Update address in NIC data structure */
2256 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2258 /* reset pool bitmap */
2259 dev->data->mac_pool_sel[index] = 0;
2265 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2267 struct rte_eth_dev *dev;
2269 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2271 if (!is_valid_assigned_ether_addr(addr))
2274 dev = &rte_eth_devices[port_id];
2275 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2277 /* Update default address in NIC data structure */
2278 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2280 (*dev->dev_ops->mac_addr_set)(dev, addr);
2286 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2287 uint16_t rx_mode, uint8_t on)
2290 struct rte_eth_dev *dev;
2291 struct rte_eth_dev_info dev_info;
2293 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2295 dev = &rte_eth_devices[port_id];
2296 rte_eth_dev_info_get(port_id, &dev_info);
2298 num_vfs = dev_info.max_vfs;
2300 RTE_PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2305 RTE_PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2308 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2309 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2313 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2317 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2319 struct rte_eth_dev_info dev_info;
2320 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2323 rte_eth_dev_info_get(port_id, &dev_info);
2324 if (!dev->data->hash_mac_addrs)
2327 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2328 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2329 ETHER_ADDR_LEN) == 0)
2336 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2341 struct rte_eth_dev *dev;
2343 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2345 dev = &rte_eth_devices[port_id];
2346 if (is_zero_ether_addr(addr)) {
2347 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2352 index = get_hash_mac_addr_index(port_id, addr);
2353 /* Check if it's already there, and do nothing */
2354 if ((index >= 0) && (on))
2359 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2360 "set in UTA\n", port_id);
2364 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2366 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2372 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2373 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2375 /* Update address in NIC data structure */
2377 ether_addr_copy(addr,
2378 &dev->data->hash_mac_addrs[index]);
2380 ether_addr_copy(&null_mac_addr,
2381 &dev->data->hash_mac_addrs[index]);
2388 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2390 struct rte_eth_dev *dev;
2392 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2394 dev = &rte_eth_devices[port_id];
2396 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2397 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2401 rte_eth_dev_set_vf_rx(uint8_t port_id, uint16_t vf, uint8_t on)
2404 struct rte_eth_dev *dev;
2405 struct rte_eth_dev_info dev_info;
2407 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2409 dev = &rte_eth_devices[port_id];
2410 rte_eth_dev_info_get(port_id, &dev_info);
2412 num_vfs = dev_info.max_vfs;
2414 RTE_PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2418 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2419 return (*dev->dev_ops->set_vf_rx)(dev, vf, on);
2423 rte_eth_dev_set_vf_tx(uint8_t port_id, uint16_t vf, uint8_t on)
2426 struct rte_eth_dev *dev;
2427 struct rte_eth_dev_info dev_info;
2429 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2431 dev = &rte_eth_devices[port_id];
2432 rte_eth_dev_info_get(port_id, &dev_info);
2434 num_vfs = dev_info.max_vfs;
2436 RTE_PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2440 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2441 return (*dev->dev_ops->set_vf_tx)(dev, vf, on);
2445 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2446 uint64_t vf_mask, uint8_t vlan_on)
2448 struct rte_eth_dev *dev;
2450 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2452 dev = &rte_eth_devices[port_id];
2454 if (vlan_id > ETHER_MAX_VLAN_ID) {
2455 RTE_PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2461 RTE_PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2465 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2466 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2470 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2473 struct rte_eth_dev *dev;
2474 struct rte_eth_dev_info dev_info;
2475 struct rte_eth_link link;
2477 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2479 dev = &rte_eth_devices[port_id];
2480 rte_eth_dev_info_get(port_id, &dev_info);
2481 link = dev->data->dev_link;
2483 if (queue_idx > dev_info.max_tx_queues) {
2484 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2485 "invalid queue id=%d\n", port_id, queue_idx);
2489 if (tx_rate > link.link_speed) {
2490 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2491 "bigger than link speed= %d\n",
2492 tx_rate, link.link_speed);
2496 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2497 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2500 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2503 struct rte_eth_dev *dev;
2504 struct rte_eth_dev_info dev_info;
2505 struct rte_eth_link link;
2510 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2512 dev = &rte_eth_devices[port_id];
2513 rte_eth_dev_info_get(port_id, &dev_info);
2514 link = dev->data->dev_link;
2516 if (vf > dev_info.max_vfs) {
2517 RTE_PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2518 "invalid vf id=%d\n", port_id, vf);
2522 if (tx_rate > link.link_speed) {
2523 RTE_PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2524 "bigger than link speed= %d\n",
2525 tx_rate, link.link_speed);
2529 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2530 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2534 rte_eth_mirror_rule_set(uint8_t port_id,
2535 struct rte_eth_mirror_conf *mirror_conf,
2536 uint8_t rule_id, uint8_t on)
2538 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2540 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2541 if (mirror_conf->rule_type == 0) {
2542 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2546 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2547 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2552 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2553 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2554 (mirror_conf->pool_mask == 0)) {
2555 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2559 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2560 mirror_conf->vlan.vlan_mask == 0) {
2561 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2565 dev = &rte_eth_devices[port_id];
2566 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2568 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2572 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2574 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2576 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2578 dev = &rte_eth_devices[port_id];
2579 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2581 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2585 rte_eth_dev_callback_register(uint8_t port_id,
2586 enum rte_eth_event_type event,
2587 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2589 struct rte_eth_dev *dev;
2590 struct rte_eth_dev_callback *user_cb;
2595 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2597 dev = &rte_eth_devices[port_id];
2598 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2600 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2601 if (user_cb->cb_fn == cb_fn &&
2602 user_cb->cb_arg == cb_arg &&
2603 user_cb->event == event) {
2608 /* create a new callback. */
2609 if (user_cb == NULL)
2610 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2611 sizeof(struct rte_eth_dev_callback), 0);
2612 if (user_cb != NULL) {
2613 user_cb->cb_fn = cb_fn;
2614 user_cb->cb_arg = cb_arg;
2615 user_cb->event = event;
2616 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2619 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2620 return (user_cb == NULL) ? -ENOMEM : 0;
2624 rte_eth_dev_callback_unregister(uint8_t port_id,
2625 enum rte_eth_event_type event,
2626 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2629 struct rte_eth_dev *dev;
2630 struct rte_eth_dev_callback *cb, *next;
2635 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2637 dev = &rte_eth_devices[port_id];
2638 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2641 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2643 next = TAILQ_NEXT(cb, next);
2645 if (cb->cb_fn != cb_fn || cb->event != event ||
2646 (cb->cb_arg != (void *)-1 &&
2647 cb->cb_arg != cb_arg))
2651 * if this callback is not executing right now,
2654 if (cb->active == 0) {
2655 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2662 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2667 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2668 enum rte_eth_event_type event)
2670 struct rte_eth_dev_callback *cb_lst;
2671 struct rte_eth_dev_callback dev_cb;
2673 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2674 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2675 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2679 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2680 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2682 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2685 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2689 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
2692 struct rte_eth_dev *dev;
2693 struct rte_intr_handle *intr_handle;
2697 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2699 dev = &rte_eth_devices[port_id];
2700 intr_handle = &dev->pci_dev->intr_handle;
2701 if (!intr_handle->intr_vec) {
2702 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2706 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2707 vec = intr_handle->intr_vec[qid];
2708 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2709 if (rc && rc != -EEXIST) {
2710 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2711 " op %d epfd %d vec %u\n",
2712 port_id, qid, op, epfd, vec);
2719 const struct rte_memzone *
2720 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2721 uint16_t queue_id, size_t size, unsigned align,
2724 char z_name[RTE_MEMZONE_NAMESIZE];
2725 const struct rte_memzone *mz;
2727 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2728 dev->driver->pci_drv.name, ring_name,
2729 dev->data->port_id, queue_id);
2731 mz = rte_memzone_lookup(z_name);
2735 if (rte_xen_dom0_supported())
2736 return rte_memzone_reserve_bounded(z_name, size, socket_id,
2737 0, align, RTE_PGSIZE_2M);
2739 return rte_memzone_reserve_aligned(z_name, size, socket_id,
2744 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
2745 int epfd, int op, void *data)
2748 struct rte_eth_dev *dev;
2749 struct rte_intr_handle *intr_handle;
2752 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2754 dev = &rte_eth_devices[port_id];
2755 if (queue_id >= dev->data->nb_rx_queues) {
2756 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
2760 intr_handle = &dev->pci_dev->intr_handle;
2761 if (!intr_handle->intr_vec) {
2762 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2766 vec = intr_handle->intr_vec[queue_id];
2767 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2768 if (rc && rc != -EEXIST) {
2769 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2770 " op %d epfd %d vec %u\n",
2771 port_id, queue_id, op, epfd, vec);
2779 rte_eth_dev_rx_intr_enable(uint8_t port_id,
2782 struct rte_eth_dev *dev;
2784 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2786 dev = &rte_eth_devices[port_id];
2788 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
2789 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
2793 rte_eth_dev_rx_intr_disable(uint8_t port_id,
2796 struct rte_eth_dev *dev;
2798 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2800 dev = &rte_eth_devices[port_id];
2802 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
2803 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
2806 #ifdef RTE_NIC_BYPASS
2807 int rte_eth_dev_bypass_init(uint8_t port_id)
2809 struct rte_eth_dev *dev;
2811 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2813 dev = &rte_eth_devices[port_id];
2814 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2815 (*dev->dev_ops->bypass_init)(dev);
2820 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2822 struct rte_eth_dev *dev;
2824 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2826 dev = &rte_eth_devices[port_id];
2827 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2828 (*dev->dev_ops->bypass_state_show)(dev, state);
2833 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2835 struct rte_eth_dev *dev;
2837 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2839 dev = &rte_eth_devices[port_id];
2840 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2841 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2846 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2848 struct rte_eth_dev *dev;
2850 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2852 dev = &rte_eth_devices[port_id];
2853 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2854 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2859 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2861 struct rte_eth_dev *dev;
2863 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2865 dev = &rte_eth_devices[port_id];
2867 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2868 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2873 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2875 struct rte_eth_dev *dev;
2877 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2879 dev = &rte_eth_devices[port_id];
2881 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2882 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2887 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2889 struct rte_eth_dev *dev;
2891 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2893 dev = &rte_eth_devices[port_id];
2895 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2896 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2901 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2903 struct rte_eth_dev *dev;
2905 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2907 dev = &rte_eth_devices[port_id];
2909 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2910 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2915 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2917 struct rte_eth_dev *dev;
2919 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2921 dev = &rte_eth_devices[port_id];
2923 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2924 (*dev->dev_ops->bypass_wd_reset)(dev);
2930 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
2932 struct rte_eth_dev *dev;
2934 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2936 dev = &rte_eth_devices[port_id];
2937 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2938 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
2939 RTE_ETH_FILTER_NOP, NULL);
2943 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
2944 enum rte_filter_op filter_op, void *arg)
2946 struct rte_eth_dev *dev;
2948 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2950 dev = &rte_eth_devices[port_id];
2951 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2952 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
2956 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
2957 rte_rx_callback_fn fn, void *user_param)
2959 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2960 rte_errno = ENOTSUP;
2963 /* check input parameters */
2964 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2965 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2969 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2977 cb->param = user_param;
2979 rte_spinlock_lock(&rte_eth_rx_cb_lock);
2980 /* Add the callbacks in fifo order. */
2981 struct rte_eth_rxtx_callback *tail =
2982 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2985 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2992 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
2998 rte_eth_add_first_rx_callback(uint8_t port_id, uint16_t queue_id,
2999 rte_rx_callback_fn fn, void *user_param)
3001 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3002 rte_errno = ENOTSUP;
3005 /* check input parameters */
3006 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3007 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3012 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3020 cb->param = user_param;
3022 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3023 /* Add the callbacks at fisrt position*/
3024 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3026 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3027 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3033 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
3034 rte_tx_callback_fn fn, void *user_param)
3036 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3037 rte_errno = ENOTSUP;
3040 /* check input parameters */
3041 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3042 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3047 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3055 cb->param = user_param;
3057 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3058 /* Add the callbacks in fifo order. */
3059 struct rte_eth_rxtx_callback *tail =
3060 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3063 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3070 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3076 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3077 struct rte_eth_rxtx_callback *user_cb)
3079 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3082 /* Check input parameters. */
3083 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3084 if (user_cb == NULL ||
3085 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
3088 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3089 struct rte_eth_rxtx_callback *cb;
3090 struct rte_eth_rxtx_callback **prev_cb;
3093 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3094 prev_cb = &dev->post_rx_burst_cbs[queue_id];
3095 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3097 if (cb == user_cb) {
3098 /* Remove the user cb from the callback list. */
3099 *prev_cb = cb->next;
3104 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3110 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3111 struct rte_eth_rxtx_callback *user_cb)
3113 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3116 /* Check input parameters. */
3117 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3118 if (user_cb == NULL ||
3119 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
3122 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3124 struct rte_eth_rxtx_callback *cb;
3125 struct rte_eth_rxtx_callback **prev_cb;
3127 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3128 prev_cb = &dev->pre_tx_burst_cbs[queue_id];
3129 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3131 if (cb == user_cb) {
3132 /* Remove the user cb from the callback list. */
3133 *prev_cb = cb->next;
3138 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3144 rte_eth_rx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3145 struct rte_eth_rxq_info *qinfo)
3147 struct rte_eth_dev *dev;
3149 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3154 dev = &rte_eth_devices[port_id];
3155 if (queue_id >= dev->data->nb_rx_queues) {
3156 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3160 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3162 memset(qinfo, 0, sizeof(*qinfo));
3163 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3168 rte_eth_tx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3169 struct rte_eth_txq_info *qinfo)
3171 struct rte_eth_dev *dev;
3173 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3178 dev = &rte_eth_devices[port_id];
3179 if (queue_id >= dev->data->nb_tx_queues) {
3180 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3184 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3186 memset(qinfo, 0, sizeof(*qinfo));
3187 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3192 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3193 struct ether_addr *mc_addr_set,
3194 uint32_t nb_mc_addr)
3196 struct rte_eth_dev *dev;
3198 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3200 dev = &rte_eth_devices[port_id];
3201 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3202 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3206 rte_eth_timesync_enable(uint8_t port_id)
3208 struct rte_eth_dev *dev;
3210 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3211 dev = &rte_eth_devices[port_id];
3213 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3214 return (*dev->dev_ops->timesync_enable)(dev);
3218 rte_eth_timesync_disable(uint8_t port_id)
3220 struct rte_eth_dev *dev;
3222 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3223 dev = &rte_eth_devices[port_id];
3225 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3226 return (*dev->dev_ops->timesync_disable)(dev);
3230 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3233 struct rte_eth_dev *dev;
3235 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3236 dev = &rte_eth_devices[port_id];
3238 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3239 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3243 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3245 struct rte_eth_dev *dev;
3247 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3248 dev = &rte_eth_devices[port_id];
3250 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3251 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3255 rte_eth_timesync_adjust_time(uint8_t port_id, int64_t delta)
3257 struct rte_eth_dev *dev;
3259 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3260 dev = &rte_eth_devices[port_id];
3262 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3263 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3267 rte_eth_timesync_read_time(uint8_t port_id, struct timespec *timestamp)
3269 struct rte_eth_dev *dev;
3271 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3272 dev = &rte_eth_devices[port_id];
3274 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3275 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3279 rte_eth_timesync_write_time(uint8_t port_id, const struct timespec *timestamp)
3281 struct rte_eth_dev *dev;
3283 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3284 dev = &rte_eth_devices[port_id];
3286 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3287 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3291 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3293 struct rte_eth_dev *dev;
3295 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3297 dev = &rte_eth_devices[port_id];
3298 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3299 return (*dev->dev_ops->get_reg)(dev, info);
3303 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3305 struct rte_eth_dev *dev;
3307 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3309 dev = &rte_eth_devices[port_id];
3310 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3311 return (*dev->dev_ops->get_eeprom_length)(dev);
3315 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3317 struct rte_eth_dev *dev;
3319 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3321 dev = &rte_eth_devices[port_id];
3322 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3323 return (*dev->dev_ops->get_eeprom)(dev, info);
3327 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3329 struct rte_eth_dev *dev;
3331 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3333 dev = &rte_eth_devices[port_id];
3334 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3335 return (*dev->dev_ops->set_eeprom)(dev, info);
3339 rte_eth_dev_get_dcb_info(uint8_t port_id,
3340 struct rte_eth_dcb_info *dcb_info)
3342 struct rte_eth_dev *dev;
3344 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3346 dev = &rte_eth_devices[port_id];
3347 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3349 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3350 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3354 rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_dev)
3356 if ((eth_dev == NULL) || (pci_dev == NULL)) {
3357 RTE_PMD_DEBUG_TRACE("NULL pointer eth_dev=%p pci_dev=%p\n",
3362 eth_dev->data->dev_flags = 0;
3363 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
3364 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
3365 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_DETACHABLE)
3366 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
3368 eth_dev->data->kdrv = pci_dev->kdrv;
3369 eth_dev->data->numa_node = pci_dev->numa_node;
3370 eth_dev->data->drv_name = pci_dev->driver->name;
3374 rte_eth_dev_l2_tunnel_eth_type_conf(uint8_t port_id,
3375 struct rte_eth_l2_tunnel_conf *l2_tunnel)
3377 struct rte_eth_dev *dev;
3379 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3380 if (l2_tunnel == NULL) {
3381 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3385 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3386 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
3390 dev = &rte_eth_devices[port_id];
3391 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
3393 return (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev, l2_tunnel);
3397 rte_eth_dev_l2_tunnel_offload_set(uint8_t port_id,
3398 struct rte_eth_l2_tunnel_conf *l2_tunnel,
3402 struct rte_eth_dev *dev;
3404 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3406 if (l2_tunnel == NULL) {
3407 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3411 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3412 RTE_PMD_DEBUG_TRACE("Invalid tunnel type.\n");
3417 RTE_PMD_DEBUG_TRACE("Mask should have a value.\n");
3421 dev = &rte_eth_devices[port_id];
3422 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
3424 return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);