4 * Copyright(c) 2010-2017 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 void *ret_param; /**< Return parameter */
133 enum rte_eth_event_type event; /**< Interrupt event type */
134 uint32_t active; /**< Callback is executing */
143 rte_eth_find_next(uint8_t port_id)
145 while (port_id < RTE_MAX_ETHPORTS &&
146 rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED)
149 if (port_id >= RTE_MAX_ETHPORTS)
150 return RTE_MAX_ETHPORTS;
156 rte_eth_dev_data_alloc(void)
158 const unsigned flags = 0;
159 const struct rte_memzone *mz;
161 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
162 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
163 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
164 rte_socket_id(), flags);
166 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
168 rte_panic("Cannot allocate memzone for ethernet port data\n");
170 rte_eth_dev_data = mz->addr;
171 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
172 memset(rte_eth_dev_data, 0,
173 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
177 rte_eth_dev_allocated(const char *name)
181 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
182 if (rte_eth_devices[i].state == RTE_ETH_DEV_ATTACHED &&
183 rte_eth_devices[i].device) {
184 if (!strcmp(rte_eth_devices[i].device->name, name))
185 return &rte_eth_devices[i];
192 rte_eth_dev_find_free_port(void)
196 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
197 if (rte_eth_devices[i].state == RTE_ETH_DEV_UNUSED)
200 return RTE_MAX_ETHPORTS;
203 static struct rte_eth_dev *
204 eth_dev_get(uint8_t port_id)
206 struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
208 eth_dev->data = &rte_eth_dev_data[port_id];
209 eth_dev->state = RTE_ETH_DEV_ATTACHED;
210 TAILQ_INIT(&(eth_dev->link_intr_cbs));
212 eth_dev_last_created_port = port_id;
219 rte_eth_dev_allocate(const char *name)
222 struct rte_eth_dev *eth_dev;
224 port_id = rte_eth_dev_find_free_port();
225 if (port_id == RTE_MAX_ETHPORTS) {
226 RTE_PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
230 if (rte_eth_dev_data == NULL)
231 rte_eth_dev_data_alloc();
233 if (rte_eth_dev_allocated(name) != NULL) {
234 RTE_PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n",
239 memset(&rte_eth_dev_data[port_id], 0, sizeof(struct rte_eth_dev_data));
240 eth_dev = eth_dev_get(port_id);
241 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
242 eth_dev->data->port_id = port_id;
243 eth_dev->data->mtu = ETHER_MTU;
249 * Attach to a port already registered by the primary process, which
250 * makes sure that the same device would have the same port id both
251 * in the primary and secondary process.
254 rte_eth_dev_attach_secondary(const char *name)
257 struct rte_eth_dev *eth_dev;
259 if (rte_eth_dev_data == NULL)
260 rte_eth_dev_data_alloc();
262 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
263 if (strcmp(rte_eth_dev_data[i].name, name) == 0)
266 if (i == RTE_MAX_ETHPORTS) {
268 "device %s is not driven by the primary process\n",
273 eth_dev = eth_dev_get(i);
274 RTE_ASSERT(eth_dev->data->port_id == i);
280 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
285 eth_dev->state = RTE_ETH_DEV_UNUSED;
291 rte_eth_dev_is_valid_port(uint8_t port_id)
293 if (port_id >= RTE_MAX_ETHPORTS ||
294 (rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
295 rte_eth_devices[port_id].state != RTE_ETH_DEV_DEFERRED))
302 rte_eth_dev_socket_id(uint8_t port_id)
304 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
305 return rte_eth_devices[port_id].data->numa_node;
309 rte_eth_dev_count(void)
315 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
319 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
322 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
326 /* shouldn't check 'rte_eth_devices[i].data',
327 * because it might be overwritten by VDEV PMD */
328 tmp = rte_eth_devices[port_id].device->name;
334 rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
340 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
347 RTE_ETH_FOREACH_DEV(i) {
348 if (!rte_eth_devices[i].device)
351 ret = strncmp(name, rte_eth_devices[i].device->name,
362 rte_eth_dev_is_detachable(uint8_t port_id)
366 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
368 switch (rte_eth_devices[port_id].data->kdrv) {
369 case RTE_KDRV_IGB_UIO:
370 case RTE_KDRV_UIO_GENERIC:
371 case RTE_KDRV_NIC_UIO:
378 dev_flags = rte_eth_devices[port_id].data->dev_flags;
379 if ((dev_flags & RTE_ETH_DEV_DETACHABLE) &&
380 (!(dev_flags & RTE_ETH_DEV_BONDED_SLAVE)))
386 /* attach the new device, then store port_id of the device */
388 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
391 int current = rte_eth_dev_count();
395 if ((devargs == NULL) || (port_id == NULL)) {
400 /* parse devargs, then retrieve device name and args */
401 if (rte_eal_parse_devargs_str(devargs, &name, &args))
404 ret = rte_eal_dev_attach(name, args);
408 /* no point looking at the port count if no port exists */
409 if (!rte_eth_dev_count()) {
410 RTE_LOG(ERR, EAL, "No port found for device (%s)\n", name);
415 /* if nothing happened, there is a bug here, since some driver told us
416 * it did attach a device, but did not create a port.
418 if (current == rte_eth_dev_count()) {
423 *port_id = eth_dev_last_created_port;
432 /* detach the device, then store the name of the device */
434 rte_eth_dev_detach(uint8_t port_id, char *name)
443 /* FIXME: move this to eal, once device flags are relocated there */
444 if (rte_eth_dev_is_detachable(port_id))
447 snprintf(name, sizeof(rte_eth_devices[port_id].device->name),
448 "%s", rte_eth_devices[port_id].device->name);
450 ret = rte_eal_dev_detach(rte_eth_devices[port_id].device);
461 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
463 uint16_t old_nb_queues = dev->data->nb_rx_queues;
467 if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */
468 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
469 sizeof(dev->data->rx_queues[0]) * nb_queues,
470 RTE_CACHE_LINE_SIZE);
471 if (dev->data->rx_queues == NULL) {
472 dev->data->nb_rx_queues = 0;
475 } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */
476 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
478 rxq = dev->data->rx_queues;
480 for (i = nb_queues; i < old_nb_queues; i++)
481 (*dev->dev_ops->rx_queue_release)(rxq[i]);
482 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
483 RTE_CACHE_LINE_SIZE);
486 if (nb_queues > old_nb_queues) {
487 uint16_t new_qs = nb_queues - old_nb_queues;
489 memset(rxq + old_nb_queues, 0,
490 sizeof(rxq[0]) * new_qs);
493 dev->data->rx_queues = rxq;
495 } else if (dev->data->rx_queues != NULL && nb_queues == 0) {
496 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
498 rxq = dev->data->rx_queues;
500 for (i = nb_queues; i < old_nb_queues; i++)
501 (*dev->dev_ops->rx_queue_release)(rxq[i]);
503 rte_free(dev->data->rx_queues);
504 dev->data->rx_queues = NULL;
506 dev->data->nb_rx_queues = nb_queues;
511 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
513 struct rte_eth_dev *dev;
515 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
517 dev = &rte_eth_devices[port_id];
518 if (rx_queue_id >= dev->data->nb_rx_queues) {
519 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
523 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
525 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
526 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
527 " already started\n",
528 rx_queue_id, port_id);
532 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
537 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
539 struct rte_eth_dev *dev;
541 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
543 dev = &rte_eth_devices[port_id];
544 if (rx_queue_id >= dev->data->nb_rx_queues) {
545 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
549 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
551 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
552 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
553 " already stopped\n",
554 rx_queue_id, port_id);
558 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
563 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
565 struct rte_eth_dev *dev;
567 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
569 dev = &rte_eth_devices[port_id];
570 if (tx_queue_id >= dev->data->nb_tx_queues) {
571 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
575 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
577 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
578 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
579 " already started\n",
580 tx_queue_id, port_id);
584 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
589 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
591 struct rte_eth_dev *dev;
593 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
595 dev = &rte_eth_devices[port_id];
596 if (tx_queue_id >= dev->data->nb_tx_queues) {
597 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
601 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
603 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
604 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
605 " already stopped\n",
606 tx_queue_id, port_id);
610 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
615 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
617 uint16_t old_nb_queues = dev->data->nb_tx_queues;
621 if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */
622 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
623 sizeof(dev->data->tx_queues[0]) * nb_queues,
624 RTE_CACHE_LINE_SIZE);
625 if (dev->data->tx_queues == NULL) {
626 dev->data->nb_tx_queues = 0;
629 } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */
630 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
632 txq = dev->data->tx_queues;
634 for (i = nb_queues; i < old_nb_queues; i++)
635 (*dev->dev_ops->tx_queue_release)(txq[i]);
636 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
637 RTE_CACHE_LINE_SIZE);
640 if (nb_queues > old_nb_queues) {
641 uint16_t new_qs = nb_queues - old_nb_queues;
643 memset(txq + old_nb_queues, 0,
644 sizeof(txq[0]) * new_qs);
647 dev->data->tx_queues = txq;
649 } else if (dev->data->tx_queues != NULL && nb_queues == 0) {
650 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
652 txq = dev->data->tx_queues;
654 for (i = nb_queues; i < old_nb_queues; i++)
655 (*dev->dev_ops->tx_queue_release)(txq[i]);
657 rte_free(dev->data->tx_queues);
658 dev->data->tx_queues = NULL;
660 dev->data->nb_tx_queues = nb_queues;
665 rte_eth_speed_bitflag(uint32_t speed, int duplex)
668 case ETH_SPEED_NUM_10M:
669 return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD;
670 case ETH_SPEED_NUM_100M:
671 return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD;
672 case ETH_SPEED_NUM_1G:
673 return ETH_LINK_SPEED_1G;
674 case ETH_SPEED_NUM_2_5G:
675 return ETH_LINK_SPEED_2_5G;
676 case ETH_SPEED_NUM_5G:
677 return ETH_LINK_SPEED_5G;
678 case ETH_SPEED_NUM_10G:
679 return ETH_LINK_SPEED_10G;
680 case ETH_SPEED_NUM_20G:
681 return ETH_LINK_SPEED_20G;
682 case ETH_SPEED_NUM_25G:
683 return ETH_LINK_SPEED_25G;
684 case ETH_SPEED_NUM_40G:
685 return ETH_LINK_SPEED_40G;
686 case ETH_SPEED_NUM_50G:
687 return ETH_LINK_SPEED_50G;
688 case ETH_SPEED_NUM_56G:
689 return ETH_LINK_SPEED_56G;
690 case ETH_SPEED_NUM_100G:
691 return ETH_LINK_SPEED_100G;
698 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
699 const struct rte_eth_conf *dev_conf)
701 struct rte_eth_dev *dev;
702 struct rte_eth_dev_info dev_info;
705 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
707 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
709 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
710 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
714 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
716 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
717 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
721 dev = &rte_eth_devices[port_id];
723 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
724 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
726 if (dev->data->dev_started) {
728 "port %d must be stopped to allow configuration\n", port_id);
732 /* Copy the dev_conf parameter into the dev structure */
733 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
736 * Check that the numbers of RX and TX queues are not greater
737 * than the maximum number of RX and TX queues supported by the
740 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
742 if (nb_rx_q == 0 && nb_tx_q == 0) {
743 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d both rx and tx queue cannot be 0\n", port_id);
747 if (nb_rx_q > dev_info.max_rx_queues) {
748 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
749 port_id, nb_rx_q, dev_info.max_rx_queues);
753 if (nb_tx_q > dev_info.max_tx_queues) {
754 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
755 port_id, nb_tx_q, dev_info.max_tx_queues);
759 /* Check that the device supports requested interrupts */
760 if ((dev_conf->intr_conf.lsc == 1) &&
761 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
762 RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
763 dev->device->driver->name);
766 if ((dev_conf->intr_conf.rmv == 1) &&
767 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_RMV))) {
768 RTE_PMD_DEBUG_TRACE("driver %s does not support rmv\n",
769 dev->device->driver->name);
774 * If jumbo frames are enabled, check that the maximum RX packet
775 * length is supported by the configured device.
777 if (dev_conf->rxmode.jumbo_frame == 1) {
778 if (dev_conf->rxmode.max_rx_pkt_len >
779 dev_info.max_rx_pktlen) {
780 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
781 " > max valid value %u\n",
783 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
784 (unsigned)dev_info.max_rx_pktlen);
786 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
787 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
788 " < min valid value %u\n",
790 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
791 (unsigned)ETHER_MIN_LEN);
795 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
796 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
797 /* Use default value */
798 dev->data->dev_conf.rxmode.max_rx_pkt_len =
803 * Setup new number of RX/TX queues and reconfigure device.
805 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
807 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
812 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
814 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
816 rte_eth_dev_rx_queue_config(dev, 0);
820 diag = (*dev->dev_ops->dev_configure)(dev);
822 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
824 rte_eth_dev_rx_queue_config(dev, 0);
825 rte_eth_dev_tx_queue_config(dev, 0);
833 _rte_eth_dev_reset(struct rte_eth_dev *dev)
835 if (dev->data->dev_started) {
837 "port %d must be stopped to allow reset\n",
842 rte_eth_dev_rx_queue_config(dev, 0);
843 rte_eth_dev_tx_queue_config(dev, 0);
845 memset(&dev->data->dev_conf, 0, sizeof(dev->data->dev_conf));
849 rte_eth_dev_config_restore(uint8_t port_id)
851 struct rte_eth_dev *dev;
852 struct rte_eth_dev_info dev_info;
853 struct ether_addr *addr;
858 dev = &rte_eth_devices[port_id];
860 rte_eth_dev_info_get(port_id, &dev_info);
862 /* replay MAC address configuration including default MAC */
863 addr = &dev->data->mac_addrs[0];
864 if (*dev->dev_ops->mac_addr_set != NULL)
865 (*dev->dev_ops->mac_addr_set)(dev, addr);
866 else if (*dev->dev_ops->mac_addr_add != NULL)
867 (*dev->dev_ops->mac_addr_add)(dev, addr, 0, pool);
869 if (*dev->dev_ops->mac_addr_add != NULL) {
870 for (i = 1; i < dev_info.max_mac_addrs; i++) {
871 addr = &dev->data->mac_addrs[i];
873 /* skip zero address */
874 if (is_zero_ether_addr(addr))
878 pool_mask = dev->data->mac_pool_sel[i];
881 if (pool_mask & 1ULL)
882 (*dev->dev_ops->mac_addr_add)(dev,
890 /* replay promiscuous configuration */
891 if (rte_eth_promiscuous_get(port_id) == 1)
892 rte_eth_promiscuous_enable(port_id);
893 else if (rte_eth_promiscuous_get(port_id) == 0)
894 rte_eth_promiscuous_disable(port_id);
896 /* replay all multicast configuration */
897 if (rte_eth_allmulticast_get(port_id) == 1)
898 rte_eth_allmulticast_enable(port_id);
899 else if (rte_eth_allmulticast_get(port_id) == 0)
900 rte_eth_allmulticast_disable(port_id);
904 rte_eth_dev_start(uint8_t port_id)
906 struct rte_eth_dev *dev;
909 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
911 dev = &rte_eth_devices[port_id];
913 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
915 if (dev->data->dev_started != 0) {
916 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
917 " already started\n",
922 diag = (*dev->dev_ops->dev_start)(dev);
924 dev->data->dev_started = 1;
928 rte_eth_dev_config_restore(port_id);
930 if (dev->data->dev_conf.intr_conf.lsc == 0) {
931 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
932 (*dev->dev_ops->link_update)(dev, 0);
938 rte_eth_dev_stop(uint8_t port_id)
940 struct rte_eth_dev *dev;
942 RTE_ETH_VALID_PORTID_OR_RET(port_id);
943 dev = &rte_eth_devices[port_id];
945 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
947 if (dev->data->dev_started == 0) {
948 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
949 " already stopped\n",
954 dev->data->dev_started = 0;
955 (*dev->dev_ops->dev_stop)(dev);
959 rte_eth_dev_set_link_up(uint8_t port_id)
961 struct rte_eth_dev *dev;
963 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
965 dev = &rte_eth_devices[port_id];
967 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
968 return (*dev->dev_ops->dev_set_link_up)(dev);
972 rte_eth_dev_set_link_down(uint8_t port_id)
974 struct rte_eth_dev *dev;
976 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
978 dev = &rte_eth_devices[port_id];
980 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
981 return (*dev->dev_ops->dev_set_link_down)(dev);
985 rte_eth_dev_close(uint8_t port_id)
987 struct rte_eth_dev *dev;
989 RTE_ETH_VALID_PORTID_OR_RET(port_id);
990 dev = &rte_eth_devices[port_id];
992 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
993 dev->data->dev_started = 0;
994 (*dev->dev_ops->dev_close)(dev);
996 dev->data->nb_rx_queues = 0;
997 rte_free(dev->data->rx_queues);
998 dev->data->rx_queues = NULL;
999 dev->data->nb_tx_queues = 0;
1000 rte_free(dev->data->tx_queues);
1001 dev->data->tx_queues = NULL;
1005 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1006 uint16_t nb_rx_desc, unsigned int socket_id,
1007 const struct rte_eth_rxconf *rx_conf,
1008 struct rte_mempool *mp)
1011 uint32_t mbp_buf_size;
1012 struct rte_eth_dev *dev;
1013 struct rte_eth_dev_info dev_info;
1016 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1018 dev = &rte_eth_devices[port_id];
1019 if (rx_queue_id >= dev->data->nb_rx_queues) {
1020 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1024 if (dev->data->dev_started) {
1025 RTE_PMD_DEBUG_TRACE(
1026 "port %d must be stopped to allow configuration\n", port_id);
1030 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1031 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1034 * Check the size of the mbuf data buffer.
1035 * This value must be provided in the private data of the memory pool.
1036 * First check that the memory pool has a valid private data.
1038 rte_eth_dev_info_get(port_id, &dev_info);
1039 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1040 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1041 mp->name, (int) mp->private_data_size,
1042 (int) sizeof(struct rte_pktmbuf_pool_private));
1045 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1047 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1048 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1049 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1053 (int)(RTE_PKTMBUF_HEADROOM +
1054 dev_info.min_rx_bufsize),
1055 (int)RTE_PKTMBUF_HEADROOM,
1056 (int)dev_info.min_rx_bufsize);
1060 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1061 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1062 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1064 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1065 "should be: <= %hu, = %hu, and a product of %hu\n",
1067 dev_info.rx_desc_lim.nb_max,
1068 dev_info.rx_desc_lim.nb_min,
1069 dev_info.rx_desc_lim.nb_align);
1073 rxq = dev->data->rx_queues;
1074 if (rxq[rx_queue_id]) {
1075 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release,
1077 (*dev->dev_ops->rx_queue_release)(rxq[rx_queue_id]);
1078 rxq[rx_queue_id] = NULL;
1081 if (rx_conf == NULL)
1082 rx_conf = &dev_info.default_rxconf;
1084 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1085 socket_id, rx_conf, mp);
1087 if (!dev->data->min_rx_buf_size ||
1088 dev->data->min_rx_buf_size > mbp_buf_size)
1089 dev->data->min_rx_buf_size = mbp_buf_size;
1096 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1097 uint16_t nb_tx_desc, unsigned int socket_id,
1098 const struct rte_eth_txconf *tx_conf)
1100 struct rte_eth_dev *dev;
1101 struct rte_eth_dev_info dev_info;
1104 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1106 dev = &rte_eth_devices[port_id];
1107 if (tx_queue_id >= dev->data->nb_tx_queues) {
1108 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1112 if (dev->data->dev_started) {
1113 RTE_PMD_DEBUG_TRACE(
1114 "port %d must be stopped to allow configuration\n", port_id);
1118 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1119 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1121 rte_eth_dev_info_get(port_id, &dev_info);
1123 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1124 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1125 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1126 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1127 "should be: <= %hu, = %hu, and a product of %hu\n",
1129 dev_info.tx_desc_lim.nb_max,
1130 dev_info.tx_desc_lim.nb_min,
1131 dev_info.tx_desc_lim.nb_align);
1135 txq = dev->data->tx_queues;
1136 if (txq[tx_queue_id]) {
1137 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release,
1139 (*dev->dev_ops->tx_queue_release)(txq[tx_queue_id]);
1140 txq[tx_queue_id] = NULL;
1143 if (tx_conf == NULL)
1144 tx_conf = &dev_info.default_txconf;
1146 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1147 socket_id, tx_conf);
1151 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
1152 void *userdata __rte_unused)
1156 for (i = 0; i < unsent; i++)
1157 rte_pktmbuf_free(pkts[i]);
1161 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
1164 uint64_t *count = userdata;
1167 for (i = 0; i < unsent; i++)
1168 rte_pktmbuf_free(pkts[i]);
1174 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
1175 buffer_tx_error_fn cbfn, void *userdata)
1177 buffer->error_callback = cbfn;
1178 buffer->error_userdata = userdata;
1183 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
1190 buffer->size = size;
1191 if (buffer->error_callback == NULL) {
1192 ret = rte_eth_tx_buffer_set_err_callback(
1193 buffer, rte_eth_tx_buffer_drop_callback, NULL);
1200 rte_eth_tx_done_cleanup(uint8_t port_id, uint16_t queue_id, uint32_t free_cnt)
1202 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1204 /* Validate Input Data. Bail if not valid or not supported. */
1205 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1206 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_done_cleanup, -ENOTSUP);
1208 /* Call driver to free pending mbufs. */
1209 return (*dev->dev_ops->tx_done_cleanup)(dev->data->tx_queues[queue_id],
1214 rte_eth_promiscuous_enable(uint8_t port_id)
1216 struct rte_eth_dev *dev;
1218 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1219 dev = &rte_eth_devices[port_id];
1221 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1222 (*dev->dev_ops->promiscuous_enable)(dev);
1223 dev->data->promiscuous = 1;
1227 rte_eth_promiscuous_disable(uint8_t port_id)
1229 struct rte_eth_dev *dev;
1231 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1232 dev = &rte_eth_devices[port_id];
1234 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1235 dev->data->promiscuous = 0;
1236 (*dev->dev_ops->promiscuous_disable)(dev);
1240 rte_eth_promiscuous_get(uint8_t port_id)
1242 struct rte_eth_dev *dev;
1244 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1246 dev = &rte_eth_devices[port_id];
1247 return dev->data->promiscuous;
1251 rte_eth_allmulticast_enable(uint8_t port_id)
1253 struct rte_eth_dev *dev;
1255 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1256 dev = &rte_eth_devices[port_id];
1258 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1259 (*dev->dev_ops->allmulticast_enable)(dev);
1260 dev->data->all_multicast = 1;
1264 rte_eth_allmulticast_disable(uint8_t port_id)
1266 struct rte_eth_dev *dev;
1268 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1269 dev = &rte_eth_devices[port_id];
1271 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1272 dev->data->all_multicast = 0;
1273 (*dev->dev_ops->allmulticast_disable)(dev);
1277 rte_eth_allmulticast_get(uint8_t port_id)
1279 struct rte_eth_dev *dev;
1281 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1283 dev = &rte_eth_devices[port_id];
1284 return dev->data->all_multicast;
1288 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1289 struct rte_eth_link *link)
1291 struct rte_eth_link *dst = link;
1292 struct rte_eth_link *src = &(dev->data->dev_link);
1294 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1295 *(uint64_t *)src) == 0)
1302 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1304 struct rte_eth_dev *dev;
1306 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1307 dev = &rte_eth_devices[port_id];
1309 if (dev->data->dev_conf.intr_conf.lsc != 0)
1310 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1312 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1313 (*dev->dev_ops->link_update)(dev, 1);
1314 *eth_link = dev->data->dev_link;
1319 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1321 struct rte_eth_dev *dev;
1323 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1324 dev = &rte_eth_devices[port_id];
1326 if (dev->data->dev_conf.intr_conf.lsc != 0)
1327 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1329 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1330 (*dev->dev_ops->link_update)(dev, 0);
1331 *eth_link = dev->data->dev_link;
1336 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
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 memset(stats, 0, sizeof(*stats));
1345 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1346 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1347 (*dev->dev_ops->stats_get)(dev, stats);
1352 rte_eth_stats_reset(uint8_t port_id)
1354 struct rte_eth_dev *dev;
1356 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1357 dev = &rte_eth_devices[port_id];
1359 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1360 (*dev->dev_ops->stats_reset)(dev);
1361 dev->data->rx_mbuf_alloc_failed = 0;
1365 get_xstats_count(uint8_t port_id)
1367 struct rte_eth_dev *dev;
1370 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1371 dev = &rte_eth_devices[port_id];
1372 if (dev->dev_ops->xstats_get_names_by_id != NULL) {
1373 count = (*dev->dev_ops->xstats_get_names_by_id)(dev, NULL,
1378 if (dev->dev_ops->xstats_get_names != NULL) {
1379 count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0);
1385 count += RTE_NB_STATS;
1386 count += RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
1388 count += RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
1394 rte_eth_xstats_get_id_by_name(uint8_t port_id, const char *xstat_name,
1397 int cnt_xstats, idx_xstat;
1399 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1402 RTE_PMD_DEBUG_TRACE("Error: id pointer is NULL\n");
1407 RTE_PMD_DEBUG_TRACE("Error: xstat_name pointer is NULL\n");
1412 cnt_xstats = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
1413 if (cnt_xstats < 0) {
1414 RTE_PMD_DEBUG_TRACE("Error: Cannot get count of xstats\n");
1418 /* Get id-name lookup table */
1419 struct rte_eth_xstat_name xstats_names[cnt_xstats];
1421 if (cnt_xstats != rte_eth_xstats_get_names_by_id(
1422 port_id, xstats_names, cnt_xstats, NULL)) {
1423 RTE_PMD_DEBUG_TRACE("Error: Cannot get xstats lookup\n");
1427 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
1428 if (!strcmp(xstats_names[idx_xstat].name, xstat_name)) {
1438 rte_eth_xstats_get_names_by_id(uint8_t port_id,
1439 struct rte_eth_xstat_name *xstats_names, unsigned int size,
1442 /* Get all xstats */
1444 struct rte_eth_dev *dev;
1445 int cnt_used_entries;
1446 int cnt_expected_entries;
1447 int cnt_driver_entries;
1448 uint32_t idx, id_queue;
1451 cnt_expected_entries = get_xstats_count(port_id);
1452 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1453 (int)size < cnt_expected_entries)
1454 return cnt_expected_entries;
1456 /* port_id checked in get_xstats_count() */
1457 dev = &rte_eth_devices[port_id];
1458 cnt_used_entries = 0;
1460 for (idx = 0; idx < RTE_NB_STATS; idx++) {
1461 snprintf(xstats_names[cnt_used_entries].name,
1462 sizeof(xstats_names[0].name),
1463 "%s", rte_stats_strings[idx].name);
1466 num_q = RTE_MIN(dev->data->nb_rx_queues,
1467 RTE_ETHDEV_QUEUE_STAT_CNTRS);
1468 for (id_queue = 0; id_queue < num_q; id_queue++) {
1469 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1470 snprintf(xstats_names[cnt_used_entries].name,
1471 sizeof(xstats_names[0].name),
1474 rte_rxq_stats_strings[idx].name);
1479 num_q = RTE_MIN(dev->data->nb_tx_queues,
1480 RTE_ETHDEV_QUEUE_STAT_CNTRS);
1481 for (id_queue = 0; id_queue < num_q; id_queue++) {
1482 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
1483 snprintf(xstats_names[cnt_used_entries].name,
1484 sizeof(xstats_names[0].name),
1487 rte_txq_stats_strings[idx].name);
1492 if (dev->dev_ops->xstats_get_names_by_id != NULL) {
1493 /* If there are any driver-specific xstats, append them
1496 cnt_driver_entries =
1497 (*dev->dev_ops->xstats_get_names_by_id)(
1499 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;
1506 } else if (dev->dev_ops->xstats_get_names != NULL) {
1507 /* If there are any driver-specific xstats, append them
1510 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
1512 xstats_names + cnt_used_entries,
1513 size - cnt_used_entries);
1514 if (cnt_driver_entries < 0)
1515 return cnt_driver_entries;
1516 cnt_used_entries += cnt_driver_entries;
1519 return cnt_used_entries;
1521 /* Get only xstats given by IDS */
1524 struct rte_eth_xstat_name *xstats_names_copy;
1526 len = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
1529 malloc(sizeof(struct rte_eth_xstat_name) * len);
1530 if (!xstats_names_copy) {
1531 RTE_PMD_DEBUG_TRACE(
1532 "ERROR: can't allocate memory for values_copy\n");
1533 free(xstats_names_copy);
1537 rte_eth_xstats_get_names_by_id(port_id, xstats_names_copy,
1540 for (i = 0; i < size; i++) {
1541 if (ids[i] >= len) {
1542 RTE_PMD_DEBUG_TRACE(
1543 "ERROR: id value isn't valid\n");
1546 strcpy(xstats_names[i].name,
1547 xstats_names_copy[ids[i]].name);
1549 free(xstats_names_copy);
1555 rte_eth_xstats_get_names(uint8_t port_id,
1556 struct rte_eth_xstat_name *xstats_names,
1559 struct rte_eth_dev *dev;
1560 int cnt_used_entries;
1561 int cnt_expected_entries;
1562 int cnt_driver_entries;
1563 uint32_t idx, id_queue;
1566 cnt_expected_entries = get_xstats_count(port_id);
1567 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1568 (int)size < cnt_expected_entries)
1569 return cnt_expected_entries;
1571 /* port_id checked in get_xstats_count() */
1572 dev = &rte_eth_devices[port_id];
1573 cnt_used_entries = 0;
1575 for (idx = 0; idx < RTE_NB_STATS; idx++) {
1576 snprintf(xstats_names[cnt_used_entries].name,
1577 sizeof(xstats_names[0].name),
1578 "%s", rte_stats_strings[idx].name);
1581 num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1582 for (id_queue = 0; id_queue < num_q; id_queue++) {
1583 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1584 snprintf(xstats_names[cnt_used_entries].name,
1585 sizeof(xstats_names[0].name),
1587 id_queue, rte_rxq_stats_strings[idx].name);
1592 num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1593 for (id_queue = 0; id_queue < num_q; id_queue++) {
1594 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
1595 snprintf(xstats_names[cnt_used_entries].name,
1596 sizeof(xstats_names[0].name),
1598 id_queue, rte_txq_stats_strings[idx].name);
1603 if (dev->dev_ops->xstats_get_names != NULL) {
1604 /* If there are any driver-specific xstats, append them
1607 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
1609 xstats_names + cnt_used_entries,
1610 size - cnt_used_entries);
1611 if (cnt_driver_entries < 0)
1612 return cnt_driver_entries;
1613 cnt_used_entries += cnt_driver_entries;
1616 return cnt_used_entries;
1619 /* retrieve ethdev extended statistics */
1621 rte_eth_xstats_get_by_id(uint8_t port_id, const uint64_t *ids, uint64_t *values,
1624 /* If need all xstats */
1626 struct rte_eth_stats eth_stats;
1627 struct rte_eth_dev *dev;
1628 unsigned int count = 0, i, q;
1629 signed int xcount = 0;
1630 uint64_t val, *stats_ptr;
1631 uint16_t nb_rxqs, nb_txqs;
1633 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1634 dev = &rte_eth_devices[port_id];
1636 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues,
1637 RTE_ETHDEV_QUEUE_STAT_CNTRS);
1638 nb_txqs = RTE_MIN(dev->data->nb_tx_queues,
1639 RTE_ETHDEV_QUEUE_STAT_CNTRS);
1641 /* Return generic statistics */
1642 count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
1643 (nb_txqs * RTE_NB_TXQ_STATS);
1646 /* implemented by the driver */
1647 if (dev->dev_ops->xstats_get_by_id != NULL) {
1648 /* Retrieve the xstats from the driver at the end of the
1649 * xstats struct. Retrieve all xstats.
1651 xcount = (*dev->dev_ops->xstats_get_by_id)(dev,
1653 values ? values + count : NULL,
1654 (n > count) ? n - count : 0);
1658 /* implemented by the driver */
1659 } else if (dev->dev_ops->xstats_get != NULL) {
1660 /* Retrieve the xstats from the driver at the end of the
1661 * xstats struct. Retrieve all xstats.
1662 * Compatibility for PMD without xstats_get_by_ids
1664 unsigned int size = (n > count) ? n - count : 1;
1665 struct rte_eth_xstat xstats[size];
1667 xcount = (*dev->dev_ops->xstats_get)(dev,
1668 values ? xstats : NULL, size);
1674 for (i = 0 ; i < (unsigned int)xcount; i++)
1675 values[i + count] = xstats[i].value;
1678 if (n < count + xcount || values == NULL)
1679 return count + xcount;
1681 /* now fill the xstats structure */
1683 rte_eth_stats_get(port_id, ð_stats);
1686 for (i = 0; i < RTE_NB_STATS; i++) {
1687 stats_ptr = RTE_PTR_ADD(ð_stats,
1688 rte_stats_strings[i].offset);
1690 values[count++] = val;
1694 for (q = 0; q < nb_rxqs; q++) {
1695 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1696 stats_ptr = RTE_PTR_ADD(ð_stats,
1697 rte_rxq_stats_strings[i].offset +
1698 q * sizeof(uint64_t));
1700 values[count++] = val;
1705 for (q = 0; q < nb_txqs; q++) {
1706 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1707 stats_ptr = RTE_PTR_ADD(ð_stats,
1708 rte_txq_stats_strings[i].offset +
1709 q * sizeof(uint64_t));
1711 values[count++] = val;
1715 return count + xcount;
1717 /* Need only xstats given by IDS array */
1720 uint64_t *values_copy;
1722 size = rte_eth_xstats_get_by_id(port_id, NULL, NULL, 0);
1724 values_copy = malloc(sizeof(*values_copy) * size);
1726 RTE_PMD_DEBUG_TRACE(
1727 "ERROR: can't allocate memory for values_copy\n");
1731 rte_eth_xstats_get_by_id(port_id, NULL, values_copy, size);
1733 for (i = 0; i < n; i++) {
1734 if (ids[i] >= size) {
1735 RTE_PMD_DEBUG_TRACE(
1736 "ERROR: id value isn't valid\n");
1739 values[i] = values_copy[ids[i]];
1747 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstat *xstats,
1750 struct rte_eth_stats eth_stats;
1751 struct rte_eth_dev *dev;
1752 unsigned int count = 0, i, q;
1753 signed int xcount = 0;
1754 uint64_t val, *stats_ptr;
1755 uint16_t nb_rxqs, nb_txqs;
1757 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1759 dev = &rte_eth_devices[port_id];
1761 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1762 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1764 /* Return generic statistics */
1765 count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
1766 (nb_txqs * RTE_NB_TXQ_STATS);
1768 /* implemented by the driver */
1769 if (dev->dev_ops->xstats_get != NULL) {
1770 /* Retrieve the xstats from the driver at the end of the
1773 xcount = (*dev->dev_ops->xstats_get)(dev,
1774 xstats ? xstats + count : NULL,
1775 (n > count) ? n - count : 0);
1781 if (n < count + xcount || xstats == NULL)
1782 return count + xcount;
1784 /* now fill the xstats structure */
1786 rte_eth_stats_get(port_id, ð_stats);
1789 for (i = 0; i < RTE_NB_STATS; i++) {
1790 stats_ptr = RTE_PTR_ADD(ð_stats,
1791 rte_stats_strings[i].offset);
1793 xstats[count++].value = val;
1797 for (q = 0; q < nb_rxqs; q++) {
1798 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1799 stats_ptr = RTE_PTR_ADD(ð_stats,
1800 rte_rxq_stats_strings[i].offset +
1801 q * sizeof(uint64_t));
1803 xstats[count++].value = val;
1808 for (q = 0; q < nb_txqs; q++) {
1809 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1810 stats_ptr = RTE_PTR_ADD(ð_stats,
1811 rte_txq_stats_strings[i].offset +
1812 q * sizeof(uint64_t));
1814 xstats[count++].value = val;
1818 for (i = 0; i < count; i++)
1820 /* add an offset to driver-specific stats */
1821 for ( ; i < count + xcount; i++)
1822 xstats[i].id += count;
1824 return count + xcount;
1827 /* reset ethdev extended statistics */
1829 rte_eth_xstats_reset(uint8_t port_id)
1831 struct rte_eth_dev *dev;
1833 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1834 dev = &rte_eth_devices[port_id];
1836 /* implemented by the driver */
1837 if (dev->dev_ops->xstats_reset != NULL) {
1838 (*dev->dev_ops->xstats_reset)(dev);
1842 /* fallback to default */
1843 rte_eth_stats_reset(port_id);
1847 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1850 struct rte_eth_dev *dev;
1852 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1854 dev = &rte_eth_devices[port_id];
1856 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1857 return (*dev->dev_ops->queue_stats_mapping_set)
1858 (dev, queue_id, stat_idx, is_rx);
1863 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1866 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1872 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1875 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1880 rte_eth_dev_fw_version_get(uint8_t port_id, char *fw_version, size_t fw_size)
1882 struct rte_eth_dev *dev;
1884 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1885 dev = &rte_eth_devices[port_id];
1887 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP);
1888 return (*dev->dev_ops->fw_version_get)(dev, fw_version, fw_size);
1892 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1894 struct rte_eth_dev *dev;
1895 const struct rte_eth_desc_lim lim = {
1896 .nb_max = UINT16_MAX,
1901 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1902 dev = &rte_eth_devices[port_id];
1904 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1905 dev_info->rx_desc_lim = lim;
1906 dev_info->tx_desc_lim = lim;
1908 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1909 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1910 dev_info->driver_name = dev->device->driver->name;
1911 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
1912 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
1916 rte_eth_dev_get_supported_ptypes(uint8_t port_id, uint32_t ptype_mask,
1917 uint32_t *ptypes, int num)
1920 struct rte_eth_dev *dev;
1921 const uint32_t *all_ptypes;
1923 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1924 dev = &rte_eth_devices[port_id];
1925 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
1926 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
1931 for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
1932 if (all_ptypes[i] & ptype_mask) {
1934 ptypes[j] = all_ptypes[i];
1942 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1944 struct rte_eth_dev *dev;
1946 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1947 dev = &rte_eth_devices[port_id];
1948 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1953 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1955 struct rte_eth_dev *dev;
1957 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1959 dev = &rte_eth_devices[port_id];
1960 *mtu = dev->data->mtu;
1965 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1968 struct rte_eth_dev *dev;
1970 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1971 dev = &rte_eth_devices[port_id];
1972 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1974 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1976 dev->data->mtu = mtu;
1982 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1984 struct rte_eth_dev *dev;
1987 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1988 dev = &rte_eth_devices[port_id];
1989 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1990 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1994 if (vlan_id > 4095) {
1995 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1996 port_id, (unsigned) vlan_id);
1999 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
2001 ret = (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
2003 struct rte_vlan_filter_conf *vfc;
2007 vfc = &dev->data->vlan_filter_conf;
2008 vidx = vlan_id / 64;
2009 vbit = vlan_id % 64;
2012 vfc->ids[vidx] |= UINT64_C(1) << vbit;
2014 vfc->ids[vidx] &= ~(UINT64_C(1) << vbit);
2021 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
2023 struct rte_eth_dev *dev;
2025 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2026 dev = &rte_eth_devices[port_id];
2027 if (rx_queue_id >= dev->data->nb_rx_queues) {
2028 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
2032 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
2033 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
2039 rte_eth_dev_set_vlan_ether_type(uint8_t port_id,
2040 enum rte_vlan_type vlan_type,
2043 struct rte_eth_dev *dev;
2045 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2046 dev = &rte_eth_devices[port_id];
2047 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
2049 return (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type, tpid);
2053 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
2055 struct rte_eth_dev *dev;
2060 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2061 dev = &rte_eth_devices[port_id];
2063 /*check which option changed by application*/
2064 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
2065 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
2067 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
2068 mask |= ETH_VLAN_STRIP_MASK;
2071 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
2072 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
2074 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
2075 mask |= ETH_VLAN_FILTER_MASK;
2078 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
2079 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
2081 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
2082 mask |= ETH_VLAN_EXTEND_MASK;
2089 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
2090 (*dev->dev_ops->vlan_offload_set)(dev, mask);
2096 rte_eth_dev_get_vlan_offload(uint8_t port_id)
2098 struct rte_eth_dev *dev;
2101 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2102 dev = &rte_eth_devices[port_id];
2104 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
2105 ret |= ETH_VLAN_STRIP_OFFLOAD;
2107 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
2108 ret |= ETH_VLAN_FILTER_OFFLOAD;
2110 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
2111 ret |= ETH_VLAN_EXTEND_OFFLOAD;
2117 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
2119 struct rte_eth_dev *dev;
2121 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2122 dev = &rte_eth_devices[port_id];
2123 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
2124 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
2130 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2132 struct rte_eth_dev *dev;
2134 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2135 dev = &rte_eth_devices[port_id];
2136 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2137 memset(fc_conf, 0, sizeof(*fc_conf));
2138 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
2142 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2144 struct rte_eth_dev *dev;
2146 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2147 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2148 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2152 dev = &rte_eth_devices[port_id];
2153 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2154 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
2158 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
2160 struct rte_eth_dev *dev;
2162 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2163 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2164 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2168 dev = &rte_eth_devices[port_id];
2169 /* High water, low water validation are device specific */
2170 if (*dev->dev_ops->priority_flow_ctrl_set)
2171 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
2176 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2184 num = (reta_size + RTE_RETA_GROUP_SIZE - 1) / RTE_RETA_GROUP_SIZE;
2185 for (i = 0; i < num; i++) {
2186 if (reta_conf[i].mask)
2194 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2198 uint16_t i, idx, shift;
2204 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
2208 for (i = 0; i < reta_size; i++) {
2209 idx = i / RTE_RETA_GROUP_SIZE;
2210 shift = i % RTE_RETA_GROUP_SIZE;
2211 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2212 (reta_conf[idx].reta[shift] >= max_rxq)) {
2213 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2214 "the maximum rxq index: %u\n", idx, shift,
2215 reta_conf[idx].reta[shift], max_rxq);
2224 rte_eth_dev_rss_reta_update(uint8_t port_id,
2225 struct rte_eth_rss_reta_entry64 *reta_conf,
2228 struct rte_eth_dev *dev;
2231 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2232 /* Check mask bits */
2233 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2237 dev = &rte_eth_devices[port_id];
2239 /* Check entry value */
2240 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2241 dev->data->nb_rx_queues);
2245 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2246 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2250 rte_eth_dev_rss_reta_query(uint8_t port_id,
2251 struct rte_eth_rss_reta_entry64 *reta_conf,
2254 struct rte_eth_dev *dev;
2257 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2259 /* Check mask bits */
2260 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2264 dev = &rte_eth_devices[port_id];
2265 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2266 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2270 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2272 struct rte_eth_dev *dev;
2273 uint16_t rss_hash_protos;
2275 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2276 rss_hash_protos = rss_conf->rss_hf;
2277 if ((rss_hash_protos != 0) &&
2278 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2279 RTE_PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2283 dev = &rte_eth_devices[port_id];
2284 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2285 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2289 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2290 struct rte_eth_rss_conf *rss_conf)
2292 struct rte_eth_dev *dev;
2294 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2295 dev = &rte_eth_devices[port_id];
2296 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2297 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2301 rte_eth_dev_udp_tunnel_port_add(uint8_t port_id,
2302 struct rte_eth_udp_tunnel *udp_tunnel)
2304 struct rte_eth_dev *dev;
2306 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2307 if (udp_tunnel == NULL) {
2308 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2312 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2313 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2317 dev = &rte_eth_devices[port_id];
2318 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
2319 return (*dev->dev_ops->udp_tunnel_port_add)(dev, udp_tunnel);
2323 rte_eth_dev_udp_tunnel_port_delete(uint8_t port_id,
2324 struct rte_eth_udp_tunnel *udp_tunnel)
2326 struct rte_eth_dev *dev;
2328 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2329 dev = &rte_eth_devices[port_id];
2331 if (udp_tunnel == NULL) {
2332 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2336 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2337 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2341 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
2342 return (*dev->dev_ops->udp_tunnel_port_del)(dev, udp_tunnel);
2346 rte_eth_led_on(uint8_t port_id)
2348 struct rte_eth_dev *dev;
2350 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2351 dev = &rte_eth_devices[port_id];
2352 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2353 return (*dev->dev_ops->dev_led_on)(dev);
2357 rte_eth_led_off(uint8_t port_id)
2359 struct rte_eth_dev *dev;
2361 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2362 dev = &rte_eth_devices[port_id];
2363 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2364 return (*dev->dev_ops->dev_led_off)(dev);
2368 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2372 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2374 struct rte_eth_dev_info dev_info;
2375 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2378 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2379 rte_eth_dev_info_get(port_id, &dev_info);
2381 for (i = 0; i < dev_info.max_mac_addrs; i++)
2382 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2388 static const struct ether_addr null_mac_addr;
2391 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2394 struct rte_eth_dev *dev;
2399 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2400 dev = &rte_eth_devices[port_id];
2401 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2403 if (is_zero_ether_addr(addr)) {
2404 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2408 if (pool >= ETH_64_POOLS) {
2409 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2413 index = get_mac_addr_index(port_id, addr);
2415 index = get_mac_addr_index(port_id, &null_mac_addr);
2417 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2422 pool_mask = dev->data->mac_pool_sel[index];
2424 /* Check if both MAC address and pool is already there, and do nothing */
2425 if (pool_mask & (1ULL << pool))
2430 ret = (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2433 /* Update address in NIC data structure */
2434 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2436 /* Update pool bitmap in NIC data structure */
2437 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2444 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2446 struct rte_eth_dev *dev;
2449 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2450 dev = &rte_eth_devices[port_id];
2451 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2453 index = get_mac_addr_index(port_id, addr);
2455 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2457 } else if (index < 0)
2458 return 0; /* Do nothing if address wasn't found */
2461 (*dev->dev_ops->mac_addr_remove)(dev, index);
2463 /* Update address in NIC data structure */
2464 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2466 /* reset pool bitmap */
2467 dev->data->mac_pool_sel[index] = 0;
2473 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2475 struct rte_eth_dev *dev;
2477 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2479 if (!is_valid_assigned_ether_addr(addr))
2482 dev = &rte_eth_devices[port_id];
2483 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2485 /* Update default address in NIC data structure */
2486 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2488 (*dev->dev_ops->mac_addr_set)(dev, addr);
2495 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2499 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2501 struct rte_eth_dev_info dev_info;
2502 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2505 rte_eth_dev_info_get(port_id, &dev_info);
2506 if (!dev->data->hash_mac_addrs)
2509 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2510 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2511 ETHER_ADDR_LEN) == 0)
2518 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2523 struct rte_eth_dev *dev;
2525 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2527 dev = &rte_eth_devices[port_id];
2528 if (is_zero_ether_addr(addr)) {
2529 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2534 index = get_hash_mac_addr_index(port_id, addr);
2535 /* Check if it's already there, and do nothing */
2536 if ((index >= 0) && (on))
2541 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2542 "set in UTA\n", port_id);
2546 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2548 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2554 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2555 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2557 /* Update address in NIC data structure */
2559 ether_addr_copy(addr,
2560 &dev->data->hash_mac_addrs[index]);
2562 ether_addr_copy(&null_mac_addr,
2563 &dev->data->hash_mac_addrs[index]);
2570 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2572 struct rte_eth_dev *dev;
2574 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2576 dev = &rte_eth_devices[port_id];
2578 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2579 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2582 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2585 struct rte_eth_dev *dev;
2586 struct rte_eth_dev_info dev_info;
2587 struct rte_eth_link link;
2589 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2591 dev = &rte_eth_devices[port_id];
2592 rte_eth_dev_info_get(port_id, &dev_info);
2593 link = dev->data->dev_link;
2595 if (queue_idx > dev_info.max_tx_queues) {
2596 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2597 "invalid queue id=%d\n", port_id, queue_idx);
2601 if (tx_rate > link.link_speed) {
2602 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2603 "bigger than link speed= %d\n",
2604 tx_rate, link.link_speed);
2608 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2609 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2613 rte_eth_mirror_rule_set(uint8_t port_id,
2614 struct rte_eth_mirror_conf *mirror_conf,
2615 uint8_t rule_id, uint8_t on)
2617 struct rte_eth_dev *dev;
2619 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2620 if (mirror_conf->rule_type == 0) {
2621 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2625 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2626 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2631 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2632 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2633 (mirror_conf->pool_mask == 0)) {
2634 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2638 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2639 mirror_conf->vlan.vlan_mask == 0) {
2640 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2644 dev = &rte_eth_devices[port_id];
2645 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2647 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2651 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2653 struct rte_eth_dev *dev;
2655 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2657 dev = &rte_eth_devices[port_id];
2658 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2660 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2664 rte_eth_dev_callback_register(uint8_t port_id,
2665 enum rte_eth_event_type event,
2666 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2668 struct rte_eth_dev *dev;
2669 struct rte_eth_dev_callback *user_cb;
2674 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2676 dev = &rte_eth_devices[port_id];
2677 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2679 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2680 if (user_cb->cb_fn == cb_fn &&
2681 user_cb->cb_arg == cb_arg &&
2682 user_cb->event == event) {
2687 /* create a new callback. */
2688 if (user_cb == NULL) {
2689 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2690 sizeof(struct rte_eth_dev_callback), 0);
2691 if (user_cb != NULL) {
2692 user_cb->cb_fn = cb_fn;
2693 user_cb->cb_arg = cb_arg;
2694 user_cb->event = event;
2695 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2699 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2700 return (user_cb == NULL) ? -ENOMEM : 0;
2704 rte_eth_dev_callback_unregister(uint8_t port_id,
2705 enum rte_eth_event_type event,
2706 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2709 struct rte_eth_dev *dev;
2710 struct rte_eth_dev_callback *cb, *next;
2715 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2717 dev = &rte_eth_devices[port_id];
2718 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2721 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2723 next = TAILQ_NEXT(cb, next);
2725 if (cb->cb_fn != cb_fn || cb->event != event ||
2726 (cb->cb_arg != (void *)-1 &&
2727 cb->cb_arg != cb_arg))
2731 * if this callback is not executing right now,
2734 if (cb->active == 0) {
2735 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2742 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2747 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2748 enum rte_eth_event_type event, void *cb_arg, void *ret_param)
2750 struct rte_eth_dev_callback *cb_lst;
2751 struct rte_eth_dev_callback dev_cb;
2754 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2755 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2756 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2761 dev_cb.cb_arg = cb_arg;
2762 if (ret_param != NULL)
2763 dev_cb.ret_param = ret_param;
2765 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2766 rc = dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2767 dev_cb.cb_arg, dev_cb.ret_param);
2768 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2771 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2776 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
2779 struct rte_eth_dev *dev;
2780 struct rte_intr_handle *intr_handle;
2784 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2786 dev = &rte_eth_devices[port_id];
2788 if (!dev->intr_handle) {
2789 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
2793 intr_handle = dev->intr_handle;
2794 if (!intr_handle->intr_vec) {
2795 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2799 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2800 vec = intr_handle->intr_vec[qid];
2801 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2802 if (rc && rc != -EEXIST) {
2803 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2804 " op %d epfd %d vec %u\n",
2805 port_id, qid, op, epfd, vec);
2812 const struct rte_memzone *
2813 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2814 uint16_t queue_id, size_t size, unsigned align,
2817 char z_name[RTE_MEMZONE_NAMESIZE];
2818 const struct rte_memzone *mz;
2820 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2821 dev->device->driver->name, ring_name,
2822 dev->data->port_id, queue_id);
2824 mz = rte_memzone_lookup(z_name);
2828 if (rte_xen_dom0_supported())
2829 return rte_memzone_reserve_bounded(z_name, size, socket_id,
2830 0, align, RTE_PGSIZE_2M);
2832 return rte_memzone_reserve_aligned(z_name, size, socket_id,
2837 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
2838 int epfd, int op, void *data)
2841 struct rte_eth_dev *dev;
2842 struct rte_intr_handle *intr_handle;
2845 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2847 dev = &rte_eth_devices[port_id];
2848 if (queue_id >= dev->data->nb_rx_queues) {
2849 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
2853 if (!dev->intr_handle) {
2854 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
2858 intr_handle = dev->intr_handle;
2859 if (!intr_handle->intr_vec) {
2860 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2864 vec = intr_handle->intr_vec[queue_id];
2865 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2866 if (rc && rc != -EEXIST) {
2867 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2868 " op %d epfd %d vec %u\n",
2869 port_id, queue_id, op, epfd, vec);
2877 rte_eth_dev_rx_intr_enable(uint8_t port_id,
2880 struct rte_eth_dev *dev;
2882 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2884 dev = &rte_eth_devices[port_id];
2886 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
2887 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
2891 rte_eth_dev_rx_intr_disable(uint8_t port_id,
2894 struct rte_eth_dev *dev;
2896 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2898 dev = &rte_eth_devices[port_id];
2900 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
2901 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
2906 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
2908 struct rte_eth_dev *dev;
2910 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2912 dev = &rte_eth_devices[port_id];
2913 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2914 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
2915 RTE_ETH_FILTER_NOP, NULL);
2919 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
2920 enum rte_filter_op filter_op, void *arg)
2922 struct rte_eth_dev *dev;
2924 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2926 dev = &rte_eth_devices[port_id];
2927 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2928 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
2932 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
2933 rte_rx_callback_fn fn, void *user_param)
2935 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2936 rte_errno = ENOTSUP;
2939 /* check input parameters */
2940 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2941 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2945 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2953 cb->param = user_param;
2955 rte_spinlock_lock(&rte_eth_rx_cb_lock);
2956 /* Add the callbacks in fifo order. */
2957 struct rte_eth_rxtx_callback *tail =
2958 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2961 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2968 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
2974 rte_eth_add_first_rx_callback(uint8_t port_id, uint16_t queue_id,
2975 rte_rx_callback_fn fn, void *user_param)
2977 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2978 rte_errno = ENOTSUP;
2981 /* check input parameters */
2982 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2983 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2988 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2996 cb->param = user_param;
2998 rte_spinlock_lock(&rte_eth_rx_cb_lock);
2999 /* Add the callbacks at fisrt position*/
3000 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3002 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3003 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3009 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
3010 rte_tx_callback_fn fn, void *user_param)
3012 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3013 rte_errno = ENOTSUP;
3016 /* check input parameters */
3017 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3018 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3023 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3031 cb->param = user_param;
3033 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3034 /* Add the callbacks in fifo order. */
3035 struct rte_eth_rxtx_callback *tail =
3036 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3039 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3046 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3052 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3053 struct rte_eth_rxtx_callback *user_cb)
3055 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3058 /* Check input parameters. */
3059 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3060 if (user_cb == NULL ||
3061 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
3064 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3065 struct rte_eth_rxtx_callback *cb;
3066 struct rte_eth_rxtx_callback **prev_cb;
3069 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3070 prev_cb = &dev->post_rx_burst_cbs[queue_id];
3071 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3073 if (cb == user_cb) {
3074 /* Remove the user cb from the callback list. */
3075 *prev_cb = cb->next;
3080 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3086 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3087 struct rte_eth_rxtx_callback *user_cb)
3089 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3092 /* Check input parameters. */
3093 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3094 if (user_cb == NULL ||
3095 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
3098 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3100 struct rte_eth_rxtx_callback *cb;
3101 struct rte_eth_rxtx_callback **prev_cb;
3103 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3104 prev_cb = &dev->pre_tx_burst_cbs[queue_id];
3105 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3107 if (cb == user_cb) {
3108 /* Remove the user cb from the callback list. */
3109 *prev_cb = cb->next;
3114 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3120 rte_eth_rx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3121 struct rte_eth_rxq_info *qinfo)
3123 struct rte_eth_dev *dev;
3125 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3130 dev = &rte_eth_devices[port_id];
3131 if (queue_id >= dev->data->nb_rx_queues) {
3132 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3136 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3138 memset(qinfo, 0, sizeof(*qinfo));
3139 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3144 rte_eth_tx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3145 struct rte_eth_txq_info *qinfo)
3147 struct rte_eth_dev *dev;
3149 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3154 dev = &rte_eth_devices[port_id];
3155 if (queue_id >= dev->data->nb_tx_queues) {
3156 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3160 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3162 memset(qinfo, 0, sizeof(*qinfo));
3163 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3168 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3169 struct ether_addr *mc_addr_set,
3170 uint32_t nb_mc_addr)
3172 struct rte_eth_dev *dev;
3174 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3176 dev = &rte_eth_devices[port_id];
3177 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3178 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3182 rte_eth_timesync_enable(uint8_t port_id)
3184 struct rte_eth_dev *dev;
3186 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3187 dev = &rte_eth_devices[port_id];
3189 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3190 return (*dev->dev_ops->timesync_enable)(dev);
3194 rte_eth_timesync_disable(uint8_t port_id)
3196 struct rte_eth_dev *dev;
3198 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3199 dev = &rte_eth_devices[port_id];
3201 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3202 return (*dev->dev_ops->timesync_disable)(dev);
3206 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3209 struct rte_eth_dev *dev;
3211 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3212 dev = &rte_eth_devices[port_id];
3214 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3215 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3219 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3221 struct rte_eth_dev *dev;
3223 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3224 dev = &rte_eth_devices[port_id];
3226 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3227 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3231 rte_eth_timesync_adjust_time(uint8_t port_id, int64_t delta)
3233 struct rte_eth_dev *dev;
3235 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3236 dev = &rte_eth_devices[port_id];
3238 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3239 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3243 rte_eth_timesync_read_time(uint8_t port_id, struct timespec *timestamp)
3245 struct rte_eth_dev *dev;
3247 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3248 dev = &rte_eth_devices[port_id];
3250 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3251 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3255 rte_eth_timesync_write_time(uint8_t port_id, const struct timespec *timestamp)
3257 struct rte_eth_dev *dev;
3259 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3260 dev = &rte_eth_devices[port_id];
3262 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3263 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3267 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3269 struct rte_eth_dev *dev;
3271 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3273 dev = &rte_eth_devices[port_id];
3274 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3275 return (*dev->dev_ops->get_reg)(dev, info);
3279 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3281 struct rte_eth_dev *dev;
3283 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3285 dev = &rte_eth_devices[port_id];
3286 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3287 return (*dev->dev_ops->get_eeprom_length)(dev);
3291 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3293 struct rte_eth_dev *dev;
3295 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3297 dev = &rte_eth_devices[port_id];
3298 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3299 return (*dev->dev_ops->get_eeprom)(dev, info);
3303 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3305 struct rte_eth_dev *dev;
3307 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3309 dev = &rte_eth_devices[port_id];
3310 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3311 return (*dev->dev_ops->set_eeprom)(dev, info);
3315 rte_eth_dev_get_dcb_info(uint8_t port_id,
3316 struct rte_eth_dcb_info *dcb_info)
3318 struct rte_eth_dev *dev;
3320 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3322 dev = &rte_eth_devices[port_id];
3323 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3325 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3326 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3330 rte_eth_dev_l2_tunnel_eth_type_conf(uint8_t port_id,
3331 struct rte_eth_l2_tunnel_conf *l2_tunnel)
3333 struct rte_eth_dev *dev;
3335 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3336 if (l2_tunnel == NULL) {
3337 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3341 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3342 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
3346 dev = &rte_eth_devices[port_id];
3347 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
3349 return (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev, l2_tunnel);
3353 rte_eth_dev_l2_tunnel_offload_set(uint8_t port_id,
3354 struct rte_eth_l2_tunnel_conf *l2_tunnel,
3358 struct rte_eth_dev *dev;
3360 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3362 if (l2_tunnel == NULL) {
3363 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3367 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3368 RTE_PMD_DEBUG_TRACE("Invalid tunnel type.\n");
3373 RTE_PMD_DEBUG_TRACE("Mask should have a value.\n");
3377 dev = &rte_eth_devices[port_id];
3378 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
3380 return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);
3384 rte_eth_dev_adjust_nb_desc(uint16_t *nb_desc,
3385 const struct rte_eth_desc_lim *desc_lim)
3387 if (desc_lim->nb_align != 0)
3388 *nb_desc = RTE_ALIGN_CEIL(*nb_desc, desc_lim->nb_align);
3390 if (desc_lim->nb_max != 0)
3391 *nb_desc = RTE_MIN(*nb_desc, desc_lim->nb_max);
3393 *nb_desc = RTE_MAX(*nb_desc, desc_lim->nb_min);
3397 rte_eth_dev_adjust_nb_rx_tx_desc(uint8_t port_id,
3398 uint16_t *nb_rx_desc,
3399 uint16_t *nb_tx_desc)
3401 struct rte_eth_dev *dev;
3402 struct rte_eth_dev_info dev_info;
3404 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3406 dev = &rte_eth_devices[port_id];
3407 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
3409 rte_eth_dev_info_get(port_id, &dev_info);
3411 if (nb_rx_desc != NULL)
3412 rte_eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim);
3414 if (nb_tx_desc != NULL)
3415 rte_eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim);