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;
76 /* spinlock for eth device callbacks */
77 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
79 /* spinlock for add/remove rx callbacks */
80 static rte_spinlock_t rte_eth_rx_cb_lock = RTE_SPINLOCK_INITIALIZER;
82 /* spinlock for add/remove tx callbacks */
83 static rte_spinlock_t rte_eth_tx_cb_lock = RTE_SPINLOCK_INITIALIZER;
85 /* store statistics names and its offset in stats structure */
86 struct rte_eth_xstats_name_off {
87 char name[RTE_ETH_XSTATS_NAME_SIZE];
91 static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
92 {"rx_good_packets", offsetof(struct rte_eth_stats, ipackets)},
93 {"tx_good_packets", offsetof(struct rte_eth_stats, opackets)},
94 {"rx_good_bytes", offsetof(struct rte_eth_stats, ibytes)},
95 {"tx_good_bytes", offsetof(struct rte_eth_stats, obytes)},
96 {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
97 {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
98 {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats,
102 #define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
104 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
105 {"packets", offsetof(struct rte_eth_stats, q_ipackets)},
106 {"bytes", offsetof(struct rte_eth_stats, q_ibytes)},
107 {"errors", offsetof(struct rte_eth_stats, q_errors)},
110 #define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) / \
111 sizeof(rte_rxq_stats_strings[0]))
113 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
114 {"packets", offsetof(struct rte_eth_stats, q_opackets)},
115 {"bytes", offsetof(struct rte_eth_stats, q_obytes)},
117 #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) / \
118 sizeof(rte_txq_stats_strings[0]))
122 * The user application callback description.
124 * It contains callback address to be registered by user application,
125 * the pointer to the parameters for callback, and the event type.
127 struct rte_eth_dev_callback {
128 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
129 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
130 void *cb_arg; /**< Parameter for callback */
131 void *ret_param; /**< Return parameter */
132 enum rte_eth_event_type event; /**< Interrupt event type */
133 uint32_t active; /**< Callback is executing */
142 rte_eth_find_next(uint8_t port_id)
144 while (port_id < RTE_MAX_ETHPORTS &&
145 rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED)
148 if (port_id >= RTE_MAX_ETHPORTS)
149 return RTE_MAX_ETHPORTS;
155 rte_eth_dev_data_alloc(void)
157 const unsigned flags = 0;
158 const struct rte_memzone *mz;
160 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
161 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
162 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
163 rte_socket_id(), flags);
165 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
167 rte_panic("Cannot allocate memzone for ethernet port data\n");
169 rte_eth_dev_data = mz->addr;
170 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
171 memset(rte_eth_dev_data, 0,
172 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
176 rte_eth_dev_allocated(const char *name)
180 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
181 if (rte_eth_devices[i].state == RTE_ETH_DEV_ATTACHED &&
182 rte_eth_devices[i].device) {
183 if (!strcmp(rte_eth_devices[i].device->name, name))
184 return &rte_eth_devices[i];
191 rte_eth_dev_find_free_port(void)
195 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
196 if (rte_eth_devices[i].state == RTE_ETH_DEV_UNUSED)
199 return RTE_MAX_ETHPORTS;
202 static struct rte_eth_dev *
203 eth_dev_get(uint8_t port_id)
205 struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
207 eth_dev->data = &rte_eth_dev_data[port_id];
208 eth_dev->state = RTE_ETH_DEV_ATTACHED;
209 TAILQ_INIT(&(eth_dev->link_intr_cbs));
211 eth_dev_last_created_port = port_id;
217 rte_eth_dev_allocate(const char *name)
220 struct rte_eth_dev *eth_dev;
222 port_id = rte_eth_dev_find_free_port();
223 if (port_id == RTE_MAX_ETHPORTS) {
224 RTE_PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
228 if (rte_eth_dev_data == NULL)
229 rte_eth_dev_data_alloc();
231 if (rte_eth_dev_allocated(name) != NULL) {
232 RTE_PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n",
237 memset(&rte_eth_dev_data[port_id], 0, sizeof(struct rte_eth_dev_data));
238 eth_dev = eth_dev_get(port_id);
239 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
240 eth_dev->data->port_id = port_id;
241 eth_dev->data->mtu = ETHER_MTU;
247 * Attach to a port already registered by the primary process, which
248 * makes sure that the same device would have the same port id both
249 * in the primary and secondary process.
252 rte_eth_dev_attach_secondary(const char *name)
255 struct rte_eth_dev *eth_dev;
257 if (rte_eth_dev_data == NULL)
258 rte_eth_dev_data_alloc();
260 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
261 if (strcmp(rte_eth_dev_data[i].name, name) == 0)
264 if (i == RTE_MAX_ETHPORTS) {
266 "device %s is not driven by the primary process\n",
271 eth_dev = eth_dev_get(i);
272 RTE_ASSERT(eth_dev->data->port_id == i);
278 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
283 eth_dev->state = RTE_ETH_DEV_UNUSED;
288 rte_eth_dev_is_valid_port(uint8_t port_id)
290 if (port_id >= RTE_MAX_ETHPORTS ||
291 (rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
292 rte_eth_devices[port_id].state != RTE_ETH_DEV_DEFERRED))
299 rte_eth_dev_socket_id(uint8_t port_id)
301 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
302 return rte_eth_devices[port_id].data->numa_node;
306 rte_eth_dev_count(void)
313 RTE_ETH_FOREACH_DEV(p)
320 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
324 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
327 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
331 /* shouldn't check 'rte_eth_devices[i].data',
332 * because it might be overwritten by VDEV PMD */
333 tmp = rte_eth_devices[port_id].device->name;
339 rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
345 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
349 RTE_ETH_FOREACH_DEV(i) {
350 if (!rte_eth_devices[i].device)
353 ret = strncmp(name, rte_eth_devices[i].device->name,
364 rte_eth_dev_is_detachable(uint8_t port_id)
368 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
370 switch (rte_eth_devices[port_id].data->kdrv) {
371 case RTE_KDRV_IGB_UIO:
372 case RTE_KDRV_UIO_GENERIC:
373 case RTE_KDRV_NIC_UIO:
380 dev_flags = rte_eth_devices[port_id].data->dev_flags;
381 if ((dev_flags & RTE_ETH_DEV_DETACHABLE) &&
382 (!(dev_flags & RTE_ETH_DEV_BONDED_SLAVE)))
388 /* attach the new device, then store port_id of the device */
390 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
393 int current = rte_eth_dev_count();
397 if ((devargs == NULL) || (port_id == NULL)) {
402 /* parse devargs, then retrieve device name and args */
403 if (rte_eal_parse_devargs_str(devargs, &name, &args))
406 ret = rte_eal_dev_attach(name, args);
410 /* no point looking at the port count if no port exists */
411 if (!rte_eth_dev_count()) {
412 RTE_LOG(ERR, EAL, "No port found for device (%s)\n", name);
417 /* if nothing happened, there is a bug here, since some driver told us
418 * it did attach a device, but did not create a port.
420 if (current == rte_eth_dev_count()) {
425 *port_id = eth_dev_last_created_port;
434 /* detach the device, then store the name of the device */
436 rte_eth_dev_detach(uint8_t port_id, char *name)
445 /* FIXME: move this to eal, once device flags are relocated there */
446 if (rte_eth_dev_is_detachable(port_id))
449 snprintf(name, sizeof(rte_eth_devices[port_id].device->name),
450 "%s", rte_eth_devices[port_id].device->name);
452 ret = rte_eal_dev_detach(rte_eth_devices[port_id].device);
456 rte_eth_devices[port_id].state = RTE_ETH_DEV_UNUSED;
464 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
466 uint16_t old_nb_queues = dev->data->nb_rx_queues;
470 if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */
471 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
472 sizeof(dev->data->rx_queues[0]) * nb_queues,
473 RTE_CACHE_LINE_SIZE);
474 if (dev->data->rx_queues == NULL) {
475 dev->data->nb_rx_queues = 0;
478 } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */
479 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
481 rxq = dev->data->rx_queues;
483 for (i = nb_queues; i < old_nb_queues; i++)
484 (*dev->dev_ops->rx_queue_release)(rxq[i]);
485 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
486 RTE_CACHE_LINE_SIZE);
489 if (nb_queues > old_nb_queues) {
490 uint16_t new_qs = nb_queues - old_nb_queues;
492 memset(rxq + old_nb_queues, 0,
493 sizeof(rxq[0]) * new_qs);
496 dev->data->rx_queues = rxq;
498 } else if (dev->data->rx_queues != NULL && nb_queues == 0) {
499 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
501 rxq = dev->data->rx_queues;
503 for (i = nb_queues; i < old_nb_queues; i++)
504 (*dev->dev_ops->rx_queue_release)(rxq[i]);
506 rte_free(dev->data->rx_queues);
507 dev->data->rx_queues = NULL;
509 dev->data->nb_rx_queues = nb_queues;
514 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
516 struct rte_eth_dev *dev;
518 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
520 dev = &rte_eth_devices[port_id];
521 if (rx_queue_id >= dev->data->nb_rx_queues) {
522 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
526 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
528 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
529 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
530 " already started\n",
531 rx_queue_id, port_id);
535 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
540 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
542 struct rte_eth_dev *dev;
544 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
546 dev = &rte_eth_devices[port_id];
547 if (rx_queue_id >= dev->data->nb_rx_queues) {
548 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
552 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
554 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
555 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
556 " already stopped\n",
557 rx_queue_id, port_id);
561 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
566 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
568 struct rte_eth_dev *dev;
570 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
572 dev = &rte_eth_devices[port_id];
573 if (tx_queue_id >= dev->data->nb_tx_queues) {
574 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
578 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
580 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
581 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
582 " already started\n",
583 tx_queue_id, port_id);
587 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
592 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
594 struct rte_eth_dev *dev;
596 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
598 dev = &rte_eth_devices[port_id];
599 if (tx_queue_id >= dev->data->nb_tx_queues) {
600 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
604 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
606 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
607 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
608 " already stopped\n",
609 tx_queue_id, port_id);
613 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
618 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
620 uint16_t old_nb_queues = dev->data->nb_tx_queues;
624 if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */
625 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
626 sizeof(dev->data->tx_queues[0]) * nb_queues,
627 RTE_CACHE_LINE_SIZE);
628 if (dev->data->tx_queues == NULL) {
629 dev->data->nb_tx_queues = 0;
632 } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */
633 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
635 txq = dev->data->tx_queues;
637 for (i = nb_queues; i < old_nb_queues; i++)
638 (*dev->dev_ops->tx_queue_release)(txq[i]);
639 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
640 RTE_CACHE_LINE_SIZE);
643 if (nb_queues > old_nb_queues) {
644 uint16_t new_qs = nb_queues - old_nb_queues;
646 memset(txq + old_nb_queues, 0,
647 sizeof(txq[0]) * new_qs);
650 dev->data->tx_queues = txq;
652 } else if (dev->data->tx_queues != NULL && nb_queues == 0) {
653 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
655 txq = dev->data->tx_queues;
657 for (i = nb_queues; i < old_nb_queues; i++)
658 (*dev->dev_ops->tx_queue_release)(txq[i]);
660 rte_free(dev->data->tx_queues);
661 dev->data->tx_queues = NULL;
663 dev->data->nb_tx_queues = nb_queues;
668 rte_eth_speed_bitflag(uint32_t speed, int duplex)
671 case ETH_SPEED_NUM_10M:
672 return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD;
673 case ETH_SPEED_NUM_100M:
674 return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD;
675 case ETH_SPEED_NUM_1G:
676 return ETH_LINK_SPEED_1G;
677 case ETH_SPEED_NUM_2_5G:
678 return ETH_LINK_SPEED_2_5G;
679 case ETH_SPEED_NUM_5G:
680 return ETH_LINK_SPEED_5G;
681 case ETH_SPEED_NUM_10G:
682 return ETH_LINK_SPEED_10G;
683 case ETH_SPEED_NUM_20G:
684 return ETH_LINK_SPEED_20G;
685 case ETH_SPEED_NUM_25G:
686 return ETH_LINK_SPEED_25G;
687 case ETH_SPEED_NUM_40G:
688 return ETH_LINK_SPEED_40G;
689 case ETH_SPEED_NUM_50G:
690 return ETH_LINK_SPEED_50G;
691 case ETH_SPEED_NUM_56G:
692 return ETH_LINK_SPEED_56G;
693 case ETH_SPEED_NUM_100G:
694 return ETH_LINK_SPEED_100G;
701 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
702 const struct rte_eth_conf *dev_conf)
704 struct rte_eth_dev *dev;
705 struct rte_eth_dev_info dev_info;
708 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
710 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
712 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
713 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
717 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
719 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
720 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
724 dev = &rte_eth_devices[port_id];
726 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
727 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
729 if (dev->data->dev_started) {
731 "port %d must be stopped to allow configuration\n", port_id);
735 /* Copy the dev_conf parameter into the dev structure */
736 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
739 * Check that the numbers of RX and TX queues are not greater
740 * than the maximum number of RX and TX queues supported by the
743 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
745 if (nb_rx_q == 0 && nb_tx_q == 0) {
746 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d both rx and tx queue cannot be 0\n", port_id);
750 if (nb_rx_q > dev_info.max_rx_queues) {
751 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
752 port_id, nb_rx_q, dev_info.max_rx_queues);
756 if (nb_tx_q > dev_info.max_tx_queues) {
757 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
758 port_id, nb_tx_q, dev_info.max_tx_queues);
762 /* Check that the device supports requested interrupts */
763 if ((dev_conf->intr_conf.lsc == 1) &&
764 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
765 RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
766 dev->device->driver->name);
769 if ((dev_conf->intr_conf.rmv == 1) &&
770 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_RMV))) {
771 RTE_PMD_DEBUG_TRACE("driver %s does not support rmv\n",
772 dev->device->driver->name);
777 * If jumbo frames are enabled, check that the maximum RX packet
778 * length is supported by the configured device.
780 if (dev_conf->rxmode.jumbo_frame == 1) {
781 if (dev_conf->rxmode.max_rx_pkt_len >
782 dev_info.max_rx_pktlen) {
783 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
784 " > max valid value %u\n",
786 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
787 (unsigned)dev_info.max_rx_pktlen);
789 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
790 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
791 " < min valid value %u\n",
793 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
794 (unsigned)ETHER_MIN_LEN);
798 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
799 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
800 /* Use default value */
801 dev->data->dev_conf.rxmode.max_rx_pkt_len =
806 * Setup new number of RX/TX queues and reconfigure device.
808 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
810 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
815 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
817 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
819 rte_eth_dev_rx_queue_config(dev, 0);
823 diag = (*dev->dev_ops->dev_configure)(dev);
825 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
827 rte_eth_dev_rx_queue_config(dev, 0);
828 rte_eth_dev_tx_queue_config(dev, 0);
836 _rte_eth_dev_reset(struct rte_eth_dev *dev)
838 if (dev->data->dev_started) {
840 "port %d must be stopped to allow reset\n",
845 rte_eth_dev_rx_queue_config(dev, 0);
846 rte_eth_dev_tx_queue_config(dev, 0);
848 memset(&dev->data->dev_conf, 0, sizeof(dev->data->dev_conf));
852 rte_eth_dev_config_restore(uint8_t port_id)
854 struct rte_eth_dev *dev;
855 struct rte_eth_dev_info dev_info;
856 struct ether_addr *addr;
861 dev = &rte_eth_devices[port_id];
863 rte_eth_dev_info_get(port_id, &dev_info);
865 /* replay MAC address configuration including default MAC */
866 addr = &dev->data->mac_addrs[0];
867 if (*dev->dev_ops->mac_addr_set != NULL)
868 (*dev->dev_ops->mac_addr_set)(dev, addr);
869 else if (*dev->dev_ops->mac_addr_add != NULL)
870 (*dev->dev_ops->mac_addr_add)(dev, addr, 0, pool);
872 if (*dev->dev_ops->mac_addr_add != NULL) {
873 for (i = 1; i < dev_info.max_mac_addrs; i++) {
874 addr = &dev->data->mac_addrs[i];
876 /* skip zero address */
877 if (is_zero_ether_addr(addr))
881 pool_mask = dev->data->mac_pool_sel[i];
884 if (pool_mask & 1ULL)
885 (*dev->dev_ops->mac_addr_add)(dev,
893 /* replay promiscuous configuration */
894 if (rte_eth_promiscuous_get(port_id) == 1)
895 rte_eth_promiscuous_enable(port_id);
896 else if (rte_eth_promiscuous_get(port_id) == 0)
897 rte_eth_promiscuous_disable(port_id);
899 /* replay all multicast configuration */
900 if (rte_eth_allmulticast_get(port_id) == 1)
901 rte_eth_allmulticast_enable(port_id);
902 else if (rte_eth_allmulticast_get(port_id) == 0)
903 rte_eth_allmulticast_disable(port_id);
907 rte_eth_dev_start(uint8_t port_id)
909 struct rte_eth_dev *dev;
912 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
914 dev = &rte_eth_devices[port_id];
916 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
918 if (dev->data->dev_started != 0) {
919 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
920 " already started\n",
925 diag = (*dev->dev_ops->dev_start)(dev);
927 dev->data->dev_started = 1;
931 rte_eth_dev_config_restore(port_id);
933 if (dev->data->dev_conf.intr_conf.lsc == 0) {
934 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
935 (*dev->dev_ops->link_update)(dev, 0);
941 rte_eth_dev_stop(uint8_t port_id)
943 struct rte_eth_dev *dev;
945 RTE_ETH_VALID_PORTID_OR_RET(port_id);
946 dev = &rte_eth_devices[port_id];
948 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
950 if (dev->data->dev_started == 0) {
951 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
952 " already stopped\n",
957 dev->data->dev_started = 0;
958 (*dev->dev_ops->dev_stop)(dev);
962 rte_eth_dev_set_link_up(uint8_t port_id)
964 struct rte_eth_dev *dev;
966 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
968 dev = &rte_eth_devices[port_id];
970 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
971 return (*dev->dev_ops->dev_set_link_up)(dev);
975 rte_eth_dev_set_link_down(uint8_t port_id)
977 struct rte_eth_dev *dev;
979 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
981 dev = &rte_eth_devices[port_id];
983 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
984 return (*dev->dev_ops->dev_set_link_down)(dev);
988 rte_eth_dev_close(uint8_t port_id)
990 struct rte_eth_dev *dev;
992 RTE_ETH_VALID_PORTID_OR_RET(port_id);
993 dev = &rte_eth_devices[port_id];
995 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
996 dev->data->dev_started = 0;
997 (*dev->dev_ops->dev_close)(dev);
999 dev->data->nb_rx_queues = 0;
1000 rte_free(dev->data->rx_queues);
1001 dev->data->rx_queues = NULL;
1002 dev->data->nb_tx_queues = 0;
1003 rte_free(dev->data->tx_queues);
1004 dev->data->tx_queues = NULL;
1008 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1009 uint16_t nb_rx_desc, unsigned int socket_id,
1010 const struct rte_eth_rxconf *rx_conf,
1011 struct rte_mempool *mp)
1014 uint32_t mbp_buf_size;
1015 struct rte_eth_dev *dev;
1016 struct rte_eth_dev_info dev_info;
1019 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1021 dev = &rte_eth_devices[port_id];
1022 if (rx_queue_id >= dev->data->nb_rx_queues) {
1023 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1027 if (dev->data->dev_started) {
1028 RTE_PMD_DEBUG_TRACE(
1029 "port %d must be stopped to allow configuration\n", port_id);
1033 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1034 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1037 * Check the size of the mbuf data buffer.
1038 * This value must be provided in the private data of the memory pool.
1039 * First check that the memory pool has a valid private data.
1041 rte_eth_dev_info_get(port_id, &dev_info);
1042 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1043 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1044 mp->name, (int) mp->private_data_size,
1045 (int) sizeof(struct rte_pktmbuf_pool_private));
1048 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1050 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1051 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1052 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1056 (int)(RTE_PKTMBUF_HEADROOM +
1057 dev_info.min_rx_bufsize),
1058 (int)RTE_PKTMBUF_HEADROOM,
1059 (int)dev_info.min_rx_bufsize);
1063 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1064 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1065 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1067 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1068 "should be: <= %hu, = %hu, and a product of %hu\n",
1070 dev_info.rx_desc_lim.nb_max,
1071 dev_info.rx_desc_lim.nb_min,
1072 dev_info.rx_desc_lim.nb_align);
1076 rxq = dev->data->rx_queues;
1077 if (rxq[rx_queue_id]) {
1078 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release,
1080 (*dev->dev_ops->rx_queue_release)(rxq[rx_queue_id]);
1081 rxq[rx_queue_id] = NULL;
1084 if (rx_conf == NULL)
1085 rx_conf = &dev_info.default_rxconf;
1087 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1088 socket_id, rx_conf, mp);
1090 if (!dev->data->min_rx_buf_size ||
1091 dev->data->min_rx_buf_size > mbp_buf_size)
1092 dev->data->min_rx_buf_size = mbp_buf_size;
1099 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1100 uint16_t nb_tx_desc, unsigned int socket_id,
1101 const struct rte_eth_txconf *tx_conf)
1103 struct rte_eth_dev *dev;
1104 struct rte_eth_dev_info dev_info;
1107 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1109 dev = &rte_eth_devices[port_id];
1110 if (tx_queue_id >= dev->data->nb_tx_queues) {
1111 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1115 if (dev->data->dev_started) {
1116 RTE_PMD_DEBUG_TRACE(
1117 "port %d must be stopped to allow configuration\n", port_id);
1121 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1122 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1124 rte_eth_dev_info_get(port_id, &dev_info);
1126 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1127 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1128 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1129 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1130 "should be: <= %hu, = %hu, and a product of %hu\n",
1132 dev_info.tx_desc_lim.nb_max,
1133 dev_info.tx_desc_lim.nb_min,
1134 dev_info.tx_desc_lim.nb_align);
1138 txq = dev->data->tx_queues;
1139 if (txq[tx_queue_id]) {
1140 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release,
1142 (*dev->dev_ops->tx_queue_release)(txq[tx_queue_id]);
1143 txq[tx_queue_id] = NULL;
1146 if (tx_conf == NULL)
1147 tx_conf = &dev_info.default_txconf;
1149 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1150 socket_id, tx_conf);
1154 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
1155 void *userdata __rte_unused)
1159 for (i = 0; i < unsent; i++)
1160 rte_pktmbuf_free(pkts[i]);
1164 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
1167 uint64_t *count = userdata;
1170 for (i = 0; i < unsent; i++)
1171 rte_pktmbuf_free(pkts[i]);
1177 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
1178 buffer_tx_error_fn cbfn, void *userdata)
1180 buffer->error_callback = cbfn;
1181 buffer->error_userdata = userdata;
1186 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
1193 buffer->size = size;
1194 if (buffer->error_callback == NULL) {
1195 ret = rte_eth_tx_buffer_set_err_callback(
1196 buffer, rte_eth_tx_buffer_drop_callback, NULL);
1203 rte_eth_tx_done_cleanup(uint8_t port_id, uint16_t queue_id, uint32_t free_cnt)
1205 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1207 /* Validate Input Data. Bail if not valid or not supported. */
1208 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1209 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_done_cleanup, -ENOTSUP);
1211 /* Call driver to free pending mbufs. */
1212 return (*dev->dev_ops->tx_done_cleanup)(dev->data->tx_queues[queue_id],
1217 rte_eth_promiscuous_enable(uint8_t port_id)
1219 struct rte_eth_dev *dev;
1221 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1222 dev = &rte_eth_devices[port_id];
1224 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1225 (*dev->dev_ops->promiscuous_enable)(dev);
1226 dev->data->promiscuous = 1;
1230 rte_eth_promiscuous_disable(uint8_t port_id)
1232 struct rte_eth_dev *dev;
1234 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1235 dev = &rte_eth_devices[port_id];
1237 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1238 dev->data->promiscuous = 0;
1239 (*dev->dev_ops->promiscuous_disable)(dev);
1243 rte_eth_promiscuous_get(uint8_t port_id)
1245 struct rte_eth_dev *dev;
1247 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1249 dev = &rte_eth_devices[port_id];
1250 return dev->data->promiscuous;
1254 rte_eth_allmulticast_enable(uint8_t port_id)
1256 struct rte_eth_dev *dev;
1258 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1259 dev = &rte_eth_devices[port_id];
1261 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1262 (*dev->dev_ops->allmulticast_enable)(dev);
1263 dev->data->all_multicast = 1;
1267 rte_eth_allmulticast_disable(uint8_t port_id)
1269 struct rte_eth_dev *dev;
1271 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1272 dev = &rte_eth_devices[port_id];
1274 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1275 dev->data->all_multicast = 0;
1276 (*dev->dev_ops->allmulticast_disable)(dev);
1280 rte_eth_allmulticast_get(uint8_t port_id)
1282 struct rte_eth_dev *dev;
1284 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1286 dev = &rte_eth_devices[port_id];
1287 return dev->data->all_multicast;
1291 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1292 struct rte_eth_link *link)
1294 struct rte_eth_link *dst = link;
1295 struct rte_eth_link *src = &(dev->data->dev_link);
1297 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1298 *(uint64_t *)src) == 0)
1305 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1307 struct rte_eth_dev *dev;
1309 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1310 dev = &rte_eth_devices[port_id];
1312 if (dev->data->dev_conf.intr_conf.lsc != 0)
1313 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1315 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1316 (*dev->dev_ops->link_update)(dev, 1);
1317 *eth_link = dev->data->dev_link;
1322 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1324 struct rte_eth_dev *dev;
1326 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1327 dev = &rte_eth_devices[port_id];
1329 if (dev->data->dev_conf.intr_conf.lsc != 0)
1330 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1332 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1333 (*dev->dev_ops->link_update)(dev, 0);
1334 *eth_link = dev->data->dev_link;
1339 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1341 struct rte_eth_dev *dev;
1343 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1345 dev = &rte_eth_devices[port_id];
1346 memset(stats, 0, sizeof(*stats));
1348 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1349 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1350 (*dev->dev_ops->stats_get)(dev, stats);
1355 rte_eth_stats_reset(uint8_t port_id)
1357 struct rte_eth_dev *dev;
1359 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1360 dev = &rte_eth_devices[port_id];
1362 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1363 (*dev->dev_ops->stats_reset)(dev);
1364 dev->data->rx_mbuf_alloc_failed = 0;
1368 get_xstats_count(uint8_t port_id)
1370 struct rte_eth_dev *dev;
1373 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1374 dev = &rte_eth_devices[port_id];
1375 if (dev->dev_ops->xstats_get_names_by_id != NULL) {
1376 count = (*dev->dev_ops->xstats_get_names_by_id)(dev, NULL,
1381 if (dev->dev_ops->xstats_get_names != NULL) {
1382 count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0);
1388 count += RTE_NB_STATS;
1389 count += RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
1391 count += RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
1397 rte_eth_xstats_get_id_by_name(uint8_t port_id, const char *xstat_name,
1400 int cnt_xstats, idx_xstat;
1402 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1405 RTE_PMD_DEBUG_TRACE("Error: id pointer is NULL\n");
1410 RTE_PMD_DEBUG_TRACE("Error: xstat_name pointer is NULL\n");
1415 cnt_xstats = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
1416 if (cnt_xstats < 0) {
1417 RTE_PMD_DEBUG_TRACE("Error: Cannot get count of xstats\n");
1421 /* Get id-name lookup table */
1422 struct rte_eth_xstat_name xstats_names[cnt_xstats];
1424 if (cnt_xstats != rte_eth_xstats_get_names_by_id(
1425 port_id, xstats_names, cnt_xstats, NULL)) {
1426 RTE_PMD_DEBUG_TRACE("Error: Cannot get xstats lookup\n");
1430 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
1431 if (!strcmp(xstats_names[idx_xstat].name, xstat_name)) {
1441 rte_eth_xstats_get_names_by_id(uint8_t port_id,
1442 struct rte_eth_xstat_name *xstats_names, unsigned int size,
1445 /* Get all xstats */
1447 struct rte_eth_dev *dev;
1448 int cnt_used_entries;
1449 int cnt_expected_entries;
1450 int cnt_driver_entries;
1451 uint32_t idx, id_queue;
1454 cnt_expected_entries = get_xstats_count(port_id);
1455 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1456 (int)size < cnt_expected_entries)
1457 return cnt_expected_entries;
1459 /* port_id checked in get_xstats_count() */
1460 dev = &rte_eth_devices[port_id];
1461 cnt_used_entries = 0;
1463 for (idx = 0; idx < RTE_NB_STATS; idx++) {
1464 snprintf(xstats_names[cnt_used_entries].name,
1465 sizeof(xstats_names[0].name),
1466 "%s", rte_stats_strings[idx].name);
1469 num_q = RTE_MIN(dev->data->nb_rx_queues,
1470 RTE_ETHDEV_QUEUE_STAT_CNTRS);
1471 for (id_queue = 0; id_queue < num_q; id_queue++) {
1472 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1473 snprintf(xstats_names[cnt_used_entries].name,
1474 sizeof(xstats_names[0].name),
1477 rte_rxq_stats_strings[idx].name);
1482 num_q = RTE_MIN(dev->data->nb_tx_queues,
1483 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),
1490 rte_txq_stats_strings[idx].name);
1495 if (dev->dev_ops->xstats_get_names_by_id != NULL) {
1496 /* If there are any driver-specific xstats, append them
1499 cnt_driver_entries =
1500 (*dev->dev_ops->xstats_get_names_by_id)(
1502 xstats_names + cnt_used_entries,
1504 size - cnt_used_entries);
1505 if (cnt_driver_entries < 0)
1506 return cnt_driver_entries;
1507 cnt_used_entries += cnt_driver_entries;
1509 } else if (dev->dev_ops->xstats_get_names != NULL) {
1510 /* If there are any driver-specific xstats, append them
1513 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
1515 xstats_names + cnt_used_entries,
1516 size - cnt_used_entries);
1517 if (cnt_driver_entries < 0)
1518 return cnt_driver_entries;
1519 cnt_used_entries += cnt_driver_entries;
1522 return cnt_used_entries;
1524 /* Get only xstats given by IDS */
1527 struct rte_eth_xstat_name *xstats_names_copy;
1529 len = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
1532 malloc(sizeof(struct rte_eth_xstat_name) * len);
1533 if (!xstats_names_copy) {
1534 RTE_PMD_DEBUG_TRACE(
1535 "ERROR: can't allocate memory for values_copy\n");
1536 free(xstats_names_copy);
1540 rte_eth_xstats_get_names_by_id(port_id, xstats_names_copy,
1543 for (i = 0; i < size; i++) {
1544 if (ids[i] >= len) {
1545 RTE_PMD_DEBUG_TRACE(
1546 "ERROR: id value isn't valid\n");
1549 strcpy(xstats_names[i].name,
1550 xstats_names_copy[ids[i]].name);
1552 free(xstats_names_copy);
1558 rte_eth_xstats_get_names(uint8_t port_id,
1559 struct rte_eth_xstat_name *xstats_names,
1562 struct rte_eth_dev *dev;
1563 int cnt_used_entries;
1564 int cnt_expected_entries;
1565 int cnt_driver_entries;
1566 uint32_t idx, id_queue;
1569 cnt_expected_entries = get_xstats_count(port_id);
1570 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1571 (int)size < cnt_expected_entries)
1572 return cnt_expected_entries;
1574 /* port_id checked in get_xstats_count() */
1575 dev = &rte_eth_devices[port_id];
1576 cnt_used_entries = 0;
1578 for (idx = 0; idx < RTE_NB_STATS; idx++) {
1579 snprintf(xstats_names[cnt_used_entries].name,
1580 sizeof(xstats_names[0].name),
1581 "%s", rte_stats_strings[idx].name);
1584 num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1585 for (id_queue = 0; id_queue < num_q; id_queue++) {
1586 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1587 snprintf(xstats_names[cnt_used_entries].name,
1588 sizeof(xstats_names[0].name),
1590 id_queue, rte_rxq_stats_strings[idx].name);
1595 num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1596 for (id_queue = 0; id_queue < num_q; id_queue++) {
1597 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
1598 snprintf(xstats_names[cnt_used_entries].name,
1599 sizeof(xstats_names[0].name),
1601 id_queue, rte_txq_stats_strings[idx].name);
1606 if (dev->dev_ops->xstats_get_names != NULL) {
1607 /* If there are any driver-specific xstats, append them
1610 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
1612 xstats_names + cnt_used_entries,
1613 size - cnt_used_entries);
1614 if (cnt_driver_entries < 0)
1615 return cnt_driver_entries;
1616 cnt_used_entries += cnt_driver_entries;
1619 return cnt_used_entries;
1622 /* retrieve ethdev extended statistics */
1624 rte_eth_xstats_get_by_id(uint8_t port_id, const uint64_t *ids, uint64_t *values,
1627 /* If need all xstats */
1629 struct rte_eth_stats eth_stats;
1630 struct rte_eth_dev *dev;
1631 unsigned int count = 0, i, q;
1632 signed int xcount = 0;
1633 uint64_t val, *stats_ptr;
1634 uint16_t nb_rxqs, nb_txqs;
1636 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1637 dev = &rte_eth_devices[port_id];
1639 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues,
1640 RTE_ETHDEV_QUEUE_STAT_CNTRS);
1641 nb_txqs = RTE_MIN(dev->data->nb_tx_queues,
1642 RTE_ETHDEV_QUEUE_STAT_CNTRS);
1644 /* Return generic statistics */
1645 count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
1646 (nb_txqs * RTE_NB_TXQ_STATS);
1649 /* implemented by the driver */
1650 if (dev->dev_ops->xstats_get_by_id != NULL) {
1651 /* Retrieve the xstats from the driver at the end of the
1652 * xstats struct. Retrieve all xstats.
1654 xcount = (*dev->dev_ops->xstats_get_by_id)(dev,
1656 values ? values + count : NULL,
1657 (n > count) ? n - count : 0);
1661 /* implemented by the driver */
1662 } else if (dev->dev_ops->xstats_get != NULL) {
1663 /* Retrieve the xstats from the driver at the end of the
1664 * xstats struct. Retrieve all xstats.
1665 * Compatibility for PMD without xstats_get_by_ids
1667 unsigned int size = (n > count) ? n - count : 1;
1668 struct rte_eth_xstat xstats[size];
1670 xcount = (*dev->dev_ops->xstats_get)(dev,
1671 values ? xstats : NULL, size);
1677 for (i = 0 ; i < (unsigned int)xcount; i++)
1678 values[i + count] = xstats[i].value;
1681 if (n < count + xcount || values == NULL)
1682 return count + xcount;
1684 /* now fill the xstats structure */
1686 rte_eth_stats_get(port_id, ð_stats);
1689 for (i = 0; i < RTE_NB_STATS; i++) {
1690 stats_ptr = RTE_PTR_ADD(ð_stats,
1691 rte_stats_strings[i].offset);
1693 values[count++] = val;
1697 for (q = 0; q < nb_rxqs; q++) {
1698 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1699 stats_ptr = RTE_PTR_ADD(ð_stats,
1700 rte_rxq_stats_strings[i].offset +
1701 q * sizeof(uint64_t));
1703 values[count++] = val;
1708 for (q = 0; q < nb_txqs; q++) {
1709 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1710 stats_ptr = RTE_PTR_ADD(ð_stats,
1711 rte_txq_stats_strings[i].offset +
1712 q * sizeof(uint64_t));
1714 values[count++] = val;
1718 return count + xcount;
1720 /* Need only xstats given by IDS array */
1723 uint64_t *values_copy;
1725 size = rte_eth_xstats_get_by_id(port_id, NULL, NULL, 0);
1727 values_copy = malloc(sizeof(*values_copy) * size);
1729 RTE_PMD_DEBUG_TRACE(
1730 "ERROR: can't allocate memory for values_copy\n");
1734 rte_eth_xstats_get_by_id(port_id, NULL, values_copy, size);
1736 for (i = 0; i < n; i++) {
1737 if (ids[i] >= size) {
1738 RTE_PMD_DEBUG_TRACE(
1739 "ERROR: id value isn't valid\n");
1742 values[i] = values_copy[ids[i]];
1750 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstat *xstats,
1753 struct rte_eth_stats eth_stats;
1754 struct rte_eth_dev *dev;
1755 unsigned int count = 0, i, q;
1756 signed int xcount = 0;
1757 uint64_t val, *stats_ptr;
1758 uint16_t nb_rxqs, nb_txqs;
1760 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1762 dev = &rte_eth_devices[port_id];
1764 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1765 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1767 /* Return generic statistics */
1768 count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
1769 (nb_txqs * RTE_NB_TXQ_STATS);
1771 /* implemented by the driver */
1772 if (dev->dev_ops->xstats_get != NULL) {
1773 /* Retrieve the xstats from the driver at the end of the
1776 xcount = (*dev->dev_ops->xstats_get)(dev,
1777 xstats ? xstats + count : NULL,
1778 (n > count) ? n - count : 0);
1784 if (n < count + xcount || xstats == NULL)
1785 return count + xcount;
1787 /* now fill the xstats structure */
1789 rte_eth_stats_get(port_id, ð_stats);
1792 for (i = 0; i < RTE_NB_STATS; i++) {
1793 stats_ptr = RTE_PTR_ADD(ð_stats,
1794 rte_stats_strings[i].offset);
1796 xstats[count++].value = val;
1800 for (q = 0; q < nb_rxqs; q++) {
1801 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1802 stats_ptr = RTE_PTR_ADD(ð_stats,
1803 rte_rxq_stats_strings[i].offset +
1804 q * sizeof(uint64_t));
1806 xstats[count++].value = val;
1811 for (q = 0; q < nb_txqs; q++) {
1812 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1813 stats_ptr = RTE_PTR_ADD(ð_stats,
1814 rte_txq_stats_strings[i].offset +
1815 q * sizeof(uint64_t));
1817 xstats[count++].value = val;
1821 for (i = 0; i < count; i++)
1823 /* add an offset to driver-specific stats */
1824 for ( ; i < count + xcount; i++)
1825 xstats[i].id += count;
1827 return count + xcount;
1830 /* reset ethdev extended statistics */
1832 rte_eth_xstats_reset(uint8_t port_id)
1834 struct rte_eth_dev *dev;
1836 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1837 dev = &rte_eth_devices[port_id];
1839 /* implemented by the driver */
1840 if (dev->dev_ops->xstats_reset != NULL) {
1841 (*dev->dev_ops->xstats_reset)(dev);
1845 /* fallback to default */
1846 rte_eth_stats_reset(port_id);
1850 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1853 struct rte_eth_dev *dev;
1855 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1857 dev = &rte_eth_devices[port_id];
1859 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1860 return (*dev->dev_ops->queue_stats_mapping_set)
1861 (dev, queue_id, stat_idx, is_rx);
1866 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1869 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1875 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1878 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1883 rte_eth_dev_fw_version_get(uint8_t port_id, char *fw_version, size_t fw_size)
1885 struct rte_eth_dev *dev;
1887 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1888 dev = &rte_eth_devices[port_id];
1890 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP);
1891 return (*dev->dev_ops->fw_version_get)(dev, fw_version, fw_size);
1895 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1897 struct rte_eth_dev *dev;
1898 const struct rte_eth_desc_lim lim = {
1899 .nb_max = UINT16_MAX,
1904 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1905 dev = &rte_eth_devices[port_id];
1907 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1908 dev_info->rx_desc_lim = lim;
1909 dev_info->tx_desc_lim = lim;
1911 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1912 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1913 dev_info->driver_name = dev->device->driver->name;
1914 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
1915 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
1919 rte_eth_dev_get_supported_ptypes(uint8_t port_id, uint32_t ptype_mask,
1920 uint32_t *ptypes, int num)
1923 struct rte_eth_dev *dev;
1924 const uint32_t *all_ptypes;
1926 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1927 dev = &rte_eth_devices[port_id];
1928 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
1929 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
1934 for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
1935 if (all_ptypes[i] & ptype_mask) {
1937 ptypes[j] = all_ptypes[i];
1945 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1947 struct rte_eth_dev *dev;
1949 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1950 dev = &rte_eth_devices[port_id];
1951 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1956 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1958 struct rte_eth_dev *dev;
1960 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1962 dev = &rte_eth_devices[port_id];
1963 *mtu = dev->data->mtu;
1968 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1971 struct rte_eth_dev *dev;
1973 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1974 dev = &rte_eth_devices[port_id];
1975 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1977 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1979 dev->data->mtu = mtu;
1985 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1987 struct rte_eth_dev *dev;
1990 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1991 dev = &rte_eth_devices[port_id];
1992 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1993 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1997 if (vlan_id > 4095) {
1998 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1999 port_id, (unsigned) vlan_id);
2002 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
2004 ret = (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
2006 struct rte_vlan_filter_conf *vfc;
2010 vfc = &dev->data->vlan_filter_conf;
2011 vidx = vlan_id / 64;
2012 vbit = vlan_id % 64;
2015 vfc->ids[vidx] |= UINT64_C(1) << vbit;
2017 vfc->ids[vidx] &= ~(UINT64_C(1) << vbit);
2024 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
2026 struct rte_eth_dev *dev;
2028 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2029 dev = &rte_eth_devices[port_id];
2030 if (rx_queue_id >= dev->data->nb_rx_queues) {
2031 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
2035 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
2036 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
2042 rte_eth_dev_set_vlan_ether_type(uint8_t port_id,
2043 enum rte_vlan_type vlan_type,
2046 struct rte_eth_dev *dev;
2048 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2049 dev = &rte_eth_devices[port_id];
2050 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
2052 return (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type, tpid);
2056 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
2058 struct rte_eth_dev *dev;
2063 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2064 dev = &rte_eth_devices[port_id];
2066 /*check which option changed by application*/
2067 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
2068 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
2070 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
2071 mask |= ETH_VLAN_STRIP_MASK;
2074 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
2075 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
2077 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
2078 mask |= ETH_VLAN_FILTER_MASK;
2081 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
2082 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
2084 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
2085 mask |= ETH_VLAN_EXTEND_MASK;
2092 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
2093 (*dev->dev_ops->vlan_offload_set)(dev, mask);
2099 rte_eth_dev_get_vlan_offload(uint8_t port_id)
2101 struct rte_eth_dev *dev;
2104 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2105 dev = &rte_eth_devices[port_id];
2107 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
2108 ret |= ETH_VLAN_STRIP_OFFLOAD;
2110 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
2111 ret |= ETH_VLAN_FILTER_OFFLOAD;
2113 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
2114 ret |= ETH_VLAN_EXTEND_OFFLOAD;
2120 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
2122 struct rte_eth_dev *dev;
2124 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2125 dev = &rte_eth_devices[port_id];
2126 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
2127 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
2133 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2135 struct rte_eth_dev *dev;
2137 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2138 dev = &rte_eth_devices[port_id];
2139 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2140 memset(fc_conf, 0, sizeof(*fc_conf));
2141 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
2145 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2147 struct rte_eth_dev *dev;
2149 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2150 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2151 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2155 dev = &rte_eth_devices[port_id];
2156 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2157 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
2161 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
2163 struct rte_eth_dev *dev;
2165 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2166 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2167 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2171 dev = &rte_eth_devices[port_id];
2172 /* High water, low water validation are device specific */
2173 if (*dev->dev_ops->priority_flow_ctrl_set)
2174 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
2179 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2187 num = (reta_size + RTE_RETA_GROUP_SIZE - 1) / RTE_RETA_GROUP_SIZE;
2188 for (i = 0; i < num; i++) {
2189 if (reta_conf[i].mask)
2197 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2201 uint16_t i, idx, shift;
2207 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
2211 for (i = 0; i < reta_size; i++) {
2212 idx = i / RTE_RETA_GROUP_SIZE;
2213 shift = i % RTE_RETA_GROUP_SIZE;
2214 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2215 (reta_conf[idx].reta[shift] >= max_rxq)) {
2216 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2217 "the maximum rxq index: %u\n", idx, shift,
2218 reta_conf[idx].reta[shift], max_rxq);
2227 rte_eth_dev_rss_reta_update(uint8_t port_id,
2228 struct rte_eth_rss_reta_entry64 *reta_conf,
2231 struct rte_eth_dev *dev;
2234 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2235 /* Check mask bits */
2236 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2240 dev = &rte_eth_devices[port_id];
2242 /* Check entry value */
2243 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2244 dev->data->nb_rx_queues);
2248 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2249 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2253 rte_eth_dev_rss_reta_query(uint8_t port_id,
2254 struct rte_eth_rss_reta_entry64 *reta_conf,
2257 struct rte_eth_dev *dev;
2260 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2262 /* Check mask bits */
2263 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2267 dev = &rte_eth_devices[port_id];
2268 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2269 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2273 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2275 struct rte_eth_dev *dev;
2276 uint16_t rss_hash_protos;
2278 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2279 rss_hash_protos = rss_conf->rss_hf;
2280 if ((rss_hash_protos != 0) &&
2281 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2282 RTE_PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2286 dev = &rte_eth_devices[port_id];
2287 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2288 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2292 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2293 struct rte_eth_rss_conf *rss_conf)
2295 struct rte_eth_dev *dev;
2297 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2298 dev = &rte_eth_devices[port_id];
2299 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2300 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2304 rte_eth_dev_udp_tunnel_port_add(uint8_t port_id,
2305 struct rte_eth_udp_tunnel *udp_tunnel)
2307 struct rte_eth_dev *dev;
2309 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2310 if (udp_tunnel == NULL) {
2311 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2315 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2316 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2320 dev = &rte_eth_devices[port_id];
2321 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
2322 return (*dev->dev_ops->udp_tunnel_port_add)(dev, udp_tunnel);
2326 rte_eth_dev_udp_tunnel_port_delete(uint8_t port_id,
2327 struct rte_eth_udp_tunnel *udp_tunnel)
2329 struct rte_eth_dev *dev;
2331 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2332 dev = &rte_eth_devices[port_id];
2334 if (udp_tunnel == NULL) {
2335 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2339 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2340 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2344 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
2345 return (*dev->dev_ops->udp_tunnel_port_del)(dev, udp_tunnel);
2349 rte_eth_led_on(uint8_t port_id)
2351 struct rte_eth_dev *dev;
2353 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2354 dev = &rte_eth_devices[port_id];
2355 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2356 return (*dev->dev_ops->dev_led_on)(dev);
2360 rte_eth_led_off(uint8_t port_id)
2362 struct rte_eth_dev *dev;
2364 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2365 dev = &rte_eth_devices[port_id];
2366 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2367 return (*dev->dev_ops->dev_led_off)(dev);
2371 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2375 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2377 struct rte_eth_dev_info dev_info;
2378 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2381 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2382 rte_eth_dev_info_get(port_id, &dev_info);
2384 for (i = 0; i < dev_info.max_mac_addrs; i++)
2385 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2391 static const struct ether_addr null_mac_addr;
2394 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2397 struct rte_eth_dev *dev;
2402 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2403 dev = &rte_eth_devices[port_id];
2404 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2406 if (is_zero_ether_addr(addr)) {
2407 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2411 if (pool >= ETH_64_POOLS) {
2412 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2416 index = get_mac_addr_index(port_id, addr);
2418 index = get_mac_addr_index(port_id, &null_mac_addr);
2420 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2425 pool_mask = dev->data->mac_pool_sel[index];
2427 /* Check if both MAC address and pool is already there, and do nothing */
2428 if (pool_mask & (1ULL << pool))
2433 ret = (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2436 /* Update address in NIC data structure */
2437 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2439 /* Update pool bitmap in NIC data structure */
2440 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2447 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2449 struct rte_eth_dev *dev;
2452 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2453 dev = &rte_eth_devices[port_id];
2454 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2456 index = get_mac_addr_index(port_id, addr);
2458 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2460 } else if (index < 0)
2461 return 0; /* Do nothing if address wasn't found */
2464 (*dev->dev_ops->mac_addr_remove)(dev, index);
2466 /* Update address in NIC data structure */
2467 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2469 /* reset pool bitmap */
2470 dev->data->mac_pool_sel[index] = 0;
2476 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2478 struct rte_eth_dev *dev;
2480 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2482 if (!is_valid_assigned_ether_addr(addr))
2485 dev = &rte_eth_devices[port_id];
2486 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2488 /* Update default address in NIC data structure */
2489 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2491 (*dev->dev_ops->mac_addr_set)(dev, addr);
2498 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2502 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2504 struct rte_eth_dev_info dev_info;
2505 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2508 rte_eth_dev_info_get(port_id, &dev_info);
2509 if (!dev->data->hash_mac_addrs)
2512 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2513 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2514 ETHER_ADDR_LEN) == 0)
2521 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2526 struct rte_eth_dev *dev;
2528 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2530 dev = &rte_eth_devices[port_id];
2531 if (is_zero_ether_addr(addr)) {
2532 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2537 index = get_hash_mac_addr_index(port_id, addr);
2538 /* Check if it's already there, and do nothing */
2539 if ((index >= 0) && (on))
2544 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2545 "set in UTA\n", port_id);
2549 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2551 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2557 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2558 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2560 /* Update address in NIC data structure */
2562 ether_addr_copy(addr,
2563 &dev->data->hash_mac_addrs[index]);
2565 ether_addr_copy(&null_mac_addr,
2566 &dev->data->hash_mac_addrs[index]);
2573 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2575 struct rte_eth_dev *dev;
2577 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2579 dev = &rte_eth_devices[port_id];
2581 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2582 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2585 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2588 struct rte_eth_dev *dev;
2589 struct rte_eth_dev_info dev_info;
2590 struct rte_eth_link link;
2592 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2594 dev = &rte_eth_devices[port_id];
2595 rte_eth_dev_info_get(port_id, &dev_info);
2596 link = dev->data->dev_link;
2598 if (queue_idx > dev_info.max_tx_queues) {
2599 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2600 "invalid queue id=%d\n", port_id, queue_idx);
2604 if (tx_rate > link.link_speed) {
2605 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2606 "bigger than link speed= %d\n",
2607 tx_rate, link.link_speed);
2611 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2612 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2616 rte_eth_mirror_rule_set(uint8_t port_id,
2617 struct rte_eth_mirror_conf *mirror_conf,
2618 uint8_t rule_id, uint8_t on)
2620 struct rte_eth_dev *dev;
2622 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2623 if (mirror_conf->rule_type == 0) {
2624 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2628 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2629 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2634 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2635 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2636 (mirror_conf->pool_mask == 0)) {
2637 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2641 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2642 mirror_conf->vlan.vlan_mask == 0) {
2643 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2647 dev = &rte_eth_devices[port_id];
2648 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2650 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2654 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2656 struct rte_eth_dev *dev;
2658 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2660 dev = &rte_eth_devices[port_id];
2661 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2663 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2667 rte_eth_dev_callback_register(uint8_t port_id,
2668 enum rte_eth_event_type event,
2669 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2671 struct rte_eth_dev *dev;
2672 struct rte_eth_dev_callback *user_cb;
2677 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2679 dev = &rte_eth_devices[port_id];
2680 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2682 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2683 if (user_cb->cb_fn == cb_fn &&
2684 user_cb->cb_arg == cb_arg &&
2685 user_cb->event == event) {
2690 /* create a new callback. */
2691 if (user_cb == NULL) {
2692 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2693 sizeof(struct rte_eth_dev_callback), 0);
2694 if (user_cb != NULL) {
2695 user_cb->cb_fn = cb_fn;
2696 user_cb->cb_arg = cb_arg;
2697 user_cb->event = event;
2698 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2702 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2703 return (user_cb == NULL) ? -ENOMEM : 0;
2707 rte_eth_dev_callback_unregister(uint8_t port_id,
2708 enum rte_eth_event_type event,
2709 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2712 struct rte_eth_dev *dev;
2713 struct rte_eth_dev_callback *cb, *next;
2718 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2720 dev = &rte_eth_devices[port_id];
2721 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2724 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2726 next = TAILQ_NEXT(cb, next);
2728 if (cb->cb_fn != cb_fn || cb->event != event ||
2729 (cb->cb_arg != (void *)-1 &&
2730 cb->cb_arg != cb_arg))
2734 * if this callback is not executing right now,
2737 if (cb->active == 0) {
2738 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2745 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2750 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2751 enum rte_eth_event_type event, void *cb_arg, void *ret_param)
2753 struct rte_eth_dev_callback *cb_lst;
2754 struct rte_eth_dev_callback dev_cb;
2757 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2758 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2759 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2764 dev_cb.cb_arg = cb_arg;
2765 if (ret_param != NULL)
2766 dev_cb.ret_param = ret_param;
2768 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2769 rc = dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2770 dev_cb.cb_arg, dev_cb.ret_param);
2771 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2774 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2779 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
2782 struct rte_eth_dev *dev;
2783 struct rte_intr_handle *intr_handle;
2787 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2789 dev = &rte_eth_devices[port_id];
2791 if (!dev->intr_handle) {
2792 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
2796 intr_handle = dev->intr_handle;
2797 if (!intr_handle->intr_vec) {
2798 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2802 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2803 vec = intr_handle->intr_vec[qid];
2804 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2805 if (rc && rc != -EEXIST) {
2806 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2807 " op %d epfd %d vec %u\n",
2808 port_id, qid, op, epfd, vec);
2815 const struct rte_memzone *
2816 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2817 uint16_t queue_id, size_t size, unsigned align,
2820 char z_name[RTE_MEMZONE_NAMESIZE];
2821 const struct rte_memzone *mz;
2823 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2824 dev->device->driver->name, ring_name,
2825 dev->data->port_id, queue_id);
2827 mz = rte_memzone_lookup(z_name);
2831 if (rte_xen_dom0_supported())
2832 return rte_memzone_reserve_bounded(z_name, size, socket_id,
2833 0, align, RTE_PGSIZE_2M);
2835 return rte_memzone_reserve_aligned(z_name, size, socket_id,
2840 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
2841 int epfd, int op, void *data)
2844 struct rte_eth_dev *dev;
2845 struct rte_intr_handle *intr_handle;
2848 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2850 dev = &rte_eth_devices[port_id];
2851 if (queue_id >= dev->data->nb_rx_queues) {
2852 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
2856 if (!dev->intr_handle) {
2857 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
2861 intr_handle = dev->intr_handle;
2862 if (!intr_handle->intr_vec) {
2863 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2867 vec = intr_handle->intr_vec[queue_id];
2868 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2869 if (rc && rc != -EEXIST) {
2870 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2871 " op %d epfd %d vec %u\n",
2872 port_id, queue_id, op, epfd, vec);
2880 rte_eth_dev_rx_intr_enable(uint8_t port_id,
2883 struct rte_eth_dev *dev;
2885 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2887 dev = &rte_eth_devices[port_id];
2889 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
2890 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
2894 rte_eth_dev_rx_intr_disable(uint8_t port_id,
2897 struct rte_eth_dev *dev;
2899 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2901 dev = &rte_eth_devices[port_id];
2903 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
2904 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
2909 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
2911 struct rte_eth_dev *dev;
2913 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2915 dev = &rte_eth_devices[port_id];
2916 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2917 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
2918 RTE_ETH_FILTER_NOP, NULL);
2922 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
2923 enum rte_filter_op filter_op, void *arg)
2925 struct rte_eth_dev *dev;
2927 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2929 dev = &rte_eth_devices[port_id];
2930 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2931 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
2935 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
2936 rte_rx_callback_fn fn, void *user_param)
2938 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2939 rte_errno = ENOTSUP;
2942 /* check input parameters */
2943 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2944 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2948 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2956 cb->param = user_param;
2958 rte_spinlock_lock(&rte_eth_rx_cb_lock);
2959 /* Add the callbacks in fifo order. */
2960 struct rte_eth_rxtx_callback *tail =
2961 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2964 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2971 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
2977 rte_eth_add_first_rx_callback(uint8_t port_id, uint16_t queue_id,
2978 rte_rx_callback_fn fn, void *user_param)
2980 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2981 rte_errno = ENOTSUP;
2984 /* check input parameters */
2985 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2986 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2991 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2999 cb->param = user_param;
3001 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3002 /* Add the callbacks at fisrt position*/
3003 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3005 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3006 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3012 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
3013 rte_tx_callback_fn fn, void *user_param)
3015 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3016 rte_errno = ENOTSUP;
3019 /* check input parameters */
3020 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3021 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3026 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3034 cb->param = user_param;
3036 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3037 /* Add the callbacks in fifo order. */
3038 struct rte_eth_rxtx_callback *tail =
3039 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3042 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3049 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3055 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3056 struct rte_eth_rxtx_callback *user_cb)
3058 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3061 /* Check input parameters. */
3062 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3063 if (user_cb == NULL ||
3064 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
3067 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3068 struct rte_eth_rxtx_callback *cb;
3069 struct rte_eth_rxtx_callback **prev_cb;
3072 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3073 prev_cb = &dev->post_rx_burst_cbs[queue_id];
3074 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3076 if (cb == user_cb) {
3077 /* Remove the user cb from the callback list. */
3078 *prev_cb = cb->next;
3083 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3089 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3090 struct rte_eth_rxtx_callback *user_cb)
3092 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3095 /* Check input parameters. */
3096 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3097 if (user_cb == NULL ||
3098 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
3101 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3103 struct rte_eth_rxtx_callback *cb;
3104 struct rte_eth_rxtx_callback **prev_cb;
3106 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3107 prev_cb = &dev->pre_tx_burst_cbs[queue_id];
3108 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3110 if (cb == user_cb) {
3111 /* Remove the user cb from the callback list. */
3112 *prev_cb = cb->next;
3117 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3123 rte_eth_rx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3124 struct rte_eth_rxq_info *qinfo)
3126 struct rte_eth_dev *dev;
3128 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3133 dev = &rte_eth_devices[port_id];
3134 if (queue_id >= dev->data->nb_rx_queues) {
3135 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3139 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3141 memset(qinfo, 0, sizeof(*qinfo));
3142 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3147 rte_eth_tx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3148 struct rte_eth_txq_info *qinfo)
3150 struct rte_eth_dev *dev;
3152 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3157 dev = &rte_eth_devices[port_id];
3158 if (queue_id >= dev->data->nb_tx_queues) {
3159 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3163 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3165 memset(qinfo, 0, sizeof(*qinfo));
3166 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3171 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3172 struct ether_addr *mc_addr_set,
3173 uint32_t nb_mc_addr)
3175 struct rte_eth_dev *dev;
3177 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3179 dev = &rte_eth_devices[port_id];
3180 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3181 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3185 rte_eth_timesync_enable(uint8_t port_id)
3187 struct rte_eth_dev *dev;
3189 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3190 dev = &rte_eth_devices[port_id];
3192 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3193 return (*dev->dev_ops->timesync_enable)(dev);
3197 rte_eth_timesync_disable(uint8_t port_id)
3199 struct rte_eth_dev *dev;
3201 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3202 dev = &rte_eth_devices[port_id];
3204 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3205 return (*dev->dev_ops->timesync_disable)(dev);
3209 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3212 struct rte_eth_dev *dev;
3214 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3215 dev = &rte_eth_devices[port_id];
3217 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3218 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3222 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3224 struct rte_eth_dev *dev;
3226 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3227 dev = &rte_eth_devices[port_id];
3229 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3230 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3234 rte_eth_timesync_adjust_time(uint8_t port_id, int64_t delta)
3236 struct rte_eth_dev *dev;
3238 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3239 dev = &rte_eth_devices[port_id];
3241 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3242 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3246 rte_eth_timesync_read_time(uint8_t port_id, struct timespec *timestamp)
3248 struct rte_eth_dev *dev;
3250 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3251 dev = &rte_eth_devices[port_id];
3253 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3254 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3258 rte_eth_timesync_write_time(uint8_t port_id, const struct timespec *timestamp)
3260 struct rte_eth_dev *dev;
3262 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3263 dev = &rte_eth_devices[port_id];
3265 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3266 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3270 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3272 struct rte_eth_dev *dev;
3274 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3276 dev = &rte_eth_devices[port_id];
3277 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3278 return (*dev->dev_ops->get_reg)(dev, info);
3282 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3284 struct rte_eth_dev *dev;
3286 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3288 dev = &rte_eth_devices[port_id];
3289 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3290 return (*dev->dev_ops->get_eeprom_length)(dev);
3294 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3296 struct rte_eth_dev *dev;
3298 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3300 dev = &rte_eth_devices[port_id];
3301 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3302 return (*dev->dev_ops->get_eeprom)(dev, info);
3306 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3308 struct rte_eth_dev *dev;
3310 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3312 dev = &rte_eth_devices[port_id];
3313 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3314 return (*dev->dev_ops->set_eeprom)(dev, info);
3318 rte_eth_dev_get_dcb_info(uint8_t port_id,
3319 struct rte_eth_dcb_info *dcb_info)
3321 struct rte_eth_dev *dev;
3323 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3325 dev = &rte_eth_devices[port_id];
3326 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3328 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3329 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3333 rte_eth_dev_l2_tunnel_eth_type_conf(uint8_t port_id,
3334 struct rte_eth_l2_tunnel_conf *l2_tunnel)
3336 struct rte_eth_dev *dev;
3338 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3339 if (l2_tunnel == NULL) {
3340 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3344 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3345 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
3349 dev = &rte_eth_devices[port_id];
3350 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
3352 return (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev, l2_tunnel);
3356 rte_eth_dev_l2_tunnel_offload_set(uint8_t port_id,
3357 struct rte_eth_l2_tunnel_conf *l2_tunnel,
3361 struct rte_eth_dev *dev;
3363 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3365 if (l2_tunnel == NULL) {
3366 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3370 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3371 RTE_PMD_DEBUG_TRACE("Invalid tunnel type.\n");
3376 RTE_PMD_DEBUG_TRACE("Mask should have a value.\n");
3380 dev = &rte_eth_devices[port_id];
3381 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
3383 return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);
3387 rte_eth_dev_adjust_nb_desc(uint16_t *nb_desc,
3388 const struct rte_eth_desc_lim *desc_lim)
3390 if (desc_lim->nb_align != 0)
3391 *nb_desc = RTE_ALIGN_CEIL(*nb_desc, desc_lim->nb_align);
3393 if (desc_lim->nb_max != 0)
3394 *nb_desc = RTE_MIN(*nb_desc, desc_lim->nb_max);
3396 *nb_desc = RTE_MAX(*nb_desc, desc_lim->nb_min);
3400 rte_eth_dev_adjust_nb_rx_tx_desc(uint8_t port_id,
3401 uint16_t *nb_rx_desc,
3402 uint16_t *nb_tx_desc)
3404 struct rte_eth_dev *dev;
3405 struct rte_eth_dev_info dev_info;
3407 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3409 dev = &rte_eth_devices[port_id];
3410 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
3412 rte_eth_dev_info_get(port_id, &dev_info);
3414 if (nb_rx_desc != NULL)
3415 rte_eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim);
3417 if (nb_tx_desc != NULL)
3418 rte_eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim);