4 * Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/types.h>
35 #include <sys/queue.h>
44 #include <netinet/in.h>
46 #include <rte_byteorder.h>
48 #include <rte_debug.h>
49 #include <rte_interrupts.h>
51 #include <rte_memory.h>
52 #include <rte_memcpy.h>
53 #include <rte_memzone.h>
54 #include <rte_launch.h>
56 #include <rte_per_lcore.h>
57 #include <rte_lcore.h>
58 #include <rte_atomic.h>
59 #include <rte_branch_prediction.h>
60 #include <rte_common.h>
62 #include <rte_mempool.h>
63 #include <rte_malloc.h>
65 #include <rte_errno.h>
66 #include <rte_spinlock.h>
67 #include <rte_string_fns.h>
69 #include "rte_ether.h"
70 #include "rte_ethdev.h"
72 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 return !(dev_flags & RTE_ETH_DEV_DETACHABLE);
501 /* attach the new physical device, then store port_id of the device */
503 rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
505 /* re-construct pci_device_list */
506 if (rte_eal_pci_scan())
508 /* Invoke probe func of the driver can handle the new device. */
509 if (rte_eal_pci_probe_one(addr))
512 if (rte_eth_dev_get_port_by_addr(addr, port_id))
517 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
521 /* detach the new physical device, then store pci_addr of the device */
523 rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
525 struct rte_pci_addr freed_addr;
526 struct rte_pci_addr vp;
528 /* check whether the driver supports detach feature, or not */
529 if (rte_eth_dev_is_detachable(port_id))
532 /* get pci address by port id */
533 if (rte_eth_dev_get_addr_by_port(port_id, &freed_addr))
536 /* Zeroed pci addr means the port comes from virtual device */
537 vp.domain = vp.bus = vp.devid = vp.function = 0;
538 if (rte_eal_compare_pci_addr(&vp, &freed_addr) == 0)
541 /* invoke devuninit func of the pci driver,
542 * also remove the device from pci_device_list */
543 if (rte_eal_pci_detach(&freed_addr))
549 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
553 /* attach the new virtual device, then store port_id of the device */
555 rte_eth_dev_attach_vdev(const char *vdevargs, uint8_t *port_id)
557 char *name = NULL, *args = NULL;
560 /* parse vdevargs, then retrieve device name and args */
561 if (rte_eal_parse_devargs_str(vdevargs, &name, &args))
564 /* walk around dev_driver_list to find the driver of the device,
565 * then invoke probe function of the driver.
566 * rte_eal_vdev_init() updates port_id allocated after
569 if (rte_eal_vdev_init(name, args))
572 if (rte_eth_dev_get_port_by_name(name, port_id))
581 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
585 /* detach the new virtual device, then store the name of the device */
587 rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
589 char name[RTE_ETH_NAME_MAX_LEN];
591 /* check whether the driver supports detach feature, or not */
592 if (rte_eth_dev_is_detachable(port_id))
595 /* get device name by port id */
596 if (rte_eth_dev_get_name_by_port(port_id, name))
598 /* walk around dev_driver_list to find the driver of the device,
599 * then invoke uninit function of the driver */
600 if (rte_eal_vdev_uninit(name))
603 strncpy(vdevname, name, sizeof(name));
606 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
610 /* attach the new device, then store port_id of the device */
612 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
614 struct rte_pci_addr addr;
616 if ((devargs == NULL) || (port_id == NULL))
619 if (eal_parse_pci_DomBDF(devargs, &addr) == 0)
620 return rte_eth_dev_attach_pdev(&addr, port_id);
622 return rte_eth_dev_attach_vdev(devargs, port_id);
625 /* detach the device, then store the name of the device */
627 rte_eth_dev_detach(uint8_t port_id, char *name)
629 struct rte_pci_addr addr;
635 if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {
636 ret = rte_eth_dev_get_addr_by_port(port_id, &addr);
640 ret = rte_eth_dev_detach_pdev(port_id, &addr);
642 snprintf(name, RTE_ETH_NAME_MAX_LEN,
644 addr.domain, addr.bus,
645 addr.devid, addr.function);
649 return rte_eth_dev_detach_vdev(port_id, name);
653 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
655 uint16_t old_nb_queues = dev->data->nb_rx_queues;
659 if (dev->data->rx_queues == NULL) { /* first time configuration */
660 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
661 sizeof(dev->data->rx_queues[0]) * nb_queues,
662 RTE_CACHE_LINE_SIZE);
663 if (dev->data->rx_queues == NULL) {
664 dev->data->nb_rx_queues = 0;
667 } else { /* re-configure */
668 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
670 rxq = dev->data->rx_queues;
672 for (i = nb_queues; i < old_nb_queues; i++)
673 (*dev->dev_ops->rx_queue_release)(rxq[i]);
674 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
675 RTE_CACHE_LINE_SIZE);
678 if (nb_queues > old_nb_queues) {
679 uint16_t new_qs = nb_queues - old_nb_queues;
681 memset(rxq + old_nb_queues, 0,
682 sizeof(rxq[0]) * new_qs);
685 dev->data->rx_queues = rxq;
688 dev->data->nb_rx_queues = nb_queues;
693 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
695 struct rte_eth_dev *dev;
697 /* This function is only safe when called from the primary process
698 * in a multi-process setup*/
699 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
701 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
703 dev = &rte_eth_devices[port_id];
704 if (rx_queue_id >= dev->data->nb_rx_queues) {
705 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
709 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
711 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
712 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
713 " already started\n",
714 rx_queue_id, port_id);
718 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
723 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
725 struct rte_eth_dev *dev;
727 /* This function is only safe when called from the primary process
728 * in a multi-process setup*/
729 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
731 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
733 dev = &rte_eth_devices[port_id];
734 if (rx_queue_id >= dev->data->nb_rx_queues) {
735 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
739 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
741 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
742 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
743 " already stopped\n",
744 rx_queue_id, port_id);
748 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
753 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
755 struct rte_eth_dev *dev;
757 /* This function is only safe when called from the primary process
758 * in a multi-process setup*/
759 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
761 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
763 dev = &rte_eth_devices[port_id];
764 if (tx_queue_id >= dev->data->nb_tx_queues) {
765 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
769 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
771 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
772 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
773 " already started\n",
774 tx_queue_id, port_id);
778 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
783 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
785 struct rte_eth_dev *dev;
787 /* This function is only safe when called from the primary process
788 * in a multi-process setup*/
789 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
791 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
793 dev = &rte_eth_devices[port_id];
794 if (tx_queue_id >= dev->data->nb_tx_queues) {
795 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
799 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
801 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
802 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
803 " already stopped\n",
804 tx_queue_id, port_id);
808 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
813 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
815 uint16_t old_nb_queues = dev->data->nb_tx_queues;
819 if (dev->data->tx_queues == NULL) { /* first time configuration */
820 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
821 sizeof(dev->data->tx_queues[0]) * nb_queues,
822 RTE_CACHE_LINE_SIZE);
823 if (dev->data->tx_queues == NULL) {
824 dev->data->nb_tx_queues = 0;
827 } else { /* re-configure */
828 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
830 txq = dev->data->tx_queues;
832 for (i = nb_queues; i < old_nb_queues; i++)
833 (*dev->dev_ops->tx_queue_release)(txq[i]);
834 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
835 RTE_CACHE_LINE_SIZE);
838 if (nb_queues > old_nb_queues) {
839 uint16_t new_qs = nb_queues - old_nb_queues;
841 memset(txq + old_nb_queues, 0,
842 sizeof(txq[0]) * new_qs);
845 dev->data->tx_queues = txq;
848 dev->data->nb_tx_queues = nb_queues;
853 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
854 const struct rte_eth_conf *dev_conf)
856 struct rte_eth_dev *dev;
857 struct rte_eth_dev_info dev_info;
860 /* This function is only safe when called from the primary process
861 * in a multi-process setup*/
862 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
864 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
866 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
868 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
869 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
873 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
875 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
876 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
880 dev = &rte_eth_devices[port_id];
882 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
883 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
885 if (dev->data->dev_started) {
887 "port %d must be stopped to allow configuration\n", port_id);
892 * Check that the numbers of RX and TX queues are not greater
893 * than the maximum number of RX and TX queues supported by the
896 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
897 if (nb_rx_q > dev_info.max_rx_queues) {
898 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
899 port_id, nb_rx_q, dev_info.max_rx_queues);
903 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
907 if (nb_tx_q > dev_info.max_tx_queues) {
908 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
909 port_id, nb_tx_q, dev_info.max_tx_queues);
913 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
917 /* Copy the dev_conf parameter into the dev structure */
918 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
921 * If link state interrupt is enabled, check that the
922 * device supports it.
924 if ((dev_conf->intr_conf.lsc == 1) &&
925 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
926 RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
927 dev->data->drv_name);
932 * If jumbo frames are enabled, check that the maximum RX packet
933 * length is supported by the configured device.
935 if (dev_conf->rxmode.jumbo_frame == 1) {
936 if (dev_conf->rxmode.max_rx_pkt_len >
937 dev_info.max_rx_pktlen) {
938 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
939 " > max valid value %u\n",
941 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
942 (unsigned)dev_info.max_rx_pktlen);
944 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
945 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
946 " < min valid value %u\n",
948 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
949 (unsigned)ETHER_MIN_LEN);
953 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
954 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
955 /* Use default value */
956 dev->data->dev_conf.rxmode.max_rx_pkt_len =
961 * Setup new number of RX/TX queues and reconfigure device.
963 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
965 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
970 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
972 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
974 rte_eth_dev_rx_queue_config(dev, 0);
978 diag = (*dev->dev_ops->dev_configure)(dev);
980 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
982 rte_eth_dev_rx_queue_config(dev, 0);
983 rte_eth_dev_tx_queue_config(dev, 0);
991 rte_eth_dev_config_restore(uint8_t port_id)
993 struct rte_eth_dev *dev;
994 struct rte_eth_dev_info dev_info;
995 struct ether_addr addr;
999 dev = &rte_eth_devices[port_id];
1001 rte_eth_dev_info_get(port_id, &dev_info);
1003 if (RTE_ETH_DEV_SRIOV(dev).active)
1004 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
1006 /* replay MAC address configuration */
1007 for (i = 0; i < dev_info.max_mac_addrs; i++) {
1008 addr = dev->data->mac_addrs[i];
1010 /* skip zero address */
1011 if (is_zero_ether_addr(&addr))
1014 /* add address to the hardware */
1015 if (*dev->dev_ops->mac_addr_add &&
1016 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
1017 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
1019 RTE_PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
1021 /* exit the loop but not return an error */
1026 /* replay promiscuous configuration */
1027 if (rte_eth_promiscuous_get(port_id) == 1)
1028 rte_eth_promiscuous_enable(port_id);
1029 else if (rte_eth_promiscuous_get(port_id) == 0)
1030 rte_eth_promiscuous_disable(port_id);
1032 /* replay all multicast configuration */
1033 if (rte_eth_allmulticast_get(port_id) == 1)
1034 rte_eth_allmulticast_enable(port_id);
1035 else if (rte_eth_allmulticast_get(port_id) == 0)
1036 rte_eth_allmulticast_disable(port_id);
1040 rte_eth_dev_start(uint8_t port_id)
1042 struct rte_eth_dev *dev;
1045 /* This function is only safe when called from the primary process
1046 * in a multi-process setup*/
1047 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1049 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1051 dev = &rte_eth_devices[port_id];
1053 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1055 if (dev->data->dev_started != 0) {
1056 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1057 " already started\n",
1062 diag = (*dev->dev_ops->dev_start)(dev);
1064 dev->data->dev_started = 1;
1068 rte_eth_dev_config_restore(port_id);
1070 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1071 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1072 (*dev->dev_ops->link_update)(dev, 0);
1078 rte_eth_dev_stop(uint8_t port_id)
1080 struct rte_eth_dev *dev;
1082 /* This function is only safe when called from the primary process
1083 * in a multi-process setup*/
1084 RTE_PROC_PRIMARY_OR_RET();
1086 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1087 dev = &rte_eth_devices[port_id];
1089 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1091 if (dev->data->dev_started == 0) {
1092 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1093 " already stopped\n",
1098 dev->data->dev_started = 0;
1099 (*dev->dev_ops->dev_stop)(dev);
1103 rte_eth_dev_set_link_up(uint8_t port_id)
1105 struct rte_eth_dev *dev;
1107 /* This function is only safe when called from the primary process
1108 * in a multi-process setup*/
1109 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1111 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1113 dev = &rte_eth_devices[port_id];
1115 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1116 return (*dev->dev_ops->dev_set_link_up)(dev);
1120 rte_eth_dev_set_link_down(uint8_t port_id)
1122 struct rte_eth_dev *dev;
1124 /* This function is only safe when called from the primary process
1125 * in a multi-process setup*/
1126 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1128 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1130 dev = &rte_eth_devices[port_id];
1132 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1133 return (*dev->dev_ops->dev_set_link_down)(dev);
1137 rte_eth_dev_close(uint8_t port_id)
1139 struct rte_eth_dev *dev;
1141 /* This function is only safe when called from the primary process
1142 * in a multi-process setup*/
1143 RTE_PROC_PRIMARY_OR_RET();
1145 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1146 dev = &rte_eth_devices[port_id];
1148 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1149 dev->data->dev_started = 0;
1150 (*dev->dev_ops->dev_close)(dev);
1152 rte_free(dev->data->rx_queues);
1153 dev->data->rx_queues = NULL;
1154 rte_free(dev->data->tx_queues);
1155 dev->data->tx_queues = NULL;
1159 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1160 uint16_t nb_rx_desc, unsigned int socket_id,
1161 const struct rte_eth_rxconf *rx_conf,
1162 struct rte_mempool *mp)
1165 uint32_t mbp_buf_size;
1166 struct rte_eth_dev *dev;
1167 struct rte_eth_dev_info dev_info;
1169 /* This function is only safe when called from the primary process
1170 * in a multi-process setup*/
1171 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1173 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1175 dev = &rte_eth_devices[port_id];
1176 if (rx_queue_id >= dev->data->nb_rx_queues) {
1177 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1181 if (dev->data->dev_started) {
1182 RTE_PMD_DEBUG_TRACE(
1183 "port %d must be stopped to allow configuration\n", port_id);
1187 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1188 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1191 * Check the size of the mbuf data buffer.
1192 * This value must be provided in the private data of the memory pool.
1193 * First check that the memory pool has a valid private data.
1195 rte_eth_dev_info_get(port_id, &dev_info);
1196 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1197 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1198 mp->name, (int) mp->private_data_size,
1199 (int) sizeof(struct rte_pktmbuf_pool_private));
1202 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1204 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1205 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1206 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1210 (int)(RTE_PKTMBUF_HEADROOM +
1211 dev_info.min_rx_bufsize),
1212 (int)RTE_PKTMBUF_HEADROOM,
1213 (int)dev_info.min_rx_bufsize);
1217 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1218 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1219 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1221 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1222 "should be: <= %hu, = %hu, and a product of %hu\n",
1224 dev_info.rx_desc_lim.nb_max,
1225 dev_info.rx_desc_lim.nb_min,
1226 dev_info.rx_desc_lim.nb_align);
1230 if (rx_conf == NULL)
1231 rx_conf = &dev_info.default_rxconf;
1233 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1234 socket_id, rx_conf, mp);
1236 if (!dev->data->min_rx_buf_size ||
1237 dev->data->min_rx_buf_size > mbp_buf_size)
1238 dev->data->min_rx_buf_size = mbp_buf_size;
1245 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1246 uint16_t nb_tx_desc, unsigned int socket_id,
1247 const struct rte_eth_txconf *tx_conf)
1249 struct rte_eth_dev *dev;
1250 struct rte_eth_dev_info dev_info;
1252 /* This function is only safe when called from the primary process
1253 * in a multi-process setup*/
1254 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1256 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1258 dev = &rte_eth_devices[port_id];
1259 if (tx_queue_id >= dev->data->nb_tx_queues) {
1260 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1264 if (dev->data->dev_started) {
1265 RTE_PMD_DEBUG_TRACE(
1266 "port %d must be stopped to allow configuration\n", port_id);
1270 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1271 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1273 rte_eth_dev_info_get(port_id, &dev_info);
1275 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1276 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1277 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1278 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1279 "should be: <= %hu, = %hu, and a product of %hu\n",
1281 dev_info.tx_desc_lim.nb_max,
1282 dev_info.tx_desc_lim.nb_min,
1283 dev_info.tx_desc_lim.nb_align);
1287 if (tx_conf == NULL)
1288 tx_conf = &dev_info.default_txconf;
1290 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1291 socket_id, tx_conf);
1295 rte_eth_promiscuous_enable(uint8_t port_id)
1297 struct rte_eth_dev *dev;
1299 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1300 dev = &rte_eth_devices[port_id];
1302 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1303 (*dev->dev_ops->promiscuous_enable)(dev);
1304 dev->data->promiscuous = 1;
1308 rte_eth_promiscuous_disable(uint8_t port_id)
1310 struct rte_eth_dev *dev;
1312 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1313 dev = &rte_eth_devices[port_id];
1315 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1316 dev->data->promiscuous = 0;
1317 (*dev->dev_ops->promiscuous_disable)(dev);
1321 rte_eth_promiscuous_get(uint8_t port_id)
1323 struct rte_eth_dev *dev;
1325 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1327 dev = &rte_eth_devices[port_id];
1328 return dev->data->promiscuous;
1332 rte_eth_allmulticast_enable(uint8_t port_id)
1334 struct rte_eth_dev *dev;
1336 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1337 dev = &rte_eth_devices[port_id];
1339 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1340 (*dev->dev_ops->allmulticast_enable)(dev);
1341 dev->data->all_multicast = 1;
1345 rte_eth_allmulticast_disable(uint8_t port_id)
1347 struct rte_eth_dev *dev;
1349 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1350 dev = &rte_eth_devices[port_id];
1352 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1353 dev->data->all_multicast = 0;
1354 (*dev->dev_ops->allmulticast_disable)(dev);
1358 rte_eth_allmulticast_get(uint8_t port_id)
1360 struct rte_eth_dev *dev;
1362 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1364 dev = &rte_eth_devices[port_id];
1365 return dev->data->all_multicast;
1369 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1370 struct rte_eth_link *link)
1372 struct rte_eth_link *dst = link;
1373 struct rte_eth_link *src = &(dev->data->dev_link);
1375 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1376 *(uint64_t *)src) == 0)
1383 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1385 struct rte_eth_dev *dev;
1387 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1388 dev = &rte_eth_devices[port_id];
1390 if (dev->data->dev_conf.intr_conf.lsc != 0)
1391 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1393 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1394 (*dev->dev_ops->link_update)(dev, 1);
1395 *eth_link = dev->data->dev_link;
1400 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1402 struct rte_eth_dev *dev;
1404 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1405 dev = &rte_eth_devices[port_id];
1407 if (dev->data->dev_conf.intr_conf.lsc != 0)
1408 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1410 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1411 (*dev->dev_ops->link_update)(dev, 0);
1412 *eth_link = dev->data->dev_link;
1417 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1419 struct rte_eth_dev *dev;
1421 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1423 dev = &rte_eth_devices[port_id];
1424 memset(stats, 0, sizeof(*stats));
1426 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1427 (*dev->dev_ops->stats_get)(dev, stats);
1428 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1433 rte_eth_stats_reset(uint8_t port_id)
1435 struct rte_eth_dev *dev;
1437 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1438 dev = &rte_eth_devices[port_id];
1440 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1441 (*dev->dev_ops->stats_reset)(dev);
1442 dev->data->rx_mbuf_alloc_failed = 0;
1445 /* retrieve ethdev extended statistics */
1447 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1450 struct rte_eth_stats eth_stats;
1451 struct rte_eth_dev *dev;
1452 unsigned count = 0, i, q;
1454 uint64_t val, *stats_ptr;
1456 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1458 dev = &rte_eth_devices[port_id];
1460 /* Return generic statistics */
1461 count = RTE_NB_STATS + (dev->data->nb_rx_queues * RTE_NB_RXQ_STATS) +
1462 (dev->data->nb_tx_queues * RTE_NB_TXQ_STATS);
1464 /* implemented by the driver */
1465 if (dev->dev_ops->xstats_get != NULL) {
1466 /* Retrieve the xstats from the driver at the end of the
1469 xcount = (*dev->dev_ops->xstats_get)(dev, &xstats[count],
1470 (n > count) ? n - count : 0);
1476 if (n < count + xcount)
1477 return count + xcount;
1479 /* now fill the xstats structure */
1481 rte_eth_stats_get(port_id, ð_stats);
1484 for (i = 0; i < RTE_NB_STATS; i++) {
1485 stats_ptr = RTE_PTR_ADD(ð_stats,
1486 rte_stats_strings[i].offset);
1488 snprintf(xstats[count].name, sizeof(xstats[count].name),
1489 "%s", rte_stats_strings[i].name);
1490 xstats[count++].value = val;
1494 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1495 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1496 stats_ptr = RTE_PTR_ADD(ð_stats,
1497 rte_rxq_stats_strings[i].offset +
1498 q * sizeof(uint64_t));
1500 snprintf(xstats[count].name, sizeof(xstats[count].name),
1502 rte_rxq_stats_strings[i].name);
1503 xstats[count++].value = val;
1508 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1509 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1510 stats_ptr = RTE_PTR_ADD(ð_stats,
1511 rte_txq_stats_strings[i].offset +
1512 q * sizeof(uint64_t));
1514 snprintf(xstats[count].name, sizeof(xstats[count].name),
1516 rte_txq_stats_strings[i].name);
1517 xstats[count++].value = val;
1521 return count + xcount;
1524 /* reset ethdev extended statistics */
1526 rte_eth_xstats_reset(uint8_t port_id)
1528 struct rte_eth_dev *dev;
1530 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1531 dev = &rte_eth_devices[port_id];
1533 /* implemented by the driver */
1534 if (dev->dev_ops->xstats_reset != NULL) {
1535 (*dev->dev_ops->xstats_reset)(dev);
1539 /* fallback to default */
1540 rte_eth_stats_reset(port_id);
1544 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1547 struct rte_eth_dev *dev;
1549 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1551 dev = &rte_eth_devices[port_id];
1553 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1554 return (*dev->dev_ops->queue_stats_mapping_set)
1555 (dev, queue_id, stat_idx, is_rx);
1560 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1563 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1569 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1572 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1578 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1580 struct rte_eth_dev *dev;
1581 const struct rte_eth_desc_lim lim = {
1582 .nb_max = UINT16_MAX,
1587 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1588 dev = &rte_eth_devices[port_id];
1590 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1591 dev_info->rx_desc_lim = lim;
1592 dev_info->tx_desc_lim = lim;
1594 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1595 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1596 dev_info->pci_dev = dev->pci_dev;
1597 dev_info->driver_name = dev->data->drv_name;
1601 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1603 struct rte_eth_dev *dev;
1605 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1606 dev = &rte_eth_devices[port_id];
1607 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1612 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1614 struct rte_eth_dev *dev;
1616 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1618 dev = &rte_eth_devices[port_id];
1619 *mtu = dev->data->mtu;
1624 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1627 struct rte_eth_dev *dev;
1629 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1630 dev = &rte_eth_devices[port_id];
1631 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1633 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1635 dev->data->mtu = mtu;
1641 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1643 struct rte_eth_dev *dev;
1645 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1646 dev = &rte_eth_devices[port_id];
1647 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1648 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1652 if (vlan_id > 4095) {
1653 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1654 port_id, (unsigned) vlan_id);
1657 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1659 return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1663 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1665 struct rte_eth_dev *dev;
1667 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1668 dev = &rte_eth_devices[port_id];
1669 if (rx_queue_id >= dev->data->nb_rx_queues) {
1670 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1674 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1675 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1681 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1683 struct rte_eth_dev *dev;
1685 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1686 dev = &rte_eth_devices[port_id];
1687 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1688 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1694 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1696 struct rte_eth_dev *dev;
1701 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1702 dev = &rte_eth_devices[port_id];
1704 /*check which option changed by application*/
1705 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1706 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1708 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1709 mask |= ETH_VLAN_STRIP_MASK;
1712 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1713 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1715 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1716 mask |= ETH_VLAN_FILTER_MASK;
1719 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1720 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1722 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1723 mask |= ETH_VLAN_EXTEND_MASK;
1730 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1731 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1737 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1739 struct rte_eth_dev *dev;
1742 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1743 dev = &rte_eth_devices[port_id];
1745 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1746 ret |= ETH_VLAN_STRIP_OFFLOAD;
1748 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1749 ret |= ETH_VLAN_FILTER_OFFLOAD;
1751 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1752 ret |= ETH_VLAN_EXTEND_OFFLOAD;
1758 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1760 struct rte_eth_dev *dev;
1762 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1763 dev = &rte_eth_devices[port_id];
1764 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1765 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1771 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1773 struct rte_eth_dev *dev;
1775 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1776 dev = &rte_eth_devices[port_id];
1777 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1778 memset(fc_conf, 0, sizeof(*fc_conf));
1779 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1783 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1785 struct rte_eth_dev *dev;
1787 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1788 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1789 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1793 dev = &rte_eth_devices[port_id];
1794 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1795 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1799 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1801 struct rte_eth_dev *dev;
1803 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1804 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1805 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1809 dev = &rte_eth_devices[port_id];
1810 /* High water, low water validation are device specific */
1811 if (*dev->dev_ops->priority_flow_ctrl_set)
1812 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1817 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
1825 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
1826 RTE_PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
1827 RTE_RETA_GROUP_SIZE);
1831 num = reta_size / RTE_RETA_GROUP_SIZE;
1832 for (i = 0; i < num; i++) {
1833 if (reta_conf[i].mask)
1841 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
1845 uint16_t i, idx, shift;
1851 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
1855 for (i = 0; i < reta_size; i++) {
1856 idx = i / RTE_RETA_GROUP_SIZE;
1857 shift = i % RTE_RETA_GROUP_SIZE;
1858 if ((reta_conf[idx].mask & (1ULL << shift)) &&
1859 (reta_conf[idx].reta[shift] >= max_rxq)) {
1860 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
1861 "the maximum rxq index: %u\n", idx, shift,
1862 reta_conf[idx].reta[shift], max_rxq);
1871 rte_eth_dev_rss_reta_update(uint8_t port_id,
1872 struct rte_eth_rss_reta_entry64 *reta_conf,
1875 struct rte_eth_dev *dev;
1878 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1879 /* Check mask bits */
1880 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
1884 dev = &rte_eth_devices[port_id];
1886 /* Check entry value */
1887 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
1888 dev->data->nb_rx_queues);
1892 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
1893 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
1897 rte_eth_dev_rss_reta_query(uint8_t port_id,
1898 struct rte_eth_rss_reta_entry64 *reta_conf,
1901 struct rte_eth_dev *dev;
1904 if (port_id >= nb_ports) {
1905 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1909 /* Check mask bits */
1910 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
1914 dev = &rte_eth_devices[port_id];
1915 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
1916 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
1920 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
1922 struct rte_eth_dev *dev;
1923 uint16_t rss_hash_protos;
1925 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1926 rss_hash_protos = rss_conf->rss_hf;
1927 if ((rss_hash_protos != 0) &&
1928 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
1929 RTE_PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
1933 dev = &rte_eth_devices[port_id];
1934 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
1935 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
1939 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
1940 struct rte_eth_rss_conf *rss_conf)
1942 struct rte_eth_dev *dev;
1944 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1945 dev = &rte_eth_devices[port_id];
1946 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
1947 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
1951 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
1952 struct rte_eth_udp_tunnel *udp_tunnel)
1954 struct rte_eth_dev *dev;
1956 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1957 if (udp_tunnel == NULL) {
1958 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
1962 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
1963 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
1967 dev = &rte_eth_devices[port_id];
1968 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
1969 return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
1973 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
1974 struct rte_eth_udp_tunnel *udp_tunnel)
1976 struct rte_eth_dev *dev;
1978 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1979 dev = &rte_eth_devices[port_id];
1981 if (udp_tunnel == NULL) {
1982 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
1986 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
1987 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
1991 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
1992 return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
1996 rte_eth_led_on(uint8_t port_id)
1998 struct rte_eth_dev *dev;
2000 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2001 dev = &rte_eth_devices[port_id];
2002 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2003 return (*dev->dev_ops->dev_led_on)(dev);
2007 rte_eth_led_off(uint8_t port_id)
2009 struct rte_eth_dev *dev;
2011 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2012 dev = &rte_eth_devices[port_id];
2013 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2014 return (*dev->dev_ops->dev_led_off)(dev);
2018 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2022 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2024 struct rte_eth_dev_info dev_info;
2025 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2028 rte_eth_dev_info_get(port_id, &dev_info);
2030 for (i = 0; i < dev_info.max_mac_addrs; i++)
2031 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2037 static const struct ether_addr null_mac_addr;
2040 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2043 struct rte_eth_dev *dev;
2047 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2048 dev = &rte_eth_devices[port_id];
2049 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2051 if (is_zero_ether_addr(addr)) {
2052 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2056 if (pool >= ETH_64_POOLS) {
2057 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2061 index = get_mac_addr_index(port_id, addr);
2063 index = get_mac_addr_index(port_id, &null_mac_addr);
2065 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2070 pool_mask = dev->data->mac_pool_sel[index];
2072 /* Check if both MAC address and pool is already there, and do nothing */
2073 if (pool_mask & (1ULL << pool))
2078 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2080 /* Update address in NIC data structure */
2081 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2083 /* Update pool bitmap in NIC data structure */
2084 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2090 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2092 struct rte_eth_dev *dev;
2095 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2096 dev = &rte_eth_devices[port_id];
2097 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2099 index = get_mac_addr_index(port_id, addr);
2101 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2103 } else if (index < 0)
2104 return 0; /* Do nothing if address wasn't found */
2107 (*dev->dev_ops->mac_addr_remove)(dev, index);
2109 /* Update address in NIC data structure */
2110 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2112 /* reset pool bitmap */
2113 dev->data->mac_pool_sel[index] = 0;
2119 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2121 struct rte_eth_dev *dev;
2123 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2125 if (!is_valid_assigned_ether_addr(addr))
2128 dev = &rte_eth_devices[port_id];
2129 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2131 /* Update default address in NIC data structure */
2132 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2134 (*dev->dev_ops->mac_addr_set)(dev, addr);
2140 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2141 uint16_t rx_mode, uint8_t on)
2144 struct rte_eth_dev *dev;
2145 struct rte_eth_dev_info dev_info;
2147 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2149 dev = &rte_eth_devices[port_id];
2150 rte_eth_dev_info_get(port_id, &dev_info);
2152 num_vfs = dev_info.max_vfs;
2154 RTE_PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2159 RTE_PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2162 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2163 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2167 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2171 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2173 struct rte_eth_dev_info dev_info;
2174 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2177 rte_eth_dev_info_get(port_id, &dev_info);
2178 if (!dev->data->hash_mac_addrs)
2181 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2182 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2183 ETHER_ADDR_LEN) == 0)
2190 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2195 struct rte_eth_dev *dev;
2197 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2199 dev = &rte_eth_devices[port_id];
2200 if (is_zero_ether_addr(addr)) {
2201 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2206 index = get_hash_mac_addr_index(port_id, addr);
2207 /* Check if it's already there, and do nothing */
2208 if ((index >= 0) && (on))
2213 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2214 "set in UTA\n", port_id);
2218 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2220 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2226 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2227 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2229 /* Update address in NIC data structure */
2231 ether_addr_copy(addr,
2232 &dev->data->hash_mac_addrs[index]);
2234 ether_addr_copy(&null_mac_addr,
2235 &dev->data->hash_mac_addrs[index]);
2242 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2244 struct rte_eth_dev *dev;
2246 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2248 dev = &rte_eth_devices[port_id];
2250 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2251 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2255 rte_eth_dev_set_vf_rx(uint8_t port_id, uint16_t vf, uint8_t on)
2258 struct rte_eth_dev *dev;
2259 struct rte_eth_dev_info dev_info;
2261 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2263 dev = &rte_eth_devices[port_id];
2264 rte_eth_dev_info_get(port_id, &dev_info);
2266 num_vfs = dev_info.max_vfs;
2268 RTE_PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2272 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2273 return (*dev->dev_ops->set_vf_rx)(dev, vf, on);
2277 rte_eth_dev_set_vf_tx(uint8_t port_id, uint16_t vf, uint8_t on)
2280 struct rte_eth_dev *dev;
2281 struct rte_eth_dev_info dev_info;
2283 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2285 dev = &rte_eth_devices[port_id];
2286 rte_eth_dev_info_get(port_id, &dev_info);
2288 num_vfs = dev_info.max_vfs;
2290 RTE_PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2294 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2295 return (*dev->dev_ops->set_vf_tx)(dev, vf, on);
2299 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2300 uint64_t vf_mask, uint8_t vlan_on)
2302 struct rte_eth_dev *dev;
2304 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2306 dev = &rte_eth_devices[port_id];
2308 if (vlan_id > ETHER_MAX_VLAN_ID) {
2309 RTE_PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2315 RTE_PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2319 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2320 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2324 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2327 struct rte_eth_dev *dev;
2328 struct rte_eth_dev_info dev_info;
2329 struct rte_eth_link link;
2331 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2333 dev = &rte_eth_devices[port_id];
2334 rte_eth_dev_info_get(port_id, &dev_info);
2335 link = dev->data->dev_link;
2337 if (queue_idx > dev_info.max_tx_queues) {
2338 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2339 "invalid queue id=%d\n", port_id, queue_idx);
2343 if (tx_rate > link.link_speed) {
2344 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2345 "bigger than link speed= %d\n",
2346 tx_rate, link.link_speed);
2350 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2351 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2354 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2357 struct rte_eth_dev *dev;
2358 struct rte_eth_dev_info dev_info;
2359 struct rte_eth_link link;
2364 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2366 dev = &rte_eth_devices[port_id];
2367 rte_eth_dev_info_get(port_id, &dev_info);
2368 link = dev->data->dev_link;
2370 if (vf > dev_info.max_vfs) {
2371 RTE_PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2372 "invalid vf id=%d\n", port_id, vf);
2376 if (tx_rate > link.link_speed) {
2377 RTE_PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2378 "bigger than link speed= %d\n",
2379 tx_rate, link.link_speed);
2383 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2384 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2388 rte_eth_mirror_rule_set(uint8_t port_id,
2389 struct rte_eth_mirror_conf *mirror_conf,
2390 uint8_t rule_id, uint8_t on)
2392 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2394 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2395 if (mirror_conf->rule_type == 0) {
2396 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2400 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2401 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2406 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2407 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2408 (mirror_conf->pool_mask == 0)) {
2409 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2413 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2414 mirror_conf->vlan.vlan_mask == 0) {
2415 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2419 dev = &rte_eth_devices[port_id];
2420 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2422 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2426 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2428 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2430 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2432 dev = &rte_eth_devices[port_id];
2433 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2435 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2439 rte_eth_dev_callback_register(uint8_t port_id,
2440 enum rte_eth_event_type event,
2441 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2443 struct rte_eth_dev *dev;
2444 struct rte_eth_dev_callback *user_cb;
2449 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2451 dev = &rte_eth_devices[port_id];
2452 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2454 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2455 if (user_cb->cb_fn == cb_fn &&
2456 user_cb->cb_arg == cb_arg &&
2457 user_cb->event == event) {
2462 /* create a new callback. */
2463 if (user_cb == NULL)
2464 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2465 sizeof(struct rte_eth_dev_callback), 0);
2466 if (user_cb != NULL) {
2467 user_cb->cb_fn = cb_fn;
2468 user_cb->cb_arg = cb_arg;
2469 user_cb->event = event;
2470 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2473 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2474 return (user_cb == NULL) ? -ENOMEM : 0;
2478 rte_eth_dev_callback_unregister(uint8_t port_id,
2479 enum rte_eth_event_type event,
2480 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2483 struct rte_eth_dev *dev;
2484 struct rte_eth_dev_callback *cb, *next;
2489 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2491 dev = &rte_eth_devices[port_id];
2492 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2495 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2497 next = TAILQ_NEXT(cb, next);
2499 if (cb->cb_fn != cb_fn || cb->event != event ||
2500 (cb->cb_arg != (void *)-1 &&
2501 cb->cb_arg != cb_arg))
2505 * if this callback is not executing right now,
2508 if (cb->active == 0) {
2509 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2516 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2521 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2522 enum rte_eth_event_type event)
2524 struct rte_eth_dev_callback *cb_lst;
2525 struct rte_eth_dev_callback dev_cb;
2527 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2528 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2529 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2533 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2534 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2536 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2539 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2543 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
2546 struct rte_eth_dev *dev;
2547 struct rte_intr_handle *intr_handle;
2551 if (!rte_eth_dev_is_valid_port(port_id)) {
2552 RTE_PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
2556 dev = &rte_eth_devices[port_id];
2557 intr_handle = &dev->pci_dev->intr_handle;
2558 if (!intr_handle->intr_vec) {
2559 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2563 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2564 vec = intr_handle->intr_vec[qid];
2565 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2566 if (rc && rc != -EEXIST) {
2567 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2568 " op %d epfd %d vec %u\n",
2569 port_id, qid, op, epfd, vec);
2576 const struct rte_memzone *
2577 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2578 uint16_t queue_id, size_t size, unsigned align,
2581 char z_name[RTE_MEMZONE_NAMESIZE];
2582 const struct rte_memzone *mz;
2584 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2585 dev->driver->pci_drv.name, ring_name,
2586 dev->data->port_id, queue_id);
2588 mz = rte_memzone_lookup(z_name);
2592 if (rte_xen_dom0_supported())
2593 return rte_memzone_reserve_bounded(z_name, size, socket_id,
2594 0, align, RTE_PGSIZE_2M);
2596 return rte_memzone_reserve_aligned(z_name, size, socket_id,
2601 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
2602 int epfd, int op, void *data)
2605 struct rte_eth_dev *dev;
2606 struct rte_intr_handle *intr_handle;
2609 if (!rte_eth_dev_is_valid_port(port_id)) {
2610 RTE_PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
2614 dev = &rte_eth_devices[port_id];
2615 if (queue_id >= dev->data->nb_rx_queues) {
2616 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
2620 intr_handle = &dev->pci_dev->intr_handle;
2621 if (!intr_handle->intr_vec) {
2622 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2626 vec = intr_handle->intr_vec[queue_id];
2627 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2628 if (rc && rc != -EEXIST) {
2629 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2630 " op %d epfd %d vec %u\n",
2631 port_id, queue_id, op, epfd, vec);
2639 rte_eth_dev_rx_intr_enable(uint8_t port_id,
2642 struct rte_eth_dev *dev;
2644 if (!rte_eth_dev_is_valid_port(port_id)) {
2645 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2649 dev = &rte_eth_devices[port_id];
2651 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
2652 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
2656 rte_eth_dev_rx_intr_disable(uint8_t port_id,
2659 struct rte_eth_dev *dev;
2661 if (!rte_eth_dev_is_valid_port(port_id)) {
2662 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2666 dev = &rte_eth_devices[port_id];
2668 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
2669 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
2672 #ifdef RTE_NIC_BYPASS
2673 int rte_eth_dev_bypass_init(uint8_t port_id)
2675 struct rte_eth_dev *dev;
2677 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2679 dev = &rte_eth_devices[port_id];
2680 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2681 (*dev->dev_ops->bypass_init)(dev);
2686 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2688 struct rte_eth_dev *dev;
2690 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2692 dev = &rte_eth_devices[port_id];
2693 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2694 (*dev->dev_ops->bypass_state_show)(dev, state);
2699 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2701 struct rte_eth_dev *dev;
2703 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2705 dev = &rte_eth_devices[port_id];
2706 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2707 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2712 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2714 struct rte_eth_dev *dev;
2716 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2718 dev = &rte_eth_devices[port_id];
2719 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2720 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2725 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2727 struct rte_eth_dev *dev;
2729 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2731 dev = &rte_eth_devices[port_id];
2733 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2734 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2739 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2741 struct rte_eth_dev *dev;
2743 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2745 dev = &rte_eth_devices[port_id];
2747 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2748 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2753 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2755 struct rte_eth_dev *dev;
2757 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2759 dev = &rte_eth_devices[port_id];
2761 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2762 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2767 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2769 struct rte_eth_dev *dev;
2771 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2773 dev = &rte_eth_devices[port_id];
2775 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2776 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2781 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2783 struct rte_eth_dev *dev;
2785 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2787 dev = &rte_eth_devices[port_id];
2789 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2790 (*dev->dev_ops->bypass_wd_reset)(dev);
2796 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
2798 struct rte_eth_dev *dev;
2800 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2802 dev = &rte_eth_devices[port_id];
2803 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2804 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
2805 RTE_ETH_FILTER_NOP, NULL);
2809 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
2810 enum rte_filter_op filter_op, void *arg)
2812 struct rte_eth_dev *dev;
2814 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2816 dev = &rte_eth_devices[port_id];
2817 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2818 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
2822 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
2823 rte_rx_callback_fn fn, void *user_param)
2825 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2826 rte_errno = ENOTSUP;
2829 /* check input parameters */
2830 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2831 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2836 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2844 cb->param = user_param;
2846 /* Add the callbacks in fifo order. */
2847 struct rte_eth_rxtx_callback *tail =
2848 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2851 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2863 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
2864 rte_tx_callback_fn fn, void *user_param)
2866 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2867 rte_errno = ENOTSUP;
2870 /* check input parameters */
2871 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2872 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
2877 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2885 cb->param = user_param;
2887 /* Add the callbacks in fifo order. */
2888 struct rte_eth_rxtx_callback *tail =
2889 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
2892 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
2904 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
2905 struct rte_eth_rxtx_callback *user_cb)
2907 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2910 /* Check input parameters. */
2911 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
2912 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2916 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2917 struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
2918 struct rte_eth_rxtx_callback *prev_cb;
2920 /* Reset head pointer and remove user cb if first in the list. */
2921 if (cb == user_cb) {
2922 dev->post_rx_burst_cbs[queue_id] = user_cb->next;
2926 /* Remove the user cb from the callback list. */
2931 if (cb == user_cb) {
2932 prev_cb->next = user_cb->next;
2936 } while (cb != NULL);
2938 /* Callback wasn't found. */
2943 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
2944 struct rte_eth_rxtx_callback *user_cb)
2946 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2949 /* Check input parameters. */
2950 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
2951 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
2955 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2956 struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
2957 struct rte_eth_rxtx_callback *prev_cb;
2959 /* Reset head pointer and remove user cb if first in the list. */
2960 if (cb == user_cb) {
2961 dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
2965 /* Remove the user cb from the callback list. */
2970 if (cb == user_cb) {
2971 prev_cb->next = user_cb->next;
2975 } while (cb != NULL);
2977 /* Callback wasn't found. */
2982 rte_eth_rx_queue_info_get(uint8_t port_id, uint16_t queue_id,
2983 struct rte_eth_rxq_info *qinfo)
2985 struct rte_eth_dev *dev;
2987 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2992 dev = &rte_eth_devices[port_id];
2993 if (queue_id >= dev->data->nb_rx_queues) {
2994 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2998 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3000 memset(qinfo, 0, sizeof(*qinfo));
3001 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3006 rte_eth_tx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3007 struct rte_eth_txq_info *qinfo)
3009 struct rte_eth_dev *dev;
3011 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3016 dev = &rte_eth_devices[port_id];
3017 if (queue_id >= dev->data->nb_tx_queues) {
3018 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3022 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3024 memset(qinfo, 0, sizeof(*qinfo));
3025 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3030 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3031 struct ether_addr *mc_addr_set,
3032 uint32_t nb_mc_addr)
3034 struct rte_eth_dev *dev;
3036 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3038 dev = &rte_eth_devices[port_id];
3039 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3040 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3044 rte_eth_timesync_enable(uint8_t port_id)
3046 struct rte_eth_dev *dev;
3048 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3049 dev = &rte_eth_devices[port_id];
3051 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3052 return (*dev->dev_ops->timesync_enable)(dev);
3056 rte_eth_timesync_disable(uint8_t port_id)
3058 struct rte_eth_dev *dev;
3060 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3061 dev = &rte_eth_devices[port_id];
3063 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3064 return (*dev->dev_ops->timesync_disable)(dev);
3068 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3071 struct rte_eth_dev *dev;
3073 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3074 dev = &rte_eth_devices[port_id];
3076 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3077 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3081 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3083 struct rte_eth_dev *dev;
3085 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3086 dev = &rte_eth_devices[port_id];
3088 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3089 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3093 rte_eth_timesync_adjust_time(uint8_t port_id, int64_t delta)
3095 struct rte_eth_dev *dev;
3097 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3098 dev = &rte_eth_devices[port_id];
3100 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3101 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3105 rte_eth_timesync_read_time(uint8_t port_id, struct timespec *timestamp)
3107 struct rte_eth_dev *dev;
3109 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3110 dev = &rte_eth_devices[port_id];
3112 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3113 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3117 rte_eth_timesync_write_time(uint8_t port_id, const struct timespec *timestamp)
3119 struct rte_eth_dev *dev;
3121 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3122 dev = &rte_eth_devices[port_id];
3124 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3125 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3129 rte_eth_dev_get_reg_length(uint8_t port_id)
3131 struct rte_eth_dev *dev;
3133 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3135 dev = &rte_eth_devices[port_id];
3136 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg_length, -ENOTSUP);
3137 return (*dev->dev_ops->get_reg_length)(dev);
3141 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3143 struct rte_eth_dev *dev;
3145 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3147 dev = &rte_eth_devices[port_id];
3148 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3149 return (*dev->dev_ops->get_reg)(dev, info);
3153 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3155 struct rte_eth_dev *dev;
3157 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3159 dev = &rte_eth_devices[port_id];
3160 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3161 return (*dev->dev_ops->get_eeprom_length)(dev);
3165 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3167 struct rte_eth_dev *dev;
3169 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3171 dev = &rte_eth_devices[port_id];
3172 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3173 return (*dev->dev_ops->get_eeprom)(dev, info);
3177 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3179 struct rte_eth_dev *dev;
3181 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3183 dev = &rte_eth_devices[port_id];
3184 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3185 return (*dev->dev_ops->set_eeprom)(dev, info);
3189 rte_eth_dev_get_dcb_info(uint8_t port_id,
3190 struct rte_eth_dcb_info *dcb_info)
3192 struct rte_eth_dev *dev;
3194 if (!rte_eth_dev_is_valid_port(port_id)) {
3195 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3199 dev = &rte_eth_devices[port_id];
3200 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3202 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3203 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3207 rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_dev)
3209 if ((eth_dev == NULL) || (pci_dev == NULL)) {
3210 RTE_PMD_DEBUG_TRACE("NULL pointer eth_dev=%p pci_dev=%p\n",
3215 eth_dev->data->dev_flags = 0;
3216 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
3217 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
3218 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_DETACHABLE)
3219 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
3221 eth_dev->data->kdrv = pci_dev->kdrv;
3222 eth_dev->data->numa_node = pci_dev->numa_node;
3223 eth_dev->data->drv_name = pci_dev->driver->name;