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_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
871 const struct rte_eth_conf *dev_conf)
873 struct rte_eth_dev *dev;
874 struct rte_eth_dev_info dev_info;
877 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
879 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
881 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
882 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
886 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
888 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
889 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
893 dev = &rte_eth_devices[port_id];
895 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
896 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
898 if (dev->data->dev_started) {
900 "port %d must be stopped to allow configuration\n", port_id);
905 * Check that the numbers of RX and TX queues are not greater
906 * than the maximum number of RX and TX queues supported by the
909 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
911 if (nb_rx_q == 0 && nb_tx_q == 0) {
912 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d both rx and tx queue cannot be 0\n", port_id);
916 if (nb_rx_q > dev_info.max_rx_queues) {
917 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
918 port_id, nb_rx_q, dev_info.max_rx_queues);
922 if (nb_tx_q > dev_info.max_tx_queues) {
923 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
924 port_id, nb_tx_q, dev_info.max_tx_queues);
928 /* Copy the dev_conf parameter into the dev structure */
929 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
932 * If link state interrupt is enabled, check that the
933 * device supports it.
935 if ((dev_conf->intr_conf.lsc == 1) &&
936 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
937 RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
938 dev->data->drv_name);
943 * If jumbo frames are enabled, check that the maximum RX packet
944 * length is supported by the configured device.
946 if (dev_conf->rxmode.jumbo_frame == 1) {
947 if (dev_conf->rxmode.max_rx_pkt_len >
948 dev_info.max_rx_pktlen) {
949 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
950 " > max valid value %u\n",
952 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
953 (unsigned)dev_info.max_rx_pktlen);
955 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
956 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
957 " < min valid value %u\n",
959 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
960 (unsigned)ETHER_MIN_LEN);
964 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
965 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
966 /* Use default value */
967 dev->data->dev_conf.rxmode.max_rx_pkt_len =
972 * Setup new number of RX/TX queues and reconfigure device.
974 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
976 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
981 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
983 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
985 rte_eth_dev_rx_queue_config(dev, 0);
989 diag = (*dev->dev_ops->dev_configure)(dev);
991 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
993 rte_eth_dev_rx_queue_config(dev, 0);
994 rte_eth_dev_tx_queue_config(dev, 0);
1002 rte_eth_dev_config_restore(uint8_t port_id)
1004 struct rte_eth_dev *dev;
1005 struct rte_eth_dev_info dev_info;
1006 struct ether_addr addr;
1010 dev = &rte_eth_devices[port_id];
1012 rte_eth_dev_info_get(port_id, &dev_info);
1014 if (RTE_ETH_DEV_SRIOV(dev).active)
1015 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
1017 /* replay MAC address configuration */
1018 for (i = 0; i < dev_info.max_mac_addrs; i++) {
1019 addr = dev->data->mac_addrs[i];
1021 /* skip zero address */
1022 if (is_zero_ether_addr(&addr))
1025 /* add address to the hardware */
1026 if (*dev->dev_ops->mac_addr_add &&
1027 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
1028 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
1030 RTE_PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
1032 /* exit the loop but not return an error */
1037 /* replay promiscuous configuration */
1038 if (rte_eth_promiscuous_get(port_id) == 1)
1039 rte_eth_promiscuous_enable(port_id);
1040 else if (rte_eth_promiscuous_get(port_id) == 0)
1041 rte_eth_promiscuous_disable(port_id);
1043 /* replay all multicast configuration */
1044 if (rte_eth_allmulticast_get(port_id) == 1)
1045 rte_eth_allmulticast_enable(port_id);
1046 else if (rte_eth_allmulticast_get(port_id) == 0)
1047 rte_eth_allmulticast_disable(port_id);
1051 rte_eth_dev_start(uint8_t port_id)
1053 struct rte_eth_dev *dev;
1056 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1058 dev = &rte_eth_devices[port_id];
1060 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1062 if (dev->data->dev_started != 0) {
1063 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1064 " already started\n",
1069 diag = (*dev->dev_ops->dev_start)(dev);
1071 dev->data->dev_started = 1;
1075 rte_eth_dev_config_restore(port_id);
1077 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1078 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1079 (*dev->dev_ops->link_update)(dev, 0);
1085 rte_eth_dev_stop(uint8_t port_id)
1087 struct rte_eth_dev *dev;
1089 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1090 dev = &rte_eth_devices[port_id];
1092 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1094 if (dev->data->dev_started == 0) {
1095 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1096 " already stopped\n",
1101 dev->data->dev_started = 0;
1102 (*dev->dev_ops->dev_stop)(dev);
1106 rte_eth_dev_set_link_up(uint8_t port_id)
1108 struct rte_eth_dev *dev;
1110 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1112 dev = &rte_eth_devices[port_id];
1114 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1115 return (*dev->dev_ops->dev_set_link_up)(dev);
1119 rte_eth_dev_set_link_down(uint8_t port_id)
1121 struct rte_eth_dev *dev;
1123 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1125 dev = &rte_eth_devices[port_id];
1127 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1128 return (*dev->dev_ops->dev_set_link_down)(dev);
1132 rte_eth_dev_close(uint8_t port_id)
1134 struct rte_eth_dev *dev;
1136 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1137 dev = &rte_eth_devices[port_id];
1139 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1140 dev->data->dev_started = 0;
1141 (*dev->dev_ops->dev_close)(dev);
1143 rte_free(dev->data->rx_queues);
1144 dev->data->rx_queues = NULL;
1145 rte_free(dev->data->tx_queues);
1146 dev->data->tx_queues = NULL;
1150 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1151 uint16_t nb_rx_desc, unsigned int socket_id,
1152 const struct rte_eth_rxconf *rx_conf,
1153 struct rte_mempool *mp)
1156 uint32_t mbp_buf_size;
1157 struct rte_eth_dev *dev;
1158 struct rte_eth_dev_info dev_info;
1160 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1162 dev = &rte_eth_devices[port_id];
1163 if (rx_queue_id >= dev->data->nb_rx_queues) {
1164 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1168 if (dev->data->dev_started) {
1169 RTE_PMD_DEBUG_TRACE(
1170 "port %d must be stopped to allow configuration\n", port_id);
1174 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1175 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1178 * Check the size of the mbuf data buffer.
1179 * This value must be provided in the private data of the memory pool.
1180 * First check that the memory pool has a valid private data.
1182 rte_eth_dev_info_get(port_id, &dev_info);
1183 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1184 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1185 mp->name, (int) mp->private_data_size,
1186 (int) sizeof(struct rte_pktmbuf_pool_private));
1189 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1191 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1192 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1193 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1197 (int)(RTE_PKTMBUF_HEADROOM +
1198 dev_info.min_rx_bufsize),
1199 (int)RTE_PKTMBUF_HEADROOM,
1200 (int)dev_info.min_rx_bufsize);
1204 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1205 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1206 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1208 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1209 "should be: <= %hu, = %hu, and a product of %hu\n",
1211 dev_info.rx_desc_lim.nb_max,
1212 dev_info.rx_desc_lim.nb_min,
1213 dev_info.rx_desc_lim.nb_align);
1217 if (rx_conf == NULL)
1218 rx_conf = &dev_info.default_rxconf;
1220 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1221 socket_id, rx_conf, mp);
1223 if (!dev->data->min_rx_buf_size ||
1224 dev->data->min_rx_buf_size > mbp_buf_size)
1225 dev->data->min_rx_buf_size = mbp_buf_size;
1232 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1233 uint16_t nb_tx_desc, unsigned int socket_id,
1234 const struct rte_eth_txconf *tx_conf)
1236 struct rte_eth_dev *dev;
1237 struct rte_eth_dev_info dev_info;
1239 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1241 dev = &rte_eth_devices[port_id];
1242 if (tx_queue_id >= dev->data->nb_tx_queues) {
1243 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1247 if (dev->data->dev_started) {
1248 RTE_PMD_DEBUG_TRACE(
1249 "port %d must be stopped to allow configuration\n", port_id);
1253 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1254 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1256 rte_eth_dev_info_get(port_id, &dev_info);
1258 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1259 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1260 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1261 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1262 "should be: <= %hu, = %hu, and a product of %hu\n",
1264 dev_info.tx_desc_lim.nb_max,
1265 dev_info.tx_desc_lim.nb_min,
1266 dev_info.tx_desc_lim.nb_align);
1270 if (tx_conf == NULL)
1271 tx_conf = &dev_info.default_txconf;
1273 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1274 socket_id, tx_conf);
1278 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
1279 void *userdata __rte_unused)
1283 for (i = 0; i < unsent; i++)
1284 rte_pktmbuf_free(pkts[i]);
1288 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
1291 uint64_t *count = userdata;
1294 for (i = 0; i < unsent; i++)
1295 rte_pktmbuf_free(pkts[i]);
1301 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
1302 buffer_tx_error_fn cbfn, void *userdata)
1304 buffer->error_callback = cbfn;
1305 buffer->error_userdata = userdata;
1310 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
1315 buffer->size = size;
1316 if (buffer->error_callback == NULL)
1317 rte_eth_tx_buffer_set_err_callback(buffer,
1318 rte_eth_tx_buffer_drop_callback, NULL);
1324 rte_eth_promiscuous_enable(uint8_t port_id)
1326 struct rte_eth_dev *dev;
1328 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1329 dev = &rte_eth_devices[port_id];
1331 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1332 (*dev->dev_ops->promiscuous_enable)(dev);
1333 dev->data->promiscuous = 1;
1337 rte_eth_promiscuous_disable(uint8_t port_id)
1339 struct rte_eth_dev *dev;
1341 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1342 dev = &rte_eth_devices[port_id];
1344 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1345 dev->data->promiscuous = 0;
1346 (*dev->dev_ops->promiscuous_disable)(dev);
1350 rte_eth_promiscuous_get(uint8_t port_id)
1352 struct rte_eth_dev *dev;
1354 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1356 dev = &rte_eth_devices[port_id];
1357 return dev->data->promiscuous;
1361 rte_eth_allmulticast_enable(uint8_t port_id)
1363 struct rte_eth_dev *dev;
1365 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1366 dev = &rte_eth_devices[port_id];
1368 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1369 (*dev->dev_ops->allmulticast_enable)(dev);
1370 dev->data->all_multicast = 1;
1374 rte_eth_allmulticast_disable(uint8_t port_id)
1376 struct rte_eth_dev *dev;
1378 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1379 dev = &rte_eth_devices[port_id];
1381 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1382 dev->data->all_multicast = 0;
1383 (*dev->dev_ops->allmulticast_disable)(dev);
1387 rte_eth_allmulticast_get(uint8_t port_id)
1389 struct rte_eth_dev *dev;
1391 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1393 dev = &rte_eth_devices[port_id];
1394 return dev->data->all_multicast;
1398 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1399 struct rte_eth_link *link)
1401 struct rte_eth_link *dst = link;
1402 struct rte_eth_link *src = &(dev->data->dev_link);
1404 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1405 *(uint64_t *)src) == 0)
1412 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1414 struct rte_eth_dev *dev;
1416 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1417 dev = &rte_eth_devices[port_id];
1419 if (dev->data->dev_conf.intr_conf.lsc != 0)
1420 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1422 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1423 (*dev->dev_ops->link_update)(dev, 1);
1424 *eth_link = dev->data->dev_link;
1429 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1431 struct rte_eth_dev *dev;
1433 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1434 dev = &rte_eth_devices[port_id];
1436 if (dev->data->dev_conf.intr_conf.lsc != 0)
1437 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1439 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1440 (*dev->dev_ops->link_update)(dev, 0);
1441 *eth_link = dev->data->dev_link;
1446 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1448 struct rte_eth_dev *dev;
1450 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1452 dev = &rte_eth_devices[port_id];
1453 memset(stats, 0, sizeof(*stats));
1455 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1456 (*dev->dev_ops->stats_get)(dev, stats);
1457 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1462 rte_eth_stats_reset(uint8_t port_id)
1464 struct rte_eth_dev *dev;
1466 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1467 dev = &rte_eth_devices[port_id];
1469 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1470 (*dev->dev_ops->stats_reset)(dev);
1471 dev->data->rx_mbuf_alloc_failed = 0;
1474 /* retrieve ethdev extended statistics */
1476 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1479 struct rte_eth_stats eth_stats;
1480 struct rte_eth_dev *dev;
1481 unsigned count = 0, i, q;
1483 uint64_t val, *stats_ptr;
1485 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1487 dev = &rte_eth_devices[port_id];
1489 /* Return generic statistics */
1490 count = RTE_NB_STATS + (dev->data->nb_rx_queues * RTE_NB_RXQ_STATS) +
1491 (dev->data->nb_tx_queues * RTE_NB_TXQ_STATS);
1493 /* implemented by the driver */
1494 if (dev->dev_ops->xstats_get != NULL) {
1495 /* Retrieve the xstats from the driver at the end of the
1498 xcount = (*dev->dev_ops->xstats_get)(dev,
1499 xstats ? xstats + count : NULL,
1500 (n > count) ? n - count : 0);
1506 if (n < count + xcount)
1507 return count + xcount;
1509 /* now fill the xstats structure */
1511 rte_eth_stats_get(port_id, ð_stats);
1514 for (i = 0; i < RTE_NB_STATS; i++) {
1515 stats_ptr = RTE_PTR_ADD(ð_stats,
1516 rte_stats_strings[i].offset);
1518 snprintf(xstats[count].name, sizeof(xstats[count].name),
1519 "%s", rte_stats_strings[i].name);
1520 xstats[count++].value = val;
1524 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1525 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1526 stats_ptr = RTE_PTR_ADD(ð_stats,
1527 rte_rxq_stats_strings[i].offset +
1528 q * sizeof(uint64_t));
1530 snprintf(xstats[count].name, sizeof(xstats[count].name),
1532 rte_rxq_stats_strings[i].name);
1533 xstats[count++].value = val;
1538 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1539 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1540 stats_ptr = RTE_PTR_ADD(ð_stats,
1541 rte_txq_stats_strings[i].offset +
1542 q * sizeof(uint64_t));
1544 snprintf(xstats[count].name, sizeof(xstats[count].name),
1546 rte_txq_stats_strings[i].name);
1547 xstats[count++].value = val;
1551 return count + xcount;
1554 /* reset ethdev extended statistics */
1556 rte_eth_xstats_reset(uint8_t port_id)
1558 struct rte_eth_dev *dev;
1560 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1561 dev = &rte_eth_devices[port_id];
1563 /* implemented by the driver */
1564 if (dev->dev_ops->xstats_reset != NULL) {
1565 (*dev->dev_ops->xstats_reset)(dev);
1569 /* fallback to default */
1570 rte_eth_stats_reset(port_id);
1574 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1577 struct rte_eth_dev *dev;
1579 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1581 dev = &rte_eth_devices[port_id];
1583 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1584 return (*dev->dev_ops->queue_stats_mapping_set)
1585 (dev, queue_id, stat_idx, is_rx);
1590 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1593 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1599 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1602 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1608 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1610 struct rte_eth_dev *dev;
1611 const struct rte_eth_desc_lim lim = {
1612 .nb_max = UINT16_MAX,
1617 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1618 dev = &rte_eth_devices[port_id];
1620 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1621 dev_info->rx_desc_lim = lim;
1622 dev_info->tx_desc_lim = lim;
1624 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1625 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1626 dev_info->pci_dev = dev->pci_dev;
1627 dev_info->driver_name = dev->data->drv_name;
1631 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1633 struct rte_eth_dev *dev;
1635 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1636 dev = &rte_eth_devices[port_id];
1637 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1642 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1644 struct rte_eth_dev *dev;
1646 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1648 dev = &rte_eth_devices[port_id];
1649 *mtu = dev->data->mtu;
1654 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1657 struct rte_eth_dev *dev;
1659 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1660 dev = &rte_eth_devices[port_id];
1661 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1663 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1665 dev->data->mtu = mtu;
1671 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1673 struct rte_eth_dev *dev;
1675 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1676 dev = &rte_eth_devices[port_id];
1677 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1678 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1682 if (vlan_id > 4095) {
1683 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1684 port_id, (unsigned) vlan_id);
1687 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1689 return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1693 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1695 struct rte_eth_dev *dev;
1697 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1698 dev = &rte_eth_devices[port_id];
1699 if (rx_queue_id >= dev->data->nb_rx_queues) {
1700 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1704 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1705 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1711 rte_eth_dev_set_vlan_ether_type(uint8_t port_id,
1712 enum rte_vlan_type vlan_type,
1715 struct rte_eth_dev *dev;
1717 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1718 dev = &rte_eth_devices[port_id];
1719 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1721 return (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type, tpid);
1725 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1727 struct rte_eth_dev *dev;
1732 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1733 dev = &rte_eth_devices[port_id];
1735 /*check which option changed by application*/
1736 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1737 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1739 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1740 mask |= ETH_VLAN_STRIP_MASK;
1743 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1744 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1746 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1747 mask |= ETH_VLAN_FILTER_MASK;
1750 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1751 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1753 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1754 mask |= ETH_VLAN_EXTEND_MASK;
1761 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1762 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1768 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1770 struct rte_eth_dev *dev;
1773 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1774 dev = &rte_eth_devices[port_id];
1776 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1777 ret |= ETH_VLAN_STRIP_OFFLOAD;
1779 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1780 ret |= ETH_VLAN_FILTER_OFFLOAD;
1782 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1783 ret |= ETH_VLAN_EXTEND_OFFLOAD;
1789 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1791 struct rte_eth_dev *dev;
1793 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1794 dev = &rte_eth_devices[port_id];
1795 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1796 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1802 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1804 struct rte_eth_dev *dev;
1806 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1807 dev = &rte_eth_devices[port_id];
1808 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1809 memset(fc_conf, 0, sizeof(*fc_conf));
1810 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1814 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1816 struct rte_eth_dev *dev;
1818 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1819 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1820 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1824 dev = &rte_eth_devices[port_id];
1825 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1826 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1830 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1832 struct rte_eth_dev *dev;
1834 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1835 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1836 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1840 dev = &rte_eth_devices[port_id];
1841 /* High water, low water validation are device specific */
1842 if (*dev->dev_ops->priority_flow_ctrl_set)
1843 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1848 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
1856 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
1857 RTE_PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
1858 RTE_RETA_GROUP_SIZE);
1862 num = reta_size / RTE_RETA_GROUP_SIZE;
1863 for (i = 0; i < num; i++) {
1864 if (reta_conf[i].mask)
1872 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
1876 uint16_t i, idx, shift;
1882 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
1886 for (i = 0; i < reta_size; i++) {
1887 idx = i / RTE_RETA_GROUP_SIZE;
1888 shift = i % RTE_RETA_GROUP_SIZE;
1889 if ((reta_conf[idx].mask & (1ULL << shift)) &&
1890 (reta_conf[idx].reta[shift] >= max_rxq)) {
1891 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
1892 "the maximum rxq index: %u\n", idx, shift,
1893 reta_conf[idx].reta[shift], max_rxq);
1902 rte_eth_dev_rss_reta_update(uint8_t port_id,
1903 struct rte_eth_rss_reta_entry64 *reta_conf,
1906 struct rte_eth_dev *dev;
1909 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1910 /* Check mask bits */
1911 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
1915 dev = &rte_eth_devices[port_id];
1917 /* Check entry value */
1918 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
1919 dev->data->nb_rx_queues);
1923 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
1924 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
1928 rte_eth_dev_rss_reta_query(uint8_t port_id,
1929 struct rte_eth_rss_reta_entry64 *reta_conf,
1932 struct rte_eth_dev *dev;
1935 if (port_id >= nb_ports) {
1936 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1940 /* Check mask bits */
1941 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
1945 dev = &rte_eth_devices[port_id];
1946 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
1947 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
1951 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
1953 struct rte_eth_dev *dev;
1954 uint16_t rss_hash_protos;
1956 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1957 rss_hash_protos = rss_conf->rss_hf;
1958 if ((rss_hash_protos != 0) &&
1959 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
1960 RTE_PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
1964 dev = &rte_eth_devices[port_id];
1965 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
1966 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
1970 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
1971 struct rte_eth_rss_conf *rss_conf)
1973 struct rte_eth_dev *dev;
1975 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1976 dev = &rte_eth_devices[port_id];
1977 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
1978 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
1982 rte_eth_dev_udp_tunnel_port_add(uint8_t port_id,
1983 struct rte_eth_udp_tunnel *udp_tunnel)
1985 struct rte_eth_dev *dev;
1987 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1988 if (udp_tunnel == NULL) {
1989 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
1993 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
1994 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
1998 dev = &rte_eth_devices[port_id];
1999 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
2000 return (*dev->dev_ops->udp_tunnel_port_add)(dev, udp_tunnel);
2004 rte_eth_dev_udp_tunnel_port_delete(uint8_t port_id,
2005 struct rte_eth_udp_tunnel *udp_tunnel)
2007 struct rte_eth_dev *dev;
2009 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2010 dev = &rte_eth_devices[port_id];
2012 if (udp_tunnel == NULL) {
2013 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2017 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2018 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2022 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
2023 return (*dev->dev_ops->udp_tunnel_port_del)(dev, udp_tunnel);
2027 rte_eth_led_on(uint8_t port_id)
2029 struct rte_eth_dev *dev;
2031 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2032 dev = &rte_eth_devices[port_id];
2033 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2034 return (*dev->dev_ops->dev_led_on)(dev);
2038 rte_eth_led_off(uint8_t port_id)
2040 struct rte_eth_dev *dev;
2042 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2043 dev = &rte_eth_devices[port_id];
2044 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2045 return (*dev->dev_ops->dev_led_off)(dev);
2049 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2053 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2055 struct rte_eth_dev_info dev_info;
2056 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2059 rte_eth_dev_info_get(port_id, &dev_info);
2061 for (i = 0; i < dev_info.max_mac_addrs; i++)
2062 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2068 static const struct ether_addr null_mac_addr;
2071 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2074 struct rte_eth_dev *dev;
2078 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2079 dev = &rte_eth_devices[port_id];
2080 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2082 if (is_zero_ether_addr(addr)) {
2083 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2087 if (pool >= ETH_64_POOLS) {
2088 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2092 index = get_mac_addr_index(port_id, addr);
2094 index = get_mac_addr_index(port_id, &null_mac_addr);
2096 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2101 pool_mask = dev->data->mac_pool_sel[index];
2103 /* Check if both MAC address and pool is already there, and do nothing */
2104 if (pool_mask & (1ULL << pool))
2109 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2111 /* Update address in NIC data structure */
2112 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2114 /* Update pool bitmap in NIC data structure */
2115 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2121 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2123 struct rte_eth_dev *dev;
2126 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2127 dev = &rte_eth_devices[port_id];
2128 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2130 index = get_mac_addr_index(port_id, addr);
2132 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2134 } else if (index < 0)
2135 return 0; /* Do nothing if address wasn't found */
2138 (*dev->dev_ops->mac_addr_remove)(dev, index);
2140 /* Update address in NIC data structure */
2141 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2143 /* reset pool bitmap */
2144 dev->data->mac_pool_sel[index] = 0;
2150 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2152 struct rte_eth_dev *dev;
2154 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2156 if (!is_valid_assigned_ether_addr(addr))
2159 dev = &rte_eth_devices[port_id];
2160 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2162 /* Update default address in NIC data structure */
2163 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2165 (*dev->dev_ops->mac_addr_set)(dev, addr);
2171 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2172 uint16_t rx_mode, uint8_t on)
2175 struct rte_eth_dev *dev;
2176 struct rte_eth_dev_info dev_info;
2178 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2180 dev = &rte_eth_devices[port_id];
2181 rte_eth_dev_info_get(port_id, &dev_info);
2183 num_vfs = dev_info.max_vfs;
2185 RTE_PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2190 RTE_PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2193 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2194 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2198 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2202 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2204 struct rte_eth_dev_info dev_info;
2205 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2208 rte_eth_dev_info_get(port_id, &dev_info);
2209 if (!dev->data->hash_mac_addrs)
2212 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2213 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2214 ETHER_ADDR_LEN) == 0)
2221 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2226 struct rte_eth_dev *dev;
2228 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2230 dev = &rte_eth_devices[port_id];
2231 if (is_zero_ether_addr(addr)) {
2232 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2237 index = get_hash_mac_addr_index(port_id, addr);
2238 /* Check if it's already there, and do nothing */
2239 if ((index >= 0) && (on))
2244 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2245 "set in UTA\n", port_id);
2249 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2251 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2257 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2258 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2260 /* Update address in NIC data structure */
2262 ether_addr_copy(addr,
2263 &dev->data->hash_mac_addrs[index]);
2265 ether_addr_copy(&null_mac_addr,
2266 &dev->data->hash_mac_addrs[index]);
2273 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2275 struct rte_eth_dev *dev;
2277 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2279 dev = &rte_eth_devices[port_id];
2281 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2282 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2286 rte_eth_dev_set_vf_rx(uint8_t port_id, uint16_t vf, uint8_t on)
2289 struct rte_eth_dev *dev;
2290 struct rte_eth_dev_info dev_info;
2292 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2294 dev = &rte_eth_devices[port_id];
2295 rte_eth_dev_info_get(port_id, &dev_info);
2297 num_vfs = dev_info.max_vfs;
2299 RTE_PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2303 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2304 return (*dev->dev_ops->set_vf_rx)(dev, vf, on);
2308 rte_eth_dev_set_vf_tx(uint8_t port_id, uint16_t vf, uint8_t on)
2311 struct rte_eth_dev *dev;
2312 struct rte_eth_dev_info dev_info;
2314 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2316 dev = &rte_eth_devices[port_id];
2317 rte_eth_dev_info_get(port_id, &dev_info);
2319 num_vfs = dev_info.max_vfs;
2321 RTE_PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2325 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2326 return (*dev->dev_ops->set_vf_tx)(dev, vf, on);
2330 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2331 uint64_t vf_mask, uint8_t vlan_on)
2333 struct rte_eth_dev *dev;
2335 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2337 dev = &rte_eth_devices[port_id];
2339 if (vlan_id > ETHER_MAX_VLAN_ID) {
2340 RTE_PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2346 RTE_PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2350 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2351 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2355 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2358 struct rte_eth_dev *dev;
2359 struct rte_eth_dev_info dev_info;
2360 struct rte_eth_link link;
2362 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2364 dev = &rte_eth_devices[port_id];
2365 rte_eth_dev_info_get(port_id, &dev_info);
2366 link = dev->data->dev_link;
2368 if (queue_idx > dev_info.max_tx_queues) {
2369 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2370 "invalid queue id=%d\n", port_id, queue_idx);
2374 if (tx_rate > link.link_speed) {
2375 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2376 "bigger than link speed= %d\n",
2377 tx_rate, link.link_speed);
2381 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2382 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2385 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2388 struct rte_eth_dev *dev;
2389 struct rte_eth_dev_info dev_info;
2390 struct rte_eth_link link;
2395 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2397 dev = &rte_eth_devices[port_id];
2398 rte_eth_dev_info_get(port_id, &dev_info);
2399 link = dev->data->dev_link;
2401 if (vf > dev_info.max_vfs) {
2402 RTE_PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2403 "invalid vf id=%d\n", port_id, vf);
2407 if (tx_rate > link.link_speed) {
2408 RTE_PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2409 "bigger than link speed= %d\n",
2410 tx_rate, link.link_speed);
2414 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2415 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2419 rte_eth_mirror_rule_set(uint8_t port_id,
2420 struct rte_eth_mirror_conf *mirror_conf,
2421 uint8_t rule_id, uint8_t on)
2423 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2425 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2426 if (mirror_conf->rule_type == 0) {
2427 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2431 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2432 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2437 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2438 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2439 (mirror_conf->pool_mask == 0)) {
2440 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2444 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2445 mirror_conf->vlan.vlan_mask == 0) {
2446 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2450 dev = &rte_eth_devices[port_id];
2451 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2453 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2457 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2459 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2461 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2463 dev = &rte_eth_devices[port_id];
2464 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2466 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2470 rte_eth_dev_callback_register(uint8_t port_id,
2471 enum rte_eth_event_type event,
2472 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2474 struct rte_eth_dev *dev;
2475 struct rte_eth_dev_callback *user_cb;
2480 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2482 dev = &rte_eth_devices[port_id];
2483 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2485 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2486 if (user_cb->cb_fn == cb_fn &&
2487 user_cb->cb_arg == cb_arg &&
2488 user_cb->event == event) {
2493 /* create a new callback. */
2494 if (user_cb == NULL)
2495 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2496 sizeof(struct rte_eth_dev_callback), 0);
2497 if (user_cb != NULL) {
2498 user_cb->cb_fn = cb_fn;
2499 user_cb->cb_arg = cb_arg;
2500 user_cb->event = event;
2501 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2504 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2505 return (user_cb == NULL) ? -ENOMEM : 0;
2509 rte_eth_dev_callback_unregister(uint8_t port_id,
2510 enum rte_eth_event_type event,
2511 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2514 struct rte_eth_dev *dev;
2515 struct rte_eth_dev_callback *cb, *next;
2520 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2522 dev = &rte_eth_devices[port_id];
2523 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2526 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2528 next = TAILQ_NEXT(cb, next);
2530 if (cb->cb_fn != cb_fn || cb->event != event ||
2531 (cb->cb_arg != (void *)-1 &&
2532 cb->cb_arg != cb_arg))
2536 * if this callback is not executing right now,
2539 if (cb->active == 0) {
2540 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2547 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2552 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2553 enum rte_eth_event_type event)
2555 struct rte_eth_dev_callback *cb_lst;
2556 struct rte_eth_dev_callback dev_cb;
2558 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2559 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2560 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2564 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2565 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2567 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2570 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2574 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
2577 struct rte_eth_dev *dev;
2578 struct rte_intr_handle *intr_handle;
2582 if (!rte_eth_dev_is_valid_port(port_id)) {
2583 RTE_PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
2587 dev = &rte_eth_devices[port_id];
2588 intr_handle = &dev->pci_dev->intr_handle;
2589 if (!intr_handle->intr_vec) {
2590 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2594 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2595 vec = intr_handle->intr_vec[qid];
2596 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2597 if (rc && rc != -EEXIST) {
2598 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2599 " op %d epfd %d vec %u\n",
2600 port_id, qid, op, epfd, vec);
2607 const struct rte_memzone *
2608 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2609 uint16_t queue_id, size_t size, unsigned align,
2612 char z_name[RTE_MEMZONE_NAMESIZE];
2613 const struct rte_memzone *mz;
2615 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2616 dev->driver->pci_drv.name, ring_name,
2617 dev->data->port_id, queue_id);
2619 mz = rte_memzone_lookup(z_name);
2623 if (rte_xen_dom0_supported())
2624 return rte_memzone_reserve_bounded(z_name, size, socket_id,
2625 0, align, RTE_PGSIZE_2M);
2627 return rte_memzone_reserve_aligned(z_name, size, socket_id,
2632 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
2633 int epfd, int op, void *data)
2636 struct rte_eth_dev *dev;
2637 struct rte_intr_handle *intr_handle;
2640 if (!rte_eth_dev_is_valid_port(port_id)) {
2641 RTE_PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
2645 dev = &rte_eth_devices[port_id];
2646 if (queue_id >= dev->data->nb_rx_queues) {
2647 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
2651 intr_handle = &dev->pci_dev->intr_handle;
2652 if (!intr_handle->intr_vec) {
2653 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2657 vec = intr_handle->intr_vec[queue_id];
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, queue_id, op, epfd, vec);
2670 rte_eth_dev_rx_intr_enable(uint8_t port_id,
2673 struct rte_eth_dev *dev;
2675 if (!rte_eth_dev_is_valid_port(port_id)) {
2676 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2680 dev = &rte_eth_devices[port_id];
2682 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
2683 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
2687 rte_eth_dev_rx_intr_disable(uint8_t port_id,
2690 struct rte_eth_dev *dev;
2692 if (!rte_eth_dev_is_valid_port(port_id)) {
2693 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2697 dev = &rte_eth_devices[port_id];
2699 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
2700 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
2703 #ifdef RTE_NIC_BYPASS
2704 int rte_eth_dev_bypass_init(uint8_t port_id)
2706 struct rte_eth_dev *dev;
2708 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2710 dev = &rte_eth_devices[port_id];
2711 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2712 (*dev->dev_ops->bypass_init)(dev);
2717 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2719 struct rte_eth_dev *dev;
2721 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2723 dev = &rte_eth_devices[port_id];
2724 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2725 (*dev->dev_ops->bypass_state_show)(dev, state);
2730 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2732 struct rte_eth_dev *dev;
2734 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2736 dev = &rte_eth_devices[port_id];
2737 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2738 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2743 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2745 struct rte_eth_dev *dev;
2747 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2749 dev = &rte_eth_devices[port_id];
2750 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2751 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2756 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2758 struct rte_eth_dev *dev;
2760 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2762 dev = &rte_eth_devices[port_id];
2764 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2765 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2770 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2772 struct rte_eth_dev *dev;
2774 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2776 dev = &rte_eth_devices[port_id];
2778 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2779 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2784 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2786 struct rte_eth_dev *dev;
2788 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2790 dev = &rte_eth_devices[port_id];
2792 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2793 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2798 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2800 struct rte_eth_dev *dev;
2802 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2804 dev = &rte_eth_devices[port_id];
2806 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2807 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2812 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2814 struct rte_eth_dev *dev;
2816 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2818 dev = &rte_eth_devices[port_id];
2820 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2821 (*dev->dev_ops->bypass_wd_reset)(dev);
2827 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
2829 struct rte_eth_dev *dev;
2831 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2833 dev = &rte_eth_devices[port_id];
2834 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2835 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
2836 RTE_ETH_FILTER_NOP, NULL);
2840 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
2841 enum rte_filter_op filter_op, void *arg)
2843 struct rte_eth_dev *dev;
2845 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2847 dev = &rte_eth_devices[port_id];
2848 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2849 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
2853 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
2854 rte_rx_callback_fn fn, void *user_param)
2856 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2857 rte_errno = ENOTSUP;
2860 /* check input parameters */
2861 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2862 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2867 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2875 cb->param = user_param;
2877 /* Add the callbacks in fifo order. */
2878 struct rte_eth_rxtx_callback *tail =
2879 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2882 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2894 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
2895 rte_tx_callback_fn fn, void *user_param)
2897 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2898 rte_errno = ENOTSUP;
2901 /* check input parameters */
2902 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2903 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
2908 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2916 cb->param = user_param;
2918 /* Add the callbacks in fifo order. */
2919 struct rte_eth_rxtx_callback *tail =
2920 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
2923 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
2935 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
2936 struct rte_eth_rxtx_callback *user_cb)
2938 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2941 /* Check input parameters. */
2942 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
2943 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2947 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2948 struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
2949 struct rte_eth_rxtx_callback *prev_cb;
2951 /* Reset head pointer and remove user cb if first in the list. */
2952 if (cb == user_cb) {
2953 dev->post_rx_burst_cbs[queue_id] = user_cb->next;
2957 /* Remove the user cb from the callback list. */
2962 if (cb == user_cb) {
2963 prev_cb->next = user_cb->next;
2967 } while (cb != NULL);
2969 /* Callback wasn't found. */
2974 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
2975 struct rte_eth_rxtx_callback *user_cb)
2977 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2980 /* Check input parameters. */
2981 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
2982 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
2986 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2987 struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
2988 struct rte_eth_rxtx_callback *prev_cb;
2990 /* Reset head pointer and remove user cb if first in the list. */
2991 if (cb == user_cb) {
2992 dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
2996 /* Remove the user cb from the callback list. */
3001 if (cb == user_cb) {
3002 prev_cb->next = user_cb->next;
3006 } while (cb != NULL);
3008 /* Callback wasn't found. */
3013 rte_eth_rx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3014 struct rte_eth_rxq_info *qinfo)
3016 struct rte_eth_dev *dev;
3018 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3023 dev = &rte_eth_devices[port_id];
3024 if (queue_id >= dev->data->nb_rx_queues) {
3025 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3029 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3031 memset(qinfo, 0, sizeof(*qinfo));
3032 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3037 rte_eth_tx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3038 struct rte_eth_txq_info *qinfo)
3040 struct rte_eth_dev *dev;
3042 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3047 dev = &rte_eth_devices[port_id];
3048 if (queue_id >= dev->data->nb_tx_queues) {
3049 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3053 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3055 memset(qinfo, 0, sizeof(*qinfo));
3056 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3061 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3062 struct ether_addr *mc_addr_set,
3063 uint32_t nb_mc_addr)
3065 struct rte_eth_dev *dev;
3067 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3069 dev = &rte_eth_devices[port_id];
3070 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3071 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3075 rte_eth_timesync_enable(uint8_t port_id)
3077 struct rte_eth_dev *dev;
3079 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3080 dev = &rte_eth_devices[port_id];
3082 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3083 return (*dev->dev_ops->timesync_enable)(dev);
3087 rte_eth_timesync_disable(uint8_t port_id)
3089 struct rte_eth_dev *dev;
3091 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3092 dev = &rte_eth_devices[port_id];
3094 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3095 return (*dev->dev_ops->timesync_disable)(dev);
3099 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3102 struct rte_eth_dev *dev;
3104 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3105 dev = &rte_eth_devices[port_id];
3107 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3108 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3112 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3114 struct rte_eth_dev *dev;
3116 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3117 dev = &rte_eth_devices[port_id];
3119 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3120 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3124 rte_eth_timesync_adjust_time(uint8_t port_id, int64_t delta)
3126 struct rte_eth_dev *dev;
3128 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3129 dev = &rte_eth_devices[port_id];
3131 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3132 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3136 rte_eth_timesync_read_time(uint8_t port_id, struct timespec *timestamp)
3138 struct rte_eth_dev *dev;
3140 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3141 dev = &rte_eth_devices[port_id];
3143 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3144 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3148 rte_eth_timesync_write_time(uint8_t port_id, const struct timespec *timestamp)
3150 struct rte_eth_dev *dev;
3152 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3153 dev = &rte_eth_devices[port_id];
3155 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3156 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3160 rte_eth_dev_get_reg_length(uint8_t port_id)
3162 struct rte_eth_dev *dev;
3164 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3166 dev = &rte_eth_devices[port_id];
3167 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg_length, -ENOTSUP);
3168 return (*dev->dev_ops->get_reg_length)(dev);
3172 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3174 struct rte_eth_dev *dev;
3176 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3178 dev = &rte_eth_devices[port_id];
3179 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3180 return (*dev->dev_ops->get_reg)(dev, info);
3184 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3186 struct rte_eth_dev *dev;
3188 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3190 dev = &rte_eth_devices[port_id];
3191 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3192 return (*dev->dev_ops->get_eeprom_length)(dev);
3196 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3198 struct rte_eth_dev *dev;
3200 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3202 dev = &rte_eth_devices[port_id];
3203 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3204 return (*dev->dev_ops->get_eeprom)(dev, info);
3208 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3210 struct rte_eth_dev *dev;
3212 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3214 dev = &rte_eth_devices[port_id];
3215 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3216 return (*dev->dev_ops->set_eeprom)(dev, info);
3220 rte_eth_dev_get_dcb_info(uint8_t port_id,
3221 struct rte_eth_dcb_info *dcb_info)
3223 struct rte_eth_dev *dev;
3225 if (!rte_eth_dev_is_valid_port(port_id)) {
3226 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3230 dev = &rte_eth_devices[port_id];
3231 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3233 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3234 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3238 rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_dev)
3240 if ((eth_dev == NULL) || (pci_dev == NULL)) {
3241 RTE_PMD_DEBUG_TRACE("NULL pointer eth_dev=%p pci_dev=%p\n",
3246 eth_dev->data->dev_flags = 0;
3247 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
3248 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
3249 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_DETACHABLE)
3250 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
3252 eth_dev->data->kdrv = pci_dev->kdrv;
3253 eth_dev->data->numa_node = pci_dev->numa_node;
3254 eth_dev->data->drv_name = pci_dev->driver->name;
3258 rte_eth_dev_l2_tunnel_eth_type_conf(uint8_t port_id,
3259 struct rte_eth_l2_tunnel_conf *l2_tunnel)
3261 struct rte_eth_dev *dev;
3263 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3264 if (l2_tunnel == NULL) {
3265 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3269 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3270 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
3274 dev = &rte_eth_devices[port_id];
3275 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
3277 return (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev, l2_tunnel);
3281 rte_eth_dev_l2_tunnel_offload_set(uint8_t port_id,
3282 struct rte_eth_l2_tunnel_conf *l2_tunnel,
3286 struct rte_eth_dev *dev;
3288 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3290 if (l2_tunnel == NULL) {
3291 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3295 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3296 RTE_PMD_DEBUG_TRACE("Invalid tunnel type.\n");
3301 RTE_PMD_DEBUG_TRACE("Mask should have a value.\n");
3305 dev = &rte_eth_devices[port_id];
3306 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
3308 return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);