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>
50 #include <rte_memory.h>
51 #include <rte_memcpy.h>
52 #include <rte_memzone.h>
53 #include <rte_launch.h>
55 #include <rte_per_lcore.h>
56 #include <rte_lcore.h>
57 #include <rte_atomic.h>
58 #include <rte_branch_prediction.h>
59 #include <rte_common.h>
60 #include <rte_mempool.h>
61 #include <rte_malloc.h>
63 #include <rte_errno.h>
64 #include <rte_spinlock.h>
65 #include <rte_string_fns.h>
67 #include "rte_ether.h"
68 #include "rte_ethdev.h"
69 #include "ethdev_profile.h"
71 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
72 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
73 static struct rte_eth_dev_data *rte_eth_dev_data;
74 static uint8_t eth_dev_last_created_port;
76 /* spinlock for eth device callbacks */
77 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
79 /* spinlock for add/remove rx callbacks */
80 static rte_spinlock_t rte_eth_rx_cb_lock = RTE_SPINLOCK_INITIALIZER;
82 /* spinlock for add/remove tx callbacks */
83 static rte_spinlock_t rte_eth_tx_cb_lock = RTE_SPINLOCK_INITIALIZER;
85 /* store statistics names and its offset in stats structure */
86 struct rte_eth_xstats_name_off {
87 char name[RTE_ETH_XSTATS_NAME_SIZE];
91 static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
92 {"rx_good_packets", offsetof(struct rte_eth_stats, ipackets)},
93 {"tx_good_packets", offsetof(struct rte_eth_stats, opackets)},
94 {"rx_good_bytes", offsetof(struct rte_eth_stats, ibytes)},
95 {"tx_good_bytes", offsetof(struct rte_eth_stats, obytes)},
96 {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
97 {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
98 {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats,
102 #define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
104 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
105 {"packets", offsetof(struct rte_eth_stats, q_ipackets)},
106 {"bytes", offsetof(struct rte_eth_stats, q_ibytes)},
107 {"errors", offsetof(struct rte_eth_stats, q_errors)},
110 #define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) / \
111 sizeof(rte_rxq_stats_strings[0]))
113 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
114 {"packets", offsetof(struct rte_eth_stats, q_opackets)},
115 {"bytes", offsetof(struct rte_eth_stats, q_obytes)},
117 #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) / \
118 sizeof(rte_txq_stats_strings[0]))
122 * The user application callback description.
124 * It contains callback address to be registered by user application,
125 * the pointer to the parameters for callback, and the event type.
127 struct rte_eth_dev_callback {
128 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
129 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
130 void *cb_arg; /**< Parameter for callback */
131 void *ret_param; /**< Return parameter */
132 enum rte_eth_event_type event; /**< Interrupt event type */
133 uint32_t active; /**< Callback is executing */
142 rte_eth_find_next(uint16_t port_id)
144 while (port_id < RTE_MAX_ETHPORTS &&
145 rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED)
148 if (port_id >= RTE_MAX_ETHPORTS)
149 return RTE_MAX_ETHPORTS;
155 rte_eth_dev_data_alloc(void)
157 const unsigned flags = 0;
158 const struct rte_memzone *mz;
160 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
161 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
162 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
163 rte_socket_id(), flags);
165 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
167 rte_panic("Cannot allocate memzone for ethernet port data\n");
169 rte_eth_dev_data = mz->addr;
170 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
171 memset(rte_eth_dev_data, 0,
172 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
176 rte_eth_dev_allocated(const char *name)
180 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
181 if ((rte_eth_devices[i].state == RTE_ETH_DEV_ATTACHED) &&
182 strcmp(rte_eth_devices[i].data->name, name) == 0)
183 return &rte_eth_devices[i];
189 rte_eth_dev_find_free_port(void)
193 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
194 if (rte_eth_devices[i].state == RTE_ETH_DEV_UNUSED)
197 return RTE_MAX_ETHPORTS;
200 static struct rte_eth_dev *
201 eth_dev_get(uint16_t port_id)
203 struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
205 eth_dev->data = &rte_eth_dev_data[port_id];
206 eth_dev->state = RTE_ETH_DEV_ATTACHED;
207 TAILQ_INIT(&(eth_dev->link_intr_cbs));
209 eth_dev_last_created_port = port_id;
215 rte_eth_dev_allocate(const char *name)
218 struct rte_eth_dev *eth_dev;
220 port_id = rte_eth_dev_find_free_port();
221 if (port_id == RTE_MAX_ETHPORTS) {
222 RTE_PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
226 if (rte_eth_dev_data == NULL)
227 rte_eth_dev_data_alloc();
229 if (rte_eth_dev_allocated(name) != NULL) {
230 RTE_PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n",
235 memset(&rte_eth_dev_data[port_id], 0, sizeof(struct rte_eth_dev_data));
236 eth_dev = eth_dev_get(port_id);
237 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
238 eth_dev->data->port_id = port_id;
239 eth_dev->data->mtu = ETHER_MTU;
245 * Attach to a port already registered by the primary process, which
246 * makes sure that the same device would have the same port id both
247 * in the primary and secondary process.
250 rte_eth_dev_attach_secondary(const char *name)
253 struct rte_eth_dev *eth_dev;
255 if (rte_eth_dev_data == NULL)
256 rte_eth_dev_data_alloc();
258 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
259 if (strcmp(rte_eth_dev_data[i].name, name) == 0)
262 if (i == RTE_MAX_ETHPORTS) {
264 "device %s is not driven by the primary process\n",
269 eth_dev = eth_dev_get(i);
270 RTE_ASSERT(eth_dev->data->port_id == i);
276 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
281 eth_dev->state = RTE_ETH_DEV_UNUSED;
286 rte_eth_dev_is_valid_port(uint16_t port_id)
288 if (port_id >= RTE_MAX_ETHPORTS ||
289 (rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
290 rte_eth_devices[port_id].state != RTE_ETH_DEV_DEFERRED))
297 rte_eth_dev_socket_id(uint16_t port_id)
299 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
300 return rte_eth_devices[port_id].data->numa_node;
304 rte_eth_dev_get_sec_ctx(uint8_t port_id)
306 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, NULL);
307 return rte_eth_devices[port_id].security_ctx;
311 rte_eth_dev_count(void)
318 RTE_ETH_FOREACH_DEV(p)
325 rte_eth_dev_get_name_by_port(uint16_t port_id, char *name)
329 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
332 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
336 /* shouldn't check 'rte_eth_devices[i].data',
337 * because it might be overwritten by VDEV PMD */
338 tmp = rte_eth_dev_data[port_id].name;
344 rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
349 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
353 RTE_ETH_FOREACH_DEV(i) {
355 rte_eth_dev_data[i].name, strlen(name))) {
365 /* attach the new device, then store port_id of the device */
367 rte_eth_dev_attach(const char *devargs, uint16_t *port_id)
370 int current = rte_eth_dev_count();
374 if ((devargs == NULL) || (port_id == NULL)) {
379 /* parse devargs, then retrieve device name and args */
380 if (rte_eal_parse_devargs_str(devargs, &name, &args))
383 ret = rte_eal_dev_attach(name, args);
387 /* no point looking at the port count if no port exists */
388 if (!rte_eth_dev_count()) {
389 RTE_LOG(ERR, EAL, "No port found for device (%s)\n", name);
394 /* if nothing happened, there is a bug here, since some driver told us
395 * it did attach a device, but did not create a port.
397 if (current == rte_eth_dev_count()) {
402 *port_id = eth_dev_last_created_port;
411 /* detach the device, then store the name of the device */
413 rte_eth_dev_detach(uint16_t port_id, char *name)
418 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
425 dev_flags = rte_eth_devices[port_id].data->dev_flags;
426 if (dev_flags & RTE_ETH_DEV_BONDED_SLAVE) {
427 RTE_LOG(ERR, EAL, "Port %" PRIu16 " is bonded, cannot detach\n",
433 snprintf(name, sizeof(rte_eth_devices[port_id].data->name),
434 "%s", rte_eth_devices[port_id].data->name);
436 ret = rte_eal_dev_detach(rte_eth_devices[port_id].device);
440 rte_eth_devices[port_id].state = RTE_ETH_DEV_UNUSED;
448 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
450 uint16_t old_nb_queues = dev->data->nb_rx_queues;
454 if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */
455 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
456 sizeof(dev->data->rx_queues[0]) * nb_queues,
457 RTE_CACHE_LINE_SIZE);
458 if (dev->data->rx_queues == NULL) {
459 dev->data->nb_rx_queues = 0;
462 } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */
463 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
465 rxq = dev->data->rx_queues;
467 for (i = nb_queues; i < old_nb_queues; i++)
468 (*dev->dev_ops->rx_queue_release)(rxq[i]);
469 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
470 RTE_CACHE_LINE_SIZE);
473 if (nb_queues > old_nb_queues) {
474 uint16_t new_qs = nb_queues - old_nb_queues;
476 memset(rxq + old_nb_queues, 0,
477 sizeof(rxq[0]) * new_qs);
480 dev->data->rx_queues = rxq;
482 } else if (dev->data->rx_queues != NULL && nb_queues == 0) {
483 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
485 rxq = dev->data->rx_queues;
487 for (i = nb_queues; i < old_nb_queues; i++)
488 (*dev->dev_ops->rx_queue_release)(rxq[i]);
490 rte_free(dev->data->rx_queues);
491 dev->data->rx_queues = NULL;
493 dev->data->nb_rx_queues = nb_queues;
498 rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id)
500 struct rte_eth_dev *dev;
502 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
504 dev = &rte_eth_devices[port_id];
505 if (rx_queue_id >= dev->data->nb_rx_queues) {
506 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
510 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
512 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
513 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
514 " already started\n",
515 rx_queue_id, port_id);
519 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
524 rte_eth_dev_rx_queue_stop(uint16_t port_id, uint16_t rx_queue_id)
526 struct rte_eth_dev *dev;
528 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
530 dev = &rte_eth_devices[port_id];
531 if (rx_queue_id >= dev->data->nb_rx_queues) {
532 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
536 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
538 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
539 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
540 " already stopped\n",
541 rx_queue_id, port_id);
545 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
550 rte_eth_dev_tx_queue_start(uint16_t port_id, uint16_t tx_queue_id)
552 struct rte_eth_dev *dev;
554 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
556 dev = &rte_eth_devices[port_id];
557 if (tx_queue_id >= dev->data->nb_tx_queues) {
558 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
562 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
564 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
565 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
566 " already started\n",
567 tx_queue_id, port_id);
571 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
576 rte_eth_dev_tx_queue_stop(uint16_t port_id, uint16_t tx_queue_id)
578 struct rte_eth_dev *dev;
580 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
582 dev = &rte_eth_devices[port_id];
583 if (tx_queue_id >= dev->data->nb_tx_queues) {
584 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
588 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
590 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
591 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
592 " already stopped\n",
593 tx_queue_id, port_id);
597 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
602 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
604 uint16_t old_nb_queues = dev->data->nb_tx_queues;
608 if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */
609 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
610 sizeof(dev->data->tx_queues[0]) * nb_queues,
611 RTE_CACHE_LINE_SIZE);
612 if (dev->data->tx_queues == NULL) {
613 dev->data->nb_tx_queues = 0;
616 } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */
617 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
619 txq = dev->data->tx_queues;
621 for (i = nb_queues; i < old_nb_queues; i++)
622 (*dev->dev_ops->tx_queue_release)(txq[i]);
623 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
624 RTE_CACHE_LINE_SIZE);
627 if (nb_queues > old_nb_queues) {
628 uint16_t new_qs = nb_queues - old_nb_queues;
630 memset(txq + old_nb_queues, 0,
631 sizeof(txq[0]) * new_qs);
634 dev->data->tx_queues = txq;
636 } else if (dev->data->tx_queues != NULL && nb_queues == 0) {
637 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
639 txq = dev->data->tx_queues;
641 for (i = nb_queues; i < old_nb_queues; i++)
642 (*dev->dev_ops->tx_queue_release)(txq[i]);
644 rte_free(dev->data->tx_queues);
645 dev->data->tx_queues = NULL;
647 dev->data->nb_tx_queues = nb_queues;
652 rte_eth_speed_bitflag(uint32_t speed, int duplex)
655 case ETH_SPEED_NUM_10M:
656 return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD;
657 case ETH_SPEED_NUM_100M:
658 return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD;
659 case ETH_SPEED_NUM_1G:
660 return ETH_LINK_SPEED_1G;
661 case ETH_SPEED_NUM_2_5G:
662 return ETH_LINK_SPEED_2_5G;
663 case ETH_SPEED_NUM_5G:
664 return ETH_LINK_SPEED_5G;
665 case ETH_SPEED_NUM_10G:
666 return ETH_LINK_SPEED_10G;
667 case ETH_SPEED_NUM_20G:
668 return ETH_LINK_SPEED_20G;
669 case ETH_SPEED_NUM_25G:
670 return ETH_LINK_SPEED_25G;
671 case ETH_SPEED_NUM_40G:
672 return ETH_LINK_SPEED_40G;
673 case ETH_SPEED_NUM_50G:
674 return ETH_LINK_SPEED_50G;
675 case ETH_SPEED_NUM_56G:
676 return ETH_LINK_SPEED_56G;
677 case ETH_SPEED_NUM_100G:
678 return ETH_LINK_SPEED_100G;
685 * A conversion function from rxmode bitfield API.
688 rte_eth_convert_rx_offload_bitfield(const struct rte_eth_rxmode *rxmode,
689 uint64_t *rx_offloads)
691 uint64_t offloads = 0;
693 if (rxmode->header_split == 1)
694 offloads |= DEV_RX_OFFLOAD_HEADER_SPLIT;
695 if (rxmode->hw_ip_checksum == 1)
696 offloads |= DEV_RX_OFFLOAD_CHECKSUM;
697 if (rxmode->hw_vlan_filter == 1)
698 offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
699 if (rxmode->hw_vlan_strip == 1)
700 offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
701 if (rxmode->hw_vlan_extend == 1)
702 offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
703 if (rxmode->jumbo_frame == 1)
704 offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
705 if (rxmode->hw_strip_crc == 1)
706 offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
707 if (rxmode->enable_scatter == 1)
708 offloads |= DEV_RX_OFFLOAD_SCATTER;
709 if (rxmode->enable_lro == 1)
710 offloads |= DEV_RX_OFFLOAD_TCP_LRO;
711 if (rxmode->hw_timestamp == 1)
712 offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
713 if (rxmode->security == 1)
714 offloads |= DEV_RX_OFFLOAD_SECURITY;
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;
767 if (rx_offloads & DEV_RX_OFFLOAD_SECURITY)
768 rxmode->security = 1;
770 rxmode->security = 0;
774 rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
775 const struct rte_eth_conf *dev_conf)
777 struct rte_eth_dev *dev;
778 struct rte_eth_dev_info dev_info;
779 struct rte_eth_conf local_conf = *dev_conf;
782 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
784 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
786 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
787 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
791 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
793 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
794 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
798 dev = &rte_eth_devices[port_id];
800 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
801 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
803 if (dev->data->dev_started) {
805 "port %d must be stopped to allow configuration\n", port_id);
810 * Convert between the offloads API to enable PMDs to support
813 if ((dev_conf->rxmode.ignore_offload_bitfield == 0)) {
814 rte_eth_convert_rx_offload_bitfield(
815 &dev_conf->rxmode, &local_conf.rxmode.offloads);
817 rte_eth_convert_rx_offloads(dev_conf->rxmode.offloads,
821 /* Copy the dev_conf parameter into the dev structure */
822 memcpy(&dev->data->dev_conf, &local_conf, sizeof(dev->data->dev_conf));
825 * Check that the numbers of RX and TX queues are not greater
826 * than the maximum number of RX and TX queues supported by the
829 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
831 if (nb_rx_q == 0 && nb_tx_q == 0) {
832 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d both rx and tx queue cannot be 0\n", port_id);
836 if (nb_rx_q > dev_info.max_rx_queues) {
837 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
838 port_id, nb_rx_q, dev_info.max_rx_queues);
842 if (nb_tx_q > dev_info.max_tx_queues) {
843 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
844 port_id, nb_tx_q, dev_info.max_tx_queues);
848 /* Check that the device supports requested interrupts */
849 if ((dev_conf->intr_conf.lsc == 1) &&
850 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
851 RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
852 dev->device->driver->name);
855 if ((dev_conf->intr_conf.rmv == 1) &&
856 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_RMV))) {
857 RTE_PMD_DEBUG_TRACE("driver %s does not support rmv\n",
858 dev->device->driver->name);
863 * If jumbo frames are enabled, check that the maximum RX packet
864 * length is supported by the configured device.
866 if (local_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
867 if (dev_conf->rxmode.max_rx_pkt_len >
868 dev_info.max_rx_pktlen) {
869 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
870 " > max valid value %u\n",
872 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
873 (unsigned)dev_info.max_rx_pktlen);
875 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
876 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
877 " < min valid value %u\n",
879 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
880 (unsigned)ETHER_MIN_LEN);
884 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
885 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
886 /* Use default value */
887 dev->data->dev_conf.rxmode.max_rx_pkt_len =
892 * Setup new number of RX/TX queues and reconfigure device.
894 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
896 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
901 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
903 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
905 rte_eth_dev_rx_queue_config(dev, 0);
909 diag = (*dev->dev_ops->dev_configure)(dev);
911 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
913 rte_eth_dev_rx_queue_config(dev, 0);
914 rte_eth_dev_tx_queue_config(dev, 0);
918 /* Initialize Rx profiling if enabled at compilation time. */
919 diag = __rte_eth_profile_rx_init(port_id, dev);
921 RTE_PMD_DEBUG_TRACE("port%d __rte_eth_profile_rx_init = %d\n",
923 rte_eth_dev_rx_queue_config(dev, 0);
924 rte_eth_dev_tx_queue_config(dev, 0);
932 _rte_eth_dev_reset(struct rte_eth_dev *dev)
934 if (dev->data->dev_started) {
936 "port %d must be stopped to allow reset\n",
941 rte_eth_dev_rx_queue_config(dev, 0);
942 rte_eth_dev_tx_queue_config(dev, 0);
944 memset(&dev->data->dev_conf, 0, sizeof(dev->data->dev_conf));
948 rte_eth_dev_config_restore(uint16_t port_id)
950 struct rte_eth_dev *dev;
951 struct rte_eth_dev_info dev_info;
952 struct ether_addr *addr;
957 dev = &rte_eth_devices[port_id];
959 rte_eth_dev_info_get(port_id, &dev_info);
961 /* replay MAC address configuration including default MAC */
962 addr = &dev->data->mac_addrs[0];
963 if (*dev->dev_ops->mac_addr_set != NULL)
964 (*dev->dev_ops->mac_addr_set)(dev, addr);
965 else if (*dev->dev_ops->mac_addr_add != NULL)
966 (*dev->dev_ops->mac_addr_add)(dev, addr, 0, pool);
968 if (*dev->dev_ops->mac_addr_add != NULL) {
969 for (i = 1; i < dev_info.max_mac_addrs; i++) {
970 addr = &dev->data->mac_addrs[i];
972 /* skip zero address */
973 if (is_zero_ether_addr(addr))
977 pool_mask = dev->data->mac_pool_sel[i];
980 if (pool_mask & 1ULL)
981 (*dev->dev_ops->mac_addr_add)(dev,
989 /* replay promiscuous configuration */
990 if (rte_eth_promiscuous_get(port_id) == 1)
991 rte_eth_promiscuous_enable(port_id);
992 else if (rte_eth_promiscuous_get(port_id) == 0)
993 rte_eth_promiscuous_disable(port_id);
995 /* replay all multicast configuration */
996 if (rte_eth_allmulticast_get(port_id) == 1)
997 rte_eth_allmulticast_enable(port_id);
998 else if (rte_eth_allmulticast_get(port_id) == 0)
999 rte_eth_allmulticast_disable(port_id);
1003 rte_eth_dev_start(uint16_t port_id)
1005 struct rte_eth_dev *dev;
1008 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1010 dev = &rte_eth_devices[port_id];
1012 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1014 if (dev->data->dev_started != 0) {
1015 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu16
1016 " already started\n",
1021 diag = (*dev->dev_ops->dev_start)(dev);
1023 dev->data->dev_started = 1;
1027 rte_eth_dev_config_restore(port_id);
1029 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1030 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1031 (*dev->dev_ops->link_update)(dev, 0);
1037 rte_eth_dev_stop(uint16_t port_id)
1039 struct rte_eth_dev *dev;
1041 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1042 dev = &rte_eth_devices[port_id];
1044 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1046 if (dev->data->dev_started == 0) {
1047 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu16
1048 " already stopped\n",
1053 dev->data->dev_started = 0;
1054 (*dev->dev_ops->dev_stop)(dev);
1058 rte_eth_dev_set_link_up(uint16_t port_id)
1060 struct rte_eth_dev *dev;
1062 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1064 dev = &rte_eth_devices[port_id];
1066 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1067 return (*dev->dev_ops->dev_set_link_up)(dev);
1071 rte_eth_dev_set_link_down(uint16_t port_id)
1073 struct rte_eth_dev *dev;
1075 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1077 dev = &rte_eth_devices[port_id];
1079 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1080 return (*dev->dev_ops->dev_set_link_down)(dev);
1084 rte_eth_dev_close(uint16_t port_id)
1086 struct rte_eth_dev *dev;
1088 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1089 dev = &rte_eth_devices[port_id];
1091 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1092 dev->data->dev_started = 0;
1093 (*dev->dev_ops->dev_close)(dev);
1095 dev->data->nb_rx_queues = 0;
1096 rte_free(dev->data->rx_queues);
1097 dev->data->rx_queues = NULL;
1098 dev->data->nb_tx_queues = 0;
1099 rte_free(dev->data->tx_queues);
1100 dev->data->tx_queues = NULL;
1104 rte_eth_dev_reset(uint16_t port_id)
1106 struct rte_eth_dev *dev;
1109 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1110 dev = &rte_eth_devices[port_id];
1112 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_reset, -ENOTSUP);
1114 rte_eth_dev_stop(port_id);
1115 ret = dev->dev_ops->dev_reset(dev);
1121 rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
1122 uint16_t nb_rx_desc, unsigned int socket_id,
1123 const struct rte_eth_rxconf *rx_conf,
1124 struct rte_mempool *mp)
1127 uint32_t mbp_buf_size;
1128 struct rte_eth_dev *dev;
1129 struct rte_eth_dev_info dev_info;
1130 struct rte_eth_rxconf local_conf;
1133 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1135 dev = &rte_eth_devices[port_id];
1136 if (rx_queue_id >= dev->data->nb_rx_queues) {
1137 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1141 if (dev->data->dev_started) {
1142 RTE_PMD_DEBUG_TRACE(
1143 "port %d must be stopped to allow configuration\n", port_id);
1147 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1148 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1151 * Check the size of the mbuf data buffer.
1152 * This value must be provided in the private data of the memory pool.
1153 * First check that the memory pool has a valid private data.
1155 rte_eth_dev_info_get(port_id, &dev_info);
1156 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1157 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1158 mp->name, (int) mp->private_data_size,
1159 (int) sizeof(struct rte_pktmbuf_pool_private));
1162 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1164 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1165 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1166 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1170 (int)(RTE_PKTMBUF_HEADROOM +
1171 dev_info.min_rx_bufsize),
1172 (int)RTE_PKTMBUF_HEADROOM,
1173 (int)dev_info.min_rx_bufsize);
1177 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1178 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1179 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1181 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1182 "should be: <= %hu, = %hu, and a product of %hu\n",
1184 dev_info.rx_desc_lim.nb_max,
1185 dev_info.rx_desc_lim.nb_min,
1186 dev_info.rx_desc_lim.nb_align);
1190 rxq = dev->data->rx_queues;
1191 if (rxq[rx_queue_id]) {
1192 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release,
1194 (*dev->dev_ops->rx_queue_release)(rxq[rx_queue_id]);
1195 rxq[rx_queue_id] = NULL;
1198 if (rx_conf == NULL)
1199 rx_conf = &dev_info.default_rxconf;
1201 local_conf = *rx_conf;
1202 if (dev->data->dev_conf.rxmode.ignore_offload_bitfield == 0) {
1204 * Reflect port offloads to queue offloads in order for
1205 * offloads to not be discarded.
1207 rte_eth_convert_rx_offload_bitfield(&dev->data->dev_conf.rxmode,
1208 &local_conf.offloads);
1211 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1212 socket_id, &local_conf, mp);
1214 if (!dev->data->min_rx_buf_size ||
1215 dev->data->min_rx_buf_size > mbp_buf_size)
1216 dev->data->min_rx_buf_size = mbp_buf_size;
1223 * A conversion function from txq_flags API.
1226 rte_eth_convert_txq_flags(const uint32_t txq_flags, uint64_t *tx_offloads)
1228 uint64_t offloads = 0;
1230 if (!(txq_flags & ETH_TXQ_FLAGS_NOMULTSEGS))
1231 offloads |= DEV_TX_OFFLOAD_MULTI_SEGS;
1232 if (!(txq_flags & ETH_TXQ_FLAGS_NOVLANOFFL))
1233 offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
1234 if (!(txq_flags & ETH_TXQ_FLAGS_NOXSUMSCTP))
1235 offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
1236 if (!(txq_flags & ETH_TXQ_FLAGS_NOXSUMUDP))
1237 offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
1238 if (!(txq_flags & ETH_TXQ_FLAGS_NOXSUMTCP))
1239 offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
1240 if ((txq_flags & ETH_TXQ_FLAGS_NOREFCOUNT) &&
1241 (txq_flags & ETH_TXQ_FLAGS_NOMULTMEMP))
1242 offloads |= DEV_TX_OFFLOAD_MBUF_FAST_FREE;
1244 *tx_offloads = offloads;
1248 * A conversion function from offloads API.
1251 rte_eth_convert_txq_offloads(const uint64_t tx_offloads, uint32_t *txq_flags)
1255 if (!(tx_offloads & DEV_TX_OFFLOAD_MULTI_SEGS))
1256 flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
1257 if (!(tx_offloads & DEV_TX_OFFLOAD_VLAN_INSERT))
1258 flags |= ETH_TXQ_FLAGS_NOVLANOFFL;
1259 if (!(tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM))
1260 flags |= ETH_TXQ_FLAGS_NOXSUMSCTP;
1261 if (!(tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM))
1262 flags |= ETH_TXQ_FLAGS_NOXSUMUDP;
1263 if (!(tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM))
1264 flags |= ETH_TXQ_FLAGS_NOXSUMTCP;
1265 if (tx_offloads & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
1266 flags |= (ETH_TXQ_FLAGS_NOREFCOUNT | ETH_TXQ_FLAGS_NOMULTMEMP);
1272 rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
1273 uint16_t nb_tx_desc, unsigned int socket_id,
1274 const struct rte_eth_txconf *tx_conf)
1276 struct rte_eth_dev *dev;
1277 struct rte_eth_dev_info dev_info;
1278 struct rte_eth_txconf local_conf;
1281 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1283 dev = &rte_eth_devices[port_id];
1284 if (tx_queue_id >= dev->data->nb_tx_queues) {
1285 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1289 if (dev->data->dev_started) {
1290 RTE_PMD_DEBUG_TRACE(
1291 "port %d must be stopped to allow configuration\n", port_id);
1295 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1296 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1298 rte_eth_dev_info_get(port_id, &dev_info);
1300 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1301 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1302 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1303 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1304 "should be: <= %hu, = %hu, and a product of %hu\n",
1306 dev_info.tx_desc_lim.nb_max,
1307 dev_info.tx_desc_lim.nb_min,
1308 dev_info.tx_desc_lim.nb_align);
1312 txq = dev->data->tx_queues;
1313 if (txq[tx_queue_id]) {
1314 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release,
1316 (*dev->dev_ops->tx_queue_release)(txq[tx_queue_id]);
1317 txq[tx_queue_id] = NULL;
1320 if (tx_conf == NULL)
1321 tx_conf = &dev_info.default_txconf;
1324 * Convert between the offloads API to enable PMDs to support
1327 local_conf = *tx_conf;
1328 if (tx_conf->txq_flags & ETH_TXQ_FLAGS_IGNORE) {
1329 rte_eth_convert_txq_offloads(tx_conf->offloads,
1330 &local_conf.txq_flags);
1331 /* Keep the ignore flag. */
1332 local_conf.txq_flags |= ETH_TXQ_FLAGS_IGNORE;
1334 rte_eth_convert_txq_flags(tx_conf->txq_flags,
1335 &local_conf.offloads);
1338 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1339 socket_id, &local_conf);
1343 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
1344 void *userdata __rte_unused)
1348 for (i = 0; i < unsent; i++)
1349 rte_pktmbuf_free(pkts[i]);
1353 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
1356 uint64_t *count = userdata;
1359 for (i = 0; i < unsent; i++)
1360 rte_pktmbuf_free(pkts[i]);
1366 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
1367 buffer_tx_error_fn cbfn, void *userdata)
1369 buffer->error_callback = cbfn;
1370 buffer->error_userdata = userdata;
1375 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
1382 buffer->size = size;
1383 if (buffer->error_callback == NULL) {
1384 ret = rte_eth_tx_buffer_set_err_callback(
1385 buffer, rte_eth_tx_buffer_drop_callback, NULL);
1392 rte_eth_tx_done_cleanup(uint16_t port_id, uint16_t queue_id, uint32_t free_cnt)
1394 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1396 /* Validate Input Data. Bail if not valid or not supported. */
1397 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1398 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_done_cleanup, -ENOTSUP);
1400 /* Call driver to free pending mbufs. */
1401 return (*dev->dev_ops->tx_done_cleanup)(dev->data->tx_queues[queue_id],
1406 rte_eth_promiscuous_enable(uint16_t port_id)
1408 struct rte_eth_dev *dev;
1410 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1411 dev = &rte_eth_devices[port_id];
1413 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1414 (*dev->dev_ops->promiscuous_enable)(dev);
1415 dev->data->promiscuous = 1;
1419 rte_eth_promiscuous_disable(uint16_t port_id)
1421 struct rte_eth_dev *dev;
1423 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1424 dev = &rte_eth_devices[port_id];
1426 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1427 dev->data->promiscuous = 0;
1428 (*dev->dev_ops->promiscuous_disable)(dev);
1432 rte_eth_promiscuous_get(uint16_t port_id)
1434 struct rte_eth_dev *dev;
1436 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1438 dev = &rte_eth_devices[port_id];
1439 return dev->data->promiscuous;
1443 rte_eth_allmulticast_enable(uint16_t port_id)
1445 struct rte_eth_dev *dev;
1447 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1448 dev = &rte_eth_devices[port_id];
1450 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1451 (*dev->dev_ops->allmulticast_enable)(dev);
1452 dev->data->all_multicast = 1;
1456 rte_eth_allmulticast_disable(uint16_t port_id)
1458 struct rte_eth_dev *dev;
1460 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1461 dev = &rte_eth_devices[port_id];
1463 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1464 dev->data->all_multicast = 0;
1465 (*dev->dev_ops->allmulticast_disable)(dev);
1469 rte_eth_allmulticast_get(uint16_t port_id)
1471 struct rte_eth_dev *dev;
1473 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1475 dev = &rte_eth_devices[port_id];
1476 return dev->data->all_multicast;
1480 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1481 struct rte_eth_link *link)
1483 struct rte_eth_link *dst = link;
1484 struct rte_eth_link *src = &(dev->data->dev_link);
1486 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1487 *(uint64_t *)src) == 0)
1494 rte_eth_link_get(uint16_t port_id, struct rte_eth_link *eth_link)
1496 struct rte_eth_dev *dev;
1498 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1499 dev = &rte_eth_devices[port_id];
1501 if (dev->data->dev_conf.intr_conf.lsc != 0)
1502 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1504 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1505 (*dev->dev_ops->link_update)(dev, 1);
1506 *eth_link = dev->data->dev_link;
1511 rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link)
1513 struct rte_eth_dev *dev;
1515 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1516 dev = &rte_eth_devices[port_id];
1518 if (dev->data->dev_conf.intr_conf.lsc != 0)
1519 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1521 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1522 (*dev->dev_ops->link_update)(dev, 0);
1523 *eth_link = dev->data->dev_link;
1528 rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats)
1530 struct rte_eth_dev *dev;
1532 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1534 dev = &rte_eth_devices[port_id];
1535 memset(stats, 0, sizeof(*stats));
1537 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1538 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1539 return (*dev->dev_ops->stats_get)(dev, stats);
1543 rte_eth_stats_reset(uint16_t port_id)
1545 struct rte_eth_dev *dev;
1547 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1548 dev = &rte_eth_devices[port_id];
1550 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_reset, -ENOTSUP);
1551 (*dev->dev_ops->stats_reset)(dev);
1552 dev->data->rx_mbuf_alloc_failed = 0;
1558 get_xstats_basic_count(struct rte_eth_dev *dev)
1560 uint16_t nb_rxqs, nb_txqs;
1563 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1564 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1566 count = RTE_NB_STATS;
1567 count += nb_rxqs * RTE_NB_RXQ_STATS;
1568 count += nb_txqs * RTE_NB_TXQ_STATS;
1574 get_xstats_count(uint16_t port_id)
1576 struct rte_eth_dev *dev;
1579 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1580 dev = &rte_eth_devices[port_id];
1581 if (dev->dev_ops->xstats_get_names_by_id != NULL) {
1582 count = (*dev->dev_ops->xstats_get_names_by_id)(dev, NULL,
1587 if (dev->dev_ops->xstats_get_names != NULL) {
1588 count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0);
1595 count += get_xstats_basic_count(dev);
1601 rte_eth_xstats_get_id_by_name(uint16_t port_id, const char *xstat_name,
1604 int cnt_xstats, idx_xstat;
1606 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1609 RTE_PMD_DEBUG_TRACE("Error: id pointer is NULL\n");
1614 RTE_PMD_DEBUG_TRACE("Error: xstat_name pointer is NULL\n");
1619 cnt_xstats = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
1620 if (cnt_xstats < 0) {
1621 RTE_PMD_DEBUG_TRACE("Error: Cannot get count of xstats\n");
1625 /* Get id-name lookup table */
1626 struct rte_eth_xstat_name xstats_names[cnt_xstats];
1628 if (cnt_xstats != rte_eth_xstats_get_names_by_id(
1629 port_id, xstats_names, cnt_xstats, NULL)) {
1630 RTE_PMD_DEBUG_TRACE("Error: Cannot get xstats lookup\n");
1634 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
1635 if (!strcmp(xstats_names[idx_xstat].name, xstat_name)) {
1644 /* retrieve ethdev extended statistics names */
1646 rte_eth_xstats_get_names_by_id(uint16_t port_id,
1647 struct rte_eth_xstat_name *xstats_names, unsigned int size,
1650 struct rte_eth_xstat_name *xstats_names_copy;
1651 unsigned int no_basic_stat_requested = 1;
1652 unsigned int expected_entries;
1653 struct rte_eth_dev *dev;
1657 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1658 dev = &rte_eth_devices[port_id];
1660 ret = get_xstats_count(port_id);
1663 expected_entries = (unsigned int)ret;
1665 /* Return max number of stats if no ids given */
1668 return expected_entries;
1669 else if (xstats_names && size < expected_entries)
1670 return expected_entries;
1673 if (ids && !xstats_names)
1676 if (ids && dev->dev_ops->xstats_get_names_by_id != NULL && size > 0) {
1677 unsigned int basic_count = get_xstats_basic_count(dev);
1678 uint64_t ids_copy[size];
1680 for (i = 0; i < size; i++) {
1681 if (ids[i] < basic_count) {
1682 no_basic_stat_requested = 0;
1687 * Convert ids to xstats ids that PMD knows.
1688 * ids known by user are basic + extended stats.
1690 ids_copy[i] = ids[i] - basic_count;
1693 if (no_basic_stat_requested)
1694 return (*dev->dev_ops->xstats_get_names_by_id)(dev,
1695 xstats_names, ids_copy, size);
1698 /* Retrieve all stats */
1700 int num_stats = rte_eth_xstats_get_names(port_id, xstats_names,
1702 if (num_stats < 0 || num_stats > (int)expected_entries)
1705 return expected_entries;
1708 xstats_names_copy = calloc(expected_entries,
1709 sizeof(struct rte_eth_xstat_name));
1711 if (!xstats_names_copy) {
1712 RTE_PMD_DEBUG_TRACE("ERROR: can't allocate memory");
1716 /* Fill xstats_names_copy structure */
1717 rte_eth_xstats_get_names(port_id, xstats_names_copy, expected_entries);
1720 for (i = 0; i < size; i++) {
1721 if (ids[i] >= expected_entries) {
1722 RTE_PMD_DEBUG_TRACE("ERROR: id value isn't valid\n");
1723 free(xstats_names_copy);
1726 xstats_names[i] = xstats_names_copy[ids[i]];
1729 free(xstats_names_copy);
1734 rte_eth_xstats_get_names(uint16_t port_id,
1735 struct rte_eth_xstat_name *xstats_names,
1738 struct rte_eth_dev *dev;
1739 int cnt_used_entries;
1740 int cnt_expected_entries;
1741 int cnt_driver_entries;
1742 uint32_t idx, id_queue;
1745 cnt_expected_entries = get_xstats_count(port_id);
1746 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1747 (int)size < cnt_expected_entries)
1748 return cnt_expected_entries;
1750 /* port_id checked in get_xstats_count() */
1751 dev = &rte_eth_devices[port_id];
1752 cnt_used_entries = 0;
1754 for (idx = 0; idx < RTE_NB_STATS; idx++) {
1755 snprintf(xstats_names[cnt_used_entries].name,
1756 sizeof(xstats_names[0].name),
1757 "%s", rte_stats_strings[idx].name);
1760 num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1761 for (id_queue = 0; id_queue < num_q; id_queue++) {
1762 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1763 snprintf(xstats_names[cnt_used_entries].name,
1764 sizeof(xstats_names[0].name),
1766 id_queue, rte_rxq_stats_strings[idx].name);
1771 num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1772 for (id_queue = 0; id_queue < num_q; id_queue++) {
1773 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
1774 snprintf(xstats_names[cnt_used_entries].name,
1775 sizeof(xstats_names[0].name),
1777 id_queue, rte_txq_stats_strings[idx].name);
1782 if (dev->dev_ops->xstats_get_names != NULL) {
1783 /* If there are any driver-specific xstats, append them
1786 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
1788 xstats_names + cnt_used_entries,
1789 size - cnt_used_entries);
1790 if (cnt_driver_entries < 0)
1791 return cnt_driver_entries;
1792 cnt_used_entries += cnt_driver_entries;
1795 return cnt_used_entries;
1798 /* retrieve ethdev extended statistics */
1800 rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
1801 uint64_t *values, unsigned int size)
1803 unsigned int no_basic_stat_requested = 1;
1804 unsigned int num_xstats_filled;
1805 uint16_t expected_entries;
1806 struct rte_eth_dev *dev;
1810 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1811 expected_entries = get_xstats_count(port_id);
1812 struct rte_eth_xstat xstats[expected_entries];
1813 dev = &rte_eth_devices[port_id];
1815 /* Return max number of stats if no ids given */
1818 return expected_entries;
1819 else if (values && size < expected_entries)
1820 return expected_entries;
1826 if (ids && dev->dev_ops->xstats_get_by_id != NULL && size) {
1827 unsigned int basic_count = get_xstats_basic_count(dev);
1828 uint64_t ids_copy[size];
1830 for (i = 0; i < size; i++) {
1831 if (ids[i] < basic_count) {
1832 no_basic_stat_requested = 0;
1837 * Convert ids to xstats ids that PMD knows.
1838 * ids known by user are basic + extended stats.
1840 ids_copy[i] = ids[i] - basic_count;
1843 if (no_basic_stat_requested)
1844 return (*dev->dev_ops->xstats_get_by_id)(dev, ids_copy,
1848 /* Fill the xstats structure */
1849 ret = rte_eth_xstats_get(port_id, xstats, expected_entries);
1852 num_xstats_filled = (unsigned int)ret;
1854 /* Return all stats */
1856 for (i = 0; i < num_xstats_filled; i++)
1857 values[i] = xstats[i].value;
1858 return expected_entries;
1862 for (i = 0; i < size; i++) {
1863 if (ids[i] >= expected_entries) {
1864 RTE_PMD_DEBUG_TRACE("ERROR: id value isn't valid\n");
1867 values[i] = xstats[ids[i]].value;
1873 rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats,
1876 struct rte_eth_stats eth_stats;
1877 struct rte_eth_dev *dev;
1878 unsigned int count = 0, i, q;
1879 signed int xcount = 0;
1880 uint64_t val, *stats_ptr;
1881 uint16_t nb_rxqs, nb_txqs;
1883 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1885 dev = &rte_eth_devices[port_id];
1887 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1888 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1890 /* Return generic statistics */
1891 count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
1892 (nb_txqs * RTE_NB_TXQ_STATS);
1894 /* implemented by the driver */
1895 if (dev->dev_ops->xstats_get != NULL) {
1896 /* Retrieve the xstats from the driver at the end of the
1899 xcount = (*dev->dev_ops->xstats_get)(dev,
1900 xstats ? xstats + count : NULL,
1901 (n > count) ? n - count : 0);
1907 if (n < count + xcount || xstats == NULL)
1908 return count + xcount;
1910 /* now fill the xstats structure */
1912 rte_eth_stats_get(port_id, ð_stats);
1915 for (i = 0; i < RTE_NB_STATS; i++) {
1916 stats_ptr = RTE_PTR_ADD(ð_stats,
1917 rte_stats_strings[i].offset);
1919 xstats[count++].value = val;
1923 for (q = 0; q < nb_rxqs; q++) {
1924 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1925 stats_ptr = RTE_PTR_ADD(ð_stats,
1926 rte_rxq_stats_strings[i].offset +
1927 q * sizeof(uint64_t));
1929 xstats[count++].value = val;
1934 for (q = 0; q < nb_txqs; q++) {
1935 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1936 stats_ptr = RTE_PTR_ADD(ð_stats,
1937 rte_txq_stats_strings[i].offset +
1938 q * sizeof(uint64_t));
1940 xstats[count++].value = val;
1944 for (i = 0; i < count; i++)
1946 /* add an offset to driver-specific stats */
1947 for ( ; i < count + xcount; i++)
1948 xstats[i].id += count;
1950 return count + xcount;
1953 /* reset ethdev extended statistics */
1955 rte_eth_xstats_reset(uint16_t port_id)
1957 struct rte_eth_dev *dev;
1959 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1960 dev = &rte_eth_devices[port_id];
1962 /* implemented by the driver */
1963 if (dev->dev_ops->xstats_reset != NULL) {
1964 (*dev->dev_ops->xstats_reset)(dev);
1968 /* fallback to default */
1969 rte_eth_stats_reset(port_id);
1973 set_queue_stats_mapping(uint16_t port_id, uint16_t queue_id, uint8_t stat_idx,
1976 struct rte_eth_dev *dev;
1978 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1980 dev = &rte_eth_devices[port_id];
1982 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1983 return (*dev->dev_ops->queue_stats_mapping_set)
1984 (dev, queue_id, stat_idx, is_rx);
1989 rte_eth_dev_set_tx_queue_stats_mapping(uint16_t port_id, uint16_t tx_queue_id,
1992 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1998 rte_eth_dev_set_rx_queue_stats_mapping(uint16_t port_id, uint16_t rx_queue_id,
2001 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
2006 rte_eth_dev_fw_version_get(uint16_t port_id, char *fw_version, size_t fw_size)
2008 struct rte_eth_dev *dev;
2010 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2011 dev = &rte_eth_devices[port_id];
2013 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP);
2014 return (*dev->dev_ops->fw_version_get)(dev, fw_version, fw_size);
2018 rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)
2020 struct rte_eth_dev *dev;
2021 const struct rte_eth_desc_lim lim = {
2022 .nb_max = UINT16_MAX,
2027 RTE_ETH_VALID_PORTID_OR_RET(port_id);
2028 dev = &rte_eth_devices[port_id];
2030 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
2031 dev_info->rx_desc_lim = lim;
2032 dev_info->tx_desc_lim = lim;
2034 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
2035 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
2036 dev_info->driver_name = dev->device->driver->name;
2037 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
2038 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
2042 rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
2043 uint32_t *ptypes, int num)
2046 struct rte_eth_dev *dev;
2047 const uint32_t *all_ptypes;
2049 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2050 dev = &rte_eth_devices[port_id];
2051 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
2052 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
2057 for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
2058 if (all_ptypes[i] & ptype_mask) {
2060 ptypes[j] = all_ptypes[i];
2068 rte_eth_macaddr_get(uint16_t port_id, struct ether_addr *mac_addr)
2070 struct rte_eth_dev *dev;
2072 RTE_ETH_VALID_PORTID_OR_RET(port_id);
2073 dev = &rte_eth_devices[port_id];
2074 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
2079 rte_eth_dev_get_mtu(uint16_t port_id, uint16_t *mtu)
2081 struct rte_eth_dev *dev;
2083 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2085 dev = &rte_eth_devices[port_id];
2086 *mtu = dev->data->mtu;
2091 rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
2094 struct rte_eth_dev *dev;
2096 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2097 dev = &rte_eth_devices[port_id];
2098 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
2100 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
2102 dev->data->mtu = mtu;
2108 rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on)
2110 struct rte_eth_dev *dev;
2113 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2114 dev = &rte_eth_devices[port_id];
2115 if (!(dev->data->dev_conf.rxmode.offloads &
2116 DEV_RX_OFFLOAD_VLAN_FILTER)) {
2117 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
2121 if (vlan_id > 4095) {
2122 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
2123 port_id, (unsigned) vlan_id);
2126 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
2128 ret = (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
2130 struct rte_vlan_filter_conf *vfc;
2134 vfc = &dev->data->vlan_filter_conf;
2135 vidx = vlan_id / 64;
2136 vbit = vlan_id % 64;
2139 vfc->ids[vidx] |= UINT64_C(1) << vbit;
2141 vfc->ids[vidx] &= ~(UINT64_C(1) << vbit);
2148 rte_eth_dev_set_vlan_strip_on_queue(uint16_t port_id, uint16_t rx_queue_id,
2151 struct rte_eth_dev *dev;
2153 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2154 dev = &rte_eth_devices[port_id];
2155 if (rx_queue_id >= dev->data->nb_rx_queues) {
2156 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
2160 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
2161 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
2167 rte_eth_dev_set_vlan_ether_type(uint16_t port_id,
2168 enum rte_vlan_type vlan_type,
2171 struct rte_eth_dev *dev;
2173 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2174 dev = &rte_eth_devices[port_id];
2175 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
2177 return (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type, tpid);
2181 rte_eth_dev_set_vlan_offload(uint16_t port_id, int offload_mask)
2183 struct rte_eth_dev *dev;
2187 uint64_t orig_offloads;
2189 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2190 dev = &rte_eth_devices[port_id];
2192 /* save original values in case of failure */
2193 orig_offloads = dev->data->dev_conf.rxmode.offloads;
2195 /*check which option changed by application*/
2196 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
2197 org = !!(dev->data->dev_conf.rxmode.offloads &
2198 DEV_RX_OFFLOAD_VLAN_STRIP);
2201 dev->data->dev_conf.rxmode.offloads |=
2202 DEV_RX_OFFLOAD_VLAN_STRIP;
2204 dev->data->dev_conf.rxmode.offloads &=
2205 ~DEV_RX_OFFLOAD_VLAN_STRIP;
2206 mask |= ETH_VLAN_STRIP_MASK;
2209 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
2210 org = !!(dev->data->dev_conf.rxmode.offloads &
2211 DEV_RX_OFFLOAD_VLAN_FILTER);
2214 dev->data->dev_conf.rxmode.offloads |=
2215 DEV_RX_OFFLOAD_VLAN_FILTER;
2217 dev->data->dev_conf.rxmode.offloads &=
2218 ~DEV_RX_OFFLOAD_VLAN_FILTER;
2219 mask |= ETH_VLAN_FILTER_MASK;
2222 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
2223 org = !!(dev->data->dev_conf.rxmode.offloads &
2224 DEV_RX_OFFLOAD_VLAN_EXTEND);
2227 dev->data->dev_conf.rxmode.offloads |=
2228 DEV_RX_OFFLOAD_VLAN_EXTEND;
2230 dev->data->dev_conf.rxmode.offloads &=
2231 ~DEV_RX_OFFLOAD_VLAN_EXTEND;
2232 mask |= ETH_VLAN_EXTEND_MASK;
2239 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
2242 * Convert to the offload bitfield API just in case the underlying PMD
2243 * still supporting it.
2245 rte_eth_convert_rx_offloads(dev->data->dev_conf.rxmode.offloads,
2246 &dev->data->dev_conf.rxmode);
2247 ret = (*dev->dev_ops->vlan_offload_set)(dev, mask);
2249 /* hit an error restore original values */
2250 dev->data->dev_conf.rxmode.offloads = orig_offloads;
2251 rte_eth_convert_rx_offloads(dev->data->dev_conf.rxmode.offloads,
2252 &dev->data->dev_conf.rxmode);
2259 rte_eth_dev_get_vlan_offload(uint16_t port_id)
2261 struct rte_eth_dev *dev;
2264 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2265 dev = &rte_eth_devices[port_id];
2267 if (dev->data->dev_conf.rxmode.offloads &
2268 DEV_RX_OFFLOAD_VLAN_STRIP)
2269 ret |= ETH_VLAN_STRIP_OFFLOAD;
2271 if (dev->data->dev_conf.rxmode.offloads &
2272 DEV_RX_OFFLOAD_VLAN_FILTER)
2273 ret |= ETH_VLAN_FILTER_OFFLOAD;
2275 if (dev->data->dev_conf.rxmode.offloads &
2276 DEV_RX_OFFLOAD_VLAN_EXTEND)
2277 ret |= ETH_VLAN_EXTEND_OFFLOAD;
2283 rte_eth_dev_set_vlan_pvid(uint16_t port_id, uint16_t pvid, int on)
2285 struct rte_eth_dev *dev;
2287 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2288 dev = &rte_eth_devices[port_id];
2289 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
2290 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
2296 rte_eth_dev_flow_ctrl_get(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
2298 struct rte_eth_dev *dev;
2300 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2301 dev = &rte_eth_devices[port_id];
2302 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2303 memset(fc_conf, 0, sizeof(*fc_conf));
2304 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
2308 rte_eth_dev_flow_ctrl_set(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
2310 struct rte_eth_dev *dev;
2312 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2313 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2314 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2318 dev = &rte_eth_devices[port_id];
2319 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2320 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
2324 rte_eth_dev_priority_flow_ctrl_set(uint16_t port_id,
2325 struct rte_eth_pfc_conf *pfc_conf)
2327 struct rte_eth_dev *dev;
2329 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2330 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2331 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2335 dev = &rte_eth_devices[port_id];
2336 /* High water, low water validation are device specific */
2337 if (*dev->dev_ops->priority_flow_ctrl_set)
2338 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
2343 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2351 num = (reta_size + RTE_RETA_GROUP_SIZE - 1) / RTE_RETA_GROUP_SIZE;
2352 for (i = 0; i < num; i++) {
2353 if (reta_conf[i].mask)
2361 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2365 uint16_t i, idx, shift;
2371 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
2375 for (i = 0; i < reta_size; i++) {
2376 idx = i / RTE_RETA_GROUP_SIZE;
2377 shift = i % RTE_RETA_GROUP_SIZE;
2378 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2379 (reta_conf[idx].reta[shift] >= max_rxq)) {
2380 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2381 "the maximum rxq index: %u\n", idx, shift,
2382 reta_conf[idx].reta[shift], max_rxq);
2391 rte_eth_dev_rss_reta_update(uint16_t port_id,
2392 struct rte_eth_rss_reta_entry64 *reta_conf,
2395 struct rte_eth_dev *dev;
2398 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2399 /* Check mask bits */
2400 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2404 dev = &rte_eth_devices[port_id];
2406 /* Check entry value */
2407 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2408 dev->data->nb_rx_queues);
2412 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2413 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2417 rte_eth_dev_rss_reta_query(uint16_t port_id,
2418 struct rte_eth_rss_reta_entry64 *reta_conf,
2421 struct rte_eth_dev *dev;
2424 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2426 /* Check mask bits */
2427 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2431 dev = &rte_eth_devices[port_id];
2432 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2433 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2437 rte_eth_dev_rss_hash_update(uint16_t port_id,
2438 struct rte_eth_rss_conf *rss_conf)
2440 struct rte_eth_dev *dev;
2442 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2443 dev = &rte_eth_devices[port_id];
2444 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2445 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2449 rte_eth_dev_rss_hash_conf_get(uint16_t port_id,
2450 struct rte_eth_rss_conf *rss_conf)
2452 struct rte_eth_dev *dev;
2454 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2455 dev = &rte_eth_devices[port_id];
2456 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2457 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2461 rte_eth_dev_udp_tunnel_port_add(uint16_t port_id,
2462 struct rte_eth_udp_tunnel *udp_tunnel)
2464 struct rte_eth_dev *dev;
2466 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2467 if (udp_tunnel == NULL) {
2468 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2472 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2473 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2477 dev = &rte_eth_devices[port_id];
2478 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
2479 return (*dev->dev_ops->udp_tunnel_port_add)(dev, udp_tunnel);
2483 rte_eth_dev_udp_tunnel_port_delete(uint16_t port_id,
2484 struct rte_eth_udp_tunnel *udp_tunnel)
2486 struct rte_eth_dev *dev;
2488 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2489 dev = &rte_eth_devices[port_id];
2491 if (udp_tunnel == NULL) {
2492 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2496 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2497 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2501 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
2502 return (*dev->dev_ops->udp_tunnel_port_del)(dev, udp_tunnel);
2506 rte_eth_led_on(uint16_t port_id)
2508 struct rte_eth_dev *dev;
2510 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2511 dev = &rte_eth_devices[port_id];
2512 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2513 return (*dev->dev_ops->dev_led_on)(dev);
2517 rte_eth_led_off(uint16_t port_id)
2519 struct rte_eth_dev *dev;
2521 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2522 dev = &rte_eth_devices[port_id];
2523 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2524 return (*dev->dev_ops->dev_led_off)(dev);
2528 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2532 get_mac_addr_index(uint16_t port_id, const struct ether_addr *addr)
2534 struct rte_eth_dev_info dev_info;
2535 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2538 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2539 rte_eth_dev_info_get(port_id, &dev_info);
2541 for (i = 0; i < dev_info.max_mac_addrs; i++)
2542 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2548 static const struct ether_addr null_mac_addr;
2551 rte_eth_dev_mac_addr_add(uint16_t port_id, struct ether_addr *addr,
2554 struct rte_eth_dev *dev;
2559 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2560 dev = &rte_eth_devices[port_id];
2561 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2563 if (is_zero_ether_addr(addr)) {
2564 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2568 if (pool >= ETH_64_POOLS) {
2569 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2573 index = get_mac_addr_index(port_id, addr);
2575 index = get_mac_addr_index(port_id, &null_mac_addr);
2577 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2582 pool_mask = dev->data->mac_pool_sel[index];
2584 /* Check if both MAC address and pool is already there, and do nothing */
2585 if (pool_mask & (1ULL << pool))
2590 ret = (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2593 /* Update address in NIC data structure */
2594 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2596 /* Update pool bitmap in NIC data structure */
2597 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2604 rte_eth_dev_mac_addr_remove(uint16_t port_id, struct ether_addr *addr)
2606 struct rte_eth_dev *dev;
2609 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2610 dev = &rte_eth_devices[port_id];
2611 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2613 index = get_mac_addr_index(port_id, addr);
2615 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2617 } else if (index < 0)
2618 return 0; /* Do nothing if address wasn't found */
2621 (*dev->dev_ops->mac_addr_remove)(dev, index);
2623 /* Update address in NIC data structure */
2624 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2626 /* reset pool bitmap */
2627 dev->data->mac_pool_sel[index] = 0;
2633 rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct ether_addr *addr)
2635 struct rte_eth_dev *dev;
2637 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2639 if (!is_valid_assigned_ether_addr(addr))
2642 dev = &rte_eth_devices[port_id];
2643 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2645 /* Update default address in NIC data structure */
2646 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2648 (*dev->dev_ops->mac_addr_set)(dev, addr);
2655 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2659 get_hash_mac_addr_index(uint16_t port_id, const struct ether_addr *addr)
2661 struct rte_eth_dev_info dev_info;
2662 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2665 rte_eth_dev_info_get(port_id, &dev_info);
2666 if (!dev->data->hash_mac_addrs)
2669 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2670 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2671 ETHER_ADDR_LEN) == 0)
2678 rte_eth_dev_uc_hash_table_set(uint16_t port_id, struct ether_addr *addr,
2683 struct rte_eth_dev *dev;
2685 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2687 dev = &rte_eth_devices[port_id];
2688 if (is_zero_ether_addr(addr)) {
2689 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2694 index = get_hash_mac_addr_index(port_id, addr);
2695 /* Check if it's already there, and do nothing */
2696 if ((index >= 0) && (on))
2701 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2702 "set in UTA\n", port_id);
2706 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2708 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2714 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2715 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2717 /* Update address in NIC data structure */
2719 ether_addr_copy(addr,
2720 &dev->data->hash_mac_addrs[index]);
2722 ether_addr_copy(&null_mac_addr,
2723 &dev->data->hash_mac_addrs[index]);
2730 rte_eth_dev_uc_all_hash_table_set(uint16_t port_id, uint8_t on)
2732 struct rte_eth_dev *dev;
2734 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2736 dev = &rte_eth_devices[port_id];
2738 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2739 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2742 int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx,
2745 struct rte_eth_dev *dev;
2746 struct rte_eth_dev_info dev_info;
2747 struct rte_eth_link link;
2749 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2751 dev = &rte_eth_devices[port_id];
2752 rte_eth_dev_info_get(port_id, &dev_info);
2753 link = dev->data->dev_link;
2755 if (queue_idx > dev_info.max_tx_queues) {
2756 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2757 "invalid queue id=%d\n", port_id, queue_idx);
2761 if (tx_rate > link.link_speed) {
2762 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2763 "bigger than link speed= %d\n",
2764 tx_rate, link.link_speed);
2768 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2769 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2773 rte_eth_mirror_rule_set(uint16_t port_id,
2774 struct rte_eth_mirror_conf *mirror_conf,
2775 uint8_t rule_id, uint8_t on)
2777 struct rte_eth_dev *dev;
2779 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2780 if (mirror_conf->rule_type == 0) {
2781 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2785 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2786 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2791 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2792 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2793 (mirror_conf->pool_mask == 0)) {
2794 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2798 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2799 mirror_conf->vlan.vlan_mask == 0) {
2800 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2804 dev = &rte_eth_devices[port_id];
2805 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2807 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2811 rte_eth_mirror_rule_reset(uint16_t port_id, uint8_t rule_id)
2813 struct rte_eth_dev *dev;
2815 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2817 dev = &rte_eth_devices[port_id];
2818 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2820 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2824 rte_eth_dev_callback_register(uint16_t port_id,
2825 enum rte_eth_event_type event,
2826 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2828 struct rte_eth_dev *dev;
2829 struct rte_eth_dev_callback *user_cb;
2834 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2836 dev = &rte_eth_devices[port_id];
2837 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2839 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2840 if (user_cb->cb_fn == cb_fn &&
2841 user_cb->cb_arg == cb_arg &&
2842 user_cb->event == event) {
2847 /* create a new callback. */
2848 if (user_cb == NULL) {
2849 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2850 sizeof(struct rte_eth_dev_callback), 0);
2851 if (user_cb != NULL) {
2852 user_cb->cb_fn = cb_fn;
2853 user_cb->cb_arg = cb_arg;
2854 user_cb->event = event;
2855 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2859 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2860 return (user_cb == NULL) ? -ENOMEM : 0;
2864 rte_eth_dev_callback_unregister(uint16_t port_id,
2865 enum rte_eth_event_type event,
2866 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2869 struct rte_eth_dev *dev;
2870 struct rte_eth_dev_callback *cb, *next;
2875 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2877 dev = &rte_eth_devices[port_id];
2878 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2881 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2883 next = TAILQ_NEXT(cb, next);
2885 if (cb->cb_fn != cb_fn || cb->event != event ||
2886 (cb->cb_arg != (void *)-1 &&
2887 cb->cb_arg != cb_arg))
2891 * if this callback is not executing right now,
2894 if (cb->active == 0) {
2895 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2902 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2907 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2908 enum rte_eth_event_type event, void *cb_arg, void *ret_param)
2910 struct rte_eth_dev_callback *cb_lst;
2911 struct rte_eth_dev_callback dev_cb;
2914 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2915 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2916 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2921 dev_cb.cb_arg = cb_arg;
2922 if (ret_param != NULL)
2923 dev_cb.ret_param = ret_param;
2925 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2926 rc = dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2927 dev_cb.cb_arg, dev_cb.ret_param);
2928 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2931 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2936 rte_eth_dev_rx_intr_ctl(uint16_t port_id, int epfd, int op, void *data)
2939 struct rte_eth_dev *dev;
2940 struct rte_intr_handle *intr_handle;
2944 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2946 dev = &rte_eth_devices[port_id];
2948 if (!dev->intr_handle) {
2949 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
2953 intr_handle = dev->intr_handle;
2954 if (!intr_handle->intr_vec) {
2955 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2959 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2960 vec = intr_handle->intr_vec[qid];
2961 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2962 if (rc && rc != -EEXIST) {
2963 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2964 " op %d epfd %d vec %u\n",
2965 port_id, qid, op, epfd, vec);
2972 const struct rte_memzone *
2973 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2974 uint16_t queue_id, size_t size, unsigned align,
2977 char z_name[RTE_MEMZONE_NAMESIZE];
2978 const struct rte_memzone *mz;
2980 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2981 dev->device->driver->name, ring_name,
2982 dev->data->port_id, queue_id);
2984 mz = rte_memzone_lookup(z_name);
2988 return rte_memzone_reserve_aligned(z_name, size, socket_id, 0, align);
2992 rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id,
2993 int epfd, int op, void *data)
2996 struct rte_eth_dev *dev;
2997 struct rte_intr_handle *intr_handle;
3000 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3002 dev = &rte_eth_devices[port_id];
3003 if (queue_id >= dev->data->nb_rx_queues) {
3004 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
3008 if (!dev->intr_handle) {
3009 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
3013 intr_handle = dev->intr_handle;
3014 if (!intr_handle->intr_vec) {
3015 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
3019 vec = intr_handle->intr_vec[queue_id];
3020 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
3021 if (rc && rc != -EEXIST) {
3022 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
3023 " op %d epfd %d vec %u\n",
3024 port_id, queue_id, op, epfd, vec);
3032 rte_eth_dev_rx_intr_enable(uint16_t port_id,
3035 struct rte_eth_dev *dev;
3037 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3039 dev = &rte_eth_devices[port_id];
3041 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
3042 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
3046 rte_eth_dev_rx_intr_disable(uint16_t port_id,
3049 struct rte_eth_dev *dev;
3051 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3053 dev = &rte_eth_devices[port_id];
3055 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
3056 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
3061 rte_eth_dev_filter_supported(uint16_t port_id,
3062 enum rte_filter_type filter_type)
3064 struct rte_eth_dev *dev;
3066 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3068 dev = &rte_eth_devices[port_id];
3069 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3070 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3071 RTE_ETH_FILTER_NOP, NULL);
3075 rte_eth_dev_filter_ctrl(uint16_t port_id, enum rte_filter_type filter_type,
3076 enum rte_filter_op filter_op, void *arg)
3078 struct rte_eth_dev *dev;
3080 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3082 dev = &rte_eth_devices[port_id];
3083 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3084 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
3088 rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
3089 rte_rx_callback_fn fn, void *user_param)
3091 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3092 rte_errno = ENOTSUP;
3095 /* check input parameters */
3096 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3097 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3101 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3109 cb->param = user_param;
3111 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3112 /* Add the callbacks in fifo order. */
3113 struct rte_eth_rxtx_callback *tail =
3114 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3117 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3124 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3130 rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
3131 rte_rx_callback_fn fn, void *user_param)
3133 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3134 rte_errno = ENOTSUP;
3137 /* check input parameters */
3138 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3139 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3144 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3152 cb->param = user_param;
3154 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3155 /* Add the callbacks at fisrt position*/
3156 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3158 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3159 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3165 rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
3166 rte_tx_callback_fn fn, void *user_param)
3168 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3169 rte_errno = ENOTSUP;
3172 /* check input parameters */
3173 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3174 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3179 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3187 cb->param = user_param;
3189 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3190 /* Add the callbacks in fifo order. */
3191 struct rte_eth_rxtx_callback *tail =
3192 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3195 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3202 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3208 rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
3209 struct rte_eth_rxtx_callback *user_cb)
3211 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3214 /* Check input parameters. */
3215 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3216 if (user_cb == NULL ||
3217 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
3220 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3221 struct rte_eth_rxtx_callback *cb;
3222 struct rte_eth_rxtx_callback **prev_cb;
3225 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3226 prev_cb = &dev->post_rx_burst_cbs[queue_id];
3227 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3229 if (cb == user_cb) {
3230 /* Remove the user cb from the callback list. */
3231 *prev_cb = cb->next;
3236 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3242 rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
3243 struct rte_eth_rxtx_callback *user_cb)
3245 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3248 /* Check input parameters. */
3249 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3250 if (user_cb == NULL ||
3251 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
3254 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3256 struct rte_eth_rxtx_callback *cb;
3257 struct rte_eth_rxtx_callback **prev_cb;
3259 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3260 prev_cb = &dev->pre_tx_burst_cbs[queue_id];
3261 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3263 if (cb == user_cb) {
3264 /* Remove the user cb from the callback list. */
3265 *prev_cb = cb->next;
3270 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3276 rte_eth_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
3277 struct rte_eth_rxq_info *qinfo)
3279 struct rte_eth_dev *dev;
3281 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3286 dev = &rte_eth_devices[port_id];
3287 if (queue_id >= dev->data->nb_rx_queues) {
3288 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3292 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3294 memset(qinfo, 0, sizeof(*qinfo));
3295 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3300 rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,
3301 struct rte_eth_txq_info *qinfo)
3303 struct rte_eth_dev *dev;
3305 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3310 dev = &rte_eth_devices[port_id];
3311 if (queue_id >= dev->data->nb_tx_queues) {
3312 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3316 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3318 memset(qinfo, 0, sizeof(*qinfo));
3319 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3324 rte_eth_dev_set_mc_addr_list(uint16_t port_id,
3325 struct ether_addr *mc_addr_set,
3326 uint32_t nb_mc_addr)
3328 struct rte_eth_dev *dev;
3330 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3332 dev = &rte_eth_devices[port_id];
3333 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3334 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3338 rte_eth_timesync_enable(uint16_t port_id)
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_enable, -ENOTSUP);
3346 return (*dev->dev_ops->timesync_enable)(dev);
3350 rte_eth_timesync_disable(uint16_t port_id)
3352 struct rte_eth_dev *dev;
3354 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3355 dev = &rte_eth_devices[port_id];
3357 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3358 return (*dev->dev_ops->timesync_disable)(dev);
3362 rte_eth_timesync_read_rx_timestamp(uint16_t port_id, struct timespec *timestamp,
3365 struct rte_eth_dev *dev;
3367 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3368 dev = &rte_eth_devices[port_id];
3370 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3371 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3375 rte_eth_timesync_read_tx_timestamp(uint16_t port_id,
3376 struct timespec *timestamp)
3378 struct rte_eth_dev *dev;
3380 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3381 dev = &rte_eth_devices[port_id];
3383 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3384 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3388 rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta)
3390 struct rte_eth_dev *dev;
3392 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3393 dev = &rte_eth_devices[port_id];
3395 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3396 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3400 rte_eth_timesync_read_time(uint16_t port_id, struct timespec *timestamp)
3402 struct rte_eth_dev *dev;
3404 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3405 dev = &rte_eth_devices[port_id];
3407 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3408 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3412 rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *timestamp)
3414 struct rte_eth_dev *dev;
3416 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3417 dev = &rte_eth_devices[port_id];
3419 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3420 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3424 rte_eth_dev_get_reg_info(uint16_t port_id, struct rte_dev_reg_info *info)
3426 struct rte_eth_dev *dev;
3428 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3430 dev = &rte_eth_devices[port_id];
3431 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3432 return (*dev->dev_ops->get_reg)(dev, info);
3436 rte_eth_dev_get_eeprom_length(uint16_t port_id)
3438 struct rte_eth_dev *dev;
3440 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3442 dev = &rte_eth_devices[port_id];
3443 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3444 return (*dev->dev_ops->get_eeprom_length)(dev);
3448 rte_eth_dev_get_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
3450 struct rte_eth_dev *dev;
3452 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3454 dev = &rte_eth_devices[port_id];
3455 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3456 return (*dev->dev_ops->get_eeprom)(dev, info);
3460 rte_eth_dev_set_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
3462 struct rte_eth_dev *dev;
3464 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3466 dev = &rte_eth_devices[port_id];
3467 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3468 return (*dev->dev_ops->set_eeprom)(dev, info);
3472 rte_eth_dev_get_dcb_info(uint16_t port_id,
3473 struct rte_eth_dcb_info *dcb_info)
3475 struct rte_eth_dev *dev;
3477 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3479 dev = &rte_eth_devices[port_id];
3480 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3482 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3483 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3487 rte_eth_dev_l2_tunnel_eth_type_conf(uint16_t port_id,
3488 struct rte_eth_l2_tunnel_conf *l2_tunnel)
3490 struct rte_eth_dev *dev;
3492 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3493 if (l2_tunnel == NULL) {
3494 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3498 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3499 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
3503 dev = &rte_eth_devices[port_id];
3504 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
3506 return (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev, l2_tunnel);
3510 rte_eth_dev_l2_tunnel_offload_set(uint16_t port_id,
3511 struct rte_eth_l2_tunnel_conf *l2_tunnel,
3515 struct rte_eth_dev *dev;
3517 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3519 if (l2_tunnel == NULL) {
3520 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3524 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3525 RTE_PMD_DEBUG_TRACE("Invalid tunnel type.\n");
3530 RTE_PMD_DEBUG_TRACE("Mask should have a value.\n");
3534 dev = &rte_eth_devices[port_id];
3535 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
3537 return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);
3541 rte_eth_dev_adjust_nb_desc(uint16_t *nb_desc,
3542 const struct rte_eth_desc_lim *desc_lim)
3544 if (desc_lim->nb_align != 0)
3545 *nb_desc = RTE_ALIGN_CEIL(*nb_desc, desc_lim->nb_align);
3547 if (desc_lim->nb_max != 0)
3548 *nb_desc = RTE_MIN(*nb_desc, desc_lim->nb_max);
3550 *nb_desc = RTE_MAX(*nb_desc, desc_lim->nb_min);
3554 rte_eth_dev_adjust_nb_rx_tx_desc(uint16_t port_id,
3555 uint16_t *nb_rx_desc,
3556 uint16_t *nb_tx_desc)
3558 struct rte_eth_dev *dev;
3559 struct rte_eth_dev_info dev_info;
3561 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3563 dev = &rte_eth_devices[port_id];
3564 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
3566 rte_eth_dev_info_get(port_id, &dev_info);
3568 if (nb_rx_desc != NULL)
3569 rte_eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim);
3571 if (nb_tx_desc != NULL)
3572 rte_eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim);
3578 rte_eth_dev_pool_ops_supported(uint16_t port_id, const char *pool)
3580 struct rte_eth_dev *dev;
3582 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3587 dev = &rte_eth_devices[port_id];
3589 if (*dev->dev_ops->pool_ops_supported == NULL)
3590 return 1; /* all pools are supported */
3592 return (*dev->dev_ops->pool_ops_supported)(dev, pool);