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 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
73 #define PMD_DEBUG_TRACE(fmt, args...) do { \
74 RTE_LOG(ERR, PMD, "%s: " fmt, __func__, ## args); \
77 #define PMD_DEBUG_TRACE(fmt, args...)
80 /* Macros for checking for restricting functions to primary instance only */
81 #define PROC_PRIMARY_OR_ERR_RET(retval) do { \
82 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
83 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
88 #define PROC_PRIMARY_OR_RET() do { \
89 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
90 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
95 /* Macros to check for invalid function pointers in dev_ops structure */
96 #define FUNC_PTR_OR_ERR_RET(func, retval) do { \
97 if ((func) == NULL) { \
98 PMD_DEBUG_TRACE("Function not supported\n"); \
103 #define FUNC_PTR_OR_RET(func) do { \
104 if ((func) == NULL) { \
105 PMD_DEBUG_TRACE("Function not supported\n"); \
110 /* Macros to check for valid port */
111 #define VALID_PORTID_OR_ERR_RET(port_id, retval) do { \
112 if (!rte_eth_dev_is_valid_port(port_id)) { \
113 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); \
118 #define VALID_PORTID_OR_RET(port_id) do { \
119 if (!rte_eth_dev_is_valid_port(port_id)) { \
120 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); \
125 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
126 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
127 static struct rte_eth_dev_data *rte_eth_dev_data;
128 static uint8_t nb_ports;
130 /* spinlock for eth device callbacks */
131 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
133 /* store statistics names and its offset in stats structure */
134 struct rte_eth_xstats_name_off {
135 char name[RTE_ETH_XSTATS_NAME_SIZE];
139 static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
140 {"rx_good_packets", offsetof(struct rte_eth_stats, ipackets)},
141 {"tx_good_packets", offsetof(struct rte_eth_stats, opackets)},
142 {"rx_good_bytes", offsetof(struct rte_eth_stats, ibytes)},
143 {"tx_good_bytes", offsetof(struct rte_eth_stats, obytes)},
144 {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
145 {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
146 {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats,
150 #define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
152 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
153 {"packets", offsetof(struct rte_eth_stats, q_ipackets)},
154 {"bytes", offsetof(struct rte_eth_stats, q_ibytes)},
155 {"errors", offsetof(struct rte_eth_stats, q_errors)},
158 #define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) / \
159 sizeof(rte_rxq_stats_strings[0]))
161 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
162 {"packets", offsetof(struct rte_eth_stats, q_opackets)},
163 {"bytes", offsetof(struct rte_eth_stats, q_obytes)},
165 #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) / \
166 sizeof(rte_txq_stats_strings[0]))
170 * The user application callback description.
172 * It contains callback address to be registered by user application,
173 * the pointer to the parameters for callback, and the event type.
175 struct rte_eth_dev_callback {
176 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
177 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
178 void *cb_arg; /**< Parameter for callback */
179 enum rte_eth_event_type event; /**< Interrupt event type */
180 uint32_t active; /**< Callback is executing */
194 rte_eth_dev_data_alloc(void)
196 const unsigned flags = 0;
197 const struct rte_memzone *mz;
199 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
200 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
201 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
202 rte_socket_id(), flags);
204 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
206 rte_panic("Cannot allocate memzone for ethernet port data\n");
208 rte_eth_dev_data = mz->addr;
209 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
210 memset(rte_eth_dev_data, 0,
211 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
215 rte_eth_dev_allocated(const char *name)
219 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
220 if ((rte_eth_devices[i].attached == DEV_ATTACHED) &&
221 strcmp(rte_eth_devices[i].data->name, name) == 0)
222 return &rte_eth_devices[i];
228 rte_eth_dev_find_free_port(void)
232 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
233 if (rte_eth_devices[i].attached == DEV_DETACHED)
236 return RTE_MAX_ETHPORTS;
240 rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
243 struct rte_eth_dev *eth_dev;
245 port_id = rte_eth_dev_find_free_port();
246 if (port_id == RTE_MAX_ETHPORTS) {
247 PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
251 if (rte_eth_dev_data == NULL)
252 rte_eth_dev_data_alloc();
254 if (rte_eth_dev_allocated(name) != NULL) {
255 PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n",
260 eth_dev = &rte_eth_devices[port_id];
261 eth_dev->data = &rte_eth_dev_data[port_id];
262 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
263 eth_dev->data->port_id = port_id;
264 eth_dev->attached = DEV_ATTACHED;
265 eth_dev->dev_type = type;
271 rte_eth_dev_create_unique_device_name(char *name, size_t size,
272 struct rte_pci_device *pci_dev)
276 if ((name == NULL) || (pci_dev == NULL))
279 ret = snprintf(name, size, "%d:%d.%d",
280 pci_dev->addr.bus, pci_dev->addr.devid,
281 pci_dev->addr.function);
288 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
293 eth_dev->attached = DEV_DETACHED;
299 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
300 struct rte_pci_device *pci_dev)
302 struct eth_driver *eth_drv;
303 struct rte_eth_dev *eth_dev;
304 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
308 eth_drv = (struct eth_driver *)pci_drv;
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_allocate(ethdev_name, RTE_ETH_DEV_PCI);
318 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
319 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
320 eth_drv->dev_private_size,
321 RTE_CACHE_LINE_SIZE);
322 if (eth_dev->data->dev_private == NULL)
323 rte_panic("Cannot allocate memzone for private port data\n");
325 eth_dev->pci_dev = pci_dev;
326 eth_dev->driver = eth_drv;
327 eth_dev->data->rx_mbuf_alloc_failed = 0;
329 /* init user callbacks */
330 TAILQ_INIT(&(eth_dev->link_intr_cbs));
333 * Set the default MTU.
335 eth_dev->data->mtu = ETHER_MTU;
337 /* Invoke PMD device initialization function */
338 diag = (*eth_drv->eth_dev_init)(eth_dev);
342 PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x) failed\n",
344 (unsigned) pci_dev->id.vendor_id,
345 (unsigned) pci_dev->id.device_id);
346 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
347 rte_free(eth_dev->data->dev_private);
348 rte_eth_dev_release_port(eth_dev);
353 rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
355 const struct eth_driver *eth_drv;
356 struct rte_eth_dev *eth_dev;
357 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
363 /* Create unique Ethernet device name using PCI address */
364 rte_eth_dev_create_unique_device_name(ethdev_name,
365 sizeof(ethdev_name), pci_dev);
367 eth_dev = rte_eth_dev_allocated(ethdev_name);
371 eth_drv = (const struct eth_driver *)pci_dev->driver;
373 /* Invoke PMD device uninit function */
374 if (*eth_drv->eth_dev_uninit) {
375 ret = (*eth_drv->eth_dev_uninit)(eth_dev);
380 /* free ether device */
381 rte_eth_dev_release_port(eth_dev);
383 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
384 rte_free(eth_dev->data->dev_private);
386 eth_dev->pci_dev = NULL;
387 eth_dev->driver = NULL;
388 eth_dev->data = NULL;
394 * Register an Ethernet [Poll Mode] driver.
396 * Function invoked by the initialization function of an Ethernet driver
397 * to simultaneously register itself as a PCI driver and as an Ethernet
399 * Invokes the rte_eal_pci_register() function to register the *pci_drv*
400 * structure embedded in the *eth_drv* structure, after having stored the
401 * address of the rte_eth_dev_init() function in the *devinit* field of
402 * the *pci_drv* structure.
403 * During the PCI probing phase, the rte_eth_dev_init() function is
404 * invoked for each PCI [Ethernet device] matching the embedded PCI
405 * identifiers provided by the driver.
408 rte_eth_driver_register(struct eth_driver *eth_drv)
410 eth_drv->pci_drv.devinit = rte_eth_dev_init;
411 eth_drv->pci_drv.devuninit = rte_eth_dev_uninit;
412 rte_eal_pci_register(ð_drv->pci_drv);
416 rte_eth_dev_is_valid_port(uint8_t port_id)
418 if (port_id >= RTE_MAX_ETHPORTS ||
419 rte_eth_devices[port_id].attached != DEV_ATTACHED)
426 rte_eth_dev_socket_id(uint8_t port_id)
428 if (!rte_eth_dev_is_valid_port(port_id))
430 return rte_eth_devices[port_id].data->numa_node;
434 rte_eth_dev_count(void)
439 static enum rte_eth_dev_type
440 rte_eth_dev_get_device_type(uint8_t port_id)
442 if (!rte_eth_dev_is_valid_port(port_id))
443 return RTE_ETH_DEV_UNKNOWN;
444 return rte_eth_devices[port_id].dev_type;
448 rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr)
450 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
453 PMD_DEBUG_TRACE("Null pointer is specified\n");
457 *addr = rte_eth_devices[port_id].pci_dev->addr;
462 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
466 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
469 PMD_DEBUG_TRACE("Null pointer is specified\n");
473 /* shouldn't check 'rte_eth_devices[i].data',
474 * because it might be overwritten by VDEV PMD */
475 tmp = rte_eth_dev_data[port_id].name;
481 rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
486 PMD_DEBUG_TRACE("Null pointer is specified\n");
490 *port_id = RTE_MAX_ETHPORTS;
492 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
495 rte_eth_dev_data[i].name, strlen(name))) {
506 rte_eth_dev_get_port_by_addr(const struct rte_pci_addr *addr, uint8_t *port_id)
509 struct rte_pci_device *pci_dev = NULL;
512 PMD_DEBUG_TRACE("Null pointer is specified\n");
516 *port_id = RTE_MAX_ETHPORTS;
518 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
520 pci_dev = rte_eth_devices[i].pci_dev;
523 !rte_eal_compare_pci_addr(&pci_dev->addr, addr)) {
534 rte_eth_dev_is_detachable(uint8_t port_id)
538 if (!rte_eth_dev_is_valid_port(port_id)) {
539 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
543 switch (rte_eth_devices[port_id].data->kdrv) {
544 case RTE_KDRV_IGB_UIO:
545 case RTE_KDRV_UIO_GENERIC:
546 case RTE_KDRV_NIC_UIO:
553 dev_flags = rte_eth_devices[port_id].data->dev_flags;
554 return !(dev_flags & RTE_ETH_DEV_DETACHABLE);
557 /* attach the new physical device, then store port_id of the device */
559 rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
561 if ((addr == NULL) || (port_id == NULL))
564 /* re-construct pci_device_list */
565 if (rte_eal_pci_scan())
567 /* Invoke probe func of the driver can handle the new device. */
568 if (rte_eal_pci_probe_one(addr))
571 if (rte_eth_dev_get_port_by_addr(addr, port_id))
576 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
580 /* detach the new physical device, then store pci_addr of the device */
582 rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
584 struct rte_pci_addr freed_addr;
585 struct rte_pci_addr vp;
590 /* check whether the driver supports detach feature, or not */
591 if (rte_eth_dev_is_detachable(port_id))
594 /* get pci address by port id */
595 if (rte_eth_dev_get_addr_by_port(port_id, &freed_addr))
598 /* Zeroed pci addr means the port comes from virtual device */
599 vp.domain = vp.bus = vp.devid = vp.function = 0;
600 if (rte_eal_compare_pci_addr(&vp, &freed_addr) == 0)
603 /* invoke devuninit func of the pci driver,
604 * also remove the device from pci_device_list */
605 if (rte_eal_pci_detach(&freed_addr))
611 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
615 /* attach the new virtual device, then store port_id of the device */
617 rte_eth_dev_attach_vdev(const char *vdevargs, uint8_t *port_id)
619 char *name = NULL, *args = NULL;
622 if ((vdevargs == NULL) || (port_id == NULL))
625 /* parse vdevargs, then retrieve device name and args */
626 if (rte_eal_parse_devargs_str(vdevargs, &name, &args))
629 /* walk around dev_driver_list to find the driver of the device,
630 * then invoke probe function of the driver.
631 * rte_eal_vdev_init() updates port_id allocated after
634 if (rte_eal_vdev_init(name, args))
637 if (rte_eth_dev_get_port_by_name(name, port_id))
648 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
652 /* detach the new virtual device, then store the name of the device */
654 rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
656 char name[RTE_ETH_NAME_MAX_LEN];
658 if (vdevname == NULL)
661 /* check whether the driver supports detach feature, or not */
662 if (rte_eth_dev_is_detachable(port_id))
665 /* get device name by port id */
666 if (rte_eth_dev_get_name_by_port(port_id, name))
668 /* walk around dev_driver_list to find the driver of the device,
669 * then invoke uninit function of the driver */
670 if (rte_eal_vdev_uninit(name))
673 strncpy(vdevname, name, sizeof(name));
676 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
680 /* attach the new device, then store port_id of the device */
682 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
684 struct rte_pci_addr addr;
686 if ((devargs == NULL) || (port_id == NULL))
689 if (eal_parse_pci_DomBDF(devargs, &addr) == 0)
690 return rte_eth_dev_attach_pdev(&addr, port_id);
692 return rte_eth_dev_attach_vdev(devargs, port_id);
695 /* detach the device, then store the name of the device */
697 rte_eth_dev_detach(uint8_t port_id, char *name)
699 struct rte_pci_addr addr;
705 if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {
706 ret = rte_eth_dev_get_addr_by_port(port_id, &addr);
710 ret = rte_eth_dev_detach_pdev(port_id, &addr);
712 snprintf(name, RTE_ETH_NAME_MAX_LEN,
714 addr.domain, addr.bus,
715 addr.devid, addr.function);
719 return rte_eth_dev_detach_vdev(port_id, name);
723 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
725 uint16_t old_nb_queues = dev->data->nb_rx_queues;
729 if (dev->data->rx_queues == NULL) { /* first time configuration */
730 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
731 sizeof(dev->data->rx_queues[0]) * nb_queues,
732 RTE_CACHE_LINE_SIZE);
733 if (dev->data->rx_queues == NULL) {
734 dev->data->nb_rx_queues = 0;
737 } else { /* re-configure */
738 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
740 rxq = dev->data->rx_queues;
742 for (i = nb_queues; i < old_nb_queues; i++)
743 (*dev->dev_ops->rx_queue_release)(rxq[i]);
744 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
745 RTE_CACHE_LINE_SIZE);
748 if (nb_queues > old_nb_queues) {
749 uint16_t new_qs = nb_queues - old_nb_queues;
751 memset(rxq + old_nb_queues, 0,
752 sizeof(rxq[0]) * new_qs);
755 dev->data->rx_queues = rxq;
758 dev->data->nb_rx_queues = nb_queues;
763 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
765 struct rte_eth_dev *dev;
767 /* This function is only safe when called from the primary process
768 * in a multi-process setup*/
769 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
771 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
773 dev = &rte_eth_devices[port_id];
774 if (rx_queue_id >= dev->data->nb_rx_queues) {
775 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
779 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
781 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
782 PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
783 " already started\n",
784 rx_queue_id, port_id);
788 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
793 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
795 struct rte_eth_dev *dev;
797 /* This function is only safe when called from the primary process
798 * in a multi-process setup*/
799 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
801 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
803 dev = &rte_eth_devices[port_id];
804 if (rx_queue_id >= dev->data->nb_rx_queues) {
805 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
809 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
811 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
812 PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
813 " already stopped\n",
814 rx_queue_id, port_id);
818 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
823 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
825 struct rte_eth_dev *dev;
827 /* This function is only safe when called from the primary process
828 * in a multi-process setup*/
829 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
831 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
833 dev = &rte_eth_devices[port_id];
834 if (tx_queue_id >= dev->data->nb_tx_queues) {
835 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
839 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
841 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
842 PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
843 " already started\n",
844 tx_queue_id, port_id);
848 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
853 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
855 struct rte_eth_dev *dev;
857 /* This function is only safe when called from the primary process
858 * in a multi-process setup*/
859 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
861 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
863 dev = &rte_eth_devices[port_id];
864 if (tx_queue_id >= dev->data->nb_tx_queues) {
865 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
869 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
871 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
872 PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
873 " already stopped\n",
874 tx_queue_id, port_id);
878 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
883 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
885 uint16_t old_nb_queues = dev->data->nb_tx_queues;
889 if (dev->data->tx_queues == NULL) { /* first time configuration */
890 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
891 sizeof(dev->data->tx_queues[0]) * nb_queues,
892 RTE_CACHE_LINE_SIZE);
893 if (dev->data->tx_queues == NULL) {
894 dev->data->nb_tx_queues = 0;
897 } else { /* re-configure */
898 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
900 txq = dev->data->tx_queues;
902 for (i = nb_queues; i < old_nb_queues; i++)
903 (*dev->dev_ops->tx_queue_release)(txq[i]);
904 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
905 RTE_CACHE_LINE_SIZE);
908 if (nb_queues > old_nb_queues) {
909 uint16_t new_qs = nb_queues - old_nb_queues;
911 memset(txq + old_nb_queues, 0,
912 sizeof(txq[0]) * new_qs);
915 dev->data->tx_queues = txq;
918 dev->data->nb_tx_queues = nb_queues;
923 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
924 const struct rte_eth_conf *dev_conf)
926 struct rte_eth_dev *dev;
927 struct rte_eth_dev_info dev_info;
930 /* This function is only safe when called from the primary process
931 * in a multi-process setup*/
932 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
934 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
936 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
938 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
939 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
943 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
945 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
946 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
950 dev = &rte_eth_devices[port_id];
952 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
953 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
955 if (dev->data->dev_started) {
957 "port %d must be stopped to allow configuration\n", port_id);
962 * Check that the numbers of RX and TX queues are not greater
963 * than the maximum number of RX and TX queues supported by the
966 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
967 if (nb_rx_q > dev_info.max_rx_queues) {
968 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
969 port_id, nb_rx_q, dev_info.max_rx_queues);
973 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
977 if (nb_tx_q > dev_info.max_tx_queues) {
978 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
979 port_id, nb_tx_q, dev_info.max_tx_queues);
983 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
987 /* Copy the dev_conf parameter into the dev structure */
988 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
991 * If link state interrupt is enabled, check that the
992 * device supports it.
994 if ((dev_conf->intr_conf.lsc == 1) &&
995 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
996 PMD_DEBUG_TRACE("driver %s does not support lsc\n",
997 dev->data->drv_name);
1002 * If jumbo frames are enabled, check that the maximum RX packet
1003 * length is supported by the configured device.
1005 if (dev_conf->rxmode.jumbo_frame == 1) {
1006 if (dev_conf->rxmode.max_rx_pkt_len >
1007 dev_info.max_rx_pktlen) {
1008 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
1009 " > max valid value %u\n",
1011 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
1012 (unsigned)dev_info.max_rx_pktlen);
1014 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
1015 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
1016 " < min valid value %u\n",
1018 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
1019 (unsigned)ETHER_MIN_LEN);
1023 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
1024 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
1025 /* Use default value */
1026 dev->data->dev_conf.rxmode.max_rx_pkt_len =
1031 * Setup new number of RX/TX queues and reconfigure device.
1033 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
1035 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
1040 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
1042 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
1044 rte_eth_dev_rx_queue_config(dev, 0);
1048 diag = (*dev->dev_ops->dev_configure)(dev);
1050 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
1052 rte_eth_dev_rx_queue_config(dev, 0);
1053 rte_eth_dev_tx_queue_config(dev, 0);
1061 rte_eth_dev_config_restore(uint8_t port_id)
1063 struct rte_eth_dev *dev;
1064 struct rte_eth_dev_info dev_info;
1065 struct ether_addr addr;
1069 dev = &rte_eth_devices[port_id];
1071 rte_eth_dev_info_get(port_id, &dev_info);
1073 if (RTE_ETH_DEV_SRIOV(dev).active)
1074 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
1076 /* replay MAC address configuration */
1077 for (i = 0; i < dev_info.max_mac_addrs; i++) {
1078 addr = dev->data->mac_addrs[i];
1080 /* skip zero address */
1081 if (is_zero_ether_addr(&addr))
1084 /* add address to the hardware */
1085 if (*dev->dev_ops->mac_addr_add &&
1086 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
1087 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
1089 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
1091 /* exit the loop but not return an error */
1096 /* replay promiscuous configuration */
1097 if (rte_eth_promiscuous_get(port_id) == 1)
1098 rte_eth_promiscuous_enable(port_id);
1099 else if (rte_eth_promiscuous_get(port_id) == 0)
1100 rte_eth_promiscuous_disable(port_id);
1102 /* replay all multicast configuration */
1103 if (rte_eth_allmulticast_get(port_id) == 1)
1104 rte_eth_allmulticast_enable(port_id);
1105 else if (rte_eth_allmulticast_get(port_id) == 0)
1106 rte_eth_allmulticast_disable(port_id);
1110 rte_eth_dev_start(uint8_t port_id)
1112 struct rte_eth_dev *dev;
1115 /* This function is only safe when called from the primary process
1116 * in a multi-process setup*/
1117 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1119 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1121 dev = &rte_eth_devices[port_id];
1123 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1125 if (dev->data->dev_started != 0) {
1126 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1127 " already started\n",
1132 diag = (*dev->dev_ops->dev_start)(dev);
1134 dev->data->dev_started = 1;
1138 rte_eth_dev_config_restore(port_id);
1140 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1141 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1142 (*dev->dev_ops->link_update)(dev, 0);
1148 rte_eth_dev_stop(uint8_t port_id)
1150 struct rte_eth_dev *dev;
1152 /* This function is only safe when called from the primary process
1153 * in a multi-process setup*/
1154 PROC_PRIMARY_OR_RET();
1156 VALID_PORTID_OR_RET(port_id);
1157 dev = &rte_eth_devices[port_id];
1159 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1161 if (dev->data->dev_started == 0) {
1162 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1163 " already stopped\n",
1168 dev->data->dev_started = 0;
1169 (*dev->dev_ops->dev_stop)(dev);
1173 rte_eth_dev_set_link_up(uint8_t port_id)
1175 struct rte_eth_dev *dev;
1177 /* This function is only safe when called from the primary process
1178 * in a multi-process setup*/
1179 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1181 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1183 dev = &rte_eth_devices[port_id];
1185 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1186 return (*dev->dev_ops->dev_set_link_up)(dev);
1190 rte_eth_dev_set_link_down(uint8_t port_id)
1192 struct rte_eth_dev *dev;
1194 /* This function is only safe when called from the primary process
1195 * in a multi-process setup*/
1196 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1198 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1200 dev = &rte_eth_devices[port_id];
1202 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1203 return (*dev->dev_ops->dev_set_link_down)(dev);
1207 rte_eth_dev_close(uint8_t port_id)
1209 struct rte_eth_dev *dev;
1211 /* This function is only safe when called from the primary process
1212 * in a multi-process setup*/
1213 PROC_PRIMARY_OR_RET();
1215 VALID_PORTID_OR_RET(port_id);
1216 dev = &rte_eth_devices[port_id];
1218 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1219 dev->data->dev_started = 0;
1220 (*dev->dev_ops->dev_close)(dev);
1222 rte_free(dev->data->rx_queues);
1223 dev->data->rx_queues = NULL;
1224 rte_free(dev->data->tx_queues);
1225 dev->data->tx_queues = NULL;
1229 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1230 uint16_t nb_rx_desc, unsigned int socket_id,
1231 const struct rte_eth_rxconf *rx_conf,
1232 struct rte_mempool *mp)
1235 uint32_t mbp_buf_size;
1236 struct rte_eth_dev *dev;
1237 struct rte_eth_dev_info dev_info;
1239 /* This function is only safe when called from the primary process
1240 * in a multi-process setup*/
1241 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1243 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1245 dev = &rte_eth_devices[port_id];
1246 if (rx_queue_id >= dev->data->nb_rx_queues) {
1247 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1251 if (dev->data->dev_started) {
1253 "port %d must be stopped to allow configuration\n", port_id);
1257 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1258 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1261 * Check the size of the mbuf data buffer.
1262 * This value must be provided in the private data of the memory pool.
1263 * First check that the memory pool has a valid private data.
1265 rte_eth_dev_info_get(port_id, &dev_info);
1266 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1267 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1268 mp->name, (int) mp->private_data_size,
1269 (int) sizeof(struct rte_pktmbuf_pool_private));
1272 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1274 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1275 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1276 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1280 (int)(RTE_PKTMBUF_HEADROOM +
1281 dev_info.min_rx_bufsize),
1282 (int)RTE_PKTMBUF_HEADROOM,
1283 (int)dev_info.min_rx_bufsize);
1287 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1288 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1289 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1291 PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1292 "should be: <= %hu, = %hu, and a product of %hu\n",
1294 dev_info.rx_desc_lim.nb_max,
1295 dev_info.rx_desc_lim.nb_min,
1296 dev_info.rx_desc_lim.nb_align);
1300 if (rx_conf == NULL)
1301 rx_conf = &dev_info.default_rxconf;
1303 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1304 socket_id, rx_conf, mp);
1306 if (!dev->data->min_rx_buf_size ||
1307 dev->data->min_rx_buf_size > mbp_buf_size)
1308 dev->data->min_rx_buf_size = mbp_buf_size;
1315 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1316 uint16_t nb_tx_desc, unsigned int socket_id,
1317 const struct rte_eth_txconf *tx_conf)
1319 struct rte_eth_dev *dev;
1320 struct rte_eth_dev_info dev_info;
1322 /* This function is only safe when called from the primary process
1323 * in a multi-process setup*/
1324 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1326 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1328 dev = &rte_eth_devices[port_id];
1329 if (tx_queue_id >= dev->data->nb_tx_queues) {
1330 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1334 if (dev->data->dev_started) {
1336 "port %d must be stopped to allow configuration\n", port_id);
1340 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1341 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1343 rte_eth_dev_info_get(port_id, &dev_info);
1345 if (tx_conf == NULL)
1346 tx_conf = &dev_info.default_txconf;
1348 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1349 socket_id, tx_conf);
1353 rte_eth_promiscuous_enable(uint8_t port_id)
1355 struct rte_eth_dev *dev;
1357 VALID_PORTID_OR_RET(port_id);
1358 dev = &rte_eth_devices[port_id];
1360 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1361 (*dev->dev_ops->promiscuous_enable)(dev);
1362 dev->data->promiscuous = 1;
1366 rte_eth_promiscuous_disable(uint8_t port_id)
1368 struct rte_eth_dev *dev;
1370 VALID_PORTID_OR_RET(port_id);
1371 dev = &rte_eth_devices[port_id];
1373 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1374 dev->data->promiscuous = 0;
1375 (*dev->dev_ops->promiscuous_disable)(dev);
1379 rte_eth_promiscuous_get(uint8_t port_id)
1381 struct rte_eth_dev *dev;
1383 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1385 dev = &rte_eth_devices[port_id];
1386 return dev->data->promiscuous;
1390 rte_eth_allmulticast_enable(uint8_t port_id)
1392 struct rte_eth_dev *dev;
1394 VALID_PORTID_OR_RET(port_id);
1395 dev = &rte_eth_devices[port_id];
1397 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1398 (*dev->dev_ops->allmulticast_enable)(dev);
1399 dev->data->all_multicast = 1;
1403 rte_eth_allmulticast_disable(uint8_t port_id)
1405 struct rte_eth_dev *dev;
1407 VALID_PORTID_OR_RET(port_id);
1408 dev = &rte_eth_devices[port_id];
1410 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1411 dev->data->all_multicast = 0;
1412 (*dev->dev_ops->allmulticast_disable)(dev);
1416 rte_eth_allmulticast_get(uint8_t port_id)
1418 struct rte_eth_dev *dev;
1420 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1422 dev = &rte_eth_devices[port_id];
1423 return dev->data->all_multicast;
1427 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1428 struct rte_eth_link *link)
1430 struct rte_eth_link *dst = link;
1431 struct rte_eth_link *src = &(dev->data->dev_link);
1433 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1434 *(uint64_t *)src) == 0)
1441 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1443 struct rte_eth_dev *dev;
1445 VALID_PORTID_OR_RET(port_id);
1446 dev = &rte_eth_devices[port_id];
1448 if (dev->data->dev_conf.intr_conf.lsc != 0)
1449 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1451 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1452 (*dev->dev_ops->link_update)(dev, 1);
1453 *eth_link = dev->data->dev_link;
1458 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1460 struct rte_eth_dev *dev;
1462 VALID_PORTID_OR_RET(port_id);
1463 dev = &rte_eth_devices[port_id];
1465 if (dev->data->dev_conf.intr_conf.lsc != 0)
1466 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1468 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1469 (*dev->dev_ops->link_update)(dev, 0);
1470 *eth_link = dev->data->dev_link;
1475 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1477 struct rte_eth_dev *dev;
1479 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1481 dev = &rte_eth_devices[port_id];
1482 memset(stats, 0, sizeof(*stats));
1484 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1485 (*dev->dev_ops->stats_get)(dev, stats);
1486 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1491 rte_eth_stats_reset(uint8_t port_id)
1493 struct rte_eth_dev *dev;
1495 VALID_PORTID_OR_RET(port_id);
1496 dev = &rte_eth_devices[port_id];
1498 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1499 (*dev->dev_ops->stats_reset)(dev);
1502 /* retrieve ethdev extended statistics */
1504 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1507 struct rte_eth_stats eth_stats;
1508 struct rte_eth_dev *dev;
1509 unsigned count = 0, i, q;
1511 uint64_t val, *stats_ptr;
1513 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1515 dev = &rte_eth_devices[port_id];
1517 /* Return generic statistics */
1518 count = RTE_NB_STATS + (dev->data->nb_rx_queues * RTE_NB_RXQ_STATS) +
1519 (dev->data->nb_tx_queues * RTE_NB_TXQ_STATS);
1521 /* implemented by the driver */
1522 if (dev->dev_ops->xstats_get != NULL) {
1523 /* Retrieve the xstats from the driver at the end of the
1526 xcount = (*dev->dev_ops->xstats_get)(dev, &xstats[count],
1527 (n > count) ? n - count : 0);
1533 if (n < count + xcount)
1534 return count + xcount;
1536 /* now fill the xstats structure */
1538 rte_eth_stats_get(port_id, ð_stats);
1541 for (i = 0; i < RTE_NB_STATS; i++) {
1542 stats_ptr = RTE_PTR_ADD(ð_stats,
1543 rte_stats_strings[i].offset);
1545 snprintf(xstats[count].name, sizeof(xstats[count].name),
1546 "%s", rte_stats_strings[i].name);
1547 xstats[count++].value = val;
1551 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1552 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1553 stats_ptr = RTE_PTR_ADD(ð_stats,
1554 rte_rxq_stats_strings[i].offset +
1555 q * sizeof(uint64_t));
1557 snprintf(xstats[count].name, sizeof(xstats[count].name),
1559 rte_rxq_stats_strings[i].name);
1560 xstats[count++].value = val;
1565 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1566 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1567 stats_ptr = RTE_PTR_ADD(ð_stats,
1568 rte_txq_stats_strings[i].offset +
1569 q * sizeof(uint64_t));
1571 snprintf(xstats[count].name, sizeof(xstats[count].name),
1573 rte_txq_stats_strings[i].name);
1574 xstats[count++].value = val;
1578 return count + xcount;
1581 /* reset ethdev extended statistics */
1583 rte_eth_xstats_reset(uint8_t port_id)
1585 struct rte_eth_dev *dev;
1587 VALID_PORTID_OR_RET(port_id);
1588 dev = &rte_eth_devices[port_id];
1590 /* implemented by the driver */
1591 if (dev->dev_ops->xstats_reset != NULL) {
1592 (*dev->dev_ops->xstats_reset)(dev);
1596 /* fallback to default */
1597 rte_eth_stats_reset(port_id);
1601 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1604 struct rte_eth_dev *dev;
1606 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1608 dev = &rte_eth_devices[port_id];
1610 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1611 return (*dev->dev_ops->queue_stats_mapping_set)
1612 (dev, queue_id, stat_idx, is_rx);
1617 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1620 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1626 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1629 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1635 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1637 struct rte_eth_dev *dev;
1638 const struct rte_eth_desc_lim lim = {
1639 .nb_max = UINT16_MAX,
1644 VALID_PORTID_OR_RET(port_id);
1645 dev = &rte_eth_devices[port_id];
1647 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1648 dev_info->rx_desc_lim = lim;
1649 dev_info->tx_desc_lim = lim;
1651 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1652 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1653 dev_info->pci_dev = dev->pci_dev;
1654 dev_info->driver_name = dev->data->drv_name;
1658 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1660 struct rte_eth_dev *dev;
1662 VALID_PORTID_OR_RET(port_id);
1663 dev = &rte_eth_devices[port_id];
1664 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1669 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1671 struct rte_eth_dev *dev;
1673 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1675 dev = &rte_eth_devices[port_id];
1676 *mtu = dev->data->mtu;
1681 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1684 struct rte_eth_dev *dev;
1686 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1687 dev = &rte_eth_devices[port_id];
1688 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1690 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1692 dev->data->mtu = mtu;
1698 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1700 struct rte_eth_dev *dev;
1702 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1703 dev = &rte_eth_devices[port_id];
1704 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1705 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1709 if (vlan_id > 4095) {
1710 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1711 port_id, (unsigned) vlan_id);
1714 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1716 return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1720 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1722 struct rte_eth_dev *dev;
1724 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1725 dev = &rte_eth_devices[port_id];
1726 if (rx_queue_id >= dev->data->nb_rx_queues) {
1727 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1731 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1732 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1738 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1740 struct rte_eth_dev *dev;
1742 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1743 dev = &rte_eth_devices[port_id];
1744 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1745 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1751 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1753 struct rte_eth_dev *dev;
1758 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1759 dev = &rte_eth_devices[port_id];
1761 /*check which option changed by application*/
1762 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1763 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1765 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1766 mask |= ETH_VLAN_STRIP_MASK;
1769 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1770 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1772 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1773 mask |= ETH_VLAN_FILTER_MASK;
1776 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1777 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1779 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1780 mask |= ETH_VLAN_EXTEND_MASK;
1787 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1788 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1794 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1796 struct rte_eth_dev *dev;
1799 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1800 dev = &rte_eth_devices[port_id];
1802 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1803 ret |= ETH_VLAN_STRIP_OFFLOAD;
1805 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1806 ret |= ETH_VLAN_FILTER_OFFLOAD;
1808 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1809 ret |= ETH_VLAN_EXTEND_OFFLOAD;
1815 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1817 struct rte_eth_dev *dev;
1819 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1820 dev = &rte_eth_devices[port_id];
1821 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1822 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1828 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1830 struct rte_eth_dev *dev;
1832 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1833 dev = &rte_eth_devices[port_id];
1834 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1835 memset(fc_conf, 0, sizeof(*fc_conf));
1836 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1840 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1842 struct rte_eth_dev *dev;
1844 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1845 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1846 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1850 dev = &rte_eth_devices[port_id];
1851 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1852 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1856 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1858 struct rte_eth_dev *dev;
1860 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1861 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1862 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1866 dev = &rte_eth_devices[port_id];
1867 /* High water, low water validation are device specific */
1868 if (*dev->dev_ops->priority_flow_ctrl_set)
1869 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1874 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
1882 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
1883 PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
1884 RTE_RETA_GROUP_SIZE);
1888 num = reta_size / RTE_RETA_GROUP_SIZE;
1889 for (i = 0; i < num; i++) {
1890 if (reta_conf[i].mask)
1898 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
1902 uint16_t i, idx, shift;
1908 PMD_DEBUG_TRACE("No receive queue is available\n");
1912 for (i = 0; i < reta_size; i++) {
1913 idx = i / RTE_RETA_GROUP_SIZE;
1914 shift = i % RTE_RETA_GROUP_SIZE;
1915 if ((reta_conf[idx].mask & (1ULL << shift)) &&
1916 (reta_conf[idx].reta[shift] >= max_rxq)) {
1917 PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
1918 "the maximum rxq index: %u\n", idx, shift,
1919 reta_conf[idx].reta[shift], max_rxq);
1928 rte_eth_dev_rss_reta_update(uint8_t port_id,
1929 struct rte_eth_rss_reta_entry64 *reta_conf,
1932 struct rte_eth_dev *dev;
1935 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1936 /* Check mask bits */
1937 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
1941 dev = &rte_eth_devices[port_id];
1943 /* Check entry value */
1944 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
1945 dev->data->nb_rx_queues);
1949 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
1950 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
1954 rte_eth_dev_rss_reta_query(uint8_t port_id,
1955 struct rte_eth_rss_reta_entry64 *reta_conf,
1958 struct rte_eth_dev *dev;
1961 if (port_id >= nb_ports) {
1962 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1966 /* Check mask bits */
1967 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
1971 dev = &rte_eth_devices[port_id];
1972 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
1973 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
1977 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
1979 struct rte_eth_dev *dev;
1980 uint16_t rss_hash_protos;
1982 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1983 rss_hash_protos = rss_conf->rss_hf;
1984 if ((rss_hash_protos != 0) &&
1985 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
1986 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
1990 dev = &rte_eth_devices[port_id];
1991 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
1992 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
1996 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
1997 struct rte_eth_rss_conf *rss_conf)
1999 struct rte_eth_dev *dev;
2001 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2002 dev = &rte_eth_devices[port_id];
2003 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2004 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2008 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
2009 struct rte_eth_udp_tunnel *udp_tunnel)
2011 struct rte_eth_dev *dev;
2013 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2014 if (udp_tunnel == NULL) {
2015 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2019 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2020 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2024 dev = &rte_eth_devices[port_id];
2025 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
2026 return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
2030 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
2031 struct rte_eth_udp_tunnel *udp_tunnel)
2033 struct rte_eth_dev *dev;
2035 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2036 dev = &rte_eth_devices[port_id];
2038 if (udp_tunnel == NULL) {
2039 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2043 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2044 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2048 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2049 return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2053 rte_eth_led_on(uint8_t port_id)
2055 struct rte_eth_dev *dev;
2057 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2058 dev = &rte_eth_devices[port_id];
2059 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2060 return (*dev->dev_ops->dev_led_on)(dev);
2064 rte_eth_led_off(uint8_t port_id)
2066 struct rte_eth_dev *dev;
2068 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2069 dev = &rte_eth_devices[port_id];
2070 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2071 return (*dev->dev_ops->dev_led_off)(dev);
2075 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2079 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2081 struct rte_eth_dev_info dev_info;
2082 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2085 rte_eth_dev_info_get(port_id, &dev_info);
2087 for (i = 0; i < dev_info.max_mac_addrs; i++)
2088 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2094 static const struct ether_addr null_mac_addr;
2097 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2100 struct rte_eth_dev *dev;
2104 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2105 dev = &rte_eth_devices[port_id];
2106 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2108 if (is_zero_ether_addr(addr)) {
2109 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2113 if (pool >= ETH_64_POOLS) {
2114 PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2118 index = get_mac_addr_index(port_id, addr);
2120 index = get_mac_addr_index(port_id, &null_mac_addr);
2122 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2127 pool_mask = dev->data->mac_pool_sel[index];
2129 /* Check if both MAC address and pool is already there, and do nothing */
2130 if (pool_mask & (1ULL << pool))
2135 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2137 /* Update address in NIC data structure */
2138 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2140 /* Update pool bitmap in NIC data structure */
2141 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2147 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2149 struct rte_eth_dev *dev;
2152 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2153 dev = &rte_eth_devices[port_id];
2154 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2156 index = get_mac_addr_index(port_id, addr);
2158 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2160 } else if (index < 0)
2161 return 0; /* Do nothing if address wasn't found */
2164 (*dev->dev_ops->mac_addr_remove)(dev, index);
2166 /* Update address in NIC data structure */
2167 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2169 /* reset pool bitmap */
2170 dev->data->mac_pool_sel[index] = 0;
2176 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2178 struct rte_eth_dev *dev;
2180 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2182 if (!is_valid_assigned_ether_addr(addr))
2185 dev = &rte_eth_devices[port_id];
2186 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2188 /* Update default address in NIC data structure */
2189 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2191 (*dev->dev_ops->mac_addr_set)(dev, addr);
2197 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2198 uint16_t rx_mode, uint8_t on)
2201 struct rte_eth_dev *dev;
2202 struct rte_eth_dev_info dev_info;
2204 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2206 dev = &rte_eth_devices[port_id];
2207 rte_eth_dev_info_get(port_id, &dev_info);
2209 num_vfs = dev_info.max_vfs;
2211 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2216 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2219 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2220 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2224 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2228 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2230 struct rte_eth_dev_info dev_info;
2231 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2234 rte_eth_dev_info_get(port_id, &dev_info);
2235 if (!dev->data->hash_mac_addrs)
2238 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2239 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2240 ETHER_ADDR_LEN) == 0)
2247 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2252 struct rte_eth_dev *dev;
2254 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2256 dev = &rte_eth_devices[port_id];
2257 if (is_zero_ether_addr(addr)) {
2258 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2263 index = get_hash_mac_addr_index(port_id, addr);
2264 /* Check if it's already there, and do nothing */
2265 if ((index >= 0) && (on))
2270 PMD_DEBUG_TRACE("port %d: the MAC address was not "
2271 "set in UTA\n", port_id);
2275 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2277 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2283 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2284 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2286 /* Update address in NIC data structure */
2288 ether_addr_copy(addr,
2289 &dev->data->hash_mac_addrs[index]);
2291 ether_addr_copy(&null_mac_addr,
2292 &dev->data->hash_mac_addrs[index]);
2299 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2301 struct rte_eth_dev *dev;
2303 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2305 dev = &rte_eth_devices[port_id];
2307 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2308 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2312 rte_eth_dev_set_vf_rx(uint8_t port_id, uint16_t vf, uint8_t on)
2315 struct rte_eth_dev *dev;
2316 struct rte_eth_dev_info dev_info;
2318 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2320 dev = &rte_eth_devices[port_id];
2321 rte_eth_dev_info_get(port_id, &dev_info);
2323 num_vfs = dev_info.max_vfs;
2325 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2329 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2330 return (*dev->dev_ops->set_vf_rx)(dev, vf, on);
2334 rte_eth_dev_set_vf_tx(uint8_t port_id, uint16_t vf, uint8_t on)
2337 struct rte_eth_dev *dev;
2338 struct rte_eth_dev_info dev_info;
2340 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2342 dev = &rte_eth_devices[port_id];
2343 rte_eth_dev_info_get(port_id, &dev_info);
2345 num_vfs = dev_info.max_vfs;
2347 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2351 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2352 return (*dev->dev_ops->set_vf_tx)(dev, vf, on);
2356 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2357 uint64_t vf_mask, uint8_t vlan_on)
2359 struct rte_eth_dev *dev;
2361 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2363 dev = &rte_eth_devices[port_id];
2365 if (vlan_id > ETHER_MAX_VLAN_ID) {
2366 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2372 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2376 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2377 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2381 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2384 struct rte_eth_dev *dev;
2385 struct rte_eth_dev_info dev_info;
2386 struct rte_eth_link link;
2388 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2390 dev = &rte_eth_devices[port_id];
2391 rte_eth_dev_info_get(port_id, &dev_info);
2392 link = dev->data->dev_link;
2394 if (queue_idx > dev_info.max_tx_queues) {
2395 PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2396 "invalid queue id=%d\n", port_id, queue_idx);
2400 if (tx_rate > link.link_speed) {
2401 PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2402 "bigger than link speed= %d\n",
2403 tx_rate, link.link_speed);
2407 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2408 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2411 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2414 struct rte_eth_dev *dev;
2415 struct rte_eth_dev_info dev_info;
2416 struct rte_eth_link link;
2421 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2423 dev = &rte_eth_devices[port_id];
2424 rte_eth_dev_info_get(port_id, &dev_info);
2425 link = dev->data->dev_link;
2427 if (vf > dev_info.max_vfs) {
2428 PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2429 "invalid vf id=%d\n", port_id, vf);
2433 if (tx_rate > link.link_speed) {
2434 PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2435 "bigger than link speed= %d\n",
2436 tx_rate, link.link_speed);
2440 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2441 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2445 rte_eth_mirror_rule_set(uint8_t port_id,
2446 struct rte_eth_mirror_conf *mirror_conf,
2447 uint8_t rule_id, uint8_t on)
2449 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2451 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2452 if (mirror_conf->rule_type == 0) {
2453 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2457 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2458 PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2463 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2464 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2465 (mirror_conf->pool_mask == 0)) {
2466 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2470 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2471 mirror_conf->vlan.vlan_mask == 0) {
2472 PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2476 dev = &rte_eth_devices[port_id];
2477 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2479 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2483 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2485 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2487 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2489 dev = &rte_eth_devices[port_id];
2490 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2492 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2495 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2497 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2498 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2500 struct rte_eth_dev *dev;
2502 VALID_PORTID_OR_ERR_RET(port_id, 0);
2504 dev = &rte_eth_devices[port_id];
2505 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);
2506 if (queue_id >= dev->data->nb_rx_queues) {
2507 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2510 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2515 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2516 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2518 struct rte_eth_dev *dev;
2520 VALID_PORTID_OR_ERR_RET(port_id, 0);
2522 dev = &rte_eth_devices[port_id];
2524 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0);
2525 if (queue_id >= dev->data->nb_tx_queues) {
2526 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2529 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2534 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2536 struct rte_eth_dev *dev;
2538 VALID_PORTID_OR_ERR_RET(port_id, 0);
2540 dev = &rte_eth_devices[port_id];
2541 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0);
2542 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2546 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2548 struct rte_eth_dev *dev;
2550 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2552 dev = &rte_eth_devices[port_id];
2553 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2554 return (*dev->dev_ops->rx_descriptor_done)(dev->data->rx_queues[queue_id],
2560 rte_eth_dev_callback_register(uint8_t port_id,
2561 enum rte_eth_event_type event,
2562 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2564 struct rte_eth_dev *dev;
2565 struct rte_eth_dev_callback *user_cb;
2570 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2572 dev = &rte_eth_devices[port_id];
2573 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2575 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2576 if (user_cb->cb_fn == cb_fn &&
2577 user_cb->cb_arg == cb_arg &&
2578 user_cb->event == event) {
2583 /* create a new callback. */
2584 if (user_cb == NULL)
2585 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2586 sizeof(struct rte_eth_dev_callback), 0);
2587 if (user_cb != NULL) {
2588 user_cb->cb_fn = cb_fn;
2589 user_cb->cb_arg = cb_arg;
2590 user_cb->event = event;
2591 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2594 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2595 return (user_cb == NULL) ? -ENOMEM : 0;
2599 rte_eth_dev_callback_unregister(uint8_t port_id,
2600 enum rte_eth_event_type event,
2601 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2604 struct rte_eth_dev *dev;
2605 struct rte_eth_dev_callback *cb, *next;
2610 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2612 dev = &rte_eth_devices[port_id];
2613 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2616 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2618 next = TAILQ_NEXT(cb, next);
2620 if (cb->cb_fn != cb_fn || cb->event != event ||
2621 (cb->cb_arg != (void *)-1 &&
2622 cb->cb_arg != cb_arg))
2626 * if this callback is not executing right now,
2629 if (cb->active == 0) {
2630 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2637 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2642 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2643 enum rte_eth_event_type event)
2645 struct rte_eth_dev_callback *cb_lst;
2646 struct rte_eth_dev_callback dev_cb;
2648 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2649 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2650 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2654 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2655 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2657 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2660 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2664 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
2667 struct rte_eth_dev *dev;
2668 struct rte_intr_handle *intr_handle;
2672 if (!rte_eth_dev_is_valid_port(port_id)) {
2673 PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
2677 dev = &rte_eth_devices[port_id];
2678 intr_handle = &dev->pci_dev->intr_handle;
2679 if (!intr_handle->intr_vec) {
2680 PMD_DEBUG_TRACE("RX Intr vector unset\n");
2684 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2685 vec = intr_handle->intr_vec[qid];
2686 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2687 if (rc && rc != -EEXIST) {
2688 PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2689 " op %d epfd %d vec %u\n",
2690 port_id, qid, op, epfd, vec);
2697 const struct rte_memzone *
2698 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2699 uint16_t queue_id, size_t size, unsigned align,
2702 char z_name[RTE_MEMZONE_NAMESIZE];
2703 const struct rte_memzone *mz;
2705 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2706 dev->driver->pci_drv.name, ring_name,
2707 dev->data->port_id, queue_id);
2709 mz = rte_memzone_lookup(z_name);
2713 if (is_xen_dom0_supported())
2714 return rte_memzone_reserve_bounded(z_name, size, socket_id,
2715 0, align, RTE_PGSIZE_2M);
2717 return rte_memzone_reserve_aligned(z_name, size, socket_id,
2722 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
2723 int epfd, int op, void *data)
2726 struct rte_eth_dev *dev;
2727 struct rte_intr_handle *intr_handle;
2730 if (!rte_eth_dev_is_valid_port(port_id)) {
2731 PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
2735 dev = &rte_eth_devices[port_id];
2736 if (queue_id >= dev->data->nb_rx_queues) {
2737 PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
2741 intr_handle = &dev->pci_dev->intr_handle;
2742 if (!intr_handle->intr_vec) {
2743 PMD_DEBUG_TRACE("RX Intr vector unset\n");
2747 vec = intr_handle->intr_vec[queue_id];
2748 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2749 if (rc && rc != -EEXIST) {
2750 PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2751 " op %d epfd %d vec %u\n",
2752 port_id, queue_id, op, epfd, vec);
2760 rte_eth_dev_rx_intr_enable(uint8_t port_id,
2763 struct rte_eth_dev *dev;
2765 if (!rte_eth_dev_is_valid_port(port_id)) {
2766 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2770 dev = &rte_eth_devices[port_id];
2772 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
2773 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
2777 rte_eth_dev_rx_intr_disable(uint8_t port_id,
2780 struct rte_eth_dev *dev;
2782 if (!rte_eth_dev_is_valid_port(port_id)) {
2783 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2787 dev = &rte_eth_devices[port_id];
2789 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
2790 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
2793 #ifdef RTE_NIC_BYPASS
2794 int rte_eth_dev_bypass_init(uint8_t port_id)
2796 struct rte_eth_dev *dev;
2798 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2800 dev = &rte_eth_devices[port_id];
2801 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2802 (*dev->dev_ops->bypass_init)(dev);
2807 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2809 struct rte_eth_dev *dev;
2811 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2813 dev = &rte_eth_devices[port_id];
2814 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2815 (*dev->dev_ops->bypass_state_show)(dev, state);
2820 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2822 struct rte_eth_dev *dev;
2824 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2826 dev = &rte_eth_devices[port_id];
2827 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2828 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2833 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2835 struct rte_eth_dev *dev;
2837 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2839 dev = &rte_eth_devices[port_id];
2840 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2841 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2846 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2848 struct rte_eth_dev *dev;
2850 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2852 dev = &rte_eth_devices[port_id];
2854 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2855 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2860 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2862 struct rte_eth_dev *dev;
2864 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2866 dev = &rte_eth_devices[port_id];
2868 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2869 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2874 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2876 struct rte_eth_dev *dev;
2878 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2880 dev = &rte_eth_devices[port_id];
2882 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2883 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2888 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2890 struct rte_eth_dev *dev;
2892 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2894 dev = &rte_eth_devices[port_id];
2896 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2897 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2902 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2904 struct rte_eth_dev *dev;
2906 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2908 dev = &rte_eth_devices[port_id];
2910 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2911 (*dev->dev_ops->bypass_wd_reset)(dev);
2917 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
2919 struct rte_eth_dev *dev;
2921 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2923 dev = &rte_eth_devices[port_id];
2924 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2925 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
2926 RTE_ETH_FILTER_NOP, NULL);
2930 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
2931 enum rte_filter_op filter_op, void *arg)
2933 struct rte_eth_dev *dev;
2935 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2937 dev = &rte_eth_devices[port_id];
2938 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2939 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
2943 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
2944 rte_rx_callback_fn fn, void *user_param)
2946 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2947 rte_errno = ENOTSUP;
2950 /* check input parameters */
2951 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2952 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2957 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2965 cb->param = user_param;
2967 /* Add the callbacks in fifo order. */
2968 struct rte_eth_rxtx_callback *tail =
2969 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2972 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2984 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
2985 rte_tx_callback_fn fn, void *user_param)
2987 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2988 rte_errno = ENOTSUP;
2991 /* check input parameters */
2992 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2993 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
2998 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3006 cb->param = user_param;
3008 /* Add the callbacks in fifo order. */
3009 struct rte_eth_rxtx_callback *tail =
3010 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3013 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3025 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3026 struct rte_eth_rxtx_callback *user_cb)
3028 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3031 /* Check input parameters. */
3032 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
3033 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3037 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3038 struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
3039 struct rte_eth_rxtx_callback *prev_cb;
3041 /* Reset head pointer and remove user cb if first in the list. */
3042 if (cb == user_cb) {
3043 dev->post_rx_burst_cbs[queue_id] = user_cb->next;
3047 /* Remove the user cb from the callback list. */
3052 if (cb == user_cb) {
3053 prev_cb->next = user_cb->next;
3057 } while (cb != NULL);
3059 /* Callback wasn't found. */
3064 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3065 struct rte_eth_rxtx_callback *user_cb)
3067 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3070 /* Check input parameters. */
3071 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
3072 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3076 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3077 struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
3078 struct rte_eth_rxtx_callback *prev_cb;
3080 /* Reset head pointer and remove user cb if first in the list. */
3081 if (cb == user_cb) {
3082 dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
3086 /* Remove the user cb from the callback list. */
3091 if (cb == user_cb) {
3092 prev_cb->next = user_cb->next;
3096 } while (cb != NULL);
3098 /* Callback wasn't found. */
3103 rte_eth_rx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3104 struct rte_eth_rxq_info *qinfo)
3106 struct rte_eth_dev *dev;
3108 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3113 dev = &rte_eth_devices[port_id];
3114 if (queue_id >= dev->data->nb_rx_queues) {
3115 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3119 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3121 memset(qinfo, 0, sizeof(*qinfo));
3122 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3127 rte_eth_tx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3128 struct rte_eth_txq_info *qinfo)
3130 struct rte_eth_dev *dev;
3132 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3137 dev = &rte_eth_devices[port_id];
3138 if (queue_id >= dev->data->nb_tx_queues) {
3139 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3143 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3145 memset(qinfo, 0, sizeof(*qinfo));
3146 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3151 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3152 struct ether_addr *mc_addr_set,
3153 uint32_t nb_mc_addr)
3155 struct rte_eth_dev *dev;
3157 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3159 dev = &rte_eth_devices[port_id];
3160 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3161 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3165 rte_eth_timesync_enable(uint8_t port_id)
3167 struct rte_eth_dev *dev;
3169 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3170 dev = &rte_eth_devices[port_id];
3172 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3173 return (*dev->dev_ops->timesync_enable)(dev);
3177 rte_eth_timesync_disable(uint8_t port_id)
3179 struct rte_eth_dev *dev;
3181 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3182 dev = &rte_eth_devices[port_id];
3184 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3185 return (*dev->dev_ops->timesync_disable)(dev);
3189 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3192 struct rte_eth_dev *dev;
3194 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3195 dev = &rte_eth_devices[port_id];
3197 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3198 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3202 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3204 struct rte_eth_dev *dev;
3206 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3207 dev = &rte_eth_devices[port_id];
3209 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3210 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3214 rte_eth_timesync_adjust_time(uint8_t port_id, int64_t delta)
3216 struct rte_eth_dev *dev;
3218 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3219 dev = &rte_eth_devices[port_id];
3221 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3222 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3226 rte_eth_timesync_read_time(uint8_t port_id, struct timespec *timestamp)
3228 struct rte_eth_dev *dev;
3230 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3231 dev = &rte_eth_devices[port_id];
3233 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3234 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3238 rte_eth_timesync_write_time(uint8_t port_id, const struct timespec *timestamp)
3240 struct rte_eth_dev *dev;
3242 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3243 dev = &rte_eth_devices[port_id];
3245 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3246 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3250 rte_eth_dev_get_reg_length(uint8_t port_id)
3252 struct rte_eth_dev *dev;
3254 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3256 dev = &rte_eth_devices[port_id];
3257 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg_length, -ENOTSUP);
3258 return (*dev->dev_ops->get_reg_length)(dev);
3262 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3264 struct rte_eth_dev *dev;
3266 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3268 dev = &rte_eth_devices[port_id];
3269 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3270 return (*dev->dev_ops->get_reg)(dev, info);
3274 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3276 struct rte_eth_dev *dev;
3278 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3280 dev = &rte_eth_devices[port_id];
3281 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3282 return (*dev->dev_ops->get_eeprom_length)(dev);
3286 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3288 struct rte_eth_dev *dev;
3290 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3292 dev = &rte_eth_devices[port_id];
3293 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3294 return (*dev->dev_ops->get_eeprom)(dev, info);
3298 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3300 struct rte_eth_dev *dev;
3302 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3304 dev = &rte_eth_devices[port_id];
3305 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3306 return (*dev->dev_ops->set_eeprom)(dev, info);
3310 rte_eth_dev_get_dcb_info(uint8_t port_id,
3311 struct rte_eth_dcb_info *dcb_info)
3313 struct rte_eth_dev *dev;
3315 if (!rte_eth_dev_is_valid_port(port_id)) {
3316 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3320 dev = &rte_eth_devices[port_id];
3321 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3323 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3324 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3328 rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_dev)
3330 if ((eth_dev == NULL) || (pci_dev == NULL)) {
3331 PMD_DEBUG_TRACE("NULL pointer eth_dev=%p pci_dev=%p\n",
3336 eth_dev->data->dev_flags = 0;
3337 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
3338 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
3339 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_DETACHABLE)
3340 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
3342 eth_dev->data->kdrv = pci_dev->kdrv;
3343 eth_dev->data->numa_node = pci_dev->numa_node;
3344 eth_dev->data->drv_name = pci_dev->driver->name;