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 eth_dev_last_created_port;
75 static uint8_t nb_ports;
77 /* spinlock for eth device callbacks */
78 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
80 /* spinlock for add/remove rx callbacks */
81 static rte_spinlock_t rte_eth_rx_cb_lock = RTE_SPINLOCK_INITIALIZER;
83 /* spinlock for add/remove tx callbacks */
84 static rte_spinlock_t rte_eth_tx_cb_lock = RTE_SPINLOCK_INITIALIZER;
86 /* store statistics names and its offset in stats structure */
87 struct rte_eth_xstats_name_off {
88 char name[RTE_ETH_XSTATS_NAME_SIZE];
92 static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
93 {"rx_good_packets", offsetof(struct rte_eth_stats, ipackets)},
94 {"tx_good_packets", offsetof(struct rte_eth_stats, opackets)},
95 {"rx_good_bytes", offsetof(struct rte_eth_stats, ibytes)},
96 {"tx_good_bytes", offsetof(struct rte_eth_stats, obytes)},
97 {"rx_missed_errors", offsetof(struct rte_eth_stats, imissed)},
98 {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
99 {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
100 {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats,
104 #define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
106 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
107 {"packets", offsetof(struct rte_eth_stats, q_ipackets)},
108 {"bytes", offsetof(struct rte_eth_stats, q_ibytes)},
109 {"errors", offsetof(struct rte_eth_stats, q_errors)},
112 #define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) / \
113 sizeof(rte_rxq_stats_strings[0]))
115 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
116 {"packets", offsetof(struct rte_eth_stats, q_opackets)},
117 {"bytes", offsetof(struct rte_eth_stats, q_obytes)},
119 #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) / \
120 sizeof(rte_txq_stats_strings[0]))
124 * The user application callback description.
126 * It contains callback address to be registered by user application,
127 * the pointer to the parameters for callback, and the event type.
129 struct rte_eth_dev_callback {
130 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
131 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
132 void *cb_arg; /**< Parameter for callback */
133 enum rte_eth_event_type event; /**< Interrupt event type */
134 uint32_t active; /**< Callback is executing */
148 rte_eth_dev_data_alloc(void)
150 const unsigned flags = 0;
151 const struct rte_memzone *mz;
153 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
154 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
155 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
156 rte_socket_id(), flags);
158 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
160 rte_panic("Cannot allocate memzone for ethernet port data\n");
162 rte_eth_dev_data = mz->addr;
163 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
164 memset(rte_eth_dev_data, 0,
165 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
169 rte_eth_dev_allocated(const char *name)
173 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
174 if ((rte_eth_devices[i].attached == DEV_ATTACHED) &&
175 strcmp(rte_eth_devices[i].data->name, name) == 0)
176 return &rte_eth_devices[i];
182 rte_eth_dev_find_free_port(void)
186 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
187 if (rte_eth_devices[i].attached == DEV_DETACHED)
190 return RTE_MAX_ETHPORTS;
193 static struct rte_eth_dev *
194 eth_dev_get(uint8_t port_id)
196 struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
198 eth_dev->data = &rte_eth_dev_data[port_id];
199 eth_dev->attached = DEV_ATTACHED;
201 eth_dev_last_created_port = port_id;
208 rte_eth_dev_allocate(const char *name)
211 struct rte_eth_dev *eth_dev;
213 port_id = rte_eth_dev_find_free_port();
214 if (port_id == RTE_MAX_ETHPORTS) {
215 RTE_PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
219 if (rte_eth_dev_data == NULL)
220 rte_eth_dev_data_alloc();
222 if (rte_eth_dev_allocated(name) != NULL) {
223 RTE_PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n",
228 eth_dev = eth_dev_get(port_id);
229 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
230 eth_dev->data->port_id = port_id;
236 * Attach to a port already registered by the primary process, which
237 * makes sure that the same device would have the same port id both
238 * in the primary and secondary process.
240 static struct rte_eth_dev *
241 eth_dev_attach_secondary(const char *name)
244 struct rte_eth_dev *eth_dev;
246 if (rte_eth_dev_data == NULL)
247 rte_eth_dev_data_alloc();
249 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
250 if (strcmp(rte_eth_dev_data[i].name, name) == 0)
253 if (i == RTE_MAX_ETHPORTS) {
255 "device %s is not driven by the primary process\n",
260 eth_dev = eth_dev_get(i);
261 RTE_ASSERT(eth_dev->data->port_id == i);
267 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
272 eth_dev->attached = DEV_DETACHED;
278 rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
279 struct rte_pci_device *pci_dev)
281 struct eth_driver *eth_drv;
282 struct rte_eth_dev *eth_dev;
283 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
287 eth_drv = (struct eth_driver *)pci_drv;
289 rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
290 sizeof(ethdev_name));
292 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
293 eth_dev = rte_eth_dev_allocate(ethdev_name);
297 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
298 eth_drv->dev_private_size,
299 RTE_CACHE_LINE_SIZE);
300 if (eth_dev->data->dev_private == NULL)
301 rte_panic("Cannot allocate memzone for private port data\n");
303 eth_dev = eth_dev_attach_secondary(ethdev_name);
304 if (eth_dev == NULL) {
306 * if we failed to attach a device, it means the
307 * device is skipped in primary process, due to
308 * some errors. If so, we return a positive value,
309 * to let EAL skip it for the secondary process
315 eth_dev->pci_dev = pci_dev;
316 eth_dev->driver = eth_drv;
317 eth_dev->data->rx_mbuf_alloc_failed = 0;
319 /* init user callbacks */
320 TAILQ_INIT(&(eth_dev->link_intr_cbs));
323 * Set the default MTU.
325 eth_dev->data->mtu = ETHER_MTU;
327 /* Invoke PMD device initialization function */
328 diag = (*eth_drv->eth_dev_init)(eth_dev);
332 RTE_PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%x device_id=0x%x) failed\n",
333 pci_drv->driver.name,
334 (unsigned) pci_dev->id.vendor_id,
335 (unsigned) pci_dev->id.device_id);
336 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
337 rte_free(eth_dev->data->dev_private);
338 rte_eth_dev_release_port(eth_dev);
343 rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
345 const struct eth_driver *eth_drv;
346 struct rte_eth_dev *eth_dev;
347 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
353 rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
354 sizeof(ethdev_name));
356 eth_dev = rte_eth_dev_allocated(ethdev_name);
360 eth_drv = (const struct eth_driver *)pci_dev->driver;
362 /* Invoke PMD device uninit function */
363 if (*eth_drv->eth_dev_uninit) {
364 ret = (*eth_drv->eth_dev_uninit)(eth_dev);
369 /* free ether device */
370 rte_eth_dev_release_port(eth_dev);
372 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
373 rte_free(eth_dev->data->dev_private);
375 eth_dev->pci_dev = NULL;
376 eth_dev->driver = NULL;
377 eth_dev->data = NULL;
383 rte_eth_dev_is_valid_port(uint8_t port_id)
385 if (port_id >= RTE_MAX_ETHPORTS ||
386 rte_eth_devices[port_id].attached != DEV_ATTACHED)
393 rte_eth_dev_socket_id(uint8_t port_id)
395 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
396 return rte_eth_devices[port_id].data->numa_node;
400 rte_eth_dev_count(void)
406 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
410 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
413 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
417 /* shouldn't check 'rte_eth_devices[i].data',
418 * because it might be overwritten by VDEV PMD */
419 tmp = rte_eth_dev_data[port_id].name;
425 rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
430 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
437 *port_id = RTE_MAX_ETHPORTS;
439 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
441 if (!strcmp(name, rte_eth_dev_data[i].name)) {
452 rte_eth_dev_is_detachable(uint8_t port_id)
456 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
458 switch (rte_eth_devices[port_id].data->kdrv) {
459 case RTE_KDRV_IGB_UIO:
460 case RTE_KDRV_UIO_GENERIC:
461 case RTE_KDRV_NIC_UIO:
468 dev_flags = rte_eth_devices[port_id].data->dev_flags;
469 if ((dev_flags & RTE_ETH_DEV_DETACHABLE) &&
470 (!(dev_flags & RTE_ETH_DEV_BONDED_SLAVE)))
476 /* attach the new device, then store port_id of the device */
478 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
481 int current = rte_eth_dev_count();
485 if ((devargs == NULL) || (port_id == NULL)) {
490 /* parse devargs, then retrieve device name and args */
491 if (rte_eal_parse_devargs_str(devargs, &name, &args))
494 ret = rte_eal_dev_attach(name, args);
498 /* no point looking at the port count if no port exists */
499 if (!rte_eth_dev_count()) {
500 RTE_LOG(ERR, EAL, "No port found for device (%s)\n", name);
505 /* if nothing happened, there is a bug here, since some driver told us
506 * it did attach a device, but did not create a port.
508 if (current == rte_eth_dev_count()) {
513 *port_id = eth_dev_last_created_port;
522 /* detach the device, then store the name of the device */
524 rte_eth_dev_detach(uint8_t port_id, char *name)
533 /* FIXME: move this to eal, once device flags are relocated there */
534 if (rte_eth_dev_is_detachable(port_id))
537 snprintf(name, sizeof(rte_eth_devices[port_id].data->name),
538 "%s", rte_eth_devices[port_id].data->name);
539 ret = rte_eal_dev_detach(name);
550 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
552 uint16_t old_nb_queues = dev->data->nb_rx_queues;
556 if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */
557 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
558 sizeof(dev->data->rx_queues[0]) * nb_queues,
559 RTE_CACHE_LINE_SIZE);
560 if (dev->data->rx_queues == NULL) {
561 dev->data->nb_rx_queues = 0;
564 } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */
565 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
567 rxq = dev->data->rx_queues;
569 for (i = nb_queues; i < old_nb_queues; i++)
570 (*dev->dev_ops->rx_queue_release)(rxq[i]);
571 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
572 RTE_CACHE_LINE_SIZE);
575 if (nb_queues > old_nb_queues) {
576 uint16_t new_qs = nb_queues - old_nb_queues;
578 memset(rxq + old_nb_queues, 0,
579 sizeof(rxq[0]) * new_qs);
582 dev->data->rx_queues = rxq;
584 } else if (dev->data->rx_queues != NULL && nb_queues == 0) {
585 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
587 rxq = dev->data->rx_queues;
589 for (i = nb_queues; i < old_nb_queues; i++)
590 (*dev->dev_ops->rx_queue_release)(rxq[i]);
592 dev->data->nb_rx_queues = nb_queues;
597 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
599 struct rte_eth_dev *dev;
601 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
603 dev = &rte_eth_devices[port_id];
604 if (rx_queue_id >= dev->data->nb_rx_queues) {
605 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
609 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
611 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
612 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
613 " already started\n",
614 rx_queue_id, port_id);
618 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
623 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
625 struct rte_eth_dev *dev;
627 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
629 dev = &rte_eth_devices[port_id];
630 if (!dev->data->dev_started) {
632 "port %d must be started before start any queue\n", port_id);
636 if (rx_queue_id >= dev->data->nb_rx_queues) {
637 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
641 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
643 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
644 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
645 " already stopped\n",
646 rx_queue_id, port_id);
650 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
655 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
657 struct rte_eth_dev *dev;
659 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
661 dev = &rte_eth_devices[port_id];
662 if (tx_queue_id >= dev->data->nb_tx_queues) {
663 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
667 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
669 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
670 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
671 " already started\n",
672 tx_queue_id, port_id);
676 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
681 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_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 (!dev->data->dev_started) {
690 "port %d must be started before start any queue\n", port_id);
694 if (tx_queue_id >= dev->data->nb_tx_queues) {
695 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
699 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
701 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
702 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
703 " already stopped\n",
704 tx_queue_id, port_id);
708 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
713 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
715 uint16_t old_nb_queues = dev->data->nb_tx_queues;
719 if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */
720 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
721 sizeof(dev->data->tx_queues[0]) * nb_queues,
722 RTE_CACHE_LINE_SIZE);
723 if (dev->data->tx_queues == NULL) {
724 dev->data->nb_tx_queues = 0;
727 } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */
728 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
730 txq = dev->data->tx_queues;
732 for (i = nb_queues; i < old_nb_queues; i++)
733 (*dev->dev_ops->tx_queue_release)(txq[i]);
734 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
735 RTE_CACHE_LINE_SIZE);
738 if (nb_queues > old_nb_queues) {
739 uint16_t new_qs = nb_queues - old_nb_queues;
741 memset(txq + old_nb_queues, 0,
742 sizeof(txq[0]) * new_qs);
745 dev->data->tx_queues = txq;
747 } else if (dev->data->tx_queues != NULL && nb_queues == 0) {
748 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
750 txq = dev->data->tx_queues;
752 for (i = nb_queues; i < old_nb_queues; i++)
753 (*dev->dev_ops->tx_queue_release)(txq[i]);
755 dev->data->nb_tx_queues = nb_queues;
760 rte_eth_speed_bitflag(uint32_t speed, int duplex)
763 case ETH_SPEED_NUM_10M:
764 return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD;
765 case ETH_SPEED_NUM_100M:
766 return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD;
767 case ETH_SPEED_NUM_1G:
768 return ETH_LINK_SPEED_1G;
769 case ETH_SPEED_NUM_2_5G:
770 return ETH_LINK_SPEED_2_5G;
771 case ETH_SPEED_NUM_5G:
772 return ETH_LINK_SPEED_5G;
773 case ETH_SPEED_NUM_10G:
774 return ETH_LINK_SPEED_10G;
775 case ETH_SPEED_NUM_20G:
776 return ETH_LINK_SPEED_20G;
777 case ETH_SPEED_NUM_25G:
778 return ETH_LINK_SPEED_25G;
779 case ETH_SPEED_NUM_40G:
780 return ETH_LINK_SPEED_40G;
781 case ETH_SPEED_NUM_50G:
782 return ETH_LINK_SPEED_50G;
783 case ETH_SPEED_NUM_56G:
784 return ETH_LINK_SPEED_56G;
785 case ETH_SPEED_NUM_100G:
786 return ETH_LINK_SPEED_100G;
793 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
794 const struct rte_eth_conf *dev_conf)
796 struct rte_eth_dev *dev;
797 struct rte_eth_dev_info dev_info;
800 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
802 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
804 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
805 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
809 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
811 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
812 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
816 dev = &rte_eth_devices[port_id];
818 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
819 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
821 if (dev->data->dev_started) {
823 "port %d must be stopped to allow configuration\n", port_id);
827 /* Copy the dev_conf parameter into the dev structure */
828 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
831 * Check that the numbers of RX and TX queues are not greater
832 * than the maximum number of RX and TX queues supported by the
835 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
837 if (nb_rx_q == 0 && nb_tx_q == 0) {
838 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d both rx and tx queue cannot be 0\n", port_id);
842 if (nb_rx_q > dev_info.max_rx_queues) {
843 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
844 port_id, nb_rx_q, dev_info.max_rx_queues);
848 if (nb_tx_q > dev_info.max_tx_queues) {
849 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
850 port_id, nb_tx_q, dev_info.max_tx_queues);
855 * If link state interrupt is enabled, check that the
856 * device supports it.
858 if ((dev_conf->intr_conf.lsc == 1) &&
859 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
860 RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
861 dev->data->drv_name);
866 * If jumbo frames are enabled, check that the maximum RX packet
867 * length is supported by the configured device.
869 if (dev_conf->rxmode.jumbo_frame == 1) {
870 if (dev_conf->rxmode.max_rx_pkt_len >
871 dev_info.max_rx_pktlen) {
872 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
873 " > max valid value %u\n",
875 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
876 (unsigned)dev_info.max_rx_pktlen);
878 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
879 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
880 " < min valid value %u\n",
882 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
883 (unsigned)ETHER_MIN_LEN);
887 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
888 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
889 /* Use default value */
890 dev->data->dev_conf.rxmode.max_rx_pkt_len =
895 * Setup new number of RX/TX queues and reconfigure device.
897 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
899 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
904 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
906 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
908 rte_eth_dev_rx_queue_config(dev, 0);
912 diag = (*dev->dev_ops->dev_configure)(dev);
914 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
916 rte_eth_dev_rx_queue_config(dev, 0);
917 rte_eth_dev_tx_queue_config(dev, 0);
925 rte_eth_dev_config_restore(uint8_t port_id)
927 struct rte_eth_dev *dev;
928 struct rte_eth_dev_info dev_info;
929 struct ether_addr addr;
933 dev = &rte_eth_devices[port_id];
935 rte_eth_dev_info_get(port_id, &dev_info);
937 if (RTE_ETH_DEV_SRIOV(dev).active)
938 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
940 /* replay MAC address configuration */
941 for (i = 0; i < dev_info.max_mac_addrs; i++) {
942 addr = dev->data->mac_addrs[i];
944 /* skip zero address */
945 if (is_zero_ether_addr(&addr))
948 /* add address to the hardware */
949 if (*dev->dev_ops->mac_addr_add &&
950 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
951 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
953 RTE_PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
955 /* exit the loop but not return an error */
960 /* replay promiscuous configuration */
961 if (rte_eth_promiscuous_get(port_id) == 1)
962 rte_eth_promiscuous_enable(port_id);
963 else if (rte_eth_promiscuous_get(port_id) == 0)
964 rte_eth_promiscuous_disable(port_id);
966 /* replay all multicast configuration */
967 if (rte_eth_allmulticast_get(port_id) == 1)
968 rte_eth_allmulticast_enable(port_id);
969 else if (rte_eth_allmulticast_get(port_id) == 0)
970 rte_eth_allmulticast_disable(port_id);
974 rte_eth_dev_start(uint8_t port_id)
976 struct rte_eth_dev *dev;
979 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
981 dev = &rte_eth_devices[port_id];
983 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
985 if (dev->data->dev_started != 0) {
986 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
987 " already started\n",
992 diag = (*dev->dev_ops->dev_start)(dev);
994 dev->data->dev_started = 1;
998 rte_eth_dev_config_restore(port_id);
1000 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1001 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1002 (*dev->dev_ops->link_update)(dev, 0);
1008 rte_eth_dev_stop(uint8_t port_id)
1010 struct rte_eth_dev *dev;
1012 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1013 dev = &rte_eth_devices[port_id];
1015 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1017 if (dev->data->dev_started == 0) {
1018 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1019 " already stopped\n",
1024 dev->data->dev_started = 0;
1025 (*dev->dev_ops->dev_stop)(dev);
1029 rte_eth_dev_set_link_up(uint8_t port_id)
1031 struct rte_eth_dev *dev;
1033 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1035 dev = &rte_eth_devices[port_id];
1037 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1038 return (*dev->dev_ops->dev_set_link_up)(dev);
1042 rte_eth_dev_set_link_down(uint8_t port_id)
1044 struct rte_eth_dev *dev;
1046 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1048 dev = &rte_eth_devices[port_id];
1050 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1051 return (*dev->dev_ops->dev_set_link_down)(dev);
1055 rte_eth_dev_close(uint8_t port_id)
1057 struct rte_eth_dev *dev;
1059 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1060 dev = &rte_eth_devices[port_id];
1062 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1063 dev->data->dev_started = 0;
1064 (*dev->dev_ops->dev_close)(dev);
1066 dev->data->nb_rx_queues = 0;
1067 rte_free(dev->data->rx_queues);
1068 dev->data->rx_queues = NULL;
1069 dev->data->nb_tx_queues = 0;
1070 rte_free(dev->data->tx_queues);
1071 dev->data->tx_queues = NULL;
1075 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1076 uint16_t nb_rx_desc, unsigned int socket_id,
1077 const struct rte_eth_rxconf *rx_conf,
1078 struct rte_mempool *mp)
1081 uint32_t mbp_buf_size;
1082 struct rte_eth_dev *dev;
1083 struct rte_eth_dev_info dev_info;
1085 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1087 dev = &rte_eth_devices[port_id];
1088 if (rx_queue_id >= dev->data->nb_rx_queues) {
1089 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1093 if (dev->data->dev_started) {
1094 RTE_PMD_DEBUG_TRACE(
1095 "port %d must be stopped to allow configuration\n", port_id);
1099 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1100 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1103 * Check the size of the mbuf data buffer.
1104 * This value must be provided in the private data of the memory pool.
1105 * First check that the memory pool has a valid private data.
1107 rte_eth_dev_info_get(port_id, &dev_info);
1108 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1109 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1110 mp->name, (int) mp->private_data_size,
1111 (int) sizeof(struct rte_pktmbuf_pool_private));
1114 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1116 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1117 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1118 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1122 (int)(RTE_PKTMBUF_HEADROOM +
1123 dev_info.min_rx_bufsize),
1124 (int)RTE_PKTMBUF_HEADROOM,
1125 (int)dev_info.min_rx_bufsize);
1129 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1130 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1131 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1133 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1134 "should be: <= %hu, = %hu, and a product of %hu\n",
1136 dev_info.rx_desc_lim.nb_max,
1137 dev_info.rx_desc_lim.nb_min,
1138 dev_info.rx_desc_lim.nb_align);
1142 if (rx_conf == NULL)
1143 rx_conf = &dev_info.default_rxconf;
1145 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1146 socket_id, rx_conf, mp);
1148 if (!dev->data->min_rx_buf_size ||
1149 dev->data->min_rx_buf_size > mbp_buf_size)
1150 dev->data->min_rx_buf_size = mbp_buf_size;
1157 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1158 uint16_t nb_tx_desc, unsigned int socket_id,
1159 const struct rte_eth_txconf *tx_conf)
1161 struct rte_eth_dev *dev;
1162 struct rte_eth_dev_info dev_info;
1164 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1166 dev = &rte_eth_devices[port_id];
1167 if (tx_queue_id >= dev->data->nb_tx_queues) {
1168 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1172 if (dev->data->dev_started) {
1173 RTE_PMD_DEBUG_TRACE(
1174 "port %d must be stopped to allow configuration\n", port_id);
1178 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1179 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1181 rte_eth_dev_info_get(port_id, &dev_info);
1183 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1184 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1185 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1186 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1187 "should be: <= %hu, = %hu, and a product of %hu\n",
1189 dev_info.tx_desc_lim.nb_max,
1190 dev_info.tx_desc_lim.nb_min,
1191 dev_info.tx_desc_lim.nb_align);
1195 if (tx_conf == NULL)
1196 tx_conf = &dev_info.default_txconf;
1198 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1199 socket_id, tx_conf);
1203 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
1204 void *userdata __rte_unused)
1208 for (i = 0; i < unsent; i++)
1209 rte_pktmbuf_free(pkts[i]);
1213 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
1216 uint64_t *count = userdata;
1219 for (i = 0; i < unsent; i++)
1220 rte_pktmbuf_free(pkts[i]);
1226 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
1227 buffer_tx_error_fn cbfn, void *userdata)
1229 buffer->error_callback = cbfn;
1230 buffer->error_userdata = userdata;
1235 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
1242 buffer->size = size;
1243 if (buffer->error_callback == NULL) {
1244 ret = rte_eth_tx_buffer_set_err_callback(
1245 buffer, rte_eth_tx_buffer_drop_callback, NULL);
1252 rte_eth_promiscuous_enable(uint8_t port_id)
1254 struct rte_eth_dev *dev;
1256 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1257 dev = &rte_eth_devices[port_id];
1259 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1260 (*dev->dev_ops->promiscuous_enable)(dev);
1261 dev->data->promiscuous = 1;
1265 rte_eth_promiscuous_disable(uint8_t port_id)
1267 struct rte_eth_dev *dev;
1269 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1270 dev = &rte_eth_devices[port_id];
1272 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1273 dev->data->promiscuous = 0;
1274 (*dev->dev_ops->promiscuous_disable)(dev);
1278 rte_eth_promiscuous_get(uint8_t port_id)
1280 struct rte_eth_dev *dev;
1282 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1284 dev = &rte_eth_devices[port_id];
1285 return dev->data->promiscuous;
1289 rte_eth_allmulticast_enable(uint8_t port_id)
1291 struct rte_eth_dev *dev;
1293 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1294 dev = &rte_eth_devices[port_id];
1296 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1297 (*dev->dev_ops->allmulticast_enable)(dev);
1298 dev->data->all_multicast = 1;
1302 rte_eth_allmulticast_disable(uint8_t port_id)
1304 struct rte_eth_dev *dev;
1306 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1307 dev = &rte_eth_devices[port_id];
1309 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1310 dev->data->all_multicast = 0;
1311 (*dev->dev_ops->allmulticast_disable)(dev);
1315 rte_eth_allmulticast_get(uint8_t port_id)
1317 struct rte_eth_dev *dev;
1319 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1321 dev = &rte_eth_devices[port_id];
1322 return dev->data->all_multicast;
1326 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1327 struct rte_eth_link *link)
1329 struct rte_eth_link *dst = link;
1330 struct rte_eth_link *src = &(dev->data->dev_link);
1332 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1333 *(uint64_t *)src) == 0)
1340 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1342 struct rte_eth_dev *dev;
1344 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1345 dev = &rte_eth_devices[port_id];
1347 if (dev->data->dev_conf.intr_conf.lsc != 0)
1348 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1350 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1351 (*dev->dev_ops->link_update)(dev, 1);
1352 *eth_link = dev->data->dev_link;
1357 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1359 struct rte_eth_dev *dev;
1361 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1362 dev = &rte_eth_devices[port_id];
1364 if (dev->data->dev_conf.intr_conf.lsc != 0)
1365 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1367 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1368 (*dev->dev_ops->link_update)(dev, 0);
1369 *eth_link = dev->data->dev_link;
1374 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1376 struct rte_eth_dev *dev;
1378 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1380 dev = &rte_eth_devices[port_id];
1381 memset(stats, 0, sizeof(*stats));
1383 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1384 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1385 (*dev->dev_ops->stats_get)(dev, stats);
1390 rte_eth_stats_reset(uint8_t port_id)
1392 struct rte_eth_dev *dev;
1394 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1395 dev = &rte_eth_devices[port_id];
1397 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1398 (*dev->dev_ops->stats_reset)(dev);
1399 dev->data->rx_mbuf_alloc_failed = 0;
1403 get_xstats_count(uint8_t port_id)
1405 struct rte_eth_dev *dev;
1408 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1409 dev = &rte_eth_devices[port_id];
1410 if (dev->dev_ops->xstats_get_names != NULL) {
1411 count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0);
1416 count += RTE_NB_STATS;
1417 count += RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
1419 count += RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
1425 rte_eth_xstats_get_names(uint8_t port_id,
1426 struct rte_eth_xstat_name *xstats_names,
1429 struct rte_eth_dev *dev;
1430 int cnt_used_entries;
1431 int cnt_expected_entries;
1432 int cnt_driver_entries;
1433 uint32_t idx, id_queue;
1436 cnt_expected_entries = get_xstats_count(port_id);
1437 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1438 (int)size < cnt_expected_entries)
1439 return cnt_expected_entries;
1441 /* port_id checked in get_xstats_count() */
1442 dev = &rte_eth_devices[port_id];
1443 cnt_used_entries = 0;
1445 for (idx = 0; idx < RTE_NB_STATS; idx++) {
1446 snprintf(xstats_names[cnt_used_entries].name,
1447 sizeof(xstats_names[0].name),
1448 "%s", rte_stats_strings[idx].name);
1451 num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1452 for (id_queue = 0; id_queue < num_q; id_queue++) {
1453 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1454 snprintf(xstats_names[cnt_used_entries].name,
1455 sizeof(xstats_names[0].name),
1457 id_queue, rte_rxq_stats_strings[idx].name);
1462 num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1463 for (id_queue = 0; id_queue < num_q; id_queue++) {
1464 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
1465 snprintf(xstats_names[cnt_used_entries].name,
1466 sizeof(xstats_names[0].name),
1468 id_queue, rte_txq_stats_strings[idx].name);
1473 if (dev->dev_ops->xstats_get_names != NULL) {
1474 /* If there are any driver-specific xstats, append them
1477 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
1479 xstats_names + cnt_used_entries,
1480 size - cnt_used_entries);
1481 if (cnt_driver_entries < 0)
1482 return cnt_driver_entries;
1483 cnt_used_entries += cnt_driver_entries;
1486 return cnt_used_entries;
1489 /* retrieve ethdev extended statistics */
1491 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstat *xstats,
1494 struct rte_eth_stats eth_stats;
1495 struct rte_eth_dev *dev;
1496 unsigned count = 0, i, q;
1498 uint64_t val, *stats_ptr;
1499 uint16_t nb_rxqs, nb_txqs;
1501 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1503 dev = &rte_eth_devices[port_id];
1505 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1506 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1508 /* Return generic statistics */
1509 count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
1510 (nb_txqs * RTE_NB_TXQ_STATS);
1512 /* implemented by the driver */
1513 if (dev->dev_ops->xstats_get != NULL) {
1514 /* Retrieve the xstats from the driver at the end of the
1517 xcount = (*dev->dev_ops->xstats_get)(dev,
1518 xstats ? xstats + count : NULL,
1519 (n > count) ? n - count : 0);
1525 if (n < count + xcount || xstats == NULL)
1526 return count + xcount;
1528 /* now fill the xstats structure */
1530 rte_eth_stats_get(port_id, ð_stats);
1533 for (i = 0; i < RTE_NB_STATS; i++) {
1534 stats_ptr = RTE_PTR_ADD(ð_stats,
1535 rte_stats_strings[i].offset);
1537 xstats[count++].value = val;
1541 for (q = 0; q < nb_rxqs; q++) {
1542 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1543 stats_ptr = RTE_PTR_ADD(ð_stats,
1544 rte_rxq_stats_strings[i].offset +
1545 q * sizeof(uint64_t));
1547 xstats[count++].value = val;
1552 for (q = 0; q < nb_txqs; q++) {
1553 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1554 stats_ptr = RTE_PTR_ADD(ð_stats,
1555 rte_txq_stats_strings[i].offset +
1556 q * sizeof(uint64_t));
1558 xstats[count++].value = val;
1562 for (i = 0; i < count; i++)
1564 /* add an offset to driver-specific stats */
1565 for ( ; i < count + xcount; i++)
1566 xstats[i].id += count;
1568 return count + xcount;
1571 /* reset ethdev extended statistics */
1573 rte_eth_xstats_reset(uint8_t port_id)
1575 struct rte_eth_dev *dev;
1577 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1578 dev = &rte_eth_devices[port_id];
1580 /* implemented by the driver */
1581 if (dev->dev_ops->xstats_reset != NULL) {
1582 (*dev->dev_ops->xstats_reset)(dev);
1586 /* fallback to default */
1587 rte_eth_stats_reset(port_id);
1591 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1594 struct rte_eth_dev *dev;
1596 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1598 dev = &rte_eth_devices[port_id];
1600 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1601 return (*dev->dev_ops->queue_stats_mapping_set)
1602 (dev, queue_id, stat_idx, is_rx);
1607 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1610 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1616 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1619 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1624 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1626 struct rte_eth_dev *dev;
1627 const struct rte_eth_desc_lim lim = {
1628 .nb_max = UINT16_MAX,
1633 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1634 dev = &rte_eth_devices[port_id];
1636 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1637 dev_info->rx_desc_lim = lim;
1638 dev_info->tx_desc_lim = lim;
1640 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1641 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1642 dev_info->pci_dev = dev->pci_dev;
1643 dev_info->driver_name = dev->data->drv_name;
1644 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
1645 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
1649 rte_eth_dev_get_supported_ptypes(uint8_t port_id, uint32_t ptype_mask,
1650 uint32_t *ptypes, int num)
1653 struct rte_eth_dev *dev;
1654 const uint32_t *all_ptypes;
1656 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1657 dev = &rte_eth_devices[port_id];
1658 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
1659 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
1664 for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
1665 if (all_ptypes[i] & ptype_mask) {
1667 ptypes[j] = all_ptypes[i];
1675 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1677 struct rte_eth_dev *dev;
1679 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1680 dev = &rte_eth_devices[port_id];
1681 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1686 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1688 struct rte_eth_dev *dev;
1690 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1692 dev = &rte_eth_devices[port_id];
1693 *mtu = dev->data->mtu;
1698 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1701 struct rte_eth_dev *dev;
1703 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1704 dev = &rte_eth_devices[port_id];
1705 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1707 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1709 dev->data->mtu = mtu;
1715 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1717 struct rte_eth_dev *dev;
1719 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1720 dev = &rte_eth_devices[port_id];
1721 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1722 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1726 if (vlan_id > 4095) {
1727 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1728 port_id, (unsigned) vlan_id);
1731 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1733 return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1737 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1739 struct rte_eth_dev *dev;
1741 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1742 dev = &rte_eth_devices[port_id];
1743 if (rx_queue_id >= dev->data->nb_rx_queues) {
1744 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1748 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1749 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1755 rte_eth_dev_set_vlan_ether_type(uint8_t port_id,
1756 enum rte_vlan_type vlan_type,
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->vlan_tpid_set, -ENOTSUP);
1765 return (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type, tpid);
1769 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1771 struct rte_eth_dev *dev;
1776 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1777 dev = &rte_eth_devices[port_id];
1779 /*check which option changed by application*/
1780 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1781 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1783 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1784 mask |= ETH_VLAN_STRIP_MASK;
1787 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1788 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1790 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1791 mask |= ETH_VLAN_FILTER_MASK;
1794 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1795 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1797 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1798 mask |= ETH_VLAN_EXTEND_MASK;
1805 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1806 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1812 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1814 struct rte_eth_dev *dev;
1817 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1818 dev = &rte_eth_devices[port_id];
1820 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1821 ret |= ETH_VLAN_STRIP_OFFLOAD;
1823 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1824 ret |= ETH_VLAN_FILTER_OFFLOAD;
1826 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1827 ret |= ETH_VLAN_EXTEND_OFFLOAD;
1833 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1835 struct rte_eth_dev *dev;
1837 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1838 dev = &rte_eth_devices[port_id];
1839 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1840 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1846 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1848 struct rte_eth_dev *dev;
1850 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1851 dev = &rte_eth_devices[port_id];
1852 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1853 memset(fc_conf, 0, sizeof(*fc_conf));
1854 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1858 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1860 struct rte_eth_dev *dev;
1862 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1863 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1864 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1868 dev = &rte_eth_devices[port_id];
1869 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1870 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1874 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1876 struct rte_eth_dev *dev;
1878 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1879 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1880 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1884 dev = &rte_eth_devices[port_id];
1885 /* High water, low water validation are device specific */
1886 if (*dev->dev_ops->priority_flow_ctrl_set)
1887 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1892 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
1900 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
1901 RTE_PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
1902 RTE_RETA_GROUP_SIZE);
1906 num = reta_size / RTE_RETA_GROUP_SIZE;
1907 for (i = 0; i < num; i++) {
1908 if (reta_conf[i].mask)
1916 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
1920 uint16_t i, idx, shift;
1926 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
1930 for (i = 0; i < reta_size; i++) {
1931 idx = i / RTE_RETA_GROUP_SIZE;
1932 shift = i % RTE_RETA_GROUP_SIZE;
1933 if ((reta_conf[idx].mask & (1ULL << shift)) &&
1934 (reta_conf[idx].reta[shift] >= max_rxq)) {
1935 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
1936 "the maximum rxq index: %u\n", idx, shift,
1937 reta_conf[idx].reta[shift], max_rxq);
1946 rte_eth_dev_rss_reta_update(uint8_t port_id,
1947 struct rte_eth_rss_reta_entry64 *reta_conf,
1950 struct rte_eth_dev *dev;
1953 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1954 /* Check mask bits */
1955 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
1959 dev = &rte_eth_devices[port_id];
1961 /* Check entry value */
1962 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
1963 dev->data->nb_rx_queues);
1967 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
1968 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
1972 rte_eth_dev_rss_reta_query(uint8_t port_id,
1973 struct rte_eth_rss_reta_entry64 *reta_conf,
1976 struct rte_eth_dev *dev;
1979 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1981 /* Check mask bits */
1982 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
1986 dev = &rte_eth_devices[port_id];
1987 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
1988 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
1992 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
1994 struct rte_eth_dev *dev;
1995 uint16_t rss_hash_protos;
1997 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1998 rss_hash_protos = rss_conf->rss_hf;
1999 if ((rss_hash_protos != 0) &&
2000 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2001 RTE_PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2005 dev = &rte_eth_devices[port_id];
2006 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2007 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2011 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2012 struct rte_eth_rss_conf *rss_conf)
2014 struct rte_eth_dev *dev;
2016 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2017 dev = &rte_eth_devices[port_id];
2018 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2019 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2023 rte_eth_dev_udp_tunnel_port_add(uint8_t port_id,
2024 struct rte_eth_udp_tunnel *udp_tunnel)
2026 struct rte_eth_dev *dev;
2028 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2029 if (udp_tunnel == NULL) {
2030 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2034 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2035 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2039 dev = &rte_eth_devices[port_id];
2040 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
2041 return (*dev->dev_ops->udp_tunnel_port_add)(dev, udp_tunnel);
2045 rte_eth_dev_udp_tunnel_port_delete(uint8_t port_id,
2046 struct rte_eth_udp_tunnel *udp_tunnel)
2048 struct rte_eth_dev *dev;
2050 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2051 dev = &rte_eth_devices[port_id];
2053 if (udp_tunnel == NULL) {
2054 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2058 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2059 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2063 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
2064 return (*dev->dev_ops->udp_tunnel_port_del)(dev, udp_tunnel);
2068 rte_eth_led_on(uint8_t port_id)
2070 struct rte_eth_dev *dev;
2072 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2073 dev = &rte_eth_devices[port_id];
2074 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2075 return (*dev->dev_ops->dev_led_on)(dev);
2079 rte_eth_led_off(uint8_t port_id)
2081 struct rte_eth_dev *dev;
2083 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2084 dev = &rte_eth_devices[port_id];
2085 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2086 return (*dev->dev_ops->dev_led_off)(dev);
2090 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2094 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2096 struct rte_eth_dev_info dev_info;
2097 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2100 rte_eth_dev_info_get(port_id, &dev_info);
2102 for (i = 0; i < dev_info.max_mac_addrs; i++)
2103 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2109 static const struct ether_addr null_mac_addr;
2112 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2115 struct rte_eth_dev *dev;
2119 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2120 dev = &rte_eth_devices[port_id];
2121 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2123 if (is_zero_ether_addr(addr)) {
2124 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2128 if (pool >= ETH_64_POOLS) {
2129 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2133 index = get_mac_addr_index(port_id, addr);
2135 index = get_mac_addr_index(port_id, &null_mac_addr);
2137 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2142 pool_mask = dev->data->mac_pool_sel[index];
2144 /* Check if both MAC address and pool is already there, and do nothing */
2145 if (pool_mask & (1ULL << pool))
2150 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2152 /* Update address in NIC data structure */
2153 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2155 /* Update pool bitmap in NIC data structure */
2156 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2162 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2164 struct rte_eth_dev *dev;
2167 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2168 dev = &rte_eth_devices[port_id];
2169 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2171 index = get_mac_addr_index(port_id, addr);
2173 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2175 } else if (index < 0)
2176 return 0; /* Do nothing if address wasn't found */
2179 (*dev->dev_ops->mac_addr_remove)(dev, index);
2181 /* Update address in NIC data structure */
2182 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2184 /* reset pool bitmap */
2185 dev->data->mac_pool_sel[index] = 0;
2191 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2193 struct rte_eth_dev *dev;
2195 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2197 if (!is_valid_assigned_ether_addr(addr))
2200 dev = &rte_eth_devices[port_id];
2201 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2203 /* Update default address in NIC data structure */
2204 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2206 (*dev->dev_ops->mac_addr_set)(dev, addr);
2212 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2213 uint16_t rx_mode, uint8_t on)
2216 struct rte_eth_dev *dev;
2217 struct rte_eth_dev_info dev_info;
2219 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2221 dev = &rte_eth_devices[port_id];
2222 rte_eth_dev_info_get(port_id, &dev_info);
2224 num_vfs = dev_info.max_vfs;
2226 RTE_PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2231 RTE_PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2234 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2235 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2239 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2243 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2245 struct rte_eth_dev_info dev_info;
2246 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2249 rte_eth_dev_info_get(port_id, &dev_info);
2250 if (!dev->data->hash_mac_addrs)
2253 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2254 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2255 ETHER_ADDR_LEN) == 0)
2262 rte_eth_dev_uc_hash_table_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 dev = &rte_eth_devices[port_id];
2272 if (is_zero_ether_addr(addr)) {
2273 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2278 index = get_hash_mac_addr_index(port_id, addr);
2279 /* Check if it's already there, and do nothing */
2280 if ((index >= 0) && (on))
2285 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2286 "set in UTA\n", port_id);
2290 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2292 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2298 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2299 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2301 /* Update address in NIC data structure */
2303 ether_addr_copy(addr,
2304 &dev->data->hash_mac_addrs[index]);
2306 ether_addr_copy(&null_mac_addr,
2307 &dev->data->hash_mac_addrs[index]);
2314 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2316 struct rte_eth_dev *dev;
2318 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2320 dev = &rte_eth_devices[port_id];
2322 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2323 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2327 rte_eth_dev_set_vf_rx(uint8_t port_id, uint16_t vf, uint8_t on)
2330 struct rte_eth_dev *dev;
2331 struct rte_eth_dev_info dev_info;
2333 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2335 dev = &rte_eth_devices[port_id];
2336 rte_eth_dev_info_get(port_id, &dev_info);
2338 num_vfs = dev_info.max_vfs;
2340 RTE_PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2344 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2345 return (*dev->dev_ops->set_vf_rx)(dev, vf, on);
2349 rte_eth_dev_set_vf_tx(uint8_t port_id, uint16_t vf, uint8_t on)
2352 struct rte_eth_dev *dev;
2353 struct rte_eth_dev_info dev_info;
2355 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2357 dev = &rte_eth_devices[port_id];
2358 rte_eth_dev_info_get(port_id, &dev_info);
2360 num_vfs = dev_info.max_vfs;
2362 RTE_PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2366 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2367 return (*dev->dev_ops->set_vf_tx)(dev, vf, on);
2371 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2372 uint64_t vf_mask, uint8_t vlan_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 if (vlan_id > ETHER_MAX_VLAN_ID) {
2381 RTE_PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2387 RTE_PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2391 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2392 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2396 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2399 struct rte_eth_dev *dev;
2400 struct rte_eth_dev_info dev_info;
2401 struct rte_eth_link link;
2403 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2405 dev = &rte_eth_devices[port_id];
2406 rte_eth_dev_info_get(port_id, &dev_info);
2407 link = dev->data->dev_link;
2409 if (queue_idx > dev_info.max_tx_queues) {
2410 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2411 "invalid queue id=%d\n", port_id, queue_idx);
2415 if (tx_rate > link.link_speed) {
2416 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2417 "bigger than link speed= %d\n",
2418 tx_rate, link.link_speed);
2422 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2423 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2426 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2429 struct rte_eth_dev *dev;
2430 struct rte_eth_dev_info dev_info;
2431 struct rte_eth_link link;
2436 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2438 dev = &rte_eth_devices[port_id];
2439 rte_eth_dev_info_get(port_id, &dev_info);
2440 link = dev->data->dev_link;
2442 if (vf > dev_info.max_vfs) {
2443 RTE_PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2444 "invalid vf id=%d\n", port_id, vf);
2448 if (tx_rate > link.link_speed) {
2449 RTE_PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2450 "bigger than link speed= %d\n",
2451 tx_rate, link.link_speed);
2455 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2456 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2460 rte_eth_mirror_rule_set(uint8_t port_id,
2461 struct rte_eth_mirror_conf *mirror_conf,
2462 uint8_t rule_id, uint8_t on)
2464 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2466 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2467 if (mirror_conf->rule_type == 0) {
2468 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2472 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2473 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2478 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2479 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2480 (mirror_conf->pool_mask == 0)) {
2481 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2485 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2486 mirror_conf->vlan.vlan_mask == 0) {
2487 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2491 dev = &rte_eth_devices[port_id];
2492 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2494 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2498 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2500 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2502 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2504 dev = &rte_eth_devices[port_id];
2505 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2507 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2511 rte_eth_dev_callback_register(uint8_t port_id,
2512 enum rte_eth_event_type event,
2513 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2515 struct rte_eth_dev *dev;
2516 struct rte_eth_dev_callback *user_cb;
2521 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2523 dev = &rte_eth_devices[port_id];
2524 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2526 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2527 if (user_cb->cb_fn == cb_fn &&
2528 user_cb->cb_arg == cb_arg &&
2529 user_cb->event == event) {
2534 /* create a new callback. */
2535 if (user_cb == NULL) {
2536 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2537 sizeof(struct rte_eth_dev_callback), 0);
2538 if (user_cb != NULL) {
2539 user_cb->cb_fn = cb_fn;
2540 user_cb->cb_arg = cb_arg;
2541 user_cb->event = event;
2542 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2546 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2547 return (user_cb == NULL) ? -ENOMEM : 0;
2551 rte_eth_dev_callback_unregister(uint8_t port_id,
2552 enum rte_eth_event_type event,
2553 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2556 struct rte_eth_dev *dev;
2557 struct rte_eth_dev_callback *cb, *next;
2562 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2564 dev = &rte_eth_devices[port_id];
2565 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2568 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2570 next = TAILQ_NEXT(cb, next);
2572 if (cb->cb_fn != cb_fn || cb->event != event ||
2573 (cb->cb_arg != (void *)-1 &&
2574 cb->cb_arg != cb_arg))
2578 * if this callback is not executing right now,
2581 if (cb->active == 0) {
2582 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2589 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2594 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2595 enum rte_eth_event_type event, void *cb_arg)
2597 struct rte_eth_dev_callback *cb_lst;
2598 struct rte_eth_dev_callback dev_cb;
2600 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2601 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2602 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2607 dev_cb.cb_arg = (void *) cb_arg;
2609 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2610 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2612 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2615 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2619 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
2622 struct rte_eth_dev *dev;
2623 struct rte_intr_handle *intr_handle;
2627 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2629 dev = &rte_eth_devices[port_id];
2630 intr_handle = &dev->pci_dev->intr_handle;
2631 if (!intr_handle->intr_vec) {
2632 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2636 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2637 vec = intr_handle->intr_vec[qid];
2638 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2639 if (rc && rc != -EEXIST) {
2640 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2641 " op %d epfd %d vec %u\n",
2642 port_id, qid, op, epfd, vec);
2649 const struct rte_memzone *
2650 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2651 uint16_t queue_id, size_t size, unsigned align,
2654 char z_name[RTE_MEMZONE_NAMESIZE];
2655 const struct rte_memzone *mz;
2657 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2658 dev->driver->pci_drv.driver.name, ring_name,
2659 dev->data->port_id, queue_id);
2661 mz = rte_memzone_lookup(z_name);
2665 if (rte_xen_dom0_supported())
2666 return rte_memzone_reserve_bounded(z_name, size, socket_id,
2667 0, align, RTE_PGSIZE_2M);
2669 return rte_memzone_reserve_aligned(z_name, size, socket_id,
2674 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
2675 int epfd, int op, void *data)
2678 struct rte_eth_dev *dev;
2679 struct rte_intr_handle *intr_handle;
2682 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2684 dev = &rte_eth_devices[port_id];
2685 if (queue_id >= dev->data->nb_rx_queues) {
2686 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
2690 intr_handle = &dev->pci_dev->intr_handle;
2691 if (!intr_handle->intr_vec) {
2692 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2696 vec = intr_handle->intr_vec[queue_id];
2697 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2698 if (rc && rc != -EEXIST) {
2699 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2700 " op %d epfd %d vec %u\n",
2701 port_id, queue_id, op, epfd, vec);
2709 rte_eth_dev_rx_intr_enable(uint8_t port_id,
2712 struct rte_eth_dev *dev;
2714 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2716 dev = &rte_eth_devices[port_id];
2718 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
2719 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
2723 rte_eth_dev_rx_intr_disable(uint8_t port_id,
2726 struct rte_eth_dev *dev;
2728 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2730 dev = &rte_eth_devices[port_id];
2732 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
2733 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
2736 #ifdef RTE_NIC_BYPASS
2737 int rte_eth_dev_bypass_init(uint8_t port_id)
2739 struct rte_eth_dev *dev;
2741 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2743 dev = &rte_eth_devices[port_id];
2744 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2745 (*dev->dev_ops->bypass_init)(dev);
2750 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2752 struct rte_eth_dev *dev;
2754 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2756 dev = &rte_eth_devices[port_id];
2757 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2758 (*dev->dev_ops->bypass_state_show)(dev, state);
2763 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2765 struct rte_eth_dev *dev;
2767 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2769 dev = &rte_eth_devices[port_id];
2770 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2771 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2776 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2778 struct rte_eth_dev *dev;
2780 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2782 dev = &rte_eth_devices[port_id];
2783 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2784 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2789 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2791 struct rte_eth_dev *dev;
2793 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2795 dev = &rte_eth_devices[port_id];
2797 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2798 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2803 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2805 struct rte_eth_dev *dev;
2807 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2809 dev = &rte_eth_devices[port_id];
2811 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2812 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2817 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2819 struct rte_eth_dev *dev;
2821 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2823 dev = &rte_eth_devices[port_id];
2825 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2826 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2831 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2833 struct rte_eth_dev *dev;
2835 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2837 dev = &rte_eth_devices[port_id];
2839 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2840 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2845 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2847 struct rte_eth_dev *dev;
2849 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2851 dev = &rte_eth_devices[port_id];
2853 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2854 (*dev->dev_ops->bypass_wd_reset)(dev);
2860 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
2862 struct rte_eth_dev *dev;
2864 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2866 dev = &rte_eth_devices[port_id];
2867 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2868 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
2869 RTE_ETH_FILTER_NOP, NULL);
2873 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
2874 enum rte_filter_op filter_op, void *arg)
2876 struct rte_eth_dev *dev;
2878 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2880 dev = &rte_eth_devices[port_id];
2881 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2882 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
2886 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
2887 rte_rx_callback_fn fn, void *user_param)
2889 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2890 rte_errno = ENOTSUP;
2893 /* check input parameters */
2894 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2895 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2899 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2907 cb->param = user_param;
2909 rte_spinlock_lock(&rte_eth_rx_cb_lock);
2910 /* Add the callbacks in fifo order. */
2911 struct rte_eth_rxtx_callback *tail =
2912 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2915 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2922 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
2928 rte_eth_add_first_rx_callback(uint8_t port_id, uint16_t queue_id,
2929 rte_rx_callback_fn fn, void *user_param)
2931 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2932 rte_errno = ENOTSUP;
2935 /* check input parameters */
2936 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2937 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2942 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2950 cb->param = user_param;
2952 rte_spinlock_lock(&rte_eth_rx_cb_lock);
2953 /* Add the callbacks at fisrt position*/
2954 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2956 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2957 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
2963 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
2964 rte_tx_callback_fn fn, void *user_param)
2966 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2967 rte_errno = ENOTSUP;
2970 /* check input parameters */
2971 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2972 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
2977 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2985 cb->param = user_param;
2987 rte_spinlock_lock(&rte_eth_tx_cb_lock);
2988 /* Add the callbacks in fifo order. */
2989 struct rte_eth_rxtx_callback *tail =
2990 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
2993 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3000 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3006 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3007 struct rte_eth_rxtx_callback *user_cb)
3009 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3012 /* Check input parameters. */
3013 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3014 if (user_cb == NULL ||
3015 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
3018 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3019 struct rte_eth_rxtx_callback *cb;
3020 struct rte_eth_rxtx_callback **prev_cb;
3023 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3024 prev_cb = &dev->post_rx_burst_cbs[queue_id];
3025 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3027 if (cb == user_cb) {
3028 /* Remove the user cb from the callback list. */
3029 *prev_cb = cb->next;
3034 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3040 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3041 struct rte_eth_rxtx_callback *user_cb)
3043 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3046 /* Check input parameters. */
3047 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3048 if (user_cb == NULL ||
3049 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
3052 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3054 struct rte_eth_rxtx_callback *cb;
3055 struct rte_eth_rxtx_callback **prev_cb;
3057 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3058 prev_cb = &dev->pre_tx_burst_cbs[queue_id];
3059 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3061 if (cb == user_cb) {
3062 /* Remove the user cb from the callback list. */
3063 *prev_cb = cb->next;
3068 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3074 rte_eth_rx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3075 struct rte_eth_rxq_info *qinfo)
3077 struct rte_eth_dev *dev;
3079 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3084 dev = &rte_eth_devices[port_id];
3085 if (queue_id >= dev->data->nb_rx_queues) {
3086 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3090 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3092 memset(qinfo, 0, sizeof(*qinfo));
3093 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3098 rte_eth_tx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3099 struct rte_eth_txq_info *qinfo)
3101 struct rte_eth_dev *dev;
3103 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3108 dev = &rte_eth_devices[port_id];
3109 if (queue_id >= dev->data->nb_tx_queues) {
3110 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3114 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3116 memset(qinfo, 0, sizeof(*qinfo));
3117 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3122 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3123 struct ether_addr *mc_addr_set,
3124 uint32_t nb_mc_addr)
3126 struct rte_eth_dev *dev;
3128 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3130 dev = &rte_eth_devices[port_id];
3131 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3132 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3136 rte_eth_timesync_enable(uint8_t port_id)
3138 struct rte_eth_dev *dev;
3140 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3141 dev = &rte_eth_devices[port_id];
3143 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3144 return (*dev->dev_ops->timesync_enable)(dev);
3148 rte_eth_timesync_disable(uint8_t port_id)
3150 struct rte_eth_dev *dev;
3152 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3153 dev = &rte_eth_devices[port_id];
3155 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3156 return (*dev->dev_ops->timesync_disable)(dev);
3160 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3163 struct rte_eth_dev *dev;
3165 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3166 dev = &rte_eth_devices[port_id];
3168 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3169 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3173 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3175 struct rte_eth_dev *dev;
3177 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3178 dev = &rte_eth_devices[port_id];
3180 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3181 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3185 rte_eth_timesync_adjust_time(uint8_t port_id, int64_t delta)
3187 struct rte_eth_dev *dev;
3189 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3190 dev = &rte_eth_devices[port_id];
3192 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3193 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3197 rte_eth_timesync_read_time(uint8_t port_id, struct timespec *timestamp)
3199 struct rte_eth_dev *dev;
3201 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3202 dev = &rte_eth_devices[port_id];
3204 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3205 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3209 rte_eth_timesync_write_time(uint8_t port_id, const struct timespec *timestamp)
3211 struct rte_eth_dev *dev;
3213 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3214 dev = &rte_eth_devices[port_id];
3216 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3217 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3221 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3223 struct rte_eth_dev *dev;
3225 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3227 dev = &rte_eth_devices[port_id];
3228 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3229 return (*dev->dev_ops->get_reg)(dev, info);
3233 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3235 struct rte_eth_dev *dev;
3237 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3239 dev = &rte_eth_devices[port_id];
3240 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3241 return (*dev->dev_ops->get_eeprom_length)(dev);
3245 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3247 struct rte_eth_dev *dev;
3249 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3251 dev = &rte_eth_devices[port_id];
3252 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3253 return (*dev->dev_ops->get_eeprom)(dev, info);
3257 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3259 struct rte_eth_dev *dev;
3261 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3263 dev = &rte_eth_devices[port_id];
3264 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3265 return (*dev->dev_ops->set_eeprom)(dev, info);
3269 rte_eth_dev_get_dcb_info(uint8_t port_id,
3270 struct rte_eth_dcb_info *dcb_info)
3272 struct rte_eth_dev *dev;
3274 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3276 dev = &rte_eth_devices[port_id];
3277 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3279 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3280 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3284 rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_dev)
3286 if ((eth_dev == NULL) || (pci_dev == NULL)) {
3287 RTE_PMD_DEBUG_TRACE("NULL pointer eth_dev=%p pci_dev=%p\n",
3292 eth_dev->data->dev_flags = 0;
3293 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
3294 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
3295 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_DETACHABLE)
3296 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
3298 eth_dev->data->kdrv = pci_dev->kdrv;
3299 eth_dev->data->numa_node = pci_dev->device.numa_node;
3300 eth_dev->data->drv_name = pci_dev->driver->driver.name;
3304 rte_eth_dev_l2_tunnel_eth_type_conf(uint8_t port_id,
3305 struct rte_eth_l2_tunnel_conf *l2_tunnel)
3307 struct rte_eth_dev *dev;
3309 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3310 if (l2_tunnel == NULL) {
3311 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3315 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3316 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
3320 dev = &rte_eth_devices[port_id];
3321 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
3323 return (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev, l2_tunnel);
3327 rte_eth_dev_l2_tunnel_offload_set(uint8_t port_id,
3328 struct rte_eth_l2_tunnel_conf *l2_tunnel,
3332 struct rte_eth_dev *dev;
3334 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3336 if (l2_tunnel == NULL) {
3337 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3341 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3342 RTE_PMD_DEBUG_TRACE("Invalid tunnel type.\n");
3347 RTE_PMD_DEBUG_TRACE("Mask should have a value.\n");
3351 dev = &rte_eth_devices[port_id];
3352 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
3354 return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);