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_missed_errors", offsetof(struct rte_eth_stats, imissed)},
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 /* Using shared name field to find a free port. */
196 if (rte_eth_dev_data[i].name[0] == '\0') {
197 RTE_ASSERT(rte_eth_devices[i].state ==
202 return RTE_MAX_ETHPORTS;
205 static struct rte_eth_dev *
206 eth_dev_get(uint16_t port_id)
208 struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
210 eth_dev->data = &rte_eth_dev_data[port_id];
211 eth_dev->state = RTE_ETH_DEV_ATTACHED;
212 TAILQ_INIT(&(eth_dev->link_intr_cbs));
214 eth_dev_last_created_port = port_id;
220 rte_eth_dev_allocate(const char *name)
223 struct rte_eth_dev *eth_dev;
225 if (rte_eth_dev_data == NULL)
226 rte_eth_dev_data_alloc();
228 port_id = rte_eth_dev_find_free_port();
229 if (port_id == RTE_MAX_ETHPORTS) {
230 RTE_PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
234 if (rte_eth_dev_allocated(name) != NULL) {
235 RTE_PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n",
240 eth_dev = eth_dev_get(port_id);
241 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
242 eth_dev->data->port_id = port_id;
243 eth_dev->data->mtu = ETHER_MTU;
249 * Attach to a port already registered by the primary process, which
250 * makes sure that the same device would have the same port id both
251 * in the primary and secondary process.
254 rte_eth_dev_attach_secondary(const char *name)
257 struct rte_eth_dev *eth_dev;
259 if (rte_eth_dev_data == NULL)
260 rte_eth_dev_data_alloc();
262 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
263 if (strcmp(rte_eth_dev_data[i].name, name) == 0)
266 if (i == RTE_MAX_ETHPORTS) {
268 "device %s is not driven by the primary process\n",
273 eth_dev = eth_dev_get(i);
274 RTE_ASSERT(eth_dev->data->port_id == i);
280 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
285 memset(eth_dev->data, 0, sizeof(struct rte_eth_dev_data));
286 eth_dev->state = RTE_ETH_DEV_UNUSED;
291 rte_eth_dev_is_valid_port(uint16_t port_id)
293 if (port_id >= RTE_MAX_ETHPORTS ||
294 (rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
295 rte_eth_devices[port_id].state != RTE_ETH_DEV_DEFERRED))
302 rte_eth_dev_socket_id(uint16_t port_id)
304 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
305 return rte_eth_devices[port_id].data->numa_node;
309 rte_eth_dev_get_sec_ctx(uint8_t port_id)
311 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, NULL);
312 return rte_eth_devices[port_id].security_ctx;
316 rte_eth_dev_count(void)
323 RTE_ETH_FOREACH_DEV(p)
330 rte_eth_dev_get_name_by_port(uint16_t port_id, char *name)
334 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
337 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
341 /* shouldn't check 'rte_eth_devices[i].data',
342 * because it might be overwritten by VDEV PMD */
343 tmp = rte_eth_dev_data[port_id].name;
349 rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
354 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
358 RTE_ETH_FOREACH_DEV(i) {
360 rte_eth_dev_data[i].name, strlen(name))) {
370 /* attach the new device, then store port_id of the device */
372 rte_eth_dev_attach(const char *devargs, uint16_t *port_id)
375 int current = rte_eth_dev_count();
379 if ((devargs == NULL) || (port_id == NULL)) {
384 /* parse devargs, then retrieve device name and args */
385 if (rte_eal_parse_devargs_str(devargs, &name, &args))
388 ret = rte_eal_dev_attach(name, args);
392 /* no point looking at the port count if no port exists */
393 if (!rte_eth_dev_count()) {
394 RTE_LOG(ERR, EAL, "No port found for device (%s)\n", name);
399 /* if nothing happened, there is a bug here, since some driver told us
400 * it did attach a device, but did not create a port.
402 if (current == rte_eth_dev_count()) {
407 *port_id = eth_dev_last_created_port;
416 /* detach the device, then store the name of the device */
418 rte_eth_dev_detach(uint16_t port_id, char *name)
423 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
430 dev_flags = rte_eth_devices[port_id].data->dev_flags;
431 if (dev_flags & RTE_ETH_DEV_BONDED_SLAVE) {
432 RTE_LOG(ERR, EAL, "Port %" PRIu16 " is bonded, cannot detach\n",
438 snprintf(name, sizeof(rte_eth_devices[port_id].data->name),
439 "%s", rte_eth_devices[port_id].data->name);
441 ret = rte_eal_dev_detach(rte_eth_devices[port_id].device);
445 rte_eth_devices[port_id].state = RTE_ETH_DEV_UNUSED;
453 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
455 uint16_t old_nb_queues = dev->data->nb_rx_queues;
459 if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */
460 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
461 sizeof(dev->data->rx_queues[0]) * nb_queues,
462 RTE_CACHE_LINE_SIZE);
463 if (dev->data->rx_queues == NULL) {
464 dev->data->nb_rx_queues = 0;
467 } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */
468 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
470 rxq = dev->data->rx_queues;
472 for (i = nb_queues; i < old_nb_queues; i++)
473 (*dev->dev_ops->rx_queue_release)(rxq[i]);
474 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
475 RTE_CACHE_LINE_SIZE);
478 if (nb_queues > old_nb_queues) {
479 uint16_t new_qs = nb_queues - old_nb_queues;
481 memset(rxq + old_nb_queues, 0,
482 sizeof(rxq[0]) * new_qs);
485 dev->data->rx_queues = rxq;
487 } else if (dev->data->rx_queues != NULL && nb_queues == 0) {
488 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
490 rxq = dev->data->rx_queues;
492 for (i = nb_queues; i < old_nb_queues; i++)
493 (*dev->dev_ops->rx_queue_release)(rxq[i]);
495 rte_free(dev->data->rx_queues);
496 dev->data->rx_queues = NULL;
498 dev->data->nb_rx_queues = nb_queues;
503 rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id)
505 struct rte_eth_dev *dev;
507 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
509 dev = &rte_eth_devices[port_id];
510 if (rx_queue_id >= dev->data->nb_rx_queues) {
511 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
515 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
517 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
518 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
519 " already started\n",
520 rx_queue_id, port_id);
524 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
529 rte_eth_dev_rx_queue_stop(uint16_t port_id, uint16_t rx_queue_id)
531 struct rte_eth_dev *dev;
533 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
535 dev = &rte_eth_devices[port_id];
536 if (rx_queue_id >= dev->data->nb_rx_queues) {
537 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
541 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
543 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
544 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
545 " already stopped\n",
546 rx_queue_id, port_id);
550 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
555 rte_eth_dev_tx_queue_start(uint16_t port_id, uint16_t tx_queue_id)
557 struct rte_eth_dev *dev;
559 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
561 dev = &rte_eth_devices[port_id];
562 if (tx_queue_id >= dev->data->nb_tx_queues) {
563 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
567 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
569 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
570 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
571 " already started\n",
572 tx_queue_id, port_id);
576 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
581 rte_eth_dev_tx_queue_stop(uint16_t port_id, uint16_t tx_queue_id)
583 struct rte_eth_dev *dev;
585 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
587 dev = &rte_eth_devices[port_id];
588 if (tx_queue_id >= dev->data->nb_tx_queues) {
589 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
593 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
595 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
596 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
597 " already stopped\n",
598 tx_queue_id, port_id);
602 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
607 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
609 uint16_t old_nb_queues = dev->data->nb_tx_queues;
613 if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */
614 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
615 sizeof(dev->data->tx_queues[0]) * nb_queues,
616 RTE_CACHE_LINE_SIZE);
617 if (dev->data->tx_queues == NULL) {
618 dev->data->nb_tx_queues = 0;
621 } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */
622 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
624 txq = dev->data->tx_queues;
626 for (i = nb_queues; i < old_nb_queues; i++)
627 (*dev->dev_ops->tx_queue_release)(txq[i]);
628 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
629 RTE_CACHE_LINE_SIZE);
632 if (nb_queues > old_nb_queues) {
633 uint16_t new_qs = nb_queues - old_nb_queues;
635 memset(txq + old_nb_queues, 0,
636 sizeof(txq[0]) * new_qs);
639 dev->data->tx_queues = txq;
641 } else if (dev->data->tx_queues != NULL && nb_queues == 0) {
642 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
644 txq = dev->data->tx_queues;
646 for (i = nb_queues; i < old_nb_queues; i++)
647 (*dev->dev_ops->tx_queue_release)(txq[i]);
649 rte_free(dev->data->tx_queues);
650 dev->data->tx_queues = NULL;
652 dev->data->nb_tx_queues = nb_queues;
657 rte_eth_speed_bitflag(uint32_t speed, int duplex)
660 case ETH_SPEED_NUM_10M:
661 return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD;
662 case ETH_SPEED_NUM_100M:
663 return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD;
664 case ETH_SPEED_NUM_1G:
665 return ETH_LINK_SPEED_1G;
666 case ETH_SPEED_NUM_2_5G:
667 return ETH_LINK_SPEED_2_5G;
668 case ETH_SPEED_NUM_5G:
669 return ETH_LINK_SPEED_5G;
670 case ETH_SPEED_NUM_10G:
671 return ETH_LINK_SPEED_10G;
672 case ETH_SPEED_NUM_20G:
673 return ETH_LINK_SPEED_20G;
674 case ETH_SPEED_NUM_25G:
675 return ETH_LINK_SPEED_25G;
676 case ETH_SPEED_NUM_40G:
677 return ETH_LINK_SPEED_40G;
678 case ETH_SPEED_NUM_50G:
679 return ETH_LINK_SPEED_50G;
680 case ETH_SPEED_NUM_56G:
681 return ETH_LINK_SPEED_56G;
682 case ETH_SPEED_NUM_100G:
683 return ETH_LINK_SPEED_100G;
690 * A conversion function from rxmode bitfield API.
693 rte_eth_convert_rx_offload_bitfield(const struct rte_eth_rxmode *rxmode,
694 uint64_t *rx_offloads)
696 uint64_t offloads = 0;
698 if (rxmode->header_split == 1)
699 offloads |= DEV_RX_OFFLOAD_HEADER_SPLIT;
700 if (rxmode->hw_ip_checksum == 1)
701 offloads |= DEV_RX_OFFLOAD_CHECKSUM;
702 if (rxmode->hw_vlan_filter == 1)
703 offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
704 if (rxmode->hw_vlan_strip == 1)
705 offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
706 if (rxmode->hw_vlan_extend == 1)
707 offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
708 if (rxmode->jumbo_frame == 1)
709 offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
710 if (rxmode->hw_strip_crc == 1)
711 offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
712 if (rxmode->enable_scatter == 1)
713 offloads |= DEV_RX_OFFLOAD_SCATTER;
714 if (rxmode->enable_lro == 1)
715 offloads |= DEV_RX_OFFLOAD_TCP_LRO;
716 if (rxmode->hw_timestamp == 1)
717 offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
718 if (rxmode->security == 1)
719 offloads |= DEV_RX_OFFLOAD_SECURITY;
721 *rx_offloads = offloads;
725 * A conversion function from rxmode offloads API.
728 rte_eth_convert_rx_offloads(const uint64_t rx_offloads,
729 struct rte_eth_rxmode *rxmode)
732 if (rx_offloads & DEV_RX_OFFLOAD_HEADER_SPLIT)
733 rxmode->header_split = 1;
735 rxmode->header_split = 0;
736 if (rx_offloads & DEV_RX_OFFLOAD_CHECKSUM)
737 rxmode->hw_ip_checksum = 1;
739 rxmode->hw_ip_checksum = 0;
740 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
741 rxmode->hw_vlan_filter = 1;
743 rxmode->hw_vlan_filter = 0;
744 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
745 rxmode->hw_vlan_strip = 1;
747 rxmode->hw_vlan_strip = 0;
748 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND)
749 rxmode->hw_vlan_extend = 1;
751 rxmode->hw_vlan_extend = 0;
752 if (rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME)
753 rxmode->jumbo_frame = 1;
755 rxmode->jumbo_frame = 0;
756 if (rx_offloads & DEV_RX_OFFLOAD_CRC_STRIP)
757 rxmode->hw_strip_crc = 1;
759 rxmode->hw_strip_crc = 0;
760 if (rx_offloads & DEV_RX_OFFLOAD_SCATTER)
761 rxmode->enable_scatter = 1;
763 rxmode->enable_scatter = 0;
764 if (rx_offloads & DEV_RX_OFFLOAD_TCP_LRO)
765 rxmode->enable_lro = 1;
767 rxmode->enable_lro = 0;
768 if (rx_offloads & DEV_RX_OFFLOAD_TIMESTAMP)
769 rxmode->hw_timestamp = 1;
771 rxmode->hw_timestamp = 0;
772 if (rx_offloads & DEV_RX_OFFLOAD_SECURITY)
773 rxmode->security = 1;
775 rxmode->security = 0;
779 rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
780 const struct rte_eth_conf *dev_conf)
782 struct rte_eth_dev *dev;
783 struct rte_eth_dev_info dev_info;
784 struct rte_eth_conf local_conf = *dev_conf;
787 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
789 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
791 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
792 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
796 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
798 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
799 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
803 dev = &rte_eth_devices[port_id];
805 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
806 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
808 if (dev->data->dev_started) {
810 "port %d must be stopped to allow configuration\n", port_id);
815 * Convert between the offloads API to enable PMDs to support
818 if ((dev_conf->rxmode.ignore_offload_bitfield == 0)) {
819 rte_eth_convert_rx_offload_bitfield(
820 &dev_conf->rxmode, &local_conf.rxmode.offloads);
822 rte_eth_convert_rx_offloads(dev_conf->rxmode.offloads,
826 /* Copy the dev_conf parameter into the dev structure */
827 memcpy(&dev->data->dev_conf, &local_conf, sizeof(dev->data->dev_conf));
830 * Check that the numbers of RX and TX queues are not greater
831 * than the maximum number of RX and TX queues supported by the
834 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
836 if (nb_rx_q == 0 && nb_tx_q == 0) {
837 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d both rx and tx queue cannot be 0\n", port_id);
841 if (nb_rx_q > dev_info.max_rx_queues) {
842 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
843 port_id, nb_rx_q, dev_info.max_rx_queues);
847 if (nb_tx_q > dev_info.max_tx_queues) {
848 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
849 port_id, nb_tx_q, dev_info.max_tx_queues);
853 /* Check that the device supports requested interrupts */
854 if ((dev_conf->intr_conf.lsc == 1) &&
855 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
856 RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
857 dev->device->driver->name);
860 if ((dev_conf->intr_conf.rmv == 1) &&
861 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_RMV))) {
862 RTE_PMD_DEBUG_TRACE("driver %s does not support rmv\n",
863 dev->device->driver->name);
868 * If jumbo frames are enabled, check that the maximum RX packet
869 * length is supported by the configured device.
871 if (local_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
872 if (dev_conf->rxmode.max_rx_pkt_len >
873 dev_info.max_rx_pktlen) {
874 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
875 " > max valid value %u\n",
877 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
878 (unsigned)dev_info.max_rx_pktlen);
880 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
881 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
882 " < min valid value %u\n",
884 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
885 (unsigned)ETHER_MIN_LEN);
889 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
890 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
891 /* Use default value */
892 dev->data->dev_conf.rxmode.max_rx_pkt_len =
897 * Setup new number of RX/TX queues and reconfigure device.
899 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
901 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
906 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
908 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
910 rte_eth_dev_rx_queue_config(dev, 0);
914 diag = (*dev->dev_ops->dev_configure)(dev);
916 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
918 rte_eth_dev_rx_queue_config(dev, 0);
919 rte_eth_dev_tx_queue_config(dev, 0);
923 /* Initialize Rx profiling if enabled at compilation time. */
924 diag = __rte_eth_profile_rx_init(port_id, dev);
926 RTE_PMD_DEBUG_TRACE("port%d __rte_eth_profile_rx_init = %d\n",
928 rte_eth_dev_rx_queue_config(dev, 0);
929 rte_eth_dev_tx_queue_config(dev, 0);
937 _rte_eth_dev_reset(struct rte_eth_dev *dev)
939 if (dev->data->dev_started) {
941 "port %d must be stopped to allow reset\n",
946 rte_eth_dev_rx_queue_config(dev, 0);
947 rte_eth_dev_tx_queue_config(dev, 0);
949 memset(&dev->data->dev_conf, 0, sizeof(dev->data->dev_conf));
953 rte_eth_dev_config_restore(uint16_t port_id)
955 struct rte_eth_dev *dev;
956 struct rte_eth_dev_info dev_info;
957 struct ether_addr *addr;
962 dev = &rte_eth_devices[port_id];
964 rte_eth_dev_info_get(port_id, &dev_info);
966 /* replay MAC address configuration including default MAC */
967 addr = &dev->data->mac_addrs[0];
968 if (*dev->dev_ops->mac_addr_set != NULL)
969 (*dev->dev_ops->mac_addr_set)(dev, addr);
970 else if (*dev->dev_ops->mac_addr_add != NULL)
971 (*dev->dev_ops->mac_addr_add)(dev, addr, 0, pool);
973 if (*dev->dev_ops->mac_addr_add != NULL) {
974 for (i = 1; i < dev_info.max_mac_addrs; i++) {
975 addr = &dev->data->mac_addrs[i];
977 /* skip zero address */
978 if (is_zero_ether_addr(addr))
982 pool_mask = dev->data->mac_pool_sel[i];
985 if (pool_mask & 1ULL)
986 (*dev->dev_ops->mac_addr_add)(dev,
994 /* replay promiscuous configuration */
995 if (rte_eth_promiscuous_get(port_id) == 1)
996 rte_eth_promiscuous_enable(port_id);
997 else if (rte_eth_promiscuous_get(port_id) == 0)
998 rte_eth_promiscuous_disable(port_id);
1000 /* replay all multicast configuration */
1001 if (rte_eth_allmulticast_get(port_id) == 1)
1002 rte_eth_allmulticast_enable(port_id);
1003 else if (rte_eth_allmulticast_get(port_id) == 0)
1004 rte_eth_allmulticast_disable(port_id);
1008 rte_eth_dev_start(uint16_t port_id)
1010 struct rte_eth_dev *dev;
1013 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1015 dev = &rte_eth_devices[port_id];
1017 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1019 if (dev->data->dev_started != 0) {
1020 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu16
1021 " already started\n",
1026 diag = (*dev->dev_ops->dev_start)(dev);
1028 dev->data->dev_started = 1;
1032 rte_eth_dev_config_restore(port_id);
1034 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1035 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1036 (*dev->dev_ops->link_update)(dev, 0);
1042 rte_eth_dev_stop(uint16_t port_id)
1044 struct rte_eth_dev *dev;
1046 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1047 dev = &rte_eth_devices[port_id];
1049 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1051 if (dev->data->dev_started == 0) {
1052 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu16
1053 " already stopped\n",
1058 dev->data->dev_started = 0;
1059 (*dev->dev_ops->dev_stop)(dev);
1063 rte_eth_dev_set_link_up(uint16_t port_id)
1065 struct rte_eth_dev *dev;
1067 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1069 dev = &rte_eth_devices[port_id];
1071 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1072 return (*dev->dev_ops->dev_set_link_up)(dev);
1076 rte_eth_dev_set_link_down(uint16_t port_id)
1078 struct rte_eth_dev *dev;
1080 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1082 dev = &rte_eth_devices[port_id];
1084 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1085 return (*dev->dev_ops->dev_set_link_down)(dev);
1089 rte_eth_dev_close(uint16_t port_id)
1091 struct rte_eth_dev *dev;
1093 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1094 dev = &rte_eth_devices[port_id];
1096 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1097 dev->data->dev_started = 0;
1098 (*dev->dev_ops->dev_close)(dev);
1100 dev->data->nb_rx_queues = 0;
1101 rte_free(dev->data->rx_queues);
1102 dev->data->rx_queues = NULL;
1103 dev->data->nb_tx_queues = 0;
1104 rte_free(dev->data->tx_queues);
1105 dev->data->tx_queues = NULL;
1109 rte_eth_dev_reset(uint16_t port_id)
1111 struct rte_eth_dev *dev;
1114 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1115 dev = &rte_eth_devices[port_id];
1117 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_reset, -ENOTSUP);
1119 rte_eth_dev_stop(port_id);
1120 ret = dev->dev_ops->dev_reset(dev);
1126 rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
1127 uint16_t nb_rx_desc, unsigned int socket_id,
1128 const struct rte_eth_rxconf *rx_conf,
1129 struct rte_mempool *mp)
1132 uint32_t mbp_buf_size;
1133 struct rte_eth_dev *dev;
1134 struct rte_eth_dev_info dev_info;
1135 struct rte_eth_rxconf local_conf;
1138 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1140 dev = &rte_eth_devices[port_id];
1141 if (rx_queue_id >= dev->data->nb_rx_queues) {
1142 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1146 if (dev->data->dev_started) {
1147 RTE_PMD_DEBUG_TRACE(
1148 "port %d must be stopped to allow configuration\n", port_id);
1152 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1153 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1156 * Check the size of the mbuf data buffer.
1157 * This value must be provided in the private data of the memory pool.
1158 * First check that the memory pool has a valid private data.
1160 rte_eth_dev_info_get(port_id, &dev_info);
1161 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1162 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1163 mp->name, (int) mp->private_data_size,
1164 (int) sizeof(struct rte_pktmbuf_pool_private));
1167 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1169 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1170 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1171 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1175 (int)(RTE_PKTMBUF_HEADROOM +
1176 dev_info.min_rx_bufsize),
1177 (int)RTE_PKTMBUF_HEADROOM,
1178 (int)dev_info.min_rx_bufsize);
1182 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1183 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1184 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1186 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1187 "should be: <= %hu, = %hu, and a product of %hu\n",
1189 dev_info.rx_desc_lim.nb_max,
1190 dev_info.rx_desc_lim.nb_min,
1191 dev_info.rx_desc_lim.nb_align);
1195 rxq = dev->data->rx_queues;
1196 if (rxq[rx_queue_id]) {
1197 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release,
1199 (*dev->dev_ops->rx_queue_release)(rxq[rx_queue_id]);
1200 rxq[rx_queue_id] = NULL;
1203 if (rx_conf == NULL)
1204 rx_conf = &dev_info.default_rxconf;
1206 local_conf = *rx_conf;
1207 if (dev->data->dev_conf.rxmode.ignore_offload_bitfield == 0) {
1209 * Reflect port offloads to queue offloads in order for
1210 * offloads to not be discarded.
1212 rte_eth_convert_rx_offload_bitfield(&dev->data->dev_conf.rxmode,
1213 &local_conf.offloads);
1216 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1217 socket_id, &local_conf, mp);
1219 if (!dev->data->min_rx_buf_size ||
1220 dev->data->min_rx_buf_size > mbp_buf_size)
1221 dev->data->min_rx_buf_size = mbp_buf_size;
1228 * A conversion function from txq_flags API.
1231 rte_eth_convert_txq_flags(const uint32_t txq_flags, uint64_t *tx_offloads)
1233 uint64_t offloads = 0;
1235 if (!(txq_flags & ETH_TXQ_FLAGS_NOMULTSEGS))
1236 offloads |= DEV_TX_OFFLOAD_MULTI_SEGS;
1237 if (!(txq_flags & ETH_TXQ_FLAGS_NOVLANOFFL))
1238 offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
1239 if (!(txq_flags & ETH_TXQ_FLAGS_NOXSUMSCTP))
1240 offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
1241 if (!(txq_flags & ETH_TXQ_FLAGS_NOXSUMUDP))
1242 offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
1243 if (!(txq_flags & ETH_TXQ_FLAGS_NOXSUMTCP))
1244 offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
1245 if ((txq_flags & ETH_TXQ_FLAGS_NOREFCOUNT) &&
1246 (txq_flags & ETH_TXQ_FLAGS_NOMULTMEMP))
1247 offloads |= DEV_TX_OFFLOAD_MBUF_FAST_FREE;
1249 *tx_offloads = offloads;
1253 * A conversion function from offloads API.
1256 rte_eth_convert_txq_offloads(const uint64_t tx_offloads, uint32_t *txq_flags)
1260 if (!(tx_offloads & DEV_TX_OFFLOAD_MULTI_SEGS))
1261 flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
1262 if (!(tx_offloads & DEV_TX_OFFLOAD_VLAN_INSERT))
1263 flags |= ETH_TXQ_FLAGS_NOVLANOFFL;
1264 if (!(tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM))
1265 flags |= ETH_TXQ_FLAGS_NOXSUMSCTP;
1266 if (!(tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM))
1267 flags |= ETH_TXQ_FLAGS_NOXSUMUDP;
1268 if (!(tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM))
1269 flags |= ETH_TXQ_FLAGS_NOXSUMTCP;
1270 if (tx_offloads & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
1271 flags |= (ETH_TXQ_FLAGS_NOREFCOUNT | ETH_TXQ_FLAGS_NOMULTMEMP);
1277 rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
1278 uint16_t nb_tx_desc, unsigned int socket_id,
1279 const struct rte_eth_txconf *tx_conf)
1281 struct rte_eth_dev *dev;
1282 struct rte_eth_dev_info dev_info;
1283 struct rte_eth_txconf local_conf;
1286 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1288 dev = &rte_eth_devices[port_id];
1289 if (tx_queue_id >= dev->data->nb_tx_queues) {
1290 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1294 if (dev->data->dev_started) {
1295 RTE_PMD_DEBUG_TRACE(
1296 "port %d must be stopped to allow configuration\n", port_id);
1300 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1301 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1303 rte_eth_dev_info_get(port_id, &dev_info);
1305 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1306 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1307 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1308 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1309 "should be: <= %hu, = %hu, and a product of %hu\n",
1311 dev_info.tx_desc_lim.nb_max,
1312 dev_info.tx_desc_lim.nb_min,
1313 dev_info.tx_desc_lim.nb_align);
1317 txq = dev->data->tx_queues;
1318 if (txq[tx_queue_id]) {
1319 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release,
1321 (*dev->dev_ops->tx_queue_release)(txq[tx_queue_id]);
1322 txq[tx_queue_id] = NULL;
1325 if (tx_conf == NULL)
1326 tx_conf = &dev_info.default_txconf;
1329 * Convert between the offloads API to enable PMDs to support
1332 local_conf = *tx_conf;
1333 if (tx_conf->txq_flags & ETH_TXQ_FLAGS_IGNORE) {
1334 rte_eth_convert_txq_offloads(tx_conf->offloads,
1335 &local_conf.txq_flags);
1336 /* Keep the ignore flag. */
1337 local_conf.txq_flags |= ETH_TXQ_FLAGS_IGNORE;
1339 rte_eth_convert_txq_flags(tx_conf->txq_flags,
1340 &local_conf.offloads);
1343 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1344 socket_id, &local_conf);
1348 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
1349 void *userdata __rte_unused)
1353 for (i = 0; i < unsent; i++)
1354 rte_pktmbuf_free(pkts[i]);
1358 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
1361 uint64_t *count = userdata;
1364 for (i = 0; i < unsent; i++)
1365 rte_pktmbuf_free(pkts[i]);
1371 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
1372 buffer_tx_error_fn cbfn, void *userdata)
1374 buffer->error_callback = cbfn;
1375 buffer->error_userdata = userdata;
1380 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
1387 buffer->size = size;
1388 if (buffer->error_callback == NULL) {
1389 ret = rte_eth_tx_buffer_set_err_callback(
1390 buffer, rte_eth_tx_buffer_drop_callback, NULL);
1397 rte_eth_tx_done_cleanup(uint16_t port_id, uint16_t queue_id, uint32_t free_cnt)
1399 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1401 /* Validate Input Data. Bail if not valid or not supported. */
1402 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1403 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_done_cleanup, -ENOTSUP);
1405 /* Call driver to free pending mbufs. */
1406 return (*dev->dev_ops->tx_done_cleanup)(dev->data->tx_queues[queue_id],
1411 rte_eth_promiscuous_enable(uint16_t port_id)
1413 struct rte_eth_dev *dev;
1415 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1416 dev = &rte_eth_devices[port_id];
1418 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1419 (*dev->dev_ops->promiscuous_enable)(dev);
1420 dev->data->promiscuous = 1;
1424 rte_eth_promiscuous_disable(uint16_t port_id)
1426 struct rte_eth_dev *dev;
1428 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1429 dev = &rte_eth_devices[port_id];
1431 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1432 dev->data->promiscuous = 0;
1433 (*dev->dev_ops->promiscuous_disable)(dev);
1437 rte_eth_promiscuous_get(uint16_t port_id)
1439 struct rte_eth_dev *dev;
1441 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1443 dev = &rte_eth_devices[port_id];
1444 return dev->data->promiscuous;
1448 rte_eth_allmulticast_enable(uint16_t port_id)
1450 struct rte_eth_dev *dev;
1452 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1453 dev = &rte_eth_devices[port_id];
1455 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1456 (*dev->dev_ops->allmulticast_enable)(dev);
1457 dev->data->all_multicast = 1;
1461 rte_eth_allmulticast_disable(uint16_t port_id)
1463 struct rte_eth_dev *dev;
1465 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1466 dev = &rte_eth_devices[port_id];
1468 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1469 dev->data->all_multicast = 0;
1470 (*dev->dev_ops->allmulticast_disable)(dev);
1474 rte_eth_allmulticast_get(uint16_t port_id)
1476 struct rte_eth_dev *dev;
1478 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1480 dev = &rte_eth_devices[port_id];
1481 return dev->data->all_multicast;
1485 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1486 struct rte_eth_link *link)
1488 struct rte_eth_link *dst = link;
1489 struct rte_eth_link *src = &(dev->data->dev_link);
1491 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1492 *(uint64_t *)src) == 0)
1499 rte_eth_link_get(uint16_t port_id, struct rte_eth_link *eth_link)
1501 struct rte_eth_dev *dev;
1503 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1504 dev = &rte_eth_devices[port_id];
1506 if (dev->data->dev_conf.intr_conf.lsc != 0)
1507 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1509 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1510 (*dev->dev_ops->link_update)(dev, 1);
1511 *eth_link = dev->data->dev_link;
1516 rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link)
1518 struct rte_eth_dev *dev;
1520 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1521 dev = &rte_eth_devices[port_id];
1523 if (dev->data->dev_conf.intr_conf.lsc != 0)
1524 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1526 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1527 (*dev->dev_ops->link_update)(dev, 0);
1528 *eth_link = dev->data->dev_link;
1533 rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats)
1535 struct rte_eth_dev *dev;
1537 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1539 dev = &rte_eth_devices[port_id];
1540 memset(stats, 0, sizeof(*stats));
1542 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1543 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1544 return (*dev->dev_ops->stats_get)(dev, stats);
1548 rte_eth_stats_reset(uint16_t port_id)
1550 struct rte_eth_dev *dev;
1552 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1553 dev = &rte_eth_devices[port_id];
1555 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_reset, -ENOTSUP);
1556 (*dev->dev_ops->stats_reset)(dev);
1557 dev->data->rx_mbuf_alloc_failed = 0;
1563 get_xstats_basic_count(struct rte_eth_dev *dev)
1565 uint16_t nb_rxqs, nb_txqs;
1568 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1569 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1571 count = RTE_NB_STATS;
1572 count += nb_rxqs * RTE_NB_RXQ_STATS;
1573 count += nb_txqs * RTE_NB_TXQ_STATS;
1579 get_xstats_count(uint16_t port_id)
1581 struct rte_eth_dev *dev;
1584 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1585 dev = &rte_eth_devices[port_id];
1586 if (dev->dev_ops->xstats_get_names_by_id != NULL) {
1587 count = (*dev->dev_ops->xstats_get_names_by_id)(dev, NULL,
1592 if (dev->dev_ops->xstats_get_names != NULL) {
1593 count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0);
1600 count += get_xstats_basic_count(dev);
1606 rte_eth_xstats_get_id_by_name(uint16_t port_id, const char *xstat_name,
1609 int cnt_xstats, idx_xstat;
1611 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1614 RTE_PMD_DEBUG_TRACE("Error: id pointer is NULL\n");
1619 RTE_PMD_DEBUG_TRACE("Error: xstat_name pointer is NULL\n");
1624 cnt_xstats = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
1625 if (cnt_xstats < 0) {
1626 RTE_PMD_DEBUG_TRACE("Error: Cannot get count of xstats\n");
1630 /* Get id-name lookup table */
1631 struct rte_eth_xstat_name xstats_names[cnt_xstats];
1633 if (cnt_xstats != rte_eth_xstats_get_names_by_id(
1634 port_id, xstats_names, cnt_xstats, NULL)) {
1635 RTE_PMD_DEBUG_TRACE("Error: Cannot get xstats lookup\n");
1639 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
1640 if (!strcmp(xstats_names[idx_xstat].name, xstat_name)) {
1649 /* retrieve ethdev extended statistics names */
1651 rte_eth_xstats_get_names_by_id(uint16_t port_id,
1652 struct rte_eth_xstat_name *xstats_names, unsigned int size,
1655 struct rte_eth_xstat_name *xstats_names_copy;
1656 unsigned int no_basic_stat_requested = 1;
1657 unsigned int expected_entries;
1658 struct rte_eth_dev *dev;
1662 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1663 dev = &rte_eth_devices[port_id];
1665 ret = get_xstats_count(port_id);
1668 expected_entries = (unsigned int)ret;
1670 /* Return max number of stats if no ids given */
1673 return expected_entries;
1674 else if (xstats_names && size < expected_entries)
1675 return expected_entries;
1678 if (ids && !xstats_names)
1681 if (ids && dev->dev_ops->xstats_get_names_by_id != NULL && size > 0) {
1682 unsigned int basic_count = get_xstats_basic_count(dev);
1683 uint64_t ids_copy[size];
1685 for (i = 0; i < size; i++) {
1686 if (ids[i] < basic_count) {
1687 no_basic_stat_requested = 0;
1692 * Convert ids to xstats ids that PMD knows.
1693 * ids known by user are basic + extended stats.
1695 ids_copy[i] = ids[i] - basic_count;
1698 if (no_basic_stat_requested)
1699 return (*dev->dev_ops->xstats_get_names_by_id)(dev,
1700 xstats_names, ids_copy, size);
1703 /* Retrieve all stats */
1705 int num_stats = rte_eth_xstats_get_names(port_id, xstats_names,
1707 if (num_stats < 0 || num_stats > (int)expected_entries)
1710 return expected_entries;
1713 xstats_names_copy = calloc(expected_entries,
1714 sizeof(struct rte_eth_xstat_name));
1716 if (!xstats_names_copy) {
1717 RTE_PMD_DEBUG_TRACE("ERROR: can't allocate memory");
1721 /* Fill xstats_names_copy structure */
1722 rte_eth_xstats_get_names(port_id, xstats_names_copy, expected_entries);
1725 for (i = 0; i < size; i++) {
1726 if (ids[i] >= expected_entries) {
1727 RTE_PMD_DEBUG_TRACE("ERROR: id value isn't valid\n");
1728 free(xstats_names_copy);
1731 xstats_names[i] = xstats_names_copy[ids[i]];
1734 free(xstats_names_copy);
1739 rte_eth_xstats_get_names(uint16_t port_id,
1740 struct rte_eth_xstat_name *xstats_names,
1743 struct rte_eth_dev *dev;
1744 int cnt_used_entries;
1745 int cnt_expected_entries;
1746 int cnt_driver_entries;
1747 uint32_t idx, id_queue;
1750 cnt_expected_entries = get_xstats_count(port_id);
1751 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1752 (int)size < cnt_expected_entries)
1753 return cnt_expected_entries;
1755 /* port_id checked in get_xstats_count() */
1756 dev = &rte_eth_devices[port_id];
1757 cnt_used_entries = 0;
1759 for (idx = 0; idx < RTE_NB_STATS; idx++) {
1760 snprintf(xstats_names[cnt_used_entries].name,
1761 sizeof(xstats_names[0].name),
1762 "%s", rte_stats_strings[idx].name);
1765 num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1766 for (id_queue = 0; id_queue < num_q; id_queue++) {
1767 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1768 snprintf(xstats_names[cnt_used_entries].name,
1769 sizeof(xstats_names[0].name),
1771 id_queue, rte_rxq_stats_strings[idx].name);
1776 num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1777 for (id_queue = 0; id_queue < num_q; id_queue++) {
1778 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
1779 snprintf(xstats_names[cnt_used_entries].name,
1780 sizeof(xstats_names[0].name),
1782 id_queue, rte_txq_stats_strings[idx].name);
1787 if (dev->dev_ops->xstats_get_names != NULL) {
1788 /* If there are any driver-specific xstats, append them
1791 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
1793 xstats_names + cnt_used_entries,
1794 size - cnt_used_entries);
1795 if (cnt_driver_entries < 0)
1796 return cnt_driver_entries;
1797 cnt_used_entries += cnt_driver_entries;
1800 return cnt_used_entries;
1803 /* retrieve ethdev extended statistics */
1805 rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
1806 uint64_t *values, unsigned int size)
1808 unsigned int no_basic_stat_requested = 1;
1809 unsigned int num_xstats_filled;
1810 uint16_t expected_entries;
1811 struct rte_eth_dev *dev;
1815 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1816 expected_entries = get_xstats_count(port_id);
1817 struct rte_eth_xstat xstats[expected_entries];
1818 dev = &rte_eth_devices[port_id];
1820 /* Return max number of stats if no ids given */
1823 return expected_entries;
1824 else if (values && size < expected_entries)
1825 return expected_entries;
1831 if (ids && dev->dev_ops->xstats_get_by_id != NULL && size) {
1832 unsigned int basic_count = get_xstats_basic_count(dev);
1833 uint64_t ids_copy[size];
1835 for (i = 0; i < size; i++) {
1836 if (ids[i] < basic_count) {
1837 no_basic_stat_requested = 0;
1842 * Convert ids to xstats ids that PMD knows.
1843 * ids known by user are basic + extended stats.
1845 ids_copy[i] = ids[i] - basic_count;
1848 if (no_basic_stat_requested)
1849 return (*dev->dev_ops->xstats_get_by_id)(dev, ids_copy,
1853 /* Fill the xstats structure */
1854 ret = rte_eth_xstats_get(port_id, xstats, expected_entries);
1857 num_xstats_filled = (unsigned int)ret;
1859 /* Return all stats */
1861 for (i = 0; i < num_xstats_filled; i++)
1862 values[i] = xstats[i].value;
1863 return expected_entries;
1867 for (i = 0; i < size; i++) {
1868 if (ids[i] >= expected_entries) {
1869 RTE_PMD_DEBUG_TRACE("ERROR: id value isn't valid\n");
1872 values[i] = xstats[ids[i]].value;
1878 rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats,
1881 struct rte_eth_stats eth_stats;
1882 struct rte_eth_dev *dev;
1883 unsigned int count = 0, i, q;
1884 signed int xcount = 0;
1885 uint64_t val, *stats_ptr;
1886 uint16_t nb_rxqs, nb_txqs;
1888 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1890 dev = &rte_eth_devices[port_id];
1892 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1893 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1895 /* Return generic statistics */
1896 count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
1897 (nb_txqs * RTE_NB_TXQ_STATS);
1899 /* implemented by the driver */
1900 if (dev->dev_ops->xstats_get != NULL) {
1901 /* Retrieve the xstats from the driver at the end of the
1904 xcount = (*dev->dev_ops->xstats_get)(dev,
1905 xstats ? xstats + count : NULL,
1906 (n > count) ? n - count : 0);
1912 if (n < count + xcount || xstats == NULL)
1913 return count + xcount;
1915 /* now fill the xstats structure */
1917 rte_eth_stats_get(port_id, ð_stats);
1920 for (i = 0; i < RTE_NB_STATS; i++) {
1921 stats_ptr = RTE_PTR_ADD(ð_stats,
1922 rte_stats_strings[i].offset);
1924 xstats[count++].value = val;
1928 for (q = 0; q < nb_rxqs; q++) {
1929 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1930 stats_ptr = RTE_PTR_ADD(ð_stats,
1931 rte_rxq_stats_strings[i].offset +
1932 q * sizeof(uint64_t));
1934 xstats[count++].value = val;
1939 for (q = 0; q < nb_txqs; q++) {
1940 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1941 stats_ptr = RTE_PTR_ADD(ð_stats,
1942 rte_txq_stats_strings[i].offset +
1943 q * sizeof(uint64_t));
1945 xstats[count++].value = val;
1949 for (i = 0; i < count; i++)
1951 /* add an offset to driver-specific stats */
1952 for ( ; i < count + xcount; i++)
1953 xstats[i].id += count;
1955 return count + xcount;
1958 /* reset ethdev extended statistics */
1960 rte_eth_xstats_reset(uint16_t port_id)
1962 struct rte_eth_dev *dev;
1964 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1965 dev = &rte_eth_devices[port_id];
1967 /* implemented by the driver */
1968 if (dev->dev_ops->xstats_reset != NULL) {
1969 (*dev->dev_ops->xstats_reset)(dev);
1973 /* fallback to default */
1974 rte_eth_stats_reset(port_id);
1978 set_queue_stats_mapping(uint16_t port_id, uint16_t queue_id, uint8_t stat_idx,
1981 struct rte_eth_dev *dev;
1983 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1985 dev = &rte_eth_devices[port_id];
1987 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1988 return (*dev->dev_ops->queue_stats_mapping_set)
1989 (dev, queue_id, stat_idx, is_rx);
1994 rte_eth_dev_set_tx_queue_stats_mapping(uint16_t port_id, uint16_t tx_queue_id,
1997 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
2003 rte_eth_dev_set_rx_queue_stats_mapping(uint16_t port_id, uint16_t rx_queue_id,
2006 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
2011 rte_eth_dev_fw_version_get(uint16_t port_id, char *fw_version, size_t fw_size)
2013 struct rte_eth_dev *dev;
2015 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2016 dev = &rte_eth_devices[port_id];
2018 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP);
2019 return (*dev->dev_ops->fw_version_get)(dev, fw_version, fw_size);
2023 rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)
2025 struct rte_eth_dev *dev;
2026 const struct rte_eth_desc_lim lim = {
2027 .nb_max = UINT16_MAX,
2032 RTE_ETH_VALID_PORTID_OR_RET(port_id);
2033 dev = &rte_eth_devices[port_id];
2035 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
2036 dev_info->rx_desc_lim = lim;
2037 dev_info->tx_desc_lim = lim;
2039 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
2040 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
2041 dev_info->driver_name = dev->device->driver->name;
2042 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
2043 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
2047 rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
2048 uint32_t *ptypes, int num)
2051 struct rte_eth_dev *dev;
2052 const uint32_t *all_ptypes;
2054 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2055 dev = &rte_eth_devices[port_id];
2056 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
2057 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
2062 for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
2063 if (all_ptypes[i] & ptype_mask) {
2065 ptypes[j] = all_ptypes[i];
2073 rte_eth_macaddr_get(uint16_t port_id, struct ether_addr *mac_addr)
2075 struct rte_eth_dev *dev;
2077 RTE_ETH_VALID_PORTID_OR_RET(port_id);
2078 dev = &rte_eth_devices[port_id];
2079 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
2084 rte_eth_dev_get_mtu(uint16_t port_id, uint16_t *mtu)
2086 struct rte_eth_dev *dev;
2088 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2090 dev = &rte_eth_devices[port_id];
2091 *mtu = dev->data->mtu;
2096 rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
2099 struct rte_eth_dev *dev;
2101 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2102 dev = &rte_eth_devices[port_id];
2103 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
2105 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
2107 dev->data->mtu = mtu;
2113 rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on)
2115 struct rte_eth_dev *dev;
2118 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2119 dev = &rte_eth_devices[port_id];
2120 if (!(dev->data->dev_conf.rxmode.offloads &
2121 DEV_RX_OFFLOAD_VLAN_FILTER)) {
2122 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
2126 if (vlan_id > 4095) {
2127 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
2128 port_id, (unsigned) vlan_id);
2131 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
2133 ret = (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
2135 struct rte_vlan_filter_conf *vfc;
2139 vfc = &dev->data->vlan_filter_conf;
2140 vidx = vlan_id / 64;
2141 vbit = vlan_id % 64;
2144 vfc->ids[vidx] |= UINT64_C(1) << vbit;
2146 vfc->ids[vidx] &= ~(UINT64_C(1) << vbit);
2153 rte_eth_dev_set_vlan_strip_on_queue(uint16_t port_id, uint16_t rx_queue_id,
2156 struct rte_eth_dev *dev;
2158 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2159 dev = &rte_eth_devices[port_id];
2160 if (rx_queue_id >= dev->data->nb_rx_queues) {
2161 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
2165 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
2166 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
2172 rte_eth_dev_set_vlan_ether_type(uint16_t port_id,
2173 enum rte_vlan_type vlan_type,
2176 struct rte_eth_dev *dev;
2178 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2179 dev = &rte_eth_devices[port_id];
2180 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
2182 return (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type, tpid);
2186 rte_eth_dev_set_vlan_offload(uint16_t port_id, int offload_mask)
2188 struct rte_eth_dev *dev;
2192 uint64_t orig_offloads;
2194 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2195 dev = &rte_eth_devices[port_id];
2197 /* save original values in case of failure */
2198 orig_offloads = dev->data->dev_conf.rxmode.offloads;
2200 /*check which option changed by application*/
2201 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
2202 org = !!(dev->data->dev_conf.rxmode.offloads &
2203 DEV_RX_OFFLOAD_VLAN_STRIP);
2206 dev->data->dev_conf.rxmode.offloads |=
2207 DEV_RX_OFFLOAD_VLAN_STRIP;
2209 dev->data->dev_conf.rxmode.offloads &=
2210 ~DEV_RX_OFFLOAD_VLAN_STRIP;
2211 mask |= ETH_VLAN_STRIP_MASK;
2214 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
2215 org = !!(dev->data->dev_conf.rxmode.offloads &
2216 DEV_RX_OFFLOAD_VLAN_FILTER);
2219 dev->data->dev_conf.rxmode.offloads |=
2220 DEV_RX_OFFLOAD_VLAN_FILTER;
2222 dev->data->dev_conf.rxmode.offloads &=
2223 ~DEV_RX_OFFLOAD_VLAN_FILTER;
2224 mask |= ETH_VLAN_FILTER_MASK;
2227 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
2228 org = !!(dev->data->dev_conf.rxmode.offloads &
2229 DEV_RX_OFFLOAD_VLAN_EXTEND);
2232 dev->data->dev_conf.rxmode.offloads |=
2233 DEV_RX_OFFLOAD_VLAN_EXTEND;
2235 dev->data->dev_conf.rxmode.offloads &=
2236 ~DEV_RX_OFFLOAD_VLAN_EXTEND;
2237 mask |= ETH_VLAN_EXTEND_MASK;
2244 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
2247 * Convert to the offload bitfield API just in case the underlying PMD
2248 * still supporting it.
2250 rte_eth_convert_rx_offloads(dev->data->dev_conf.rxmode.offloads,
2251 &dev->data->dev_conf.rxmode);
2252 ret = (*dev->dev_ops->vlan_offload_set)(dev, mask);
2254 /* hit an error restore original values */
2255 dev->data->dev_conf.rxmode.offloads = orig_offloads;
2256 rte_eth_convert_rx_offloads(dev->data->dev_conf.rxmode.offloads,
2257 &dev->data->dev_conf.rxmode);
2264 rte_eth_dev_get_vlan_offload(uint16_t port_id)
2266 struct rte_eth_dev *dev;
2269 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2270 dev = &rte_eth_devices[port_id];
2272 if (dev->data->dev_conf.rxmode.offloads &
2273 DEV_RX_OFFLOAD_VLAN_STRIP)
2274 ret |= ETH_VLAN_STRIP_OFFLOAD;
2276 if (dev->data->dev_conf.rxmode.offloads &
2277 DEV_RX_OFFLOAD_VLAN_FILTER)
2278 ret |= ETH_VLAN_FILTER_OFFLOAD;
2280 if (dev->data->dev_conf.rxmode.offloads &
2281 DEV_RX_OFFLOAD_VLAN_EXTEND)
2282 ret |= ETH_VLAN_EXTEND_OFFLOAD;
2288 rte_eth_dev_set_vlan_pvid(uint16_t port_id, uint16_t pvid, int on)
2290 struct rte_eth_dev *dev;
2292 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2293 dev = &rte_eth_devices[port_id];
2294 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
2295 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
2301 rte_eth_dev_flow_ctrl_get(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
2303 struct rte_eth_dev *dev;
2305 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2306 dev = &rte_eth_devices[port_id];
2307 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2308 memset(fc_conf, 0, sizeof(*fc_conf));
2309 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
2313 rte_eth_dev_flow_ctrl_set(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
2315 struct rte_eth_dev *dev;
2317 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2318 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2319 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2323 dev = &rte_eth_devices[port_id];
2324 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2325 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
2329 rte_eth_dev_priority_flow_ctrl_set(uint16_t port_id,
2330 struct rte_eth_pfc_conf *pfc_conf)
2332 struct rte_eth_dev *dev;
2334 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2335 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2336 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2340 dev = &rte_eth_devices[port_id];
2341 /* High water, low water validation are device specific */
2342 if (*dev->dev_ops->priority_flow_ctrl_set)
2343 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
2348 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2356 num = (reta_size + RTE_RETA_GROUP_SIZE - 1) / RTE_RETA_GROUP_SIZE;
2357 for (i = 0; i < num; i++) {
2358 if (reta_conf[i].mask)
2366 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2370 uint16_t i, idx, shift;
2376 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
2380 for (i = 0; i < reta_size; i++) {
2381 idx = i / RTE_RETA_GROUP_SIZE;
2382 shift = i % RTE_RETA_GROUP_SIZE;
2383 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2384 (reta_conf[idx].reta[shift] >= max_rxq)) {
2385 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2386 "the maximum rxq index: %u\n", idx, shift,
2387 reta_conf[idx].reta[shift], max_rxq);
2396 rte_eth_dev_rss_reta_update(uint16_t port_id,
2397 struct rte_eth_rss_reta_entry64 *reta_conf,
2400 struct rte_eth_dev *dev;
2403 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2404 /* Check mask bits */
2405 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2409 dev = &rte_eth_devices[port_id];
2411 /* Check entry value */
2412 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2413 dev->data->nb_rx_queues);
2417 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2418 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2422 rte_eth_dev_rss_reta_query(uint16_t port_id,
2423 struct rte_eth_rss_reta_entry64 *reta_conf,
2426 struct rte_eth_dev *dev;
2429 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2431 /* Check mask bits */
2432 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2436 dev = &rte_eth_devices[port_id];
2437 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2438 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2442 rte_eth_dev_rss_hash_update(uint16_t port_id,
2443 struct rte_eth_rss_conf *rss_conf)
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->rss_hash_update, -ENOTSUP);
2450 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2454 rte_eth_dev_rss_hash_conf_get(uint16_t port_id,
2455 struct rte_eth_rss_conf *rss_conf)
2457 struct rte_eth_dev *dev;
2459 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2460 dev = &rte_eth_devices[port_id];
2461 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2462 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2466 rte_eth_dev_udp_tunnel_port_add(uint16_t port_id,
2467 struct rte_eth_udp_tunnel *udp_tunnel)
2469 struct rte_eth_dev *dev;
2471 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2472 if (udp_tunnel == NULL) {
2473 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2477 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2478 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2482 dev = &rte_eth_devices[port_id];
2483 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
2484 return (*dev->dev_ops->udp_tunnel_port_add)(dev, udp_tunnel);
2488 rte_eth_dev_udp_tunnel_port_delete(uint16_t port_id,
2489 struct rte_eth_udp_tunnel *udp_tunnel)
2491 struct rte_eth_dev *dev;
2493 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2494 dev = &rte_eth_devices[port_id];
2496 if (udp_tunnel == NULL) {
2497 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2501 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2502 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2506 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
2507 return (*dev->dev_ops->udp_tunnel_port_del)(dev, udp_tunnel);
2511 rte_eth_led_on(uint16_t port_id)
2513 struct rte_eth_dev *dev;
2515 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2516 dev = &rte_eth_devices[port_id];
2517 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2518 return (*dev->dev_ops->dev_led_on)(dev);
2522 rte_eth_led_off(uint16_t port_id)
2524 struct rte_eth_dev *dev;
2526 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2527 dev = &rte_eth_devices[port_id];
2528 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2529 return (*dev->dev_ops->dev_led_off)(dev);
2533 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2537 get_mac_addr_index(uint16_t port_id, const struct ether_addr *addr)
2539 struct rte_eth_dev_info dev_info;
2540 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2543 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2544 rte_eth_dev_info_get(port_id, &dev_info);
2546 for (i = 0; i < dev_info.max_mac_addrs; i++)
2547 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2553 static const struct ether_addr null_mac_addr;
2556 rte_eth_dev_mac_addr_add(uint16_t port_id, struct ether_addr *addr,
2559 struct rte_eth_dev *dev;
2564 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2565 dev = &rte_eth_devices[port_id];
2566 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2568 if (is_zero_ether_addr(addr)) {
2569 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2573 if (pool >= ETH_64_POOLS) {
2574 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2578 index = get_mac_addr_index(port_id, addr);
2580 index = get_mac_addr_index(port_id, &null_mac_addr);
2582 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2587 pool_mask = dev->data->mac_pool_sel[index];
2589 /* Check if both MAC address and pool is already there, and do nothing */
2590 if (pool_mask & (1ULL << pool))
2595 ret = (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2598 /* Update address in NIC data structure */
2599 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2601 /* Update pool bitmap in NIC data structure */
2602 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2609 rte_eth_dev_mac_addr_remove(uint16_t port_id, struct ether_addr *addr)
2611 struct rte_eth_dev *dev;
2614 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2615 dev = &rte_eth_devices[port_id];
2616 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2618 index = get_mac_addr_index(port_id, addr);
2620 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2622 } else if (index < 0)
2623 return 0; /* Do nothing if address wasn't found */
2626 (*dev->dev_ops->mac_addr_remove)(dev, index);
2628 /* Update address in NIC data structure */
2629 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2631 /* reset pool bitmap */
2632 dev->data->mac_pool_sel[index] = 0;
2638 rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct ether_addr *addr)
2640 struct rte_eth_dev *dev;
2642 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2644 if (!is_valid_assigned_ether_addr(addr))
2647 dev = &rte_eth_devices[port_id];
2648 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2650 /* Update default address in NIC data structure */
2651 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2653 (*dev->dev_ops->mac_addr_set)(dev, addr);
2660 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2664 get_hash_mac_addr_index(uint16_t port_id, const struct ether_addr *addr)
2666 struct rte_eth_dev_info dev_info;
2667 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2670 rte_eth_dev_info_get(port_id, &dev_info);
2671 if (!dev->data->hash_mac_addrs)
2674 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2675 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2676 ETHER_ADDR_LEN) == 0)
2683 rte_eth_dev_uc_hash_table_set(uint16_t port_id, struct ether_addr *addr,
2688 struct rte_eth_dev *dev;
2690 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2692 dev = &rte_eth_devices[port_id];
2693 if (is_zero_ether_addr(addr)) {
2694 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2699 index = get_hash_mac_addr_index(port_id, addr);
2700 /* Check if it's already there, and do nothing */
2701 if ((index >= 0) && (on))
2706 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2707 "set in UTA\n", port_id);
2711 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2713 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2719 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2720 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2722 /* Update address in NIC data structure */
2724 ether_addr_copy(addr,
2725 &dev->data->hash_mac_addrs[index]);
2727 ether_addr_copy(&null_mac_addr,
2728 &dev->data->hash_mac_addrs[index]);
2735 rte_eth_dev_uc_all_hash_table_set(uint16_t port_id, uint8_t on)
2737 struct rte_eth_dev *dev;
2739 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2741 dev = &rte_eth_devices[port_id];
2743 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2744 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2747 int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx,
2750 struct rte_eth_dev *dev;
2751 struct rte_eth_dev_info dev_info;
2752 struct rte_eth_link link;
2754 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2756 dev = &rte_eth_devices[port_id];
2757 rte_eth_dev_info_get(port_id, &dev_info);
2758 link = dev->data->dev_link;
2760 if (queue_idx > dev_info.max_tx_queues) {
2761 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2762 "invalid queue id=%d\n", port_id, queue_idx);
2766 if (tx_rate > link.link_speed) {
2767 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2768 "bigger than link speed= %d\n",
2769 tx_rate, link.link_speed);
2773 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2774 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2778 rte_eth_mirror_rule_set(uint16_t port_id,
2779 struct rte_eth_mirror_conf *mirror_conf,
2780 uint8_t rule_id, uint8_t on)
2782 struct rte_eth_dev *dev;
2784 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2785 if (mirror_conf->rule_type == 0) {
2786 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2790 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2791 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2796 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2797 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2798 (mirror_conf->pool_mask == 0)) {
2799 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2803 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2804 mirror_conf->vlan.vlan_mask == 0) {
2805 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2809 dev = &rte_eth_devices[port_id];
2810 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2812 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2816 rte_eth_mirror_rule_reset(uint16_t port_id, uint8_t rule_id)
2818 struct rte_eth_dev *dev;
2820 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2822 dev = &rte_eth_devices[port_id];
2823 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2825 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2829 rte_eth_dev_callback_register(uint16_t port_id,
2830 enum rte_eth_event_type event,
2831 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2833 struct rte_eth_dev *dev;
2834 struct rte_eth_dev_callback *user_cb;
2839 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2841 dev = &rte_eth_devices[port_id];
2842 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2844 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2845 if (user_cb->cb_fn == cb_fn &&
2846 user_cb->cb_arg == cb_arg &&
2847 user_cb->event == event) {
2852 /* create a new callback. */
2853 if (user_cb == NULL) {
2854 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2855 sizeof(struct rte_eth_dev_callback), 0);
2856 if (user_cb != NULL) {
2857 user_cb->cb_fn = cb_fn;
2858 user_cb->cb_arg = cb_arg;
2859 user_cb->event = event;
2860 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2864 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2865 return (user_cb == NULL) ? -ENOMEM : 0;
2869 rte_eth_dev_callback_unregister(uint16_t port_id,
2870 enum rte_eth_event_type event,
2871 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2874 struct rte_eth_dev *dev;
2875 struct rte_eth_dev_callback *cb, *next;
2880 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2882 dev = &rte_eth_devices[port_id];
2883 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2886 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2888 next = TAILQ_NEXT(cb, next);
2890 if (cb->cb_fn != cb_fn || cb->event != event ||
2891 (cb->cb_arg != (void *)-1 &&
2892 cb->cb_arg != cb_arg))
2896 * if this callback is not executing right now,
2899 if (cb->active == 0) {
2900 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2907 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2912 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2913 enum rte_eth_event_type event, void *cb_arg, void *ret_param)
2915 struct rte_eth_dev_callback *cb_lst;
2916 struct rte_eth_dev_callback dev_cb;
2919 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2920 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2921 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2926 dev_cb.cb_arg = cb_arg;
2927 if (ret_param != NULL)
2928 dev_cb.ret_param = ret_param;
2930 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2931 rc = dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2932 dev_cb.cb_arg, dev_cb.ret_param);
2933 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2936 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2941 rte_eth_dev_rx_intr_ctl(uint16_t port_id, int epfd, int op, void *data)
2944 struct rte_eth_dev *dev;
2945 struct rte_intr_handle *intr_handle;
2949 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2951 dev = &rte_eth_devices[port_id];
2953 if (!dev->intr_handle) {
2954 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
2958 intr_handle = dev->intr_handle;
2959 if (!intr_handle->intr_vec) {
2960 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2964 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2965 vec = intr_handle->intr_vec[qid];
2966 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2967 if (rc && rc != -EEXIST) {
2968 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2969 " op %d epfd %d vec %u\n",
2970 port_id, qid, op, epfd, vec);
2977 const struct rte_memzone *
2978 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2979 uint16_t queue_id, size_t size, unsigned align,
2982 char z_name[RTE_MEMZONE_NAMESIZE];
2983 const struct rte_memzone *mz;
2985 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2986 dev->device->driver->name, ring_name,
2987 dev->data->port_id, queue_id);
2989 mz = rte_memzone_lookup(z_name);
2993 return rte_memzone_reserve_aligned(z_name, size, socket_id, 0, align);
2997 rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id,
2998 int epfd, int op, void *data)
3001 struct rte_eth_dev *dev;
3002 struct rte_intr_handle *intr_handle;
3005 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3007 dev = &rte_eth_devices[port_id];
3008 if (queue_id >= dev->data->nb_rx_queues) {
3009 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
3013 if (!dev->intr_handle) {
3014 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
3018 intr_handle = dev->intr_handle;
3019 if (!intr_handle->intr_vec) {
3020 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
3024 vec = intr_handle->intr_vec[queue_id];
3025 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
3026 if (rc && rc != -EEXIST) {
3027 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
3028 " op %d epfd %d vec %u\n",
3029 port_id, queue_id, op, epfd, vec);
3037 rte_eth_dev_rx_intr_enable(uint16_t port_id,
3040 struct rte_eth_dev *dev;
3042 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3044 dev = &rte_eth_devices[port_id];
3046 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
3047 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
3051 rte_eth_dev_rx_intr_disable(uint16_t port_id,
3054 struct rte_eth_dev *dev;
3056 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3058 dev = &rte_eth_devices[port_id];
3060 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
3061 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
3066 rte_eth_dev_filter_supported(uint16_t port_id,
3067 enum rte_filter_type filter_type)
3069 struct rte_eth_dev *dev;
3071 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3073 dev = &rte_eth_devices[port_id];
3074 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3075 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3076 RTE_ETH_FILTER_NOP, NULL);
3080 rte_eth_dev_filter_ctrl(uint16_t port_id, enum rte_filter_type filter_type,
3081 enum rte_filter_op filter_op, void *arg)
3083 struct rte_eth_dev *dev;
3085 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3087 dev = &rte_eth_devices[port_id];
3088 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3089 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
3093 rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
3094 rte_rx_callback_fn fn, void *user_param)
3096 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3097 rte_errno = ENOTSUP;
3100 /* check input parameters */
3101 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3102 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3106 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3114 cb->param = user_param;
3116 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3117 /* Add the callbacks in fifo order. */
3118 struct rte_eth_rxtx_callback *tail =
3119 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3122 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3129 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3135 rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
3136 rte_rx_callback_fn fn, void *user_param)
3138 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3139 rte_errno = ENOTSUP;
3142 /* check input parameters */
3143 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3144 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3149 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3157 cb->param = user_param;
3159 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3160 /* Add the callbacks at fisrt position*/
3161 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3163 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3164 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3170 rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
3171 rte_tx_callback_fn fn, void *user_param)
3173 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3174 rte_errno = ENOTSUP;
3177 /* check input parameters */
3178 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3179 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3184 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3192 cb->param = user_param;
3194 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3195 /* Add the callbacks in fifo order. */
3196 struct rte_eth_rxtx_callback *tail =
3197 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3200 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3207 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3213 rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
3214 struct rte_eth_rxtx_callback *user_cb)
3216 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3219 /* Check input parameters. */
3220 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3221 if (user_cb == NULL ||
3222 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
3225 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3226 struct rte_eth_rxtx_callback *cb;
3227 struct rte_eth_rxtx_callback **prev_cb;
3230 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3231 prev_cb = &dev->post_rx_burst_cbs[queue_id];
3232 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3234 if (cb == user_cb) {
3235 /* Remove the user cb from the callback list. */
3236 *prev_cb = cb->next;
3241 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3247 rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
3248 struct rte_eth_rxtx_callback *user_cb)
3250 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3253 /* Check input parameters. */
3254 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3255 if (user_cb == NULL ||
3256 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
3259 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3261 struct rte_eth_rxtx_callback *cb;
3262 struct rte_eth_rxtx_callback **prev_cb;
3264 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3265 prev_cb = &dev->pre_tx_burst_cbs[queue_id];
3266 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3268 if (cb == user_cb) {
3269 /* Remove the user cb from the callback list. */
3270 *prev_cb = cb->next;
3275 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3281 rte_eth_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
3282 struct rte_eth_rxq_info *qinfo)
3284 struct rte_eth_dev *dev;
3286 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3291 dev = &rte_eth_devices[port_id];
3292 if (queue_id >= dev->data->nb_rx_queues) {
3293 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3297 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3299 memset(qinfo, 0, sizeof(*qinfo));
3300 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3305 rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,
3306 struct rte_eth_txq_info *qinfo)
3308 struct rte_eth_dev *dev;
3310 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3315 dev = &rte_eth_devices[port_id];
3316 if (queue_id >= dev->data->nb_tx_queues) {
3317 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3321 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3323 memset(qinfo, 0, sizeof(*qinfo));
3324 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3329 rte_eth_dev_set_mc_addr_list(uint16_t port_id,
3330 struct ether_addr *mc_addr_set,
3331 uint32_t nb_mc_addr)
3333 struct rte_eth_dev *dev;
3335 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3337 dev = &rte_eth_devices[port_id];
3338 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3339 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3343 rte_eth_timesync_enable(uint16_t port_id)
3345 struct rte_eth_dev *dev;
3347 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3348 dev = &rte_eth_devices[port_id];
3350 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3351 return (*dev->dev_ops->timesync_enable)(dev);
3355 rte_eth_timesync_disable(uint16_t port_id)
3357 struct rte_eth_dev *dev;
3359 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3360 dev = &rte_eth_devices[port_id];
3362 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3363 return (*dev->dev_ops->timesync_disable)(dev);
3367 rte_eth_timesync_read_rx_timestamp(uint16_t port_id, struct timespec *timestamp,
3370 struct rte_eth_dev *dev;
3372 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3373 dev = &rte_eth_devices[port_id];
3375 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3376 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3380 rte_eth_timesync_read_tx_timestamp(uint16_t port_id,
3381 struct timespec *timestamp)
3383 struct rte_eth_dev *dev;
3385 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3386 dev = &rte_eth_devices[port_id];
3388 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3389 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3393 rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta)
3395 struct rte_eth_dev *dev;
3397 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3398 dev = &rte_eth_devices[port_id];
3400 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3401 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3405 rte_eth_timesync_read_time(uint16_t port_id, struct timespec *timestamp)
3407 struct rte_eth_dev *dev;
3409 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3410 dev = &rte_eth_devices[port_id];
3412 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3413 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3417 rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *timestamp)
3419 struct rte_eth_dev *dev;
3421 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3422 dev = &rte_eth_devices[port_id];
3424 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3425 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3429 rte_eth_dev_get_reg_info(uint16_t port_id, struct rte_dev_reg_info *info)
3431 struct rte_eth_dev *dev;
3433 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3435 dev = &rte_eth_devices[port_id];
3436 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3437 return (*dev->dev_ops->get_reg)(dev, info);
3441 rte_eth_dev_get_eeprom_length(uint16_t port_id)
3443 struct rte_eth_dev *dev;
3445 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3447 dev = &rte_eth_devices[port_id];
3448 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3449 return (*dev->dev_ops->get_eeprom_length)(dev);
3453 rte_eth_dev_get_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
3455 struct rte_eth_dev *dev;
3457 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3459 dev = &rte_eth_devices[port_id];
3460 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3461 return (*dev->dev_ops->get_eeprom)(dev, info);
3465 rte_eth_dev_set_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
3467 struct rte_eth_dev *dev;
3469 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3471 dev = &rte_eth_devices[port_id];
3472 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3473 return (*dev->dev_ops->set_eeprom)(dev, info);
3477 rte_eth_dev_get_dcb_info(uint16_t port_id,
3478 struct rte_eth_dcb_info *dcb_info)
3480 struct rte_eth_dev *dev;
3482 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3484 dev = &rte_eth_devices[port_id];
3485 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3487 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3488 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3492 rte_eth_dev_l2_tunnel_eth_type_conf(uint16_t port_id,
3493 struct rte_eth_l2_tunnel_conf *l2_tunnel)
3495 struct rte_eth_dev *dev;
3497 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3498 if (l2_tunnel == NULL) {
3499 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3503 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3504 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
3508 dev = &rte_eth_devices[port_id];
3509 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
3511 return (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev, l2_tunnel);
3515 rte_eth_dev_l2_tunnel_offload_set(uint16_t port_id,
3516 struct rte_eth_l2_tunnel_conf *l2_tunnel,
3520 struct rte_eth_dev *dev;
3522 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3524 if (l2_tunnel == NULL) {
3525 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3529 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3530 RTE_PMD_DEBUG_TRACE("Invalid tunnel type.\n");
3535 RTE_PMD_DEBUG_TRACE("Mask should have a value.\n");
3539 dev = &rte_eth_devices[port_id];
3540 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
3542 return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);
3546 rte_eth_dev_adjust_nb_desc(uint16_t *nb_desc,
3547 const struct rte_eth_desc_lim *desc_lim)
3549 if (desc_lim->nb_align != 0)
3550 *nb_desc = RTE_ALIGN_CEIL(*nb_desc, desc_lim->nb_align);
3552 if (desc_lim->nb_max != 0)
3553 *nb_desc = RTE_MIN(*nb_desc, desc_lim->nb_max);
3555 *nb_desc = RTE_MAX(*nb_desc, desc_lim->nb_min);
3559 rte_eth_dev_adjust_nb_rx_tx_desc(uint16_t port_id,
3560 uint16_t *nb_rx_desc,
3561 uint16_t *nb_tx_desc)
3563 struct rte_eth_dev *dev;
3564 struct rte_eth_dev_info dev_info;
3566 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3568 dev = &rte_eth_devices[port_id];
3569 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
3571 rte_eth_dev_info_get(port_id, &dev_info);
3573 if (nb_rx_desc != NULL)
3574 rte_eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim);
3576 if (nb_tx_desc != NULL)
3577 rte_eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim);
3583 rte_eth_dev_pool_ops_supported(uint16_t port_id, const char *pool)
3585 struct rte_eth_dev *dev;
3587 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3592 dev = &rte_eth_devices[port_id];
3594 if (*dev->dev_ops->pool_ops_supported == NULL)
3595 return 1; /* all pools are supported */
3597 return (*dev->dev_ops->pool_ops_supported)(dev, pool);