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"
70 #include "ethdev_profile.h"
72 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
73 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
74 static struct rte_eth_dev_data *rte_eth_dev_data;
75 static uint8_t eth_dev_last_created_port;
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;
218 rte_eth_dev_allocate(const char *name)
221 struct rte_eth_dev *eth_dev;
223 port_id = rte_eth_dev_find_free_port();
224 if (port_id == RTE_MAX_ETHPORTS) {
225 RTE_PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
229 if (rte_eth_dev_data == NULL)
230 rte_eth_dev_data_alloc();
232 if (rte_eth_dev_allocated(name) != NULL) {
233 RTE_PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n",
238 memset(&rte_eth_dev_data[port_id], 0, sizeof(struct rte_eth_dev_data));
239 eth_dev = eth_dev_get(port_id);
240 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
241 eth_dev->data->port_id = port_id;
242 eth_dev->data->mtu = ETHER_MTU;
248 * Attach to a port already registered by the primary process, which
249 * makes sure that the same device would have the same port id both
250 * in the primary and secondary process.
253 rte_eth_dev_attach_secondary(const char *name)
256 struct rte_eth_dev *eth_dev;
258 if (rte_eth_dev_data == NULL)
259 rte_eth_dev_data_alloc();
261 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
262 if (strcmp(rte_eth_dev_data[i].name, name) == 0)
265 if (i == RTE_MAX_ETHPORTS) {
267 "device %s is not driven by the primary process\n",
272 eth_dev = eth_dev_get(i);
273 RTE_ASSERT(eth_dev->data->port_id == i);
279 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
284 eth_dev->state = RTE_ETH_DEV_UNUSED;
289 rte_eth_dev_is_valid_port(uint8_t port_id)
291 if (port_id >= RTE_MAX_ETHPORTS ||
292 (rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
293 rte_eth_devices[port_id].state != RTE_ETH_DEV_DEFERRED))
300 rte_eth_dev_socket_id(uint8_t port_id)
302 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
303 return rte_eth_devices[port_id].data->numa_node;
307 rte_eth_dev_count(void)
314 RTE_ETH_FOREACH_DEV(p)
321 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
325 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
328 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
332 /* shouldn't check 'rte_eth_devices[i].data',
333 * because it might be overwritten by VDEV PMD */
334 tmp = rte_eth_devices[port_id].device->name;
340 rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
346 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
350 RTE_ETH_FOREACH_DEV(i) {
351 if (!rte_eth_devices[i].device)
354 ret = strncmp(name, rte_eth_devices[i].device->name,
365 rte_eth_dev_is_detachable(uint8_t port_id)
369 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
371 dev_flags = rte_eth_devices[port_id].data->dev_flags;
372 if ((dev_flags & RTE_ETH_DEV_DETACHABLE) &&
373 (!(dev_flags & RTE_ETH_DEV_BONDED_SLAVE)))
379 /* attach the new device, then store port_id of the device */
381 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
384 int current = rte_eth_dev_count();
388 if ((devargs == NULL) || (port_id == NULL)) {
393 /* parse devargs, then retrieve device name and args */
394 if (rte_eal_parse_devargs_str(devargs, &name, &args))
397 ret = rte_eal_dev_attach(name, args);
401 /* no point looking at the port count if no port exists */
402 if (!rte_eth_dev_count()) {
403 RTE_LOG(ERR, EAL, "No port found for device (%s)\n", name);
408 /* if nothing happened, there is a bug here, since some driver told us
409 * it did attach a device, but did not create a port.
411 if (current == rte_eth_dev_count()) {
416 *port_id = eth_dev_last_created_port;
425 /* detach the device, then store the name of the device */
427 rte_eth_dev_detach(uint8_t port_id, char *name)
436 /* FIXME: move this to eal, once device flags are relocated there */
437 if (rte_eth_dev_is_detachable(port_id))
440 snprintf(name, RTE_DEV_NAME_MAX_LEN, "%s",
441 rte_eth_devices[port_id].device->name);
443 ret = rte_eal_dev_detach(rte_eth_devices[port_id].device);
447 rte_eth_devices[port_id].state = RTE_ETH_DEV_UNUSED;
455 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
457 uint16_t old_nb_queues = dev->data->nb_rx_queues;
461 if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */
462 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
463 sizeof(dev->data->rx_queues[0]) * nb_queues,
464 RTE_CACHE_LINE_SIZE);
465 if (dev->data->rx_queues == NULL) {
466 dev->data->nb_rx_queues = 0;
469 } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */
470 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
472 rxq = dev->data->rx_queues;
474 for (i = nb_queues; i < old_nb_queues; i++)
475 (*dev->dev_ops->rx_queue_release)(rxq[i]);
476 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
477 RTE_CACHE_LINE_SIZE);
480 if (nb_queues > old_nb_queues) {
481 uint16_t new_qs = nb_queues - old_nb_queues;
483 memset(rxq + old_nb_queues, 0,
484 sizeof(rxq[0]) * new_qs);
487 dev->data->rx_queues = rxq;
489 } else if (dev->data->rx_queues != NULL && nb_queues == 0) {
490 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
492 rxq = dev->data->rx_queues;
494 for (i = nb_queues; i < old_nb_queues; i++)
495 (*dev->dev_ops->rx_queue_release)(rxq[i]);
497 rte_free(dev->data->rx_queues);
498 dev->data->rx_queues = NULL;
500 dev->data->nb_rx_queues = nb_queues;
505 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
507 struct rte_eth_dev *dev;
509 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
511 dev = &rte_eth_devices[port_id];
512 if (rx_queue_id >= dev->data->nb_rx_queues) {
513 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
517 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
519 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
520 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
521 " already started\n",
522 rx_queue_id, port_id);
526 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
531 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
533 struct rte_eth_dev *dev;
535 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
537 dev = &rte_eth_devices[port_id];
538 if (rx_queue_id >= dev->data->nb_rx_queues) {
539 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
543 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
545 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
546 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
547 " already stopped\n",
548 rx_queue_id, port_id);
552 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
557 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
559 struct rte_eth_dev *dev;
561 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
563 dev = &rte_eth_devices[port_id];
564 if (tx_queue_id >= dev->data->nb_tx_queues) {
565 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
569 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
571 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
572 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
573 " already started\n",
574 tx_queue_id, port_id);
578 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
583 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
585 struct rte_eth_dev *dev;
587 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
589 dev = &rte_eth_devices[port_id];
590 if (tx_queue_id >= dev->data->nb_tx_queues) {
591 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
595 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
597 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
598 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
599 " already stopped\n",
600 tx_queue_id, port_id);
604 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
609 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
611 uint16_t old_nb_queues = dev->data->nb_tx_queues;
615 if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */
616 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
617 sizeof(dev->data->tx_queues[0]) * nb_queues,
618 RTE_CACHE_LINE_SIZE);
619 if (dev->data->tx_queues == NULL) {
620 dev->data->nb_tx_queues = 0;
623 } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */
624 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
626 txq = dev->data->tx_queues;
628 for (i = nb_queues; i < old_nb_queues; i++)
629 (*dev->dev_ops->tx_queue_release)(txq[i]);
630 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
631 RTE_CACHE_LINE_SIZE);
634 if (nb_queues > old_nb_queues) {
635 uint16_t new_qs = nb_queues - old_nb_queues;
637 memset(txq + old_nb_queues, 0,
638 sizeof(txq[0]) * new_qs);
641 dev->data->tx_queues = txq;
643 } else if (dev->data->tx_queues != NULL && nb_queues == 0) {
644 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
646 txq = dev->data->tx_queues;
648 for (i = nb_queues; i < old_nb_queues; i++)
649 (*dev->dev_ops->tx_queue_release)(txq[i]);
651 rte_free(dev->data->tx_queues);
652 dev->data->tx_queues = NULL;
654 dev->data->nb_tx_queues = nb_queues;
659 rte_eth_speed_bitflag(uint32_t speed, int duplex)
662 case ETH_SPEED_NUM_10M:
663 return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD;
664 case ETH_SPEED_NUM_100M:
665 return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD;
666 case ETH_SPEED_NUM_1G:
667 return ETH_LINK_SPEED_1G;
668 case ETH_SPEED_NUM_2_5G:
669 return ETH_LINK_SPEED_2_5G;
670 case ETH_SPEED_NUM_5G:
671 return ETH_LINK_SPEED_5G;
672 case ETH_SPEED_NUM_10G:
673 return ETH_LINK_SPEED_10G;
674 case ETH_SPEED_NUM_20G:
675 return ETH_LINK_SPEED_20G;
676 case ETH_SPEED_NUM_25G:
677 return ETH_LINK_SPEED_25G;
678 case ETH_SPEED_NUM_40G:
679 return ETH_LINK_SPEED_40G;
680 case ETH_SPEED_NUM_50G:
681 return ETH_LINK_SPEED_50G;
682 case ETH_SPEED_NUM_56G:
683 return ETH_LINK_SPEED_56G;
684 case ETH_SPEED_NUM_100G:
685 return ETH_LINK_SPEED_100G;
692 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
693 const struct rte_eth_conf *dev_conf)
695 struct rte_eth_dev *dev;
696 struct rte_eth_dev_info dev_info;
699 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
701 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
703 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
704 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
708 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
710 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
711 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
715 dev = &rte_eth_devices[port_id];
717 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
718 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
720 if (dev->data->dev_started) {
722 "port %d must be stopped to allow configuration\n", port_id);
726 /* Copy the dev_conf parameter into the dev structure */
727 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
730 * Check that the numbers of RX and TX queues are not greater
731 * than the maximum number of RX and TX queues supported by the
734 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
736 if (nb_rx_q == 0 && nb_tx_q == 0) {
737 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d both rx and tx queue cannot be 0\n", port_id);
741 if (nb_rx_q > dev_info.max_rx_queues) {
742 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
743 port_id, nb_rx_q, dev_info.max_rx_queues);
747 if (nb_tx_q > dev_info.max_tx_queues) {
748 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
749 port_id, nb_tx_q, dev_info.max_tx_queues);
753 /* Check that the device supports requested interrupts */
754 if ((dev_conf->intr_conf.lsc == 1) &&
755 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
756 RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
757 dev->device->driver->name);
760 if ((dev_conf->intr_conf.rmv == 1) &&
761 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_RMV))) {
762 RTE_PMD_DEBUG_TRACE("driver %s does not support rmv\n",
763 dev->device->driver->name);
768 * If jumbo frames are enabled, check that the maximum RX packet
769 * length is supported by the configured device.
771 if (dev_conf->rxmode.jumbo_frame == 1) {
772 if (dev_conf->rxmode.max_rx_pkt_len >
773 dev_info.max_rx_pktlen) {
774 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
775 " > max valid value %u\n",
777 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
778 (unsigned)dev_info.max_rx_pktlen);
780 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
781 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
782 " < min valid value %u\n",
784 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
785 (unsigned)ETHER_MIN_LEN);
789 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
790 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
791 /* Use default value */
792 dev->data->dev_conf.rxmode.max_rx_pkt_len =
797 * Setup new number of RX/TX queues and reconfigure device.
799 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
801 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
806 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
808 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
810 rte_eth_dev_rx_queue_config(dev, 0);
814 diag = (*dev->dev_ops->dev_configure)(dev);
816 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
818 rte_eth_dev_rx_queue_config(dev, 0);
819 rte_eth_dev_tx_queue_config(dev, 0);
823 /* Initialize Rx profiling if enabled at compilation time. */
824 diag = __rte_eth_profile_rx_init(port_id, dev);
826 RTE_PMD_DEBUG_TRACE("port%d __rte_eth_profile_rx_init = %d\n",
828 rte_eth_dev_rx_queue_config(dev, 0);
829 rte_eth_dev_tx_queue_config(dev, 0);
837 _rte_eth_dev_reset(struct rte_eth_dev *dev)
839 if (dev->data->dev_started) {
841 "port %d must be stopped to allow reset\n",
846 rte_eth_dev_rx_queue_config(dev, 0);
847 rte_eth_dev_tx_queue_config(dev, 0);
849 memset(&dev->data->dev_conf, 0, sizeof(dev->data->dev_conf));
853 rte_eth_dev_config_restore(uint8_t port_id)
855 struct rte_eth_dev *dev;
856 struct rte_eth_dev_info dev_info;
857 struct ether_addr *addr;
862 dev = &rte_eth_devices[port_id];
864 rte_eth_dev_info_get(port_id, &dev_info);
866 /* replay MAC address configuration including default MAC */
867 addr = &dev->data->mac_addrs[0];
868 if (*dev->dev_ops->mac_addr_set != NULL)
869 (*dev->dev_ops->mac_addr_set)(dev, addr);
870 else if (*dev->dev_ops->mac_addr_add != NULL)
871 (*dev->dev_ops->mac_addr_add)(dev, addr, 0, pool);
873 if (*dev->dev_ops->mac_addr_add != NULL) {
874 for (i = 1; i < dev_info.max_mac_addrs; i++) {
875 addr = &dev->data->mac_addrs[i];
877 /* skip zero address */
878 if (is_zero_ether_addr(addr))
882 pool_mask = dev->data->mac_pool_sel[i];
885 if (pool_mask & 1ULL)
886 (*dev->dev_ops->mac_addr_add)(dev,
894 /* replay promiscuous configuration */
895 if (rte_eth_promiscuous_get(port_id) == 1)
896 rte_eth_promiscuous_enable(port_id);
897 else if (rte_eth_promiscuous_get(port_id) == 0)
898 rte_eth_promiscuous_disable(port_id);
900 /* replay all multicast configuration */
901 if (rte_eth_allmulticast_get(port_id) == 1)
902 rte_eth_allmulticast_enable(port_id);
903 else if (rte_eth_allmulticast_get(port_id) == 0)
904 rte_eth_allmulticast_disable(port_id);
908 rte_eth_dev_start(uint8_t port_id)
910 struct rte_eth_dev *dev;
913 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
915 dev = &rte_eth_devices[port_id];
917 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
919 if (dev->data->dev_started != 0) {
920 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
921 " already started\n",
926 diag = (*dev->dev_ops->dev_start)(dev);
928 dev->data->dev_started = 1;
932 rte_eth_dev_config_restore(port_id);
934 if (dev->data->dev_conf.intr_conf.lsc == 0) {
935 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
936 (*dev->dev_ops->link_update)(dev, 0);
942 rte_eth_dev_stop(uint8_t port_id)
944 struct rte_eth_dev *dev;
946 RTE_ETH_VALID_PORTID_OR_RET(port_id);
947 dev = &rte_eth_devices[port_id];
949 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
951 if (dev->data->dev_started == 0) {
952 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
953 " already stopped\n",
958 dev->data->dev_started = 0;
959 (*dev->dev_ops->dev_stop)(dev);
963 rte_eth_dev_set_link_up(uint8_t port_id)
965 struct rte_eth_dev *dev;
967 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
969 dev = &rte_eth_devices[port_id];
971 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
972 return (*dev->dev_ops->dev_set_link_up)(dev);
976 rte_eth_dev_set_link_down(uint8_t port_id)
978 struct rte_eth_dev *dev;
980 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
982 dev = &rte_eth_devices[port_id];
984 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
985 return (*dev->dev_ops->dev_set_link_down)(dev);
989 rte_eth_dev_close(uint8_t port_id)
991 struct rte_eth_dev *dev;
993 RTE_ETH_VALID_PORTID_OR_RET(port_id);
994 dev = &rte_eth_devices[port_id];
996 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
997 dev->data->dev_started = 0;
998 (*dev->dev_ops->dev_close)(dev);
1000 dev->data->nb_rx_queues = 0;
1001 rte_free(dev->data->rx_queues);
1002 dev->data->rx_queues = NULL;
1003 dev->data->nb_tx_queues = 0;
1004 rte_free(dev->data->tx_queues);
1005 dev->data->tx_queues = NULL;
1009 rte_eth_dev_reset(uint8_t port_id)
1011 struct rte_eth_dev *dev;
1014 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1015 dev = &rte_eth_devices[port_id];
1017 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_reset, -ENOTSUP);
1019 rte_eth_dev_stop(port_id);
1020 ret = dev->dev_ops->dev_reset(dev);
1026 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1027 uint16_t nb_rx_desc, unsigned int socket_id,
1028 const struct rte_eth_rxconf *rx_conf,
1029 struct rte_mempool *mp)
1032 uint32_t mbp_buf_size;
1033 struct rte_eth_dev *dev;
1034 struct rte_eth_dev_info dev_info;
1037 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1039 dev = &rte_eth_devices[port_id];
1040 if (rx_queue_id >= dev->data->nb_rx_queues) {
1041 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1045 if (dev->data->dev_started) {
1046 RTE_PMD_DEBUG_TRACE(
1047 "port %d must be stopped to allow configuration\n", port_id);
1051 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1052 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1055 * Check the size of the mbuf data buffer.
1056 * This value must be provided in the private data of the memory pool.
1057 * First check that the memory pool has a valid private data.
1059 rte_eth_dev_info_get(port_id, &dev_info);
1060 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1061 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1062 mp->name, (int) mp->private_data_size,
1063 (int) sizeof(struct rte_pktmbuf_pool_private));
1066 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1068 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1069 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1070 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1074 (int)(RTE_PKTMBUF_HEADROOM +
1075 dev_info.min_rx_bufsize),
1076 (int)RTE_PKTMBUF_HEADROOM,
1077 (int)dev_info.min_rx_bufsize);
1081 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1082 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1083 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1085 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1086 "should be: <= %hu, = %hu, and a product of %hu\n",
1088 dev_info.rx_desc_lim.nb_max,
1089 dev_info.rx_desc_lim.nb_min,
1090 dev_info.rx_desc_lim.nb_align);
1094 rxq = dev->data->rx_queues;
1095 if (rxq[rx_queue_id]) {
1096 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release,
1098 (*dev->dev_ops->rx_queue_release)(rxq[rx_queue_id]);
1099 rxq[rx_queue_id] = NULL;
1102 if (rx_conf == NULL)
1103 rx_conf = &dev_info.default_rxconf;
1105 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1106 socket_id, rx_conf, mp);
1108 if (!dev->data->min_rx_buf_size ||
1109 dev->data->min_rx_buf_size > mbp_buf_size)
1110 dev->data->min_rx_buf_size = mbp_buf_size;
1117 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1118 uint16_t nb_tx_desc, unsigned int socket_id,
1119 const struct rte_eth_txconf *tx_conf)
1121 struct rte_eth_dev *dev;
1122 struct rte_eth_dev_info dev_info;
1125 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1127 dev = &rte_eth_devices[port_id];
1128 if (tx_queue_id >= dev->data->nb_tx_queues) {
1129 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1133 if (dev->data->dev_started) {
1134 RTE_PMD_DEBUG_TRACE(
1135 "port %d must be stopped to allow configuration\n", port_id);
1139 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1140 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1142 rte_eth_dev_info_get(port_id, &dev_info);
1144 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1145 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1146 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1147 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1148 "should be: <= %hu, = %hu, and a product of %hu\n",
1150 dev_info.tx_desc_lim.nb_max,
1151 dev_info.tx_desc_lim.nb_min,
1152 dev_info.tx_desc_lim.nb_align);
1156 txq = dev->data->tx_queues;
1157 if (txq[tx_queue_id]) {
1158 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release,
1160 (*dev->dev_ops->tx_queue_release)(txq[tx_queue_id]);
1161 txq[tx_queue_id] = NULL;
1164 if (tx_conf == NULL)
1165 tx_conf = &dev_info.default_txconf;
1167 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1168 socket_id, tx_conf);
1172 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
1173 void *userdata __rte_unused)
1177 for (i = 0; i < unsent; i++)
1178 rte_pktmbuf_free(pkts[i]);
1182 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
1185 uint64_t *count = userdata;
1188 for (i = 0; i < unsent; i++)
1189 rte_pktmbuf_free(pkts[i]);
1195 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
1196 buffer_tx_error_fn cbfn, void *userdata)
1198 buffer->error_callback = cbfn;
1199 buffer->error_userdata = userdata;
1204 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
1211 buffer->size = size;
1212 if (buffer->error_callback == NULL) {
1213 ret = rte_eth_tx_buffer_set_err_callback(
1214 buffer, rte_eth_tx_buffer_drop_callback, NULL);
1221 rte_eth_tx_done_cleanup(uint8_t port_id, uint16_t queue_id, uint32_t free_cnt)
1223 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1225 /* Validate Input Data. Bail if not valid or not supported. */
1226 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1227 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_done_cleanup, -ENOTSUP);
1229 /* Call driver to free pending mbufs. */
1230 return (*dev->dev_ops->tx_done_cleanup)(dev->data->tx_queues[queue_id],
1235 rte_eth_promiscuous_enable(uint8_t port_id)
1237 struct rte_eth_dev *dev;
1239 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1240 dev = &rte_eth_devices[port_id];
1242 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1243 (*dev->dev_ops->promiscuous_enable)(dev);
1244 dev->data->promiscuous = 1;
1248 rte_eth_promiscuous_disable(uint8_t port_id)
1250 struct rte_eth_dev *dev;
1252 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1253 dev = &rte_eth_devices[port_id];
1255 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1256 dev->data->promiscuous = 0;
1257 (*dev->dev_ops->promiscuous_disable)(dev);
1261 rte_eth_promiscuous_get(uint8_t port_id)
1263 struct rte_eth_dev *dev;
1265 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1267 dev = &rte_eth_devices[port_id];
1268 return dev->data->promiscuous;
1272 rte_eth_allmulticast_enable(uint8_t port_id)
1274 struct rte_eth_dev *dev;
1276 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1277 dev = &rte_eth_devices[port_id];
1279 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1280 (*dev->dev_ops->allmulticast_enable)(dev);
1281 dev->data->all_multicast = 1;
1285 rte_eth_allmulticast_disable(uint8_t port_id)
1287 struct rte_eth_dev *dev;
1289 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1290 dev = &rte_eth_devices[port_id];
1292 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1293 dev->data->all_multicast = 0;
1294 (*dev->dev_ops->allmulticast_disable)(dev);
1298 rte_eth_allmulticast_get(uint8_t port_id)
1300 struct rte_eth_dev *dev;
1302 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1304 dev = &rte_eth_devices[port_id];
1305 return dev->data->all_multicast;
1309 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1310 struct rte_eth_link *link)
1312 struct rte_eth_link *dst = link;
1313 struct rte_eth_link *src = &(dev->data->dev_link);
1315 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1316 *(uint64_t *)src) == 0)
1323 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1325 struct rte_eth_dev *dev;
1327 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1328 dev = &rte_eth_devices[port_id];
1330 if (dev->data->dev_conf.intr_conf.lsc != 0)
1331 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1333 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1334 (*dev->dev_ops->link_update)(dev, 1);
1335 *eth_link = dev->data->dev_link;
1340 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1342 struct rte_eth_dev *dev;
1344 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1345 dev = &rte_eth_devices[port_id];
1347 if (dev->data->dev_conf.intr_conf.lsc != 0)
1348 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1350 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1351 (*dev->dev_ops->link_update)(dev, 0);
1352 *eth_link = dev->data->dev_link;
1357 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1359 struct rte_eth_dev *dev;
1361 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1363 dev = &rte_eth_devices[port_id];
1364 memset(stats, 0, sizeof(*stats));
1366 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1367 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1368 (*dev->dev_ops->stats_get)(dev, stats);
1373 rte_eth_stats_reset(uint8_t port_id)
1375 struct rte_eth_dev *dev;
1377 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1378 dev = &rte_eth_devices[port_id];
1380 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1381 (*dev->dev_ops->stats_reset)(dev);
1382 dev->data->rx_mbuf_alloc_failed = 0;
1386 get_xstats_count(uint8_t port_id)
1388 struct rte_eth_dev *dev;
1391 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1392 dev = &rte_eth_devices[port_id];
1393 if (dev->dev_ops->xstats_get_names_by_id != NULL) {
1394 count = (*dev->dev_ops->xstats_get_names_by_id)(dev, NULL,
1399 if (dev->dev_ops->xstats_get_names != NULL) {
1400 count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0);
1406 count += RTE_NB_STATS;
1407 count += RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
1409 count += RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
1415 rte_eth_xstats_get_id_by_name(uint8_t port_id, const char *xstat_name,
1418 int cnt_xstats, idx_xstat;
1420 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1423 RTE_PMD_DEBUG_TRACE("Error: id pointer is NULL\n");
1428 RTE_PMD_DEBUG_TRACE("Error: xstat_name pointer is NULL\n");
1433 cnt_xstats = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
1434 if (cnt_xstats < 0) {
1435 RTE_PMD_DEBUG_TRACE("Error: Cannot get count of xstats\n");
1439 /* Get id-name lookup table */
1440 struct rte_eth_xstat_name xstats_names[cnt_xstats];
1442 if (cnt_xstats != rte_eth_xstats_get_names_by_id(
1443 port_id, xstats_names, cnt_xstats, NULL)) {
1444 RTE_PMD_DEBUG_TRACE("Error: Cannot get xstats lookup\n");
1448 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
1449 if (!strcmp(xstats_names[idx_xstat].name, xstat_name)) {
1459 rte_eth_xstats_get_names_by_id(uint8_t port_id,
1460 struct rte_eth_xstat_name *xstats_names, unsigned int size,
1463 /* Get all xstats */
1465 struct rte_eth_dev *dev;
1466 int cnt_used_entries;
1467 int cnt_expected_entries;
1468 int cnt_driver_entries;
1469 uint32_t idx, id_queue;
1472 cnt_expected_entries = get_xstats_count(port_id);
1473 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1474 (int)size < cnt_expected_entries)
1475 return cnt_expected_entries;
1477 /* port_id checked in get_xstats_count() */
1478 dev = &rte_eth_devices[port_id];
1479 cnt_used_entries = 0;
1481 for (idx = 0; idx < RTE_NB_STATS; idx++) {
1482 snprintf(xstats_names[cnt_used_entries].name,
1483 sizeof(xstats_names[0].name),
1484 "%s", rte_stats_strings[idx].name);
1487 num_q = RTE_MIN(dev->data->nb_rx_queues,
1488 RTE_ETHDEV_QUEUE_STAT_CNTRS);
1489 for (id_queue = 0; id_queue < num_q; id_queue++) {
1490 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1491 snprintf(xstats_names[cnt_used_entries].name,
1492 sizeof(xstats_names[0].name),
1495 rte_rxq_stats_strings[idx].name);
1500 num_q = RTE_MIN(dev->data->nb_tx_queues,
1501 RTE_ETHDEV_QUEUE_STAT_CNTRS);
1502 for (id_queue = 0; id_queue < num_q; id_queue++) {
1503 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
1504 snprintf(xstats_names[cnt_used_entries].name,
1505 sizeof(xstats_names[0].name),
1508 rte_txq_stats_strings[idx].name);
1513 if (dev->dev_ops->xstats_get_names_by_id != NULL) {
1514 /* If there are any driver-specific xstats, append them
1517 cnt_driver_entries =
1518 (*dev->dev_ops->xstats_get_names_by_id)(
1520 xstats_names + cnt_used_entries,
1522 size - cnt_used_entries);
1523 if (cnt_driver_entries < 0)
1524 return cnt_driver_entries;
1525 cnt_used_entries += cnt_driver_entries;
1527 } else if (dev->dev_ops->xstats_get_names != NULL) {
1528 /* If there are any driver-specific xstats, append them
1531 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
1533 xstats_names + cnt_used_entries,
1534 size - cnt_used_entries);
1535 if (cnt_driver_entries < 0)
1536 return cnt_driver_entries;
1537 cnt_used_entries += cnt_driver_entries;
1540 return cnt_used_entries;
1542 /* Get only xstats given by IDS */
1545 struct rte_eth_xstat_name *xstats_names_copy;
1547 len = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
1550 malloc(sizeof(struct rte_eth_xstat_name) * len);
1551 if (!xstats_names_copy) {
1552 RTE_PMD_DEBUG_TRACE(
1553 "ERROR: can't allocate memory for values_copy\n");
1554 free(xstats_names_copy);
1558 rte_eth_xstats_get_names_by_id(port_id, xstats_names_copy,
1561 for (i = 0; i < size; i++) {
1562 if (ids[i] >= len) {
1563 RTE_PMD_DEBUG_TRACE(
1564 "ERROR: id value isn't valid\n");
1567 strcpy(xstats_names[i].name,
1568 xstats_names_copy[ids[i]].name);
1570 free(xstats_names_copy);
1576 rte_eth_xstats_get_names(uint8_t port_id,
1577 struct rte_eth_xstat_name *xstats_names,
1580 struct rte_eth_dev *dev;
1581 int cnt_used_entries;
1582 int cnt_expected_entries;
1583 int cnt_driver_entries;
1584 uint32_t idx, id_queue;
1587 cnt_expected_entries = get_xstats_count(port_id);
1588 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1589 (int)size < cnt_expected_entries)
1590 return cnt_expected_entries;
1592 /* port_id checked in get_xstats_count() */
1593 dev = &rte_eth_devices[port_id];
1594 cnt_used_entries = 0;
1596 for (idx = 0; idx < RTE_NB_STATS; idx++) {
1597 snprintf(xstats_names[cnt_used_entries].name,
1598 sizeof(xstats_names[0].name),
1599 "%s", rte_stats_strings[idx].name);
1602 num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1603 for (id_queue = 0; id_queue < num_q; id_queue++) {
1604 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1605 snprintf(xstats_names[cnt_used_entries].name,
1606 sizeof(xstats_names[0].name),
1608 id_queue, rte_rxq_stats_strings[idx].name);
1613 num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1614 for (id_queue = 0; id_queue < num_q; id_queue++) {
1615 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
1616 snprintf(xstats_names[cnt_used_entries].name,
1617 sizeof(xstats_names[0].name),
1619 id_queue, rte_txq_stats_strings[idx].name);
1624 if (dev->dev_ops->xstats_get_names != NULL) {
1625 /* If there are any driver-specific xstats, append them
1628 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
1630 xstats_names + cnt_used_entries,
1631 size - cnt_used_entries);
1632 if (cnt_driver_entries < 0)
1633 return cnt_driver_entries;
1634 cnt_used_entries += cnt_driver_entries;
1637 return cnt_used_entries;
1640 /* retrieve ethdev extended statistics */
1642 rte_eth_xstats_get_by_id(uint8_t port_id, const uint64_t *ids, uint64_t *values,
1645 /* If need all xstats */
1647 struct rte_eth_stats eth_stats;
1648 struct rte_eth_dev *dev;
1649 unsigned int count = 0, i, q;
1650 signed int xcount = 0;
1651 uint64_t val, *stats_ptr;
1652 uint16_t nb_rxqs, nb_txqs;
1654 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1655 dev = &rte_eth_devices[port_id];
1657 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues,
1658 RTE_ETHDEV_QUEUE_STAT_CNTRS);
1659 nb_txqs = RTE_MIN(dev->data->nb_tx_queues,
1660 RTE_ETHDEV_QUEUE_STAT_CNTRS);
1662 /* Return generic statistics */
1663 count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
1664 (nb_txqs * RTE_NB_TXQ_STATS);
1667 /* implemented by the driver */
1668 if (dev->dev_ops->xstats_get_by_id != NULL) {
1669 /* Retrieve the xstats from the driver at the end of the
1670 * xstats struct. Retrieve all xstats.
1672 xcount = (*dev->dev_ops->xstats_get_by_id)(dev,
1674 values ? values + count : NULL,
1675 (n > count) ? n - count : 0);
1679 /* implemented by the driver */
1680 } else if (dev->dev_ops->xstats_get != NULL) {
1681 /* Retrieve the xstats from the driver at the end of the
1682 * xstats struct. Retrieve all xstats.
1683 * Compatibility for PMD without xstats_get_by_ids
1685 unsigned int size = (n > count) ? n - count : 1;
1686 struct rte_eth_xstat xstats[size];
1688 xcount = (*dev->dev_ops->xstats_get)(dev,
1689 values ? xstats : NULL, size);
1695 for (i = 0 ; i < (unsigned int)xcount; i++)
1696 values[i + count] = xstats[i].value;
1699 if (n < count + xcount || values == NULL)
1700 return count + xcount;
1702 /* now fill the xstats structure */
1704 rte_eth_stats_get(port_id, ð_stats);
1707 for (i = 0; i < RTE_NB_STATS; i++) {
1708 stats_ptr = RTE_PTR_ADD(ð_stats,
1709 rte_stats_strings[i].offset);
1711 values[count++] = val;
1715 for (q = 0; q < nb_rxqs; q++) {
1716 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1717 stats_ptr = RTE_PTR_ADD(ð_stats,
1718 rte_rxq_stats_strings[i].offset +
1719 q * sizeof(uint64_t));
1721 values[count++] = val;
1726 for (q = 0; q < nb_txqs; q++) {
1727 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1728 stats_ptr = RTE_PTR_ADD(ð_stats,
1729 rte_txq_stats_strings[i].offset +
1730 q * sizeof(uint64_t));
1732 values[count++] = val;
1736 return count + xcount;
1738 /* Need only xstats given by IDS array */
1741 uint64_t *values_copy;
1743 size = rte_eth_xstats_get_by_id(port_id, NULL, NULL, 0);
1745 values_copy = malloc(sizeof(*values_copy) * size);
1747 RTE_PMD_DEBUG_TRACE(
1748 "ERROR: can't allocate memory for values_copy\n");
1752 rte_eth_xstats_get_by_id(port_id, NULL, values_copy, size);
1754 for (i = 0; i < n; i++) {
1755 if (ids[i] >= size) {
1756 RTE_PMD_DEBUG_TRACE(
1757 "ERROR: id value isn't valid\n");
1760 values[i] = values_copy[ids[i]];
1768 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstat *xstats,
1771 struct rte_eth_stats eth_stats;
1772 struct rte_eth_dev *dev;
1773 unsigned int count = 0, i, q;
1774 signed int xcount = 0;
1775 uint64_t val, *stats_ptr;
1776 uint16_t nb_rxqs, nb_txqs;
1778 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1780 dev = &rte_eth_devices[port_id];
1782 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1783 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1785 /* Return generic statistics */
1786 count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
1787 (nb_txqs * RTE_NB_TXQ_STATS);
1789 /* implemented by the driver */
1790 if (dev->dev_ops->xstats_get != NULL) {
1791 /* Retrieve the xstats from the driver at the end of the
1794 xcount = (*dev->dev_ops->xstats_get)(dev,
1795 xstats ? xstats + count : NULL,
1796 (n > count) ? n - count : 0);
1802 if (n < count + xcount || xstats == NULL)
1803 return count + xcount;
1805 /* now fill the xstats structure */
1807 rte_eth_stats_get(port_id, ð_stats);
1810 for (i = 0; i < RTE_NB_STATS; i++) {
1811 stats_ptr = RTE_PTR_ADD(ð_stats,
1812 rte_stats_strings[i].offset);
1814 xstats[count++].value = val;
1818 for (q = 0; q < nb_rxqs; q++) {
1819 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1820 stats_ptr = RTE_PTR_ADD(ð_stats,
1821 rte_rxq_stats_strings[i].offset +
1822 q * sizeof(uint64_t));
1824 xstats[count++].value = val;
1829 for (q = 0; q < nb_txqs; q++) {
1830 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1831 stats_ptr = RTE_PTR_ADD(ð_stats,
1832 rte_txq_stats_strings[i].offset +
1833 q * sizeof(uint64_t));
1835 xstats[count++].value = val;
1839 for (i = 0; i < count; i++)
1841 /* add an offset to driver-specific stats */
1842 for ( ; i < count + xcount; i++)
1843 xstats[i].id += count;
1845 return count + xcount;
1848 /* reset ethdev extended statistics */
1850 rte_eth_xstats_reset(uint8_t port_id)
1852 struct rte_eth_dev *dev;
1854 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1855 dev = &rte_eth_devices[port_id];
1857 /* implemented by the driver */
1858 if (dev->dev_ops->xstats_reset != NULL) {
1859 (*dev->dev_ops->xstats_reset)(dev);
1863 /* fallback to default */
1864 rte_eth_stats_reset(port_id);
1868 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1871 struct rte_eth_dev *dev;
1873 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1875 dev = &rte_eth_devices[port_id];
1877 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1878 return (*dev->dev_ops->queue_stats_mapping_set)
1879 (dev, queue_id, stat_idx, is_rx);
1884 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1887 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1893 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1896 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1901 rte_eth_dev_fw_version_get(uint8_t port_id, char *fw_version, size_t fw_size)
1903 struct rte_eth_dev *dev;
1905 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1906 dev = &rte_eth_devices[port_id];
1908 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP);
1909 return (*dev->dev_ops->fw_version_get)(dev, fw_version, fw_size);
1913 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1915 struct rte_eth_dev *dev;
1916 const struct rte_eth_desc_lim lim = {
1917 .nb_max = UINT16_MAX,
1922 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1923 dev = &rte_eth_devices[port_id];
1925 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1926 dev_info->rx_desc_lim = lim;
1927 dev_info->tx_desc_lim = lim;
1929 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1930 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1931 dev_info->driver_name = dev->device->driver->name;
1932 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
1933 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
1937 rte_eth_dev_get_supported_ptypes(uint8_t port_id, uint32_t ptype_mask,
1938 uint32_t *ptypes, int num)
1941 struct rte_eth_dev *dev;
1942 const uint32_t *all_ptypes;
1944 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1945 dev = &rte_eth_devices[port_id];
1946 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
1947 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
1952 for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
1953 if (all_ptypes[i] & ptype_mask) {
1955 ptypes[j] = all_ptypes[i];
1963 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1965 struct rte_eth_dev *dev;
1967 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1968 dev = &rte_eth_devices[port_id];
1969 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1974 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1976 struct rte_eth_dev *dev;
1978 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1980 dev = &rte_eth_devices[port_id];
1981 *mtu = dev->data->mtu;
1986 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1989 struct rte_eth_dev *dev;
1991 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1992 dev = &rte_eth_devices[port_id];
1993 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1995 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1997 dev->data->mtu = mtu;
2003 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
2005 struct rte_eth_dev *dev;
2008 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2009 dev = &rte_eth_devices[port_id];
2010 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
2011 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
2015 if (vlan_id > 4095) {
2016 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
2017 port_id, (unsigned) vlan_id);
2020 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
2022 ret = (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
2024 struct rte_vlan_filter_conf *vfc;
2028 vfc = &dev->data->vlan_filter_conf;
2029 vidx = vlan_id / 64;
2030 vbit = vlan_id % 64;
2033 vfc->ids[vidx] |= UINT64_C(1) << vbit;
2035 vfc->ids[vidx] &= ~(UINT64_C(1) << vbit);
2042 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
2044 struct rte_eth_dev *dev;
2046 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2047 dev = &rte_eth_devices[port_id];
2048 if (rx_queue_id >= dev->data->nb_rx_queues) {
2049 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
2053 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
2054 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
2060 rte_eth_dev_set_vlan_ether_type(uint8_t port_id,
2061 enum rte_vlan_type vlan_type,
2064 struct rte_eth_dev *dev;
2066 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2067 dev = &rte_eth_devices[port_id];
2068 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
2070 return (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type, tpid);
2074 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
2076 struct rte_eth_dev *dev;
2081 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2082 dev = &rte_eth_devices[port_id];
2084 /*check which option changed by application*/
2085 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
2086 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
2088 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
2089 mask |= ETH_VLAN_STRIP_MASK;
2092 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
2093 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
2095 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
2096 mask |= ETH_VLAN_FILTER_MASK;
2099 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
2100 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
2102 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
2103 mask |= ETH_VLAN_EXTEND_MASK;
2110 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
2111 (*dev->dev_ops->vlan_offload_set)(dev, mask);
2117 rte_eth_dev_get_vlan_offload(uint8_t port_id)
2119 struct rte_eth_dev *dev;
2122 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2123 dev = &rte_eth_devices[port_id];
2125 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
2126 ret |= ETH_VLAN_STRIP_OFFLOAD;
2128 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
2129 ret |= ETH_VLAN_FILTER_OFFLOAD;
2131 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
2132 ret |= ETH_VLAN_EXTEND_OFFLOAD;
2138 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
2140 struct rte_eth_dev *dev;
2142 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2143 dev = &rte_eth_devices[port_id];
2144 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
2145 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
2151 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2153 struct rte_eth_dev *dev;
2155 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2156 dev = &rte_eth_devices[port_id];
2157 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2158 memset(fc_conf, 0, sizeof(*fc_conf));
2159 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
2163 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2165 struct rte_eth_dev *dev;
2167 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2168 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2169 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2173 dev = &rte_eth_devices[port_id];
2174 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2175 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
2179 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
2181 struct rte_eth_dev *dev;
2183 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2184 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2185 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2189 dev = &rte_eth_devices[port_id];
2190 /* High water, low water validation are device specific */
2191 if (*dev->dev_ops->priority_flow_ctrl_set)
2192 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
2197 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2205 num = (reta_size + RTE_RETA_GROUP_SIZE - 1) / RTE_RETA_GROUP_SIZE;
2206 for (i = 0; i < num; i++) {
2207 if (reta_conf[i].mask)
2215 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2219 uint16_t i, idx, shift;
2225 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
2229 for (i = 0; i < reta_size; i++) {
2230 idx = i / RTE_RETA_GROUP_SIZE;
2231 shift = i % RTE_RETA_GROUP_SIZE;
2232 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2233 (reta_conf[idx].reta[shift] >= max_rxq)) {
2234 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2235 "the maximum rxq index: %u\n", idx, shift,
2236 reta_conf[idx].reta[shift], max_rxq);
2245 rte_eth_dev_rss_reta_update(uint8_t port_id,
2246 struct rte_eth_rss_reta_entry64 *reta_conf,
2249 struct rte_eth_dev *dev;
2252 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2253 /* Check mask bits */
2254 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2258 dev = &rte_eth_devices[port_id];
2260 /* Check entry value */
2261 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2262 dev->data->nb_rx_queues);
2266 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2267 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2271 rte_eth_dev_rss_reta_query(uint8_t port_id,
2272 struct rte_eth_rss_reta_entry64 *reta_conf,
2275 struct rte_eth_dev *dev;
2278 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2280 /* Check mask bits */
2281 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2285 dev = &rte_eth_devices[port_id];
2286 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2287 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2291 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2293 struct rte_eth_dev *dev;
2294 uint16_t rss_hash_protos;
2296 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2297 rss_hash_protos = rss_conf->rss_hf;
2298 if ((rss_hash_protos != 0) &&
2299 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2300 RTE_PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2304 dev = &rte_eth_devices[port_id];
2305 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2306 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2310 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2311 struct rte_eth_rss_conf *rss_conf)
2313 struct rte_eth_dev *dev;
2315 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2316 dev = &rte_eth_devices[port_id];
2317 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2318 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2322 rte_eth_dev_udp_tunnel_port_add(uint8_t port_id,
2323 struct rte_eth_udp_tunnel *udp_tunnel)
2325 struct rte_eth_dev *dev;
2327 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2328 if (udp_tunnel == NULL) {
2329 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2333 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2334 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2338 dev = &rte_eth_devices[port_id];
2339 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
2340 return (*dev->dev_ops->udp_tunnel_port_add)(dev, udp_tunnel);
2344 rte_eth_dev_udp_tunnel_port_delete(uint8_t port_id,
2345 struct rte_eth_udp_tunnel *udp_tunnel)
2347 struct rte_eth_dev *dev;
2349 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2350 dev = &rte_eth_devices[port_id];
2352 if (udp_tunnel == NULL) {
2353 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2357 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2358 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2362 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
2363 return (*dev->dev_ops->udp_tunnel_port_del)(dev, udp_tunnel);
2367 rte_eth_led_on(uint8_t port_id)
2369 struct rte_eth_dev *dev;
2371 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2372 dev = &rte_eth_devices[port_id];
2373 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2374 return (*dev->dev_ops->dev_led_on)(dev);
2378 rte_eth_led_off(uint8_t port_id)
2380 struct rte_eth_dev *dev;
2382 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2383 dev = &rte_eth_devices[port_id];
2384 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2385 return (*dev->dev_ops->dev_led_off)(dev);
2389 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2393 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2395 struct rte_eth_dev_info dev_info;
2396 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2399 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2400 rte_eth_dev_info_get(port_id, &dev_info);
2402 for (i = 0; i < dev_info.max_mac_addrs; i++)
2403 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2409 static const struct ether_addr null_mac_addr;
2412 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2415 struct rte_eth_dev *dev;
2420 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2421 dev = &rte_eth_devices[port_id];
2422 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2424 if (is_zero_ether_addr(addr)) {
2425 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2429 if (pool >= ETH_64_POOLS) {
2430 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2434 index = get_mac_addr_index(port_id, addr);
2436 index = get_mac_addr_index(port_id, &null_mac_addr);
2438 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2443 pool_mask = dev->data->mac_pool_sel[index];
2445 /* Check if both MAC address and pool is already there, and do nothing */
2446 if (pool_mask & (1ULL << pool))
2451 ret = (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2454 /* Update address in NIC data structure */
2455 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2457 /* Update pool bitmap in NIC data structure */
2458 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2465 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2467 struct rte_eth_dev *dev;
2470 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2471 dev = &rte_eth_devices[port_id];
2472 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2474 index = get_mac_addr_index(port_id, addr);
2476 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2478 } else if (index < 0)
2479 return 0; /* Do nothing if address wasn't found */
2482 (*dev->dev_ops->mac_addr_remove)(dev, index);
2484 /* Update address in NIC data structure */
2485 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2487 /* reset pool bitmap */
2488 dev->data->mac_pool_sel[index] = 0;
2494 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2496 struct rte_eth_dev *dev;
2498 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2500 if (!is_valid_assigned_ether_addr(addr))
2503 dev = &rte_eth_devices[port_id];
2504 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2506 /* Update default address in NIC data structure */
2507 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2509 (*dev->dev_ops->mac_addr_set)(dev, addr);
2516 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2520 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2522 struct rte_eth_dev_info dev_info;
2523 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2526 rte_eth_dev_info_get(port_id, &dev_info);
2527 if (!dev->data->hash_mac_addrs)
2530 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2531 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2532 ETHER_ADDR_LEN) == 0)
2539 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2544 struct rte_eth_dev *dev;
2546 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2548 dev = &rte_eth_devices[port_id];
2549 if (is_zero_ether_addr(addr)) {
2550 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2555 index = get_hash_mac_addr_index(port_id, addr);
2556 /* Check if it's already there, and do nothing */
2557 if ((index >= 0) && (on))
2562 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2563 "set in UTA\n", port_id);
2567 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2569 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2575 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2576 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2578 /* Update address in NIC data structure */
2580 ether_addr_copy(addr,
2581 &dev->data->hash_mac_addrs[index]);
2583 ether_addr_copy(&null_mac_addr,
2584 &dev->data->hash_mac_addrs[index]);
2591 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2593 struct rte_eth_dev *dev;
2595 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2597 dev = &rte_eth_devices[port_id];
2599 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2600 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2603 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2606 struct rte_eth_dev *dev;
2607 struct rte_eth_dev_info dev_info;
2608 struct rte_eth_link link;
2610 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2612 dev = &rte_eth_devices[port_id];
2613 rte_eth_dev_info_get(port_id, &dev_info);
2614 link = dev->data->dev_link;
2616 if (queue_idx > dev_info.max_tx_queues) {
2617 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2618 "invalid queue id=%d\n", port_id, queue_idx);
2622 if (tx_rate > link.link_speed) {
2623 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2624 "bigger than link speed= %d\n",
2625 tx_rate, link.link_speed);
2629 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2630 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2634 rte_eth_mirror_rule_set(uint8_t port_id,
2635 struct rte_eth_mirror_conf *mirror_conf,
2636 uint8_t rule_id, uint8_t on)
2638 struct rte_eth_dev *dev;
2640 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2641 if (mirror_conf->rule_type == 0) {
2642 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2646 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2647 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2652 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2653 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2654 (mirror_conf->pool_mask == 0)) {
2655 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2659 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2660 mirror_conf->vlan.vlan_mask == 0) {
2661 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2665 dev = &rte_eth_devices[port_id];
2666 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2668 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2672 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2674 struct rte_eth_dev *dev;
2676 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2678 dev = &rte_eth_devices[port_id];
2679 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2681 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2685 rte_eth_dev_callback_register(uint8_t port_id,
2686 enum rte_eth_event_type event,
2687 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2689 struct rte_eth_dev *dev;
2690 struct rte_eth_dev_callback *user_cb;
2695 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2697 dev = &rte_eth_devices[port_id];
2698 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2700 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2701 if (user_cb->cb_fn == cb_fn &&
2702 user_cb->cb_arg == cb_arg &&
2703 user_cb->event == event) {
2708 /* create a new callback. */
2709 if (user_cb == NULL) {
2710 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2711 sizeof(struct rte_eth_dev_callback), 0);
2712 if (user_cb != NULL) {
2713 user_cb->cb_fn = cb_fn;
2714 user_cb->cb_arg = cb_arg;
2715 user_cb->event = event;
2716 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2720 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2721 return (user_cb == NULL) ? -ENOMEM : 0;
2725 rte_eth_dev_callback_unregister(uint8_t port_id,
2726 enum rte_eth_event_type event,
2727 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2730 struct rte_eth_dev *dev;
2731 struct rte_eth_dev_callback *cb, *next;
2736 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2738 dev = &rte_eth_devices[port_id];
2739 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2742 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2744 next = TAILQ_NEXT(cb, next);
2746 if (cb->cb_fn != cb_fn || cb->event != event ||
2747 (cb->cb_arg != (void *)-1 &&
2748 cb->cb_arg != cb_arg))
2752 * if this callback is not executing right now,
2755 if (cb->active == 0) {
2756 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2763 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2768 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2769 enum rte_eth_event_type event, void *cb_arg, void *ret_param)
2771 struct rte_eth_dev_callback *cb_lst;
2772 struct rte_eth_dev_callback dev_cb;
2775 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2776 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2777 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2782 dev_cb.cb_arg = cb_arg;
2783 if (ret_param != NULL)
2784 dev_cb.ret_param = ret_param;
2786 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2787 rc = dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2788 dev_cb.cb_arg, dev_cb.ret_param);
2789 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2792 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2797 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
2800 struct rte_eth_dev *dev;
2801 struct rte_intr_handle *intr_handle;
2805 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2807 dev = &rte_eth_devices[port_id];
2809 if (!dev->intr_handle) {
2810 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
2814 intr_handle = dev->intr_handle;
2815 if (!intr_handle->intr_vec) {
2816 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2820 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2821 vec = intr_handle->intr_vec[qid];
2822 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2823 if (rc && rc != -EEXIST) {
2824 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2825 " op %d epfd %d vec %u\n",
2826 port_id, qid, op, epfd, vec);
2833 const struct rte_memzone *
2834 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2835 uint16_t queue_id, size_t size, unsigned align,
2838 char z_name[RTE_MEMZONE_NAMESIZE];
2839 const struct rte_memzone *mz;
2841 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2842 dev->device->driver->name, ring_name,
2843 dev->data->port_id, queue_id);
2845 mz = rte_memzone_lookup(z_name);
2849 if (rte_xen_dom0_supported())
2850 return rte_memzone_reserve_bounded(z_name, size, socket_id,
2851 0, align, RTE_PGSIZE_2M);
2853 return rte_memzone_reserve_aligned(z_name, size, socket_id,
2858 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
2859 int epfd, int op, void *data)
2862 struct rte_eth_dev *dev;
2863 struct rte_intr_handle *intr_handle;
2866 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2868 dev = &rte_eth_devices[port_id];
2869 if (queue_id >= dev->data->nb_rx_queues) {
2870 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
2874 if (!dev->intr_handle) {
2875 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
2879 intr_handle = dev->intr_handle;
2880 if (!intr_handle->intr_vec) {
2881 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2885 vec = intr_handle->intr_vec[queue_id];
2886 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2887 if (rc && rc != -EEXIST) {
2888 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2889 " op %d epfd %d vec %u\n",
2890 port_id, queue_id, op, epfd, vec);
2898 rte_eth_dev_rx_intr_enable(uint8_t port_id,
2901 struct rte_eth_dev *dev;
2903 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2905 dev = &rte_eth_devices[port_id];
2907 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
2908 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
2912 rte_eth_dev_rx_intr_disable(uint8_t port_id,
2915 struct rte_eth_dev *dev;
2917 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2919 dev = &rte_eth_devices[port_id];
2921 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
2922 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
2927 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
2929 struct rte_eth_dev *dev;
2931 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2933 dev = &rte_eth_devices[port_id];
2934 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2935 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
2936 RTE_ETH_FILTER_NOP, NULL);
2940 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
2941 enum rte_filter_op filter_op, void *arg)
2943 struct rte_eth_dev *dev;
2945 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2947 dev = &rte_eth_devices[port_id];
2948 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2949 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
2953 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
2954 rte_rx_callback_fn fn, void *user_param)
2956 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2957 rte_errno = ENOTSUP;
2960 /* check input parameters */
2961 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2962 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2966 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2974 cb->param = user_param;
2976 rte_spinlock_lock(&rte_eth_rx_cb_lock);
2977 /* Add the callbacks in fifo order. */
2978 struct rte_eth_rxtx_callback *tail =
2979 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2982 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2989 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
2995 rte_eth_add_first_rx_callback(uint8_t port_id, uint16_t queue_id,
2996 rte_rx_callback_fn fn, void *user_param)
2998 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2999 rte_errno = ENOTSUP;
3002 /* check input parameters */
3003 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3004 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3009 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3017 cb->param = user_param;
3019 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3020 /* Add the callbacks at fisrt position*/
3021 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3023 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3024 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3030 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
3031 rte_tx_callback_fn fn, void *user_param)
3033 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3034 rte_errno = ENOTSUP;
3037 /* check input parameters */
3038 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3039 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3044 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3052 cb->param = user_param;
3054 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3055 /* Add the callbacks in fifo order. */
3056 struct rte_eth_rxtx_callback *tail =
3057 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3060 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3067 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3073 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3074 struct rte_eth_rxtx_callback *user_cb)
3076 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3079 /* Check input parameters. */
3080 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3081 if (user_cb == NULL ||
3082 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
3085 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3086 struct rte_eth_rxtx_callback *cb;
3087 struct rte_eth_rxtx_callback **prev_cb;
3090 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3091 prev_cb = &dev->post_rx_burst_cbs[queue_id];
3092 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3094 if (cb == user_cb) {
3095 /* Remove the user cb from the callback list. */
3096 *prev_cb = cb->next;
3101 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3107 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3108 struct rte_eth_rxtx_callback *user_cb)
3110 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3113 /* Check input parameters. */
3114 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3115 if (user_cb == NULL ||
3116 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
3119 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3121 struct rte_eth_rxtx_callback *cb;
3122 struct rte_eth_rxtx_callback **prev_cb;
3124 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3125 prev_cb = &dev->pre_tx_burst_cbs[queue_id];
3126 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3128 if (cb == user_cb) {
3129 /* Remove the user cb from the callback list. */
3130 *prev_cb = cb->next;
3135 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3141 rte_eth_rx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3142 struct rte_eth_rxq_info *qinfo)
3144 struct rte_eth_dev *dev;
3146 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3151 dev = &rte_eth_devices[port_id];
3152 if (queue_id >= dev->data->nb_rx_queues) {
3153 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3157 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3159 memset(qinfo, 0, sizeof(*qinfo));
3160 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3165 rte_eth_tx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3166 struct rte_eth_txq_info *qinfo)
3168 struct rte_eth_dev *dev;
3170 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3175 dev = &rte_eth_devices[port_id];
3176 if (queue_id >= dev->data->nb_tx_queues) {
3177 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3181 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3183 memset(qinfo, 0, sizeof(*qinfo));
3184 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3189 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3190 struct ether_addr *mc_addr_set,
3191 uint32_t nb_mc_addr)
3193 struct rte_eth_dev *dev;
3195 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3197 dev = &rte_eth_devices[port_id];
3198 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3199 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3203 rte_eth_timesync_enable(uint8_t port_id)
3205 struct rte_eth_dev *dev;
3207 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3208 dev = &rte_eth_devices[port_id];
3210 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3211 return (*dev->dev_ops->timesync_enable)(dev);
3215 rte_eth_timesync_disable(uint8_t port_id)
3217 struct rte_eth_dev *dev;
3219 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3220 dev = &rte_eth_devices[port_id];
3222 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3223 return (*dev->dev_ops->timesync_disable)(dev);
3227 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3230 struct rte_eth_dev *dev;
3232 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3233 dev = &rte_eth_devices[port_id];
3235 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3236 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3240 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3242 struct rte_eth_dev *dev;
3244 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3245 dev = &rte_eth_devices[port_id];
3247 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3248 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3252 rte_eth_timesync_adjust_time(uint8_t port_id, int64_t delta)
3254 struct rte_eth_dev *dev;
3256 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3257 dev = &rte_eth_devices[port_id];
3259 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3260 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3264 rte_eth_timesync_read_time(uint8_t port_id, struct timespec *timestamp)
3266 struct rte_eth_dev *dev;
3268 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3269 dev = &rte_eth_devices[port_id];
3271 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3272 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3276 rte_eth_timesync_write_time(uint8_t port_id, const struct timespec *timestamp)
3278 struct rte_eth_dev *dev;
3280 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3281 dev = &rte_eth_devices[port_id];
3283 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3284 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3288 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3290 struct rte_eth_dev *dev;
3292 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3294 dev = &rte_eth_devices[port_id];
3295 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3296 return (*dev->dev_ops->get_reg)(dev, info);
3300 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3302 struct rte_eth_dev *dev;
3304 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3306 dev = &rte_eth_devices[port_id];
3307 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3308 return (*dev->dev_ops->get_eeprom_length)(dev);
3312 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3314 struct rte_eth_dev *dev;
3316 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3318 dev = &rte_eth_devices[port_id];
3319 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3320 return (*dev->dev_ops->get_eeprom)(dev, info);
3324 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3326 struct rte_eth_dev *dev;
3328 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3330 dev = &rte_eth_devices[port_id];
3331 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3332 return (*dev->dev_ops->set_eeprom)(dev, info);
3336 rte_eth_dev_get_dcb_info(uint8_t port_id,
3337 struct rte_eth_dcb_info *dcb_info)
3339 struct rte_eth_dev *dev;
3341 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3343 dev = &rte_eth_devices[port_id];
3344 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3346 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3347 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3351 rte_eth_dev_l2_tunnel_eth_type_conf(uint8_t port_id,
3352 struct rte_eth_l2_tunnel_conf *l2_tunnel)
3354 struct rte_eth_dev *dev;
3356 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3357 if (l2_tunnel == NULL) {
3358 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3362 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3363 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
3367 dev = &rte_eth_devices[port_id];
3368 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
3370 return (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev, l2_tunnel);
3374 rte_eth_dev_l2_tunnel_offload_set(uint8_t port_id,
3375 struct rte_eth_l2_tunnel_conf *l2_tunnel,
3379 struct rte_eth_dev *dev;
3381 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3383 if (l2_tunnel == NULL) {
3384 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3388 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3389 RTE_PMD_DEBUG_TRACE("Invalid tunnel type.\n");
3394 RTE_PMD_DEBUG_TRACE("Mask should have a value.\n");
3398 dev = &rte_eth_devices[port_id];
3399 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
3401 return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);
3405 rte_eth_dev_adjust_nb_desc(uint16_t *nb_desc,
3406 const struct rte_eth_desc_lim *desc_lim)
3408 if (desc_lim->nb_align != 0)
3409 *nb_desc = RTE_ALIGN_CEIL(*nb_desc, desc_lim->nb_align);
3411 if (desc_lim->nb_max != 0)
3412 *nb_desc = RTE_MIN(*nb_desc, desc_lim->nb_max);
3414 *nb_desc = RTE_MAX(*nb_desc, desc_lim->nb_min);
3418 rte_eth_dev_adjust_nb_rx_tx_desc(uint8_t port_id,
3419 uint16_t *nb_rx_desc,
3420 uint16_t *nb_tx_desc)
3422 struct rte_eth_dev *dev;
3423 struct rte_eth_dev_info dev_info;
3425 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3427 dev = &rte_eth_devices[port_id];
3428 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
3430 rte_eth_dev_info_get(port_id, &dev_info);
3432 if (nb_rx_desc != NULL)
3433 rte_eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim);
3435 if (nb_tx_desc != NULL)
3436 rte_eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim);