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 if ((name == NULL) || (pci_dev == NULL))
226 ret = snprintf(name, size, "%d:%d.%d",
227 pci_dev->addr.bus, pci_dev->addr.devid,
228 pci_dev->addr.function);
235 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
240 eth_dev->attached = DEV_DETACHED;
246 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
247 struct rte_pci_device *pci_dev)
249 struct eth_driver *eth_drv;
250 struct rte_eth_dev *eth_dev;
251 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
255 eth_drv = (struct eth_driver *)pci_drv;
257 /* Create unique Ethernet device name using PCI address */
258 rte_eth_dev_create_unique_device_name(ethdev_name,
259 sizeof(ethdev_name), pci_dev);
261 eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
265 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
266 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
267 eth_drv->dev_private_size,
268 RTE_CACHE_LINE_SIZE);
269 if (eth_dev->data->dev_private == NULL)
270 rte_panic("Cannot allocate memzone for private port data\n");
272 eth_dev->pci_dev = pci_dev;
273 eth_dev->driver = eth_drv;
274 eth_dev->data->rx_mbuf_alloc_failed = 0;
276 /* init user callbacks */
277 TAILQ_INIT(&(eth_dev->link_intr_cbs));
280 * Set the default MTU.
282 eth_dev->data->mtu = ETHER_MTU;
284 /* Invoke PMD device initialization function */
285 diag = (*eth_drv->eth_dev_init)(eth_dev);
289 RTE_PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x) failed\n",
291 (unsigned) pci_dev->id.vendor_id,
292 (unsigned) pci_dev->id.device_id);
293 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
294 rte_free(eth_dev->data->dev_private);
295 rte_eth_dev_release_port(eth_dev);
300 rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
302 const struct eth_driver *eth_drv;
303 struct rte_eth_dev *eth_dev;
304 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
310 /* Create unique Ethernet device name using PCI address */
311 rte_eth_dev_create_unique_device_name(ethdev_name,
312 sizeof(ethdev_name), pci_dev);
314 eth_dev = rte_eth_dev_allocated(ethdev_name);
318 eth_drv = (const struct eth_driver *)pci_dev->driver;
320 /* Invoke PMD device uninit function */
321 if (*eth_drv->eth_dev_uninit) {
322 ret = (*eth_drv->eth_dev_uninit)(eth_dev);
327 /* free ether device */
328 rte_eth_dev_release_port(eth_dev);
330 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
331 rte_free(eth_dev->data->dev_private);
333 eth_dev->pci_dev = NULL;
334 eth_dev->driver = NULL;
335 eth_dev->data = NULL;
341 * Register an Ethernet [Poll Mode] driver.
343 * Function invoked by the initialization function of an Ethernet driver
344 * to simultaneously register itself as a PCI driver and as an Ethernet
346 * Invokes the rte_eal_pci_register() function to register the *pci_drv*
347 * structure embedded in the *eth_drv* structure, after having stored the
348 * address of the rte_eth_dev_init() function in the *devinit* field of
349 * the *pci_drv* structure.
350 * During the PCI probing phase, the rte_eth_dev_init() function is
351 * invoked for each PCI [Ethernet device] matching the embedded PCI
352 * identifiers provided by the driver.
355 rte_eth_driver_register(struct eth_driver *eth_drv)
357 eth_drv->pci_drv.devinit = rte_eth_dev_init;
358 eth_drv->pci_drv.devuninit = rte_eth_dev_uninit;
359 rte_eal_pci_register(ð_drv->pci_drv);
363 rte_eth_dev_is_valid_port(uint8_t port_id)
365 if (port_id >= RTE_MAX_ETHPORTS ||
366 rte_eth_devices[port_id].attached != DEV_ATTACHED)
373 rte_eth_dev_socket_id(uint8_t port_id)
375 if (!rte_eth_dev_is_valid_port(port_id))
377 return rte_eth_devices[port_id].data->numa_node;
381 rte_eth_dev_count(void)
386 static enum rte_eth_dev_type
387 rte_eth_dev_get_device_type(uint8_t port_id)
389 if (!rte_eth_dev_is_valid_port(port_id))
390 return RTE_ETH_DEV_UNKNOWN;
391 return rte_eth_devices[port_id].dev_type;
395 rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr)
397 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
400 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
404 *addr = rte_eth_devices[port_id].pci_dev->addr;
409 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
413 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
416 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
420 /* shouldn't check 'rte_eth_devices[i].data',
421 * because it might be overwritten by VDEV PMD */
422 tmp = rte_eth_dev_data[port_id].name;
428 rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
433 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
437 *port_id = RTE_MAX_ETHPORTS;
439 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
442 rte_eth_dev_data[i].name, strlen(name))) {
453 rte_eth_dev_get_port_by_addr(const struct rte_pci_addr *addr, uint8_t *port_id)
456 struct rte_pci_device *pci_dev = NULL;
459 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
463 *port_id = RTE_MAX_ETHPORTS;
465 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
467 pci_dev = rte_eth_devices[i].pci_dev;
470 !rte_eal_compare_pci_addr(&pci_dev->addr, addr)) {
481 rte_eth_dev_is_detachable(uint8_t port_id)
485 if (!rte_eth_dev_is_valid_port(port_id)) {
486 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
490 switch (rte_eth_devices[port_id].data->kdrv) {
491 case RTE_KDRV_IGB_UIO:
492 case RTE_KDRV_UIO_GENERIC:
493 case RTE_KDRV_NIC_UIO:
500 dev_flags = rte_eth_devices[port_id].data->dev_flags;
501 return !(dev_flags & RTE_ETH_DEV_DETACHABLE);
504 /* attach the new physical device, then store port_id of the device */
506 rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
508 if ((addr == NULL) || (port_id == NULL))
511 /* re-construct pci_device_list */
512 if (rte_eal_pci_scan())
514 /* Invoke probe func of the driver can handle the new device. */
515 if (rte_eal_pci_probe_one(addr))
518 if (rte_eth_dev_get_port_by_addr(addr, port_id))
523 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
527 /* detach the new physical device, then store pci_addr of the device */
529 rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
531 struct rte_pci_addr freed_addr;
532 struct rte_pci_addr vp;
537 /* check whether the driver supports detach feature, or not */
538 if (rte_eth_dev_is_detachable(port_id))
541 /* get pci address by port id */
542 if (rte_eth_dev_get_addr_by_port(port_id, &freed_addr))
545 /* Zeroed pci addr means the port comes from virtual device */
546 vp.domain = vp.bus = vp.devid = vp.function = 0;
547 if (rte_eal_compare_pci_addr(&vp, &freed_addr) == 0)
550 /* invoke devuninit func of the pci driver,
551 * also remove the device from pci_device_list */
552 if (rte_eal_pci_detach(&freed_addr))
558 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
562 /* attach the new virtual device, then store port_id of the device */
564 rte_eth_dev_attach_vdev(const char *vdevargs, uint8_t *port_id)
566 char *name = NULL, *args = NULL;
569 if ((vdevargs == NULL) || (port_id == NULL))
572 /* parse vdevargs, then retrieve device name and args */
573 if (rte_eal_parse_devargs_str(vdevargs, &name, &args))
576 /* walk around dev_driver_list to find the driver of the device,
577 * then invoke probe function of the driver.
578 * rte_eal_vdev_init() updates port_id allocated after
581 if (rte_eal_vdev_init(name, args))
584 if (rte_eth_dev_get_port_by_name(name, port_id))
595 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
599 /* detach the new virtual device, then store the name of the device */
601 rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
603 char name[RTE_ETH_NAME_MAX_LEN];
605 if (vdevname == NULL)
608 /* check whether the driver supports detach feature, or not */
609 if (rte_eth_dev_is_detachable(port_id))
612 /* get device name by port id */
613 if (rte_eth_dev_get_name_by_port(port_id, name))
615 /* walk around dev_driver_list to find the driver of the device,
616 * then invoke uninit function of the driver */
617 if (rte_eal_vdev_uninit(name))
620 strncpy(vdevname, name, sizeof(name));
623 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
627 /* attach the new device, then store port_id of the device */
629 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
631 struct rte_pci_addr addr;
633 if ((devargs == NULL) || (port_id == NULL))
636 if (eal_parse_pci_DomBDF(devargs, &addr) == 0)
637 return rte_eth_dev_attach_pdev(&addr, port_id);
639 return rte_eth_dev_attach_vdev(devargs, port_id);
642 /* detach the device, then store the name of the device */
644 rte_eth_dev_detach(uint8_t port_id, char *name)
646 struct rte_pci_addr addr;
652 if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {
653 ret = rte_eth_dev_get_addr_by_port(port_id, &addr);
657 ret = rte_eth_dev_detach_pdev(port_id, &addr);
659 snprintf(name, RTE_ETH_NAME_MAX_LEN,
661 addr.domain, addr.bus,
662 addr.devid, addr.function);
666 return rte_eth_dev_detach_vdev(port_id, name);
670 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
672 uint16_t old_nb_queues = dev->data->nb_rx_queues;
676 if (dev->data->rx_queues == NULL) { /* first time configuration */
677 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
678 sizeof(dev->data->rx_queues[0]) * nb_queues,
679 RTE_CACHE_LINE_SIZE);
680 if (dev->data->rx_queues == NULL) {
681 dev->data->nb_rx_queues = 0;
684 } else { /* re-configure */
685 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
687 rxq = dev->data->rx_queues;
689 for (i = nb_queues; i < old_nb_queues; i++)
690 (*dev->dev_ops->rx_queue_release)(rxq[i]);
691 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
692 RTE_CACHE_LINE_SIZE);
695 if (nb_queues > old_nb_queues) {
696 uint16_t new_qs = nb_queues - old_nb_queues;
698 memset(rxq + old_nb_queues, 0,
699 sizeof(rxq[0]) * new_qs);
702 dev->data->rx_queues = rxq;
705 dev->data->nb_rx_queues = nb_queues;
710 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
712 struct rte_eth_dev *dev;
714 /* This function is only safe when called from the primary process
715 * in a multi-process setup*/
716 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
718 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
720 dev = &rte_eth_devices[port_id];
721 if (rx_queue_id >= dev->data->nb_rx_queues) {
722 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
726 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
728 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
729 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
730 " already started\n",
731 rx_queue_id, port_id);
735 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
740 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
742 struct rte_eth_dev *dev;
744 /* This function is only safe when called from the primary process
745 * in a multi-process setup*/
746 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
748 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
750 dev = &rte_eth_devices[port_id];
751 if (rx_queue_id >= dev->data->nb_rx_queues) {
752 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
756 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
758 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
759 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
760 " already stopped\n",
761 rx_queue_id, port_id);
765 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
770 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
772 struct rte_eth_dev *dev;
774 /* This function is only safe when called from the primary process
775 * in a multi-process setup*/
776 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
778 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
780 dev = &rte_eth_devices[port_id];
781 if (tx_queue_id >= dev->data->nb_tx_queues) {
782 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
786 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
788 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
789 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
790 " already started\n",
791 tx_queue_id, port_id);
795 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
800 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
802 struct rte_eth_dev *dev;
804 /* This function is only safe when called from the primary process
805 * in a multi-process setup*/
806 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
808 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
810 dev = &rte_eth_devices[port_id];
811 if (tx_queue_id >= dev->data->nb_tx_queues) {
812 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
816 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
818 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
819 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
820 " already stopped\n",
821 tx_queue_id, port_id);
825 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
830 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
832 uint16_t old_nb_queues = dev->data->nb_tx_queues;
836 if (dev->data->tx_queues == NULL) { /* first time configuration */
837 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
838 sizeof(dev->data->tx_queues[0]) * nb_queues,
839 RTE_CACHE_LINE_SIZE);
840 if (dev->data->tx_queues == NULL) {
841 dev->data->nb_tx_queues = 0;
844 } else { /* re-configure */
845 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
847 txq = dev->data->tx_queues;
849 for (i = nb_queues; i < old_nb_queues; i++)
850 (*dev->dev_ops->tx_queue_release)(txq[i]);
851 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
852 RTE_CACHE_LINE_SIZE);
855 if (nb_queues > old_nb_queues) {
856 uint16_t new_qs = nb_queues - old_nb_queues;
858 memset(txq + old_nb_queues, 0,
859 sizeof(txq[0]) * new_qs);
862 dev->data->tx_queues = txq;
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 /* This function is only safe when called from the primary process
878 * in a multi-process setup*/
879 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
881 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
883 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
885 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
886 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
890 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
892 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
893 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
897 dev = &rte_eth_devices[port_id];
899 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
900 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
902 if (dev->data->dev_started) {
904 "port %d must be stopped to allow configuration\n", port_id);
909 * Check that the numbers of RX and TX queues are not greater
910 * than the maximum number of RX and TX queues supported by the
913 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
914 if (nb_rx_q > dev_info.max_rx_queues) {
915 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
916 port_id, nb_rx_q, dev_info.max_rx_queues);
920 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
924 if (nb_tx_q > dev_info.max_tx_queues) {
925 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
926 port_id, nb_tx_q, dev_info.max_tx_queues);
930 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
934 /* Copy the dev_conf parameter into the dev structure */
935 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
938 * If link state interrupt is enabled, check that the
939 * device supports it.
941 if ((dev_conf->intr_conf.lsc == 1) &&
942 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
943 RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
944 dev->data->drv_name);
949 * If jumbo frames are enabled, check that the maximum RX packet
950 * length is supported by the configured device.
952 if (dev_conf->rxmode.jumbo_frame == 1) {
953 if (dev_conf->rxmode.max_rx_pkt_len >
954 dev_info.max_rx_pktlen) {
955 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
956 " > max valid value %u\n",
958 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
959 (unsigned)dev_info.max_rx_pktlen);
961 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
962 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
963 " < min valid value %u\n",
965 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
966 (unsigned)ETHER_MIN_LEN);
970 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
971 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
972 /* Use default value */
973 dev->data->dev_conf.rxmode.max_rx_pkt_len =
978 * Setup new number of RX/TX queues and reconfigure device.
980 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
982 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
987 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
989 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
991 rte_eth_dev_rx_queue_config(dev, 0);
995 diag = (*dev->dev_ops->dev_configure)(dev);
997 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
999 rte_eth_dev_rx_queue_config(dev, 0);
1000 rte_eth_dev_tx_queue_config(dev, 0);
1008 rte_eth_dev_config_restore(uint8_t port_id)
1010 struct rte_eth_dev *dev;
1011 struct rte_eth_dev_info dev_info;
1012 struct ether_addr addr;
1016 dev = &rte_eth_devices[port_id];
1018 rte_eth_dev_info_get(port_id, &dev_info);
1020 if (RTE_ETH_DEV_SRIOV(dev).active)
1021 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
1023 /* replay MAC address configuration */
1024 for (i = 0; i < dev_info.max_mac_addrs; i++) {
1025 addr = dev->data->mac_addrs[i];
1027 /* skip zero address */
1028 if (is_zero_ether_addr(&addr))
1031 /* add address to the hardware */
1032 if (*dev->dev_ops->mac_addr_add &&
1033 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
1034 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
1036 RTE_PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
1038 /* exit the loop but not return an error */
1043 /* replay promiscuous configuration */
1044 if (rte_eth_promiscuous_get(port_id) == 1)
1045 rte_eth_promiscuous_enable(port_id);
1046 else if (rte_eth_promiscuous_get(port_id) == 0)
1047 rte_eth_promiscuous_disable(port_id);
1049 /* replay all multicast configuration */
1050 if (rte_eth_allmulticast_get(port_id) == 1)
1051 rte_eth_allmulticast_enable(port_id);
1052 else if (rte_eth_allmulticast_get(port_id) == 0)
1053 rte_eth_allmulticast_disable(port_id);
1057 rte_eth_dev_start(uint8_t port_id)
1059 struct rte_eth_dev *dev;
1062 /* This function is only safe when called from the primary process
1063 * in a multi-process setup*/
1064 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1066 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1068 dev = &rte_eth_devices[port_id];
1070 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1072 if (dev->data->dev_started != 0) {
1073 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1074 " already started\n",
1079 diag = (*dev->dev_ops->dev_start)(dev);
1081 dev->data->dev_started = 1;
1085 rte_eth_dev_config_restore(port_id);
1087 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1088 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1089 (*dev->dev_ops->link_update)(dev, 0);
1095 rte_eth_dev_stop(uint8_t port_id)
1097 struct rte_eth_dev *dev;
1099 /* This function is only safe when called from the primary process
1100 * in a multi-process setup*/
1101 RTE_PROC_PRIMARY_OR_RET();
1103 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1104 dev = &rte_eth_devices[port_id];
1106 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1108 if (dev->data->dev_started == 0) {
1109 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1110 " already stopped\n",
1115 dev->data->dev_started = 0;
1116 (*dev->dev_ops->dev_stop)(dev);
1120 rte_eth_dev_set_link_up(uint8_t port_id)
1122 struct rte_eth_dev *dev;
1124 /* This function is only safe when called from the primary process
1125 * in a multi-process setup*/
1126 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1128 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1130 dev = &rte_eth_devices[port_id];
1132 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1133 return (*dev->dev_ops->dev_set_link_up)(dev);
1137 rte_eth_dev_set_link_down(uint8_t port_id)
1139 struct rte_eth_dev *dev;
1141 /* This function is only safe when called from the primary process
1142 * in a multi-process setup*/
1143 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1145 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1147 dev = &rte_eth_devices[port_id];
1149 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1150 return (*dev->dev_ops->dev_set_link_down)(dev);
1154 rte_eth_dev_close(uint8_t port_id)
1156 struct rte_eth_dev *dev;
1158 /* This function is only safe when called from the primary process
1159 * in a multi-process setup*/
1160 RTE_PROC_PRIMARY_OR_RET();
1162 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1163 dev = &rte_eth_devices[port_id];
1165 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1166 dev->data->dev_started = 0;
1167 (*dev->dev_ops->dev_close)(dev);
1169 rte_free(dev->data->rx_queues);
1170 dev->data->rx_queues = NULL;
1171 rte_free(dev->data->tx_queues);
1172 dev->data->tx_queues = NULL;
1176 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1177 uint16_t nb_rx_desc, unsigned int socket_id,
1178 const struct rte_eth_rxconf *rx_conf,
1179 struct rte_mempool *mp)
1182 uint32_t mbp_buf_size;
1183 struct rte_eth_dev *dev;
1184 struct rte_eth_dev_info dev_info;
1186 /* This function is only safe when called from the primary process
1187 * in a multi-process setup*/
1188 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1190 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1192 dev = &rte_eth_devices[port_id];
1193 if (rx_queue_id >= dev->data->nb_rx_queues) {
1194 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1198 if (dev->data->dev_started) {
1199 RTE_PMD_DEBUG_TRACE(
1200 "port %d must be stopped to allow configuration\n", port_id);
1204 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1205 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1208 * Check the size of the mbuf data buffer.
1209 * This value must be provided in the private data of the memory pool.
1210 * First check that the memory pool has a valid private data.
1212 rte_eth_dev_info_get(port_id, &dev_info);
1213 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1214 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1215 mp->name, (int) mp->private_data_size,
1216 (int) sizeof(struct rte_pktmbuf_pool_private));
1219 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1221 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1222 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1223 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1227 (int)(RTE_PKTMBUF_HEADROOM +
1228 dev_info.min_rx_bufsize),
1229 (int)RTE_PKTMBUF_HEADROOM,
1230 (int)dev_info.min_rx_bufsize);
1234 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1235 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1236 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1238 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1239 "should be: <= %hu, = %hu, and a product of %hu\n",
1241 dev_info.rx_desc_lim.nb_max,
1242 dev_info.rx_desc_lim.nb_min,
1243 dev_info.rx_desc_lim.nb_align);
1247 if (rx_conf == NULL)
1248 rx_conf = &dev_info.default_rxconf;
1250 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1251 socket_id, rx_conf, mp);
1253 if (!dev->data->min_rx_buf_size ||
1254 dev->data->min_rx_buf_size > mbp_buf_size)
1255 dev->data->min_rx_buf_size = mbp_buf_size;
1262 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1263 uint16_t nb_tx_desc, unsigned int socket_id,
1264 const struct rte_eth_txconf *tx_conf)
1266 struct rte_eth_dev *dev;
1267 struct rte_eth_dev_info dev_info;
1269 /* This function is only safe when called from the primary process
1270 * in a multi-process setup*/
1271 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1273 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1275 dev = &rte_eth_devices[port_id];
1276 if (tx_queue_id >= dev->data->nb_tx_queues) {
1277 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1281 if (dev->data->dev_started) {
1282 RTE_PMD_DEBUG_TRACE(
1283 "port %d must be stopped to allow configuration\n", port_id);
1287 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1288 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1290 rte_eth_dev_info_get(port_id, &dev_info);
1292 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1293 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1294 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1295 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1296 "should be: <= %hu, = %hu, and a product of %hu\n",
1298 dev_info.tx_desc_lim.nb_max,
1299 dev_info.tx_desc_lim.nb_min,
1300 dev_info.tx_desc_lim.nb_align);
1304 if (tx_conf == NULL)
1305 tx_conf = &dev_info.default_txconf;
1307 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1308 socket_id, tx_conf);
1312 rte_eth_promiscuous_enable(uint8_t port_id)
1314 struct rte_eth_dev *dev;
1316 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1317 dev = &rte_eth_devices[port_id];
1319 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1320 (*dev->dev_ops->promiscuous_enable)(dev);
1321 dev->data->promiscuous = 1;
1325 rte_eth_promiscuous_disable(uint8_t port_id)
1327 struct rte_eth_dev *dev;
1329 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1330 dev = &rte_eth_devices[port_id];
1332 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1333 dev->data->promiscuous = 0;
1334 (*dev->dev_ops->promiscuous_disable)(dev);
1338 rte_eth_promiscuous_get(uint8_t port_id)
1340 struct rte_eth_dev *dev;
1342 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1344 dev = &rte_eth_devices[port_id];
1345 return dev->data->promiscuous;
1349 rte_eth_allmulticast_enable(uint8_t port_id)
1351 struct rte_eth_dev *dev;
1353 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1354 dev = &rte_eth_devices[port_id];
1356 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1357 (*dev->dev_ops->allmulticast_enable)(dev);
1358 dev->data->all_multicast = 1;
1362 rte_eth_allmulticast_disable(uint8_t port_id)
1364 struct rte_eth_dev *dev;
1366 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1367 dev = &rte_eth_devices[port_id];
1369 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1370 dev->data->all_multicast = 0;
1371 (*dev->dev_ops->allmulticast_disable)(dev);
1375 rte_eth_allmulticast_get(uint8_t port_id)
1377 struct rte_eth_dev *dev;
1379 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1381 dev = &rte_eth_devices[port_id];
1382 return dev->data->all_multicast;
1386 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1387 struct rte_eth_link *link)
1389 struct rte_eth_link *dst = link;
1390 struct rte_eth_link *src = &(dev->data->dev_link);
1392 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1393 *(uint64_t *)src) == 0)
1400 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1402 struct rte_eth_dev *dev;
1404 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1405 dev = &rte_eth_devices[port_id];
1407 if (dev->data->dev_conf.intr_conf.lsc != 0)
1408 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1410 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1411 (*dev->dev_ops->link_update)(dev, 1);
1412 *eth_link = dev->data->dev_link;
1417 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1419 struct rte_eth_dev *dev;
1421 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1422 dev = &rte_eth_devices[port_id];
1424 if (dev->data->dev_conf.intr_conf.lsc != 0)
1425 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1427 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1428 (*dev->dev_ops->link_update)(dev, 0);
1429 *eth_link = dev->data->dev_link;
1434 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1436 struct rte_eth_dev *dev;
1438 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1440 dev = &rte_eth_devices[port_id];
1441 memset(stats, 0, sizeof(*stats));
1443 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1444 (*dev->dev_ops->stats_get)(dev, stats);
1445 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1450 rte_eth_stats_reset(uint8_t port_id)
1452 struct rte_eth_dev *dev;
1454 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1455 dev = &rte_eth_devices[port_id];
1457 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1458 (*dev->dev_ops->stats_reset)(dev);
1459 dev->data->rx_mbuf_alloc_failed = 0;
1462 /* retrieve ethdev extended statistics */
1464 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1467 struct rte_eth_stats eth_stats;
1468 struct rte_eth_dev *dev;
1469 unsigned count = 0, i, q;
1471 uint64_t val, *stats_ptr;
1473 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1475 dev = &rte_eth_devices[port_id];
1477 /* Return generic statistics */
1478 count = RTE_NB_STATS + (dev->data->nb_rx_queues * RTE_NB_RXQ_STATS) +
1479 (dev->data->nb_tx_queues * RTE_NB_TXQ_STATS);
1481 /* implemented by the driver */
1482 if (dev->dev_ops->xstats_get != NULL) {
1483 /* Retrieve the xstats from the driver at the end of the
1486 xcount = (*dev->dev_ops->xstats_get)(dev, &xstats[count],
1487 (n > count) ? n - count : 0);
1493 if (n < count + xcount)
1494 return count + xcount;
1496 /* now fill the xstats structure */
1498 rte_eth_stats_get(port_id, ð_stats);
1501 for (i = 0; i < RTE_NB_STATS; i++) {
1502 stats_ptr = RTE_PTR_ADD(ð_stats,
1503 rte_stats_strings[i].offset);
1505 snprintf(xstats[count].name, sizeof(xstats[count].name),
1506 "%s", rte_stats_strings[i].name);
1507 xstats[count++].value = val;
1511 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1512 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1513 stats_ptr = RTE_PTR_ADD(ð_stats,
1514 rte_rxq_stats_strings[i].offset +
1515 q * sizeof(uint64_t));
1517 snprintf(xstats[count].name, sizeof(xstats[count].name),
1519 rte_rxq_stats_strings[i].name);
1520 xstats[count++].value = val;
1525 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1526 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1527 stats_ptr = RTE_PTR_ADD(ð_stats,
1528 rte_txq_stats_strings[i].offset +
1529 q * sizeof(uint64_t));
1531 snprintf(xstats[count].name, sizeof(xstats[count].name),
1533 rte_txq_stats_strings[i].name);
1534 xstats[count++].value = val;
1538 return count + xcount;
1541 /* reset ethdev extended statistics */
1543 rte_eth_xstats_reset(uint8_t port_id)
1545 struct rte_eth_dev *dev;
1547 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1548 dev = &rte_eth_devices[port_id];
1550 /* implemented by the driver */
1551 if (dev->dev_ops->xstats_reset != NULL) {
1552 (*dev->dev_ops->xstats_reset)(dev);
1556 /* fallback to default */
1557 rte_eth_stats_reset(port_id);
1561 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1564 struct rte_eth_dev *dev;
1566 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1568 dev = &rte_eth_devices[port_id];
1570 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1571 return (*dev->dev_ops->queue_stats_mapping_set)
1572 (dev, queue_id, stat_idx, is_rx);
1577 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1580 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1586 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1589 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1595 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1597 struct rte_eth_dev *dev;
1598 const struct rte_eth_desc_lim lim = {
1599 .nb_max = UINT16_MAX,
1604 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1605 dev = &rte_eth_devices[port_id];
1607 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1608 dev_info->rx_desc_lim = lim;
1609 dev_info->tx_desc_lim = lim;
1611 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1612 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1613 dev_info->pci_dev = dev->pci_dev;
1614 dev_info->driver_name = dev->data->drv_name;
1618 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1620 struct rte_eth_dev *dev;
1622 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1623 dev = &rte_eth_devices[port_id];
1624 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1629 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1631 struct rte_eth_dev *dev;
1633 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1635 dev = &rte_eth_devices[port_id];
1636 *mtu = dev->data->mtu;
1641 rte_eth_dev_set_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);
1647 dev = &rte_eth_devices[port_id];
1648 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1650 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1652 dev->data->mtu = mtu;
1658 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1660 struct rte_eth_dev *dev;
1662 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1663 dev = &rte_eth_devices[port_id];
1664 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1665 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1669 if (vlan_id > 4095) {
1670 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1671 port_id, (unsigned) vlan_id);
1674 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1676 return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1680 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1682 struct rte_eth_dev *dev;
1684 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1685 dev = &rte_eth_devices[port_id];
1686 if (rx_queue_id >= dev->data->nb_rx_queues) {
1687 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1691 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1692 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1698 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1700 struct rte_eth_dev *dev;
1702 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1703 dev = &rte_eth_devices[port_id];
1704 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1705 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1711 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1713 struct rte_eth_dev *dev;
1718 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1719 dev = &rte_eth_devices[port_id];
1721 /*check which option changed by application*/
1722 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1723 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1725 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1726 mask |= ETH_VLAN_STRIP_MASK;
1729 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1730 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1732 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1733 mask |= ETH_VLAN_FILTER_MASK;
1736 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1737 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1739 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1740 mask |= ETH_VLAN_EXTEND_MASK;
1747 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1748 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1754 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1756 struct rte_eth_dev *dev;
1759 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1760 dev = &rte_eth_devices[port_id];
1762 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1763 ret |= ETH_VLAN_STRIP_OFFLOAD;
1765 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1766 ret |= ETH_VLAN_FILTER_OFFLOAD;
1768 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1769 ret |= ETH_VLAN_EXTEND_OFFLOAD;
1775 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1777 struct rte_eth_dev *dev;
1779 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1780 dev = &rte_eth_devices[port_id];
1781 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1782 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1788 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1790 struct rte_eth_dev *dev;
1792 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1793 dev = &rte_eth_devices[port_id];
1794 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1795 memset(fc_conf, 0, sizeof(*fc_conf));
1796 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1800 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1802 struct rte_eth_dev *dev;
1804 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1805 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1806 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1810 dev = &rte_eth_devices[port_id];
1811 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1812 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1816 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1818 struct rte_eth_dev *dev;
1820 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1821 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1822 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1826 dev = &rte_eth_devices[port_id];
1827 /* High water, low water validation are device specific */
1828 if (*dev->dev_ops->priority_flow_ctrl_set)
1829 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1834 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
1842 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
1843 RTE_PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
1844 RTE_RETA_GROUP_SIZE);
1848 num = reta_size / RTE_RETA_GROUP_SIZE;
1849 for (i = 0; i < num; i++) {
1850 if (reta_conf[i].mask)
1858 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
1862 uint16_t i, idx, shift;
1868 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
1872 for (i = 0; i < reta_size; i++) {
1873 idx = i / RTE_RETA_GROUP_SIZE;
1874 shift = i % RTE_RETA_GROUP_SIZE;
1875 if ((reta_conf[idx].mask & (1ULL << shift)) &&
1876 (reta_conf[idx].reta[shift] >= max_rxq)) {
1877 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
1878 "the maximum rxq index: %u\n", idx, shift,
1879 reta_conf[idx].reta[shift], max_rxq);
1888 rte_eth_dev_rss_reta_update(uint8_t port_id,
1889 struct rte_eth_rss_reta_entry64 *reta_conf,
1892 struct rte_eth_dev *dev;
1895 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1896 /* Check mask bits */
1897 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
1901 dev = &rte_eth_devices[port_id];
1903 /* Check entry value */
1904 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
1905 dev->data->nb_rx_queues);
1909 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
1910 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
1914 rte_eth_dev_rss_reta_query(uint8_t port_id,
1915 struct rte_eth_rss_reta_entry64 *reta_conf,
1918 struct rte_eth_dev *dev;
1921 if (port_id >= nb_ports) {
1922 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1926 /* Check mask bits */
1927 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
1931 dev = &rte_eth_devices[port_id];
1932 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
1933 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
1937 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
1939 struct rte_eth_dev *dev;
1940 uint16_t rss_hash_protos;
1942 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1943 rss_hash_protos = rss_conf->rss_hf;
1944 if ((rss_hash_protos != 0) &&
1945 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
1946 RTE_PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
1950 dev = &rte_eth_devices[port_id];
1951 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
1952 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
1956 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
1957 struct rte_eth_rss_conf *rss_conf)
1959 struct rte_eth_dev *dev;
1961 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1962 dev = &rte_eth_devices[port_id];
1963 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
1964 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
1968 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
1969 struct rte_eth_udp_tunnel *udp_tunnel)
1971 struct rte_eth_dev *dev;
1973 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1974 if (udp_tunnel == NULL) {
1975 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
1979 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
1980 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
1984 dev = &rte_eth_devices[port_id];
1985 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
1986 return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
1990 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
1991 struct rte_eth_udp_tunnel *udp_tunnel)
1993 struct rte_eth_dev *dev;
1995 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1996 dev = &rte_eth_devices[port_id];
1998 if (udp_tunnel == NULL) {
1999 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2003 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2004 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2008 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2009 return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2013 rte_eth_led_on(uint8_t port_id)
2015 struct rte_eth_dev *dev;
2017 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2018 dev = &rte_eth_devices[port_id];
2019 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2020 return (*dev->dev_ops->dev_led_on)(dev);
2024 rte_eth_led_off(uint8_t port_id)
2026 struct rte_eth_dev *dev;
2028 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2029 dev = &rte_eth_devices[port_id];
2030 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2031 return (*dev->dev_ops->dev_led_off)(dev);
2035 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2039 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2041 struct rte_eth_dev_info dev_info;
2042 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2045 rte_eth_dev_info_get(port_id, &dev_info);
2047 for (i = 0; i < dev_info.max_mac_addrs; i++)
2048 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2054 static const struct ether_addr null_mac_addr;
2057 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2060 struct rte_eth_dev *dev;
2064 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2065 dev = &rte_eth_devices[port_id];
2066 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2068 if (is_zero_ether_addr(addr)) {
2069 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2073 if (pool >= ETH_64_POOLS) {
2074 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2078 index = get_mac_addr_index(port_id, addr);
2080 index = get_mac_addr_index(port_id, &null_mac_addr);
2082 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2087 pool_mask = dev->data->mac_pool_sel[index];
2089 /* Check if both MAC address and pool is already there, and do nothing */
2090 if (pool_mask & (1ULL << pool))
2095 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2097 /* Update address in NIC data structure */
2098 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2100 /* Update pool bitmap in NIC data structure */
2101 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2107 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2109 struct rte_eth_dev *dev;
2112 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2113 dev = &rte_eth_devices[port_id];
2114 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2116 index = get_mac_addr_index(port_id, addr);
2118 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2120 } else if (index < 0)
2121 return 0; /* Do nothing if address wasn't found */
2124 (*dev->dev_ops->mac_addr_remove)(dev, index);
2126 /* Update address in NIC data structure */
2127 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2129 /* reset pool bitmap */
2130 dev->data->mac_pool_sel[index] = 0;
2136 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2138 struct rte_eth_dev *dev;
2140 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2142 if (!is_valid_assigned_ether_addr(addr))
2145 dev = &rte_eth_devices[port_id];
2146 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2148 /* Update default address in NIC data structure */
2149 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2151 (*dev->dev_ops->mac_addr_set)(dev, addr);
2157 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2158 uint16_t rx_mode, uint8_t on)
2161 struct rte_eth_dev *dev;
2162 struct rte_eth_dev_info dev_info;
2164 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2166 dev = &rte_eth_devices[port_id];
2167 rte_eth_dev_info_get(port_id, &dev_info);
2169 num_vfs = dev_info.max_vfs;
2171 RTE_PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2176 RTE_PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2179 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2180 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2184 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2188 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2190 struct rte_eth_dev_info dev_info;
2191 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2194 rte_eth_dev_info_get(port_id, &dev_info);
2195 if (!dev->data->hash_mac_addrs)
2198 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2199 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2200 ETHER_ADDR_LEN) == 0)
2207 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2212 struct rte_eth_dev *dev;
2214 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2216 dev = &rte_eth_devices[port_id];
2217 if (is_zero_ether_addr(addr)) {
2218 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2223 index = get_hash_mac_addr_index(port_id, addr);
2224 /* Check if it's already there, and do nothing */
2225 if ((index >= 0) && (on))
2230 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2231 "set in UTA\n", port_id);
2235 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2237 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2243 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2244 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2246 /* Update address in NIC data structure */
2248 ether_addr_copy(addr,
2249 &dev->data->hash_mac_addrs[index]);
2251 ether_addr_copy(&null_mac_addr,
2252 &dev->data->hash_mac_addrs[index]);
2259 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2261 struct rte_eth_dev *dev;
2263 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2265 dev = &rte_eth_devices[port_id];
2267 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2268 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2272 rte_eth_dev_set_vf_rx(uint8_t port_id, uint16_t vf, uint8_t on)
2275 struct rte_eth_dev *dev;
2276 struct rte_eth_dev_info dev_info;
2278 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2280 dev = &rte_eth_devices[port_id];
2281 rte_eth_dev_info_get(port_id, &dev_info);
2283 num_vfs = dev_info.max_vfs;
2285 RTE_PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2289 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2290 return (*dev->dev_ops->set_vf_rx)(dev, vf, on);
2294 rte_eth_dev_set_vf_tx(uint8_t port_id, uint16_t vf, uint8_t on)
2297 struct rte_eth_dev *dev;
2298 struct rte_eth_dev_info dev_info;
2300 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2302 dev = &rte_eth_devices[port_id];
2303 rte_eth_dev_info_get(port_id, &dev_info);
2305 num_vfs = dev_info.max_vfs;
2307 RTE_PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2311 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2312 return (*dev->dev_ops->set_vf_tx)(dev, vf, on);
2316 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2317 uint64_t vf_mask, uint8_t vlan_on)
2319 struct rte_eth_dev *dev;
2321 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2323 dev = &rte_eth_devices[port_id];
2325 if (vlan_id > ETHER_MAX_VLAN_ID) {
2326 RTE_PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2332 RTE_PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2336 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2337 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2341 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2344 struct rte_eth_dev *dev;
2345 struct rte_eth_dev_info dev_info;
2346 struct rte_eth_link link;
2348 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2350 dev = &rte_eth_devices[port_id];
2351 rte_eth_dev_info_get(port_id, &dev_info);
2352 link = dev->data->dev_link;
2354 if (queue_idx > dev_info.max_tx_queues) {
2355 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2356 "invalid queue id=%d\n", port_id, queue_idx);
2360 if (tx_rate > link.link_speed) {
2361 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2362 "bigger than link speed= %d\n",
2363 tx_rate, link.link_speed);
2367 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2368 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2371 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2374 struct rte_eth_dev *dev;
2375 struct rte_eth_dev_info dev_info;
2376 struct rte_eth_link link;
2381 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2383 dev = &rte_eth_devices[port_id];
2384 rte_eth_dev_info_get(port_id, &dev_info);
2385 link = dev->data->dev_link;
2387 if (vf > dev_info.max_vfs) {
2388 RTE_PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2389 "invalid vf id=%d\n", port_id, vf);
2393 if (tx_rate > link.link_speed) {
2394 RTE_PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2395 "bigger than link speed= %d\n",
2396 tx_rate, link.link_speed);
2400 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2401 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2405 rte_eth_mirror_rule_set(uint8_t port_id,
2406 struct rte_eth_mirror_conf *mirror_conf,
2407 uint8_t rule_id, uint8_t on)
2409 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2411 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2412 if (mirror_conf->rule_type == 0) {
2413 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2417 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2418 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2423 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2424 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2425 (mirror_conf->pool_mask == 0)) {
2426 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2430 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2431 mirror_conf->vlan.vlan_mask == 0) {
2432 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2436 dev = &rte_eth_devices[port_id];
2437 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2439 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2443 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2445 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2447 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2449 dev = &rte_eth_devices[port_id];
2450 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2452 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2456 rte_eth_dev_callback_register(uint8_t port_id,
2457 enum rte_eth_event_type event,
2458 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2460 struct rte_eth_dev *dev;
2461 struct rte_eth_dev_callback *user_cb;
2466 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2468 dev = &rte_eth_devices[port_id];
2469 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2471 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2472 if (user_cb->cb_fn == cb_fn &&
2473 user_cb->cb_arg == cb_arg &&
2474 user_cb->event == event) {
2479 /* create a new callback. */
2480 if (user_cb == NULL)
2481 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2482 sizeof(struct rte_eth_dev_callback), 0);
2483 if (user_cb != NULL) {
2484 user_cb->cb_fn = cb_fn;
2485 user_cb->cb_arg = cb_arg;
2486 user_cb->event = event;
2487 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2490 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2491 return (user_cb == NULL) ? -ENOMEM : 0;
2495 rte_eth_dev_callback_unregister(uint8_t port_id,
2496 enum rte_eth_event_type event,
2497 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2500 struct rte_eth_dev *dev;
2501 struct rte_eth_dev_callback *cb, *next;
2506 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2508 dev = &rte_eth_devices[port_id];
2509 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2512 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2514 next = TAILQ_NEXT(cb, next);
2516 if (cb->cb_fn != cb_fn || cb->event != event ||
2517 (cb->cb_arg != (void *)-1 &&
2518 cb->cb_arg != cb_arg))
2522 * if this callback is not executing right now,
2525 if (cb->active == 0) {
2526 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2533 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2538 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2539 enum rte_eth_event_type event)
2541 struct rte_eth_dev_callback *cb_lst;
2542 struct rte_eth_dev_callback dev_cb;
2544 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2545 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2546 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2550 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2551 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2553 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2556 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2560 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
2563 struct rte_eth_dev *dev;
2564 struct rte_intr_handle *intr_handle;
2568 if (!rte_eth_dev_is_valid_port(port_id)) {
2569 RTE_PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
2573 dev = &rte_eth_devices[port_id];
2574 intr_handle = &dev->pci_dev->intr_handle;
2575 if (!intr_handle->intr_vec) {
2576 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2580 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2581 vec = intr_handle->intr_vec[qid];
2582 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2583 if (rc && rc != -EEXIST) {
2584 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2585 " op %d epfd %d vec %u\n",
2586 port_id, qid, op, epfd, vec);
2593 const struct rte_memzone *
2594 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2595 uint16_t queue_id, size_t size, unsigned align,
2598 char z_name[RTE_MEMZONE_NAMESIZE];
2599 const struct rte_memzone *mz;
2601 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2602 dev->driver->pci_drv.name, ring_name,
2603 dev->data->port_id, queue_id);
2605 mz = rte_memzone_lookup(z_name);
2609 if (rte_xen_dom0_supported())
2610 return rte_memzone_reserve_bounded(z_name, size, socket_id,
2611 0, align, RTE_PGSIZE_2M);
2613 return rte_memzone_reserve_aligned(z_name, size, socket_id,
2618 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
2619 int epfd, int op, void *data)
2622 struct rte_eth_dev *dev;
2623 struct rte_intr_handle *intr_handle;
2626 if (!rte_eth_dev_is_valid_port(port_id)) {
2627 RTE_PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
2631 dev = &rte_eth_devices[port_id];
2632 if (queue_id >= dev->data->nb_rx_queues) {
2633 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
2637 intr_handle = &dev->pci_dev->intr_handle;
2638 if (!intr_handle->intr_vec) {
2639 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2643 vec = intr_handle->intr_vec[queue_id];
2644 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2645 if (rc && rc != -EEXIST) {
2646 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2647 " op %d epfd %d vec %u\n",
2648 port_id, queue_id, op, epfd, vec);
2656 rte_eth_dev_rx_intr_enable(uint8_t port_id,
2659 struct rte_eth_dev *dev;
2661 if (!rte_eth_dev_is_valid_port(port_id)) {
2662 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2666 dev = &rte_eth_devices[port_id];
2668 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
2669 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
2673 rte_eth_dev_rx_intr_disable(uint8_t port_id,
2676 struct rte_eth_dev *dev;
2678 if (!rte_eth_dev_is_valid_port(port_id)) {
2679 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2683 dev = &rte_eth_devices[port_id];
2685 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
2686 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
2689 #ifdef RTE_NIC_BYPASS
2690 int rte_eth_dev_bypass_init(uint8_t port_id)
2692 struct rte_eth_dev *dev;
2694 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2696 dev = &rte_eth_devices[port_id];
2697 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2698 (*dev->dev_ops->bypass_init)(dev);
2703 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2705 struct rte_eth_dev *dev;
2707 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2709 dev = &rte_eth_devices[port_id];
2710 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2711 (*dev->dev_ops->bypass_state_show)(dev, state);
2716 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2718 struct rte_eth_dev *dev;
2720 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2722 dev = &rte_eth_devices[port_id];
2723 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2724 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2729 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2731 struct rte_eth_dev *dev;
2733 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2735 dev = &rte_eth_devices[port_id];
2736 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2737 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2742 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2744 struct rte_eth_dev *dev;
2746 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2748 dev = &rte_eth_devices[port_id];
2750 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2751 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2756 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
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_wd_timeout_set, -ENOTSUP);
2765 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2770 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
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_ver_show, -ENOTSUP);
2779 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2784 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
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_wd_timeout_show, -ENOTSUP);
2793 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2798 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
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_reset, -ENOTSUP);
2807 (*dev->dev_ops->bypass_wd_reset)(dev);
2813 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
2815 struct rte_eth_dev *dev;
2817 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2819 dev = &rte_eth_devices[port_id];
2820 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2821 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
2822 RTE_ETH_FILTER_NOP, NULL);
2826 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
2827 enum rte_filter_op filter_op, void *arg)
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, filter_op, arg);
2839 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
2840 rte_rx_callback_fn fn, void *user_param)
2842 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2843 rte_errno = ENOTSUP;
2846 /* check input parameters */
2847 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2848 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2853 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2861 cb->param = user_param;
2863 /* Add the callbacks in fifo order. */
2864 struct rte_eth_rxtx_callback *tail =
2865 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2868 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2880 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
2881 rte_tx_callback_fn fn, void *user_param)
2883 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2884 rte_errno = ENOTSUP;
2887 /* check input parameters */
2888 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2889 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
2894 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2902 cb->param = user_param;
2904 /* Add the callbacks in fifo order. */
2905 struct rte_eth_rxtx_callback *tail =
2906 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
2909 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
2921 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
2922 struct rte_eth_rxtx_callback *user_cb)
2924 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2927 /* Check input parameters. */
2928 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
2929 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2933 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2934 struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
2935 struct rte_eth_rxtx_callback *prev_cb;
2937 /* Reset head pointer and remove user cb if first in the list. */
2938 if (cb == user_cb) {
2939 dev->post_rx_burst_cbs[queue_id] = user_cb->next;
2943 /* Remove the user cb from the callback list. */
2948 if (cb == user_cb) {
2949 prev_cb->next = user_cb->next;
2953 } while (cb != NULL);
2955 /* Callback wasn't found. */
2960 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
2961 struct rte_eth_rxtx_callback *user_cb)
2963 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2966 /* Check input parameters. */
2967 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
2968 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
2972 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2973 struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
2974 struct rte_eth_rxtx_callback *prev_cb;
2976 /* Reset head pointer and remove user cb if first in the list. */
2977 if (cb == user_cb) {
2978 dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
2982 /* Remove the user cb from the callback list. */
2987 if (cb == user_cb) {
2988 prev_cb->next = user_cb->next;
2992 } while (cb != NULL);
2994 /* Callback wasn't found. */
2999 rte_eth_rx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3000 struct rte_eth_rxq_info *qinfo)
3002 struct rte_eth_dev *dev;
3004 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3009 dev = &rte_eth_devices[port_id];
3010 if (queue_id >= dev->data->nb_rx_queues) {
3011 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3015 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3017 memset(qinfo, 0, sizeof(*qinfo));
3018 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3023 rte_eth_tx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3024 struct rte_eth_txq_info *qinfo)
3026 struct rte_eth_dev *dev;
3028 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3033 dev = &rte_eth_devices[port_id];
3034 if (queue_id >= dev->data->nb_tx_queues) {
3035 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3039 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3041 memset(qinfo, 0, sizeof(*qinfo));
3042 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3047 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3048 struct ether_addr *mc_addr_set,
3049 uint32_t nb_mc_addr)
3051 struct rte_eth_dev *dev;
3053 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3055 dev = &rte_eth_devices[port_id];
3056 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3057 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3061 rte_eth_timesync_enable(uint8_t port_id)
3063 struct rte_eth_dev *dev;
3065 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3066 dev = &rte_eth_devices[port_id];
3068 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3069 return (*dev->dev_ops->timesync_enable)(dev);
3073 rte_eth_timesync_disable(uint8_t port_id)
3075 struct rte_eth_dev *dev;
3077 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3078 dev = &rte_eth_devices[port_id];
3080 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3081 return (*dev->dev_ops->timesync_disable)(dev);
3085 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3088 struct rte_eth_dev *dev;
3090 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3091 dev = &rte_eth_devices[port_id];
3093 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3094 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3098 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3100 struct rte_eth_dev *dev;
3102 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3103 dev = &rte_eth_devices[port_id];
3105 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3106 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3110 rte_eth_timesync_adjust_time(uint8_t port_id, int64_t delta)
3112 struct rte_eth_dev *dev;
3114 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3115 dev = &rte_eth_devices[port_id];
3117 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3118 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3122 rte_eth_timesync_read_time(uint8_t port_id, struct timespec *timestamp)
3124 struct rte_eth_dev *dev;
3126 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3127 dev = &rte_eth_devices[port_id];
3129 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3130 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3134 rte_eth_timesync_write_time(uint8_t port_id, const struct timespec *timestamp)
3136 struct rte_eth_dev *dev;
3138 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3139 dev = &rte_eth_devices[port_id];
3141 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3142 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3146 rte_eth_dev_get_reg_length(uint8_t port_id)
3148 struct rte_eth_dev *dev;
3150 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3152 dev = &rte_eth_devices[port_id];
3153 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg_length, -ENOTSUP);
3154 return (*dev->dev_ops->get_reg_length)(dev);
3158 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3160 struct rte_eth_dev *dev;
3162 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3164 dev = &rte_eth_devices[port_id];
3165 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3166 return (*dev->dev_ops->get_reg)(dev, info);
3170 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3172 struct rte_eth_dev *dev;
3174 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3176 dev = &rte_eth_devices[port_id];
3177 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3178 return (*dev->dev_ops->get_eeprom_length)(dev);
3182 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3184 struct rte_eth_dev *dev;
3186 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3188 dev = &rte_eth_devices[port_id];
3189 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3190 return (*dev->dev_ops->get_eeprom)(dev, info);
3194 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3196 struct rte_eth_dev *dev;
3198 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3200 dev = &rte_eth_devices[port_id];
3201 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3202 return (*dev->dev_ops->set_eeprom)(dev, info);
3206 rte_eth_dev_get_dcb_info(uint8_t port_id,
3207 struct rte_eth_dcb_info *dcb_info)
3209 struct rte_eth_dev *dev;
3211 if (!rte_eth_dev_is_valid_port(port_id)) {
3212 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3216 dev = &rte_eth_devices[port_id];
3217 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3219 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3220 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3224 rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_dev)
3226 if ((eth_dev == NULL) || (pci_dev == NULL)) {
3227 RTE_PMD_DEBUG_TRACE("NULL pointer eth_dev=%p pci_dev=%p\n",
3232 eth_dev->data->dev_flags = 0;
3233 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
3234 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
3235 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_DETACHABLE)
3236 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
3238 eth_dev->data->kdrv = pci_dev->kdrv;
3239 eth_dev->data->numa_node = pci_dev->numa_node;
3240 eth_dev->data->drv_name = pci_dev->driver->name;