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(uint16_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(uint16_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;
216 rte_eth_dev_allocate(const char *name)
219 struct rte_eth_dev *eth_dev;
221 port_id = rte_eth_dev_find_free_port();
222 if (port_id == RTE_MAX_ETHPORTS) {
223 RTE_PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
227 if (rte_eth_dev_data == NULL)
228 rte_eth_dev_data_alloc();
230 if (rte_eth_dev_allocated(name) != NULL) {
231 RTE_PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n",
236 memset(&rte_eth_dev_data[port_id], 0, sizeof(struct rte_eth_dev_data));
237 eth_dev = eth_dev_get(port_id);
238 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
239 eth_dev->data->port_id = port_id;
240 eth_dev->data->mtu = ETHER_MTU;
246 * Attach to a port already registered by the primary process, which
247 * makes sure that the same device would have the same port id both
248 * in the primary and secondary process.
251 rte_eth_dev_attach_secondary(const char *name)
254 struct rte_eth_dev *eth_dev;
256 if (rte_eth_dev_data == NULL)
257 rte_eth_dev_data_alloc();
259 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
260 if (strcmp(rte_eth_dev_data[i].name, name) == 0)
263 if (i == RTE_MAX_ETHPORTS) {
265 "device %s is not driven by the primary process\n",
270 eth_dev = eth_dev_get(i);
271 RTE_ASSERT(eth_dev->data->port_id == i);
277 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
282 eth_dev->state = RTE_ETH_DEV_UNUSED;
287 rte_eth_dev_is_valid_port(uint16_t port_id)
289 if (port_id >= RTE_MAX_ETHPORTS ||
290 (rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
291 rte_eth_devices[port_id].state != RTE_ETH_DEV_DEFERRED))
298 rte_eth_dev_socket_id(uint16_t port_id)
300 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
301 return rte_eth_devices[port_id].data->numa_node;
305 rte_eth_dev_count(void)
312 RTE_ETH_FOREACH_DEV(p)
319 rte_eth_dev_get_name_by_port(uint16_t port_id, char *name)
323 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
326 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
330 /* shouldn't check 'rte_eth_devices[i].data',
331 * because it might be overwritten by VDEV PMD */
332 tmp = rte_eth_dev_data[port_id].name;
338 rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
343 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
347 RTE_ETH_FOREACH_DEV(i) {
349 rte_eth_dev_data[i].name, strlen(name))) {
360 rte_eth_dev_is_detachable(uint16_t port_id)
364 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
366 dev_flags = rte_eth_devices[port_id].data->dev_flags;
367 if ((dev_flags & RTE_ETH_DEV_DETACHABLE) &&
368 (!(dev_flags & RTE_ETH_DEV_BONDED_SLAVE)))
374 /* attach the new device, then store port_id of the device */
376 rte_eth_dev_attach(const char *devargs, uint16_t *port_id)
379 int current = rte_eth_dev_count();
383 if ((devargs == NULL) || (port_id == NULL)) {
388 /* parse devargs, then retrieve device name and args */
389 if (rte_eal_parse_devargs_str(devargs, &name, &args))
392 ret = rte_eal_dev_attach(name, args);
396 /* no point looking at the port count if no port exists */
397 if (!rte_eth_dev_count()) {
398 RTE_LOG(ERR, EAL, "No port found for device (%s)\n", name);
403 /* if nothing happened, there is a bug here, since some driver told us
404 * it did attach a device, but did not create a port.
406 if (current == rte_eth_dev_count()) {
411 *port_id = eth_dev_last_created_port;
420 /* detach the device, then store the name of the device */
422 rte_eth_dev_detach(uint16_t port_id, char *name)
431 /* FIXME: move this to eal, once device flags are relocated there */
432 if (rte_eth_dev_is_detachable(port_id))
435 snprintf(name, sizeof(rte_eth_devices[port_id].data->name),
436 "%s", rte_eth_devices[port_id].data->name);
438 ret = rte_eal_dev_detach(rte_eth_devices[port_id].device);
442 rte_eth_devices[port_id].state = RTE_ETH_DEV_UNUSED;
450 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
452 uint16_t old_nb_queues = dev->data->nb_rx_queues;
456 if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */
457 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
458 sizeof(dev->data->rx_queues[0]) * nb_queues,
459 RTE_CACHE_LINE_SIZE);
460 if (dev->data->rx_queues == NULL) {
461 dev->data->nb_rx_queues = 0;
464 } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */
465 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
467 rxq = dev->data->rx_queues;
469 for (i = nb_queues; i < old_nb_queues; i++)
470 (*dev->dev_ops->rx_queue_release)(rxq[i]);
471 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
472 RTE_CACHE_LINE_SIZE);
475 if (nb_queues > old_nb_queues) {
476 uint16_t new_qs = nb_queues - old_nb_queues;
478 memset(rxq + old_nb_queues, 0,
479 sizeof(rxq[0]) * new_qs);
482 dev->data->rx_queues = rxq;
484 } else if (dev->data->rx_queues != NULL && nb_queues == 0) {
485 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
487 rxq = dev->data->rx_queues;
489 for (i = nb_queues; i < old_nb_queues; i++)
490 (*dev->dev_ops->rx_queue_release)(rxq[i]);
492 rte_free(dev->data->rx_queues);
493 dev->data->rx_queues = NULL;
495 dev->data->nb_rx_queues = nb_queues;
500 rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id)
502 struct rte_eth_dev *dev;
504 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
506 dev = &rte_eth_devices[port_id];
507 if (rx_queue_id >= dev->data->nb_rx_queues) {
508 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
512 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
514 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
515 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
516 " already started\n",
517 rx_queue_id, port_id);
521 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
526 rte_eth_dev_rx_queue_stop(uint16_t port_id, uint16_t rx_queue_id)
528 struct rte_eth_dev *dev;
530 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
532 dev = &rte_eth_devices[port_id];
533 if (rx_queue_id >= dev->data->nb_rx_queues) {
534 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
538 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
540 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
541 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
542 " already stopped\n",
543 rx_queue_id, port_id);
547 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
552 rte_eth_dev_tx_queue_start(uint16_t port_id, uint16_t tx_queue_id)
554 struct rte_eth_dev *dev;
556 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
558 dev = &rte_eth_devices[port_id];
559 if (tx_queue_id >= dev->data->nb_tx_queues) {
560 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
564 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
566 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
567 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
568 " already started\n",
569 tx_queue_id, port_id);
573 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
578 rte_eth_dev_tx_queue_stop(uint16_t port_id, uint16_t tx_queue_id)
580 struct rte_eth_dev *dev;
582 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
584 dev = &rte_eth_devices[port_id];
585 if (tx_queue_id >= dev->data->nb_tx_queues) {
586 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
590 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
592 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
593 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
594 " already stopped\n",
595 tx_queue_id, port_id);
599 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
604 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
606 uint16_t old_nb_queues = dev->data->nb_tx_queues;
610 if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */
611 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
612 sizeof(dev->data->tx_queues[0]) * nb_queues,
613 RTE_CACHE_LINE_SIZE);
614 if (dev->data->tx_queues == NULL) {
615 dev->data->nb_tx_queues = 0;
618 } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */
619 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
621 txq = dev->data->tx_queues;
623 for (i = nb_queues; i < old_nb_queues; i++)
624 (*dev->dev_ops->tx_queue_release)(txq[i]);
625 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
626 RTE_CACHE_LINE_SIZE);
629 if (nb_queues > old_nb_queues) {
630 uint16_t new_qs = nb_queues - old_nb_queues;
632 memset(txq + old_nb_queues, 0,
633 sizeof(txq[0]) * new_qs);
636 dev->data->tx_queues = txq;
638 } else if (dev->data->tx_queues != NULL && nb_queues == 0) {
639 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
641 txq = dev->data->tx_queues;
643 for (i = nb_queues; i < old_nb_queues; i++)
644 (*dev->dev_ops->tx_queue_release)(txq[i]);
646 rte_free(dev->data->tx_queues);
647 dev->data->tx_queues = NULL;
649 dev->data->nb_tx_queues = nb_queues;
654 rte_eth_speed_bitflag(uint32_t speed, int duplex)
657 case ETH_SPEED_NUM_10M:
658 return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD;
659 case ETH_SPEED_NUM_100M:
660 return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD;
661 case ETH_SPEED_NUM_1G:
662 return ETH_LINK_SPEED_1G;
663 case ETH_SPEED_NUM_2_5G:
664 return ETH_LINK_SPEED_2_5G;
665 case ETH_SPEED_NUM_5G:
666 return ETH_LINK_SPEED_5G;
667 case ETH_SPEED_NUM_10G:
668 return ETH_LINK_SPEED_10G;
669 case ETH_SPEED_NUM_20G:
670 return ETH_LINK_SPEED_20G;
671 case ETH_SPEED_NUM_25G:
672 return ETH_LINK_SPEED_25G;
673 case ETH_SPEED_NUM_40G:
674 return ETH_LINK_SPEED_40G;
675 case ETH_SPEED_NUM_50G:
676 return ETH_LINK_SPEED_50G;
677 case ETH_SPEED_NUM_56G:
678 return ETH_LINK_SPEED_56G;
679 case ETH_SPEED_NUM_100G:
680 return ETH_LINK_SPEED_100G;
687 * A conversion function from rxmode bitfield API.
690 rte_eth_convert_rx_offload_bitfield(const struct rte_eth_rxmode *rxmode,
691 uint64_t *rx_offloads)
693 uint64_t offloads = 0;
695 if (rxmode->header_split == 1)
696 offloads |= DEV_RX_OFFLOAD_HEADER_SPLIT;
697 if (rxmode->hw_ip_checksum == 1)
698 offloads |= DEV_RX_OFFLOAD_CHECKSUM;
699 if (rxmode->hw_vlan_filter == 1)
700 offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
701 if (rxmode->hw_vlan_strip == 1)
702 offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
703 if (rxmode->hw_vlan_extend == 1)
704 offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
705 if (rxmode->jumbo_frame == 1)
706 offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
707 if (rxmode->hw_strip_crc == 1)
708 offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
709 if (rxmode->enable_scatter == 1)
710 offloads |= DEV_RX_OFFLOAD_SCATTER;
711 if (rxmode->enable_lro == 1)
712 offloads |= DEV_RX_OFFLOAD_TCP_LRO;
713 if (rxmode->hw_timestamp == 1)
714 offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
716 *rx_offloads = offloads;
720 * A conversion function from rxmode offloads API.
723 rte_eth_convert_rx_offloads(const uint64_t rx_offloads,
724 struct rte_eth_rxmode *rxmode)
727 if (rx_offloads & DEV_RX_OFFLOAD_HEADER_SPLIT)
728 rxmode->header_split = 1;
730 rxmode->header_split = 0;
731 if (rx_offloads & DEV_RX_OFFLOAD_CHECKSUM)
732 rxmode->hw_ip_checksum = 1;
734 rxmode->hw_ip_checksum = 0;
735 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
736 rxmode->hw_vlan_filter = 1;
738 rxmode->hw_vlan_filter = 0;
739 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
740 rxmode->hw_vlan_strip = 1;
742 rxmode->hw_vlan_strip = 0;
743 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND)
744 rxmode->hw_vlan_extend = 1;
746 rxmode->hw_vlan_extend = 0;
747 if (rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME)
748 rxmode->jumbo_frame = 1;
750 rxmode->jumbo_frame = 0;
751 if (rx_offloads & DEV_RX_OFFLOAD_CRC_STRIP)
752 rxmode->hw_strip_crc = 1;
754 rxmode->hw_strip_crc = 0;
755 if (rx_offloads & DEV_RX_OFFLOAD_SCATTER)
756 rxmode->enable_scatter = 1;
758 rxmode->enable_scatter = 0;
759 if (rx_offloads & DEV_RX_OFFLOAD_TCP_LRO)
760 rxmode->enable_lro = 1;
762 rxmode->enable_lro = 0;
763 if (rx_offloads & DEV_RX_OFFLOAD_TIMESTAMP)
764 rxmode->hw_timestamp = 1;
766 rxmode->hw_timestamp = 0;
770 rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
771 const struct rte_eth_conf *dev_conf)
773 struct rte_eth_dev *dev;
774 struct rte_eth_dev_info dev_info;
775 struct rte_eth_conf local_conf = *dev_conf;
778 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
780 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
782 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
783 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
787 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
789 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
790 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
794 dev = &rte_eth_devices[port_id];
796 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
797 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
799 if (dev->data->dev_started) {
801 "port %d must be stopped to allow configuration\n", port_id);
806 * Convert between the offloads API to enable PMDs to support
809 if ((dev_conf->rxmode.ignore_offload_bitfield == 0)) {
810 rte_eth_convert_rx_offload_bitfield(
811 &dev_conf->rxmode, &local_conf.rxmode.offloads);
813 rte_eth_convert_rx_offloads(dev_conf->rxmode.offloads,
817 /* Copy the dev_conf parameter into the dev structure */
818 memcpy(&dev->data->dev_conf, &local_conf, sizeof(dev->data->dev_conf));
821 * Check that the numbers of RX and TX queues are not greater
822 * than the maximum number of RX and TX queues supported by the
825 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
827 if (nb_rx_q == 0 && nb_tx_q == 0) {
828 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d both rx and tx queue cannot be 0\n", port_id);
832 if (nb_rx_q > dev_info.max_rx_queues) {
833 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
834 port_id, nb_rx_q, dev_info.max_rx_queues);
838 if (nb_tx_q > dev_info.max_tx_queues) {
839 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
840 port_id, nb_tx_q, dev_info.max_tx_queues);
844 /* Check that the device supports requested interrupts */
845 if ((dev_conf->intr_conf.lsc == 1) &&
846 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
847 RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
848 dev->device->driver->name);
851 if ((dev_conf->intr_conf.rmv == 1) &&
852 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_RMV))) {
853 RTE_PMD_DEBUG_TRACE("driver %s does not support rmv\n",
854 dev->device->driver->name);
859 * If jumbo frames are enabled, check that the maximum RX packet
860 * length is supported by the configured device.
862 if (local_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
863 if (dev_conf->rxmode.max_rx_pkt_len >
864 dev_info.max_rx_pktlen) {
865 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
866 " > max valid value %u\n",
868 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
869 (unsigned)dev_info.max_rx_pktlen);
871 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
872 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
873 " < min valid value %u\n",
875 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
876 (unsigned)ETHER_MIN_LEN);
880 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
881 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
882 /* Use default value */
883 dev->data->dev_conf.rxmode.max_rx_pkt_len =
888 * Setup new number of RX/TX queues and reconfigure device.
890 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
892 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
897 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
899 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
901 rte_eth_dev_rx_queue_config(dev, 0);
905 diag = (*dev->dev_ops->dev_configure)(dev);
907 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
909 rte_eth_dev_rx_queue_config(dev, 0);
910 rte_eth_dev_tx_queue_config(dev, 0);
914 /* Initialize Rx profiling if enabled at compilation time. */
915 diag = __rte_eth_profile_rx_init(port_id, dev);
917 RTE_PMD_DEBUG_TRACE("port%d __rte_eth_profile_rx_init = %d\n",
919 rte_eth_dev_rx_queue_config(dev, 0);
920 rte_eth_dev_tx_queue_config(dev, 0);
928 _rte_eth_dev_reset(struct rte_eth_dev *dev)
930 if (dev->data->dev_started) {
932 "port %d must be stopped to allow reset\n",
937 rte_eth_dev_rx_queue_config(dev, 0);
938 rte_eth_dev_tx_queue_config(dev, 0);
940 memset(&dev->data->dev_conf, 0, sizeof(dev->data->dev_conf));
944 rte_eth_dev_config_restore(uint16_t port_id)
946 struct rte_eth_dev *dev;
947 struct rte_eth_dev_info dev_info;
948 struct ether_addr *addr;
953 dev = &rte_eth_devices[port_id];
955 rte_eth_dev_info_get(port_id, &dev_info);
957 /* replay MAC address configuration including default MAC */
958 addr = &dev->data->mac_addrs[0];
959 if (*dev->dev_ops->mac_addr_set != NULL)
960 (*dev->dev_ops->mac_addr_set)(dev, addr);
961 else if (*dev->dev_ops->mac_addr_add != NULL)
962 (*dev->dev_ops->mac_addr_add)(dev, addr, 0, pool);
964 if (*dev->dev_ops->mac_addr_add != NULL) {
965 for (i = 1; i < dev_info.max_mac_addrs; i++) {
966 addr = &dev->data->mac_addrs[i];
968 /* skip zero address */
969 if (is_zero_ether_addr(addr))
973 pool_mask = dev->data->mac_pool_sel[i];
976 if (pool_mask & 1ULL)
977 (*dev->dev_ops->mac_addr_add)(dev,
985 /* replay promiscuous configuration */
986 if (rte_eth_promiscuous_get(port_id) == 1)
987 rte_eth_promiscuous_enable(port_id);
988 else if (rte_eth_promiscuous_get(port_id) == 0)
989 rte_eth_promiscuous_disable(port_id);
991 /* replay all multicast configuration */
992 if (rte_eth_allmulticast_get(port_id) == 1)
993 rte_eth_allmulticast_enable(port_id);
994 else if (rte_eth_allmulticast_get(port_id) == 0)
995 rte_eth_allmulticast_disable(port_id);
999 rte_eth_dev_start(uint16_t port_id)
1001 struct rte_eth_dev *dev;
1004 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1006 dev = &rte_eth_devices[port_id];
1008 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1010 if (dev->data->dev_started != 0) {
1011 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu16
1012 " already started\n",
1017 diag = (*dev->dev_ops->dev_start)(dev);
1019 dev->data->dev_started = 1;
1023 rte_eth_dev_config_restore(port_id);
1025 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1026 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1027 (*dev->dev_ops->link_update)(dev, 0);
1033 rte_eth_dev_stop(uint16_t port_id)
1035 struct rte_eth_dev *dev;
1037 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1038 dev = &rte_eth_devices[port_id];
1040 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1042 if (dev->data->dev_started == 0) {
1043 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu16
1044 " already stopped\n",
1049 dev->data->dev_started = 0;
1050 (*dev->dev_ops->dev_stop)(dev);
1054 rte_eth_dev_set_link_up(uint16_t port_id)
1056 struct rte_eth_dev *dev;
1058 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1060 dev = &rte_eth_devices[port_id];
1062 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1063 return (*dev->dev_ops->dev_set_link_up)(dev);
1067 rte_eth_dev_set_link_down(uint16_t port_id)
1069 struct rte_eth_dev *dev;
1071 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1073 dev = &rte_eth_devices[port_id];
1075 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1076 return (*dev->dev_ops->dev_set_link_down)(dev);
1080 rte_eth_dev_close(uint16_t port_id)
1082 struct rte_eth_dev *dev;
1084 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1085 dev = &rte_eth_devices[port_id];
1087 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1088 dev->data->dev_started = 0;
1089 (*dev->dev_ops->dev_close)(dev);
1091 dev->data->nb_rx_queues = 0;
1092 rte_free(dev->data->rx_queues);
1093 dev->data->rx_queues = NULL;
1094 dev->data->nb_tx_queues = 0;
1095 rte_free(dev->data->tx_queues);
1096 dev->data->tx_queues = NULL;
1100 rte_eth_dev_reset(uint16_t port_id)
1102 struct rte_eth_dev *dev;
1105 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1106 dev = &rte_eth_devices[port_id];
1108 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_reset, -ENOTSUP);
1110 rte_eth_dev_stop(port_id);
1111 ret = dev->dev_ops->dev_reset(dev);
1117 rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
1118 uint16_t nb_rx_desc, unsigned int socket_id,
1119 const struct rte_eth_rxconf *rx_conf,
1120 struct rte_mempool *mp)
1123 uint32_t mbp_buf_size;
1124 struct rte_eth_dev *dev;
1125 struct rte_eth_dev_info dev_info;
1126 struct rte_eth_rxconf local_conf;
1129 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1131 dev = &rte_eth_devices[port_id];
1132 if (rx_queue_id >= dev->data->nb_rx_queues) {
1133 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1137 if (dev->data->dev_started) {
1138 RTE_PMD_DEBUG_TRACE(
1139 "port %d must be stopped to allow configuration\n", port_id);
1143 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1144 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1147 * Check the size of the mbuf data buffer.
1148 * This value must be provided in the private data of the memory pool.
1149 * First check that the memory pool has a valid private data.
1151 rte_eth_dev_info_get(port_id, &dev_info);
1152 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1153 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1154 mp->name, (int) mp->private_data_size,
1155 (int) sizeof(struct rte_pktmbuf_pool_private));
1158 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1160 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1161 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1162 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1166 (int)(RTE_PKTMBUF_HEADROOM +
1167 dev_info.min_rx_bufsize),
1168 (int)RTE_PKTMBUF_HEADROOM,
1169 (int)dev_info.min_rx_bufsize);
1173 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1174 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1175 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1177 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1178 "should be: <= %hu, = %hu, and a product of %hu\n",
1180 dev_info.rx_desc_lim.nb_max,
1181 dev_info.rx_desc_lim.nb_min,
1182 dev_info.rx_desc_lim.nb_align);
1186 rxq = dev->data->rx_queues;
1187 if (rxq[rx_queue_id]) {
1188 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release,
1190 (*dev->dev_ops->rx_queue_release)(rxq[rx_queue_id]);
1191 rxq[rx_queue_id] = NULL;
1194 if (rx_conf == NULL)
1195 rx_conf = &dev_info.default_rxconf;
1197 local_conf = *rx_conf;
1198 if (dev->data->dev_conf.rxmode.ignore_offload_bitfield == 0) {
1200 * Reflect port offloads to queue offloads in order for
1201 * offloads to not be discarded.
1203 rte_eth_convert_rx_offload_bitfield(&dev->data->dev_conf.rxmode,
1204 &local_conf.offloads);
1207 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1208 socket_id, &local_conf, mp);
1210 if (!dev->data->min_rx_buf_size ||
1211 dev->data->min_rx_buf_size > mbp_buf_size)
1212 dev->data->min_rx_buf_size = mbp_buf_size;
1219 * A conversion function from txq_flags API.
1222 rte_eth_convert_txq_flags(const uint32_t txq_flags, uint64_t *tx_offloads)
1224 uint64_t offloads = 0;
1226 if (!(txq_flags & ETH_TXQ_FLAGS_NOMULTSEGS))
1227 offloads |= DEV_TX_OFFLOAD_MULTI_SEGS;
1228 if (!(txq_flags & ETH_TXQ_FLAGS_NOVLANOFFL))
1229 offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
1230 if (!(txq_flags & ETH_TXQ_FLAGS_NOXSUMSCTP))
1231 offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
1232 if (!(txq_flags & ETH_TXQ_FLAGS_NOXSUMUDP))
1233 offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
1234 if (!(txq_flags & ETH_TXQ_FLAGS_NOXSUMTCP))
1235 offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
1236 if ((txq_flags & ETH_TXQ_FLAGS_NOREFCOUNT) &&
1237 (txq_flags & ETH_TXQ_FLAGS_NOMULTMEMP))
1238 offloads |= DEV_TX_OFFLOAD_MBUF_FAST_FREE;
1240 *tx_offloads = offloads;
1244 * A conversion function from offloads API.
1247 rte_eth_convert_txq_offloads(const uint64_t tx_offloads, uint32_t *txq_flags)
1251 if (!(tx_offloads & DEV_TX_OFFLOAD_MULTI_SEGS))
1252 flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
1253 if (!(tx_offloads & DEV_TX_OFFLOAD_VLAN_INSERT))
1254 flags |= ETH_TXQ_FLAGS_NOVLANOFFL;
1255 if (!(tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM))
1256 flags |= ETH_TXQ_FLAGS_NOXSUMSCTP;
1257 if (!(tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM))
1258 flags |= ETH_TXQ_FLAGS_NOXSUMUDP;
1259 if (!(tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM))
1260 flags |= ETH_TXQ_FLAGS_NOXSUMTCP;
1261 if (tx_offloads & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
1262 flags |= (ETH_TXQ_FLAGS_NOREFCOUNT | ETH_TXQ_FLAGS_NOMULTMEMP);
1268 rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
1269 uint16_t nb_tx_desc, unsigned int socket_id,
1270 const struct rte_eth_txconf *tx_conf)
1272 struct rte_eth_dev *dev;
1273 struct rte_eth_dev_info dev_info;
1274 struct rte_eth_txconf local_conf;
1277 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1279 dev = &rte_eth_devices[port_id];
1280 if (tx_queue_id >= dev->data->nb_tx_queues) {
1281 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1285 if (dev->data->dev_started) {
1286 RTE_PMD_DEBUG_TRACE(
1287 "port %d must be stopped to allow configuration\n", port_id);
1291 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1292 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1294 rte_eth_dev_info_get(port_id, &dev_info);
1296 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1297 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1298 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1299 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1300 "should be: <= %hu, = %hu, and a product of %hu\n",
1302 dev_info.tx_desc_lim.nb_max,
1303 dev_info.tx_desc_lim.nb_min,
1304 dev_info.tx_desc_lim.nb_align);
1308 txq = dev->data->tx_queues;
1309 if (txq[tx_queue_id]) {
1310 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release,
1312 (*dev->dev_ops->tx_queue_release)(txq[tx_queue_id]);
1313 txq[tx_queue_id] = NULL;
1316 if (tx_conf == NULL)
1317 tx_conf = &dev_info.default_txconf;
1320 * Convert between the offloads API to enable PMDs to support
1323 local_conf = *tx_conf;
1324 if (tx_conf->txq_flags & ETH_TXQ_FLAGS_IGNORE) {
1325 rte_eth_convert_txq_offloads(tx_conf->offloads,
1326 &local_conf.txq_flags);
1327 /* Keep the ignore flag. */
1328 local_conf.txq_flags |= ETH_TXQ_FLAGS_IGNORE;
1330 rte_eth_convert_txq_flags(tx_conf->txq_flags,
1331 &local_conf.offloads);
1334 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1335 socket_id, &local_conf);
1339 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
1340 void *userdata __rte_unused)
1344 for (i = 0; i < unsent; i++)
1345 rte_pktmbuf_free(pkts[i]);
1349 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
1352 uint64_t *count = userdata;
1355 for (i = 0; i < unsent; i++)
1356 rte_pktmbuf_free(pkts[i]);
1362 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
1363 buffer_tx_error_fn cbfn, void *userdata)
1365 buffer->error_callback = cbfn;
1366 buffer->error_userdata = userdata;
1371 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
1378 buffer->size = size;
1379 if (buffer->error_callback == NULL) {
1380 ret = rte_eth_tx_buffer_set_err_callback(
1381 buffer, rte_eth_tx_buffer_drop_callback, NULL);
1388 rte_eth_tx_done_cleanup(uint16_t port_id, uint16_t queue_id, uint32_t free_cnt)
1390 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1392 /* Validate Input Data. Bail if not valid or not supported. */
1393 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1394 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_done_cleanup, -ENOTSUP);
1396 /* Call driver to free pending mbufs. */
1397 return (*dev->dev_ops->tx_done_cleanup)(dev->data->tx_queues[queue_id],
1402 rte_eth_promiscuous_enable(uint16_t port_id)
1404 struct rte_eth_dev *dev;
1406 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1407 dev = &rte_eth_devices[port_id];
1409 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1410 (*dev->dev_ops->promiscuous_enable)(dev);
1411 dev->data->promiscuous = 1;
1415 rte_eth_promiscuous_disable(uint16_t port_id)
1417 struct rte_eth_dev *dev;
1419 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1420 dev = &rte_eth_devices[port_id];
1422 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1423 dev->data->promiscuous = 0;
1424 (*dev->dev_ops->promiscuous_disable)(dev);
1428 rte_eth_promiscuous_get(uint16_t port_id)
1430 struct rte_eth_dev *dev;
1432 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1434 dev = &rte_eth_devices[port_id];
1435 return dev->data->promiscuous;
1439 rte_eth_allmulticast_enable(uint16_t port_id)
1441 struct rte_eth_dev *dev;
1443 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1444 dev = &rte_eth_devices[port_id];
1446 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1447 (*dev->dev_ops->allmulticast_enable)(dev);
1448 dev->data->all_multicast = 1;
1452 rte_eth_allmulticast_disable(uint16_t port_id)
1454 struct rte_eth_dev *dev;
1456 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1457 dev = &rte_eth_devices[port_id];
1459 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1460 dev->data->all_multicast = 0;
1461 (*dev->dev_ops->allmulticast_disable)(dev);
1465 rte_eth_allmulticast_get(uint16_t port_id)
1467 struct rte_eth_dev *dev;
1469 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1471 dev = &rte_eth_devices[port_id];
1472 return dev->data->all_multicast;
1476 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1477 struct rte_eth_link *link)
1479 struct rte_eth_link *dst = link;
1480 struct rte_eth_link *src = &(dev->data->dev_link);
1482 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1483 *(uint64_t *)src) == 0)
1490 rte_eth_link_get(uint16_t port_id, struct rte_eth_link *eth_link)
1492 struct rte_eth_dev *dev;
1494 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1495 dev = &rte_eth_devices[port_id];
1497 if (dev->data->dev_conf.intr_conf.lsc != 0)
1498 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1500 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1501 (*dev->dev_ops->link_update)(dev, 1);
1502 *eth_link = dev->data->dev_link;
1507 rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link)
1509 struct rte_eth_dev *dev;
1511 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1512 dev = &rte_eth_devices[port_id];
1514 if (dev->data->dev_conf.intr_conf.lsc != 0)
1515 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1517 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1518 (*dev->dev_ops->link_update)(dev, 0);
1519 *eth_link = dev->data->dev_link;
1524 rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats)
1526 struct rte_eth_dev *dev;
1528 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1530 dev = &rte_eth_devices[port_id];
1531 memset(stats, 0, sizeof(*stats));
1533 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1534 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1535 return (*dev->dev_ops->stats_get)(dev, stats);
1539 rte_eth_stats_reset(uint16_t port_id)
1541 struct rte_eth_dev *dev;
1543 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1544 dev = &rte_eth_devices[port_id];
1546 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_reset, -ENOTSUP);
1547 (*dev->dev_ops->stats_reset)(dev);
1548 dev->data->rx_mbuf_alloc_failed = 0;
1554 get_xstats_count(uint16_t port_id)
1556 struct rte_eth_dev *dev;
1559 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1560 dev = &rte_eth_devices[port_id];
1561 if (dev->dev_ops->xstats_get_names_by_id != NULL) {
1562 count = (*dev->dev_ops->xstats_get_names_by_id)(dev, NULL,
1567 if (dev->dev_ops->xstats_get_names != NULL) {
1568 count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0);
1574 count += RTE_NB_STATS;
1575 count += RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
1577 count += RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
1583 rte_eth_xstats_get_id_by_name(uint16_t port_id, const char *xstat_name,
1586 int cnt_xstats, idx_xstat;
1588 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1591 RTE_PMD_DEBUG_TRACE("Error: id pointer is NULL\n");
1596 RTE_PMD_DEBUG_TRACE("Error: xstat_name pointer is NULL\n");
1601 cnt_xstats = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
1602 if (cnt_xstats < 0) {
1603 RTE_PMD_DEBUG_TRACE("Error: Cannot get count of xstats\n");
1607 /* Get id-name lookup table */
1608 struct rte_eth_xstat_name xstats_names[cnt_xstats];
1610 if (cnt_xstats != rte_eth_xstats_get_names_by_id(
1611 port_id, xstats_names, cnt_xstats, NULL)) {
1612 RTE_PMD_DEBUG_TRACE("Error: Cannot get xstats lookup\n");
1616 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
1617 if (!strcmp(xstats_names[idx_xstat].name, xstat_name)) {
1626 /* retrieve ethdev extended statistics names */
1628 rte_eth_xstats_get_names_by_id(uint16_t port_id,
1629 struct rte_eth_xstat_name *xstats_names, unsigned int size,
1632 struct rte_eth_xstat_name *xstats_names_copy;
1633 unsigned int expected_entries;
1634 struct rte_eth_dev *dev;
1637 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1638 expected_entries = get_xstats_count(port_id);
1639 dev = &rte_eth_devices[port_id];
1641 /* Return max number of stats if no ids given */
1644 return expected_entries;
1645 else if (xstats_names && size < expected_entries)
1646 return expected_entries;
1649 if (ids && !xstats_names)
1652 if (dev->dev_ops->xstats_get_names_by_id != NULL)
1653 return (*dev->dev_ops->xstats_get_names_by_id)(
1654 dev, xstats_names, ids, size);
1656 /* Retrieve all stats */
1658 int num_stats = rte_eth_xstats_get_names(port_id, xstats_names,
1660 if (num_stats < 0 || num_stats > (int)expected_entries)
1663 return expected_entries;
1666 xstats_names_copy = calloc(expected_entries,
1667 sizeof(struct rte_eth_xstat_name));
1669 if (!xstats_names_copy) {
1670 RTE_PMD_DEBUG_TRACE("ERROR: can't allocate memory");
1674 /* Fill xstats_names_copy structure */
1675 rte_eth_xstats_get_names(port_id, xstats_names_copy, expected_entries);
1678 for (i = 0; i < size; i++) {
1679 if (ids[i] >= expected_entries) {
1680 RTE_PMD_DEBUG_TRACE("ERROR: id value isn't valid\n");
1681 free(xstats_names_copy);
1684 xstats_names[i] = xstats_names_copy[ids[i]];
1687 free(xstats_names_copy);
1692 rte_eth_xstats_get_names(uint16_t port_id,
1693 struct rte_eth_xstat_name *xstats_names,
1696 struct rte_eth_dev *dev;
1697 int cnt_used_entries;
1698 int cnt_expected_entries;
1699 int cnt_driver_entries;
1700 uint32_t idx, id_queue;
1703 cnt_expected_entries = get_xstats_count(port_id);
1704 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1705 (int)size < cnt_expected_entries)
1706 return cnt_expected_entries;
1708 /* port_id checked in get_xstats_count() */
1709 dev = &rte_eth_devices[port_id];
1710 cnt_used_entries = 0;
1712 for (idx = 0; idx < RTE_NB_STATS; idx++) {
1713 snprintf(xstats_names[cnt_used_entries].name,
1714 sizeof(xstats_names[0].name),
1715 "%s", rte_stats_strings[idx].name);
1718 num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1719 for (id_queue = 0; id_queue < num_q; id_queue++) {
1720 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1721 snprintf(xstats_names[cnt_used_entries].name,
1722 sizeof(xstats_names[0].name),
1724 id_queue, rte_rxq_stats_strings[idx].name);
1729 num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1730 for (id_queue = 0; id_queue < num_q; id_queue++) {
1731 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
1732 snprintf(xstats_names[cnt_used_entries].name,
1733 sizeof(xstats_names[0].name),
1735 id_queue, rte_txq_stats_strings[idx].name);
1740 if (dev->dev_ops->xstats_get_names != NULL) {
1741 /* If there are any driver-specific xstats, append them
1744 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
1746 xstats_names + cnt_used_entries,
1747 size - cnt_used_entries);
1748 if (cnt_driver_entries < 0)
1749 return cnt_driver_entries;
1750 cnt_used_entries += cnt_driver_entries;
1753 return cnt_used_entries;
1756 /* retrieve ethdev extended statistics */
1758 rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
1759 uint64_t *values, unsigned int size)
1761 unsigned int num_xstats_filled;
1762 uint16_t expected_entries;
1763 struct rte_eth_dev *dev;
1766 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1767 expected_entries = get_xstats_count(port_id);
1768 struct rte_eth_xstat xstats[expected_entries];
1769 dev = &rte_eth_devices[port_id];
1771 /* Return max number of stats if no ids given */
1774 return expected_entries;
1775 else if (values && size < expected_entries)
1776 return expected_entries;
1782 if (dev->dev_ops->xstats_get_by_id != NULL)
1783 return (*dev->dev_ops->xstats_get_by_id)(dev, ids, values,
1786 /* Fill the xstats structure */
1787 num_xstats_filled = rte_eth_xstats_get(port_id, xstats,
1790 /* Return all stats */
1792 for (i = 0; i < num_xstats_filled; i++)
1793 values[i] = xstats[i].value;
1794 return expected_entries;
1798 for (i = 0; i < size; i++) {
1799 if (ids[i] >= expected_entries) {
1800 RTE_PMD_DEBUG_TRACE("ERROR: id value isn't valid\n");
1803 values[i] = xstats[ids[i]].value;
1809 rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats,
1812 struct rte_eth_stats eth_stats;
1813 struct rte_eth_dev *dev;
1814 unsigned int count = 0, i, q;
1815 signed int xcount = 0;
1816 uint64_t val, *stats_ptr;
1817 uint16_t nb_rxqs, nb_txqs;
1819 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1821 dev = &rte_eth_devices[port_id];
1823 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1824 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1826 /* Return generic statistics */
1827 count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
1828 (nb_txqs * RTE_NB_TXQ_STATS);
1830 /* implemented by the driver */
1831 if (dev->dev_ops->xstats_get != NULL) {
1832 /* Retrieve the xstats from the driver at the end of the
1835 xcount = (*dev->dev_ops->xstats_get)(dev,
1836 xstats ? xstats + count : NULL,
1837 (n > count) ? n - count : 0);
1843 if (n < count + xcount || xstats == NULL)
1844 return count + xcount;
1846 /* now fill the xstats structure */
1848 rte_eth_stats_get(port_id, ð_stats);
1851 for (i = 0; i < RTE_NB_STATS; i++) {
1852 stats_ptr = RTE_PTR_ADD(ð_stats,
1853 rte_stats_strings[i].offset);
1855 xstats[count++].value = val;
1859 for (q = 0; q < nb_rxqs; q++) {
1860 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1861 stats_ptr = RTE_PTR_ADD(ð_stats,
1862 rte_rxq_stats_strings[i].offset +
1863 q * sizeof(uint64_t));
1865 xstats[count++].value = val;
1870 for (q = 0; q < nb_txqs; q++) {
1871 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1872 stats_ptr = RTE_PTR_ADD(ð_stats,
1873 rte_txq_stats_strings[i].offset +
1874 q * sizeof(uint64_t));
1876 xstats[count++].value = val;
1880 for (i = 0; i < count; i++)
1882 /* add an offset to driver-specific stats */
1883 for ( ; i < count + xcount; i++)
1884 xstats[i].id += count;
1886 return count + xcount;
1889 /* reset ethdev extended statistics */
1891 rte_eth_xstats_reset(uint16_t port_id)
1893 struct rte_eth_dev *dev;
1895 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1896 dev = &rte_eth_devices[port_id];
1898 /* implemented by the driver */
1899 if (dev->dev_ops->xstats_reset != NULL) {
1900 (*dev->dev_ops->xstats_reset)(dev);
1904 /* fallback to default */
1905 rte_eth_stats_reset(port_id);
1909 set_queue_stats_mapping(uint16_t port_id, uint16_t queue_id, uint8_t stat_idx,
1912 struct rte_eth_dev *dev;
1914 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1916 dev = &rte_eth_devices[port_id];
1918 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1919 return (*dev->dev_ops->queue_stats_mapping_set)
1920 (dev, queue_id, stat_idx, is_rx);
1925 rte_eth_dev_set_tx_queue_stats_mapping(uint16_t port_id, uint16_t tx_queue_id,
1928 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1934 rte_eth_dev_set_rx_queue_stats_mapping(uint16_t port_id, uint16_t rx_queue_id,
1937 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1942 rte_eth_dev_fw_version_get(uint16_t port_id, char *fw_version, size_t fw_size)
1944 struct rte_eth_dev *dev;
1946 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1947 dev = &rte_eth_devices[port_id];
1949 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP);
1950 return (*dev->dev_ops->fw_version_get)(dev, fw_version, fw_size);
1954 rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)
1956 struct rte_eth_dev *dev;
1957 const struct rte_eth_desc_lim lim = {
1958 .nb_max = UINT16_MAX,
1963 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1964 dev = &rte_eth_devices[port_id];
1966 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1967 dev_info->rx_desc_lim = lim;
1968 dev_info->tx_desc_lim = lim;
1970 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1971 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1972 dev_info->driver_name = dev->device->driver->name;
1973 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
1974 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
1978 rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
1979 uint32_t *ptypes, int num)
1982 struct rte_eth_dev *dev;
1983 const uint32_t *all_ptypes;
1985 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1986 dev = &rte_eth_devices[port_id];
1987 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
1988 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
1993 for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
1994 if (all_ptypes[i] & ptype_mask) {
1996 ptypes[j] = all_ptypes[i];
2004 rte_eth_macaddr_get(uint16_t port_id, struct ether_addr *mac_addr)
2006 struct rte_eth_dev *dev;
2008 RTE_ETH_VALID_PORTID_OR_RET(port_id);
2009 dev = &rte_eth_devices[port_id];
2010 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
2015 rte_eth_dev_get_mtu(uint16_t port_id, uint16_t *mtu)
2017 struct rte_eth_dev *dev;
2019 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2021 dev = &rte_eth_devices[port_id];
2022 *mtu = dev->data->mtu;
2027 rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
2030 struct rte_eth_dev *dev;
2032 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2033 dev = &rte_eth_devices[port_id];
2034 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
2036 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
2038 dev->data->mtu = mtu;
2044 rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on)
2046 struct rte_eth_dev *dev;
2049 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2050 dev = &rte_eth_devices[port_id];
2051 if (!(dev->data->dev_conf.rxmode.offloads &
2052 DEV_RX_OFFLOAD_VLAN_FILTER)) {
2053 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
2057 if (vlan_id > 4095) {
2058 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
2059 port_id, (unsigned) vlan_id);
2062 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
2064 ret = (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
2066 struct rte_vlan_filter_conf *vfc;
2070 vfc = &dev->data->vlan_filter_conf;
2071 vidx = vlan_id / 64;
2072 vbit = vlan_id % 64;
2075 vfc->ids[vidx] |= UINT64_C(1) << vbit;
2077 vfc->ids[vidx] &= ~(UINT64_C(1) << vbit);
2084 rte_eth_dev_set_vlan_strip_on_queue(uint16_t port_id, uint16_t rx_queue_id,
2087 struct rte_eth_dev *dev;
2089 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2090 dev = &rte_eth_devices[port_id];
2091 if (rx_queue_id >= dev->data->nb_rx_queues) {
2092 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
2096 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
2097 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
2103 rte_eth_dev_set_vlan_ether_type(uint16_t port_id,
2104 enum rte_vlan_type vlan_type,
2107 struct rte_eth_dev *dev;
2109 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2110 dev = &rte_eth_devices[port_id];
2111 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
2113 return (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type, tpid);
2117 rte_eth_dev_set_vlan_offload(uint16_t port_id, int offload_mask)
2119 struct rte_eth_dev *dev;
2124 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2125 dev = &rte_eth_devices[port_id];
2127 /*check which option changed by application*/
2128 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
2129 org = !!(dev->data->dev_conf.rxmode.offloads &
2130 DEV_RX_OFFLOAD_VLAN_STRIP);
2133 dev->data->dev_conf.rxmode.offloads |=
2134 DEV_RX_OFFLOAD_VLAN_STRIP;
2136 dev->data->dev_conf.rxmode.offloads &=
2137 ~DEV_RX_OFFLOAD_VLAN_STRIP;
2138 mask |= ETH_VLAN_STRIP_MASK;
2141 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
2142 org = !!(dev->data->dev_conf.rxmode.offloads &
2143 DEV_RX_OFFLOAD_VLAN_FILTER);
2146 dev->data->dev_conf.rxmode.offloads |=
2147 DEV_RX_OFFLOAD_VLAN_FILTER;
2149 dev->data->dev_conf.rxmode.offloads &=
2150 ~DEV_RX_OFFLOAD_VLAN_FILTER;
2151 mask |= ETH_VLAN_FILTER_MASK;
2154 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
2155 org = !!(dev->data->dev_conf.rxmode.offloads &
2156 DEV_RX_OFFLOAD_VLAN_EXTEND);
2159 dev->data->dev_conf.rxmode.offloads |=
2160 DEV_RX_OFFLOAD_VLAN_EXTEND;
2162 dev->data->dev_conf.rxmode.offloads &=
2163 ~DEV_RX_OFFLOAD_VLAN_EXTEND;
2164 mask |= ETH_VLAN_EXTEND_MASK;
2171 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
2174 * Convert to the offload bitfield API just in case the underlying PMD
2175 * still supporting it.
2177 rte_eth_convert_rx_offloads(dev->data->dev_conf.rxmode.offloads,
2178 &dev->data->dev_conf.rxmode);
2179 (*dev->dev_ops->vlan_offload_set)(dev, mask);
2185 rte_eth_dev_get_vlan_offload(uint16_t port_id)
2187 struct rte_eth_dev *dev;
2190 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2191 dev = &rte_eth_devices[port_id];
2193 if (dev->data->dev_conf.rxmode.offloads &
2194 DEV_RX_OFFLOAD_VLAN_STRIP)
2195 ret |= ETH_VLAN_STRIP_OFFLOAD;
2197 if (dev->data->dev_conf.rxmode.offloads &
2198 DEV_RX_OFFLOAD_VLAN_FILTER)
2199 ret |= ETH_VLAN_FILTER_OFFLOAD;
2201 if (dev->data->dev_conf.rxmode.offloads &
2202 DEV_RX_OFFLOAD_VLAN_EXTEND)
2203 ret |= ETH_VLAN_EXTEND_OFFLOAD;
2209 rte_eth_dev_set_vlan_pvid(uint16_t port_id, uint16_t pvid, int on)
2211 struct rte_eth_dev *dev;
2213 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2214 dev = &rte_eth_devices[port_id];
2215 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
2216 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
2222 rte_eth_dev_flow_ctrl_get(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
2224 struct rte_eth_dev *dev;
2226 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2227 dev = &rte_eth_devices[port_id];
2228 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2229 memset(fc_conf, 0, sizeof(*fc_conf));
2230 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
2234 rte_eth_dev_flow_ctrl_set(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
2236 struct rte_eth_dev *dev;
2238 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2239 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2240 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2244 dev = &rte_eth_devices[port_id];
2245 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2246 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
2250 rte_eth_dev_priority_flow_ctrl_set(uint16_t port_id,
2251 struct rte_eth_pfc_conf *pfc_conf)
2253 struct rte_eth_dev *dev;
2255 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2256 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2257 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2261 dev = &rte_eth_devices[port_id];
2262 /* High water, low water validation are device specific */
2263 if (*dev->dev_ops->priority_flow_ctrl_set)
2264 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
2269 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2277 num = (reta_size + RTE_RETA_GROUP_SIZE - 1) / RTE_RETA_GROUP_SIZE;
2278 for (i = 0; i < num; i++) {
2279 if (reta_conf[i].mask)
2287 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2291 uint16_t i, idx, shift;
2297 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
2301 for (i = 0; i < reta_size; i++) {
2302 idx = i / RTE_RETA_GROUP_SIZE;
2303 shift = i % RTE_RETA_GROUP_SIZE;
2304 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2305 (reta_conf[idx].reta[shift] >= max_rxq)) {
2306 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2307 "the maximum rxq index: %u\n", idx, shift,
2308 reta_conf[idx].reta[shift], max_rxq);
2317 rte_eth_dev_rss_reta_update(uint16_t port_id,
2318 struct rte_eth_rss_reta_entry64 *reta_conf,
2321 struct rte_eth_dev *dev;
2324 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2325 /* Check mask bits */
2326 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2330 dev = &rte_eth_devices[port_id];
2332 /* Check entry value */
2333 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2334 dev->data->nb_rx_queues);
2338 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2339 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2343 rte_eth_dev_rss_reta_query(uint16_t port_id,
2344 struct rte_eth_rss_reta_entry64 *reta_conf,
2347 struct rte_eth_dev *dev;
2350 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2352 /* Check mask bits */
2353 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2357 dev = &rte_eth_devices[port_id];
2358 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2359 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2363 rte_eth_dev_rss_hash_update(uint16_t port_id,
2364 struct rte_eth_rss_conf *rss_conf)
2366 struct rte_eth_dev *dev;
2368 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2369 dev = &rte_eth_devices[port_id];
2370 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2371 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2375 rte_eth_dev_rss_hash_conf_get(uint16_t port_id,
2376 struct rte_eth_rss_conf *rss_conf)
2378 struct rte_eth_dev *dev;
2380 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2381 dev = &rte_eth_devices[port_id];
2382 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2383 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2387 rte_eth_dev_udp_tunnel_port_add(uint16_t port_id,
2388 struct rte_eth_udp_tunnel *udp_tunnel)
2390 struct rte_eth_dev *dev;
2392 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2393 if (udp_tunnel == NULL) {
2394 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2398 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2399 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2403 dev = &rte_eth_devices[port_id];
2404 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
2405 return (*dev->dev_ops->udp_tunnel_port_add)(dev, udp_tunnel);
2409 rte_eth_dev_udp_tunnel_port_delete(uint16_t port_id,
2410 struct rte_eth_udp_tunnel *udp_tunnel)
2412 struct rte_eth_dev *dev;
2414 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2415 dev = &rte_eth_devices[port_id];
2417 if (udp_tunnel == NULL) {
2418 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2422 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2423 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2427 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
2428 return (*dev->dev_ops->udp_tunnel_port_del)(dev, udp_tunnel);
2432 rte_eth_led_on(uint16_t port_id)
2434 struct rte_eth_dev *dev;
2436 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2437 dev = &rte_eth_devices[port_id];
2438 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2439 return (*dev->dev_ops->dev_led_on)(dev);
2443 rte_eth_led_off(uint16_t port_id)
2445 struct rte_eth_dev *dev;
2447 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2448 dev = &rte_eth_devices[port_id];
2449 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2450 return (*dev->dev_ops->dev_led_off)(dev);
2454 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2458 get_mac_addr_index(uint16_t port_id, const struct ether_addr *addr)
2460 struct rte_eth_dev_info dev_info;
2461 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2464 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2465 rte_eth_dev_info_get(port_id, &dev_info);
2467 for (i = 0; i < dev_info.max_mac_addrs; i++)
2468 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2474 static const struct ether_addr null_mac_addr;
2477 rte_eth_dev_mac_addr_add(uint16_t port_id, struct ether_addr *addr,
2480 struct rte_eth_dev *dev;
2485 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2486 dev = &rte_eth_devices[port_id];
2487 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2489 if (is_zero_ether_addr(addr)) {
2490 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2494 if (pool >= ETH_64_POOLS) {
2495 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2499 index = get_mac_addr_index(port_id, addr);
2501 index = get_mac_addr_index(port_id, &null_mac_addr);
2503 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2508 pool_mask = dev->data->mac_pool_sel[index];
2510 /* Check if both MAC address and pool is already there, and do nothing */
2511 if (pool_mask & (1ULL << pool))
2516 ret = (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2519 /* Update address in NIC data structure */
2520 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2522 /* Update pool bitmap in NIC data structure */
2523 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2530 rte_eth_dev_mac_addr_remove(uint16_t port_id, struct ether_addr *addr)
2532 struct rte_eth_dev *dev;
2535 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2536 dev = &rte_eth_devices[port_id];
2537 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2539 index = get_mac_addr_index(port_id, addr);
2541 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2543 } else if (index < 0)
2544 return 0; /* Do nothing if address wasn't found */
2547 (*dev->dev_ops->mac_addr_remove)(dev, index);
2549 /* Update address in NIC data structure */
2550 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2552 /* reset pool bitmap */
2553 dev->data->mac_pool_sel[index] = 0;
2559 rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct ether_addr *addr)
2561 struct rte_eth_dev *dev;
2563 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2565 if (!is_valid_assigned_ether_addr(addr))
2568 dev = &rte_eth_devices[port_id];
2569 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2571 /* Update default address in NIC data structure */
2572 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2574 (*dev->dev_ops->mac_addr_set)(dev, addr);
2581 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2585 get_hash_mac_addr_index(uint16_t port_id, const struct ether_addr *addr)
2587 struct rte_eth_dev_info dev_info;
2588 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2591 rte_eth_dev_info_get(port_id, &dev_info);
2592 if (!dev->data->hash_mac_addrs)
2595 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2596 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2597 ETHER_ADDR_LEN) == 0)
2604 rte_eth_dev_uc_hash_table_set(uint16_t port_id, struct ether_addr *addr,
2609 struct rte_eth_dev *dev;
2611 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2613 dev = &rte_eth_devices[port_id];
2614 if (is_zero_ether_addr(addr)) {
2615 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2620 index = get_hash_mac_addr_index(port_id, addr);
2621 /* Check if it's already there, and do nothing */
2622 if ((index >= 0) && (on))
2627 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2628 "set in UTA\n", port_id);
2632 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2634 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2640 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2641 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2643 /* Update address in NIC data structure */
2645 ether_addr_copy(addr,
2646 &dev->data->hash_mac_addrs[index]);
2648 ether_addr_copy(&null_mac_addr,
2649 &dev->data->hash_mac_addrs[index]);
2656 rte_eth_dev_uc_all_hash_table_set(uint16_t port_id, uint8_t on)
2658 struct rte_eth_dev *dev;
2660 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2662 dev = &rte_eth_devices[port_id];
2664 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2665 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2668 int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx,
2671 struct rte_eth_dev *dev;
2672 struct rte_eth_dev_info dev_info;
2673 struct rte_eth_link link;
2675 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2677 dev = &rte_eth_devices[port_id];
2678 rte_eth_dev_info_get(port_id, &dev_info);
2679 link = dev->data->dev_link;
2681 if (queue_idx > dev_info.max_tx_queues) {
2682 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2683 "invalid queue id=%d\n", port_id, queue_idx);
2687 if (tx_rate > link.link_speed) {
2688 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2689 "bigger than link speed= %d\n",
2690 tx_rate, link.link_speed);
2694 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2695 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2699 rte_eth_mirror_rule_set(uint16_t port_id,
2700 struct rte_eth_mirror_conf *mirror_conf,
2701 uint8_t rule_id, uint8_t on)
2703 struct rte_eth_dev *dev;
2705 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2706 if (mirror_conf->rule_type == 0) {
2707 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2711 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2712 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2717 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2718 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2719 (mirror_conf->pool_mask == 0)) {
2720 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2724 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2725 mirror_conf->vlan.vlan_mask == 0) {
2726 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2730 dev = &rte_eth_devices[port_id];
2731 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2733 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2737 rte_eth_mirror_rule_reset(uint16_t port_id, uint8_t rule_id)
2739 struct rte_eth_dev *dev;
2741 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2743 dev = &rte_eth_devices[port_id];
2744 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2746 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2750 rte_eth_dev_callback_register(uint16_t port_id,
2751 enum rte_eth_event_type event,
2752 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2754 struct rte_eth_dev *dev;
2755 struct rte_eth_dev_callback *user_cb;
2760 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2762 dev = &rte_eth_devices[port_id];
2763 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2765 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2766 if (user_cb->cb_fn == cb_fn &&
2767 user_cb->cb_arg == cb_arg &&
2768 user_cb->event == event) {
2773 /* create a new callback. */
2774 if (user_cb == NULL) {
2775 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2776 sizeof(struct rte_eth_dev_callback), 0);
2777 if (user_cb != NULL) {
2778 user_cb->cb_fn = cb_fn;
2779 user_cb->cb_arg = cb_arg;
2780 user_cb->event = event;
2781 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2785 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2786 return (user_cb == NULL) ? -ENOMEM : 0;
2790 rte_eth_dev_callback_unregister(uint16_t port_id,
2791 enum rte_eth_event_type event,
2792 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2795 struct rte_eth_dev *dev;
2796 struct rte_eth_dev_callback *cb, *next;
2801 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2803 dev = &rte_eth_devices[port_id];
2804 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2807 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2809 next = TAILQ_NEXT(cb, next);
2811 if (cb->cb_fn != cb_fn || cb->event != event ||
2812 (cb->cb_arg != (void *)-1 &&
2813 cb->cb_arg != cb_arg))
2817 * if this callback is not executing right now,
2820 if (cb->active == 0) {
2821 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2828 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2833 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2834 enum rte_eth_event_type event, void *cb_arg, void *ret_param)
2836 struct rte_eth_dev_callback *cb_lst;
2837 struct rte_eth_dev_callback dev_cb;
2840 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2841 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2842 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2847 dev_cb.cb_arg = cb_arg;
2848 if (ret_param != NULL)
2849 dev_cb.ret_param = ret_param;
2851 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2852 rc = dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2853 dev_cb.cb_arg, dev_cb.ret_param);
2854 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2857 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2862 rte_eth_dev_rx_intr_ctl(uint16_t port_id, int epfd, int op, void *data)
2865 struct rte_eth_dev *dev;
2866 struct rte_intr_handle *intr_handle;
2870 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2872 dev = &rte_eth_devices[port_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 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2886 vec = intr_handle->intr_vec[qid];
2887 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2888 if (rc && rc != -EEXIST) {
2889 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2890 " op %d epfd %d vec %u\n",
2891 port_id, qid, op, epfd, vec);
2898 const struct rte_memzone *
2899 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2900 uint16_t queue_id, size_t size, unsigned align,
2903 char z_name[RTE_MEMZONE_NAMESIZE];
2904 const struct rte_memzone *mz;
2906 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2907 dev->device->driver->name, ring_name,
2908 dev->data->port_id, queue_id);
2910 mz = rte_memzone_lookup(z_name);
2914 return rte_memzone_reserve_aligned(z_name, size, socket_id, 0, align);
2918 rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id,
2919 int epfd, int op, void *data)
2922 struct rte_eth_dev *dev;
2923 struct rte_intr_handle *intr_handle;
2926 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2928 dev = &rte_eth_devices[port_id];
2929 if (queue_id >= dev->data->nb_rx_queues) {
2930 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
2934 if (!dev->intr_handle) {
2935 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
2939 intr_handle = dev->intr_handle;
2940 if (!intr_handle->intr_vec) {
2941 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2945 vec = intr_handle->intr_vec[queue_id];
2946 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2947 if (rc && rc != -EEXIST) {
2948 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2949 " op %d epfd %d vec %u\n",
2950 port_id, queue_id, op, epfd, vec);
2958 rte_eth_dev_rx_intr_enable(uint16_t port_id,
2961 struct rte_eth_dev *dev;
2963 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2965 dev = &rte_eth_devices[port_id];
2967 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
2968 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
2972 rte_eth_dev_rx_intr_disable(uint16_t port_id,
2975 struct rte_eth_dev *dev;
2977 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2979 dev = &rte_eth_devices[port_id];
2981 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
2982 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
2987 rte_eth_dev_filter_supported(uint16_t port_id,
2988 enum rte_filter_type filter_type)
2990 struct rte_eth_dev *dev;
2992 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2994 dev = &rte_eth_devices[port_id];
2995 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2996 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
2997 RTE_ETH_FILTER_NOP, NULL);
3001 rte_eth_dev_filter_ctrl(uint16_t port_id, enum rte_filter_type filter_type,
3002 enum rte_filter_op filter_op, void *arg)
3004 struct rte_eth_dev *dev;
3006 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3008 dev = &rte_eth_devices[port_id];
3009 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3010 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
3014 rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
3015 rte_rx_callback_fn fn, void *user_param)
3017 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3018 rte_errno = ENOTSUP;
3021 /* check input parameters */
3022 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3023 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3027 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3035 cb->param = user_param;
3037 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3038 /* Add the callbacks in fifo order. */
3039 struct rte_eth_rxtx_callback *tail =
3040 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3043 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3050 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3056 rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
3057 rte_rx_callback_fn fn, void *user_param)
3059 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3060 rte_errno = ENOTSUP;
3063 /* check input parameters */
3064 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3065 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3070 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3078 cb->param = user_param;
3080 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3081 /* Add the callbacks at fisrt position*/
3082 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3084 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3085 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3091 rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
3092 rte_tx_callback_fn fn, void *user_param)
3094 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3095 rte_errno = ENOTSUP;
3098 /* check input parameters */
3099 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3100 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3105 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3113 cb->param = user_param;
3115 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3116 /* Add the callbacks in fifo order. */
3117 struct rte_eth_rxtx_callback *tail =
3118 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3121 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3128 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3134 rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
3135 struct rte_eth_rxtx_callback *user_cb)
3137 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3140 /* Check input parameters. */
3141 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3142 if (user_cb == NULL ||
3143 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
3146 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3147 struct rte_eth_rxtx_callback *cb;
3148 struct rte_eth_rxtx_callback **prev_cb;
3151 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3152 prev_cb = &dev->post_rx_burst_cbs[queue_id];
3153 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3155 if (cb == user_cb) {
3156 /* Remove the user cb from the callback list. */
3157 *prev_cb = cb->next;
3162 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3168 rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
3169 struct rte_eth_rxtx_callback *user_cb)
3171 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3174 /* Check input parameters. */
3175 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3176 if (user_cb == NULL ||
3177 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
3180 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3182 struct rte_eth_rxtx_callback *cb;
3183 struct rte_eth_rxtx_callback **prev_cb;
3185 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3186 prev_cb = &dev->pre_tx_burst_cbs[queue_id];
3187 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3189 if (cb == user_cb) {
3190 /* Remove the user cb from the callback list. */
3191 *prev_cb = cb->next;
3196 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3202 rte_eth_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
3203 struct rte_eth_rxq_info *qinfo)
3205 struct rte_eth_dev *dev;
3207 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3212 dev = &rte_eth_devices[port_id];
3213 if (queue_id >= dev->data->nb_rx_queues) {
3214 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3218 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3220 memset(qinfo, 0, sizeof(*qinfo));
3221 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3226 rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,
3227 struct rte_eth_txq_info *qinfo)
3229 struct rte_eth_dev *dev;
3231 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3236 dev = &rte_eth_devices[port_id];
3237 if (queue_id >= dev->data->nb_tx_queues) {
3238 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3242 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3244 memset(qinfo, 0, sizeof(*qinfo));
3245 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3250 rte_eth_dev_set_mc_addr_list(uint16_t port_id,
3251 struct ether_addr *mc_addr_set,
3252 uint32_t nb_mc_addr)
3254 struct rte_eth_dev *dev;
3256 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3258 dev = &rte_eth_devices[port_id];
3259 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3260 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3264 rte_eth_timesync_enable(uint16_t port_id)
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_enable, -ENOTSUP);
3272 return (*dev->dev_ops->timesync_enable)(dev);
3276 rte_eth_timesync_disable(uint16_t port_id)
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_disable, -ENOTSUP);
3284 return (*dev->dev_ops->timesync_disable)(dev);
3288 rte_eth_timesync_read_rx_timestamp(uint16_t port_id, struct timespec *timestamp,
3291 struct rte_eth_dev *dev;
3293 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3294 dev = &rte_eth_devices[port_id];
3296 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3297 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3301 rte_eth_timesync_read_tx_timestamp(uint16_t port_id,
3302 struct timespec *timestamp)
3304 struct rte_eth_dev *dev;
3306 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3307 dev = &rte_eth_devices[port_id];
3309 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3310 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3314 rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta)
3316 struct rte_eth_dev *dev;
3318 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3319 dev = &rte_eth_devices[port_id];
3321 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3322 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3326 rte_eth_timesync_read_time(uint16_t port_id, struct timespec *timestamp)
3328 struct rte_eth_dev *dev;
3330 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3331 dev = &rte_eth_devices[port_id];
3333 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3334 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3338 rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *timestamp)
3340 struct rte_eth_dev *dev;
3342 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3343 dev = &rte_eth_devices[port_id];
3345 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3346 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3350 rte_eth_dev_get_reg_info(uint16_t port_id, struct rte_dev_reg_info *info)
3352 struct rte_eth_dev *dev;
3354 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3356 dev = &rte_eth_devices[port_id];
3357 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3358 return (*dev->dev_ops->get_reg)(dev, info);
3362 rte_eth_dev_get_eeprom_length(uint16_t port_id)
3364 struct rte_eth_dev *dev;
3366 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3368 dev = &rte_eth_devices[port_id];
3369 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3370 return (*dev->dev_ops->get_eeprom_length)(dev);
3374 rte_eth_dev_get_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
3376 struct rte_eth_dev *dev;
3378 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3380 dev = &rte_eth_devices[port_id];
3381 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3382 return (*dev->dev_ops->get_eeprom)(dev, info);
3386 rte_eth_dev_set_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
3388 struct rte_eth_dev *dev;
3390 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3392 dev = &rte_eth_devices[port_id];
3393 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3394 return (*dev->dev_ops->set_eeprom)(dev, info);
3398 rte_eth_dev_get_dcb_info(uint16_t port_id,
3399 struct rte_eth_dcb_info *dcb_info)
3401 struct rte_eth_dev *dev;
3403 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3405 dev = &rte_eth_devices[port_id];
3406 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3408 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3409 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3413 rte_eth_dev_l2_tunnel_eth_type_conf(uint16_t port_id,
3414 struct rte_eth_l2_tunnel_conf *l2_tunnel)
3416 struct rte_eth_dev *dev;
3418 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3419 if (l2_tunnel == NULL) {
3420 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3424 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3425 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
3429 dev = &rte_eth_devices[port_id];
3430 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
3432 return (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev, l2_tunnel);
3436 rte_eth_dev_l2_tunnel_offload_set(uint16_t port_id,
3437 struct rte_eth_l2_tunnel_conf *l2_tunnel,
3441 struct rte_eth_dev *dev;
3443 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3445 if (l2_tunnel == NULL) {
3446 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3450 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3451 RTE_PMD_DEBUG_TRACE("Invalid tunnel type.\n");
3456 RTE_PMD_DEBUG_TRACE("Mask should have a value.\n");
3460 dev = &rte_eth_devices[port_id];
3461 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
3463 return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);
3467 rte_eth_dev_adjust_nb_desc(uint16_t *nb_desc,
3468 const struct rte_eth_desc_lim *desc_lim)
3470 if (desc_lim->nb_align != 0)
3471 *nb_desc = RTE_ALIGN_CEIL(*nb_desc, desc_lim->nb_align);
3473 if (desc_lim->nb_max != 0)
3474 *nb_desc = RTE_MIN(*nb_desc, desc_lim->nb_max);
3476 *nb_desc = RTE_MAX(*nb_desc, desc_lim->nb_min);
3480 rte_eth_dev_adjust_nb_rx_tx_desc(uint16_t port_id,
3481 uint16_t *nb_rx_desc,
3482 uint16_t *nb_tx_desc)
3484 struct rte_eth_dev *dev;
3485 struct rte_eth_dev_info dev_info;
3487 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3489 dev = &rte_eth_devices[port_id];
3490 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
3492 rte_eth_dev_info_get(port_id, &dev_info);
3494 if (nb_rx_desc != NULL)
3495 rte_eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim);
3497 if (nb_tx_desc != NULL)
3498 rte_eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim);
3504 rte_eth_dev_pool_ops_supported(uint16_t port_id, const char *pool)
3506 struct rte_eth_dev *dev;
3508 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3513 dev = &rte_eth_devices[port_id];
3515 if (*dev->dev_ops->pool_ops_supported == NULL)
3516 return 1; /* all pools are supported */
3518 return (*dev->dev_ops->pool_ops_supported)(dev, pool);