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);
1461 /* retrieve ethdev extended statistics */
1463 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1466 struct rte_eth_stats eth_stats;
1467 struct rte_eth_dev *dev;
1468 unsigned count = 0, i, q;
1470 uint64_t val, *stats_ptr;
1472 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1474 dev = &rte_eth_devices[port_id];
1476 /* Return generic statistics */
1477 count = RTE_NB_STATS + (dev->data->nb_rx_queues * RTE_NB_RXQ_STATS) +
1478 (dev->data->nb_tx_queues * RTE_NB_TXQ_STATS);
1480 /* implemented by the driver */
1481 if (dev->dev_ops->xstats_get != NULL) {
1482 /* Retrieve the xstats from the driver at the end of the
1485 xcount = (*dev->dev_ops->xstats_get)(dev, &xstats[count],
1486 (n > count) ? n - count : 0);
1492 if (n < count + xcount)
1493 return count + xcount;
1495 /* now fill the xstats structure */
1497 rte_eth_stats_get(port_id, ð_stats);
1500 for (i = 0; i < RTE_NB_STATS; i++) {
1501 stats_ptr = RTE_PTR_ADD(ð_stats,
1502 rte_stats_strings[i].offset);
1504 snprintf(xstats[count].name, sizeof(xstats[count].name),
1505 "%s", rte_stats_strings[i].name);
1506 xstats[count++].value = val;
1510 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1511 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1512 stats_ptr = RTE_PTR_ADD(ð_stats,
1513 rte_rxq_stats_strings[i].offset +
1514 q * sizeof(uint64_t));
1516 snprintf(xstats[count].name, sizeof(xstats[count].name),
1518 rte_rxq_stats_strings[i].name);
1519 xstats[count++].value = val;
1524 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1525 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1526 stats_ptr = RTE_PTR_ADD(ð_stats,
1527 rte_txq_stats_strings[i].offset +
1528 q * sizeof(uint64_t));
1530 snprintf(xstats[count].name, sizeof(xstats[count].name),
1532 rte_txq_stats_strings[i].name);
1533 xstats[count++].value = val;
1537 return count + xcount;
1540 /* reset ethdev extended statistics */
1542 rte_eth_xstats_reset(uint8_t port_id)
1544 struct rte_eth_dev *dev;
1546 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1547 dev = &rte_eth_devices[port_id];
1549 /* implemented by the driver */
1550 if (dev->dev_ops->xstats_reset != NULL) {
1551 (*dev->dev_ops->xstats_reset)(dev);
1555 /* fallback to default */
1556 rte_eth_stats_reset(port_id);
1560 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1563 struct rte_eth_dev *dev;
1565 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1567 dev = &rte_eth_devices[port_id];
1569 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1570 return (*dev->dev_ops->queue_stats_mapping_set)
1571 (dev, queue_id, stat_idx, is_rx);
1576 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1579 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1585 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1588 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1594 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1596 struct rte_eth_dev *dev;
1597 const struct rte_eth_desc_lim lim = {
1598 .nb_max = UINT16_MAX,
1603 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1604 dev = &rte_eth_devices[port_id];
1606 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1607 dev_info->rx_desc_lim = lim;
1608 dev_info->tx_desc_lim = lim;
1610 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1611 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1612 dev_info->pci_dev = dev->pci_dev;
1613 dev_info->driver_name = dev->data->drv_name;
1617 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1619 struct rte_eth_dev *dev;
1621 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1622 dev = &rte_eth_devices[port_id];
1623 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1628 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1630 struct rte_eth_dev *dev;
1632 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1634 dev = &rte_eth_devices[port_id];
1635 *mtu = dev->data->mtu;
1640 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1643 struct rte_eth_dev *dev;
1645 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1646 dev = &rte_eth_devices[port_id];
1647 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1649 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1651 dev->data->mtu = mtu;
1657 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1659 struct rte_eth_dev *dev;
1661 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1662 dev = &rte_eth_devices[port_id];
1663 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1664 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1668 if (vlan_id > 4095) {
1669 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1670 port_id, (unsigned) vlan_id);
1673 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1675 return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1679 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1681 struct rte_eth_dev *dev;
1683 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1684 dev = &rte_eth_devices[port_id];
1685 if (rx_queue_id >= dev->data->nb_rx_queues) {
1686 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1690 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1691 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1697 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1699 struct rte_eth_dev *dev;
1701 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1702 dev = &rte_eth_devices[port_id];
1703 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1704 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1710 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1712 struct rte_eth_dev *dev;
1717 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1718 dev = &rte_eth_devices[port_id];
1720 /*check which option changed by application*/
1721 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1722 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1724 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1725 mask |= ETH_VLAN_STRIP_MASK;
1728 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1729 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1731 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1732 mask |= ETH_VLAN_FILTER_MASK;
1735 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1736 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1738 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1739 mask |= ETH_VLAN_EXTEND_MASK;
1746 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1747 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1753 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1755 struct rte_eth_dev *dev;
1758 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1759 dev = &rte_eth_devices[port_id];
1761 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1762 ret |= ETH_VLAN_STRIP_OFFLOAD;
1764 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1765 ret |= ETH_VLAN_FILTER_OFFLOAD;
1767 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1768 ret |= ETH_VLAN_EXTEND_OFFLOAD;
1774 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1776 struct rte_eth_dev *dev;
1778 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1779 dev = &rte_eth_devices[port_id];
1780 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1781 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1787 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1789 struct rte_eth_dev *dev;
1791 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1792 dev = &rte_eth_devices[port_id];
1793 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1794 memset(fc_conf, 0, sizeof(*fc_conf));
1795 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1799 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1801 struct rte_eth_dev *dev;
1803 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1804 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1805 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1809 dev = &rte_eth_devices[port_id];
1810 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1811 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1815 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1817 struct rte_eth_dev *dev;
1819 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1820 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1821 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1825 dev = &rte_eth_devices[port_id];
1826 /* High water, low water validation are device specific */
1827 if (*dev->dev_ops->priority_flow_ctrl_set)
1828 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1833 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
1841 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
1842 RTE_PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
1843 RTE_RETA_GROUP_SIZE);
1847 num = reta_size / RTE_RETA_GROUP_SIZE;
1848 for (i = 0; i < num; i++) {
1849 if (reta_conf[i].mask)
1857 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
1861 uint16_t i, idx, shift;
1867 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
1871 for (i = 0; i < reta_size; i++) {
1872 idx = i / RTE_RETA_GROUP_SIZE;
1873 shift = i % RTE_RETA_GROUP_SIZE;
1874 if ((reta_conf[idx].mask & (1ULL << shift)) &&
1875 (reta_conf[idx].reta[shift] >= max_rxq)) {
1876 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
1877 "the maximum rxq index: %u\n", idx, shift,
1878 reta_conf[idx].reta[shift], max_rxq);
1887 rte_eth_dev_rss_reta_update(uint8_t port_id,
1888 struct rte_eth_rss_reta_entry64 *reta_conf,
1891 struct rte_eth_dev *dev;
1894 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1895 /* Check mask bits */
1896 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
1900 dev = &rte_eth_devices[port_id];
1902 /* Check entry value */
1903 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
1904 dev->data->nb_rx_queues);
1908 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
1909 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
1913 rte_eth_dev_rss_reta_query(uint8_t port_id,
1914 struct rte_eth_rss_reta_entry64 *reta_conf,
1917 struct rte_eth_dev *dev;
1920 if (port_id >= nb_ports) {
1921 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1925 /* Check mask bits */
1926 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
1930 dev = &rte_eth_devices[port_id];
1931 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
1932 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
1936 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
1938 struct rte_eth_dev *dev;
1939 uint16_t rss_hash_protos;
1941 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1942 rss_hash_protos = rss_conf->rss_hf;
1943 if ((rss_hash_protos != 0) &&
1944 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
1945 RTE_PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
1949 dev = &rte_eth_devices[port_id];
1950 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
1951 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
1955 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
1956 struct rte_eth_rss_conf *rss_conf)
1958 struct rte_eth_dev *dev;
1960 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1961 dev = &rte_eth_devices[port_id];
1962 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
1963 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
1967 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
1968 struct rte_eth_udp_tunnel *udp_tunnel)
1970 struct rte_eth_dev *dev;
1972 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1973 if (udp_tunnel == NULL) {
1974 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
1978 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
1979 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
1983 dev = &rte_eth_devices[port_id];
1984 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
1985 return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
1989 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
1990 struct rte_eth_udp_tunnel *udp_tunnel)
1992 struct rte_eth_dev *dev;
1994 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1995 dev = &rte_eth_devices[port_id];
1997 if (udp_tunnel == NULL) {
1998 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2002 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2003 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2007 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2008 return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2012 rte_eth_led_on(uint8_t port_id)
2014 struct rte_eth_dev *dev;
2016 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2017 dev = &rte_eth_devices[port_id];
2018 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2019 return (*dev->dev_ops->dev_led_on)(dev);
2023 rte_eth_led_off(uint8_t port_id)
2025 struct rte_eth_dev *dev;
2027 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2028 dev = &rte_eth_devices[port_id];
2029 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2030 return (*dev->dev_ops->dev_led_off)(dev);
2034 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2038 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2040 struct rte_eth_dev_info dev_info;
2041 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2044 rte_eth_dev_info_get(port_id, &dev_info);
2046 for (i = 0; i < dev_info.max_mac_addrs; i++)
2047 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2053 static const struct ether_addr null_mac_addr;
2056 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2059 struct rte_eth_dev *dev;
2063 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2064 dev = &rte_eth_devices[port_id];
2065 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2067 if (is_zero_ether_addr(addr)) {
2068 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2072 if (pool >= ETH_64_POOLS) {
2073 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2077 index = get_mac_addr_index(port_id, addr);
2079 index = get_mac_addr_index(port_id, &null_mac_addr);
2081 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2086 pool_mask = dev->data->mac_pool_sel[index];
2088 /* Check if both MAC address and pool is already there, and do nothing */
2089 if (pool_mask & (1ULL << pool))
2094 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2096 /* Update address in NIC data structure */
2097 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2099 /* Update pool bitmap in NIC data structure */
2100 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2106 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2108 struct rte_eth_dev *dev;
2111 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2112 dev = &rte_eth_devices[port_id];
2113 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2115 index = get_mac_addr_index(port_id, addr);
2117 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2119 } else if (index < 0)
2120 return 0; /* Do nothing if address wasn't found */
2123 (*dev->dev_ops->mac_addr_remove)(dev, index);
2125 /* Update address in NIC data structure */
2126 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2128 /* reset pool bitmap */
2129 dev->data->mac_pool_sel[index] = 0;
2135 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2137 struct rte_eth_dev *dev;
2139 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2141 if (!is_valid_assigned_ether_addr(addr))
2144 dev = &rte_eth_devices[port_id];
2145 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2147 /* Update default address in NIC data structure */
2148 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2150 (*dev->dev_ops->mac_addr_set)(dev, addr);
2156 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2157 uint16_t rx_mode, uint8_t on)
2160 struct rte_eth_dev *dev;
2161 struct rte_eth_dev_info dev_info;
2163 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2165 dev = &rte_eth_devices[port_id];
2166 rte_eth_dev_info_get(port_id, &dev_info);
2168 num_vfs = dev_info.max_vfs;
2170 RTE_PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2175 RTE_PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2178 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2179 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2183 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2187 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2189 struct rte_eth_dev_info dev_info;
2190 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2193 rte_eth_dev_info_get(port_id, &dev_info);
2194 if (!dev->data->hash_mac_addrs)
2197 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2198 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2199 ETHER_ADDR_LEN) == 0)
2206 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2211 struct rte_eth_dev *dev;
2213 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2215 dev = &rte_eth_devices[port_id];
2216 if (is_zero_ether_addr(addr)) {
2217 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2222 index = get_hash_mac_addr_index(port_id, addr);
2223 /* Check if it's already there, and do nothing */
2224 if ((index >= 0) && (on))
2229 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2230 "set in UTA\n", port_id);
2234 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2236 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2242 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2243 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2245 /* Update address in NIC data structure */
2247 ether_addr_copy(addr,
2248 &dev->data->hash_mac_addrs[index]);
2250 ether_addr_copy(&null_mac_addr,
2251 &dev->data->hash_mac_addrs[index]);
2258 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2260 struct rte_eth_dev *dev;
2262 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2264 dev = &rte_eth_devices[port_id];
2266 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2267 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2271 rte_eth_dev_set_vf_rx(uint8_t port_id, uint16_t vf, uint8_t on)
2274 struct rte_eth_dev *dev;
2275 struct rte_eth_dev_info dev_info;
2277 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2279 dev = &rte_eth_devices[port_id];
2280 rte_eth_dev_info_get(port_id, &dev_info);
2282 num_vfs = dev_info.max_vfs;
2284 RTE_PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2288 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2289 return (*dev->dev_ops->set_vf_rx)(dev, vf, on);
2293 rte_eth_dev_set_vf_tx(uint8_t port_id, uint16_t vf, uint8_t on)
2296 struct rte_eth_dev *dev;
2297 struct rte_eth_dev_info dev_info;
2299 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2301 dev = &rte_eth_devices[port_id];
2302 rte_eth_dev_info_get(port_id, &dev_info);
2304 num_vfs = dev_info.max_vfs;
2306 RTE_PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2310 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2311 return (*dev->dev_ops->set_vf_tx)(dev, vf, on);
2315 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2316 uint64_t vf_mask, uint8_t vlan_on)
2318 struct rte_eth_dev *dev;
2320 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2322 dev = &rte_eth_devices[port_id];
2324 if (vlan_id > ETHER_MAX_VLAN_ID) {
2325 RTE_PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2331 RTE_PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2335 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2336 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2340 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2343 struct rte_eth_dev *dev;
2344 struct rte_eth_dev_info dev_info;
2345 struct rte_eth_link link;
2347 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2349 dev = &rte_eth_devices[port_id];
2350 rte_eth_dev_info_get(port_id, &dev_info);
2351 link = dev->data->dev_link;
2353 if (queue_idx > dev_info.max_tx_queues) {
2354 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2355 "invalid queue id=%d\n", port_id, queue_idx);
2359 if (tx_rate > link.link_speed) {
2360 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2361 "bigger than link speed= %d\n",
2362 tx_rate, link.link_speed);
2366 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2367 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2370 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2373 struct rte_eth_dev *dev;
2374 struct rte_eth_dev_info dev_info;
2375 struct rte_eth_link link;
2380 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2382 dev = &rte_eth_devices[port_id];
2383 rte_eth_dev_info_get(port_id, &dev_info);
2384 link = dev->data->dev_link;
2386 if (vf > dev_info.max_vfs) {
2387 RTE_PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2388 "invalid vf id=%d\n", port_id, vf);
2392 if (tx_rate > link.link_speed) {
2393 RTE_PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2394 "bigger than link speed= %d\n",
2395 tx_rate, link.link_speed);
2399 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2400 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2404 rte_eth_mirror_rule_set(uint8_t port_id,
2405 struct rte_eth_mirror_conf *mirror_conf,
2406 uint8_t rule_id, uint8_t on)
2408 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2410 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2411 if (mirror_conf->rule_type == 0) {
2412 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2416 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2417 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2422 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2423 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2424 (mirror_conf->pool_mask == 0)) {
2425 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2429 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2430 mirror_conf->vlan.vlan_mask == 0) {
2431 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2435 dev = &rte_eth_devices[port_id];
2436 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2438 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2442 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2444 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2446 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2448 dev = &rte_eth_devices[port_id];
2449 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2451 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2455 rte_eth_dev_callback_register(uint8_t port_id,
2456 enum rte_eth_event_type event,
2457 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2459 struct rte_eth_dev *dev;
2460 struct rte_eth_dev_callback *user_cb;
2465 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2467 dev = &rte_eth_devices[port_id];
2468 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2470 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2471 if (user_cb->cb_fn == cb_fn &&
2472 user_cb->cb_arg == cb_arg &&
2473 user_cb->event == event) {
2478 /* create a new callback. */
2479 if (user_cb == NULL)
2480 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2481 sizeof(struct rte_eth_dev_callback), 0);
2482 if (user_cb != NULL) {
2483 user_cb->cb_fn = cb_fn;
2484 user_cb->cb_arg = cb_arg;
2485 user_cb->event = event;
2486 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2489 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2490 return (user_cb == NULL) ? -ENOMEM : 0;
2494 rte_eth_dev_callback_unregister(uint8_t port_id,
2495 enum rte_eth_event_type event,
2496 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2499 struct rte_eth_dev *dev;
2500 struct rte_eth_dev_callback *cb, *next;
2505 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2507 dev = &rte_eth_devices[port_id];
2508 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2511 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2513 next = TAILQ_NEXT(cb, next);
2515 if (cb->cb_fn != cb_fn || cb->event != event ||
2516 (cb->cb_arg != (void *)-1 &&
2517 cb->cb_arg != cb_arg))
2521 * if this callback is not executing right now,
2524 if (cb->active == 0) {
2525 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2532 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2537 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2538 enum rte_eth_event_type event)
2540 struct rte_eth_dev_callback *cb_lst;
2541 struct rte_eth_dev_callback dev_cb;
2543 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2544 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2545 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2549 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2550 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2552 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2555 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2559 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
2562 struct rte_eth_dev *dev;
2563 struct rte_intr_handle *intr_handle;
2567 if (!rte_eth_dev_is_valid_port(port_id)) {
2568 RTE_PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
2572 dev = &rte_eth_devices[port_id];
2573 intr_handle = &dev->pci_dev->intr_handle;
2574 if (!intr_handle->intr_vec) {
2575 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2579 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2580 vec = intr_handle->intr_vec[qid];
2581 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2582 if (rc && rc != -EEXIST) {
2583 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2584 " op %d epfd %d vec %u\n",
2585 port_id, qid, op, epfd, vec);
2592 const struct rte_memzone *
2593 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2594 uint16_t queue_id, size_t size, unsigned align,
2597 char z_name[RTE_MEMZONE_NAMESIZE];
2598 const struct rte_memzone *mz;
2600 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2601 dev->driver->pci_drv.name, ring_name,
2602 dev->data->port_id, queue_id);
2604 mz = rte_memzone_lookup(z_name);
2608 if (is_xen_dom0_supported())
2609 return rte_memzone_reserve_bounded(z_name, size, socket_id,
2610 0, align, RTE_PGSIZE_2M);
2612 return rte_memzone_reserve_aligned(z_name, size, socket_id,
2617 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
2618 int epfd, int op, void *data)
2621 struct rte_eth_dev *dev;
2622 struct rte_intr_handle *intr_handle;
2625 if (!rte_eth_dev_is_valid_port(port_id)) {
2626 RTE_PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
2630 dev = &rte_eth_devices[port_id];
2631 if (queue_id >= dev->data->nb_rx_queues) {
2632 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
2636 intr_handle = &dev->pci_dev->intr_handle;
2637 if (!intr_handle->intr_vec) {
2638 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2642 vec = intr_handle->intr_vec[queue_id];
2643 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2644 if (rc && rc != -EEXIST) {
2645 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2646 " op %d epfd %d vec %u\n",
2647 port_id, queue_id, op, epfd, vec);
2655 rte_eth_dev_rx_intr_enable(uint8_t port_id,
2658 struct rte_eth_dev *dev;
2660 if (!rte_eth_dev_is_valid_port(port_id)) {
2661 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2665 dev = &rte_eth_devices[port_id];
2667 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
2668 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
2672 rte_eth_dev_rx_intr_disable(uint8_t port_id,
2675 struct rte_eth_dev *dev;
2677 if (!rte_eth_dev_is_valid_port(port_id)) {
2678 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2682 dev = &rte_eth_devices[port_id];
2684 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
2685 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
2688 #ifdef RTE_NIC_BYPASS
2689 int rte_eth_dev_bypass_init(uint8_t port_id)
2691 struct rte_eth_dev *dev;
2693 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2695 dev = &rte_eth_devices[port_id];
2696 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2697 (*dev->dev_ops->bypass_init)(dev);
2702 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2704 struct rte_eth_dev *dev;
2706 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2708 dev = &rte_eth_devices[port_id];
2709 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2710 (*dev->dev_ops->bypass_state_show)(dev, state);
2715 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2717 struct rte_eth_dev *dev;
2719 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2721 dev = &rte_eth_devices[port_id];
2722 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2723 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2728 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2730 struct rte_eth_dev *dev;
2732 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2734 dev = &rte_eth_devices[port_id];
2735 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2736 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2741 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2743 struct rte_eth_dev *dev;
2745 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2747 dev = &rte_eth_devices[port_id];
2749 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2750 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2755 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2757 struct rte_eth_dev *dev;
2759 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2761 dev = &rte_eth_devices[port_id];
2763 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2764 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2769 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2771 struct rte_eth_dev *dev;
2773 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2775 dev = &rte_eth_devices[port_id];
2777 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2778 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2783 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2785 struct rte_eth_dev *dev;
2787 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2789 dev = &rte_eth_devices[port_id];
2791 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2792 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2797 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2799 struct rte_eth_dev *dev;
2801 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2803 dev = &rte_eth_devices[port_id];
2805 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2806 (*dev->dev_ops->bypass_wd_reset)(dev);
2812 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
2814 struct rte_eth_dev *dev;
2816 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2818 dev = &rte_eth_devices[port_id];
2819 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2820 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
2821 RTE_ETH_FILTER_NOP, NULL);
2825 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
2826 enum rte_filter_op filter_op, void *arg)
2828 struct rte_eth_dev *dev;
2830 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2832 dev = &rte_eth_devices[port_id];
2833 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2834 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
2838 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
2839 rte_rx_callback_fn fn, void *user_param)
2841 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2842 rte_errno = ENOTSUP;
2845 /* check input parameters */
2846 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2847 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2852 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2860 cb->param = user_param;
2862 /* Add the callbacks in fifo order. */
2863 struct rte_eth_rxtx_callback *tail =
2864 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2867 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2879 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
2880 rte_tx_callback_fn fn, void *user_param)
2882 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2883 rte_errno = ENOTSUP;
2886 /* check input parameters */
2887 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2888 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
2893 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2901 cb->param = user_param;
2903 /* Add the callbacks in fifo order. */
2904 struct rte_eth_rxtx_callback *tail =
2905 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
2908 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
2920 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
2921 struct rte_eth_rxtx_callback *user_cb)
2923 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2926 /* Check input parameters. */
2927 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
2928 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2932 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2933 struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
2934 struct rte_eth_rxtx_callback *prev_cb;
2936 /* Reset head pointer and remove user cb if first in the list. */
2937 if (cb == user_cb) {
2938 dev->post_rx_burst_cbs[queue_id] = user_cb->next;
2942 /* Remove the user cb from the callback list. */
2947 if (cb == user_cb) {
2948 prev_cb->next = user_cb->next;
2952 } while (cb != NULL);
2954 /* Callback wasn't found. */
2959 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
2960 struct rte_eth_rxtx_callback *user_cb)
2962 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2965 /* Check input parameters. */
2966 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
2967 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
2971 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2972 struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
2973 struct rte_eth_rxtx_callback *prev_cb;
2975 /* Reset head pointer and remove user cb if first in the list. */
2976 if (cb == user_cb) {
2977 dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
2981 /* Remove the user cb from the callback list. */
2986 if (cb == user_cb) {
2987 prev_cb->next = user_cb->next;
2991 } while (cb != NULL);
2993 /* Callback wasn't found. */
2998 rte_eth_rx_queue_info_get(uint8_t port_id, uint16_t queue_id,
2999 struct rte_eth_rxq_info *qinfo)
3001 struct rte_eth_dev *dev;
3003 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3008 dev = &rte_eth_devices[port_id];
3009 if (queue_id >= dev->data->nb_rx_queues) {
3010 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3014 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3016 memset(qinfo, 0, sizeof(*qinfo));
3017 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3022 rte_eth_tx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3023 struct rte_eth_txq_info *qinfo)
3025 struct rte_eth_dev *dev;
3027 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3032 dev = &rte_eth_devices[port_id];
3033 if (queue_id >= dev->data->nb_tx_queues) {
3034 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3038 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3040 memset(qinfo, 0, sizeof(*qinfo));
3041 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3046 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3047 struct ether_addr *mc_addr_set,
3048 uint32_t nb_mc_addr)
3050 struct rte_eth_dev *dev;
3052 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3054 dev = &rte_eth_devices[port_id];
3055 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3056 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3060 rte_eth_timesync_enable(uint8_t port_id)
3062 struct rte_eth_dev *dev;
3064 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3065 dev = &rte_eth_devices[port_id];
3067 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3068 return (*dev->dev_ops->timesync_enable)(dev);
3072 rte_eth_timesync_disable(uint8_t port_id)
3074 struct rte_eth_dev *dev;
3076 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3077 dev = &rte_eth_devices[port_id];
3079 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3080 return (*dev->dev_ops->timesync_disable)(dev);
3084 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3087 struct rte_eth_dev *dev;
3089 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3090 dev = &rte_eth_devices[port_id];
3092 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3093 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3097 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3099 struct rte_eth_dev *dev;
3101 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3102 dev = &rte_eth_devices[port_id];
3104 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3105 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3109 rte_eth_timesync_adjust_time(uint8_t port_id, int64_t delta)
3111 struct rte_eth_dev *dev;
3113 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3114 dev = &rte_eth_devices[port_id];
3116 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3117 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3121 rte_eth_timesync_read_time(uint8_t port_id, struct timespec *timestamp)
3123 struct rte_eth_dev *dev;
3125 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3126 dev = &rte_eth_devices[port_id];
3128 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3129 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3133 rte_eth_timesync_write_time(uint8_t port_id, const struct timespec *timestamp)
3135 struct rte_eth_dev *dev;
3137 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3138 dev = &rte_eth_devices[port_id];
3140 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3141 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3145 rte_eth_dev_get_reg_length(uint8_t port_id)
3147 struct rte_eth_dev *dev;
3149 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3151 dev = &rte_eth_devices[port_id];
3152 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg_length, -ENOTSUP);
3153 return (*dev->dev_ops->get_reg_length)(dev);
3157 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3159 struct rte_eth_dev *dev;
3161 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3163 dev = &rte_eth_devices[port_id];
3164 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3165 return (*dev->dev_ops->get_reg)(dev, info);
3169 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3171 struct rte_eth_dev *dev;
3173 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3175 dev = &rte_eth_devices[port_id];
3176 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3177 return (*dev->dev_ops->get_eeprom_length)(dev);
3181 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3183 struct rte_eth_dev *dev;
3185 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3187 dev = &rte_eth_devices[port_id];
3188 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3189 return (*dev->dev_ops->get_eeprom)(dev, info);
3193 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3195 struct rte_eth_dev *dev;
3197 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3199 dev = &rte_eth_devices[port_id];
3200 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3201 return (*dev->dev_ops->set_eeprom)(dev, info);
3205 rte_eth_dev_get_dcb_info(uint8_t port_id,
3206 struct rte_eth_dcb_info *dcb_info)
3208 struct rte_eth_dev *dev;
3210 if (!rte_eth_dev_is_valid_port(port_id)) {
3211 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3215 dev = &rte_eth_devices[port_id];
3216 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3218 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3219 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3223 rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_dev)
3225 if ((eth_dev == NULL) || (pci_dev == NULL)) {
3226 RTE_PMD_DEBUG_TRACE("NULL pointer eth_dev=%p pci_dev=%p\n",
3231 eth_dev->data->dev_flags = 0;
3232 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
3233 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
3234 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_DETACHABLE)
3235 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
3237 eth_dev->data->kdrv = pci_dev->kdrv;
3238 eth_dev->data->numa_node = pci_dev->numa_node;
3239 eth_dev->data->drv_name = pci_dev->driver->name;