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>
62 #include <rte_mempool.h>
63 #include <rte_malloc.h>
65 #include <rte_errno.h>
66 #include <rte_spinlock.h>
67 #include <rte_string_fns.h>
69 #include "rte_ether.h"
70 #include "rte_ethdev.h"
72 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
73 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
74 static struct rte_eth_dev_data *rte_eth_dev_data;
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 /* store statistics names and its offset in stats structure */
81 struct rte_eth_xstats_name_off {
82 char name[RTE_ETH_XSTATS_NAME_SIZE];
86 static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
87 {"rx_good_packets", offsetof(struct rte_eth_stats, ipackets)},
88 {"tx_good_packets", offsetof(struct rte_eth_stats, opackets)},
89 {"rx_good_bytes", offsetof(struct rte_eth_stats, ibytes)},
90 {"tx_good_bytes", offsetof(struct rte_eth_stats, obytes)},
91 {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
92 {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
93 {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats,
97 #define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
99 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
100 {"packets", offsetof(struct rte_eth_stats, q_ipackets)},
101 {"bytes", offsetof(struct rte_eth_stats, q_ibytes)},
102 {"errors", offsetof(struct rte_eth_stats, q_errors)},
105 #define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) / \
106 sizeof(rte_rxq_stats_strings[0]))
108 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
109 {"packets", offsetof(struct rte_eth_stats, q_opackets)},
110 {"bytes", offsetof(struct rte_eth_stats, q_obytes)},
112 #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) / \
113 sizeof(rte_txq_stats_strings[0]))
117 * The user application callback description.
119 * It contains callback address to be registered by user application,
120 * the pointer to the parameters for callback, and the event type.
122 struct rte_eth_dev_callback {
123 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
124 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
125 void *cb_arg; /**< Parameter for callback */
126 enum rte_eth_event_type event; /**< Interrupt event type */
127 uint32_t active; /**< Callback is executing */
141 rte_eth_dev_data_alloc(void)
143 const unsigned flags = 0;
144 const struct rte_memzone *mz;
146 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
147 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
148 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
149 rte_socket_id(), flags);
151 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
153 rte_panic("Cannot allocate memzone for ethernet port data\n");
155 rte_eth_dev_data = mz->addr;
156 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
157 memset(rte_eth_dev_data, 0,
158 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
162 rte_eth_dev_allocated(const char *name)
166 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
167 if ((rte_eth_devices[i].attached == DEV_ATTACHED) &&
168 strcmp(rte_eth_devices[i].data->name, name) == 0)
169 return &rte_eth_devices[i];
175 rte_eth_dev_find_free_port(void)
179 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
180 if (rte_eth_devices[i].attached == DEV_DETACHED)
183 return RTE_MAX_ETHPORTS;
187 rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
190 struct rte_eth_dev *eth_dev;
192 port_id = rte_eth_dev_find_free_port();
193 if (port_id == RTE_MAX_ETHPORTS) {
194 RTE_PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
198 if (rte_eth_dev_data == NULL)
199 rte_eth_dev_data_alloc();
201 if (rte_eth_dev_allocated(name) != NULL) {
202 RTE_PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n",
207 eth_dev = &rte_eth_devices[port_id];
208 eth_dev->data = &rte_eth_dev_data[port_id];
209 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
210 eth_dev->data->port_id = port_id;
211 eth_dev->attached = DEV_ATTACHED;
212 eth_dev->dev_type = type;
218 rte_eth_dev_create_unique_device_name(char *name, size_t size,
219 struct rte_pci_device *pci_dev)
223 ret = snprintf(name, size, "%d:%d.%d",
224 pci_dev->addr.bus, pci_dev->addr.devid,
225 pci_dev->addr.function);
232 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
237 eth_dev->attached = DEV_DETACHED;
243 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
244 struct rte_pci_device *pci_dev)
246 struct eth_driver *eth_drv;
247 struct rte_eth_dev *eth_dev;
248 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
252 eth_drv = (struct eth_driver *)pci_drv;
254 /* Create unique Ethernet device name using PCI address */
255 rte_eth_dev_create_unique_device_name(ethdev_name,
256 sizeof(ethdev_name), pci_dev);
258 eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
262 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
263 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
264 eth_drv->dev_private_size,
265 RTE_CACHE_LINE_SIZE);
266 if (eth_dev->data->dev_private == NULL)
267 rte_panic("Cannot allocate memzone for private port data\n");
269 eth_dev->pci_dev = pci_dev;
270 eth_dev->driver = eth_drv;
271 eth_dev->data->rx_mbuf_alloc_failed = 0;
273 /* init user callbacks */
274 TAILQ_INIT(&(eth_dev->link_intr_cbs));
277 * Set the default MTU.
279 eth_dev->data->mtu = ETHER_MTU;
281 /* Invoke PMD device initialization function */
282 diag = (*eth_drv->eth_dev_init)(eth_dev);
286 RTE_PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x) failed\n",
288 (unsigned) pci_dev->id.vendor_id,
289 (unsigned) pci_dev->id.device_id);
290 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
291 rte_free(eth_dev->data->dev_private);
292 rte_eth_dev_release_port(eth_dev);
297 rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
299 const struct eth_driver *eth_drv;
300 struct rte_eth_dev *eth_dev;
301 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
307 /* Create unique Ethernet device name using PCI address */
308 rte_eth_dev_create_unique_device_name(ethdev_name,
309 sizeof(ethdev_name), pci_dev);
311 eth_dev = rte_eth_dev_allocated(ethdev_name);
315 eth_drv = (const struct eth_driver *)pci_dev->driver;
317 /* Invoke PMD device uninit function */
318 if (*eth_drv->eth_dev_uninit) {
319 ret = (*eth_drv->eth_dev_uninit)(eth_dev);
324 /* free ether device */
325 rte_eth_dev_release_port(eth_dev);
327 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
328 rte_free(eth_dev->data->dev_private);
330 eth_dev->pci_dev = NULL;
331 eth_dev->driver = NULL;
332 eth_dev->data = NULL;
338 * Register an Ethernet [Poll Mode] driver.
340 * Function invoked by the initialization function of an Ethernet driver
341 * to simultaneously register itself as a PCI driver and as an Ethernet
343 * Invokes the rte_eal_pci_register() function to register the *pci_drv*
344 * structure embedded in the *eth_drv* structure, after having stored the
345 * address of the rte_eth_dev_init() function in the *devinit* field of
346 * the *pci_drv* structure.
347 * During the PCI probing phase, the rte_eth_dev_init() function is
348 * invoked for each PCI [Ethernet device] matching the embedded PCI
349 * identifiers provided by the driver.
352 rte_eth_driver_register(struct eth_driver *eth_drv)
354 eth_drv->pci_drv.devinit = rte_eth_dev_init;
355 eth_drv->pci_drv.devuninit = rte_eth_dev_uninit;
356 rte_eal_pci_register(ð_drv->pci_drv);
360 rte_eth_dev_is_valid_port(uint8_t port_id)
362 if (port_id >= RTE_MAX_ETHPORTS ||
363 rte_eth_devices[port_id].attached != DEV_ATTACHED)
370 rte_eth_dev_socket_id(uint8_t port_id)
372 if (!rte_eth_dev_is_valid_port(port_id))
374 return rte_eth_devices[port_id].data->numa_node;
378 rte_eth_dev_count(void)
383 static enum rte_eth_dev_type
384 rte_eth_dev_get_device_type(uint8_t port_id)
386 if (!rte_eth_dev_is_valid_port(port_id))
387 return RTE_ETH_DEV_UNKNOWN;
388 return rte_eth_devices[port_id].dev_type;
392 rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr)
394 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
397 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
401 *addr = rte_eth_devices[port_id].pci_dev->addr;
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");
434 *port_id = RTE_MAX_ETHPORTS;
436 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
439 rte_eth_dev_data[i].name, strlen(name))) {
450 rte_eth_dev_get_port_by_addr(const struct rte_pci_addr *addr, uint8_t *port_id)
453 struct rte_pci_device *pci_dev = NULL;
456 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
460 *port_id = RTE_MAX_ETHPORTS;
462 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
464 pci_dev = rte_eth_devices[i].pci_dev;
467 !rte_eal_compare_pci_addr(&pci_dev->addr, addr)) {
478 rte_eth_dev_is_detachable(uint8_t port_id)
482 if (!rte_eth_dev_is_valid_port(port_id)) {
483 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
487 switch (rte_eth_devices[port_id].data->kdrv) {
488 case RTE_KDRV_IGB_UIO:
489 case RTE_KDRV_UIO_GENERIC:
490 case RTE_KDRV_NIC_UIO:
497 dev_flags = rte_eth_devices[port_id].data->dev_flags;
498 if ((dev_flags & RTE_ETH_DEV_DETACHABLE) &&
499 (!(dev_flags & RTE_ETH_DEV_BONDED_SLAVE)))
505 /* attach the new physical device, then store port_id of the device */
507 rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
509 /* re-construct pci_device_list */
510 if (rte_eal_pci_scan())
512 /* Invoke probe func of the driver can handle the new device. */
513 if (rte_eal_pci_probe_one(addr))
516 if (rte_eth_dev_get_port_by_addr(addr, port_id))
524 /* detach the new physical device, then store pci_addr of the device */
526 rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
528 struct rte_pci_addr freed_addr;
529 struct rte_pci_addr vp;
531 /* get pci address by port id */
532 if (rte_eth_dev_get_addr_by_port(port_id, &freed_addr))
535 /* Zeroed pci addr means the port comes from virtual device */
536 vp.domain = vp.bus = vp.devid = vp.function = 0;
537 if (rte_eal_compare_pci_addr(&vp, &freed_addr) == 0)
540 /* invoke devuninit func of the pci driver,
541 * also remove the device from pci_device_list */
542 if (rte_eal_pci_detach(&freed_addr))
551 /* attach the new virtual device, then store port_id of the device */
553 rte_eth_dev_attach_vdev(const char *vdevargs, uint8_t *port_id)
555 char *name = NULL, *args = NULL;
558 /* parse vdevargs, then retrieve device name and args */
559 if (rte_eal_parse_devargs_str(vdevargs, &name, &args))
562 /* walk around dev_driver_list to find the driver of the device,
563 * then invoke probe function of the driver.
564 * rte_eal_vdev_init() updates port_id allocated after
567 if (rte_eal_vdev_init(name, args))
570 if (rte_eth_dev_get_port_by_name(name, port_id))
581 /* detach the new virtual device, then store the name of the device */
583 rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
585 char name[RTE_ETH_NAME_MAX_LEN];
587 /* get device name by port id */
588 if (rte_eth_dev_get_name_by_port(port_id, name))
590 /* walk around dev_driver_list to find the driver of the device,
591 * then invoke uninit function of the driver */
592 if (rte_eal_vdev_uninit(name))
595 strncpy(vdevname, name, sizeof(name));
601 /* attach the new device, then store port_id of the device */
603 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
605 struct rte_pci_addr addr;
608 if ((devargs == NULL) || (port_id == NULL)) {
613 if (eal_parse_pci_DomBDF(devargs, &addr) == 0) {
614 ret = rte_eth_dev_attach_pdev(&addr, port_id);
618 ret = rte_eth_dev_attach_vdev(devargs, port_id);
625 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
629 /* detach the device, then store the name of the device */
631 rte_eth_dev_detach(uint8_t port_id, char *name)
633 struct rte_pci_addr addr;
641 /* check whether the driver supports detach feature, or not */
642 if (rte_eth_dev_is_detachable(port_id))
645 if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {
646 ret = rte_eth_dev_get_addr_by_port(port_id, &addr);
650 ret = rte_eth_dev_detach_pdev(port_id, &addr);
654 snprintf(name, RTE_ETH_NAME_MAX_LEN,
656 addr.domain, addr.bus,
657 addr.devid, addr.function);
659 ret = rte_eth_dev_detach_vdev(port_id, name);
667 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
672 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
674 uint16_t old_nb_queues = dev->data->nb_rx_queues;
678 if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */
679 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
680 sizeof(dev->data->rx_queues[0]) * nb_queues,
681 RTE_CACHE_LINE_SIZE);
682 if (dev->data->rx_queues == NULL) {
683 dev->data->nb_rx_queues = 0;
686 } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */
687 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
689 rxq = dev->data->rx_queues;
691 for (i = nb_queues; i < old_nb_queues; i++)
692 (*dev->dev_ops->rx_queue_release)(rxq[i]);
693 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
694 RTE_CACHE_LINE_SIZE);
697 if (nb_queues > old_nb_queues) {
698 uint16_t new_qs = nb_queues - old_nb_queues;
700 memset(rxq + old_nb_queues, 0,
701 sizeof(rxq[0]) * new_qs);
704 dev->data->rx_queues = rxq;
706 } else if (dev->data->rx_queues != NULL && nb_queues == 0) {
707 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
709 rxq = dev->data->rx_queues;
711 for (i = nb_queues; i < old_nb_queues; i++)
712 (*dev->dev_ops->rx_queue_release)(rxq[i]);
714 dev->data->nb_rx_queues = nb_queues;
719 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
721 struct rte_eth_dev *dev;
723 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
725 dev = &rte_eth_devices[port_id];
726 if (rx_queue_id >= dev->data->nb_rx_queues) {
727 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
731 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
733 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
734 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
735 " already started\n",
736 rx_queue_id, port_id);
740 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
745 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
747 struct rte_eth_dev *dev;
749 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
751 dev = &rte_eth_devices[port_id];
752 if (rx_queue_id >= dev->data->nb_rx_queues) {
753 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
757 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
759 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
760 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
761 " already stopped\n",
762 rx_queue_id, port_id);
766 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
771 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
773 struct rte_eth_dev *dev;
775 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
777 dev = &rte_eth_devices[port_id];
778 if (tx_queue_id >= dev->data->nb_tx_queues) {
779 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
783 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
785 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
786 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
787 " already started\n",
788 tx_queue_id, port_id);
792 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
797 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
799 struct rte_eth_dev *dev;
801 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
803 dev = &rte_eth_devices[port_id];
804 if (tx_queue_id >= dev->data->nb_tx_queues) {
805 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
809 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
811 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
812 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
813 " already stopped\n",
814 tx_queue_id, port_id);
818 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
823 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
825 uint16_t old_nb_queues = dev->data->nb_tx_queues;
829 if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */
830 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
831 sizeof(dev->data->tx_queues[0]) * nb_queues,
832 RTE_CACHE_LINE_SIZE);
833 if (dev->data->tx_queues == NULL) {
834 dev->data->nb_tx_queues = 0;
837 } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */
838 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
840 txq = dev->data->tx_queues;
842 for (i = nb_queues; i < old_nb_queues; i++)
843 (*dev->dev_ops->tx_queue_release)(txq[i]);
844 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
845 RTE_CACHE_LINE_SIZE);
848 if (nb_queues > old_nb_queues) {
849 uint16_t new_qs = nb_queues - old_nb_queues;
851 memset(txq + old_nb_queues, 0,
852 sizeof(txq[0]) * new_qs);
855 dev->data->tx_queues = txq;
857 } else if (dev->data->tx_queues != NULL && nb_queues == 0) {
858 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
860 txq = dev->data->tx_queues;
862 for (i = nb_queues; i < old_nb_queues; i++)
863 (*dev->dev_ops->tx_queue_release)(txq[i]);
865 dev->data->nb_tx_queues = nb_queues;
870 rte_eth_speed_bitflag(uint32_t speed, int duplex)
873 case ETH_SPEED_NUM_10M:
874 return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD;
875 case ETH_SPEED_NUM_100M:
876 return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD;
877 case ETH_SPEED_NUM_1G:
878 return ETH_LINK_SPEED_1G;
879 case ETH_SPEED_NUM_2_5G:
880 return ETH_LINK_SPEED_2_5G;
881 case ETH_SPEED_NUM_5G:
882 return ETH_LINK_SPEED_5G;
883 case ETH_SPEED_NUM_10G:
884 return ETH_LINK_SPEED_10G;
885 case ETH_SPEED_NUM_20G:
886 return ETH_LINK_SPEED_20G;
887 case ETH_SPEED_NUM_25G:
888 return ETH_LINK_SPEED_25G;
889 case ETH_SPEED_NUM_40G:
890 return ETH_LINK_SPEED_40G;
891 case ETH_SPEED_NUM_50G:
892 return ETH_LINK_SPEED_50G;
893 case ETH_SPEED_NUM_56G:
894 return ETH_LINK_SPEED_56G;
895 case ETH_SPEED_NUM_100G:
896 return ETH_LINK_SPEED_100G;
903 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
904 const struct rte_eth_conf *dev_conf)
906 struct rte_eth_dev *dev;
907 struct rte_eth_dev_info dev_info;
910 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
912 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
914 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
915 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
919 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
921 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
922 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
926 dev = &rte_eth_devices[port_id];
928 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
929 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
931 if (dev->data->dev_started) {
933 "port %d must be stopped to allow configuration\n", port_id);
937 /* Copy the dev_conf parameter into the dev structure */
938 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
941 * Check that the numbers of RX and TX queues are not greater
942 * than the maximum number of RX and TX queues supported by the
945 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
947 if (nb_rx_q == 0 && nb_tx_q == 0) {
948 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d both rx and tx queue cannot be 0\n", port_id);
952 if (nb_rx_q > dev_info.max_rx_queues) {
953 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
954 port_id, nb_rx_q, dev_info.max_rx_queues);
958 if (nb_tx_q > dev_info.max_tx_queues) {
959 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
960 port_id, nb_tx_q, dev_info.max_tx_queues);
965 * If link state interrupt is enabled, check that the
966 * device supports it.
968 if ((dev_conf->intr_conf.lsc == 1) &&
969 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
970 RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
971 dev->data->drv_name);
976 * If jumbo frames are enabled, check that the maximum RX packet
977 * length is supported by the configured device.
979 if (dev_conf->rxmode.jumbo_frame == 1) {
980 if (dev_conf->rxmode.max_rx_pkt_len >
981 dev_info.max_rx_pktlen) {
982 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
983 " > max valid value %u\n",
985 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
986 (unsigned)dev_info.max_rx_pktlen);
988 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
989 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
990 " < min valid value %u\n",
992 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
993 (unsigned)ETHER_MIN_LEN);
997 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
998 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
999 /* Use default value */
1000 dev->data->dev_conf.rxmode.max_rx_pkt_len =
1005 * Setup new number of RX/TX queues and reconfigure device.
1007 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
1009 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
1014 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
1016 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
1018 rte_eth_dev_rx_queue_config(dev, 0);
1022 diag = (*dev->dev_ops->dev_configure)(dev);
1024 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
1026 rte_eth_dev_rx_queue_config(dev, 0);
1027 rte_eth_dev_tx_queue_config(dev, 0);
1035 rte_eth_dev_config_restore(uint8_t port_id)
1037 struct rte_eth_dev *dev;
1038 struct rte_eth_dev_info dev_info;
1039 struct ether_addr addr;
1043 dev = &rte_eth_devices[port_id];
1045 rte_eth_dev_info_get(port_id, &dev_info);
1047 if (RTE_ETH_DEV_SRIOV(dev).active)
1048 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
1050 /* replay MAC address configuration */
1051 for (i = 0; i < dev_info.max_mac_addrs; i++) {
1052 addr = dev->data->mac_addrs[i];
1054 /* skip zero address */
1055 if (is_zero_ether_addr(&addr))
1058 /* add address to the hardware */
1059 if (*dev->dev_ops->mac_addr_add &&
1060 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
1061 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
1063 RTE_PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
1065 /* exit the loop but not return an error */
1070 /* replay promiscuous configuration */
1071 if (rte_eth_promiscuous_get(port_id) == 1)
1072 rte_eth_promiscuous_enable(port_id);
1073 else if (rte_eth_promiscuous_get(port_id) == 0)
1074 rte_eth_promiscuous_disable(port_id);
1076 /* replay all multicast configuration */
1077 if (rte_eth_allmulticast_get(port_id) == 1)
1078 rte_eth_allmulticast_enable(port_id);
1079 else if (rte_eth_allmulticast_get(port_id) == 0)
1080 rte_eth_allmulticast_disable(port_id);
1084 rte_eth_dev_start(uint8_t port_id)
1086 struct rte_eth_dev *dev;
1089 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1091 dev = &rte_eth_devices[port_id];
1093 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1095 if (dev->data->dev_started != 0) {
1096 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1097 " already started\n",
1102 diag = (*dev->dev_ops->dev_start)(dev);
1104 dev->data->dev_started = 1;
1108 rte_eth_dev_config_restore(port_id);
1110 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1111 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1112 (*dev->dev_ops->link_update)(dev, 0);
1118 rte_eth_dev_stop(uint8_t port_id)
1120 struct rte_eth_dev *dev;
1122 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1123 dev = &rte_eth_devices[port_id];
1125 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1127 if (dev->data->dev_started == 0) {
1128 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1129 " already stopped\n",
1134 dev->data->dev_started = 0;
1135 (*dev->dev_ops->dev_stop)(dev);
1139 rte_eth_dev_set_link_up(uint8_t port_id)
1141 struct rte_eth_dev *dev;
1143 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1145 dev = &rte_eth_devices[port_id];
1147 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1148 return (*dev->dev_ops->dev_set_link_up)(dev);
1152 rte_eth_dev_set_link_down(uint8_t port_id)
1154 struct rte_eth_dev *dev;
1156 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1158 dev = &rte_eth_devices[port_id];
1160 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1161 return (*dev->dev_ops->dev_set_link_down)(dev);
1165 rte_eth_dev_close(uint8_t port_id)
1167 struct rte_eth_dev *dev;
1169 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1170 dev = &rte_eth_devices[port_id];
1172 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1173 dev->data->dev_started = 0;
1174 (*dev->dev_ops->dev_close)(dev);
1176 rte_free(dev->data->rx_queues);
1177 dev->data->rx_queues = NULL;
1178 rte_free(dev->data->tx_queues);
1179 dev->data->tx_queues = NULL;
1183 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1184 uint16_t nb_rx_desc, unsigned int socket_id,
1185 const struct rte_eth_rxconf *rx_conf,
1186 struct rte_mempool *mp)
1189 uint32_t mbp_buf_size;
1190 struct rte_eth_dev *dev;
1191 struct rte_eth_dev_info dev_info;
1193 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1195 dev = &rte_eth_devices[port_id];
1196 if (rx_queue_id >= dev->data->nb_rx_queues) {
1197 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1201 if (dev->data->dev_started) {
1202 RTE_PMD_DEBUG_TRACE(
1203 "port %d must be stopped to allow configuration\n", port_id);
1207 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1208 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1211 * Check the size of the mbuf data buffer.
1212 * This value must be provided in the private data of the memory pool.
1213 * First check that the memory pool has a valid private data.
1215 rte_eth_dev_info_get(port_id, &dev_info);
1216 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1217 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1218 mp->name, (int) mp->private_data_size,
1219 (int) sizeof(struct rte_pktmbuf_pool_private));
1222 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1224 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1225 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1226 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1230 (int)(RTE_PKTMBUF_HEADROOM +
1231 dev_info.min_rx_bufsize),
1232 (int)RTE_PKTMBUF_HEADROOM,
1233 (int)dev_info.min_rx_bufsize);
1237 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1238 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1239 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1241 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1242 "should be: <= %hu, = %hu, and a product of %hu\n",
1244 dev_info.rx_desc_lim.nb_max,
1245 dev_info.rx_desc_lim.nb_min,
1246 dev_info.rx_desc_lim.nb_align);
1250 if (rx_conf == NULL)
1251 rx_conf = &dev_info.default_rxconf;
1253 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1254 socket_id, rx_conf, mp);
1256 if (!dev->data->min_rx_buf_size ||
1257 dev->data->min_rx_buf_size > mbp_buf_size)
1258 dev->data->min_rx_buf_size = mbp_buf_size;
1265 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1266 uint16_t nb_tx_desc, unsigned int socket_id,
1267 const struct rte_eth_txconf *tx_conf)
1269 struct rte_eth_dev *dev;
1270 struct rte_eth_dev_info dev_info;
1272 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1274 dev = &rte_eth_devices[port_id];
1275 if (tx_queue_id >= dev->data->nb_tx_queues) {
1276 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1280 if (dev->data->dev_started) {
1281 RTE_PMD_DEBUG_TRACE(
1282 "port %d must be stopped to allow configuration\n", port_id);
1286 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1287 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1289 rte_eth_dev_info_get(port_id, &dev_info);
1291 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1292 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1293 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1294 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1295 "should be: <= %hu, = %hu, and a product of %hu\n",
1297 dev_info.tx_desc_lim.nb_max,
1298 dev_info.tx_desc_lim.nb_min,
1299 dev_info.tx_desc_lim.nb_align);
1303 if (tx_conf == NULL)
1304 tx_conf = &dev_info.default_txconf;
1306 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1307 socket_id, tx_conf);
1311 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
1312 void *userdata __rte_unused)
1316 for (i = 0; i < unsent; i++)
1317 rte_pktmbuf_free(pkts[i]);
1321 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
1324 uint64_t *count = userdata;
1327 for (i = 0; i < unsent; i++)
1328 rte_pktmbuf_free(pkts[i]);
1334 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
1335 buffer_tx_error_fn cbfn, void *userdata)
1337 buffer->error_callback = cbfn;
1338 buffer->error_userdata = userdata;
1343 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
1350 buffer->size = size;
1351 if (buffer->error_callback == NULL) {
1352 ret = rte_eth_tx_buffer_set_err_callback(
1353 buffer, rte_eth_tx_buffer_drop_callback, NULL);
1360 rte_eth_promiscuous_enable(uint8_t port_id)
1362 struct rte_eth_dev *dev;
1364 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1365 dev = &rte_eth_devices[port_id];
1367 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1368 (*dev->dev_ops->promiscuous_enable)(dev);
1369 dev->data->promiscuous = 1;
1373 rte_eth_promiscuous_disable(uint8_t port_id)
1375 struct rte_eth_dev *dev;
1377 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1378 dev = &rte_eth_devices[port_id];
1380 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1381 dev->data->promiscuous = 0;
1382 (*dev->dev_ops->promiscuous_disable)(dev);
1386 rte_eth_promiscuous_get(uint8_t port_id)
1388 struct rte_eth_dev *dev;
1390 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1392 dev = &rte_eth_devices[port_id];
1393 return dev->data->promiscuous;
1397 rte_eth_allmulticast_enable(uint8_t port_id)
1399 struct rte_eth_dev *dev;
1401 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1402 dev = &rte_eth_devices[port_id];
1404 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1405 (*dev->dev_ops->allmulticast_enable)(dev);
1406 dev->data->all_multicast = 1;
1410 rte_eth_allmulticast_disable(uint8_t port_id)
1412 struct rte_eth_dev *dev;
1414 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1415 dev = &rte_eth_devices[port_id];
1417 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1418 dev->data->all_multicast = 0;
1419 (*dev->dev_ops->allmulticast_disable)(dev);
1423 rte_eth_allmulticast_get(uint8_t port_id)
1425 struct rte_eth_dev *dev;
1427 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1429 dev = &rte_eth_devices[port_id];
1430 return dev->data->all_multicast;
1434 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1435 struct rte_eth_link *link)
1437 struct rte_eth_link *dst = link;
1438 struct rte_eth_link *src = &(dev->data->dev_link);
1440 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1441 *(uint64_t *)src) == 0)
1448 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1450 struct rte_eth_dev *dev;
1452 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1453 dev = &rte_eth_devices[port_id];
1455 if (dev->data->dev_conf.intr_conf.lsc != 0)
1456 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1458 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1459 (*dev->dev_ops->link_update)(dev, 1);
1460 *eth_link = dev->data->dev_link;
1465 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1467 struct rte_eth_dev *dev;
1469 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1470 dev = &rte_eth_devices[port_id];
1472 if (dev->data->dev_conf.intr_conf.lsc != 0)
1473 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1475 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1476 (*dev->dev_ops->link_update)(dev, 0);
1477 *eth_link = dev->data->dev_link;
1482 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1484 struct rte_eth_dev *dev;
1486 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1488 dev = &rte_eth_devices[port_id];
1489 memset(stats, 0, sizeof(*stats));
1491 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1492 (*dev->dev_ops->stats_get)(dev, stats);
1493 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1498 rte_eth_stats_reset(uint8_t port_id)
1500 struct rte_eth_dev *dev;
1502 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1503 dev = &rte_eth_devices[port_id];
1505 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1506 (*dev->dev_ops->stats_reset)(dev);
1507 dev->data->rx_mbuf_alloc_failed = 0;
1510 /* retrieve ethdev extended statistics */
1512 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1515 struct rte_eth_stats eth_stats;
1516 struct rte_eth_dev *dev;
1517 unsigned count = 0, i, q;
1519 uint64_t val, *stats_ptr;
1521 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1523 dev = &rte_eth_devices[port_id];
1525 /* Return generic statistics */
1526 count = RTE_NB_STATS + (dev->data->nb_rx_queues * RTE_NB_RXQ_STATS) +
1527 (dev->data->nb_tx_queues * RTE_NB_TXQ_STATS);
1529 /* implemented by the driver */
1530 if (dev->dev_ops->xstats_get != NULL) {
1531 /* Retrieve the xstats from the driver at the end of the
1534 xcount = (*dev->dev_ops->xstats_get)(dev,
1535 xstats ? xstats + count : NULL,
1536 (n > count) ? n - count : 0);
1542 if (n < count + xcount || xstats == NULL)
1543 return count + xcount;
1545 /* now fill the xstats structure */
1547 rte_eth_stats_get(port_id, ð_stats);
1550 for (i = 0; i < RTE_NB_STATS; i++) {
1551 stats_ptr = RTE_PTR_ADD(ð_stats,
1552 rte_stats_strings[i].offset);
1554 snprintf(xstats[count].name, sizeof(xstats[count].name),
1555 "%s", rte_stats_strings[i].name);
1556 xstats[count++].value = val;
1560 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1561 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1562 stats_ptr = RTE_PTR_ADD(ð_stats,
1563 rte_rxq_stats_strings[i].offset +
1564 q * sizeof(uint64_t));
1566 snprintf(xstats[count].name, sizeof(xstats[count].name),
1568 rte_rxq_stats_strings[i].name);
1569 xstats[count++].value = val;
1574 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1575 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1576 stats_ptr = RTE_PTR_ADD(ð_stats,
1577 rte_txq_stats_strings[i].offset +
1578 q * sizeof(uint64_t));
1580 snprintf(xstats[count].name, sizeof(xstats[count].name),
1582 rte_txq_stats_strings[i].name);
1583 xstats[count++].value = val;
1587 return count + xcount;
1590 /* reset ethdev extended statistics */
1592 rte_eth_xstats_reset(uint8_t port_id)
1594 struct rte_eth_dev *dev;
1596 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1597 dev = &rte_eth_devices[port_id];
1599 /* implemented by the driver */
1600 if (dev->dev_ops->xstats_reset != NULL) {
1601 (*dev->dev_ops->xstats_reset)(dev);
1605 /* fallback to default */
1606 rte_eth_stats_reset(port_id);
1610 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1613 struct rte_eth_dev *dev;
1615 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1617 dev = &rte_eth_devices[port_id];
1619 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1620 return (*dev->dev_ops->queue_stats_mapping_set)
1621 (dev, queue_id, stat_idx, is_rx);
1626 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1629 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1635 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1638 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1644 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1646 struct rte_eth_dev *dev;
1647 const struct rte_eth_desc_lim lim = {
1648 .nb_max = UINT16_MAX,
1653 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1654 dev = &rte_eth_devices[port_id];
1656 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1657 dev_info->rx_desc_lim = lim;
1658 dev_info->tx_desc_lim = lim;
1660 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1661 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1662 dev_info->pci_dev = dev->pci_dev;
1663 dev_info->driver_name = dev->data->drv_name;
1667 rte_eth_dev_get_supported_ptypes(uint8_t port_id, uint32_t ptype_mask,
1668 uint32_t *ptypes, int num)
1671 struct rte_eth_dev *dev;
1672 const uint32_t *all_ptypes;
1674 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1675 dev = &rte_eth_devices[port_id];
1676 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
1677 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
1682 for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
1683 if (all_ptypes[i] & ptype_mask) {
1685 ptypes[j] = all_ptypes[i];
1693 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1695 struct rte_eth_dev *dev;
1697 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1698 dev = &rte_eth_devices[port_id];
1699 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1704 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1706 struct rte_eth_dev *dev;
1708 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1710 dev = &rte_eth_devices[port_id];
1711 *mtu = dev->data->mtu;
1716 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1719 struct rte_eth_dev *dev;
1721 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1722 dev = &rte_eth_devices[port_id];
1723 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1725 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1727 dev->data->mtu = mtu;
1733 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1735 struct rte_eth_dev *dev;
1737 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1738 dev = &rte_eth_devices[port_id];
1739 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1740 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1744 if (vlan_id > 4095) {
1745 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1746 port_id, (unsigned) vlan_id);
1749 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1751 return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1755 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1757 struct rte_eth_dev *dev;
1759 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1760 dev = &rte_eth_devices[port_id];
1761 if (rx_queue_id >= dev->data->nb_rx_queues) {
1762 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1766 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1767 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1773 rte_eth_dev_set_vlan_ether_type(uint8_t port_id,
1774 enum rte_vlan_type vlan_type,
1777 struct rte_eth_dev *dev;
1779 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1780 dev = &rte_eth_devices[port_id];
1781 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1783 return (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type, tpid);
1787 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1789 struct rte_eth_dev *dev;
1794 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1795 dev = &rte_eth_devices[port_id];
1797 /*check which option changed by application*/
1798 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1799 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1801 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1802 mask |= ETH_VLAN_STRIP_MASK;
1805 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1806 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1808 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1809 mask |= ETH_VLAN_FILTER_MASK;
1812 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1813 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1815 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1816 mask |= ETH_VLAN_EXTEND_MASK;
1823 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1824 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1830 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1832 struct rte_eth_dev *dev;
1835 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1836 dev = &rte_eth_devices[port_id];
1838 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1839 ret |= ETH_VLAN_STRIP_OFFLOAD;
1841 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1842 ret |= ETH_VLAN_FILTER_OFFLOAD;
1844 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1845 ret |= ETH_VLAN_EXTEND_OFFLOAD;
1851 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1853 struct rte_eth_dev *dev;
1855 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1856 dev = &rte_eth_devices[port_id];
1857 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1858 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1864 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1866 struct rte_eth_dev *dev;
1868 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1869 dev = &rte_eth_devices[port_id];
1870 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1871 memset(fc_conf, 0, sizeof(*fc_conf));
1872 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1876 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1878 struct rte_eth_dev *dev;
1880 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1881 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1882 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1886 dev = &rte_eth_devices[port_id];
1887 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1888 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1892 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1894 struct rte_eth_dev *dev;
1896 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1897 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1898 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1902 dev = &rte_eth_devices[port_id];
1903 /* High water, low water validation are device specific */
1904 if (*dev->dev_ops->priority_flow_ctrl_set)
1905 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1910 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
1918 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
1919 RTE_PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
1920 RTE_RETA_GROUP_SIZE);
1924 num = reta_size / RTE_RETA_GROUP_SIZE;
1925 for (i = 0; i < num; i++) {
1926 if (reta_conf[i].mask)
1934 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
1938 uint16_t i, idx, shift;
1944 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
1948 for (i = 0; i < reta_size; i++) {
1949 idx = i / RTE_RETA_GROUP_SIZE;
1950 shift = i % RTE_RETA_GROUP_SIZE;
1951 if ((reta_conf[idx].mask & (1ULL << shift)) &&
1952 (reta_conf[idx].reta[shift] >= max_rxq)) {
1953 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
1954 "the maximum rxq index: %u\n", idx, shift,
1955 reta_conf[idx].reta[shift], max_rxq);
1964 rte_eth_dev_rss_reta_update(uint8_t port_id,
1965 struct rte_eth_rss_reta_entry64 *reta_conf,
1968 struct rte_eth_dev *dev;
1971 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1972 /* Check mask bits */
1973 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
1977 dev = &rte_eth_devices[port_id];
1979 /* Check entry value */
1980 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
1981 dev->data->nb_rx_queues);
1985 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
1986 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
1990 rte_eth_dev_rss_reta_query(uint8_t port_id,
1991 struct rte_eth_rss_reta_entry64 *reta_conf,
1994 struct rte_eth_dev *dev;
1997 if (port_id >= nb_ports) {
1998 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2002 /* Check mask bits */
2003 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2007 dev = &rte_eth_devices[port_id];
2008 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2009 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2013 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2015 struct rte_eth_dev *dev;
2016 uint16_t rss_hash_protos;
2018 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2019 rss_hash_protos = rss_conf->rss_hf;
2020 if ((rss_hash_protos != 0) &&
2021 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2022 RTE_PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2026 dev = &rte_eth_devices[port_id];
2027 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2028 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2032 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2033 struct rte_eth_rss_conf *rss_conf)
2035 struct rte_eth_dev *dev;
2037 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2038 dev = &rte_eth_devices[port_id];
2039 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2040 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2044 rte_eth_dev_udp_tunnel_port_add(uint8_t port_id,
2045 struct rte_eth_udp_tunnel *udp_tunnel)
2047 struct rte_eth_dev *dev;
2049 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2050 if (udp_tunnel == NULL) {
2051 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2055 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2056 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2060 dev = &rte_eth_devices[port_id];
2061 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
2062 return (*dev->dev_ops->udp_tunnel_port_add)(dev, udp_tunnel);
2066 rte_eth_dev_udp_tunnel_port_delete(uint8_t port_id,
2067 struct rte_eth_udp_tunnel *udp_tunnel)
2069 struct rte_eth_dev *dev;
2071 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2072 dev = &rte_eth_devices[port_id];
2074 if (udp_tunnel == NULL) {
2075 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2079 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2080 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2084 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
2085 return (*dev->dev_ops->udp_tunnel_port_del)(dev, udp_tunnel);
2089 rte_eth_led_on(uint8_t port_id)
2091 struct rte_eth_dev *dev;
2093 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2094 dev = &rte_eth_devices[port_id];
2095 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2096 return (*dev->dev_ops->dev_led_on)(dev);
2100 rte_eth_led_off(uint8_t port_id)
2102 struct rte_eth_dev *dev;
2104 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2105 dev = &rte_eth_devices[port_id];
2106 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2107 return (*dev->dev_ops->dev_led_off)(dev);
2111 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2115 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2117 struct rte_eth_dev_info dev_info;
2118 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2121 rte_eth_dev_info_get(port_id, &dev_info);
2123 for (i = 0; i < dev_info.max_mac_addrs; i++)
2124 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2130 static const struct ether_addr null_mac_addr;
2133 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2136 struct rte_eth_dev *dev;
2140 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2141 dev = &rte_eth_devices[port_id];
2142 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2144 if (is_zero_ether_addr(addr)) {
2145 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2149 if (pool >= ETH_64_POOLS) {
2150 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2154 index = get_mac_addr_index(port_id, addr);
2156 index = get_mac_addr_index(port_id, &null_mac_addr);
2158 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2163 pool_mask = dev->data->mac_pool_sel[index];
2165 /* Check if both MAC address and pool is already there, and do nothing */
2166 if (pool_mask & (1ULL << pool))
2171 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2173 /* Update address in NIC data structure */
2174 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2176 /* Update pool bitmap in NIC data structure */
2177 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2183 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2185 struct rte_eth_dev *dev;
2188 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2189 dev = &rte_eth_devices[port_id];
2190 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2192 index = get_mac_addr_index(port_id, addr);
2194 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2196 } else if (index < 0)
2197 return 0; /* Do nothing if address wasn't found */
2200 (*dev->dev_ops->mac_addr_remove)(dev, index);
2202 /* Update address in NIC data structure */
2203 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2205 /* reset pool bitmap */
2206 dev->data->mac_pool_sel[index] = 0;
2212 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2214 struct rte_eth_dev *dev;
2216 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2218 if (!is_valid_assigned_ether_addr(addr))
2221 dev = &rte_eth_devices[port_id];
2222 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2224 /* Update default address in NIC data structure */
2225 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2227 (*dev->dev_ops->mac_addr_set)(dev, addr);
2233 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2234 uint16_t rx_mode, uint8_t on)
2237 struct rte_eth_dev *dev;
2238 struct rte_eth_dev_info dev_info;
2240 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2242 dev = &rte_eth_devices[port_id];
2243 rte_eth_dev_info_get(port_id, &dev_info);
2245 num_vfs = dev_info.max_vfs;
2247 RTE_PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2252 RTE_PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2255 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2256 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2260 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2264 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2266 struct rte_eth_dev_info dev_info;
2267 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2270 rte_eth_dev_info_get(port_id, &dev_info);
2271 if (!dev->data->hash_mac_addrs)
2274 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2275 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2276 ETHER_ADDR_LEN) == 0)
2283 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2288 struct rte_eth_dev *dev;
2290 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2292 dev = &rte_eth_devices[port_id];
2293 if (is_zero_ether_addr(addr)) {
2294 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2299 index = get_hash_mac_addr_index(port_id, addr);
2300 /* Check if it's already there, and do nothing */
2301 if ((index >= 0) && (on))
2306 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2307 "set in UTA\n", port_id);
2311 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2313 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2319 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2320 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2322 /* Update address in NIC data structure */
2324 ether_addr_copy(addr,
2325 &dev->data->hash_mac_addrs[index]);
2327 ether_addr_copy(&null_mac_addr,
2328 &dev->data->hash_mac_addrs[index]);
2335 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2337 struct rte_eth_dev *dev;
2339 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2341 dev = &rte_eth_devices[port_id];
2343 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2344 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2348 rte_eth_dev_set_vf_rx(uint8_t port_id, uint16_t vf, uint8_t on)
2351 struct rte_eth_dev *dev;
2352 struct rte_eth_dev_info dev_info;
2354 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2356 dev = &rte_eth_devices[port_id];
2357 rte_eth_dev_info_get(port_id, &dev_info);
2359 num_vfs = dev_info.max_vfs;
2361 RTE_PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2365 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2366 return (*dev->dev_ops->set_vf_rx)(dev, vf, on);
2370 rte_eth_dev_set_vf_tx(uint8_t port_id, uint16_t vf, uint8_t on)
2373 struct rte_eth_dev *dev;
2374 struct rte_eth_dev_info dev_info;
2376 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2378 dev = &rte_eth_devices[port_id];
2379 rte_eth_dev_info_get(port_id, &dev_info);
2381 num_vfs = dev_info.max_vfs;
2383 RTE_PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2387 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2388 return (*dev->dev_ops->set_vf_tx)(dev, vf, on);
2392 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2393 uint64_t vf_mask, uint8_t vlan_on)
2395 struct rte_eth_dev *dev;
2397 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2399 dev = &rte_eth_devices[port_id];
2401 if (vlan_id > ETHER_MAX_VLAN_ID) {
2402 RTE_PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2408 RTE_PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2412 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2413 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2417 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2420 struct rte_eth_dev *dev;
2421 struct rte_eth_dev_info dev_info;
2422 struct rte_eth_link link;
2424 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2426 dev = &rte_eth_devices[port_id];
2427 rte_eth_dev_info_get(port_id, &dev_info);
2428 link = dev->data->dev_link;
2430 if (queue_idx > dev_info.max_tx_queues) {
2431 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2432 "invalid queue id=%d\n", port_id, queue_idx);
2436 if (tx_rate > link.link_speed) {
2437 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2438 "bigger than link speed= %d\n",
2439 tx_rate, link.link_speed);
2443 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2444 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2447 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2450 struct rte_eth_dev *dev;
2451 struct rte_eth_dev_info dev_info;
2452 struct rte_eth_link link;
2457 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2459 dev = &rte_eth_devices[port_id];
2460 rte_eth_dev_info_get(port_id, &dev_info);
2461 link = dev->data->dev_link;
2463 if (vf > dev_info.max_vfs) {
2464 RTE_PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2465 "invalid vf id=%d\n", port_id, vf);
2469 if (tx_rate > link.link_speed) {
2470 RTE_PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2471 "bigger than link speed= %d\n",
2472 tx_rate, link.link_speed);
2476 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2477 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2481 rte_eth_mirror_rule_set(uint8_t port_id,
2482 struct rte_eth_mirror_conf *mirror_conf,
2483 uint8_t rule_id, uint8_t on)
2485 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2487 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2488 if (mirror_conf->rule_type == 0) {
2489 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2493 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2494 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2499 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2500 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2501 (mirror_conf->pool_mask == 0)) {
2502 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2506 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2507 mirror_conf->vlan.vlan_mask == 0) {
2508 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2512 dev = &rte_eth_devices[port_id];
2513 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2515 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2519 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2521 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2523 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2525 dev = &rte_eth_devices[port_id];
2526 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2528 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2532 rte_eth_dev_callback_register(uint8_t port_id,
2533 enum rte_eth_event_type event,
2534 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2536 struct rte_eth_dev *dev;
2537 struct rte_eth_dev_callback *user_cb;
2542 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2544 dev = &rte_eth_devices[port_id];
2545 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2547 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2548 if (user_cb->cb_fn == cb_fn &&
2549 user_cb->cb_arg == cb_arg &&
2550 user_cb->event == event) {
2555 /* create a new callback. */
2556 if (user_cb == NULL)
2557 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2558 sizeof(struct rte_eth_dev_callback), 0);
2559 if (user_cb != NULL) {
2560 user_cb->cb_fn = cb_fn;
2561 user_cb->cb_arg = cb_arg;
2562 user_cb->event = event;
2563 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2566 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2567 return (user_cb == NULL) ? -ENOMEM : 0;
2571 rte_eth_dev_callback_unregister(uint8_t port_id,
2572 enum rte_eth_event_type event,
2573 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2576 struct rte_eth_dev *dev;
2577 struct rte_eth_dev_callback *cb, *next;
2582 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2584 dev = &rte_eth_devices[port_id];
2585 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2588 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2590 next = TAILQ_NEXT(cb, next);
2592 if (cb->cb_fn != cb_fn || cb->event != event ||
2593 (cb->cb_arg != (void *)-1 &&
2594 cb->cb_arg != cb_arg))
2598 * if this callback is not executing right now,
2601 if (cb->active == 0) {
2602 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2609 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2614 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2615 enum rte_eth_event_type event)
2617 struct rte_eth_dev_callback *cb_lst;
2618 struct rte_eth_dev_callback dev_cb;
2620 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2621 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2622 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2626 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2627 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2629 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2632 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2636 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
2639 struct rte_eth_dev *dev;
2640 struct rte_intr_handle *intr_handle;
2644 if (!rte_eth_dev_is_valid_port(port_id)) {
2645 RTE_PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
2649 dev = &rte_eth_devices[port_id];
2650 intr_handle = &dev->pci_dev->intr_handle;
2651 if (!intr_handle->intr_vec) {
2652 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2656 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2657 vec = intr_handle->intr_vec[qid];
2658 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2659 if (rc && rc != -EEXIST) {
2660 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2661 " op %d epfd %d vec %u\n",
2662 port_id, qid, op, epfd, vec);
2669 const struct rte_memzone *
2670 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2671 uint16_t queue_id, size_t size, unsigned align,
2674 char z_name[RTE_MEMZONE_NAMESIZE];
2675 const struct rte_memzone *mz;
2677 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2678 dev->driver->pci_drv.name, ring_name,
2679 dev->data->port_id, queue_id);
2681 mz = rte_memzone_lookup(z_name);
2685 if (rte_xen_dom0_supported())
2686 return rte_memzone_reserve_bounded(z_name, size, socket_id,
2687 0, align, RTE_PGSIZE_2M);
2689 return rte_memzone_reserve_aligned(z_name, size, socket_id,
2694 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
2695 int epfd, int op, void *data)
2698 struct rte_eth_dev *dev;
2699 struct rte_intr_handle *intr_handle;
2702 if (!rte_eth_dev_is_valid_port(port_id)) {
2703 RTE_PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
2707 dev = &rte_eth_devices[port_id];
2708 if (queue_id >= dev->data->nb_rx_queues) {
2709 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
2713 intr_handle = &dev->pci_dev->intr_handle;
2714 if (!intr_handle->intr_vec) {
2715 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2719 vec = intr_handle->intr_vec[queue_id];
2720 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2721 if (rc && rc != -EEXIST) {
2722 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2723 " op %d epfd %d vec %u\n",
2724 port_id, queue_id, op, epfd, vec);
2732 rte_eth_dev_rx_intr_enable(uint8_t port_id,
2735 struct rte_eth_dev *dev;
2737 if (!rte_eth_dev_is_valid_port(port_id)) {
2738 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2742 dev = &rte_eth_devices[port_id];
2744 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
2745 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
2749 rte_eth_dev_rx_intr_disable(uint8_t port_id,
2752 struct rte_eth_dev *dev;
2754 if (!rte_eth_dev_is_valid_port(port_id)) {
2755 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2759 dev = &rte_eth_devices[port_id];
2761 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
2762 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
2765 #ifdef RTE_NIC_BYPASS
2766 int rte_eth_dev_bypass_init(uint8_t port_id)
2768 struct rte_eth_dev *dev;
2770 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2772 dev = &rte_eth_devices[port_id];
2773 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2774 (*dev->dev_ops->bypass_init)(dev);
2779 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2781 struct rte_eth_dev *dev;
2783 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2785 dev = &rte_eth_devices[port_id];
2786 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2787 (*dev->dev_ops->bypass_state_show)(dev, state);
2792 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2794 struct rte_eth_dev *dev;
2796 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2798 dev = &rte_eth_devices[port_id];
2799 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2800 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2805 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2807 struct rte_eth_dev *dev;
2809 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2811 dev = &rte_eth_devices[port_id];
2812 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2813 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2818 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2820 struct rte_eth_dev *dev;
2822 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2824 dev = &rte_eth_devices[port_id];
2826 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2827 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2832 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2834 struct rte_eth_dev *dev;
2836 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2838 dev = &rte_eth_devices[port_id];
2840 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2841 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2846 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2848 struct rte_eth_dev *dev;
2850 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2852 dev = &rte_eth_devices[port_id];
2854 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2855 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2860 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2862 struct rte_eth_dev *dev;
2864 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2866 dev = &rte_eth_devices[port_id];
2868 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2869 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2874 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2876 struct rte_eth_dev *dev;
2878 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2880 dev = &rte_eth_devices[port_id];
2882 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2883 (*dev->dev_ops->bypass_wd_reset)(dev);
2889 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
2891 struct rte_eth_dev *dev;
2893 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2895 dev = &rte_eth_devices[port_id];
2896 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2897 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
2898 RTE_ETH_FILTER_NOP, NULL);
2902 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
2903 enum rte_filter_op filter_op, void *arg)
2905 struct rte_eth_dev *dev;
2907 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2909 dev = &rte_eth_devices[port_id];
2910 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2911 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
2915 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
2916 rte_rx_callback_fn fn, void *user_param)
2918 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2919 rte_errno = ENOTSUP;
2922 /* check input parameters */
2923 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2924 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2929 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2937 cb->param = user_param;
2939 /* Add the callbacks in fifo order. */
2940 struct rte_eth_rxtx_callback *tail =
2941 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2944 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2956 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
2957 rte_tx_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_tx_queues) {
2970 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2978 cb->param = user_param;
2980 /* Add the callbacks in fifo order. */
2981 struct rte_eth_rxtx_callback *tail =
2982 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
2985 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
2997 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
2998 struct rte_eth_rxtx_callback *user_cb)
3000 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3003 /* Check input parameters. */
3004 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
3005 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3009 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3010 struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
3011 struct rte_eth_rxtx_callback *prev_cb;
3013 /* Reset head pointer and remove user cb if first in the list. */
3014 if (cb == user_cb) {
3015 dev->post_rx_burst_cbs[queue_id] = user_cb->next;
3019 /* Remove the user cb from the callback list. */
3024 if (cb == user_cb) {
3025 prev_cb->next = user_cb->next;
3029 } while (cb != NULL);
3031 /* Callback wasn't found. */
3036 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3037 struct rte_eth_rxtx_callback *user_cb)
3039 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3042 /* Check input parameters. */
3043 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
3044 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3048 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3049 struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
3050 struct rte_eth_rxtx_callback *prev_cb;
3052 /* Reset head pointer and remove user cb if first in the list. */
3053 if (cb == user_cb) {
3054 dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
3058 /* Remove the user cb from the callback list. */
3063 if (cb == user_cb) {
3064 prev_cb->next = user_cb->next;
3068 } while (cb != NULL);
3070 /* Callback wasn't found. */
3075 rte_eth_rx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3076 struct rte_eth_rxq_info *qinfo)
3078 struct rte_eth_dev *dev;
3080 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3085 dev = &rte_eth_devices[port_id];
3086 if (queue_id >= dev->data->nb_rx_queues) {
3087 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3091 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3093 memset(qinfo, 0, sizeof(*qinfo));
3094 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3099 rte_eth_tx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3100 struct rte_eth_txq_info *qinfo)
3102 struct rte_eth_dev *dev;
3104 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3109 dev = &rte_eth_devices[port_id];
3110 if (queue_id >= dev->data->nb_tx_queues) {
3111 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3115 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3117 memset(qinfo, 0, sizeof(*qinfo));
3118 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3123 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3124 struct ether_addr *mc_addr_set,
3125 uint32_t nb_mc_addr)
3127 struct rte_eth_dev *dev;
3129 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3131 dev = &rte_eth_devices[port_id];
3132 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3133 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3137 rte_eth_timesync_enable(uint8_t port_id)
3139 struct rte_eth_dev *dev;
3141 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3142 dev = &rte_eth_devices[port_id];
3144 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3145 return (*dev->dev_ops->timesync_enable)(dev);
3149 rte_eth_timesync_disable(uint8_t port_id)
3151 struct rte_eth_dev *dev;
3153 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3154 dev = &rte_eth_devices[port_id];
3156 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3157 return (*dev->dev_ops->timesync_disable)(dev);
3161 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3164 struct rte_eth_dev *dev;
3166 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3167 dev = &rte_eth_devices[port_id];
3169 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3170 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3174 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3176 struct rte_eth_dev *dev;
3178 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3179 dev = &rte_eth_devices[port_id];
3181 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3182 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3186 rte_eth_timesync_adjust_time(uint8_t port_id, int64_t delta)
3188 struct rte_eth_dev *dev;
3190 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3191 dev = &rte_eth_devices[port_id];
3193 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3194 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3198 rte_eth_timesync_read_time(uint8_t port_id, struct timespec *timestamp)
3200 struct rte_eth_dev *dev;
3202 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3203 dev = &rte_eth_devices[port_id];
3205 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3206 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3210 rte_eth_timesync_write_time(uint8_t port_id, const struct timespec *timestamp)
3212 struct rte_eth_dev *dev;
3214 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3215 dev = &rte_eth_devices[port_id];
3217 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3218 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3222 rte_eth_dev_get_reg_length(uint8_t port_id)
3224 struct rte_eth_dev *dev;
3226 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3228 dev = &rte_eth_devices[port_id];
3229 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg_length, -ENOTSUP);
3230 return (*dev->dev_ops->get_reg_length)(dev);
3234 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3236 struct rte_eth_dev *dev;
3238 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3240 dev = &rte_eth_devices[port_id];
3241 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3242 return (*dev->dev_ops->get_reg)(dev, info);
3246 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3248 struct rte_eth_dev *dev;
3250 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3252 dev = &rte_eth_devices[port_id];
3253 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3254 return (*dev->dev_ops->get_eeprom_length)(dev);
3258 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3260 struct rte_eth_dev *dev;
3262 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3264 dev = &rte_eth_devices[port_id];
3265 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3266 return (*dev->dev_ops->get_eeprom)(dev, info);
3270 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *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 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3278 return (*dev->dev_ops->set_eeprom)(dev, info);
3282 rte_eth_dev_get_dcb_info(uint8_t port_id,
3283 struct rte_eth_dcb_info *dcb_info)
3285 struct rte_eth_dev *dev;
3287 if (!rte_eth_dev_is_valid_port(port_id)) {
3288 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3292 dev = &rte_eth_devices[port_id];
3293 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3295 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3296 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3300 rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_dev)
3302 if ((eth_dev == NULL) || (pci_dev == NULL)) {
3303 RTE_PMD_DEBUG_TRACE("NULL pointer eth_dev=%p pci_dev=%p\n",
3308 eth_dev->data->dev_flags = 0;
3309 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
3310 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
3311 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_DETACHABLE)
3312 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
3314 eth_dev->data->kdrv = pci_dev->kdrv;
3315 eth_dev->data->numa_node = pci_dev->numa_node;
3316 eth_dev->data->drv_name = pci_dev->driver->name;
3320 rte_eth_dev_l2_tunnel_eth_type_conf(uint8_t port_id,
3321 struct rte_eth_l2_tunnel_conf *l2_tunnel)
3323 struct rte_eth_dev *dev;
3325 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3326 if (l2_tunnel == NULL) {
3327 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3331 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3332 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
3336 dev = &rte_eth_devices[port_id];
3337 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
3339 return (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev, l2_tunnel);
3343 rte_eth_dev_l2_tunnel_offload_set(uint8_t port_id,
3344 struct rte_eth_l2_tunnel_conf *l2_tunnel,
3348 struct rte_eth_dev *dev;
3350 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3352 if (l2_tunnel == NULL) {
3353 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3357 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3358 RTE_PMD_DEBUG_TRACE("Invalid tunnel type.\n");
3363 RTE_PMD_DEBUG_TRACE("Mask should have a value.\n");
3367 dev = &rte_eth_devices[port_id];
3368 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
3370 return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);