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))
520 /* detach the new physical device, then store pci_addr of the device */
522 rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
524 struct rte_pci_addr freed_addr;
525 struct rte_pci_addr vp;
527 /* get pci address by port id */
528 if (rte_eth_dev_get_addr_by_port(port_id, &freed_addr))
531 /* Zeroed pci addr means the port comes from virtual device */
532 vp.domain = vp.bus = vp.devid = vp.function = 0;
533 if (rte_eal_compare_pci_addr(&vp, &freed_addr) == 0)
536 /* invoke devuninit func of the pci driver,
537 * also remove the device from pci_device_list */
538 if (rte_eal_pci_detach(&freed_addr))
547 /* attach the new virtual device, then store port_id of the device */
549 rte_eth_dev_attach_vdev(const char *vdevargs, uint8_t *port_id)
551 char *name = NULL, *args = NULL;
554 /* parse vdevargs, then retrieve device name and args */
555 if (rte_eal_parse_devargs_str(vdevargs, &name, &args))
558 /* walk around dev_driver_list to find the driver of the device,
559 * then invoke probe function of the driver.
560 * rte_eal_vdev_init() updates port_id allocated after
563 if (rte_eal_vdev_init(name, args))
566 if (rte_eth_dev_get_port_by_name(name, port_id))
577 /* detach the new virtual device, then store the name of the device */
579 rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
581 char name[RTE_ETH_NAME_MAX_LEN];
583 /* get device name by port id */
584 if (rte_eth_dev_get_name_by_port(port_id, name))
586 /* walk around dev_driver_list to find the driver of the device,
587 * then invoke uninit function of the driver */
588 if (rte_eal_vdev_uninit(name))
591 strncpy(vdevname, name, sizeof(name));
597 /* attach the new device, then store port_id of the device */
599 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
601 struct rte_pci_addr addr;
604 if ((devargs == NULL) || (port_id == NULL)) {
609 if (eal_parse_pci_DomBDF(devargs, &addr) == 0) {
610 ret = rte_eth_dev_attach_pdev(&addr, port_id);
614 ret = rte_eth_dev_attach_vdev(devargs, port_id);
621 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
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;
637 /* check whether the driver supports detach feature, or not */
638 if (rte_eth_dev_is_detachable(port_id))
641 if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {
642 ret = rte_eth_dev_get_addr_by_port(port_id, &addr);
646 ret = rte_eth_dev_detach_pdev(port_id, &addr);
650 snprintf(name, RTE_ETH_NAME_MAX_LEN,
652 addr.domain, addr.bus,
653 addr.devid, addr.function);
655 ret = rte_eth_dev_detach_vdev(port_id, name);
663 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
668 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
670 uint16_t old_nb_queues = dev->data->nb_rx_queues;
674 if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */
675 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
676 sizeof(dev->data->rx_queues[0]) * nb_queues,
677 RTE_CACHE_LINE_SIZE);
678 if (dev->data->rx_queues == NULL) {
679 dev->data->nb_rx_queues = 0;
682 } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */
683 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
685 rxq = dev->data->rx_queues;
687 for (i = nb_queues; i < old_nb_queues; i++)
688 (*dev->dev_ops->rx_queue_release)(rxq[i]);
689 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
690 RTE_CACHE_LINE_SIZE);
693 if (nb_queues > old_nb_queues) {
694 uint16_t new_qs = nb_queues - old_nb_queues;
696 memset(rxq + old_nb_queues, 0,
697 sizeof(rxq[0]) * new_qs);
700 dev->data->rx_queues = rxq;
702 } else if (dev->data->rx_queues != NULL && nb_queues == 0) {
703 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
705 rxq = dev->data->rx_queues;
707 for (i = nb_queues; i < old_nb_queues; i++)
708 (*dev->dev_ops->rx_queue_release)(rxq[i]);
710 dev->data->nb_rx_queues = nb_queues;
715 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
717 struct rte_eth_dev *dev;
719 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
721 dev = &rte_eth_devices[port_id];
722 if (rx_queue_id >= dev->data->nb_rx_queues) {
723 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
727 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
729 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
730 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
731 " already started\n",
732 rx_queue_id, port_id);
736 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
741 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
743 struct rte_eth_dev *dev;
745 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
747 dev = &rte_eth_devices[port_id];
748 if (rx_queue_id >= dev->data->nb_rx_queues) {
749 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
753 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
755 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
756 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
757 " already stopped\n",
758 rx_queue_id, port_id);
762 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
767 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
769 struct rte_eth_dev *dev;
771 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
773 dev = &rte_eth_devices[port_id];
774 if (tx_queue_id >= dev->data->nb_tx_queues) {
775 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
779 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
781 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
782 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
783 " already started\n",
784 tx_queue_id, port_id);
788 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
793 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
795 struct rte_eth_dev *dev;
797 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
799 dev = &rte_eth_devices[port_id];
800 if (tx_queue_id >= dev->data->nb_tx_queues) {
801 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
805 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
807 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
808 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
809 " already stopped\n",
810 tx_queue_id, port_id);
814 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
819 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
821 uint16_t old_nb_queues = dev->data->nb_tx_queues;
825 if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */
826 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
827 sizeof(dev->data->tx_queues[0]) * nb_queues,
828 RTE_CACHE_LINE_SIZE);
829 if (dev->data->tx_queues == NULL) {
830 dev->data->nb_tx_queues = 0;
833 } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */
834 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
836 txq = dev->data->tx_queues;
838 for (i = nb_queues; i < old_nb_queues; i++)
839 (*dev->dev_ops->tx_queue_release)(txq[i]);
840 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
841 RTE_CACHE_LINE_SIZE);
844 if (nb_queues > old_nb_queues) {
845 uint16_t new_qs = nb_queues - old_nb_queues;
847 memset(txq + old_nb_queues, 0,
848 sizeof(txq[0]) * new_qs);
851 dev->data->tx_queues = txq;
853 } else if (dev->data->tx_queues != NULL && nb_queues == 0) {
854 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
856 txq = dev->data->tx_queues;
858 for (i = nb_queues; i < old_nb_queues; i++)
859 (*dev->dev_ops->tx_queue_release)(txq[i]);
861 dev->data->nb_tx_queues = nb_queues;
866 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
867 const struct rte_eth_conf *dev_conf)
869 struct rte_eth_dev *dev;
870 struct rte_eth_dev_info dev_info;
873 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
875 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
877 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
878 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
882 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
884 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
885 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
889 dev = &rte_eth_devices[port_id];
891 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
892 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
894 if (dev->data->dev_started) {
896 "port %d must be stopped to allow configuration\n", port_id);
901 * Check that the numbers of RX and TX queues are not greater
902 * than the maximum number of RX and TX queues supported by the
905 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
907 if (nb_rx_q == 0 && nb_tx_q == 0) {
908 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d both rx and tx queue cannot be 0\n", port_id);
912 if (nb_rx_q > dev_info.max_rx_queues) {
913 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
914 port_id, nb_rx_q, dev_info.max_rx_queues);
918 if (nb_tx_q > dev_info.max_tx_queues) {
919 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
920 port_id, nb_tx_q, dev_info.max_tx_queues);
924 /* Copy the dev_conf parameter into the dev structure */
925 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
928 * If link state interrupt is enabled, check that the
929 * device supports it.
931 if ((dev_conf->intr_conf.lsc == 1) &&
932 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
933 RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
934 dev->data->drv_name);
939 * If jumbo frames are enabled, check that the maximum RX packet
940 * length is supported by the configured device.
942 if (dev_conf->rxmode.jumbo_frame == 1) {
943 if (dev_conf->rxmode.max_rx_pkt_len >
944 dev_info.max_rx_pktlen) {
945 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
946 " > max valid value %u\n",
948 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
949 (unsigned)dev_info.max_rx_pktlen);
951 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
952 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
953 " < min valid value %u\n",
955 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
956 (unsigned)ETHER_MIN_LEN);
960 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
961 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
962 /* Use default value */
963 dev->data->dev_conf.rxmode.max_rx_pkt_len =
968 * Setup new number of RX/TX queues and reconfigure device.
970 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
972 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
977 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
979 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
981 rte_eth_dev_rx_queue_config(dev, 0);
985 diag = (*dev->dev_ops->dev_configure)(dev);
987 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
989 rte_eth_dev_rx_queue_config(dev, 0);
990 rte_eth_dev_tx_queue_config(dev, 0);
998 rte_eth_dev_config_restore(uint8_t port_id)
1000 struct rte_eth_dev *dev;
1001 struct rte_eth_dev_info dev_info;
1002 struct ether_addr addr;
1006 dev = &rte_eth_devices[port_id];
1008 rte_eth_dev_info_get(port_id, &dev_info);
1010 if (RTE_ETH_DEV_SRIOV(dev).active)
1011 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
1013 /* replay MAC address configuration */
1014 for (i = 0; i < dev_info.max_mac_addrs; i++) {
1015 addr = dev->data->mac_addrs[i];
1017 /* skip zero address */
1018 if (is_zero_ether_addr(&addr))
1021 /* add address to the hardware */
1022 if (*dev->dev_ops->mac_addr_add &&
1023 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
1024 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
1026 RTE_PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
1028 /* exit the loop but not return an error */
1033 /* replay promiscuous configuration */
1034 if (rte_eth_promiscuous_get(port_id) == 1)
1035 rte_eth_promiscuous_enable(port_id);
1036 else if (rte_eth_promiscuous_get(port_id) == 0)
1037 rte_eth_promiscuous_disable(port_id);
1039 /* replay all multicast configuration */
1040 if (rte_eth_allmulticast_get(port_id) == 1)
1041 rte_eth_allmulticast_enable(port_id);
1042 else if (rte_eth_allmulticast_get(port_id) == 0)
1043 rte_eth_allmulticast_disable(port_id);
1047 rte_eth_dev_start(uint8_t port_id)
1049 struct rte_eth_dev *dev;
1052 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1054 dev = &rte_eth_devices[port_id];
1056 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1058 if (dev->data->dev_started != 0) {
1059 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1060 " already started\n",
1065 diag = (*dev->dev_ops->dev_start)(dev);
1067 dev->data->dev_started = 1;
1071 rte_eth_dev_config_restore(port_id);
1073 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1074 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1075 (*dev->dev_ops->link_update)(dev, 0);
1081 rte_eth_dev_stop(uint8_t port_id)
1083 struct rte_eth_dev *dev;
1085 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1086 dev = &rte_eth_devices[port_id];
1088 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1090 if (dev->data->dev_started == 0) {
1091 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1092 " already stopped\n",
1097 dev->data->dev_started = 0;
1098 (*dev->dev_ops->dev_stop)(dev);
1102 rte_eth_dev_set_link_up(uint8_t port_id)
1104 struct rte_eth_dev *dev;
1106 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1108 dev = &rte_eth_devices[port_id];
1110 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1111 return (*dev->dev_ops->dev_set_link_up)(dev);
1115 rte_eth_dev_set_link_down(uint8_t port_id)
1117 struct rte_eth_dev *dev;
1119 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1121 dev = &rte_eth_devices[port_id];
1123 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1124 return (*dev->dev_ops->dev_set_link_down)(dev);
1128 rte_eth_dev_close(uint8_t port_id)
1130 struct rte_eth_dev *dev;
1132 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1133 dev = &rte_eth_devices[port_id];
1135 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1136 dev->data->dev_started = 0;
1137 (*dev->dev_ops->dev_close)(dev);
1139 rte_free(dev->data->rx_queues);
1140 dev->data->rx_queues = NULL;
1141 rte_free(dev->data->tx_queues);
1142 dev->data->tx_queues = NULL;
1146 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1147 uint16_t nb_rx_desc, unsigned int socket_id,
1148 const struct rte_eth_rxconf *rx_conf,
1149 struct rte_mempool *mp)
1152 uint32_t mbp_buf_size;
1153 struct rte_eth_dev *dev;
1154 struct rte_eth_dev_info dev_info;
1156 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1158 dev = &rte_eth_devices[port_id];
1159 if (rx_queue_id >= dev->data->nb_rx_queues) {
1160 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1164 if (dev->data->dev_started) {
1165 RTE_PMD_DEBUG_TRACE(
1166 "port %d must be stopped to allow configuration\n", port_id);
1170 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1171 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1174 * Check the size of the mbuf data buffer.
1175 * This value must be provided in the private data of the memory pool.
1176 * First check that the memory pool has a valid private data.
1178 rte_eth_dev_info_get(port_id, &dev_info);
1179 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1180 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1181 mp->name, (int) mp->private_data_size,
1182 (int) sizeof(struct rte_pktmbuf_pool_private));
1185 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1187 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1188 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1189 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1193 (int)(RTE_PKTMBUF_HEADROOM +
1194 dev_info.min_rx_bufsize),
1195 (int)RTE_PKTMBUF_HEADROOM,
1196 (int)dev_info.min_rx_bufsize);
1200 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1201 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1202 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1204 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1205 "should be: <= %hu, = %hu, and a product of %hu\n",
1207 dev_info.rx_desc_lim.nb_max,
1208 dev_info.rx_desc_lim.nb_min,
1209 dev_info.rx_desc_lim.nb_align);
1213 if (rx_conf == NULL)
1214 rx_conf = &dev_info.default_rxconf;
1216 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1217 socket_id, rx_conf, mp);
1219 if (!dev->data->min_rx_buf_size ||
1220 dev->data->min_rx_buf_size > mbp_buf_size)
1221 dev->data->min_rx_buf_size = mbp_buf_size;
1228 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1229 uint16_t nb_tx_desc, unsigned int socket_id,
1230 const struct rte_eth_txconf *tx_conf)
1232 struct rte_eth_dev *dev;
1233 struct rte_eth_dev_info dev_info;
1235 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1237 dev = &rte_eth_devices[port_id];
1238 if (tx_queue_id >= dev->data->nb_tx_queues) {
1239 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1243 if (dev->data->dev_started) {
1244 RTE_PMD_DEBUG_TRACE(
1245 "port %d must be stopped to allow configuration\n", port_id);
1249 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1250 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1252 rte_eth_dev_info_get(port_id, &dev_info);
1254 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1255 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1256 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1257 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1258 "should be: <= %hu, = %hu, and a product of %hu\n",
1260 dev_info.tx_desc_lim.nb_max,
1261 dev_info.tx_desc_lim.nb_min,
1262 dev_info.tx_desc_lim.nb_align);
1266 if (tx_conf == NULL)
1267 tx_conf = &dev_info.default_txconf;
1269 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1270 socket_id, tx_conf);
1274 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
1275 void *userdata __rte_unused)
1279 for (i = 0; i < unsent; i++)
1280 rte_pktmbuf_free(pkts[i]);
1284 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
1287 uint64_t *count = userdata;
1290 for (i = 0; i < unsent; i++)
1291 rte_pktmbuf_free(pkts[i]);
1297 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
1298 buffer_tx_error_fn cbfn, void *userdata)
1300 buffer->error_callback = cbfn;
1301 buffer->error_userdata = userdata;
1306 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
1311 buffer->size = size;
1312 if (buffer->error_callback == NULL)
1313 rte_eth_tx_buffer_set_err_callback(buffer,
1314 rte_eth_tx_buffer_drop_callback, NULL);
1320 rte_eth_promiscuous_enable(uint8_t port_id)
1322 struct rte_eth_dev *dev;
1324 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1325 dev = &rte_eth_devices[port_id];
1327 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1328 (*dev->dev_ops->promiscuous_enable)(dev);
1329 dev->data->promiscuous = 1;
1333 rte_eth_promiscuous_disable(uint8_t port_id)
1335 struct rte_eth_dev *dev;
1337 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1338 dev = &rte_eth_devices[port_id];
1340 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1341 dev->data->promiscuous = 0;
1342 (*dev->dev_ops->promiscuous_disable)(dev);
1346 rte_eth_promiscuous_get(uint8_t port_id)
1348 struct rte_eth_dev *dev;
1350 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1352 dev = &rte_eth_devices[port_id];
1353 return dev->data->promiscuous;
1357 rte_eth_allmulticast_enable(uint8_t port_id)
1359 struct rte_eth_dev *dev;
1361 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1362 dev = &rte_eth_devices[port_id];
1364 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1365 (*dev->dev_ops->allmulticast_enable)(dev);
1366 dev->data->all_multicast = 1;
1370 rte_eth_allmulticast_disable(uint8_t port_id)
1372 struct rte_eth_dev *dev;
1374 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1375 dev = &rte_eth_devices[port_id];
1377 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1378 dev->data->all_multicast = 0;
1379 (*dev->dev_ops->allmulticast_disable)(dev);
1383 rte_eth_allmulticast_get(uint8_t port_id)
1385 struct rte_eth_dev *dev;
1387 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1389 dev = &rte_eth_devices[port_id];
1390 return dev->data->all_multicast;
1394 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1395 struct rte_eth_link *link)
1397 struct rte_eth_link *dst = link;
1398 struct rte_eth_link *src = &(dev->data->dev_link);
1400 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1401 *(uint64_t *)src) == 0)
1408 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1410 struct rte_eth_dev *dev;
1412 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1413 dev = &rte_eth_devices[port_id];
1415 if (dev->data->dev_conf.intr_conf.lsc != 0)
1416 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1418 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1419 (*dev->dev_ops->link_update)(dev, 1);
1420 *eth_link = dev->data->dev_link;
1425 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1427 struct rte_eth_dev *dev;
1429 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1430 dev = &rte_eth_devices[port_id];
1432 if (dev->data->dev_conf.intr_conf.lsc != 0)
1433 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1435 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1436 (*dev->dev_ops->link_update)(dev, 0);
1437 *eth_link = dev->data->dev_link;
1442 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1444 struct rte_eth_dev *dev;
1446 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1448 dev = &rte_eth_devices[port_id];
1449 memset(stats, 0, sizeof(*stats));
1451 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1452 (*dev->dev_ops->stats_get)(dev, stats);
1453 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1458 rte_eth_stats_reset(uint8_t port_id)
1460 struct rte_eth_dev *dev;
1462 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1463 dev = &rte_eth_devices[port_id];
1465 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1466 (*dev->dev_ops->stats_reset)(dev);
1467 dev->data->rx_mbuf_alloc_failed = 0;
1470 /* retrieve ethdev extended statistics */
1472 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1475 struct rte_eth_stats eth_stats;
1476 struct rte_eth_dev *dev;
1477 unsigned count = 0, i, q;
1479 uint64_t val, *stats_ptr;
1481 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1483 dev = &rte_eth_devices[port_id];
1485 /* Return generic statistics */
1486 count = RTE_NB_STATS + (dev->data->nb_rx_queues * RTE_NB_RXQ_STATS) +
1487 (dev->data->nb_tx_queues * RTE_NB_TXQ_STATS);
1489 /* implemented by the driver */
1490 if (dev->dev_ops->xstats_get != NULL) {
1491 /* Retrieve the xstats from the driver at the end of the
1494 xcount = (*dev->dev_ops->xstats_get)(dev, &xstats[count],
1495 (n > count) ? n - count : 0);
1501 if (n < count + xcount)
1502 return count + xcount;
1504 /* now fill the xstats structure */
1506 rte_eth_stats_get(port_id, ð_stats);
1509 for (i = 0; i < RTE_NB_STATS; i++) {
1510 stats_ptr = RTE_PTR_ADD(ð_stats,
1511 rte_stats_strings[i].offset);
1513 snprintf(xstats[count].name, sizeof(xstats[count].name),
1514 "%s", rte_stats_strings[i].name);
1515 xstats[count++].value = val;
1519 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1520 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1521 stats_ptr = RTE_PTR_ADD(ð_stats,
1522 rte_rxq_stats_strings[i].offset +
1523 q * sizeof(uint64_t));
1525 snprintf(xstats[count].name, sizeof(xstats[count].name),
1527 rte_rxq_stats_strings[i].name);
1528 xstats[count++].value = val;
1533 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1534 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1535 stats_ptr = RTE_PTR_ADD(ð_stats,
1536 rte_txq_stats_strings[i].offset +
1537 q * sizeof(uint64_t));
1539 snprintf(xstats[count].name, sizeof(xstats[count].name),
1541 rte_txq_stats_strings[i].name);
1542 xstats[count++].value = val;
1546 return count + xcount;
1549 /* reset ethdev extended statistics */
1551 rte_eth_xstats_reset(uint8_t port_id)
1553 struct rte_eth_dev *dev;
1555 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1556 dev = &rte_eth_devices[port_id];
1558 /* implemented by the driver */
1559 if (dev->dev_ops->xstats_reset != NULL) {
1560 (*dev->dev_ops->xstats_reset)(dev);
1564 /* fallback to default */
1565 rte_eth_stats_reset(port_id);
1569 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1572 struct rte_eth_dev *dev;
1574 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1576 dev = &rte_eth_devices[port_id];
1578 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1579 return (*dev->dev_ops->queue_stats_mapping_set)
1580 (dev, queue_id, stat_idx, is_rx);
1585 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1588 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1594 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1597 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1603 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1605 struct rte_eth_dev *dev;
1606 const struct rte_eth_desc_lim lim = {
1607 .nb_max = UINT16_MAX,
1612 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1613 dev = &rte_eth_devices[port_id];
1615 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1616 dev_info->rx_desc_lim = lim;
1617 dev_info->tx_desc_lim = lim;
1619 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1620 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1621 dev_info->pci_dev = dev->pci_dev;
1622 dev_info->driver_name = dev->data->drv_name;
1626 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1628 struct rte_eth_dev *dev;
1630 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1631 dev = &rte_eth_devices[port_id];
1632 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1637 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1639 struct rte_eth_dev *dev;
1641 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1643 dev = &rte_eth_devices[port_id];
1644 *mtu = dev->data->mtu;
1649 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1652 struct rte_eth_dev *dev;
1654 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1655 dev = &rte_eth_devices[port_id];
1656 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1658 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1660 dev->data->mtu = mtu;
1666 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1668 struct rte_eth_dev *dev;
1670 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1671 dev = &rte_eth_devices[port_id];
1672 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1673 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1677 if (vlan_id > 4095) {
1678 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1679 port_id, (unsigned) vlan_id);
1682 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1684 return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1688 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1690 struct rte_eth_dev *dev;
1692 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1693 dev = &rte_eth_devices[port_id];
1694 if (rx_queue_id >= dev->data->nb_rx_queues) {
1695 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1699 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1700 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1706 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1708 struct rte_eth_dev *dev;
1710 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1711 dev = &rte_eth_devices[port_id];
1712 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1713 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1719 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1721 struct rte_eth_dev *dev;
1726 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1727 dev = &rte_eth_devices[port_id];
1729 /*check which option changed by application*/
1730 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1731 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1733 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1734 mask |= ETH_VLAN_STRIP_MASK;
1737 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1738 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1740 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1741 mask |= ETH_VLAN_FILTER_MASK;
1744 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1745 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1747 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1748 mask |= ETH_VLAN_EXTEND_MASK;
1755 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1756 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1762 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1764 struct rte_eth_dev *dev;
1767 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1768 dev = &rte_eth_devices[port_id];
1770 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1771 ret |= ETH_VLAN_STRIP_OFFLOAD;
1773 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1774 ret |= ETH_VLAN_FILTER_OFFLOAD;
1776 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1777 ret |= ETH_VLAN_EXTEND_OFFLOAD;
1783 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1785 struct rte_eth_dev *dev;
1787 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1788 dev = &rte_eth_devices[port_id];
1789 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1790 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1796 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1798 struct rte_eth_dev *dev;
1800 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1801 dev = &rte_eth_devices[port_id];
1802 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1803 memset(fc_conf, 0, sizeof(*fc_conf));
1804 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1808 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1810 struct rte_eth_dev *dev;
1812 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1813 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1814 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1818 dev = &rte_eth_devices[port_id];
1819 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1820 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1824 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1826 struct rte_eth_dev *dev;
1828 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1829 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1830 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1834 dev = &rte_eth_devices[port_id];
1835 /* High water, low water validation are device specific */
1836 if (*dev->dev_ops->priority_flow_ctrl_set)
1837 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1842 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
1850 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
1851 RTE_PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
1852 RTE_RETA_GROUP_SIZE);
1856 num = reta_size / RTE_RETA_GROUP_SIZE;
1857 for (i = 0; i < num; i++) {
1858 if (reta_conf[i].mask)
1866 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
1870 uint16_t i, idx, shift;
1876 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
1880 for (i = 0; i < reta_size; i++) {
1881 idx = i / RTE_RETA_GROUP_SIZE;
1882 shift = i % RTE_RETA_GROUP_SIZE;
1883 if ((reta_conf[idx].mask & (1ULL << shift)) &&
1884 (reta_conf[idx].reta[shift] >= max_rxq)) {
1885 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
1886 "the maximum rxq index: %u\n", idx, shift,
1887 reta_conf[idx].reta[shift], max_rxq);
1896 rte_eth_dev_rss_reta_update(uint8_t port_id,
1897 struct rte_eth_rss_reta_entry64 *reta_conf,
1900 struct rte_eth_dev *dev;
1903 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1904 /* Check mask bits */
1905 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
1909 dev = &rte_eth_devices[port_id];
1911 /* Check entry value */
1912 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
1913 dev->data->nb_rx_queues);
1917 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
1918 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
1922 rte_eth_dev_rss_reta_query(uint8_t port_id,
1923 struct rte_eth_rss_reta_entry64 *reta_conf,
1926 struct rte_eth_dev *dev;
1929 if (port_id >= nb_ports) {
1930 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1934 /* Check mask bits */
1935 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
1939 dev = &rte_eth_devices[port_id];
1940 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
1941 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
1945 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
1947 struct rte_eth_dev *dev;
1948 uint16_t rss_hash_protos;
1950 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1951 rss_hash_protos = rss_conf->rss_hf;
1952 if ((rss_hash_protos != 0) &&
1953 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
1954 RTE_PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
1958 dev = &rte_eth_devices[port_id];
1959 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
1960 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
1964 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
1965 struct rte_eth_rss_conf *rss_conf)
1967 struct rte_eth_dev *dev;
1969 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1970 dev = &rte_eth_devices[port_id];
1971 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
1972 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
1976 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
1977 struct rte_eth_udp_tunnel *udp_tunnel)
1979 struct rte_eth_dev *dev;
1981 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1982 if (udp_tunnel == NULL) {
1983 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
1987 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
1988 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
1992 dev = &rte_eth_devices[port_id];
1993 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
1994 return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
1998 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
1999 struct rte_eth_udp_tunnel *udp_tunnel)
2001 struct rte_eth_dev *dev;
2003 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2004 dev = &rte_eth_devices[port_id];
2006 if (udp_tunnel == NULL) {
2007 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2011 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2012 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2016 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2017 return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2021 rte_eth_led_on(uint8_t port_id)
2023 struct rte_eth_dev *dev;
2025 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2026 dev = &rte_eth_devices[port_id];
2027 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2028 return (*dev->dev_ops->dev_led_on)(dev);
2032 rte_eth_led_off(uint8_t port_id)
2034 struct rte_eth_dev *dev;
2036 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2037 dev = &rte_eth_devices[port_id];
2038 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2039 return (*dev->dev_ops->dev_led_off)(dev);
2043 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2047 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2049 struct rte_eth_dev_info dev_info;
2050 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2053 rte_eth_dev_info_get(port_id, &dev_info);
2055 for (i = 0; i < dev_info.max_mac_addrs; i++)
2056 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2062 static const struct ether_addr null_mac_addr;
2065 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2068 struct rte_eth_dev *dev;
2072 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2073 dev = &rte_eth_devices[port_id];
2074 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2076 if (is_zero_ether_addr(addr)) {
2077 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2081 if (pool >= ETH_64_POOLS) {
2082 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2086 index = get_mac_addr_index(port_id, addr);
2088 index = get_mac_addr_index(port_id, &null_mac_addr);
2090 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2095 pool_mask = dev->data->mac_pool_sel[index];
2097 /* Check if both MAC address and pool is already there, and do nothing */
2098 if (pool_mask & (1ULL << pool))
2103 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2105 /* Update address in NIC data structure */
2106 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2108 /* Update pool bitmap in NIC data structure */
2109 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2115 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2117 struct rte_eth_dev *dev;
2120 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2121 dev = &rte_eth_devices[port_id];
2122 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2124 index = get_mac_addr_index(port_id, addr);
2126 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2128 } else if (index < 0)
2129 return 0; /* Do nothing if address wasn't found */
2132 (*dev->dev_ops->mac_addr_remove)(dev, index);
2134 /* Update address in NIC data structure */
2135 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2137 /* reset pool bitmap */
2138 dev->data->mac_pool_sel[index] = 0;
2144 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2146 struct rte_eth_dev *dev;
2148 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2150 if (!is_valid_assigned_ether_addr(addr))
2153 dev = &rte_eth_devices[port_id];
2154 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2156 /* Update default address in NIC data structure */
2157 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2159 (*dev->dev_ops->mac_addr_set)(dev, addr);
2165 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2166 uint16_t rx_mode, uint8_t on)
2169 struct rte_eth_dev *dev;
2170 struct rte_eth_dev_info dev_info;
2172 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2174 dev = &rte_eth_devices[port_id];
2175 rte_eth_dev_info_get(port_id, &dev_info);
2177 num_vfs = dev_info.max_vfs;
2179 RTE_PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2184 RTE_PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2187 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2188 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2192 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2196 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2198 struct rte_eth_dev_info dev_info;
2199 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2202 rte_eth_dev_info_get(port_id, &dev_info);
2203 if (!dev->data->hash_mac_addrs)
2206 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2207 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2208 ETHER_ADDR_LEN) == 0)
2215 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2220 struct rte_eth_dev *dev;
2222 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2224 dev = &rte_eth_devices[port_id];
2225 if (is_zero_ether_addr(addr)) {
2226 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2231 index = get_hash_mac_addr_index(port_id, addr);
2232 /* Check if it's already there, and do nothing */
2233 if ((index >= 0) && (on))
2238 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2239 "set in UTA\n", port_id);
2243 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2245 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2251 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2252 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2254 /* Update address in NIC data structure */
2256 ether_addr_copy(addr,
2257 &dev->data->hash_mac_addrs[index]);
2259 ether_addr_copy(&null_mac_addr,
2260 &dev->data->hash_mac_addrs[index]);
2267 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2269 struct rte_eth_dev *dev;
2271 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2273 dev = &rte_eth_devices[port_id];
2275 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2276 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2280 rte_eth_dev_set_vf_rx(uint8_t port_id, uint16_t vf, uint8_t on)
2283 struct rte_eth_dev *dev;
2284 struct rte_eth_dev_info dev_info;
2286 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2288 dev = &rte_eth_devices[port_id];
2289 rte_eth_dev_info_get(port_id, &dev_info);
2291 num_vfs = dev_info.max_vfs;
2293 RTE_PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2297 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2298 return (*dev->dev_ops->set_vf_rx)(dev, vf, on);
2302 rte_eth_dev_set_vf_tx(uint8_t port_id, uint16_t vf, uint8_t on)
2305 struct rte_eth_dev *dev;
2306 struct rte_eth_dev_info dev_info;
2308 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2310 dev = &rte_eth_devices[port_id];
2311 rte_eth_dev_info_get(port_id, &dev_info);
2313 num_vfs = dev_info.max_vfs;
2315 RTE_PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2319 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2320 return (*dev->dev_ops->set_vf_tx)(dev, vf, on);
2324 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2325 uint64_t vf_mask, uint8_t vlan_on)
2327 struct rte_eth_dev *dev;
2329 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2331 dev = &rte_eth_devices[port_id];
2333 if (vlan_id > ETHER_MAX_VLAN_ID) {
2334 RTE_PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2340 RTE_PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2344 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2345 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2349 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2352 struct rte_eth_dev *dev;
2353 struct rte_eth_dev_info dev_info;
2354 struct rte_eth_link link;
2356 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2358 dev = &rte_eth_devices[port_id];
2359 rte_eth_dev_info_get(port_id, &dev_info);
2360 link = dev->data->dev_link;
2362 if (queue_idx > dev_info.max_tx_queues) {
2363 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2364 "invalid queue id=%d\n", port_id, queue_idx);
2368 if (tx_rate > link.link_speed) {
2369 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2370 "bigger than link speed= %d\n",
2371 tx_rate, link.link_speed);
2375 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2376 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2379 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2382 struct rte_eth_dev *dev;
2383 struct rte_eth_dev_info dev_info;
2384 struct rte_eth_link link;
2389 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2391 dev = &rte_eth_devices[port_id];
2392 rte_eth_dev_info_get(port_id, &dev_info);
2393 link = dev->data->dev_link;
2395 if (vf > dev_info.max_vfs) {
2396 RTE_PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2397 "invalid vf id=%d\n", port_id, vf);
2401 if (tx_rate > link.link_speed) {
2402 RTE_PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2403 "bigger than link speed= %d\n",
2404 tx_rate, link.link_speed);
2408 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2409 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2413 rte_eth_mirror_rule_set(uint8_t port_id,
2414 struct rte_eth_mirror_conf *mirror_conf,
2415 uint8_t rule_id, uint8_t on)
2417 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2419 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2420 if (mirror_conf->rule_type == 0) {
2421 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2425 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2426 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2431 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2432 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2433 (mirror_conf->pool_mask == 0)) {
2434 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2438 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2439 mirror_conf->vlan.vlan_mask == 0) {
2440 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2444 dev = &rte_eth_devices[port_id];
2445 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2447 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2451 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2453 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2455 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2457 dev = &rte_eth_devices[port_id];
2458 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2460 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2464 rte_eth_dev_callback_register(uint8_t port_id,
2465 enum rte_eth_event_type event,
2466 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2468 struct rte_eth_dev *dev;
2469 struct rte_eth_dev_callback *user_cb;
2474 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2476 dev = &rte_eth_devices[port_id];
2477 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2479 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2480 if (user_cb->cb_fn == cb_fn &&
2481 user_cb->cb_arg == cb_arg &&
2482 user_cb->event == event) {
2487 /* create a new callback. */
2488 if (user_cb == NULL)
2489 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2490 sizeof(struct rte_eth_dev_callback), 0);
2491 if (user_cb != NULL) {
2492 user_cb->cb_fn = cb_fn;
2493 user_cb->cb_arg = cb_arg;
2494 user_cb->event = event;
2495 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2498 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2499 return (user_cb == NULL) ? -ENOMEM : 0;
2503 rte_eth_dev_callback_unregister(uint8_t port_id,
2504 enum rte_eth_event_type event,
2505 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2508 struct rte_eth_dev *dev;
2509 struct rte_eth_dev_callback *cb, *next;
2514 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2516 dev = &rte_eth_devices[port_id];
2517 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2520 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2522 next = TAILQ_NEXT(cb, next);
2524 if (cb->cb_fn != cb_fn || cb->event != event ||
2525 (cb->cb_arg != (void *)-1 &&
2526 cb->cb_arg != cb_arg))
2530 * if this callback is not executing right now,
2533 if (cb->active == 0) {
2534 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2541 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2546 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2547 enum rte_eth_event_type event)
2549 struct rte_eth_dev_callback *cb_lst;
2550 struct rte_eth_dev_callback dev_cb;
2552 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2553 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2554 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2558 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2559 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2561 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2564 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2568 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
2571 struct rte_eth_dev *dev;
2572 struct rte_intr_handle *intr_handle;
2576 if (!rte_eth_dev_is_valid_port(port_id)) {
2577 RTE_PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
2581 dev = &rte_eth_devices[port_id];
2582 intr_handle = &dev->pci_dev->intr_handle;
2583 if (!intr_handle->intr_vec) {
2584 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2588 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2589 vec = intr_handle->intr_vec[qid];
2590 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2591 if (rc && rc != -EEXIST) {
2592 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2593 " op %d epfd %d vec %u\n",
2594 port_id, qid, op, epfd, vec);
2601 const struct rte_memzone *
2602 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2603 uint16_t queue_id, size_t size, unsigned align,
2606 char z_name[RTE_MEMZONE_NAMESIZE];
2607 const struct rte_memzone *mz;
2609 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2610 dev->driver->pci_drv.name, ring_name,
2611 dev->data->port_id, queue_id);
2613 mz = rte_memzone_lookup(z_name);
2617 if (rte_xen_dom0_supported())
2618 return rte_memzone_reserve_bounded(z_name, size, socket_id,
2619 0, align, RTE_PGSIZE_2M);
2621 return rte_memzone_reserve_aligned(z_name, size, socket_id,
2626 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
2627 int epfd, int op, void *data)
2630 struct rte_eth_dev *dev;
2631 struct rte_intr_handle *intr_handle;
2634 if (!rte_eth_dev_is_valid_port(port_id)) {
2635 RTE_PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
2639 dev = &rte_eth_devices[port_id];
2640 if (queue_id >= dev->data->nb_rx_queues) {
2641 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
2645 intr_handle = &dev->pci_dev->intr_handle;
2646 if (!intr_handle->intr_vec) {
2647 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2651 vec = intr_handle->intr_vec[queue_id];
2652 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2653 if (rc && rc != -EEXIST) {
2654 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2655 " op %d epfd %d vec %u\n",
2656 port_id, queue_id, op, epfd, vec);
2664 rte_eth_dev_rx_intr_enable(uint8_t port_id,
2667 struct rte_eth_dev *dev;
2669 if (!rte_eth_dev_is_valid_port(port_id)) {
2670 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2674 dev = &rte_eth_devices[port_id];
2676 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
2677 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
2681 rte_eth_dev_rx_intr_disable(uint8_t port_id,
2684 struct rte_eth_dev *dev;
2686 if (!rte_eth_dev_is_valid_port(port_id)) {
2687 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2691 dev = &rte_eth_devices[port_id];
2693 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
2694 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
2697 #ifdef RTE_NIC_BYPASS
2698 int rte_eth_dev_bypass_init(uint8_t port_id)
2700 struct rte_eth_dev *dev;
2702 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2704 dev = &rte_eth_devices[port_id];
2705 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2706 (*dev->dev_ops->bypass_init)(dev);
2711 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2713 struct rte_eth_dev *dev;
2715 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2717 dev = &rte_eth_devices[port_id];
2718 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2719 (*dev->dev_ops->bypass_state_show)(dev, state);
2724 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2726 struct rte_eth_dev *dev;
2728 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2730 dev = &rte_eth_devices[port_id];
2731 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2732 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2737 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2739 struct rte_eth_dev *dev;
2741 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2743 dev = &rte_eth_devices[port_id];
2744 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2745 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2750 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2752 struct rte_eth_dev *dev;
2754 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2756 dev = &rte_eth_devices[port_id];
2758 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2759 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2764 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2766 struct rte_eth_dev *dev;
2768 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2770 dev = &rte_eth_devices[port_id];
2772 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2773 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2778 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2780 struct rte_eth_dev *dev;
2782 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2784 dev = &rte_eth_devices[port_id];
2786 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2787 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2792 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2794 struct rte_eth_dev *dev;
2796 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2798 dev = &rte_eth_devices[port_id];
2800 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2801 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2806 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2808 struct rte_eth_dev *dev;
2810 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2812 dev = &rte_eth_devices[port_id];
2814 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2815 (*dev->dev_ops->bypass_wd_reset)(dev);
2821 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
2823 struct rte_eth_dev *dev;
2825 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2827 dev = &rte_eth_devices[port_id];
2828 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2829 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
2830 RTE_ETH_FILTER_NOP, NULL);
2834 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
2835 enum rte_filter_op filter_op, void *arg)
2837 struct rte_eth_dev *dev;
2839 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2841 dev = &rte_eth_devices[port_id];
2842 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2843 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
2847 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
2848 rte_rx_callback_fn fn, void *user_param)
2850 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2851 rte_errno = ENOTSUP;
2854 /* check input parameters */
2855 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2856 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2861 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2869 cb->param = user_param;
2871 /* Add the callbacks in fifo order. */
2872 struct rte_eth_rxtx_callback *tail =
2873 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2876 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2888 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
2889 rte_tx_callback_fn fn, void *user_param)
2891 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2892 rte_errno = ENOTSUP;
2895 /* check input parameters */
2896 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2897 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
2902 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2910 cb->param = user_param;
2912 /* Add the callbacks in fifo order. */
2913 struct rte_eth_rxtx_callback *tail =
2914 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
2917 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
2929 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
2930 struct rte_eth_rxtx_callback *user_cb)
2932 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2935 /* Check input parameters. */
2936 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
2937 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2941 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2942 struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
2943 struct rte_eth_rxtx_callback *prev_cb;
2945 /* Reset head pointer and remove user cb if first in the list. */
2946 if (cb == user_cb) {
2947 dev->post_rx_burst_cbs[queue_id] = user_cb->next;
2951 /* Remove the user cb from the callback list. */
2956 if (cb == user_cb) {
2957 prev_cb->next = user_cb->next;
2961 } while (cb != NULL);
2963 /* Callback wasn't found. */
2968 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
2969 struct rte_eth_rxtx_callback *user_cb)
2971 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2974 /* Check input parameters. */
2975 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
2976 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
2980 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2981 struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
2982 struct rte_eth_rxtx_callback *prev_cb;
2984 /* Reset head pointer and remove user cb if first in the list. */
2985 if (cb == user_cb) {
2986 dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
2990 /* Remove the user cb from the callback list. */
2995 if (cb == user_cb) {
2996 prev_cb->next = user_cb->next;
3000 } while (cb != NULL);
3002 /* Callback wasn't found. */
3007 rte_eth_rx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3008 struct rte_eth_rxq_info *qinfo)
3010 struct rte_eth_dev *dev;
3012 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3017 dev = &rte_eth_devices[port_id];
3018 if (queue_id >= dev->data->nb_rx_queues) {
3019 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3023 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3025 memset(qinfo, 0, sizeof(*qinfo));
3026 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3031 rte_eth_tx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3032 struct rte_eth_txq_info *qinfo)
3034 struct rte_eth_dev *dev;
3036 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3041 dev = &rte_eth_devices[port_id];
3042 if (queue_id >= dev->data->nb_tx_queues) {
3043 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3047 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3049 memset(qinfo, 0, sizeof(*qinfo));
3050 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3055 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3056 struct ether_addr *mc_addr_set,
3057 uint32_t nb_mc_addr)
3059 struct rte_eth_dev *dev;
3061 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3063 dev = &rte_eth_devices[port_id];
3064 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3065 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3069 rte_eth_timesync_enable(uint8_t port_id)
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_enable, -ENOTSUP);
3077 return (*dev->dev_ops->timesync_enable)(dev);
3081 rte_eth_timesync_disable(uint8_t port_id)
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_disable, -ENOTSUP);
3089 return (*dev->dev_ops->timesync_disable)(dev);
3093 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3096 struct rte_eth_dev *dev;
3098 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3099 dev = &rte_eth_devices[port_id];
3101 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3102 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3106 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3108 struct rte_eth_dev *dev;
3110 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3111 dev = &rte_eth_devices[port_id];
3113 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3114 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3118 rte_eth_timesync_adjust_time(uint8_t port_id, int64_t delta)
3120 struct rte_eth_dev *dev;
3122 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3123 dev = &rte_eth_devices[port_id];
3125 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3126 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3130 rte_eth_timesync_read_time(uint8_t port_id, struct timespec *timestamp)
3132 struct rte_eth_dev *dev;
3134 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3135 dev = &rte_eth_devices[port_id];
3137 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3138 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3142 rte_eth_timesync_write_time(uint8_t port_id, const struct timespec *timestamp)
3144 struct rte_eth_dev *dev;
3146 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3147 dev = &rte_eth_devices[port_id];
3149 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3150 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3154 rte_eth_dev_get_reg_length(uint8_t port_id)
3156 struct rte_eth_dev *dev;
3158 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3160 dev = &rte_eth_devices[port_id];
3161 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg_length, -ENOTSUP);
3162 return (*dev->dev_ops->get_reg_length)(dev);
3166 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3168 struct rte_eth_dev *dev;
3170 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3172 dev = &rte_eth_devices[port_id];
3173 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3174 return (*dev->dev_ops->get_reg)(dev, info);
3178 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3180 struct rte_eth_dev *dev;
3182 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3184 dev = &rte_eth_devices[port_id];
3185 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3186 return (*dev->dev_ops->get_eeprom_length)(dev);
3190 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3192 struct rte_eth_dev *dev;
3194 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3196 dev = &rte_eth_devices[port_id];
3197 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3198 return (*dev->dev_ops->get_eeprom)(dev, info);
3202 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3204 struct rte_eth_dev *dev;
3206 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3208 dev = &rte_eth_devices[port_id];
3209 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3210 return (*dev->dev_ops->set_eeprom)(dev, info);
3214 rte_eth_dev_get_dcb_info(uint8_t port_id,
3215 struct rte_eth_dcb_info *dcb_info)
3217 struct rte_eth_dev *dev;
3219 if (!rte_eth_dev_is_valid_port(port_id)) {
3220 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3224 dev = &rte_eth_devices[port_id];
3225 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3227 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3228 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3232 rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_dev)
3234 if ((eth_dev == NULL) || (pci_dev == NULL)) {
3235 RTE_PMD_DEBUG_TRACE("NULL pointer eth_dev=%p pci_dev=%p\n",
3240 eth_dev->data->dev_flags = 0;
3241 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
3242 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
3243 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_DETACHABLE)
3244 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
3246 eth_dev->data->kdrv = pci_dev->kdrv;
3247 eth_dev->data->numa_node = pci_dev->numa_node;
3248 eth_dev->data->drv_name = pci_dev->driver->name;