4 * Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/types.h>
35 #include <sys/queue.h>
44 #include <netinet/in.h>
46 #include <rte_byteorder.h>
48 #include <rte_debug.h>
49 #include <rte_interrupts.h>
51 #include <rte_memory.h>
52 #include <rte_memcpy.h>
53 #include <rte_memzone.h>
54 #include <rte_launch.h>
56 #include <rte_per_lcore.h>
57 #include <rte_lcore.h>
58 #include <rte_atomic.h>
59 #include <rte_branch_prediction.h>
60 #include <rte_common.h>
61 #include <rte_mempool.h>
62 #include <rte_malloc.h>
64 #include <rte_errno.h>
65 #include <rte_spinlock.h>
66 #include <rte_string_fns.h>
68 #include "rte_ether.h"
69 #include "rte_ethdev.h"
71 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
72 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
73 static struct rte_eth_dev_data *rte_eth_dev_data;
74 static uint8_t eth_dev_last_created_port;
75 static uint8_t nb_ports;
77 /* spinlock for eth device callbacks */
78 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
80 /* spinlock for add/remove rx callbacks */
81 static rte_spinlock_t rte_eth_rx_cb_lock = RTE_SPINLOCK_INITIALIZER;
83 /* spinlock for add/remove tx callbacks */
84 static rte_spinlock_t rte_eth_tx_cb_lock = RTE_SPINLOCK_INITIALIZER;
86 /* store statistics names and its offset in stats structure */
87 struct rte_eth_xstats_name_off {
88 char name[RTE_ETH_XSTATS_NAME_SIZE];
92 static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
93 {"rx_good_packets", offsetof(struct rte_eth_stats, ipackets)},
94 {"tx_good_packets", offsetof(struct rte_eth_stats, opackets)},
95 {"rx_good_bytes", offsetof(struct rte_eth_stats, ibytes)},
96 {"tx_good_bytes", offsetof(struct rte_eth_stats, obytes)},
97 {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
98 {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
99 {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats,
103 #define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
105 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
106 {"packets", offsetof(struct rte_eth_stats, q_ipackets)},
107 {"bytes", offsetof(struct rte_eth_stats, q_ibytes)},
108 {"errors", offsetof(struct rte_eth_stats, q_errors)},
111 #define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) / \
112 sizeof(rte_rxq_stats_strings[0]))
114 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
115 {"packets", offsetof(struct rte_eth_stats, q_opackets)},
116 {"bytes", offsetof(struct rte_eth_stats, q_obytes)},
118 #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) / \
119 sizeof(rte_txq_stats_strings[0]))
123 * The user application callback description.
125 * It contains callback address to be registered by user application,
126 * the pointer to the parameters for callback, and the event type.
128 struct rte_eth_dev_callback {
129 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
130 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
131 void *cb_arg; /**< Parameter for callback */
132 void *ret_param; /**< Return parameter */
133 enum rte_eth_event_type event; /**< Interrupt event type */
134 uint32_t active; /**< Callback is executing */
143 rte_eth_find_next(uint8_t port_id)
145 while (port_id < RTE_MAX_ETHPORTS &&
146 rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED)
149 if (port_id >= RTE_MAX_ETHPORTS)
150 return RTE_MAX_ETHPORTS;
156 rte_eth_dev_data_alloc(void)
158 const unsigned flags = 0;
159 const struct rte_memzone *mz;
161 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
162 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
163 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
164 rte_socket_id(), flags);
166 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
168 rte_panic("Cannot allocate memzone for ethernet port data\n");
170 rte_eth_dev_data = mz->addr;
171 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
172 memset(rte_eth_dev_data, 0,
173 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
177 rte_eth_dev_allocated(const char *name)
181 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
182 if ((rte_eth_devices[i].state == RTE_ETH_DEV_ATTACHED) &&
183 strcmp(rte_eth_devices[i].data->name, name) == 0)
184 return &rte_eth_devices[i];
190 rte_eth_dev_find_free_port(void)
194 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
195 if (rte_eth_devices[i].state == RTE_ETH_DEV_UNUSED)
198 return RTE_MAX_ETHPORTS;
201 static struct rte_eth_dev *
202 eth_dev_get(uint8_t port_id)
204 struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
206 eth_dev->data = &rte_eth_dev_data[port_id];
207 eth_dev->state = RTE_ETH_DEV_ATTACHED;
208 TAILQ_INIT(&(eth_dev->link_intr_cbs));
210 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;
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)
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)
312 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
316 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
319 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
323 /* shouldn't check 'rte_eth_devices[i].data',
324 * because it might be overwritten by VDEV PMD */
325 tmp = rte_eth_dev_data[port_id].name;
331 rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
336 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
343 RTE_ETH_FOREACH_DEV(i) {
345 rte_eth_dev_data[i].name, strlen(name))) {
356 rte_eth_dev_is_detachable(uint8_t port_id)
360 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
362 switch (rte_eth_devices[port_id].data->kdrv) {
363 case RTE_KDRV_IGB_UIO:
364 case RTE_KDRV_UIO_GENERIC:
365 case RTE_KDRV_NIC_UIO:
372 dev_flags = rte_eth_devices[port_id].data->dev_flags;
373 if ((dev_flags & RTE_ETH_DEV_DETACHABLE) &&
374 (!(dev_flags & RTE_ETH_DEV_BONDED_SLAVE)))
380 /* attach the new device, then store port_id of the device */
382 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
385 int current = rte_eth_dev_count();
389 if ((devargs == NULL) || (port_id == NULL)) {
394 /* parse devargs, then retrieve device name and args */
395 if (rte_eal_parse_devargs_str(devargs, &name, &args))
398 ret = rte_eal_dev_attach(name, args);
402 /* no point looking at the port count if no port exists */
403 if (!rte_eth_dev_count()) {
404 RTE_LOG(ERR, EAL, "No port found for device (%s)\n", name);
409 /* if nothing happened, there is a bug here, since some driver told us
410 * it did attach a device, but did not create a port.
412 if (current == rte_eth_dev_count()) {
417 *port_id = eth_dev_last_created_port;
426 /* detach the device, then store the name of the device */
428 rte_eth_dev_detach(uint8_t port_id, char *name)
437 /* FIXME: move this to eal, once device flags are relocated there */
438 if (rte_eth_dev_is_detachable(port_id))
441 snprintf(name, sizeof(rte_eth_devices[port_id].data->name),
442 "%s", rte_eth_devices[port_id].data->name);
444 ret = rte_eal_dev_detach(rte_eth_devices[port_id].device);
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);
827 _rte_eth_dev_reset(struct rte_eth_dev *dev)
829 if (dev->data->dev_started) {
831 "port %d must be stopped to allow reset\n",
836 rte_eth_dev_rx_queue_config(dev, 0);
837 rte_eth_dev_tx_queue_config(dev, 0);
839 memset(&dev->data->dev_conf, 0, sizeof(dev->data->dev_conf));
843 rte_eth_dev_config_restore(uint8_t port_id)
845 struct rte_eth_dev *dev;
846 struct rte_eth_dev_info dev_info;
847 struct ether_addr *addr;
852 dev = &rte_eth_devices[port_id];
854 rte_eth_dev_info_get(port_id, &dev_info);
856 /* replay MAC address configuration including default MAC */
857 addr = &dev->data->mac_addrs[0];
858 if (*dev->dev_ops->mac_addr_set != NULL)
859 (*dev->dev_ops->mac_addr_set)(dev, addr);
860 else if (*dev->dev_ops->mac_addr_add != NULL)
861 (*dev->dev_ops->mac_addr_add)(dev, addr, 0, pool);
863 if (*dev->dev_ops->mac_addr_add != NULL) {
864 for (i = 1; i < dev_info.max_mac_addrs; i++) {
865 addr = &dev->data->mac_addrs[i];
867 /* skip zero address */
868 if (is_zero_ether_addr(addr))
872 pool_mask = dev->data->mac_pool_sel[i];
875 if (pool_mask & 1ULL)
876 (*dev->dev_ops->mac_addr_add)(dev,
884 /* replay promiscuous configuration */
885 if (rte_eth_promiscuous_get(port_id) == 1)
886 rte_eth_promiscuous_enable(port_id);
887 else if (rte_eth_promiscuous_get(port_id) == 0)
888 rte_eth_promiscuous_disable(port_id);
890 /* replay all multicast configuration */
891 if (rte_eth_allmulticast_get(port_id) == 1)
892 rte_eth_allmulticast_enable(port_id);
893 else if (rte_eth_allmulticast_get(port_id) == 0)
894 rte_eth_allmulticast_disable(port_id);
898 rte_eth_dev_start(uint8_t port_id)
900 struct rte_eth_dev *dev;
903 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
905 dev = &rte_eth_devices[port_id];
907 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
909 if (dev->data->dev_started != 0) {
910 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
911 " already started\n",
916 diag = (*dev->dev_ops->dev_start)(dev);
918 dev->data->dev_started = 1;
922 rte_eth_dev_config_restore(port_id);
924 if (dev->data->dev_conf.intr_conf.lsc == 0) {
925 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
926 (*dev->dev_ops->link_update)(dev, 0);
932 rte_eth_dev_stop(uint8_t port_id)
934 struct rte_eth_dev *dev;
936 RTE_ETH_VALID_PORTID_OR_RET(port_id);
937 dev = &rte_eth_devices[port_id];
939 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
941 if (dev->data->dev_started == 0) {
942 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
943 " already stopped\n",
948 dev->data->dev_started = 0;
949 (*dev->dev_ops->dev_stop)(dev);
953 rte_eth_dev_set_link_up(uint8_t port_id)
955 struct rte_eth_dev *dev;
957 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
959 dev = &rte_eth_devices[port_id];
961 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
962 return (*dev->dev_ops->dev_set_link_up)(dev);
966 rte_eth_dev_set_link_down(uint8_t port_id)
968 struct rte_eth_dev *dev;
970 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
972 dev = &rte_eth_devices[port_id];
974 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
975 return (*dev->dev_ops->dev_set_link_down)(dev);
979 rte_eth_dev_close(uint8_t port_id)
981 struct rte_eth_dev *dev;
983 RTE_ETH_VALID_PORTID_OR_RET(port_id);
984 dev = &rte_eth_devices[port_id];
986 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
987 dev->data->dev_started = 0;
988 (*dev->dev_ops->dev_close)(dev);
990 dev->data->nb_rx_queues = 0;
991 rte_free(dev->data->rx_queues);
992 dev->data->rx_queues = NULL;
993 dev->data->nb_tx_queues = 0;
994 rte_free(dev->data->tx_queues);
995 dev->data->tx_queues = NULL;
999 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1000 uint16_t nb_rx_desc, unsigned int socket_id,
1001 const struct rte_eth_rxconf *rx_conf,
1002 struct rte_mempool *mp)
1005 uint32_t mbp_buf_size;
1006 struct rte_eth_dev *dev;
1007 struct rte_eth_dev_info dev_info;
1010 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1012 dev = &rte_eth_devices[port_id];
1013 if (rx_queue_id >= dev->data->nb_rx_queues) {
1014 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1018 if (dev->data->dev_started) {
1019 RTE_PMD_DEBUG_TRACE(
1020 "port %d must be stopped to allow configuration\n", port_id);
1024 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1025 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1028 * Check the size of the mbuf data buffer.
1029 * This value must be provided in the private data of the memory pool.
1030 * First check that the memory pool has a valid private data.
1032 rte_eth_dev_info_get(port_id, &dev_info);
1033 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1034 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1035 mp->name, (int) mp->private_data_size,
1036 (int) sizeof(struct rte_pktmbuf_pool_private));
1039 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1041 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1042 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1043 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1047 (int)(RTE_PKTMBUF_HEADROOM +
1048 dev_info.min_rx_bufsize),
1049 (int)RTE_PKTMBUF_HEADROOM,
1050 (int)dev_info.min_rx_bufsize);
1054 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1055 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1056 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1058 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1059 "should be: <= %hu, = %hu, and a product of %hu\n",
1061 dev_info.rx_desc_lim.nb_max,
1062 dev_info.rx_desc_lim.nb_min,
1063 dev_info.rx_desc_lim.nb_align);
1067 rxq = dev->data->rx_queues;
1068 if (rxq[rx_queue_id]) {
1069 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release,
1071 (*dev->dev_ops->rx_queue_release)(rxq[rx_queue_id]);
1072 rxq[rx_queue_id] = NULL;
1075 if (rx_conf == NULL)
1076 rx_conf = &dev_info.default_rxconf;
1078 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1079 socket_id, rx_conf, mp);
1081 if (!dev->data->min_rx_buf_size ||
1082 dev->data->min_rx_buf_size > mbp_buf_size)
1083 dev->data->min_rx_buf_size = mbp_buf_size;
1090 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1091 uint16_t nb_tx_desc, unsigned int socket_id,
1092 const struct rte_eth_txconf *tx_conf)
1094 struct rte_eth_dev *dev;
1095 struct rte_eth_dev_info dev_info;
1098 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1100 dev = &rte_eth_devices[port_id];
1101 if (tx_queue_id >= dev->data->nb_tx_queues) {
1102 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1106 if (dev->data->dev_started) {
1107 RTE_PMD_DEBUG_TRACE(
1108 "port %d must be stopped to allow configuration\n", port_id);
1112 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1113 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1115 rte_eth_dev_info_get(port_id, &dev_info);
1117 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1118 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1119 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1120 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1121 "should be: <= %hu, = %hu, and a product of %hu\n",
1123 dev_info.tx_desc_lim.nb_max,
1124 dev_info.tx_desc_lim.nb_min,
1125 dev_info.tx_desc_lim.nb_align);
1129 txq = dev->data->tx_queues;
1130 if (txq[tx_queue_id]) {
1131 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release,
1133 (*dev->dev_ops->tx_queue_release)(txq[tx_queue_id]);
1134 txq[tx_queue_id] = NULL;
1137 if (tx_conf == NULL)
1138 tx_conf = &dev_info.default_txconf;
1140 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1141 socket_id, tx_conf);
1145 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
1146 void *userdata __rte_unused)
1150 for (i = 0; i < unsent; i++)
1151 rte_pktmbuf_free(pkts[i]);
1155 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
1158 uint64_t *count = userdata;
1161 for (i = 0; i < unsent; i++)
1162 rte_pktmbuf_free(pkts[i]);
1168 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
1169 buffer_tx_error_fn cbfn, void *userdata)
1171 buffer->error_callback = cbfn;
1172 buffer->error_userdata = userdata;
1177 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
1184 buffer->size = size;
1185 if (buffer->error_callback == NULL) {
1186 ret = rte_eth_tx_buffer_set_err_callback(
1187 buffer, rte_eth_tx_buffer_drop_callback, NULL);
1194 rte_eth_tx_done_cleanup(uint8_t port_id, uint16_t queue_id, uint32_t free_cnt)
1196 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1198 /* Validate Input Data. Bail if not valid or not supported. */
1199 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1200 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_done_cleanup, -ENOTSUP);
1202 /* Call driver to free pending mbufs. */
1203 return (*dev->dev_ops->tx_done_cleanup)(dev->data->tx_queues[queue_id],
1208 rte_eth_promiscuous_enable(uint8_t port_id)
1210 struct rte_eth_dev *dev;
1212 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1213 dev = &rte_eth_devices[port_id];
1215 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1216 (*dev->dev_ops->promiscuous_enable)(dev);
1217 dev->data->promiscuous = 1;
1221 rte_eth_promiscuous_disable(uint8_t port_id)
1223 struct rte_eth_dev *dev;
1225 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1226 dev = &rte_eth_devices[port_id];
1228 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1229 dev->data->promiscuous = 0;
1230 (*dev->dev_ops->promiscuous_disable)(dev);
1234 rte_eth_promiscuous_get(uint8_t port_id)
1236 struct rte_eth_dev *dev;
1238 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1240 dev = &rte_eth_devices[port_id];
1241 return dev->data->promiscuous;
1245 rte_eth_allmulticast_enable(uint8_t port_id)
1247 struct rte_eth_dev *dev;
1249 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1250 dev = &rte_eth_devices[port_id];
1252 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1253 (*dev->dev_ops->allmulticast_enable)(dev);
1254 dev->data->all_multicast = 1;
1258 rte_eth_allmulticast_disable(uint8_t port_id)
1260 struct rte_eth_dev *dev;
1262 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1263 dev = &rte_eth_devices[port_id];
1265 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1266 dev->data->all_multicast = 0;
1267 (*dev->dev_ops->allmulticast_disable)(dev);
1271 rte_eth_allmulticast_get(uint8_t port_id)
1273 struct rte_eth_dev *dev;
1275 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1277 dev = &rte_eth_devices[port_id];
1278 return dev->data->all_multicast;
1282 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1283 struct rte_eth_link *link)
1285 struct rte_eth_link *dst = link;
1286 struct rte_eth_link *src = &(dev->data->dev_link);
1288 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1289 *(uint64_t *)src) == 0)
1296 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1298 struct rte_eth_dev *dev;
1300 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1301 dev = &rte_eth_devices[port_id];
1303 if (dev->data->dev_conf.intr_conf.lsc != 0)
1304 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1306 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1307 (*dev->dev_ops->link_update)(dev, 1);
1308 *eth_link = dev->data->dev_link;
1313 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1315 struct rte_eth_dev *dev;
1317 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1318 dev = &rte_eth_devices[port_id];
1320 if (dev->data->dev_conf.intr_conf.lsc != 0)
1321 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1323 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1324 (*dev->dev_ops->link_update)(dev, 0);
1325 *eth_link = dev->data->dev_link;
1330 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1332 struct rte_eth_dev *dev;
1334 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1336 dev = &rte_eth_devices[port_id];
1337 memset(stats, 0, sizeof(*stats));
1339 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1340 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1341 (*dev->dev_ops->stats_get)(dev, stats);
1346 rte_eth_stats_reset(uint8_t port_id)
1348 struct rte_eth_dev *dev;
1350 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1351 dev = &rte_eth_devices[port_id];
1353 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1354 (*dev->dev_ops->stats_reset)(dev);
1355 dev->data->rx_mbuf_alloc_failed = 0;
1359 get_xstats_count(uint8_t port_id)
1361 struct rte_eth_dev *dev;
1364 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1365 dev = &rte_eth_devices[port_id];
1366 if (dev->dev_ops->xstats_get_names_by_id != NULL) {
1367 count = (*dev->dev_ops->xstats_get_names_by_id)(dev, NULL,
1372 if (dev->dev_ops->xstats_get_names != NULL) {
1373 count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0);
1379 count += RTE_NB_STATS;
1380 count += RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
1382 count += RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
1388 rte_eth_xstats_get_id_by_name(uint8_t port_id, const char *xstat_name,
1391 int cnt_xstats, idx_xstat;
1393 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1396 RTE_PMD_DEBUG_TRACE("Error: id pointer is NULL\n");
1401 RTE_PMD_DEBUG_TRACE("Error: xstat_name pointer is NULL\n");
1406 cnt_xstats = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
1407 if (cnt_xstats < 0) {
1408 RTE_PMD_DEBUG_TRACE("Error: Cannot get count of xstats\n");
1412 /* Get id-name lookup table */
1413 struct rte_eth_xstat_name xstats_names[cnt_xstats];
1415 if (cnt_xstats != rte_eth_xstats_get_names_by_id(
1416 port_id, xstats_names, cnt_xstats, NULL)) {
1417 RTE_PMD_DEBUG_TRACE("Error: Cannot get xstats lookup\n");
1421 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
1422 if (!strcmp(xstats_names[idx_xstat].name, xstat_name)) {
1432 rte_eth_xstats_get_names_by_id(uint8_t port_id,
1433 struct rte_eth_xstat_name *xstats_names, unsigned int size,
1436 /* Get all xstats */
1438 struct rte_eth_dev *dev;
1439 int cnt_used_entries;
1440 int cnt_expected_entries;
1441 int cnt_driver_entries;
1442 uint32_t idx, id_queue;
1445 cnt_expected_entries = get_xstats_count(port_id);
1446 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1447 (int)size < cnt_expected_entries)
1448 return cnt_expected_entries;
1450 /* port_id checked in get_xstats_count() */
1451 dev = &rte_eth_devices[port_id];
1452 cnt_used_entries = 0;
1454 for (idx = 0; idx < RTE_NB_STATS; idx++) {
1455 snprintf(xstats_names[cnt_used_entries].name,
1456 sizeof(xstats_names[0].name),
1457 "%s", rte_stats_strings[idx].name);
1460 num_q = RTE_MIN(dev->data->nb_rx_queues,
1461 RTE_ETHDEV_QUEUE_STAT_CNTRS);
1462 for (id_queue = 0; id_queue < num_q; id_queue++) {
1463 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1464 snprintf(xstats_names[cnt_used_entries].name,
1465 sizeof(xstats_names[0].name),
1468 rte_rxq_stats_strings[idx].name);
1473 num_q = RTE_MIN(dev->data->nb_tx_queues,
1474 RTE_ETHDEV_QUEUE_STAT_CNTRS);
1475 for (id_queue = 0; id_queue < num_q; id_queue++) {
1476 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
1477 snprintf(xstats_names[cnt_used_entries].name,
1478 sizeof(xstats_names[0].name),
1481 rte_txq_stats_strings[idx].name);
1486 if (dev->dev_ops->xstats_get_names_by_id != NULL) {
1487 /* If there are any driver-specific xstats, append them
1490 cnt_driver_entries =
1491 (*dev->dev_ops->xstats_get_names_by_id)(
1493 xstats_names + cnt_used_entries,
1495 size - cnt_used_entries);
1496 if (cnt_driver_entries < 0)
1497 return cnt_driver_entries;
1498 cnt_used_entries += cnt_driver_entries;
1500 } else if (dev->dev_ops->xstats_get_names != NULL) {
1501 /* If there are any driver-specific xstats, append them
1504 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
1506 xstats_names + cnt_used_entries,
1507 size - cnt_used_entries);
1508 if (cnt_driver_entries < 0)
1509 return cnt_driver_entries;
1510 cnt_used_entries += cnt_driver_entries;
1513 return cnt_used_entries;
1515 /* Get only xstats given by IDS */
1518 struct rte_eth_xstat_name *xstats_names_copy;
1520 len = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
1523 malloc(sizeof(struct rte_eth_xstat_name) * len);
1524 if (!xstats_names_copy) {
1525 RTE_PMD_DEBUG_TRACE(
1526 "ERROR: can't allocate memory for values_copy\n");
1527 free(xstats_names_copy);
1531 rte_eth_xstats_get_names_by_id(port_id, xstats_names_copy,
1534 for (i = 0; i < size; i++) {
1535 if (ids[i] >= len) {
1536 RTE_PMD_DEBUG_TRACE(
1537 "ERROR: id value isn't valid\n");
1540 strcpy(xstats_names[i].name,
1541 xstats_names_copy[ids[i]].name);
1543 free(xstats_names_copy);
1549 rte_eth_xstats_get_names(uint8_t port_id,
1550 struct rte_eth_xstat_name *xstats_names,
1553 struct rte_eth_dev *dev;
1554 int cnt_used_entries;
1555 int cnt_expected_entries;
1556 int cnt_driver_entries;
1557 uint32_t idx, id_queue;
1560 cnt_expected_entries = get_xstats_count(port_id);
1561 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1562 (int)size < cnt_expected_entries)
1563 return cnt_expected_entries;
1565 /* port_id checked in get_xstats_count() */
1566 dev = &rte_eth_devices[port_id];
1567 cnt_used_entries = 0;
1569 for (idx = 0; idx < RTE_NB_STATS; idx++) {
1570 snprintf(xstats_names[cnt_used_entries].name,
1571 sizeof(xstats_names[0].name),
1572 "%s", rte_stats_strings[idx].name);
1575 num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1576 for (id_queue = 0; id_queue < num_q; id_queue++) {
1577 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1578 snprintf(xstats_names[cnt_used_entries].name,
1579 sizeof(xstats_names[0].name),
1581 id_queue, rte_rxq_stats_strings[idx].name);
1586 num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1587 for (id_queue = 0; id_queue < num_q; id_queue++) {
1588 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
1589 snprintf(xstats_names[cnt_used_entries].name,
1590 sizeof(xstats_names[0].name),
1592 id_queue, rte_txq_stats_strings[idx].name);
1597 if (dev->dev_ops->xstats_get_names != NULL) {
1598 /* If there are any driver-specific xstats, append them
1601 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
1603 xstats_names + cnt_used_entries,
1604 size - cnt_used_entries);
1605 if (cnt_driver_entries < 0)
1606 return cnt_driver_entries;
1607 cnt_used_entries += cnt_driver_entries;
1610 return cnt_used_entries;
1613 /* retrieve ethdev extended statistics */
1615 rte_eth_xstats_get_by_id(uint8_t port_id, const uint64_t *ids, uint64_t *values,
1618 /* If need all xstats */
1620 struct rte_eth_stats eth_stats;
1621 struct rte_eth_dev *dev;
1622 unsigned int count = 0, i, q;
1623 signed int xcount = 0;
1624 uint64_t val, *stats_ptr;
1625 uint16_t nb_rxqs, nb_txqs;
1627 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1628 dev = &rte_eth_devices[port_id];
1630 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues,
1631 RTE_ETHDEV_QUEUE_STAT_CNTRS);
1632 nb_txqs = RTE_MIN(dev->data->nb_tx_queues,
1633 RTE_ETHDEV_QUEUE_STAT_CNTRS);
1635 /* Return generic statistics */
1636 count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
1637 (nb_txqs * RTE_NB_TXQ_STATS);
1640 /* implemented by the driver */
1641 if (dev->dev_ops->xstats_get_by_id != NULL) {
1642 /* Retrieve the xstats from the driver at the end of the
1643 * xstats struct. Retrieve all xstats.
1645 xcount = (*dev->dev_ops->xstats_get_by_id)(dev,
1647 values ? values + count : NULL,
1648 (n > count) ? n - count : 0);
1652 /* implemented by the driver */
1653 } else if (dev->dev_ops->xstats_get != NULL) {
1654 /* Retrieve the xstats from the driver at the end of the
1655 * xstats struct. Retrieve all xstats.
1656 * Compatibility for PMD without xstats_get_by_ids
1658 unsigned int size = (n > count) ? n - count : 1;
1659 struct rte_eth_xstat xstats[size];
1661 xcount = (*dev->dev_ops->xstats_get)(dev,
1662 values ? xstats : NULL, size);
1668 for (i = 0 ; i < (unsigned int)xcount; i++)
1669 values[i + count] = xstats[i].value;
1672 if (n < count + xcount || values == NULL)
1673 return count + xcount;
1675 /* now fill the xstats structure */
1677 rte_eth_stats_get(port_id, ð_stats);
1680 for (i = 0; i < RTE_NB_STATS; i++) {
1681 stats_ptr = RTE_PTR_ADD(ð_stats,
1682 rte_stats_strings[i].offset);
1684 values[count++] = val;
1688 for (q = 0; q < nb_rxqs; q++) {
1689 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1690 stats_ptr = RTE_PTR_ADD(ð_stats,
1691 rte_rxq_stats_strings[i].offset +
1692 q * sizeof(uint64_t));
1694 values[count++] = val;
1699 for (q = 0; q < nb_txqs; q++) {
1700 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1701 stats_ptr = RTE_PTR_ADD(ð_stats,
1702 rte_txq_stats_strings[i].offset +
1703 q * sizeof(uint64_t));
1705 values[count++] = val;
1709 return count + xcount;
1711 /* Need only xstats given by IDS array */
1714 uint64_t *values_copy;
1716 size = rte_eth_xstats_get_by_id(port_id, NULL, NULL, 0);
1718 values_copy = malloc(sizeof(*values_copy) * size);
1720 RTE_PMD_DEBUG_TRACE(
1721 "ERROR: can't allocate memory for values_copy\n");
1725 rte_eth_xstats_get_by_id(port_id, NULL, values_copy, size);
1727 for (i = 0; i < n; i++) {
1728 if (ids[i] >= size) {
1729 RTE_PMD_DEBUG_TRACE(
1730 "ERROR: id value isn't valid\n");
1733 values[i] = values_copy[ids[i]];
1741 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstat *xstats,
1744 struct rte_eth_stats eth_stats;
1745 struct rte_eth_dev *dev;
1746 unsigned int count = 0, i, q;
1747 signed int xcount = 0;
1748 uint64_t val, *stats_ptr;
1749 uint16_t nb_rxqs, nb_txqs;
1751 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1753 dev = &rte_eth_devices[port_id];
1755 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1756 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1758 /* Return generic statistics */
1759 count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
1760 (nb_txqs * RTE_NB_TXQ_STATS);
1762 /* implemented by the driver */
1763 if (dev->dev_ops->xstats_get != NULL) {
1764 /* Retrieve the xstats from the driver at the end of the
1767 xcount = (*dev->dev_ops->xstats_get)(dev,
1768 xstats ? xstats + count : NULL,
1769 (n > count) ? n - count : 0);
1775 if (n < count + xcount || xstats == NULL)
1776 return count + xcount;
1778 /* now fill the xstats structure */
1780 rte_eth_stats_get(port_id, ð_stats);
1783 for (i = 0; i < RTE_NB_STATS; i++) {
1784 stats_ptr = RTE_PTR_ADD(ð_stats,
1785 rte_stats_strings[i].offset);
1787 xstats[count++].value = val;
1791 for (q = 0; q < nb_rxqs; q++) {
1792 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1793 stats_ptr = RTE_PTR_ADD(ð_stats,
1794 rte_rxq_stats_strings[i].offset +
1795 q * sizeof(uint64_t));
1797 xstats[count++].value = val;
1802 for (q = 0; q < nb_txqs; q++) {
1803 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1804 stats_ptr = RTE_PTR_ADD(ð_stats,
1805 rte_txq_stats_strings[i].offset +
1806 q * sizeof(uint64_t));
1808 xstats[count++].value = val;
1812 for (i = 0; i < count; i++)
1814 /* add an offset to driver-specific stats */
1815 for ( ; i < count + xcount; i++)
1816 xstats[i].id += count;
1818 return count + xcount;
1821 /* reset ethdev extended statistics */
1823 rte_eth_xstats_reset(uint8_t port_id)
1825 struct rte_eth_dev *dev;
1827 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1828 dev = &rte_eth_devices[port_id];
1830 /* implemented by the driver */
1831 if (dev->dev_ops->xstats_reset != NULL) {
1832 (*dev->dev_ops->xstats_reset)(dev);
1836 /* fallback to default */
1837 rte_eth_stats_reset(port_id);
1841 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1844 struct rte_eth_dev *dev;
1846 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1848 dev = &rte_eth_devices[port_id];
1850 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1851 return (*dev->dev_ops->queue_stats_mapping_set)
1852 (dev, queue_id, stat_idx, is_rx);
1857 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1860 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1866 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1869 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1874 rte_eth_dev_fw_version_get(uint8_t port_id, char *fw_version, size_t fw_size)
1876 struct rte_eth_dev *dev;
1878 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1879 dev = &rte_eth_devices[port_id];
1881 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP);
1882 return (*dev->dev_ops->fw_version_get)(dev, fw_version, fw_size);
1886 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1888 struct rte_eth_dev *dev;
1889 const struct rte_eth_desc_lim lim = {
1890 .nb_max = UINT16_MAX,
1895 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1896 dev = &rte_eth_devices[port_id];
1898 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1899 dev_info->rx_desc_lim = lim;
1900 dev_info->tx_desc_lim = lim;
1902 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1903 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1904 dev_info->driver_name = dev->device->driver->name;
1905 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
1906 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
1910 rte_eth_dev_get_supported_ptypes(uint8_t port_id, uint32_t ptype_mask,
1911 uint32_t *ptypes, int num)
1914 struct rte_eth_dev *dev;
1915 const uint32_t *all_ptypes;
1917 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1918 dev = &rte_eth_devices[port_id];
1919 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
1920 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
1925 for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
1926 if (all_ptypes[i] & ptype_mask) {
1928 ptypes[j] = all_ptypes[i];
1936 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1938 struct rte_eth_dev *dev;
1940 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1941 dev = &rte_eth_devices[port_id];
1942 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1947 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1949 struct rte_eth_dev *dev;
1951 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1953 dev = &rte_eth_devices[port_id];
1954 *mtu = dev->data->mtu;
1959 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1962 struct rte_eth_dev *dev;
1964 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1965 dev = &rte_eth_devices[port_id];
1966 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1968 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1970 dev->data->mtu = mtu;
1976 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1978 struct rte_eth_dev *dev;
1980 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1981 dev = &rte_eth_devices[port_id];
1982 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1983 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1987 if (vlan_id > 4095) {
1988 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1989 port_id, (unsigned) vlan_id);
1992 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1994 return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1998 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
2000 struct rte_eth_dev *dev;
2002 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2003 dev = &rte_eth_devices[port_id];
2004 if (rx_queue_id >= dev->data->nb_rx_queues) {
2005 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
2009 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
2010 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
2016 rte_eth_dev_set_vlan_ether_type(uint8_t port_id,
2017 enum rte_vlan_type vlan_type,
2020 struct rte_eth_dev *dev;
2022 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2023 dev = &rte_eth_devices[port_id];
2024 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
2026 return (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type, tpid);
2030 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
2032 struct rte_eth_dev *dev;
2037 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2038 dev = &rte_eth_devices[port_id];
2040 /*check which option changed by application*/
2041 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
2042 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
2044 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
2045 mask |= ETH_VLAN_STRIP_MASK;
2048 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
2049 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
2051 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
2052 mask |= ETH_VLAN_FILTER_MASK;
2055 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
2056 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
2058 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
2059 mask |= ETH_VLAN_EXTEND_MASK;
2066 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
2067 (*dev->dev_ops->vlan_offload_set)(dev, mask);
2073 rte_eth_dev_get_vlan_offload(uint8_t port_id)
2075 struct rte_eth_dev *dev;
2078 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2079 dev = &rte_eth_devices[port_id];
2081 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
2082 ret |= ETH_VLAN_STRIP_OFFLOAD;
2084 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
2085 ret |= ETH_VLAN_FILTER_OFFLOAD;
2087 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
2088 ret |= ETH_VLAN_EXTEND_OFFLOAD;
2094 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
2096 struct rte_eth_dev *dev;
2098 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2099 dev = &rte_eth_devices[port_id];
2100 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
2101 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
2107 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2109 struct rte_eth_dev *dev;
2111 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2112 dev = &rte_eth_devices[port_id];
2113 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2114 memset(fc_conf, 0, sizeof(*fc_conf));
2115 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
2119 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2121 struct rte_eth_dev *dev;
2123 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2124 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2125 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2129 dev = &rte_eth_devices[port_id];
2130 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2131 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
2135 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
2137 struct rte_eth_dev *dev;
2139 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2140 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2141 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2145 dev = &rte_eth_devices[port_id];
2146 /* High water, low water validation are device specific */
2147 if (*dev->dev_ops->priority_flow_ctrl_set)
2148 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
2153 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2161 num = (reta_size + RTE_RETA_GROUP_SIZE - 1) / RTE_RETA_GROUP_SIZE;
2162 for (i = 0; i < num; i++) {
2163 if (reta_conf[i].mask)
2171 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2175 uint16_t i, idx, shift;
2181 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
2185 for (i = 0; i < reta_size; i++) {
2186 idx = i / RTE_RETA_GROUP_SIZE;
2187 shift = i % RTE_RETA_GROUP_SIZE;
2188 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2189 (reta_conf[idx].reta[shift] >= max_rxq)) {
2190 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2191 "the maximum rxq index: %u\n", idx, shift,
2192 reta_conf[idx].reta[shift], max_rxq);
2201 rte_eth_dev_rss_reta_update(uint8_t port_id,
2202 struct rte_eth_rss_reta_entry64 *reta_conf,
2205 struct rte_eth_dev *dev;
2208 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2209 /* Check mask bits */
2210 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2214 dev = &rte_eth_devices[port_id];
2216 /* Check entry value */
2217 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2218 dev->data->nb_rx_queues);
2222 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2223 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2227 rte_eth_dev_rss_reta_query(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);
2236 /* Check mask bits */
2237 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2241 dev = &rte_eth_devices[port_id];
2242 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2243 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2247 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2249 struct rte_eth_dev *dev;
2250 uint16_t rss_hash_protos;
2252 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2253 rss_hash_protos = rss_conf->rss_hf;
2254 if ((rss_hash_protos != 0) &&
2255 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2256 RTE_PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2260 dev = &rte_eth_devices[port_id];
2261 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2262 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2266 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2267 struct rte_eth_rss_conf *rss_conf)
2269 struct rte_eth_dev *dev;
2271 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2272 dev = &rte_eth_devices[port_id];
2273 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2274 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2278 rte_eth_dev_udp_tunnel_port_add(uint8_t port_id,
2279 struct rte_eth_udp_tunnel *udp_tunnel)
2281 struct rte_eth_dev *dev;
2283 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2284 if (udp_tunnel == NULL) {
2285 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2289 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2290 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2294 dev = &rte_eth_devices[port_id];
2295 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
2296 return (*dev->dev_ops->udp_tunnel_port_add)(dev, udp_tunnel);
2300 rte_eth_dev_udp_tunnel_port_delete(uint8_t port_id,
2301 struct rte_eth_udp_tunnel *udp_tunnel)
2303 struct rte_eth_dev *dev;
2305 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2306 dev = &rte_eth_devices[port_id];
2308 if (udp_tunnel == NULL) {
2309 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2313 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2314 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2318 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
2319 return (*dev->dev_ops->udp_tunnel_port_del)(dev, udp_tunnel);
2323 rte_eth_led_on(uint8_t port_id)
2325 struct rte_eth_dev *dev;
2327 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2328 dev = &rte_eth_devices[port_id];
2329 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2330 return (*dev->dev_ops->dev_led_on)(dev);
2334 rte_eth_led_off(uint8_t port_id)
2336 struct rte_eth_dev *dev;
2338 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2339 dev = &rte_eth_devices[port_id];
2340 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2341 return (*dev->dev_ops->dev_led_off)(dev);
2345 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2349 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2351 struct rte_eth_dev_info dev_info;
2352 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2355 rte_eth_dev_info_get(port_id, &dev_info);
2357 for (i = 0; i < dev_info.max_mac_addrs; i++)
2358 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2364 static const struct ether_addr null_mac_addr;
2367 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2370 struct rte_eth_dev *dev;
2375 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2376 dev = &rte_eth_devices[port_id];
2377 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2379 if (is_zero_ether_addr(addr)) {
2380 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2384 if (pool >= ETH_64_POOLS) {
2385 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2389 index = get_mac_addr_index(port_id, addr);
2391 index = get_mac_addr_index(port_id, &null_mac_addr);
2393 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2398 pool_mask = dev->data->mac_pool_sel[index];
2400 /* Check if both MAC address and pool is already there, and do nothing */
2401 if (pool_mask & (1ULL << pool))
2406 ret = (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2409 /* Update address in NIC data structure */
2410 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2412 /* Update pool bitmap in NIC data structure */
2413 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2420 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2422 struct rte_eth_dev *dev;
2425 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2426 dev = &rte_eth_devices[port_id];
2427 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2429 index = get_mac_addr_index(port_id, addr);
2431 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2433 } else if (index < 0)
2434 return 0; /* Do nothing if address wasn't found */
2437 (*dev->dev_ops->mac_addr_remove)(dev, index);
2439 /* Update address in NIC data structure */
2440 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2442 /* reset pool bitmap */
2443 dev->data->mac_pool_sel[index] = 0;
2449 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2451 struct rte_eth_dev *dev;
2453 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2455 if (!is_valid_assigned_ether_addr(addr))
2458 dev = &rte_eth_devices[port_id];
2459 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2461 /* Update default address in NIC data structure */
2462 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2464 (*dev->dev_ops->mac_addr_set)(dev, addr);
2471 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2475 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2477 struct rte_eth_dev_info dev_info;
2478 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2481 rte_eth_dev_info_get(port_id, &dev_info);
2482 if (!dev->data->hash_mac_addrs)
2485 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2486 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2487 ETHER_ADDR_LEN) == 0)
2494 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2499 struct rte_eth_dev *dev;
2501 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2503 dev = &rte_eth_devices[port_id];
2504 if (is_zero_ether_addr(addr)) {
2505 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2510 index = get_hash_mac_addr_index(port_id, addr);
2511 /* Check if it's already there, and do nothing */
2512 if ((index >= 0) && (on))
2517 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2518 "set in UTA\n", port_id);
2522 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2524 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2530 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2531 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2533 /* Update address in NIC data structure */
2535 ether_addr_copy(addr,
2536 &dev->data->hash_mac_addrs[index]);
2538 ether_addr_copy(&null_mac_addr,
2539 &dev->data->hash_mac_addrs[index]);
2546 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2548 struct rte_eth_dev *dev;
2550 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2552 dev = &rte_eth_devices[port_id];
2554 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2555 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2558 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2561 struct rte_eth_dev *dev;
2562 struct rte_eth_dev_info dev_info;
2563 struct rte_eth_link link;
2565 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2567 dev = &rte_eth_devices[port_id];
2568 rte_eth_dev_info_get(port_id, &dev_info);
2569 link = dev->data->dev_link;
2571 if (queue_idx > dev_info.max_tx_queues) {
2572 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2573 "invalid queue id=%d\n", port_id, queue_idx);
2577 if (tx_rate > link.link_speed) {
2578 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2579 "bigger than link speed= %d\n",
2580 tx_rate, link.link_speed);
2584 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2585 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2589 rte_eth_mirror_rule_set(uint8_t port_id,
2590 struct rte_eth_mirror_conf *mirror_conf,
2591 uint8_t rule_id, uint8_t on)
2593 struct rte_eth_dev *dev;
2595 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2596 if (mirror_conf->rule_type == 0) {
2597 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2601 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2602 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2607 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2608 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2609 (mirror_conf->pool_mask == 0)) {
2610 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2614 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2615 mirror_conf->vlan.vlan_mask == 0) {
2616 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2620 dev = &rte_eth_devices[port_id];
2621 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2623 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2627 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2629 struct rte_eth_dev *dev;
2631 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2633 dev = &rte_eth_devices[port_id];
2634 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2636 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2640 rte_eth_dev_callback_register(uint8_t port_id,
2641 enum rte_eth_event_type event,
2642 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2644 struct rte_eth_dev *dev;
2645 struct rte_eth_dev_callback *user_cb;
2650 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2652 dev = &rte_eth_devices[port_id];
2653 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2655 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2656 if (user_cb->cb_fn == cb_fn &&
2657 user_cb->cb_arg == cb_arg &&
2658 user_cb->event == event) {
2663 /* create a new callback. */
2664 if (user_cb == NULL) {
2665 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2666 sizeof(struct rte_eth_dev_callback), 0);
2667 if (user_cb != NULL) {
2668 user_cb->cb_fn = cb_fn;
2669 user_cb->cb_arg = cb_arg;
2670 user_cb->event = event;
2671 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2675 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2676 return (user_cb == NULL) ? -ENOMEM : 0;
2680 rte_eth_dev_callback_unregister(uint8_t port_id,
2681 enum rte_eth_event_type event,
2682 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2685 struct rte_eth_dev *dev;
2686 struct rte_eth_dev_callback *cb, *next;
2691 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2693 dev = &rte_eth_devices[port_id];
2694 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2697 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2699 next = TAILQ_NEXT(cb, next);
2701 if (cb->cb_fn != cb_fn || cb->event != event ||
2702 (cb->cb_arg != (void *)-1 &&
2703 cb->cb_arg != cb_arg))
2707 * if this callback is not executing right now,
2710 if (cb->active == 0) {
2711 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2718 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2723 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2724 enum rte_eth_event_type event, void *cb_arg, void *ret_param)
2726 struct rte_eth_dev_callback *cb_lst;
2727 struct rte_eth_dev_callback dev_cb;
2730 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2731 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2732 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2737 dev_cb.cb_arg = cb_arg;
2738 if (ret_param != NULL)
2739 dev_cb.ret_param = ret_param;
2741 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2742 rc = dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2743 dev_cb.cb_arg, dev_cb.ret_param);
2744 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2747 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2752 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
2755 struct rte_eth_dev *dev;
2756 struct rte_intr_handle *intr_handle;
2760 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2762 dev = &rte_eth_devices[port_id];
2764 if (!dev->intr_handle) {
2765 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
2769 intr_handle = dev->intr_handle;
2770 if (!intr_handle->intr_vec) {
2771 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2775 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2776 vec = intr_handle->intr_vec[qid];
2777 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2778 if (rc && rc != -EEXIST) {
2779 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2780 " op %d epfd %d vec %u\n",
2781 port_id, qid, op, epfd, vec);
2788 const struct rte_memzone *
2789 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2790 uint16_t queue_id, size_t size, unsigned align,
2793 char z_name[RTE_MEMZONE_NAMESIZE];
2794 const struct rte_memzone *mz;
2796 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2797 dev->device->driver->name, ring_name,
2798 dev->data->port_id, queue_id);
2800 mz = rte_memzone_lookup(z_name);
2804 if (rte_xen_dom0_supported())
2805 return rte_memzone_reserve_bounded(z_name, size, socket_id,
2806 0, align, RTE_PGSIZE_2M);
2808 return rte_memzone_reserve_aligned(z_name, size, socket_id,
2813 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
2814 int epfd, int op, void *data)
2817 struct rte_eth_dev *dev;
2818 struct rte_intr_handle *intr_handle;
2821 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2823 dev = &rte_eth_devices[port_id];
2824 if (queue_id >= dev->data->nb_rx_queues) {
2825 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
2829 if (!dev->intr_handle) {
2830 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
2834 intr_handle = dev->intr_handle;
2835 if (!intr_handle->intr_vec) {
2836 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2840 vec = intr_handle->intr_vec[queue_id];
2841 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2842 if (rc && rc != -EEXIST) {
2843 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2844 " op %d epfd %d vec %u\n",
2845 port_id, queue_id, op, epfd, vec);
2853 rte_eth_dev_rx_intr_enable(uint8_t port_id,
2856 struct rte_eth_dev *dev;
2858 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2860 dev = &rte_eth_devices[port_id];
2862 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
2863 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
2867 rte_eth_dev_rx_intr_disable(uint8_t port_id,
2870 struct rte_eth_dev *dev;
2872 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2874 dev = &rte_eth_devices[port_id];
2876 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
2877 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
2882 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
2884 struct rte_eth_dev *dev;
2886 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2888 dev = &rte_eth_devices[port_id];
2889 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2890 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
2891 RTE_ETH_FILTER_NOP, NULL);
2895 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
2896 enum rte_filter_op filter_op, void *arg)
2898 struct rte_eth_dev *dev;
2900 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2902 dev = &rte_eth_devices[port_id];
2903 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2904 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
2908 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
2909 rte_rx_callback_fn fn, void *user_param)
2911 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2912 rte_errno = ENOTSUP;
2915 /* check input parameters */
2916 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2917 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2921 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2929 cb->param = user_param;
2931 rte_spinlock_lock(&rte_eth_rx_cb_lock);
2932 /* Add the callbacks in fifo order. */
2933 struct rte_eth_rxtx_callback *tail =
2934 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2937 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2944 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
2950 rte_eth_add_first_rx_callback(uint8_t port_id, uint16_t queue_id,
2951 rte_rx_callback_fn fn, void *user_param)
2953 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2954 rte_errno = ENOTSUP;
2957 /* check input parameters */
2958 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2959 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2964 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2972 cb->param = user_param;
2974 rte_spinlock_lock(&rte_eth_rx_cb_lock);
2975 /* Add the callbacks at fisrt position*/
2976 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2978 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2979 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
2985 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
2986 rte_tx_callback_fn fn, void *user_param)
2988 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2989 rte_errno = ENOTSUP;
2992 /* check input parameters */
2993 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2994 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
2999 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3007 cb->param = user_param;
3009 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3010 /* Add the callbacks in fifo order. */
3011 struct rte_eth_rxtx_callback *tail =
3012 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3015 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3022 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3028 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3029 struct rte_eth_rxtx_callback *user_cb)
3031 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3034 /* Check input parameters. */
3035 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3036 if (user_cb == NULL ||
3037 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
3040 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3041 struct rte_eth_rxtx_callback *cb;
3042 struct rte_eth_rxtx_callback **prev_cb;
3045 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3046 prev_cb = &dev->post_rx_burst_cbs[queue_id];
3047 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3049 if (cb == user_cb) {
3050 /* Remove the user cb from the callback list. */
3051 *prev_cb = cb->next;
3056 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3062 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3063 struct rte_eth_rxtx_callback *user_cb)
3065 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3068 /* Check input parameters. */
3069 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3070 if (user_cb == NULL ||
3071 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
3074 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3076 struct rte_eth_rxtx_callback *cb;
3077 struct rte_eth_rxtx_callback **prev_cb;
3079 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3080 prev_cb = &dev->pre_tx_burst_cbs[queue_id];
3081 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3083 if (cb == user_cb) {
3084 /* Remove the user cb from the callback list. */
3085 *prev_cb = cb->next;
3090 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3096 rte_eth_rx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3097 struct rte_eth_rxq_info *qinfo)
3099 struct rte_eth_dev *dev;
3101 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3106 dev = &rte_eth_devices[port_id];
3107 if (queue_id >= dev->data->nb_rx_queues) {
3108 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3112 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3114 memset(qinfo, 0, sizeof(*qinfo));
3115 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3120 rte_eth_tx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3121 struct rte_eth_txq_info *qinfo)
3123 struct rte_eth_dev *dev;
3125 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3130 dev = &rte_eth_devices[port_id];
3131 if (queue_id >= dev->data->nb_tx_queues) {
3132 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3136 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3138 memset(qinfo, 0, sizeof(*qinfo));
3139 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3144 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3145 struct ether_addr *mc_addr_set,
3146 uint32_t nb_mc_addr)
3148 struct rte_eth_dev *dev;
3150 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3152 dev = &rte_eth_devices[port_id];
3153 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3154 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3158 rte_eth_timesync_enable(uint8_t port_id)
3160 struct rte_eth_dev *dev;
3162 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3163 dev = &rte_eth_devices[port_id];
3165 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3166 return (*dev->dev_ops->timesync_enable)(dev);
3170 rte_eth_timesync_disable(uint8_t port_id)
3172 struct rte_eth_dev *dev;
3174 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3175 dev = &rte_eth_devices[port_id];
3177 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3178 return (*dev->dev_ops->timesync_disable)(dev);
3182 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3185 struct rte_eth_dev *dev;
3187 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3188 dev = &rte_eth_devices[port_id];
3190 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3191 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3195 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3197 struct rte_eth_dev *dev;
3199 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3200 dev = &rte_eth_devices[port_id];
3202 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3203 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3207 rte_eth_timesync_adjust_time(uint8_t port_id, int64_t delta)
3209 struct rte_eth_dev *dev;
3211 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3212 dev = &rte_eth_devices[port_id];
3214 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3215 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3219 rte_eth_timesync_read_time(uint8_t port_id, struct timespec *timestamp)
3221 struct rte_eth_dev *dev;
3223 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3224 dev = &rte_eth_devices[port_id];
3226 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3227 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3231 rte_eth_timesync_write_time(uint8_t port_id, const struct timespec *timestamp)
3233 struct rte_eth_dev *dev;
3235 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3236 dev = &rte_eth_devices[port_id];
3238 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3239 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3243 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3245 struct rte_eth_dev *dev;
3247 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3249 dev = &rte_eth_devices[port_id];
3250 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3251 return (*dev->dev_ops->get_reg)(dev, info);
3255 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3257 struct rte_eth_dev *dev;
3259 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3261 dev = &rte_eth_devices[port_id];
3262 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3263 return (*dev->dev_ops->get_eeprom_length)(dev);
3267 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3269 struct rte_eth_dev *dev;
3271 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3273 dev = &rte_eth_devices[port_id];
3274 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3275 return (*dev->dev_ops->get_eeprom)(dev, info);
3279 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3281 struct rte_eth_dev *dev;
3283 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3285 dev = &rte_eth_devices[port_id];
3286 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3287 return (*dev->dev_ops->set_eeprom)(dev, info);
3291 rte_eth_dev_get_dcb_info(uint8_t port_id,
3292 struct rte_eth_dcb_info *dcb_info)
3294 struct rte_eth_dev *dev;
3296 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3298 dev = &rte_eth_devices[port_id];
3299 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3301 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3302 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3306 rte_eth_dev_l2_tunnel_eth_type_conf(uint8_t port_id,
3307 struct rte_eth_l2_tunnel_conf *l2_tunnel)
3309 struct rte_eth_dev *dev;
3311 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3312 if (l2_tunnel == NULL) {
3313 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3317 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3318 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
3322 dev = &rte_eth_devices[port_id];
3323 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
3325 return (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev, l2_tunnel);
3329 rte_eth_dev_l2_tunnel_offload_set(uint8_t port_id,
3330 struct rte_eth_l2_tunnel_conf *l2_tunnel,
3334 struct rte_eth_dev *dev;
3336 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3338 if (l2_tunnel == NULL) {
3339 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3343 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3344 RTE_PMD_DEBUG_TRACE("Invalid tunnel type.\n");
3349 RTE_PMD_DEBUG_TRACE("Mask should have a value.\n");
3353 dev = &rte_eth_devices[port_id];
3354 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
3356 return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);