4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/types.h>
35 #include <sys/queue.h>
44 #include <netinet/in.h>
46 #include <rte_byteorder.h>
48 #include <rte_debug.h>
49 #include <rte_interrupts.h>
51 #include <rte_memory.h>
52 #include <rte_memcpy.h>
53 #include <rte_memzone.h>
54 #include <rte_launch.h>
56 #include <rte_per_lcore.h>
57 #include <rte_lcore.h>
58 #include <rte_atomic.h>
59 #include <rte_branch_prediction.h>
60 #include <rte_common.h>
61 #include <rte_mempool.h>
62 #include <rte_malloc.h>
64 #include <rte_errno.h>
65 #include <rte_spinlock.h>
66 #include <rte_string_fns.h>
68 #include "rte_ether.h"
69 #include "rte_ethdev.h"
71 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
72 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
73 static struct rte_eth_dev_data *rte_eth_dev_data;
74 static uint8_t eth_dev_last_created_port;
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 /* spinlock for add/remove rx callbacks */
81 static rte_spinlock_t rte_eth_rx_cb_lock = RTE_SPINLOCK_INITIALIZER;
83 /* spinlock for add/remove tx callbacks */
84 static rte_spinlock_t rte_eth_tx_cb_lock = RTE_SPINLOCK_INITIALIZER;
86 /* store statistics names and its offset in stats structure */
87 struct rte_eth_xstats_name_off {
88 char name[RTE_ETH_XSTATS_NAME_SIZE];
92 static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
93 {"rx_good_packets", offsetof(struct rte_eth_stats, ipackets)},
94 {"tx_good_packets", offsetof(struct rte_eth_stats, opackets)},
95 {"rx_good_bytes", offsetof(struct rte_eth_stats, ibytes)},
96 {"tx_good_bytes", offsetof(struct rte_eth_stats, obytes)},
97 {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
98 {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
99 {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats,
103 #define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
105 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
106 {"packets", offsetof(struct rte_eth_stats, q_ipackets)},
107 {"bytes", offsetof(struct rte_eth_stats, q_ibytes)},
108 {"errors", offsetof(struct rte_eth_stats, q_errors)},
111 #define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) / \
112 sizeof(rte_rxq_stats_strings[0]))
114 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
115 {"packets", offsetof(struct rte_eth_stats, q_opackets)},
116 {"bytes", offsetof(struct rte_eth_stats, q_obytes)},
118 #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) / \
119 sizeof(rte_txq_stats_strings[0]))
123 * The user application callback description.
125 * It contains callback address to be registered by user application,
126 * the pointer to the parameters for callback, and the event type.
128 struct rte_eth_dev_callback {
129 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
130 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
131 void *cb_arg; /**< Parameter for callback */
132 enum rte_eth_event_type event; /**< Interrupt event type */
133 uint32_t active; /**< Callback is executing */
147 rte_eth_dev_data_alloc(void)
149 const unsigned flags = 0;
150 const struct rte_memzone *mz;
152 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
153 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
154 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
155 rte_socket_id(), flags);
157 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
159 rte_panic("Cannot allocate memzone for ethernet port data\n");
161 rte_eth_dev_data = mz->addr;
162 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
163 memset(rte_eth_dev_data, 0,
164 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
168 rte_eth_dev_allocated(const char *name)
172 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
173 if ((rte_eth_devices[i].attached == DEV_ATTACHED) &&
174 strcmp(rte_eth_devices[i].data->name, name) == 0)
175 return &rte_eth_devices[i];
181 rte_eth_dev_find_free_port(void)
185 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
186 if (rte_eth_devices[i].attached == DEV_DETACHED)
189 return RTE_MAX_ETHPORTS;
192 static struct rte_eth_dev *
193 eth_dev_get(uint8_t port_id)
195 struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
197 eth_dev->data = &rte_eth_dev_data[port_id];
198 eth_dev->attached = DEV_ATTACHED;
199 TAILQ_INIT(&(eth_dev->link_intr_cbs));
201 eth_dev_last_created_port = port_id;
208 rte_eth_dev_allocate(const char *name)
211 struct rte_eth_dev *eth_dev;
213 port_id = rte_eth_dev_find_free_port();
214 if (port_id == RTE_MAX_ETHPORTS) {
215 RTE_PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
219 if (rte_eth_dev_data == NULL)
220 rte_eth_dev_data_alloc();
222 if (rte_eth_dev_allocated(name) != NULL) {
223 RTE_PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n",
228 memset(&rte_eth_devices[port_id], 0, sizeof(*eth_dev->data));
229 eth_dev = eth_dev_get(port_id);
230 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
231 eth_dev->data->port_id = port_id;
232 eth_dev->data->mtu = ETHER_MTU;
238 * Attach to a port already registered by the primary process, which
239 * makes sure that the same device would have the same port id both
240 * in the primary and secondary process.
242 static struct rte_eth_dev *
243 eth_dev_attach_secondary(const char *name)
246 struct rte_eth_dev *eth_dev;
248 if (rte_eth_dev_data == NULL)
249 rte_eth_dev_data_alloc();
251 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
252 if (strcmp(rte_eth_dev_data[i].name, name) == 0)
255 if (i == RTE_MAX_ETHPORTS) {
257 "device %s is not driven by the primary process\n",
262 eth_dev = eth_dev_get(i);
263 RTE_ASSERT(eth_dev->data->port_id == i);
269 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
274 eth_dev->attached = DEV_DETACHED;
280 rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
281 struct rte_pci_device *pci_dev)
283 struct eth_driver *eth_drv;
284 struct rte_eth_dev *eth_dev;
285 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
289 eth_drv = (struct eth_driver *)pci_drv;
291 rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
292 sizeof(ethdev_name));
294 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
295 eth_dev = rte_eth_dev_allocate(ethdev_name);
299 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
300 eth_drv->dev_private_size,
301 RTE_CACHE_LINE_SIZE);
302 if (eth_dev->data->dev_private == NULL)
303 rte_panic("Cannot allocate memzone for private port data\n");
305 eth_dev = eth_dev_attach_secondary(ethdev_name);
306 if (eth_dev == NULL) {
308 * if we failed to attach a device, it means the
309 * device is skipped in primary process, due to
310 * some errors. If so, we return a positive value,
311 * to let EAL skip it for the secondary process
317 eth_dev->device = &pci_dev->device;
318 eth_dev->intr_handle = &pci_dev->intr_handle;
319 eth_dev->driver = eth_drv;
321 /* Invoke PMD device initialization function */
322 diag = (*eth_drv->eth_dev_init)(eth_dev);
326 RTE_PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%x device_id=0x%x) failed\n",
327 pci_drv->driver.name,
328 (unsigned) pci_dev->id.vendor_id,
329 (unsigned) pci_dev->id.device_id);
330 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
331 rte_free(eth_dev->data->dev_private);
332 rte_eth_dev_release_port(eth_dev);
337 rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
339 const struct eth_driver *eth_drv;
340 struct rte_eth_dev *eth_dev;
341 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
347 rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
348 sizeof(ethdev_name));
350 eth_dev = rte_eth_dev_allocated(ethdev_name);
354 eth_drv = (const struct eth_driver *)pci_dev->driver;
356 /* Invoke PMD device uninit function */
357 if (*eth_drv->eth_dev_uninit) {
358 ret = (*eth_drv->eth_dev_uninit)(eth_dev);
363 /* free ether device */
364 rte_eth_dev_release_port(eth_dev);
366 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
367 rte_free(eth_dev->data->dev_private);
369 eth_dev->device = NULL;
370 eth_dev->driver = NULL;
371 eth_dev->data = NULL;
377 rte_eth_dev_is_valid_port(uint8_t port_id)
379 if (port_id >= RTE_MAX_ETHPORTS ||
380 rte_eth_devices[port_id].attached != DEV_ATTACHED)
387 rte_eth_dev_socket_id(uint8_t port_id)
389 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
390 return rte_eth_devices[port_id].data->numa_node;
394 rte_eth_dev_count(void)
400 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
404 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
407 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
411 /* shouldn't check 'rte_eth_devices[i].data',
412 * because it might be overwritten by VDEV PMD */
413 tmp = rte_eth_dev_data[port_id].name;
419 rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
424 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
431 *port_id = RTE_MAX_ETHPORTS;
433 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
436 rte_eth_dev_data[i].name, strlen(name))) {
447 rte_eth_dev_is_detachable(uint8_t port_id)
451 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
453 switch (rte_eth_devices[port_id].data->kdrv) {
454 case RTE_KDRV_IGB_UIO:
455 case RTE_KDRV_UIO_GENERIC:
456 case RTE_KDRV_NIC_UIO:
463 dev_flags = rte_eth_devices[port_id].data->dev_flags;
464 if ((dev_flags & RTE_ETH_DEV_DETACHABLE) &&
465 (!(dev_flags & RTE_ETH_DEV_BONDED_SLAVE)))
471 /* attach the new device, then store port_id of the device */
473 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
476 int current = rte_eth_dev_count();
480 if ((devargs == NULL) || (port_id == NULL)) {
485 /* parse devargs, then retrieve device name and args */
486 if (rte_eal_parse_devargs_str(devargs, &name, &args))
489 ret = rte_eal_dev_attach(name, args);
493 /* no point looking at the port count if no port exists */
494 if (!rte_eth_dev_count()) {
495 RTE_LOG(ERR, EAL, "No port found for device (%s)\n", name);
500 /* if nothing happened, there is a bug here, since some driver told us
501 * it did attach a device, but did not create a port.
503 if (current == rte_eth_dev_count()) {
508 *port_id = eth_dev_last_created_port;
517 /* detach the device, then store the name of the device */
519 rte_eth_dev_detach(uint8_t port_id, char *name)
528 /* FIXME: move this to eal, once device flags are relocated there */
529 if (rte_eth_dev_is_detachable(port_id))
532 snprintf(name, sizeof(rte_eth_devices[port_id].data->name),
533 "%s", rte_eth_devices[port_id].data->name);
534 ret = rte_eal_dev_detach(name);
545 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
547 uint16_t old_nb_queues = dev->data->nb_rx_queues;
551 if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */
552 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
553 sizeof(dev->data->rx_queues[0]) * nb_queues,
554 RTE_CACHE_LINE_SIZE);
555 if (dev->data->rx_queues == NULL) {
556 dev->data->nb_rx_queues = 0;
559 } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */
560 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
562 rxq = dev->data->rx_queues;
564 for (i = nb_queues; i < old_nb_queues; i++)
565 (*dev->dev_ops->rx_queue_release)(rxq[i]);
566 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
567 RTE_CACHE_LINE_SIZE);
570 if (nb_queues > old_nb_queues) {
571 uint16_t new_qs = nb_queues - old_nb_queues;
573 memset(rxq + old_nb_queues, 0,
574 sizeof(rxq[0]) * new_qs);
577 dev->data->rx_queues = rxq;
579 } else if (dev->data->rx_queues != NULL && nb_queues == 0) {
580 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
582 rxq = dev->data->rx_queues;
584 for (i = nb_queues; i < old_nb_queues; i++)
585 (*dev->dev_ops->rx_queue_release)(rxq[i]);
587 rte_free(dev->data->rx_queues);
588 dev->data->rx_queues = NULL;
590 dev->data->nb_rx_queues = nb_queues;
595 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
597 struct rte_eth_dev *dev;
599 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
601 dev = &rte_eth_devices[port_id];
602 if (rx_queue_id >= dev->data->nb_rx_queues) {
603 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
607 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
609 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
610 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
611 " already started\n",
612 rx_queue_id, port_id);
616 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
621 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
623 struct rte_eth_dev *dev;
625 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
627 dev = &rte_eth_devices[port_id];
628 if (rx_queue_id >= dev->data->nb_rx_queues) {
629 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
633 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
635 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
636 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
637 " already stopped\n",
638 rx_queue_id, port_id);
642 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
647 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
649 struct rte_eth_dev *dev;
651 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
653 dev = &rte_eth_devices[port_id];
654 if (tx_queue_id >= dev->data->nb_tx_queues) {
655 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
659 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
661 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
662 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
663 " already started\n",
664 tx_queue_id, port_id);
668 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
673 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
675 struct rte_eth_dev *dev;
677 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
679 dev = &rte_eth_devices[port_id];
680 if (tx_queue_id >= dev->data->nb_tx_queues) {
681 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
685 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
687 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
688 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
689 " already stopped\n",
690 tx_queue_id, port_id);
694 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
699 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
701 uint16_t old_nb_queues = dev->data->nb_tx_queues;
705 if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */
706 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
707 sizeof(dev->data->tx_queues[0]) * nb_queues,
708 RTE_CACHE_LINE_SIZE);
709 if (dev->data->tx_queues == NULL) {
710 dev->data->nb_tx_queues = 0;
713 } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */
714 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
716 txq = dev->data->tx_queues;
718 for (i = nb_queues; i < old_nb_queues; i++)
719 (*dev->dev_ops->tx_queue_release)(txq[i]);
720 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
721 RTE_CACHE_LINE_SIZE);
724 if (nb_queues > old_nb_queues) {
725 uint16_t new_qs = nb_queues - old_nb_queues;
727 memset(txq + old_nb_queues, 0,
728 sizeof(txq[0]) * new_qs);
731 dev->data->tx_queues = txq;
733 } else if (dev->data->tx_queues != NULL && nb_queues == 0) {
734 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
736 txq = dev->data->tx_queues;
738 for (i = nb_queues; i < old_nb_queues; i++)
739 (*dev->dev_ops->tx_queue_release)(txq[i]);
741 rte_free(dev->data->tx_queues);
742 dev->data->tx_queues = NULL;
744 dev->data->nb_tx_queues = nb_queues;
749 rte_eth_speed_bitflag(uint32_t speed, int duplex)
752 case ETH_SPEED_NUM_10M:
753 return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD;
754 case ETH_SPEED_NUM_100M:
755 return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD;
756 case ETH_SPEED_NUM_1G:
757 return ETH_LINK_SPEED_1G;
758 case ETH_SPEED_NUM_2_5G:
759 return ETH_LINK_SPEED_2_5G;
760 case ETH_SPEED_NUM_5G:
761 return ETH_LINK_SPEED_5G;
762 case ETH_SPEED_NUM_10G:
763 return ETH_LINK_SPEED_10G;
764 case ETH_SPEED_NUM_20G:
765 return ETH_LINK_SPEED_20G;
766 case ETH_SPEED_NUM_25G:
767 return ETH_LINK_SPEED_25G;
768 case ETH_SPEED_NUM_40G:
769 return ETH_LINK_SPEED_40G;
770 case ETH_SPEED_NUM_50G:
771 return ETH_LINK_SPEED_50G;
772 case ETH_SPEED_NUM_56G:
773 return ETH_LINK_SPEED_56G;
774 case ETH_SPEED_NUM_100G:
775 return ETH_LINK_SPEED_100G;
782 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
783 const struct rte_eth_conf *dev_conf)
785 struct rte_eth_dev *dev;
786 struct rte_eth_dev_info dev_info;
789 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
791 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
793 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
794 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
798 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
800 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
801 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
805 dev = &rte_eth_devices[port_id];
807 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
808 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
810 if (dev->data->dev_started) {
812 "port %d must be stopped to allow configuration\n", port_id);
816 /* Copy the dev_conf parameter into the dev structure */
817 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
820 * Check that the numbers of RX and TX queues are not greater
821 * than the maximum number of RX and TX queues supported by the
824 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
826 if (nb_rx_q == 0 && nb_tx_q == 0) {
827 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d both rx and tx queue cannot be 0\n", port_id);
831 if (nb_rx_q > dev_info.max_rx_queues) {
832 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
833 port_id, nb_rx_q, dev_info.max_rx_queues);
837 if (nb_tx_q > dev_info.max_tx_queues) {
838 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
839 port_id, nb_tx_q, dev_info.max_tx_queues);
844 * If link state interrupt is enabled, check that the
845 * device supports it.
847 if ((dev_conf->intr_conf.lsc == 1) &&
848 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
849 RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
850 dev->data->drv_name);
855 * If jumbo frames are enabled, check that the maximum RX packet
856 * length is supported by the configured device.
858 if (dev_conf->rxmode.jumbo_frame == 1) {
859 if (dev_conf->rxmode.max_rx_pkt_len >
860 dev_info.max_rx_pktlen) {
861 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
862 " > max valid value %u\n",
864 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
865 (unsigned)dev_info.max_rx_pktlen);
867 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
868 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
869 " < min valid value %u\n",
871 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
872 (unsigned)ETHER_MIN_LEN);
876 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
877 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
878 /* Use default value */
879 dev->data->dev_conf.rxmode.max_rx_pkt_len =
884 * Setup new number of RX/TX queues and reconfigure device.
886 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
888 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
893 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
895 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
897 rte_eth_dev_rx_queue_config(dev, 0);
901 diag = (*dev->dev_ops->dev_configure)(dev);
903 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
905 rte_eth_dev_rx_queue_config(dev, 0);
906 rte_eth_dev_tx_queue_config(dev, 0);
914 _rte_eth_dev_reset(struct rte_eth_dev *dev)
916 if (dev->data->dev_started) {
918 "port %d must be stopped to allow reset\n",
923 rte_eth_dev_rx_queue_config(dev, 0);
924 rte_eth_dev_tx_queue_config(dev, 0);
926 memset(&dev->data->dev_conf, 0, sizeof(dev->data->dev_conf));
930 rte_eth_dev_config_restore(uint8_t port_id)
932 struct rte_eth_dev *dev;
933 struct rte_eth_dev_info dev_info;
934 struct ether_addr addr;
938 dev = &rte_eth_devices[port_id];
940 rte_eth_dev_info_get(port_id, &dev_info);
942 if (RTE_ETH_DEV_SRIOV(dev).active)
943 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
945 /* replay MAC address configuration */
946 for (i = 0; i < dev_info.max_mac_addrs; i++) {
947 addr = dev->data->mac_addrs[i];
949 /* skip zero address */
950 if (is_zero_ether_addr(&addr))
953 /* add address to the hardware */
954 if (*dev->dev_ops->mac_addr_add &&
955 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
956 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
958 RTE_PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
960 /* exit the loop but not return an error */
965 /* replay promiscuous configuration */
966 if (rte_eth_promiscuous_get(port_id) == 1)
967 rte_eth_promiscuous_enable(port_id);
968 else if (rte_eth_promiscuous_get(port_id) == 0)
969 rte_eth_promiscuous_disable(port_id);
971 /* replay all multicast configuration */
972 if (rte_eth_allmulticast_get(port_id) == 1)
973 rte_eth_allmulticast_enable(port_id);
974 else if (rte_eth_allmulticast_get(port_id) == 0)
975 rte_eth_allmulticast_disable(port_id);
979 rte_eth_dev_start(uint8_t port_id)
981 struct rte_eth_dev *dev;
984 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
986 dev = &rte_eth_devices[port_id];
988 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
990 if (dev->data->dev_started != 0) {
991 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
992 " already started\n",
997 diag = (*dev->dev_ops->dev_start)(dev);
999 dev->data->dev_started = 1;
1003 rte_eth_dev_config_restore(port_id);
1005 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1006 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1007 (*dev->dev_ops->link_update)(dev, 0);
1013 rte_eth_dev_stop(uint8_t port_id)
1015 struct rte_eth_dev *dev;
1017 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1018 dev = &rte_eth_devices[port_id];
1020 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1022 if (dev->data->dev_started == 0) {
1023 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1024 " already stopped\n",
1029 dev->data->dev_started = 0;
1030 (*dev->dev_ops->dev_stop)(dev);
1034 rte_eth_dev_set_link_up(uint8_t port_id)
1036 struct rte_eth_dev *dev;
1038 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1040 dev = &rte_eth_devices[port_id];
1042 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1043 return (*dev->dev_ops->dev_set_link_up)(dev);
1047 rte_eth_dev_set_link_down(uint8_t port_id)
1049 struct rte_eth_dev *dev;
1051 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1053 dev = &rte_eth_devices[port_id];
1055 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1056 return (*dev->dev_ops->dev_set_link_down)(dev);
1060 rte_eth_dev_close(uint8_t port_id)
1062 struct rte_eth_dev *dev;
1064 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1065 dev = &rte_eth_devices[port_id];
1067 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1068 dev->data->dev_started = 0;
1069 (*dev->dev_ops->dev_close)(dev);
1071 rte_free(dev->data->rx_queues);
1072 dev->data->rx_queues = NULL;
1073 rte_free(dev->data->tx_queues);
1074 dev->data->tx_queues = NULL;
1078 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1079 uint16_t nb_rx_desc, unsigned int socket_id,
1080 const struct rte_eth_rxconf *rx_conf,
1081 struct rte_mempool *mp)
1084 uint32_t mbp_buf_size;
1085 struct rte_eth_dev *dev;
1086 struct rte_eth_dev_info dev_info;
1089 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1091 dev = &rte_eth_devices[port_id];
1092 if (rx_queue_id >= dev->data->nb_rx_queues) {
1093 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1097 if (dev->data->dev_started) {
1098 RTE_PMD_DEBUG_TRACE(
1099 "port %d must be stopped to allow configuration\n", port_id);
1103 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1104 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1107 * Check the size of the mbuf data buffer.
1108 * This value must be provided in the private data of the memory pool.
1109 * First check that the memory pool has a valid private data.
1111 rte_eth_dev_info_get(port_id, &dev_info);
1112 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1113 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1114 mp->name, (int) mp->private_data_size,
1115 (int) sizeof(struct rte_pktmbuf_pool_private));
1118 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1120 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1121 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1122 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1126 (int)(RTE_PKTMBUF_HEADROOM +
1127 dev_info.min_rx_bufsize),
1128 (int)RTE_PKTMBUF_HEADROOM,
1129 (int)dev_info.min_rx_bufsize);
1133 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1134 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1135 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1137 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1138 "should be: <= %hu, = %hu, and a product of %hu\n",
1140 dev_info.rx_desc_lim.nb_max,
1141 dev_info.rx_desc_lim.nb_min,
1142 dev_info.rx_desc_lim.nb_align);
1146 rxq = dev->data->rx_queues;
1147 if (rxq[rx_queue_id]) {
1148 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release,
1150 (*dev->dev_ops->rx_queue_release)(rxq[rx_queue_id]);
1151 rxq[rx_queue_id] = NULL;
1154 if (rx_conf == NULL)
1155 rx_conf = &dev_info.default_rxconf;
1157 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1158 socket_id, rx_conf, mp);
1160 if (!dev->data->min_rx_buf_size ||
1161 dev->data->min_rx_buf_size > mbp_buf_size)
1162 dev->data->min_rx_buf_size = mbp_buf_size;
1169 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1170 uint16_t nb_tx_desc, unsigned int socket_id,
1171 const struct rte_eth_txconf *tx_conf)
1173 struct rte_eth_dev *dev;
1174 struct rte_eth_dev_info dev_info;
1177 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1179 dev = &rte_eth_devices[port_id];
1180 if (tx_queue_id >= dev->data->nb_tx_queues) {
1181 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1185 if (dev->data->dev_started) {
1186 RTE_PMD_DEBUG_TRACE(
1187 "port %d must be stopped to allow configuration\n", port_id);
1191 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1192 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1194 rte_eth_dev_info_get(port_id, &dev_info);
1196 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1197 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1198 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1199 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1200 "should be: <= %hu, = %hu, and a product of %hu\n",
1202 dev_info.tx_desc_lim.nb_max,
1203 dev_info.tx_desc_lim.nb_min,
1204 dev_info.tx_desc_lim.nb_align);
1208 txq = dev->data->tx_queues;
1209 if (txq[tx_queue_id]) {
1210 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release,
1212 (*dev->dev_ops->tx_queue_release)(txq[tx_queue_id]);
1213 txq[tx_queue_id] = NULL;
1216 if (tx_conf == NULL)
1217 tx_conf = &dev_info.default_txconf;
1219 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1220 socket_id, tx_conf);
1224 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
1225 void *userdata __rte_unused)
1229 for (i = 0; i < unsent; i++)
1230 rte_pktmbuf_free(pkts[i]);
1234 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
1237 uint64_t *count = userdata;
1240 for (i = 0; i < unsent; i++)
1241 rte_pktmbuf_free(pkts[i]);
1247 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
1248 buffer_tx_error_fn cbfn, void *userdata)
1250 buffer->error_callback = cbfn;
1251 buffer->error_userdata = userdata;
1256 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
1263 buffer->size = size;
1264 if (buffer->error_callback == NULL) {
1265 ret = rte_eth_tx_buffer_set_err_callback(
1266 buffer, rte_eth_tx_buffer_drop_callback, NULL);
1273 rte_eth_promiscuous_enable(uint8_t port_id)
1275 struct rte_eth_dev *dev;
1277 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1278 dev = &rte_eth_devices[port_id];
1280 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1281 (*dev->dev_ops->promiscuous_enable)(dev);
1282 dev->data->promiscuous = 1;
1286 rte_eth_promiscuous_disable(uint8_t port_id)
1288 struct rte_eth_dev *dev;
1290 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1291 dev = &rte_eth_devices[port_id];
1293 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1294 dev->data->promiscuous = 0;
1295 (*dev->dev_ops->promiscuous_disable)(dev);
1299 rte_eth_promiscuous_get(uint8_t port_id)
1301 struct rte_eth_dev *dev;
1303 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1305 dev = &rte_eth_devices[port_id];
1306 return dev->data->promiscuous;
1310 rte_eth_allmulticast_enable(uint8_t port_id)
1312 struct rte_eth_dev *dev;
1314 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1315 dev = &rte_eth_devices[port_id];
1317 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1318 (*dev->dev_ops->allmulticast_enable)(dev);
1319 dev->data->all_multicast = 1;
1323 rte_eth_allmulticast_disable(uint8_t port_id)
1325 struct rte_eth_dev *dev;
1327 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1328 dev = &rte_eth_devices[port_id];
1330 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1331 dev->data->all_multicast = 0;
1332 (*dev->dev_ops->allmulticast_disable)(dev);
1336 rte_eth_allmulticast_get(uint8_t port_id)
1338 struct rte_eth_dev *dev;
1340 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1342 dev = &rte_eth_devices[port_id];
1343 return dev->data->all_multicast;
1347 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1348 struct rte_eth_link *link)
1350 struct rte_eth_link *dst = link;
1351 struct rte_eth_link *src = &(dev->data->dev_link);
1353 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1354 *(uint64_t *)src) == 0)
1361 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1363 struct rte_eth_dev *dev;
1365 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1366 dev = &rte_eth_devices[port_id];
1368 if (dev->data->dev_conf.intr_conf.lsc != 0)
1369 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1371 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1372 (*dev->dev_ops->link_update)(dev, 1);
1373 *eth_link = dev->data->dev_link;
1378 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1380 struct rte_eth_dev *dev;
1382 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1383 dev = &rte_eth_devices[port_id];
1385 if (dev->data->dev_conf.intr_conf.lsc != 0)
1386 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1388 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1389 (*dev->dev_ops->link_update)(dev, 0);
1390 *eth_link = dev->data->dev_link;
1395 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1397 struct rte_eth_dev *dev;
1399 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1401 dev = &rte_eth_devices[port_id];
1402 memset(stats, 0, sizeof(*stats));
1404 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1405 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1406 (*dev->dev_ops->stats_get)(dev, stats);
1411 rte_eth_stats_reset(uint8_t port_id)
1413 struct rte_eth_dev *dev;
1415 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1416 dev = &rte_eth_devices[port_id];
1418 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1419 (*dev->dev_ops->stats_reset)(dev);
1420 dev->data->rx_mbuf_alloc_failed = 0;
1424 get_xstats_count(uint8_t port_id)
1426 struct rte_eth_dev *dev;
1429 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1430 dev = &rte_eth_devices[port_id];
1431 if (dev->dev_ops->xstats_get_names != NULL) {
1432 count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0);
1437 count += RTE_NB_STATS;
1438 count += RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
1440 count += RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
1446 rte_eth_xstats_get_names(uint8_t port_id,
1447 struct rte_eth_xstat_name *xstats_names,
1450 struct rte_eth_dev *dev;
1451 int cnt_used_entries;
1452 int cnt_expected_entries;
1453 int cnt_driver_entries;
1454 uint32_t idx, id_queue;
1457 cnt_expected_entries = get_xstats_count(port_id);
1458 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1459 (int)size < cnt_expected_entries)
1460 return cnt_expected_entries;
1462 /* port_id checked in get_xstats_count() */
1463 dev = &rte_eth_devices[port_id];
1464 cnt_used_entries = 0;
1466 for (idx = 0; idx < RTE_NB_STATS; idx++) {
1467 snprintf(xstats_names[cnt_used_entries].name,
1468 sizeof(xstats_names[0].name),
1469 "%s", rte_stats_strings[idx].name);
1472 num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1473 for (id_queue = 0; id_queue < num_q; id_queue++) {
1474 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1475 snprintf(xstats_names[cnt_used_entries].name,
1476 sizeof(xstats_names[0].name),
1478 id_queue, rte_rxq_stats_strings[idx].name);
1483 num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1484 for (id_queue = 0; id_queue < num_q; id_queue++) {
1485 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
1486 snprintf(xstats_names[cnt_used_entries].name,
1487 sizeof(xstats_names[0].name),
1489 id_queue, rte_txq_stats_strings[idx].name);
1494 if (dev->dev_ops->xstats_get_names != NULL) {
1495 /* If there are any driver-specific xstats, append them
1498 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
1500 xstats_names + cnt_used_entries,
1501 size - cnt_used_entries);
1502 if (cnt_driver_entries < 0)
1503 return cnt_driver_entries;
1504 cnt_used_entries += cnt_driver_entries;
1507 return cnt_used_entries;
1510 /* retrieve ethdev extended statistics */
1512 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstat *xstats,
1515 struct rte_eth_stats eth_stats;
1516 struct rte_eth_dev *dev;
1517 unsigned count = 0, i, q;
1519 uint64_t val, *stats_ptr;
1520 uint16_t nb_rxqs, nb_txqs;
1522 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1524 dev = &rte_eth_devices[port_id];
1526 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1527 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1529 /* Return generic statistics */
1530 count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
1531 (nb_txqs * RTE_NB_TXQ_STATS);
1533 /* implemented by the driver */
1534 if (dev->dev_ops->xstats_get != NULL) {
1535 /* Retrieve the xstats from the driver at the end of the
1538 xcount = (*dev->dev_ops->xstats_get)(dev,
1539 xstats ? xstats + count : NULL,
1540 (n > count) ? n - count : 0);
1546 if (n < count + xcount || xstats == NULL)
1547 return count + xcount;
1549 /* now fill the xstats structure */
1551 rte_eth_stats_get(port_id, ð_stats);
1554 for (i = 0; i < RTE_NB_STATS; i++) {
1555 stats_ptr = RTE_PTR_ADD(ð_stats,
1556 rte_stats_strings[i].offset);
1558 xstats[count++].value = val;
1562 for (q = 0; q < nb_rxqs; q++) {
1563 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1564 stats_ptr = RTE_PTR_ADD(ð_stats,
1565 rte_rxq_stats_strings[i].offset +
1566 q * sizeof(uint64_t));
1568 xstats[count++].value = val;
1573 for (q = 0; q < nb_txqs; q++) {
1574 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1575 stats_ptr = RTE_PTR_ADD(ð_stats,
1576 rte_txq_stats_strings[i].offset +
1577 q * sizeof(uint64_t));
1579 xstats[count++].value = val;
1583 for (i = 0; i < count; i++)
1585 /* add an offset to driver-specific stats */
1586 for ( ; i < count + xcount; i++)
1587 xstats[i].id += count;
1589 return count + xcount;
1592 /* reset ethdev extended statistics */
1594 rte_eth_xstats_reset(uint8_t port_id)
1596 struct rte_eth_dev *dev;
1598 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1599 dev = &rte_eth_devices[port_id];
1601 /* implemented by the driver */
1602 if (dev->dev_ops->xstats_reset != NULL) {
1603 (*dev->dev_ops->xstats_reset)(dev);
1607 /* fallback to default */
1608 rte_eth_stats_reset(port_id);
1612 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1615 struct rte_eth_dev *dev;
1617 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1619 dev = &rte_eth_devices[port_id];
1621 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1622 return (*dev->dev_ops->queue_stats_mapping_set)
1623 (dev, queue_id, stat_idx, is_rx);
1628 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1631 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1637 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1640 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1645 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1647 struct rte_eth_dev *dev;
1648 const struct rte_eth_desc_lim lim = {
1649 .nb_max = UINT16_MAX,
1654 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1655 dev = &rte_eth_devices[port_id];
1657 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1658 dev_info->rx_desc_lim = lim;
1659 dev_info->tx_desc_lim = lim;
1661 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1662 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1663 dev_info->driver_name = dev->data->drv_name;
1664 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
1665 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
1669 rte_eth_dev_get_supported_ptypes(uint8_t port_id, uint32_t ptype_mask,
1670 uint32_t *ptypes, int num)
1673 struct rte_eth_dev *dev;
1674 const uint32_t *all_ptypes;
1676 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1677 dev = &rte_eth_devices[port_id];
1678 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
1679 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
1684 for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
1685 if (all_ptypes[i] & ptype_mask) {
1687 ptypes[j] = all_ptypes[i];
1695 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1697 struct rte_eth_dev *dev;
1699 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1700 dev = &rte_eth_devices[port_id];
1701 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1706 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1708 struct rte_eth_dev *dev;
1710 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1712 dev = &rte_eth_devices[port_id];
1713 *mtu = dev->data->mtu;
1718 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1721 struct rte_eth_dev *dev;
1723 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1724 dev = &rte_eth_devices[port_id];
1725 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1727 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1729 dev->data->mtu = mtu;
1735 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1737 struct rte_eth_dev *dev;
1739 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1740 dev = &rte_eth_devices[port_id];
1741 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1742 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1746 if (vlan_id > 4095) {
1747 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1748 port_id, (unsigned) vlan_id);
1751 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1753 return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1757 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1759 struct rte_eth_dev *dev;
1761 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1762 dev = &rte_eth_devices[port_id];
1763 if (rx_queue_id >= dev->data->nb_rx_queues) {
1764 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1768 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1769 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1775 rte_eth_dev_set_vlan_ether_type(uint8_t port_id,
1776 enum rte_vlan_type vlan_type,
1779 struct rte_eth_dev *dev;
1781 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1782 dev = &rte_eth_devices[port_id];
1783 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1785 return (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type, tpid);
1789 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1791 struct rte_eth_dev *dev;
1796 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1797 dev = &rte_eth_devices[port_id];
1799 /*check which option changed by application*/
1800 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1801 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1803 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1804 mask |= ETH_VLAN_STRIP_MASK;
1807 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1808 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1810 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1811 mask |= ETH_VLAN_FILTER_MASK;
1814 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1815 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1817 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1818 mask |= ETH_VLAN_EXTEND_MASK;
1825 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1826 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1832 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1834 struct rte_eth_dev *dev;
1837 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1838 dev = &rte_eth_devices[port_id];
1840 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1841 ret |= ETH_VLAN_STRIP_OFFLOAD;
1843 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1844 ret |= ETH_VLAN_FILTER_OFFLOAD;
1846 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1847 ret |= ETH_VLAN_EXTEND_OFFLOAD;
1853 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1855 struct rte_eth_dev *dev;
1857 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1858 dev = &rte_eth_devices[port_id];
1859 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1860 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1866 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1868 struct rte_eth_dev *dev;
1870 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1871 dev = &rte_eth_devices[port_id];
1872 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1873 memset(fc_conf, 0, sizeof(*fc_conf));
1874 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1878 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1880 struct rte_eth_dev *dev;
1882 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1883 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1884 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1888 dev = &rte_eth_devices[port_id];
1889 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1890 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1894 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1896 struct rte_eth_dev *dev;
1898 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1899 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1900 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1904 dev = &rte_eth_devices[port_id];
1905 /* High water, low water validation are device specific */
1906 if (*dev->dev_ops->priority_flow_ctrl_set)
1907 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1912 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
1920 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
1921 RTE_PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
1922 RTE_RETA_GROUP_SIZE);
1926 num = reta_size / RTE_RETA_GROUP_SIZE;
1927 for (i = 0; i < num; i++) {
1928 if (reta_conf[i].mask)
1936 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
1940 uint16_t i, idx, shift;
1946 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
1950 for (i = 0; i < reta_size; i++) {
1951 idx = i / RTE_RETA_GROUP_SIZE;
1952 shift = i % RTE_RETA_GROUP_SIZE;
1953 if ((reta_conf[idx].mask & (1ULL << shift)) &&
1954 (reta_conf[idx].reta[shift] >= max_rxq)) {
1955 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
1956 "the maximum rxq index: %u\n", idx, shift,
1957 reta_conf[idx].reta[shift], max_rxq);
1966 rte_eth_dev_rss_reta_update(uint8_t port_id,
1967 struct rte_eth_rss_reta_entry64 *reta_conf,
1970 struct rte_eth_dev *dev;
1973 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1974 /* Check mask bits */
1975 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
1979 dev = &rte_eth_devices[port_id];
1981 /* Check entry value */
1982 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
1983 dev->data->nb_rx_queues);
1987 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
1988 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
1992 rte_eth_dev_rss_reta_query(uint8_t port_id,
1993 struct rte_eth_rss_reta_entry64 *reta_conf,
1996 struct rte_eth_dev *dev;
1999 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2001 /* Check mask bits */
2002 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2006 dev = &rte_eth_devices[port_id];
2007 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2008 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2012 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2014 struct rte_eth_dev *dev;
2015 uint16_t rss_hash_protos;
2017 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2018 rss_hash_protos = rss_conf->rss_hf;
2019 if ((rss_hash_protos != 0) &&
2020 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2021 RTE_PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2025 dev = &rte_eth_devices[port_id];
2026 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2027 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2031 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2032 struct rte_eth_rss_conf *rss_conf)
2034 struct rte_eth_dev *dev;
2036 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2037 dev = &rte_eth_devices[port_id];
2038 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2039 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2043 rte_eth_dev_udp_tunnel_port_add(uint8_t port_id,
2044 struct rte_eth_udp_tunnel *udp_tunnel)
2046 struct rte_eth_dev *dev;
2048 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2049 if (udp_tunnel == NULL) {
2050 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2054 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2055 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2059 dev = &rte_eth_devices[port_id];
2060 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
2061 return (*dev->dev_ops->udp_tunnel_port_add)(dev, udp_tunnel);
2065 rte_eth_dev_udp_tunnel_port_delete(uint8_t port_id,
2066 struct rte_eth_udp_tunnel *udp_tunnel)
2068 struct rte_eth_dev *dev;
2070 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2071 dev = &rte_eth_devices[port_id];
2073 if (udp_tunnel == NULL) {
2074 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2078 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2079 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2083 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
2084 return (*dev->dev_ops->udp_tunnel_port_del)(dev, udp_tunnel);
2088 rte_eth_led_on(uint8_t port_id)
2090 struct rte_eth_dev *dev;
2092 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2093 dev = &rte_eth_devices[port_id];
2094 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2095 return (*dev->dev_ops->dev_led_on)(dev);
2099 rte_eth_led_off(uint8_t port_id)
2101 struct rte_eth_dev *dev;
2103 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2104 dev = &rte_eth_devices[port_id];
2105 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2106 return (*dev->dev_ops->dev_led_off)(dev);
2110 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2114 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2116 struct rte_eth_dev_info dev_info;
2117 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2120 rte_eth_dev_info_get(port_id, &dev_info);
2122 for (i = 0; i < dev_info.max_mac_addrs; i++)
2123 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2129 static const struct ether_addr null_mac_addr;
2132 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2135 struct rte_eth_dev *dev;
2139 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2140 dev = &rte_eth_devices[port_id];
2141 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2143 if (is_zero_ether_addr(addr)) {
2144 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2148 if (pool >= ETH_64_POOLS) {
2149 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2153 index = get_mac_addr_index(port_id, addr);
2155 index = get_mac_addr_index(port_id, &null_mac_addr);
2157 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2162 pool_mask = dev->data->mac_pool_sel[index];
2164 /* Check if both MAC address and pool is already there, and do nothing */
2165 if (pool_mask & (1ULL << pool))
2170 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2172 /* Update address in NIC data structure */
2173 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2175 /* Update pool bitmap in NIC data structure */
2176 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2182 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2184 struct rte_eth_dev *dev;
2187 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2188 dev = &rte_eth_devices[port_id];
2189 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2191 index = get_mac_addr_index(port_id, addr);
2193 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2195 } else if (index < 0)
2196 return 0; /* Do nothing if address wasn't found */
2199 (*dev->dev_ops->mac_addr_remove)(dev, index);
2201 /* Update address in NIC data structure */
2202 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2204 /* reset pool bitmap */
2205 dev->data->mac_pool_sel[index] = 0;
2211 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2213 struct rte_eth_dev *dev;
2215 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2217 if (!is_valid_assigned_ether_addr(addr))
2220 dev = &rte_eth_devices[port_id];
2221 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2223 /* Update default address in NIC data structure */
2224 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2226 (*dev->dev_ops->mac_addr_set)(dev, addr);
2232 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2233 uint16_t rx_mode, uint8_t on)
2236 struct rte_eth_dev *dev;
2237 struct rte_eth_dev_info dev_info;
2239 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2241 dev = &rte_eth_devices[port_id];
2242 rte_eth_dev_info_get(port_id, &dev_info);
2244 num_vfs = dev_info.max_vfs;
2246 RTE_PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2251 RTE_PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2254 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2255 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2259 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2263 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2265 struct rte_eth_dev_info dev_info;
2266 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2269 rte_eth_dev_info_get(port_id, &dev_info);
2270 if (!dev->data->hash_mac_addrs)
2273 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2274 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2275 ETHER_ADDR_LEN) == 0)
2282 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2287 struct rte_eth_dev *dev;
2289 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2291 dev = &rte_eth_devices[port_id];
2292 if (is_zero_ether_addr(addr)) {
2293 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2298 index = get_hash_mac_addr_index(port_id, addr);
2299 /* Check if it's already there, and do nothing */
2300 if ((index >= 0) && (on))
2305 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2306 "set in UTA\n", port_id);
2310 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2312 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2318 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2319 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2321 /* Update address in NIC data structure */
2323 ether_addr_copy(addr,
2324 &dev->data->hash_mac_addrs[index]);
2326 ether_addr_copy(&null_mac_addr,
2327 &dev->data->hash_mac_addrs[index]);
2334 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2336 struct rte_eth_dev *dev;
2338 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2340 dev = &rte_eth_devices[port_id];
2342 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2343 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2347 rte_eth_dev_set_vf_rx(uint8_t port_id, uint16_t vf, uint8_t on)
2350 struct rte_eth_dev *dev;
2351 struct rte_eth_dev_info dev_info;
2353 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2355 dev = &rte_eth_devices[port_id];
2356 rte_eth_dev_info_get(port_id, &dev_info);
2358 num_vfs = dev_info.max_vfs;
2360 RTE_PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2364 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2365 return (*dev->dev_ops->set_vf_rx)(dev, vf, on);
2369 rte_eth_dev_set_vf_tx(uint8_t port_id, uint16_t vf, uint8_t on)
2372 struct rte_eth_dev *dev;
2373 struct rte_eth_dev_info dev_info;
2375 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2377 dev = &rte_eth_devices[port_id];
2378 rte_eth_dev_info_get(port_id, &dev_info);
2380 num_vfs = dev_info.max_vfs;
2382 RTE_PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2386 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2387 return (*dev->dev_ops->set_vf_tx)(dev, vf, on);
2391 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2392 uint64_t vf_mask, uint8_t vlan_on)
2394 struct rte_eth_dev *dev;
2396 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2398 dev = &rte_eth_devices[port_id];
2400 if (vlan_id > ETHER_MAX_VLAN_ID) {
2401 RTE_PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2407 RTE_PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2411 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2412 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2416 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2419 struct rte_eth_dev *dev;
2420 struct rte_eth_dev_info dev_info;
2421 struct rte_eth_link link;
2423 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2425 dev = &rte_eth_devices[port_id];
2426 rte_eth_dev_info_get(port_id, &dev_info);
2427 link = dev->data->dev_link;
2429 if (queue_idx > dev_info.max_tx_queues) {
2430 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2431 "invalid queue id=%d\n", port_id, queue_idx);
2435 if (tx_rate > link.link_speed) {
2436 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2437 "bigger than link speed= %d\n",
2438 tx_rate, link.link_speed);
2442 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2443 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2446 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2449 struct rte_eth_dev *dev;
2450 struct rte_eth_dev_info dev_info;
2451 struct rte_eth_link link;
2456 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2458 dev = &rte_eth_devices[port_id];
2459 rte_eth_dev_info_get(port_id, &dev_info);
2460 link = dev->data->dev_link;
2462 if (vf > dev_info.max_vfs) {
2463 RTE_PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2464 "invalid vf id=%d\n", port_id, vf);
2468 if (tx_rate > link.link_speed) {
2469 RTE_PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2470 "bigger than link speed= %d\n",
2471 tx_rate, link.link_speed);
2475 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2476 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2480 rte_eth_mirror_rule_set(uint8_t port_id,
2481 struct rte_eth_mirror_conf *mirror_conf,
2482 uint8_t rule_id, uint8_t on)
2484 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2486 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2487 if (mirror_conf->rule_type == 0) {
2488 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2492 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2493 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2498 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2499 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2500 (mirror_conf->pool_mask == 0)) {
2501 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2505 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2506 mirror_conf->vlan.vlan_mask == 0) {
2507 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2511 dev = &rte_eth_devices[port_id];
2512 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2514 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2518 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2520 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2522 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2524 dev = &rte_eth_devices[port_id];
2525 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2527 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2531 rte_eth_dev_callback_register(uint8_t port_id,
2532 enum rte_eth_event_type event,
2533 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2535 struct rte_eth_dev *dev;
2536 struct rte_eth_dev_callback *user_cb;
2541 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2543 dev = &rte_eth_devices[port_id];
2544 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2546 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2547 if (user_cb->cb_fn == cb_fn &&
2548 user_cb->cb_arg == cb_arg &&
2549 user_cb->event == event) {
2554 /* create a new callback. */
2555 if (user_cb == NULL) {
2556 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2557 sizeof(struct rte_eth_dev_callback), 0);
2558 if (user_cb != NULL) {
2559 user_cb->cb_fn = cb_fn;
2560 user_cb->cb_arg = cb_arg;
2561 user_cb->event = event;
2562 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2566 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2567 return (user_cb == NULL) ? -ENOMEM : 0;
2571 rte_eth_dev_callback_unregister(uint8_t port_id,
2572 enum rte_eth_event_type event,
2573 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2576 struct rte_eth_dev *dev;
2577 struct rte_eth_dev_callback *cb, *next;
2582 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2584 dev = &rte_eth_devices[port_id];
2585 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2588 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2590 next = TAILQ_NEXT(cb, next);
2592 if (cb->cb_fn != cb_fn || cb->event != event ||
2593 (cb->cb_arg != (void *)-1 &&
2594 cb->cb_arg != cb_arg))
2598 * if this callback is not executing right now,
2601 if (cb->active == 0) {
2602 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2609 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2614 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2615 enum rte_eth_event_type event, void *cb_arg)
2617 struct rte_eth_dev_callback *cb_lst;
2618 struct rte_eth_dev_callback dev_cb;
2620 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2621 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2622 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2627 dev_cb.cb_arg = (void *) cb_arg;
2629 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2630 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2632 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2635 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2639 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
2642 struct rte_eth_dev *dev;
2643 struct rte_intr_handle *intr_handle;
2647 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2649 dev = &rte_eth_devices[port_id];
2651 if (!dev->intr_handle) {
2652 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
2656 intr_handle = dev->intr_handle;
2657 if (!intr_handle->intr_vec) {
2658 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2662 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2663 vec = intr_handle->intr_vec[qid];
2664 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2665 if (rc && rc != -EEXIST) {
2666 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2667 " op %d epfd %d vec %u\n",
2668 port_id, qid, op, epfd, vec);
2675 const struct rte_memzone *
2676 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2677 uint16_t queue_id, size_t size, unsigned align,
2680 char z_name[RTE_MEMZONE_NAMESIZE];
2681 const struct rte_memzone *mz;
2683 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2684 dev->data->drv_name, ring_name,
2685 dev->data->port_id, queue_id);
2687 mz = rte_memzone_lookup(z_name);
2691 if (rte_xen_dom0_supported())
2692 return rte_memzone_reserve_bounded(z_name, size, socket_id,
2693 0, align, RTE_PGSIZE_2M);
2695 return rte_memzone_reserve_aligned(z_name, size, socket_id,
2700 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
2701 int epfd, int op, void *data)
2704 struct rte_eth_dev *dev;
2705 struct rte_intr_handle *intr_handle;
2708 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2710 dev = &rte_eth_devices[port_id];
2711 if (queue_id >= dev->data->nb_rx_queues) {
2712 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
2716 if (!dev->intr_handle) {
2717 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
2721 intr_handle = dev->intr_handle;
2722 if (!intr_handle->intr_vec) {
2723 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2727 vec = intr_handle->intr_vec[queue_id];
2728 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2729 if (rc && rc != -EEXIST) {
2730 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2731 " op %d epfd %d vec %u\n",
2732 port_id, queue_id, op, epfd, vec);
2740 rte_eth_dev_rx_intr_enable(uint8_t port_id,
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->rx_queue_intr_enable, -ENOTSUP);
2750 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
2754 rte_eth_dev_rx_intr_disable(uint8_t port_id,
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->rx_queue_intr_disable, -ENOTSUP);
2764 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
2767 #ifdef RTE_NIC_BYPASS
2768 int rte_eth_dev_bypass_init(uint8_t port_id)
2770 struct rte_eth_dev *dev;
2772 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2774 dev = &rte_eth_devices[port_id];
2775 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2776 (*dev->dev_ops->bypass_init)(dev);
2781 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2783 struct rte_eth_dev *dev;
2785 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2787 dev = &rte_eth_devices[port_id];
2788 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2789 (*dev->dev_ops->bypass_state_show)(dev, state);
2794 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2796 struct rte_eth_dev *dev;
2798 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2800 dev = &rte_eth_devices[port_id];
2801 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2802 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2807 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2809 struct rte_eth_dev *dev;
2811 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2813 dev = &rte_eth_devices[port_id];
2814 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2815 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2820 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2822 struct rte_eth_dev *dev;
2824 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2826 dev = &rte_eth_devices[port_id];
2828 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2829 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2834 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2836 struct rte_eth_dev *dev;
2838 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2840 dev = &rte_eth_devices[port_id];
2842 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2843 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2848 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2850 struct rte_eth_dev *dev;
2852 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2854 dev = &rte_eth_devices[port_id];
2856 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2857 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2862 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2864 struct rte_eth_dev *dev;
2866 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2868 dev = &rte_eth_devices[port_id];
2870 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2871 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2876 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2878 struct rte_eth_dev *dev;
2880 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2882 dev = &rte_eth_devices[port_id];
2884 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2885 (*dev->dev_ops->bypass_wd_reset)(dev);
2891 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
2893 struct rte_eth_dev *dev;
2895 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2897 dev = &rte_eth_devices[port_id];
2898 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2899 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
2900 RTE_ETH_FILTER_NOP, NULL);
2904 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
2905 enum rte_filter_op filter_op, void *arg)
2907 struct rte_eth_dev *dev;
2909 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2911 dev = &rte_eth_devices[port_id];
2912 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2913 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
2917 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
2918 rte_rx_callback_fn fn, void *user_param)
2920 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2921 rte_errno = ENOTSUP;
2924 /* check input parameters */
2925 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2926 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2930 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2938 cb->param = user_param;
2940 rte_spinlock_lock(&rte_eth_rx_cb_lock);
2941 /* Add the callbacks in fifo order. */
2942 struct rte_eth_rxtx_callback *tail =
2943 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2946 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2953 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
2959 rte_eth_add_first_rx_callback(uint8_t port_id, uint16_t queue_id,
2960 rte_rx_callback_fn fn, void *user_param)
2962 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2963 rte_errno = ENOTSUP;
2966 /* check input parameters */
2967 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2968 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2973 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2981 cb->param = user_param;
2983 rte_spinlock_lock(&rte_eth_rx_cb_lock);
2984 /* Add the callbacks at fisrt position*/
2985 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2987 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2988 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
2994 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
2995 rte_tx_callback_fn fn, void *user_param)
2997 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2998 rte_errno = ENOTSUP;
3001 /* check input parameters */
3002 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3003 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3008 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3016 cb->param = user_param;
3018 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3019 /* Add the callbacks in fifo order. */
3020 struct rte_eth_rxtx_callback *tail =
3021 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3024 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3031 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3037 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3038 struct rte_eth_rxtx_callback *user_cb)
3040 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3043 /* Check input parameters. */
3044 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3045 if (user_cb == NULL ||
3046 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
3049 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3050 struct rte_eth_rxtx_callback *cb;
3051 struct rte_eth_rxtx_callback **prev_cb;
3054 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3055 prev_cb = &dev->post_rx_burst_cbs[queue_id];
3056 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3058 if (cb == user_cb) {
3059 /* Remove the user cb from the callback list. */
3060 *prev_cb = cb->next;
3065 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3071 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3072 struct rte_eth_rxtx_callback *user_cb)
3074 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3077 /* Check input parameters. */
3078 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3079 if (user_cb == NULL ||
3080 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
3083 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3085 struct rte_eth_rxtx_callback *cb;
3086 struct rte_eth_rxtx_callback **prev_cb;
3088 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3089 prev_cb = &dev->pre_tx_burst_cbs[queue_id];
3090 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3092 if (cb == user_cb) {
3093 /* Remove the user cb from the callback list. */
3094 *prev_cb = cb->next;
3099 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3105 rte_eth_rx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3106 struct rte_eth_rxq_info *qinfo)
3108 struct rte_eth_dev *dev;
3110 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3115 dev = &rte_eth_devices[port_id];
3116 if (queue_id >= dev->data->nb_rx_queues) {
3117 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3121 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3123 memset(qinfo, 0, sizeof(*qinfo));
3124 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3129 rte_eth_tx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3130 struct rte_eth_txq_info *qinfo)
3132 struct rte_eth_dev *dev;
3134 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3139 dev = &rte_eth_devices[port_id];
3140 if (queue_id >= dev->data->nb_tx_queues) {
3141 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3145 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3147 memset(qinfo, 0, sizeof(*qinfo));
3148 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3153 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3154 struct ether_addr *mc_addr_set,
3155 uint32_t nb_mc_addr)
3157 struct rte_eth_dev *dev;
3159 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3161 dev = &rte_eth_devices[port_id];
3162 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3163 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3167 rte_eth_timesync_enable(uint8_t port_id)
3169 struct rte_eth_dev *dev;
3171 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3172 dev = &rte_eth_devices[port_id];
3174 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3175 return (*dev->dev_ops->timesync_enable)(dev);
3179 rte_eth_timesync_disable(uint8_t port_id)
3181 struct rte_eth_dev *dev;
3183 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3184 dev = &rte_eth_devices[port_id];
3186 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3187 return (*dev->dev_ops->timesync_disable)(dev);
3191 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3194 struct rte_eth_dev *dev;
3196 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3197 dev = &rte_eth_devices[port_id];
3199 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3200 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3204 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3206 struct rte_eth_dev *dev;
3208 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3209 dev = &rte_eth_devices[port_id];
3211 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3212 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3216 rte_eth_timesync_adjust_time(uint8_t port_id, int64_t delta)
3218 struct rte_eth_dev *dev;
3220 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3221 dev = &rte_eth_devices[port_id];
3223 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3224 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3228 rte_eth_timesync_read_time(uint8_t port_id, struct timespec *timestamp)
3230 struct rte_eth_dev *dev;
3232 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3233 dev = &rte_eth_devices[port_id];
3235 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3236 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3240 rte_eth_timesync_write_time(uint8_t port_id, const struct timespec *timestamp)
3242 struct rte_eth_dev *dev;
3244 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3245 dev = &rte_eth_devices[port_id];
3247 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3248 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3252 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3254 struct rte_eth_dev *dev;
3256 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3258 dev = &rte_eth_devices[port_id];
3259 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3260 return (*dev->dev_ops->get_reg)(dev, info);
3264 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3266 struct rte_eth_dev *dev;
3268 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3270 dev = &rte_eth_devices[port_id];
3271 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3272 return (*dev->dev_ops->get_eeprom_length)(dev);
3276 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3278 struct rte_eth_dev *dev;
3280 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3282 dev = &rte_eth_devices[port_id];
3283 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3284 return (*dev->dev_ops->get_eeprom)(dev, info);
3288 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3290 struct rte_eth_dev *dev;
3292 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3294 dev = &rte_eth_devices[port_id];
3295 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3296 return (*dev->dev_ops->set_eeprom)(dev, info);
3300 rte_eth_dev_get_dcb_info(uint8_t port_id,
3301 struct rte_eth_dcb_info *dcb_info)
3303 struct rte_eth_dev *dev;
3305 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3307 dev = &rte_eth_devices[port_id];
3308 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3310 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3311 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3315 rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_dev)
3317 if ((eth_dev == NULL) || (pci_dev == NULL)) {
3318 RTE_PMD_DEBUG_TRACE("NULL pointer eth_dev=%p pci_dev=%p\n",
3323 eth_dev->intr_handle = &pci_dev->intr_handle;
3325 eth_dev->data->dev_flags = 0;
3326 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
3327 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
3329 eth_dev->data->kdrv = pci_dev->kdrv;
3330 eth_dev->data->numa_node = pci_dev->device.numa_node;
3331 eth_dev->data->drv_name = pci_dev->driver->driver.name;
3335 rte_eth_dev_l2_tunnel_eth_type_conf(uint8_t port_id,
3336 struct rte_eth_l2_tunnel_conf *l2_tunnel)
3338 struct rte_eth_dev *dev;
3340 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3341 if (l2_tunnel == NULL) {
3342 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3346 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3347 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
3351 dev = &rte_eth_devices[port_id];
3352 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
3354 return (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev, l2_tunnel);
3358 rte_eth_dev_l2_tunnel_offload_set(uint8_t port_id,
3359 struct rte_eth_l2_tunnel_conf *l2_tunnel,
3363 struct rte_eth_dev *dev;
3365 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3367 if (l2_tunnel == NULL) {
3368 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3372 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3373 RTE_PMD_DEBUG_TRACE("Invalid tunnel type.\n");
3378 RTE_PMD_DEBUG_TRACE("Mask should have a value.\n");
3382 dev = &rte_eth_devices[port_id];
3383 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
3385 return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);