4 * Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/types.h>
35 #include <sys/queue.h>
44 #include <netinet/in.h>
46 #include <rte_byteorder.h>
48 #include <rte_debug.h>
49 #include <rte_interrupts.h>
51 #include <rte_memory.h>
52 #include <rte_memcpy.h>
53 #include <rte_memzone.h>
54 #include <rte_launch.h>
56 #include <rte_per_lcore.h>
57 #include <rte_lcore.h>
58 #include <rte_atomic.h>
59 #include <rte_branch_prediction.h>
60 #include <rte_common.h>
61 #include <rte_mempool.h>
62 #include <rte_malloc.h>
64 #include <rte_errno.h>
65 #include <rte_spinlock.h>
66 #include <rte_string_fns.h>
68 #include "rte_ether.h"
69 #include "rte_ethdev.h"
70 #include "ethdev_profile.h"
72 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
73 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
74 static struct rte_eth_dev_data *rte_eth_dev_data;
75 static uint8_t eth_dev_last_created_port;
77 /* spinlock for eth device callbacks */
78 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
80 /* spinlock for add/remove rx callbacks */
81 static rte_spinlock_t rte_eth_rx_cb_lock = RTE_SPINLOCK_INITIALIZER;
83 /* spinlock for add/remove tx callbacks */
84 static rte_spinlock_t rte_eth_tx_cb_lock = RTE_SPINLOCK_INITIALIZER;
86 /* store statistics names and its offset in stats structure */
87 struct rte_eth_xstats_name_off {
88 char name[RTE_ETH_XSTATS_NAME_SIZE];
92 static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
93 {"rx_good_packets", offsetof(struct rte_eth_stats, ipackets)},
94 {"tx_good_packets", offsetof(struct rte_eth_stats, opackets)},
95 {"rx_good_bytes", offsetof(struct rte_eth_stats, ibytes)},
96 {"tx_good_bytes", offsetof(struct rte_eth_stats, obytes)},
97 {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
98 {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
99 {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats,
103 #define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
105 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
106 {"packets", offsetof(struct rte_eth_stats, q_ipackets)},
107 {"bytes", offsetof(struct rte_eth_stats, q_ibytes)},
108 {"errors", offsetof(struct rte_eth_stats, q_errors)},
111 #define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) / \
112 sizeof(rte_rxq_stats_strings[0]))
114 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
115 {"packets", offsetof(struct rte_eth_stats, q_opackets)},
116 {"bytes", offsetof(struct rte_eth_stats, q_obytes)},
118 #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) / \
119 sizeof(rte_txq_stats_strings[0]))
123 * The user application callback description.
125 * It contains callback address to be registered by user application,
126 * the pointer to the parameters for callback, and the event type.
128 struct rte_eth_dev_callback {
129 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
130 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
131 void *cb_arg; /**< Parameter for callback */
132 void *ret_param; /**< Return parameter */
133 enum rte_eth_event_type event; /**< Interrupt event type */
134 uint32_t active; /**< Callback is executing */
143 rte_eth_find_next(uint16_t port_id)
145 while (port_id < RTE_MAX_ETHPORTS &&
146 rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED)
149 if (port_id >= RTE_MAX_ETHPORTS)
150 return RTE_MAX_ETHPORTS;
156 rte_eth_dev_data_alloc(void)
158 const unsigned flags = 0;
159 const struct rte_memzone *mz;
161 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
162 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
163 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
164 rte_socket_id(), flags);
166 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
168 rte_panic("Cannot allocate memzone for ethernet port data\n");
170 rte_eth_dev_data = mz->addr;
171 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
172 memset(rte_eth_dev_data, 0,
173 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
177 rte_eth_dev_allocated(const char *name)
181 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
182 if ((rte_eth_devices[i].state == RTE_ETH_DEV_ATTACHED) &&
183 strcmp(rte_eth_devices[i].data->name, name) == 0)
184 return &rte_eth_devices[i];
190 rte_eth_dev_find_free_port(void)
194 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
195 if (rte_eth_devices[i].state == RTE_ETH_DEV_UNUSED)
198 return RTE_MAX_ETHPORTS;
201 static struct rte_eth_dev *
202 eth_dev_get(uint16_t port_id)
204 struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
206 eth_dev->data = &rte_eth_dev_data[port_id];
207 eth_dev->state = RTE_ETH_DEV_ATTACHED;
208 TAILQ_INIT(&(eth_dev->link_intr_cbs));
210 eth_dev_last_created_port = port_id;
216 rte_eth_dev_allocate(const char *name)
219 struct rte_eth_dev *eth_dev;
221 port_id = rte_eth_dev_find_free_port();
222 if (port_id == RTE_MAX_ETHPORTS) {
223 RTE_PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
227 if (rte_eth_dev_data == NULL)
228 rte_eth_dev_data_alloc();
230 if (rte_eth_dev_allocated(name) != NULL) {
231 RTE_PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n",
236 memset(&rte_eth_dev_data[port_id], 0, sizeof(struct rte_eth_dev_data));
237 eth_dev = eth_dev_get(port_id);
238 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
239 eth_dev->data->port_id = port_id;
240 eth_dev->data->mtu = ETHER_MTU;
246 * Attach to a port already registered by the primary process, which
247 * makes sure that the same device would have the same port id both
248 * in the primary and secondary process.
251 rte_eth_dev_attach_secondary(const char *name)
254 struct rte_eth_dev *eth_dev;
256 if (rte_eth_dev_data == NULL)
257 rte_eth_dev_data_alloc();
259 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
260 if (strcmp(rte_eth_dev_data[i].name, name) == 0)
263 if (i == RTE_MAX_ETHPORTS) {
265 "device %s is not driven by the primary process\n",
270 eth_dev = eth_dev_get(i);
271 RTE_ASSERT(eth_dev->data->port_id == i);
277 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
282 eth_dev->state = RTE_ETH_DEV_UNUSED;
287 rte_eth_dev_is_valid_port(uint16_t port_id)
289 if (port_id >= RTE_MAX_ETHPORTS ||
290 (rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
291 rte_eth_devices[port_id].state != RTE_ETH_DEV_DEFERRED))
298 rte_eth_dev_socket_id(uint16_t port_id)
300 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
301 return rte_eth_devices[port_id].data->numa_node;
305 rte_eth_dev_get_sec_ctx(uint8_t port_id)
307 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, NULL);
308 return rte_eth_devices[port_id].security_ctx;
312 rte_eth_dev_count(void)
319 RTE_ETH_FOREACH_DEV(p)
326 rte_eth_dev_get_name_by_port(uint16_t port_id, char *name)
330 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
333 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
337 /* shouldn't check 'rte_eth_devices[i].data',
338 * because it might be overwritten by VDEV PMD */
339 tmp = rte_eth_dev_data[port_id].name;
345 rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
350 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
354 RTE_ETH_FOREACH_DEV(i) {
356 rte_eth_dev_data[i].name, strlen(name))) {
367 rte_eth_dev_is_detachable(uint16_t port_id)
371 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
373 dev_flags = rte_eth_devices[port_id].data->dev_flags;
374 if ((dev_flags & RTE_ETH_DEV_DETACHABLE) &&
375 (!(dev_flags & RTE_ETH_DEV_BONDED_SLAVE)))
381 /* attach the new device, then store port_id of the device */
383 rte_eth_dev_attach(const char *devargs, uint16_t *port_id)
386 int current = rte_eth_dev_count();
390 if ((devargs == NULL) || (port_id == NULL)) {
395 /* parse devargs, then retrieve device name and args */
396 if (rte_eal_parse_devargs_str(devargs, &name, &args))
399 ret = rte_eal_dev_attach(name, args);
403 /* no point looking at the port count if no port exists */
404 if (!rte_eth_dev_count()) {
405 RTE_LOG(ERR, EAL, "No port found for device (%s)\n", name);
410 /* if nothing happened, there is a bug here, since some driver told us
411 * it did attach a device, but did not create a port.
413 if (current == rte_eth_dev_count()) {
418 *port_id = eth_dev_last_created_port;
427 /* detach the device, then store the name of the device */
429 rte_eth_dev_detach(uint16_t port_id, char *name)
438 /* FIXME: move this to eal, once device flags are relocated there */
439 if (rte_eth_dev_is_detachable(port_id))
442 snprintf(name, sizeof(rte_eth_devices[port_id].data->name),
443 "%s", rte_eth_devices[port_id].data->name);
445 ret = rte_eal_dev_detach(rte_eth_devices[port_id].device);
449 rte_eth_devices[port_id].state = RTE_ETH_DEV_UNUSED;
457 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
459 uint16_t old_nb_queues = dev->data->nb_rx_queues;
463 if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */
464 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
465 sizeof(dev->data->rx_queues[0]) * nb_queues,
466 RTE_CACHE_LINE_SIZE);
467 if (dev->data->rx_queues == NULL) {
468 dev->data->nb_rx_queues = 0;
471 } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */
472 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
474 rxq = dev->data->rx_queues;
476 for (i = nb_queues; i < old_nb_queues; i++)
477 (*dev->dev_ops->rx_queue_release)(rxq[i]);
478 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
479 RTE_CACHE_LINE_SIZE);
482 if (nb_queues > old_nb_queues) {
483 uint16_t new_qs = nb_queues - old_nb_queues;
485 memset(rxq + old_nb_queues, 0,
486 sizeof(rxq[0]) * new_qs);
489 dev->data->rx_queues = rxq;
491 } else if (dev->data->rx_queues != NULL && nb_queues == 0) {
492 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
494 rxq = dev->data->rx_queues;
496 for (i = nb_queues; i < old_nb_queues; i++)
497 (*dev->dev_ops->rx_queue_release)(rxq[i]);
499 rte_free(dev->data->rx_queues);
500 dev->data->rx_queues = NULL;
502 dev->data->nb_rx_queues = nb_queues;
507 rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id)
509 struct rte_eth_dev *dev;
511 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
513 dev = &rte_eth_devices[port_id];
514 if (rx_queue_id >= dev->data->nb_rx_queues) {
515 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
519 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
521 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
522 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
523 " already started\n",
524 rx_queue_id, port_id);
528 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
533 rte_eth_dev_rx_queue_stop(uint16_t port_id, uint16_t rx_queue_id)
535 struct rte_eth_dev *dev;
537 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
539 dev = &rte_eth_devices[port_id];
540 if (rx_queue_id >= dev->data->nb_rx_queues) {
541 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
545 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
547 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
548 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
549 " already stopped\n",
550 rx_queue_id, port_id);
554 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
559 rte_eth_dev_tx_queue_start(uint16_t port_id, uint16_t tx_queue_id)
561 struct rte_eth_dev *dev;
563 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
565 dev = &rte_eth_devices[port_id];
566 if (tx_queue_id >= dev->data->nb_tx_queues) {
567 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
571 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
573 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
574 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
575 " already started\n",
576 tx_queue_id, port_id);
580 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
585 rte_eth_dev_tx_queue_stop(uint16_t port_id, uint16_t tx_queue_id)
587 struct rte_eth_dev *dev;
589 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
591 dev = &rte_eth_devices[port_id];
592 if (tx_queue_id >= dev->data->nb_tx_queues) {
593 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
597 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
599 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
600 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
601 " already stopped\n",
602 tx_queue_id, port_id);
606 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
611 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
613 uint16_t old_nb_queues = dev->data->nb_tx_queues;
617 if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */
618 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
619 sizeof(dev->data->tx_queues[0]) * nb_queues,
620 RTE_CACHE_LINE_SIZE);
621 if (dev->data->tx_queues == NULL) {
622 dev->data->nb_tx_queues = 0;
625 } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */
626 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
628 txq = dev->data->tx_queues;
630 for (i = nb_queues; i < old_nb_queues; i++)
631 (*dev->dev_ops->tx_queue_release)(txq[i]);
632 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
633 RTE_CACHE_LINE_SIZE);
636 if (nb_queues > old_nb_queues) {
637 uint16_t new_qs = nb_queues - old_nb_queues;
639 memset(txq + old_nb_queues, 0,
640 sizeof(txq[0]) * new_qs);
643 dev->data->tx_queues = txq;
645 } else if (dev->data->tx_queues != NULL && nb_queues == 0) {
646 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
648 txq = dev->data->tx_queues;
650 for (i = nb_queues; i < old_nb_queues; i++)
651 (*dev->dev_ops->tx_queue_release)(txq[i]);
653 rte_free(dev->data->tx_queues);
654 dev->data->tx_queues = NULL;
656 dev->data->nb_tx_queues = nb_queues;
661 rte_eth_speed_bitflag(uint32_t speed, int duplex)
664 case ETH_SPEED_NUM_10M:
665 return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD;
666 case ETH_SPEED_NUM_100M:
667 return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD;
668 case ETH_SPEED_NUM_1G:
669 return ETH_LINK_SPEED_1G;
670 case ETH_SPEED_NUM_2_5G:
671 return ETH_LINK_SPEED_2_5G;
672 case ETH_SPEED_NUM_5G:
673 return ETH_LINK_SPEED_5G;
674 case ETH_SPEED_NUM_10G:
675 return ETH_LINK_SPEED_10G;
676 case ETH_SPEED_NUM_20G:
677 return ETH_LINK_SPEED_20G;
678 case ETH_SPEED_NUM_25G:
679 return ETH_LINK_SPEED_25G;
680 case ETH_SPEED_NUM_40G:
681 return ETH_LINK_SPEED_40G;
682 case ETH_SPEED_NUM_50G:
683 return ETH_LINK_SPEED_50G;
684 case ETH_SPEED_NUM_56G:
685 return ETH_LINK_SPEED_56G;
686 case ETH_SPEED_NUM_100G:
687 return ETH_LINK_SPEED_100G;
694 * A conversion function from rxmode bitfield API.
697 rte_eth_convert_rx_offload_bitfield(const struct rte_eth_rxmode *rxmode,
698 uint64_t *rx_offloads)
700 uint64_t offloads = 0;
702 if (rxmode->header_split == 1)
703 offloads |= DEV_RX_OFFLOAD_HEADER_SPLIT;
704 if (rxmode->hw_ip_checksum == 1)
705 offloads |= DEV_RX_OFFLOAD_CHECKSUM;
706 if (rxmode->hw_vlan_filter == 1)
707 offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
708 if (rxmode->hw_vlan_strip == 1)
709 offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
710 if (rxmode->hw_vlan_extend == 1)
711 offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
712 if (rxmode->jumbo_frame == 1)
713 offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
714 if (rxmode->hw_strip_crc == 1)
715 offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
716 if (rxmode->enable_scatter == 1)
717 offloads |= DEV_RX_OFFLOAD_SCATTER;
718 if (rxmode->enable_lro == 1)
719 offloads |= DEV_RX_OFFLOAD_TCP_LRO;
720 if (rxmode->hw_timestamp == 1)
721 offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
722 if (rxmode->security == 1)
723 offloads |= DEV_RX_OFFLOAD_SECURITY;
725 *rx_offloads = offloads;
729 * A conversion function from rxmode offloads API.
732 rte_eth_convert_rx_offloads(const uint64_t rx_offloads,
733 struct rte_eth_rxmode *rxmode)
736 if (rx_offloads & DEV_RX_OFFLOAD_HEADER_SPLIT)
737 rxmode->header_split = 1;
739 rxmode->header_split = 0;
740 if (rx_offloads & DEV_RX_OFFLOAD_CHECKSUM)
741 rxmode->hw_ip_checksum = 1;
743 rxmode->hw_ip_checksum = 0;
744 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
745 rxmode->hw_vlan_filter = 1;
747 rxmode->hw_vlan_filter = 0;
748 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
749 rxmode->hw_vlan_strip = 1;
751 rxmode->hw_vlan_strip = 0;
752 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND)
753 rxmode->hw_vlan_extend = 1;
755 rxmode->hw_vlan_extend = 0;
756 if (rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME)
757 rxmode->jumbo_frame = 1;
759 rxmode->jumbo_frame = 0;
760 if (rx_offloads & DEV_RX_OFFLOAD_CRC_STRIP)
761 rxmode->hw_strip_crc = 1;
763 rxmode->hw_strip_crc = 0;
764 if (rx_offloads & DEV_RX_OFFLOAD_SCATTER)
765 rxmode->enable_scatter = 1;
767 rxmode->enable_scatter = 0;
768 if (rx_offloads & DEV_RX_OFFLOAD_TCP_LRO)
769 rxmode->enable_lro = 1;
771 rxmode->enable_lro = 0;
772 if (rx_offloads & DEV_RX_OFFLOAD_TIMESTAMP)
773 rxmode->hw_timestamp = 1;
775 rxmode->hw_timestamp = 0;
776 if (rx_offloads & DEV_RX_OFFLOAD_SECURITY)
777 rxmode->security = 1;
779 rxmode->security = 0;
783 rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
784 const struct rte_eth_conf *dev_conf)
786 struct rte_eth_dev *dev;
787 struct rte_eth_dev_info dev_info;
788 struct rte_eth_conf local_conf = *dev_conf;
791 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
793 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
795 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
796 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
800 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
802 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
803 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
807 dev = &rte_eth_devices[port_id];
809 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
810 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
812 if (dev->data->dev_started) {
814 "port %d must be stopped to allow configuration\n", port_id);
819 * Convert between the offloads API to enable PMDs to support
822 if ((dev_conf->rxmode.ignore_offload_bitfield == 0)) {
823 rte_eth_convert_rx_offload_bitfield(
824 &dev_conf->rxmode, &local_conf.rxmode.offloads);
826 rte_eth_convert_rx_offloads(dev_conf->rxmode.offloads,
830 /* Copy the dev_conf parameter into the dev structure */
831 memcpy(&dev->data->dev_conf, &local_conf, sizeof(dev->data->dev_conf));
834 * Check that the numbers of RX and TX queues are not greater
835 * than the maximum number of RX and TX queues supported by the
838 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
840 if (nb_rx_q == 0 && nb_tx_q == 0) {
841 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d both rx and tx queue cannot be 0\n", port_id);
845 if (nb_rx_q > dev_info.max_rx_queues) {
846 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
847 port_id, nb_rx_q, dev_info.max_rx_queues);
851 if (nb_tx_q > dev_info.max_tx_queues) {
852 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
853 port_id, nb_tx_q, dev_info.max_tx_queues);
857 /* Check that the device supports requested interrupts */
858 if ((dev_conf->intr_conf.lsc == 1) &&
859 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
860 RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
861 dev->device->driver->name);
864 if ((dev_conf->intr_conf.rmv == 1) &&
865 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_RMV))) {
866 RTE_PMD_DEBUG_TRACE("driver %s does not support rmv\n",
867 dev->device->driver->name);
872 * If jumbo frames are enabled, check that the maximum RX packet
873 * length is supported by the configured device.
875 if (local_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
876 if (dev_conf->rxmode.max_rx_pkt_len >
877 dev_info.max_rx_pktlen) {
878 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
879 " > max valid value %u\n",
881 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
882 (unsigned)dev_info.max_rx_pktlen);
884 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
885 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
886 " < min valid value %u\n",
888 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
889 (unsigned)ETHER_MIN_LEN);
893 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
894 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
895 /* Use default value */
896 dev->data->dev_conf.rxmode.max_rx_pkt_len =
901 * Setup new number of RX/TX queues and reconfigure device.
903 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
905 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
910 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
912 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
914 rte_eth_dev_rx_queue_config(dev, 0);
918 diag = (*dev->dev_ops->dev_configure)(dev);
920 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
922 rte_eth_dev_rx_queue_config(dev, 0);
923 rte_eth_dev_tx_queue_config(dev, 0);
927 /* Initialize Rx profiling if enabled at compilation time. */
928 diag = __rte_eth_profile_rx_init(port_id, dev);
930 RTE_PMD_DEBUG_TRACE("port%d __rte_eth_profile_rx_init = %d\n",
932 rte_eth_dev_rx_queue_config(dev, 0);
933 rte_eth_dev_tx_queue_config(dev, 0);
941 _rte_eth_dev_reset(struct rte_eth_dev *dev)
943 if (dev->data->dev_started) {
945 "port %d must be stopped to allow reset\n",
950 rte_eth_dev_rx_queue_config(dev, 0);
951 rte_eth_dev_tx_queue_config(dev, 0);
953 memset(&dev->data->dev_conf, 0, sizeof(dev->data->dev_conf));
957 rte_eth_dev_config_restore(uint16_t port_id)
959 struct rte_eth_dev *dev;
960 struct rte_eth_dev_info dev_info;
961 struct ether_addr *addr;
966 dev = &rte_eth_devices[port_id];
968 rte_eth_dev_info_get(port_id, &dev_info);
970 /* replay MAC address configuration including default MAC */
971 addr = &dev->data->mac_addrs[0];
972 if (*dev->dev_ops->mac_addr_set != NULL)
973 (*dev->dev_ops->mac_addr_set)(dev, addr);
974 else if (*dev->dev_ops->mac_addr_add != NULL)
975 (*dev->dev_ops->mac_addr_add)(dev, addr, 0, pool);
977 if (*dev->dev_ops->mac_addr_add != NULL) {
978 for (i = 1; i < dev_info.max_mac_addrs; i++) {
979 addr = &dev->data->mac_addrs[i];
981 /* skip zero address */
982 if (is_zero_ether_addr(addr))
986 pool_mask = dev->data->mac_pool_sel[i];
989 if (pool_mask & 1ULL)
990 (*dev->dev_ops->mac_addr_add)(dev,
998 /* replay promiscuous configuration */
999 if (rte_eth_promiscuous_get(port_id) == 1)
1000 rte_eth_promiscuous_enable(port_id);
1001 else if (rte_eth_promiscuous_get(port_id) == 0)
1002 rte_eth_promiscuous_disable(port_id);
1004 /* replay all multicast configuration */
1005 if (rte_eth_allmulticast_get(port_id) == 1)
1006 rte_eth_allmulticast_enable(port_id);
1007 else if (rte_eth_allmulticast_get(port_id) == 0)
1008 rte_eth_allmulticast_disable(port_id);
1012 rte_eth_dev_start(uint16_t port_id)
1014 struct rte_eth_dev *dev;
1017 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1019 dev = &rte_eth_devices[port_id];
1021 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1023 if (dev->data->dev_started != 0) {
1024 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu16
1025 " already started\n",
1030 diag = (*dev->dev_ops->dev_start)(dev);
1032 dev->data->dev_started = 1;
1036 rte_eth_dev_config_restore(port_id);
1038 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1039 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1040 (*dev->dev_ops->link_update)(dev, 0);
1046 rte_eth_dev_stop(uint16_t port_id)
1048 struct rte_eth_dev *dev;
1050 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1051 dev = &rte_eth_devices[port_id];
1053 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1055 if (dev->data->dev_started == 0) {
1056 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu16
1057 " already stopped\n",
1062 dev->data->dev_started = 0;
1063 (*dev->dev_ops->dev_stop)(dev);
1067 rte_eth_dev_set_link_up(uint16_t port_id)
1069 struct rte_eth_dev *dev;
1071 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1073 dev = &rte_eth_devices[port_id];
1075 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1076 return (*dev->dev_ops->dev_set_link_up)(dev);
1080 rte_eth_dev_set_link_down(uint16_t port_id)
1082 struct rte_eth_dev *dev;
1084 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1086 dev = &rte_eth_devices[port_id];
1088 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1089 return (*dev->dev_ops->dev_set_link_down)(dev);
1093 rte_eth_dev_close(uint16_t port_id)
1095 struct rte_eth_dev *dev;
1097 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1098 dev = &rte_eth_devices[port_id];
1100 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1101 dev->data->dev_started = 0;
1102 (*dev->dev_ops->dev_close)(dev);
1104 dev->data->nb_rx_queues = 0;
1105 rte_free(dev->data->rx_queues);
1106 dev->data->rx_queues = NULL;
1107 dev->data->nb_tx_queues = 0;
1108 rte_free(dev->data->tx_queues);
1109 dev->data->tx_queues = NULL;
1113 rte_eth_dev_reset(uint16_t port_id)
1115 struct rte_eth_dev *dev;
1118 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1119 dev = &rte_eth_devices[port_id];
1121 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_reset, -ENOTSUP);
1123 rte_eth_dev_stop(port_id);
1124 ret = dev->dev_ops->dev_reset(dev);
1130 rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
1131 uint16_t nb_rx_desc, unsigned int socket_id,
1132 const struct rte_eth_rxconf *rx_conf,
1133 struct rte_mempool *mp)
1136 uint32_t mbp_buf_size;
1137 struct rte_eth_dev *dev;
1138 struct rte_eth_dev_info dev_info;
1139 struct rte_eth_rxconf local_conf;
1142 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1144 dev = &rte_eth_devices[port_id];
1145 if (rx_queue_id >= dev->data->nb_rx_queues) {
1146 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1150 if (dev->data->dev_started) {
1151 RTE_PMD_DEBUG_TRACE(
1152 "port %d must be stopped to allow configuration\n", port_id);
1156 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1157 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1160 * Check the size of the mbuf data buffer.
1161 * This value must be provided in the private data of the memory pool.
1162 * First check that the memory pool has a valid private data.
1164 rte_eth_dev_info_get(port_id, &dev_info);
1165 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1166 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1167 mp->name, (int) mp->private_data_size,
1168 (int) sizeof(struct rte_pktmbuf_pool_private));
1171 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1173 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1174 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1175 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1179 (int)(RTE_PKTMBUF_HEADROOM +
1180 dev_info.min_rx_bufsize),
1181 (int)RTE_PKTMBUF_HEADROOM,
1182 (int)dev_info.min_rx_bufsize);
1186 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1187 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1188 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1190 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1191 "should be: <= %hu, = %hu, and a product of %hu\n",
1193 dev_info.rx_desc_lim.nb_max,
1194 dev_info.rx_desc_lim.nb_min,
1195 dev_info.rx_desc_lim.nb_align);
1199 rxq = dev->data->rx_queues;
1200 if (rxq[rx_queue_id]) {
1201 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release,
1203 (*dev->dev_ops->rx_queue_release)(rxq[rx_queue_id]);
1204 rxq[rx_queue_id] = NULL;
1207 if (rx_conf == NULL)
1208 rx_conf = &dev_info.default_rxconf;
1210 local_conf = *rx_conf;
1211 if (dev->data->dev_conf.rxmode.ignore_offload_bitfield == 0) {
1213 * Reflect port offloads to queue offloads in order for
1214 * offloads to not be discarded.
1216 rte_eth_convert_rx_offload_bitfield(&dev->data->dev_conf.rxmode,
1217 &local_conf.offloads);
1220 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1221 socket_id, &local_conf, mp);
1223 if (!dev->data->min_rx_buf_size ||
1224 dev->data->min_rx_buf_size > mbp_buf_size)
1225 dev->data->min_rx_buf_size = mbp_buf_size;
1232 * A conversion function from txq_flags API.
1235 rte_eth_convert_txq_flags(const uint32_t txq_flags, uint64_t *tx_offloads)
1237 uint64_t offloads = 0;
1239 if (!(txq_flags & ETH_TXQ_FLAGS_NOMULTSEGS))
1240 offloads |= DEV_TX_OFFLOAD_MULTI_SEGS;
1241 if (!(txq_flags & ETH_TXQ_FLAGS_NOVLANOFFL))
1242 offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
1243 if (!(txq_flags & ETH_TXQ_FLAGS_NOXSUMSCTP))
1244 offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
1245 if (!(txq_flags & ETH_TXQ_FLAGS_NOXSUMUDP))
1246 offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
1247 if (!(txq_flags & ETH_TXQ_FLAGS_NOXSUMTCP))
1248 offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
1249 if ((txq_flags & ETH_TXQ_FLAGS_NOREFCOUNT) &&
1250 (txq_flags & ETH_TXQ_FLAGS_NOMULTMEMP))
1251 offloads |= DEV_TX_OFFLOAD_MBUF_FAST_FREE;
1253 *tx_offloads = offloads;
1257 * A conversion function from offloads API.
1260 rte_eth_convert_txq_offloads(const uint64_t tx_offloads, uint32_t *txq_flags)
1264 if (!(tx_offloads & DEV_TX_OFFLOAD_MULTI_SEGS))
1265 flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
1266 if (!(tx_offloads & DEV_TX_OFFLOAD_VLAN_INSERT))
1267 flags |= ETH_TXQ_FLAGS_NOVLANOFFL;
1268 if (!(tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM))
1269 flags |= ETH_TXQ_FLAGS_NOXSUMSCTP;
1270 if (!(tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM))
1271 flags |= ETH_TXQ_FLAGS_NOXSUMUDP;
1272 if (!(tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM))
1273 flags |= ETH_TXQ_FLAGS_NOXSUMTCP;
1274 if (tx_offloads & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
1275 flags |= (ETH_TXQ_FLAGS_NOREFCOUNT | ETH_TXQ_FLAGS_NOMULTMEMP);
1281 rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
1282 uint16_t nb_tx_desc, unsigned int socket_id,
1283 const struct rte_eth_txconf *tx_conf)
1285 struct rte_eth_dev *dev;
1286 struct rte_eth_dev_info dev_info;
1287 struct rte_eth_txconf local_conf;
1290 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1292 dev = &rte_eth_devices[port_id];
1293 if (tx_queue_id >= dev->data->nb_tx_queues) {
1294 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1298 if (dev->data->dev_started) {
1299 RTE_PMD_DEBUG_TRACE(
1300 "port %d must be stopped to allow configuration\n", port_id);
1304 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1305 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1307 rte_eth_dev_info_get(port_id, &dev_info);
1309 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1310 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1311 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1312 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1313 "should be: <= %hu, = %hu, and a product of %hu\n",
1315 dev_info.tx_desc_lim.nb_max,
1316 dev_info.tx_desc_lim.nb_min,
1317 dev_info.tx_desc_lim.nb_align);
1321 txq = dev->data->tx_queues;
1322 if (txq[tx_queue_id]) {
1323 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release,
1325 (*dev->dev_ops->tx_queue_release)(txq[tx_queue_id]);
1326 txq[tx_queue_id] = NULL;
1329 if (tx_conf == NULL)
1330 tx_conf = &dev_info.default_txconf;
1333 * Convert between the offloads API to enable PMDs to support
1336 local_conf = *tx_conf;
1337 if (tx_conf->txq_flags & ETH_TXQ_FLAGS_IGNORE) {
1338 rte_eth_convert_txq_offloads(tx_conf->offloads,
1339 &local_conf.txq_flags);
1340 /* Keep the ignore flag. */
1341 local_conf.txq_flags |= ETH_TXQ_FLAGS_IGNORE;
1343 rte_eth_convert_txq_flags(tx_conf->txq_flags,
1344 &local_conf.offloads);
1347 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1348 socket_id, &local_conf);
1352 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
1353 void *userdata __rte_unused)
1357 for (i = 0; i < unsent; i++)
1358 rte_pktmbuf_free(pkts[i]);
1362 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
1365 uint64_t *count = userdata;
1368 for (i = 0; i < unsent; i++)
1369 rte_pktmbuf_free(pkts[i]);
1375 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
1376 buffer_tx_error_fn cbfn, void *userdata)
1378 buffer->error_callback = cbfn;
1379 buffer->error_userdata = userdata;
1384 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
1391 buffer->size = size;
1392 if (buffer->error_callback == NULL) {
1393 ret = rte_eth_tx_buffer_set_err_callback(
1394 buffer, rte_eth_tx_buffer_drop_callback, NULL);
1401 rte_eth_tx_done_cleanup(uint16_t port_id, uint16_t queue_id, uint32_t free_cnt)
1403 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1405 /* Validate Input Data. Bail if not valid or not supported. */
1406 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1407 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_done_cleanup, -ENOTSUP);
1409 /* Call driver to free pending mbufs. */
1410 return (*dev->dev_ops->tx_done_cleanup)(dev->data->tx_queues[queue_id],
1415 rte_eth_promiscuous_enable(uint16_t port_id)
1417 struct rte_eth_dev *dev;
1419 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1420 dev = &rte_eth_devices[port_id];
1422 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1423 (*dev->dev_ops->promiscuous_enable)(dev);
1424 dev->data->promiscuous = 1;
1428 rte_eth_promiscuous_disable(uint16_t port_id)
1430 struct rte_eth_dev *dev;
1432 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1433 dev = &rte_eth_devices[port_id];
1435 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1436 dev->data->promiscuous = 0;
1437 (*dev->dev_ops->promiscuous_disable)(dev);
1441 rte_eth_promiscuous_get(uint16_t port_id)
1443 struct rte_eth_dev *dev;
1445 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1447 dev = &rte_eth_devices[port_id];
1448 return dev->data->promiscuous;
1452 rte_eth_allmulticast_enable(uint16_t port_id)
1454 struct rte_eth_dev *dev;
1456 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1457 dev = &rte_eth_devices[port_id];
1459 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1460 (*dev->dev_ops->allmulticast_enable)(dev);
1461 dev->data->all_multicast = 1;
1465 rte_eth_allmulticast_disable(uint16_t port_id)
1467 struct rte_eth_dev *dev;
1469 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1470 dev = &rte_eth_devices[port_id];
1472 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1473 dev->data->all_multicast = 0;
1474 (*dev->dev_ops->allmulticast_disable)(dev);
1478 rte_eth_allmulticast_get(uint16_t port_id)
1480 struct rte_eth_dev *dev;
1482 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1484 dev = &rte_eth_devices[port_id];
1485 return dev->data->all_multicast;
1489 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1490 struct rte_eth_link *link)
1492 struct rte_eth_link *dst = link;
1493 struct rte_eth_link *src = &(dev->data->dev_link);
1495 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1496 *(uint64_t *)src) == 0)
1503 rte_eth_link_get(uint16_t port_id, struct rte_eth_link *eth_link)
1505 struct rte_eth_dev *dev;
1507 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1508 dev = &rte_eth_devices[port_id];
1510 if (dev->data->dev_conf.intr_conf.lsc != 0)
1511 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1513 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1514 (*dev->dev_ops->link_update)(dev, 1);
1515 *eth_link = dev->data->dev_link;
1520 rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link)
1522 struct rte_eth_dev *dev;
1524 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1525 dev = &rte_eth_devices[port_id];
1527 if (dev->data->dev_conf.intr_conf.lsc != 0)
1528 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1530 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1531 (*dev->dev_ops->link_update)(dev, 0);
1532 *eth_link = dev->data->dev_link;
1537 rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats)
1539 struct rte_eth_dev *dev;
1541 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1543 dev = &rte_eth_devices[port_id];
1544 memset(stats, 0, sizeof(*stats));
1546 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1547 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1548 return (*dev->dev_ops->stats_get)(dev, stats);
1552 rte_eth_stats_reset(uint16_t port_id)
1554 struct rte_eth_dev *dev;
1556 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1557 dev = &rte_eth_devices[port_id];
1559 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_reset, -ENOTSUP);
1560 (*dev->dev_ops->stats_reset)(dev);
1561 dev->data->rx_mbuf_alloc_failed = 0;
1567 get_xstats_basic_count(struct rte_eth_dev *dev)
1569 uint16_t nb_rxqs, nb_txqs;
1572 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1573 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1575 count = RTE_NB_STATS;
1576 count += nb_rxqs * RTE_NB_RXQ_STATS;
1577 count += nb_txqs * RTE_NB_TXQ_STATS;
1583 get_xstats_count(uint16_t port_id)
1585 struct rte_eth_dev *dev;
1588 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1589 dev = &rte_eth_devices[port_id];
1590 if (dev->dev_ops->xstats_get_names_by_id != NULL) {
1591 count = (*dev->dev_ops->xstats_get_names_by_id)(dev, NULL,
1596 if (dev->dev_ops->xstats_get_names != NULL) {
1597 count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0);
1604 count += get_xstats_basic_count(dev);
1610 rte_eth_xstats_get_id_by_name(uint16_t port_id, const char *xstat_name,
1613 int cnt_xstats, idx_xstat;
1615 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1618 RTE_PMD_DEBUG_TRACE("Error: id pointer is NULL\n");
1623 RTE_PMD_DEBUG_TRACE("Error: xstat_name pointer is NULL\n");
1628 cnt_xstats = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
1629 if (cnt_xstats < 0) {
1630 RTE_PMD_DEBUG_TRACE("Error: Cannot get count of xstats\n");
1634 /* Get id-name lookup table */
1635 struct rte_eth_xstat_name xstats_names[cnt_xstats];
1637 if (cnt_xstats != rte_eth_xstats_get_names_by_id(
1638 port_id, xstats_names, cnt_xstats, NULL)) {
1639 RTE_PMD_DEBUG_TRACE("Error: Cannot get xstats lookup\n");
1643 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
1644 if (!strcmp(xstats_names[idx_xstat].name, xstat_name)) {
1653 /* retrieve ethdev extended statistics names */
1655 rte_eth_xstats_get_names_by_id(uint16_t port_id,
1656 struct rte_eth_xstat_name *xstats_names, unsigned int size,
1659 struct rte_eth_xstat_name *xstats_names_copy;
1660 unsigned int expected_entries;
1661 struct rte_eth_dev *dev;
1664 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1665 expected_entries = get_xstats_count(port_id);
1666 dev = &rte_eth_devices[port_id];
1668 /* Return max number of stats if no ids given */
1671 return expected_entries;
1672 else if (xstats_names && size < expected_entries)
1673 return expected_entries;
1676 if (ids && !xstats_names)
1679 if (dev->dev_ops->xstats_get_names_by_id != NULL)
1680 return (*dev->dev_ops->xstats_get_names_by_id)(
1681 dev, xstats_names, ids, size);
1683 /* Retrieve all stats */
1685 int num_stats = rte_eth_xstats_get_names(port_id, xstats_names,
1687 if (num_stats < 0 || num_stats > (int)expected_entries)
1690 return expected_entries;
1693 xstats_names_copy = calloc(expected_entries,
1694 sizeof(struct rte_eth_xstat_name));
1696 if (!xstats_names_copy) {
1697 RTE_PMD_DEBUG_TRACE("ERROR: can't allocate memory");
1701 /* Fill xstats_names_copy structure */
1702 rte_eth_xstats_get_names(port_id, xstats_names_copy, expected_entries);
1705 for (i = 0; i < size; i++) {
1706 if (ids[i] >= expected_entries) {
1707 RTE_PMD_DEBUG_TRACE("ERROR: id value isn't valid\n");
1708 free(xstats_names_copy);
1711 xstats_names[i] = xstats_names_copy[ids[i]];
1714 free(xstats_names_copy);
1719 rte_eth_xstats_get_names(uint16_t port_id,
1720 struct rte_eth_xstat_name *xstats_names,
1723 struct rte_eth_dev *dev;
1724 int cnt_used_entries;
1725 int cnt_expected_entries;
1726 int cnt_driver_entries;
1727 uint32_t idx, id_queue;
1730 cnt_expected_entries = get_xstats_count(port_id);
1731 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1732 (int)size < cnt_expected_entries)
1733 return cnt_expected_entries;
1735 /* port_id checked in get_xstats_count() */
1736 dev = &rte_eth_devices[port_id];
1737 cnt_used_entries = 0;
1739 for (idx = 0; idx < RTE_NB_STATS; idx++) {
1740 snprintf(xstats_names[cnt_used_entries].name,
1741 sizeof(xstats_names[0].name),
1742 "%s", rte_stats_strings[idx].name);
1745 num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1746 for (id_queue = 0; id_queue < num_q; id_queue++) {
1747 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1748 snprintf(xstats_names[cnt_used_entries].name,
1749 sizeof(xstats_names[0].name),
1751 id_queue, rte_rxq_stats_strings[idx].name);
1756 num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1757 for (id_queue = 0; id_queue < num_q; id_queue++) {
1758 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
1759 snprintf(xstats_names[cnt_used_entries].name,
1760 sizeof(xstats_names[0].name),
1762 id_queue, rte_txq_stats_strings[idx].name);
1767 if (dev->dev_ops->xstats_get_names != NULL) {
1768 /* If there are any driver-specific xstats, append them
1771 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
1773 xstats_names + cnt_used_entries,
1774 size - cnt_used_entries);
1775 if (cnt_driver_entries < 0)
1776 return cnt_driver_entries;
1777 cnt_used_entries += cnt_driver_entries;
1780 return cnt_used_entries;
1783 /* retrieve ethdev extended statistics */
1785 rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
1786 uint64_t *values, unsigned int size)
1788 unsigned int num_xstats_filled;
1789 uint16_t expected_entries;
1790 struct rte_eth_dev *dev;
1793 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1794 expected_entries = get_xstats_count(port_id);
1795 struct rte_eth_xstat xstats[expected_entries];
1796 dev = &rte_eth_devices[port_id];
1798 /* Return max number of stats if no ids given */
1801 return expected_entries;
1802 else if (values && size < expected_entries)
1803 return expected_entries;
1809 if (dev->dev_ops->xstats_get_by_id != NULL)
1810 return (*dev->dev_ops->xstats_get_by_id)(dev, ids, values,
1813 /* Fill the xstats structure */
1814 num_xstats_filled = rte_eth_xstats_get(port_id, xstats,
1817 /* Return all stats */
1819 for (i = 0; i < num_xstats_filled; i++)
1820 values[i] = xstats[i].value;
1821 return expected_entries;
1825 for (i = 0; i < size; i++) {
1826 if (ids[i] >= expected_entries) {
1827 RTE_PMD_DEBUG_TRACE("ERROR: id value isn't valid\n");
1830 values[i] = xstats[ids[i]].value;
1836 rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats,
1839 struct rte_eth_stats eth_stats;
1840 struct rte_eth_dev *dev;
1841 unsigned int count = 0, i, q;
1842 signed int xcount = 0;
1843 uint64_t val, *stats_ptr;
1844 uint16_t nb_rxqs, nb_txqs;
1846 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1848 dev = &rte_eth_devices[port_id];
1850 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1851 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1853 /* Return generic statistics */
1854 count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
1855 (nb_txqs * RTE_NB_TXQ_STATS);
1857 /* implemented by the driver */
1858 if (dev->dev_ops->xstats_get != NULL) {
1859 /* Retrieve the xstats from the driver at the end of the
1862 xcount = (*dev->dev_ops->xstats_get)(dev,
1863 xstats ? xstats + count : NULL,
1864 (n > count) ? n - count : 0);
1870 if (n < count + xcount || xstats == NULL)
1871 return count + xcount;
1873 /* now fill the xstats structure */
1875 rte_eth_stats_get(port_id, ð_stats);
1878 for (i = 0; i < RTE_NB_STATS; i++) {
1879 stats_ptr = RTE_PTR_ADD(ð_stats,
1880 rte_stats_strings[i].offset);
1882 xstats[count++].value = val;
1886 for (q = 0; q < nb_rxqs; q++) {
1887 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1888 stats_ptr = RTE_PTR_ADD(ð_stats,
1889 rte_rxq_stats_strings[i].offset +
1890 q * sizeof(uint64_t));
1892 xstats[count++].value = val;
1897 for (q = 0; q < nb_txqs; q++) {
1898 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1899 stats_ptr = RTE_PTR_ADD(ð_stats,
1900 rte_txq_stats_strings[i].offset +
1901 q * sizeof(uint64_t));
1903 xstats[count++].value = val;
1907 for (i = 0; i < count; i++)
1909 /* add an offset to driver-specific stats */
1910 for ( ; i < count + xcount; i++)
1911 xstats[i].id += count;
1913 return count + xcount;
1916 /* reset ethdev extended statistics */
1918 rte_eth_xstats_reset(uint16_t port_id)
1920 struct rte_eth_dev *dev;
1922 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1923 dev = &rte_eth_devices[port_id];
1925 /* implemented by the driver */
1926 if (dev->dev_ops->xstats_reset != NULL) {
1927 (*dev->dev_ops->xstats_reset)(dev);
1931 /* fallback to default */
1932 rte_eth_stats_reset(port_id);
1936 set_queue_stats_mapping(uint16_t port_id, uint16_t queue_id, uint8_t stat_idx,
1939 struct rte_eth_dev *dev;
1941 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1943 dev = &rte_eth_devices[port_id];
1945 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1946 return (*dev->dev_ops->queue_stats_mapping_set)
1947 (dev, queue_id, stat_idx, is_rx);
1952 rte_eth_dev_set_tx_queue_stats_mapping(uint16_t port_id, uint16_t tx_queue_id,
1955 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1961 rte_eth_dev_set_rx_queue_stats_mapping(uint16_t port_id, uint16_t rx_queue_id,
1964 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1969 rte_eth_dev_fw_version_get(uint16_t port_id, char *fw_version, size_t fw_size)
1971 struct rte_eth_dev *dev;
1973 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1974 dev = &rte_eth_devices[port_id];
1976 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP);
1977 return (*dev->dev_ops->fw_version_get)(dev, fw_version, fw_size);
1981 rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)
1983 struct rte_eth_dev *dev;
1984 const struct rte_eth_desc_lim lim = {
1985 .nb_max = UINT16_MAX,
1990 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1991 dev = &rte_eth_devices[port_id];
1993 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1994 dev_info->rx_desc_lim = lim;
1995 dev_info->tx_desc_lim = lim;
1997 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1998 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1999 dev_info->driver_name = dev->device->driver->name;
2000 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
2001 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
2005 rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
2006 uint32_t *ptypes, int num)
2009 struct rte_eth_dev *dev;
2010 const uint32_t *all_ptypes;
2012 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2013 dev = &rte_eth_devices[port_id];
2014 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
2015 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
2020 for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
2021 if (all_ptypes[i] & ptype_mask) {
2023 ptypes[j] = all_ptypes[i];
2031 rte_eth_macaddr_get(uint16_t port_id, struct ether_addr *mac_addr)
2033 struct rte_eth_dev *dev;
2035 RTE_ETH_VALID_PORTID_OR_RET(port_id);
2036 dev = &rte_eth_devices[port_id];
2037 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
2042 rte_eth_dev_get_mtu(uint16_t port_id, uint16_t *mtu)
2044 struct rte_eth_dev *dev;
2046 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2048 dev = &rte_eth_devices[port_id];
2049 *mtu = dev->data->mtu;
2054 rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
2057 struct rte_eth_dev *dev;
2059 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2060 dev = &rte_eth_devices[port_id];
2061 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
2063 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
2065 dev->data->mtu = mtu;
2071 rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on)
2073 struct rte_eth_dev *dev;
2076 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2077 dev = &rte_eth_devices[port_id];
2078 if (!(dev->data->dev_conf.rxmode.offloads &
2079 DEV_RX_OFFLOAD_VLAN_FILTER)) {
2080 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
2084 if (vlan_id > 4095) {
2085 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
2086 port_id, (unsigned) vlan_id);
2089 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
2091 ret = (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
2093 struct rte_vlan_filter_conf *vfc;
2097 vfc = &dev->data->vlan_filter_conf;
2098 vidx = vlan_id / 64;
2099 vbit = vlan_id % 64;
2102 vfc->ids[vidx] |= UINT64_C(1) << vbit;
2104 vfc->ids[vidx] &= ~(UINT64_C(1) << vbit);
2111 rte_eth_dev_set_vlan_strip_on_queue(uint16_t port_id, uint16_t rx_queue_id,
2114 struct rte_eth_dev *dev;
2116 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2117 dev = &rte_eth_devices[port_id];
2118 if (rx_queue_id >= dev->data->nb_rx_queues) {
2119 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
2123 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
2124 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
2130 rte_eth_dev_set_vlan_ether_type(uint16_t port_id,
2131 enum rte_vlan_type vlan_type,
2134 struct rte_eth_dev *dev;
2136 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2137 dev = &rte_eth_devices[port_id];
2138 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
2140 return (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type, tpid);
2144 rte_eth_dev_set_vlan_offload(uint16_t port_id, int offload_mask)
2146 struct rte_eth_dev *dev;
2151 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2152 dev = &rte_eth_devices[port_id];
2154 /*check which option changed by application*/
2155 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
2156 org = !!(dev->data->dev_conf.rxmode.offloads &
2157 DEV_RX_OFFLOAD_VLAN_STRIP);
2160 dev->data->dev_conf.rxmode.offloads |=
2161 DEV_RX_OFFLOAD_VLAN_STRIP;
2163 dev->data->dev_conf.rxmode.offloads &=
2164 ~DEV_RX_OFFLOAD_VLAN_STRIP;
2165 mask |= ETH_VLAN_STRIP_MASK;
2168 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
2169 org = !!(dev->data->dev_conf.rxmode.offloads &
2170 DEV_RX_OFFLOAD_VLAN_FILTER);
2173 dev->data->dev_conf.rxmode.offloads |=
2174 DEV_RX_OFFLOAD_VLAN_FILTER;
2176 dev->data->dev_conf.rxmode.offloads &=
2177 ~DEV_RX_OFFLOAD_VLAN_FILTER;
2178 mask |= ETH_VLAN_FILTER_MASK;
2181 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
2182 org = !!(dev->data->dev_conf.rxmode.offloads &
2183 DEV_RX_OFFLOAD_VLAN_EXTEND);
2186 dev->data->dev_conf.rxmode.offloads |=
2187 DEV_RX_OFFLOAD_VLAN_EXTEND;
2189 dev->data->dev_conf.rxmode.offloads &=
2190 ~DEV_RX_OFFLOAD_VLAN_EXTEND;
2191 mask |= ETH_VLAN_EXTEND_MASK;
2198 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
2201 * Convert to the offload bitfield API just in case the underlying PMD
2202 * still supporting it.
2204 rte_eth_convert_rx_offloads(dev->data->dev_conf.rxmode.offloads,
2205 &dev->data->dev_conf.rxmode);
2206 (*dev->dev_ops->vlan_offload_set)(dev, mask);
2212 rte_eth_dev_get_vlan_offload(uint16_t port_id)
2214 struct rte_eth_dev *dev;
2217 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2218 dev = &rte_eth_devices[port_id];
2220 if (dev->data->dev_conf.rxmode.offloads &
2221 DEV_RX_OFFLOAD_VLAN_STRIP)
2222 ret |= ETH_VLAN_STRIP_OFFLOAD;
2224 if (dev->data->dev_conf.rxmode.offloads &
2225 DEV_RX_OFFLOAD_VLAN_FILTER)
2226 ret |= ETH_VLAN_FILTER_OFFLOAD;
2228 if (dev->data->dev_conf.rxmode.offloads &
2229 DEV_RX_OFFLOAD_VLAN_EXTEND)
2230 ret |= ETH_VLAN_EXTEND_OFFLOAD;
2236 rte_eth_dev_set_vlan_pvid(uint16_t port_id, uint16_t pvid, int on)
2238 struct rte_eth_dev *dev;
2240 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2241 dev = &rte_eth_devices[port_id];
2242 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
2243 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
2249 rte_eth_dev_flow_ctrl_get(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
2251 struct rte_eth_dev *dev;
2253 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2254 dev = &rte_eth_devices[port_id];
2255 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2256 memset(fc_conf, 0, sizeof(*fc_conf));
2257 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
2261 rte_eth_dev_flow_ctrl_set(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
2263 struct rte_eth_dev *dev;
2265 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2266 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2267 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2271 dev = &rte_eth_devices[port_id];
2272 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2273 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
2277 rte_eth_dev_priority_flow_ctrl_set(uint16_t port_id,
2278 struct rte_eth_pfc_conf *pfc_conf)
2280 struct rte_eth_dev *dev;
2282 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2283 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2284 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2288 dev = &rte_eth_devices[port_id];
2289 /* High water, low water validation are device specific */
2290 if (*dev->dev_ops->priority_flow_ctrl_set)
2291 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
2296 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2304 num = (reta_size + RTE_RETA_GROUP_SIZE - 1) / RTE_RETA_GROUP_SIZE;
2305 for (i = 0; i < num; i++) {
2306 if (reta_conf[i].mask)
2314 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2318 uint16_t i, idx, shift;
2324 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
2328 for (i = 0; i < reta_size; i++) {
2329 idx = i / RTE_RETA_GROUP_SIZE;
2330 shift = i % RTE_RETA_GROUP_SIZE;
2331 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2332 (reta_conf[idx].reta[shift] >= max_rxq)) {
2333 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2334 "the maximum rxq index: %u\n", idx, shift,
2335 reta_conf[idx].reta[shift], max_rxq);
2344 rte_eth_dev_rss_reta_update(uint16_t port_id,
2345 struct rte_eth_rss_reta_entry64 *reta_conf,
2348 struct rte_eth_dev *dev;
2351 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2352 /* Check mask bits */
2353 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2357 dev = &rte_eth_devices[port_id];
2359 /* Check entry value */
2360 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2361 dev->data->nb_rx_queues);
2365 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2366 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2370 rte_eth_dev_rss_reta_query(uint16_t port_id,
2371 struct rte_eth_rss_reta_entry64 *reta_conf,
2374 struct rte_eth_dev *dev;
2377 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2379 /* Check mask bits */
2380 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2384 dev = &rte_eth_devices[port_id];
2385 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2386 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2390 rte_eth_dev_rss_hash_update(uint16_t port_id,
2391 struct rte_eth_rss_conf *rss_conf)
2393 struct rte_eth_dev *dev;
2395 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2396 dev = &rte_eth_devices[port_id];
2397 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2398 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2402 rte_eth_dev_rss_hash_conf_get(uint16_t port_id,
2403 struct rte_eth_rss_conf *rss_conf)
2405 struct rte_eth_dev *dev;
2407 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2408 dev = &rte_eth_devices[port_id];
2409 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2410 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2414 rte_eth_dev_udp_tunnel_port_add(uint16_t port_id,
2415 struct rte_eth_udp_tunnel *udp_tunnel)
2417 struct rte_eth_dev *dev;
2419 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2420 if (udp_tunnel == NULL) {
2421 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2425 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2426 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2430 dev = &rte_eth_devices[port_id];
2431 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
2432 return (*dev->dev_ops->udp_tunnel_port_add)(dev, udp_tunnel);
2436 rte_eth_dev_udp_tunnel_port_delete(uint16_t port_id,
2437 struct rte_eth_udp_tunnel *udp_tunnel)
2439 struct rte_eth_dev *dev;
2441 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2442 dev = &rte_eth_devices[port_id];
2444 if (udp_tunnel == NULL) {
2445 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2449 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2450 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2454 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
2455 return (*dev->dev_ops->udp_tunnel_port_del)(dev, udp_tunnel);
2459 rte_eth_led_on(uint16_t port_id)
2461 struct rte_eth_dev *dev;
2463 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2464 dev = &rte_eth_devices[port_id];
2465 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2466 return (*dev->dev_ops->dev_led_on)(dev);
2470 rte_eth_led_off(uint16_t port_id)
2472 struct rte_eth_dev *dev;
2474 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2475 dev = &rte_eth_devices[port_id];
2476 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2477 return (*dev->dev_ops->dev_led_off)(dev);
2481 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2485 get_mac_addr_index(uint16_t port_id, const struct ether_addr *addr)
2487 struct rte_eth_dev_info dev_info;
2488 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2491 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2492 rte_eth_dev_info_get(port_id, &dev_info);
2494 for (i = 0; i < dev_info.max_mac_addrs; i++)
2495 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2501 static const struct ether_addr null_mac_addr;
2504 rte_eth_dev_mac_addr_add(uint16_t port_id, struct ether_addr *addr,
2507 struct rte_eth_dev *dev;
2512 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2513 dev = &rte_eth_devices[port_id];
2514 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2516 if (is_zero_ether_addr(addr)) {
2517 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2521 if (pool >= ETH_64_POOLS) {
2522 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2526 index = get_mac_addr_index(port_id, addr);
2528 index = get_mac_addr_index(port_id, &null_mac_addr);
2530 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2535 pool_mask = dev->data->mac_pool_sel[index];
2537 /* Check if both MAC address and pool is already there, and do nothing */
2538 if (pool_mask & (1ULL << pool))
2543 ret = (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2546 /* Update address in NIC data structure */
2547 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2549 /* Update pool bitmap in NIC data structure */
2550 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2557 rte_eth_dev_mac_addr_remove(uint16_t port_id, struct ether_addr *addr)
2559 struct rte_eth_dev *dev;
2562 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2563 dev = &rte_eth_devices[port_id];
2564 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2566 index = get_mac_addr_index(port_id, addr);
2568 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2570 } else if (index < 0)
2571 return 0; /* Do nothing if address wasn't found */
2574 (*dev->dev_ops->mac_addr_remove)(dev, index);
2576 /* Update address in NIC data structure */
2577 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2579 /* reset pool bitmap */
2580 dev->data->mac_pool_sel[index] = 0;
2586 rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct ether_addr *addr)
2588 struct rte_eth_dev *dev;
2590 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2592 if (!is_valid_assigned_ether_addr(addr))
2595 dev = &rte_eth_devices[port_id];
2596 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2598 /* Update default address in NIC data structure */
2599 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2601 (*dev->dev_ops->mac_addr_set)(dev, addr);
2608 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2612 get_hash_mac_addr_index(uint16_t port_id, const struct ether_addr *addr)
2614 struct rte_eth_dev_info dev_info;
2615 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2618 rte_eth_dev_info_get(port_id, &dev_info);
2619 if (!dev->data->hash_mac_addrs)
2622 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2623 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2624 ETHER_ADDR_LEN) == 0)
2631 rte_eth_dev_uc_hash_table_set(uint16_t port_id, struct ether_addr *addr,
2636 struct rte_eth_dev *dev;
2638 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2640 dev = &rte_eth_devices[port_id];
2641 if (is_zero_ether_addr(addr)) {
2642 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2647 index = get_hash_mac_addr_index(port_id, addr);
2648 /* Check if it's already there, and do nothing */
2649 if ((index >= 0) && (on))
2654 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2655 "set in UTA\n", port_id);
2659 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2661 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2667 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2668 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2670 /* Update address in NIC data structure */
2672 ether_addr_copy(addr,
2673 &dev->data->hash_mac_addrs[index]);
2675 ether_addr_copy(&null_mac_addr,
2676 &dev->data->hash_mac_addrs[index]);
2683 rte_eth_dev_uc_all_hash_table_set(uint16_t port_id, uint8_t on)
2685 struct rte_eth_dev *dev;
2687 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2689 dev = &rte_eth_devices[port_id];
2691 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2692 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2695 int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx,
2698 struct rte_eth_dev *dev;
2699 struct rte_eth_dev_info dev_info;
2700 struct rte_eth_link link;
2702 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2704 dev = &rte_eth_devices[port_id];
2705 rte_eth_dev_info_get(port_id, &dev_info);
2706 link = dev->data->dev_link;
2708 if (queue_idx > dev_info.max_tx_queues) {
2709 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2710 "invalid queue id=%d\n", port_id, queue_idx);
2714 if (tx_rate > link.link_speed) {
2715 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2716 "bigger than link speed= %d\n",
2717 tx_rate, link.link_speed);
2721 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2722 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2726 rte_eth_mirror_rule_set(uint16_t port_id,
2727 struct rte_eth_mirror_conf *mirror_conf,
2728 uint8_t rule_id, uint8_t on)
2730 struct rte_eth_dev *dev;
2732 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2733 if (mirror_conf->rule_type == 0) {
2734 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2738 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2739 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2744 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2745 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2746 (mirror_conf->pool_mask == 0)) {
2747 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2751 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2752 mirror_conf->vlan.vlan_mask == 0) {
2753 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2757 dev = &rte_eth_devices[port_id];
2758 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2760 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2764 rte_eth_mirror_rule_reset(uint16_t port_id, uint8_t rule_id)
2766 struct rte_eth_dev *dev;
2768 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2770 dev = &rte_eth_devices[port_id];
2771 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2773 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2777 rte_eth_dev_callback_register(uint16_t port_id,
2778 enum rte_eth_event_type event,
2779 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2781 struct rte_eth_dev *dev;
2782 struct rte_eth_dev_callback *user_cb;
2787 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2789 dev = &rte_eth_devices[port_id];
2790 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2792 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2793 if (user_cb->cb_fn == cb_fn &&
2794 user_cb->cb_arg == cb_arg &&
2795 user_cb->event == event) {
2800 /* create a new callback. */
2801 if (user_cb == NULL) {
2802 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2803 sizeof(struct rte_eth_dev_callback), 0);
2804 if (user_cb != NULL) {
2805 user_cb->cb_fn = cb_fn;
2806 user_cb->cb_arg = cb_arg;
2807 user_cb->event = event;
2808 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2812 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2813 return (user_cb == NULL) ? -ENOMEM : 0;
2817 rte_eth_dev_callback_unregister(uint16_t port_id,
2818 enum rte_eth_event_type event,
2819 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2822 struct rte_eth_dev *dev;
2823 struct rte_eth_dev_callback *cb, *next;
2828 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2830 dev = &rte_eth_devices[port_id];
2831 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2834 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2836 next = TAILQ_NEXT(cb, next);
2838 if (cb->cb_fn != cb_fn || cb->event != event ||
2839 (cb->cb_arg != (void *)-1 &&
2840 cb->cb_arg != cb_arg))
2844 * if this callback is not executing right now,
2847 if (cb->active == 0) {
2848 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2855 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2860 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2861 enum rte_eth_event_type event, void *cb_arg, void *ret_param)
2863 struct rte_eth_dev_callback *cb_lst;
2864 struct rte_eth_dev_callback dev_cb;
2867 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2868 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2869 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2874 dev_cb.cb_arg = cb_arg;
2875 if (ret_param != NULL)
2876 dev_cb.ret_param = ret_param;
2878 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2879 rc = dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2880 dev_cb.cb_arg, dev_cb.ret_param);
2881 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2884 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2889 rte_eth_dev_rx_intr_ctl(uint16_t port_id, int epfd, int op, void *data)
2892 struct rte_eth_dev *dev;
2893 struct rte_intr_handle *intr_handle;
2897 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2899 dev = &rte_eth_devices[port_id];
2901 if (!dev->intr_handle) {
2902 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
2906 intr_handle = dev->intr_handle;
2907 if (!intr_handle->intr_vec) {
2908 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2912 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2913 vec = intr_handle->intr_vec[qid];
2914 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2915 if (rc && rc != -EEXIST) {
2916 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2917 " op %d epfd %d vec %u\n",
2918 port_id, qid, op, epfd, vec);
2925 const struct rte_memzone *
2926 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2927 uint16_t queue_id, size_t size, unsigned align,
2930 char z_name[RTE_MEMZONE_NAMESIZE];
2931 const struct rte_memzone *mz;
2933 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2934 dev->device->driver->name, ring_name,
2935 dev->data->port_id, queue_id);
2937 mz = rte_memzone_lookup(z_name);
2941 return rte_memzone_reserve_aligned(z_name, size, socket_id, 0, align);
2945 rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id,
2946 int epfd, int op, void *data)
2949 struct rte_eth_dev *dev;
2950 struct rte_intr_handle *intr_handle;
2953 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2955 dev = &rte_eth_devices[port_id];
2956 if (queue_id >= dev->data->nb_rx_queues) {
2957 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
2961 if (!dev->intr_handle) {
2962 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
2966 intr_handle = dev->intr_handle;
2967 if (!intr_handle->intr_vec) {
2968 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2972 vec = intr_handle->intr_vec[queue_id];
2973 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2974 if (rc && rc != -EEXIST) {
2975 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2976 " op %d epfd %d vec %u\n",
2977 port_id, queue_id, op, epfd, vec);
2985 rte_eth_dev_rx_intr_enable(uint16_t port_id,
2988 struct rte_eth_dev *dev;
2990 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2992 dev = &rte_eth_devices[port_id];
2994 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
2995 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
2999 rte_eth_dev_rx_intr_disable(uint16_t port_id,
3002 struct rte_eth_dev *dev;
3004 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3006 dev = &rte_eth_devices[port_id];
3008 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
3009 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
3014 rte_eth_dev_filter_supported(uint16_t port_id,
3015 enum rte_filter_type filter_type)
3017 struct rte_eth_dev *dev;
3019 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3021 dev = &rte_eth_devices[port_id];
3022 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3023 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3024 RTE_ETH_FILTER_NOP, NULL);
3028 rte_eth_dev_filter_ctrl(uint16_t port_id, enum rte_filter_type filter_type,
3029 enum rte_filter_op filter_op, void *arg)
3031 struct rte_eth_dev *dev;
3033 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3035 dev = &rte_eth_devices[port_id];
3036 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3037 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
3041 rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
3042 rte_rx_callback_fn fn, void *user_param)
3044 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3045 rte_errno = ENOTSUP;
3048 /* check input parameters */
3049 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3050 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3054 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3062 cb->param = user_param;
3064 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3065 /* Add the callbacks in fifo order. */
3066 struct rte_eth_rxtx_callback *tail =
3067 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3070 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3077 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3083 rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
3084 rte_rx_callback_fn fn, void *user_param)
3086 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3087 rte_errno = ENOTSUP;
3090 /* check input parameters */
3091 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3092 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3097 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3105 cb->param = user_param;
3107 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3108 /* Add the callbacks at fisrt position*/
3109 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3111 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3112 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3118 rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
3119 rte_tx_callback_fn fn, void *user_param)
3121 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3122 rte_errno = ENOTSUP;
3125 /* check input parameters */
3126 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3127 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3132 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3140 cb->param = user_param;
3142 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3143 /* Add the callbacks in fifo order. */
3144 struct rte_eth_rxtx_callback *tail =
3145 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3148 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3155 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3161 rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
3162 struct rte_eth_rxtx_callback *user_cb)
3164 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3167 /* Check input parameters. */
3168 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3169 if (user_cb == NULL ||
3170 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
3173 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3174 struct rte_eth_rxtx_callback *cb;
3175 struct rte_eth_rxtx_callback **prev_cb;
3178 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3179 prev_cb = &dev->post_rx_burst_cbs[queue_id];
3180 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3182 if (cb == user_cb) {
3183 /* Remove the user cb from the callback list. */
3184 *prev_cb = cb->next;
3189 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3195 rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
3196 struct rte_eth_rxtx_callback *user_cb)
3198 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3201 /* Check input parameters. */
3202 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3203 if (user_cb == NULL ||
3204 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
3207 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3209 struct rte_eth_rxtx_callback *cb;
3210 struct rte_eth_rxtx_callback **prev_cb;
3212 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3213 prev_cb = &dev->pre_tx_burst_cbs[queue_id];
3214 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3216 if (cb == user_cb) {
3217 /* Remove the user cb from the callback list. */
3218 *prev_cb = cb->next;
3223 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3229 rte_eth_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
3230 struct rte_eth_rxq_info *qinfo)
3232 struct rte_eth_dev *dev;
3234 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3239 dev = &rte_eth_devices[port_id];
3240 if (queue_id >= dev->data->nb_rx_queues) {
3241 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3245 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3247 memset(qinfo, 0, sizeof(*qinfo));
3248 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3253 rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,
3254 struct rte_eth_txq_info *qinfo)
3256 struct rte_eth_dev *dev;
3258 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3263 dev = &rte_eth_devices[port_id];
3264 if (queue_id >= dev->data->nb_tx_queues) {
3265 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3269 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3271 memset(qinfo, 0, sizeof(*qinfo));
3272 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3277 rte_eth_dev_set_mc_addr_list(uint16_t port_id,
3278 struct ether_addr *mc_addr_set,
3279 uint32_t nb_mc_addr)
3281 struct rte_eth_dev *dev;
3283 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3285 dev = &rte_eth_devices[port_id];
3286 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3287 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3291 rte_eth_timesync_enable(uint16_t port_id)
3293 struct rte_eth_dev *dev;
3295 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3296 dev = &rte_eth_devices[port_id];
3298 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3299 return (*dev->dev_ops->timesync_enable)(dev);
3303 rte_eth_timesync_disable(uint16_t port_id)
3305 struct rte_eth_dev *dev;
3307 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3308 dev = &rte_eth_devices[port_id];
3310 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3311 return (*dev->dev_ops->timesync_disable)(dev);
3315 rte_eth_timesync_read_rx_timestamp(uint16_t port_id, struct timespec *timestamp,
3318 struct rte_eth_dev *dev;
3320 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3321 dev = &rte_eth_devices[port_id];
3323 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3324 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3328 rte_eth_timesync_read_tx_timestamp(uint16_t port_id,
3329 struct timespec *timestamp)
3331 struct rte_eth_dev *dev;
3333 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3334 dev = &rte_eth_devices[port_id];
3336 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3337 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3341 rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta)
3343 struct rte_eth_dev *dev;
3345 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3346 dev = &rte_eth_devices[port_id];
3348 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3349 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3353 rte_eth_timesync_read_time(uint16_t port_id, struct timespec *timestamp)
3355 struct rte_eth_dev *dev;
3357 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3358 dev = &rte_eth_devices[port_id];
3360 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3361 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3365 rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *timestamp)
3367 struct rte_eth_dev *dev;
3369 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3370 dev = &rte_eth_devices[port_id];
3372 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3373 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3377 rte_eth_dev_get_reg_info(uint16_t port_id, struct rte_dev_reg_info *info)
3379 struct rte_eth_dev *dev;
3381 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3383 dev = &rte_eth_devices[port_id];
3384 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3385 return (*dev->dev_ops->get_reg)(dev, info);
3389 rte_eth_dev_get_eeprom_length(uint16_t port_id)
3391 struct rte_eth_dev *dev;
3393 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3395 dev = &rte_eth_devices[port_id];
3396 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3397 return (*dev->dev_ops->get_eeprom_length)(dev);
3401 rte_eth_dev_get_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
3403 struct rte_eth_dev *dev;
3405 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3407 dev = &rte_eth_devices[port_id];
3408 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3409 return (*dev->dev_ops->get_eeprom)(dev, info);
3413 rte_eth_dev_set_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
3415 struct rte_eth_dev *dev;
3417 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3419 dev = &rte_eth_devices[port_id];
3420 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3421 return (*dev->dev_ops->set_eeprom)(dev, info);
3425 rte_eth_dev_get_dcb_info(uint16_t port_id,
3426 struct rte_eth_dcb_info *dcb_info)
3428 struct rte_eth_dev *dev;
3430 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3432 dev = &rte_eth_devices[port_id];
3433 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3435 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3436 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3440 rte_eth_dev_l2_tunnel_eth_type_conf(uint16_t port_id,
3441 struct rte_eth_l2_tunnel_conf *l2_tunnel)
3443 struct rte_eth_dev *dev;
3445 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3446 if (l2_tunnel == NULL) {
3447 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3451 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3452 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
3456 dev = &rte_eth_devices[port_id];
3457 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
3459 return (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev, l2_tunnel);
3463 rte_eth_dev_l2_tunnel_offload_set(uint16_t port_id,
3464 struct rte_eth_l2_tunnel_conf *l2_tunnel,
3468 struct rte_eth_dev *dev;
3470 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3472 if (l2_tunnel == NULL) {
3473 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3477 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3478 RTE_PMD_DEBUG_TRACE("Invalid tunnel type.\n");
3483 RTE_PMD_DEBUG_TRACE("Mask should have a value.\n");
3487 dev = &rte_eth_devices[port_id];
3488 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
3490 return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);
3494 rte_eth_dev_adjust_nb_desc(uint16_t *nb_desc,
3495 const struct rte_eth_desc_lim *desc_lim)
3497 if (desc_lim->nb_align != 0)
3498 *nb_desc = RTE_ALIGN_CEIL(*nb_desc, desc_lim->nb_align);
3500 if (desc_lim->nb_max != 0)
3501 *nb_desc = RTE_MIN(*nb_desc, desc_lim->nb_max);
3503 *nb_desc = RTE_MAX(*nb_desc, desc_lim->nb_min);
3507 rte_eth_dev_adjust_nb_rx_tx_desc(uint16_t port_id,
3508 uint16_t *nb_rx_desc,
3509 uint16_t *nb_tx_desc)
3511 struct rte_eth_dev *dev;
3512 struct rte_eth_dev_info dev_info;
3514 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3516 dev = &rte_eth_devices[port_id];
3517 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
3519 rte_eth_dev_info_get(port_id, &dev_info);
3521 if (nb_rx_desc != NULL)
3522 rte_eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim);
3524 if (nb_tx_desc != NULL)
3525 rte_eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim);
3531 rte_eth_dev_pool_ops_supported(uint16_t port_id, const char *pool)
3533 struct rte_eth_dev *dev;
3535 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3540 dev = &rte_eth_devices[port_id];
3542 if (*dev->dev_ops->pool_ops_supported == NULL)
3543 return 1; /* all pools are supported */
3545 return (*dev->dev_ops->pool_ops_supported)(dev, pool);