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(uint8_t port_id)
145 while (port_id < RTE_MAX_ETHPORTS &&
146 rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED)
149 if (port_id >= RTE_MAX_ETHPORTS)
150 return RTE_MAX_ETHPORTS;
156 rte_eth_dev_data_alloc(void)
158 const unsigned flags = 0;
159 const struct rte_memzone *mz;
161 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
162 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
163 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
164 rte_socket_id(), flags);
166 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
168 rte_panic("Cannot allocate memzone for ethernet port data\n");
170 rte_eth_dev_data = mz->addr;
171 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
172 memset(rte_eth_dev_data, 0,
173 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
177 rte_eth_dev_allocated(const char *name)
181 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
182 if (rte_eth_devices[i].state == RTE_ETH_DEV_ATTACHED &&
183 rte_eth_devices[i].device) {
184 if (!strcmp(rte_eth_devices[i].device->name, name))
185 return &rte_eth_devices[i];
192 rte_eth_dev_find_free_port(void)
196 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
197 if (rte_eth_devices[i].state == RTE_ETH_DEV_UNUSED)
200 return RTE_MAX_ETHPORTS;
203 static struct rte_eth_dev *
204 eth_dev_get(uint8_t port_id)
206 struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
208 eth_dev->data = &rte_eth_dev_data[port_id];
209 eth_dev->state = RTE_ETH_DEV_ATTACHED;
210 TAILQ_INIT(&(eth_dev->link_intr_cbs));
212 eth_dev_last_created_port = port_id;
218 rte_eth_dev_allocate(const char *name)
221 struct rte_eth_dev *eth_dev;
223 port_id = rte_eth_dev_find_free_port();
224 if (port_id == RTE_MAX_ETHPORTS) {
225 RTE_PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
229 if (rte_eth_dev_data == NULL)
230 rte_eth_dev_data_alloc();
232 if (rte_eth_dev_allocated(name) != NULL) {
233 RTE_PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n",
238 memset(&rte_eth_dev_data[port_id], 0, sizeof(struct rte_eth_dev_data));
239 eth_dev = eth_dev_get(port_id);
240 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
241 eth_dev->data->port_id = port_id;
242 eth_dev->data->mtu = ETHER_MTU;
248 * Attach to a port already registered by the primary process, which
249 * makes sure that the same device would have the same port id both
250 * in the primary and secondary process.
253 rte_eth_dev_attach_secondary(const char *name)
256 struct rte_eth_dev *eth_dev;
258 if (rte_eth_dev_data == NULL)
259 rte_eth_dev_data_alloc();
261 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
262 if (strcmp(rte_eth_dev_data[i].name, name) == 0)
265 if (i == RTE_MAX_ETHPORTS) {
267 "device %s is not driven by the primary process\n",
272 eth_dev = eth_dev_get(i);
273 RTE_ASSERT(eth_dev->data->port_id == i);
279 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
284 eth_dev->state = RTE_ETH_DEV_UNUSED;
289 rte_eth_dev_is_valid_port(uint8_t port_id)
291 if (port_id >= RTE_MAX_ETHPORTS ||
292 (rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
293 rte_eth_devices[port_id].state != RTE_ETH_DEV_DEFERRED))
300 rte_eth_dev_socket_id(uint8_t port_id)
302 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
303 return rte_eth_devices[port_id].data->numa_node;
307 rte_eth_dev_count(void)
314 RTE_ETH_FOREACH_DEV(p)
321 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
325 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
328 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
332 /* shouldn't check 'rte_eth_devices[i].data',
333 * because it might be overwritten by VDEV PMD */
334 tmp = rte_eth_devices[port_id].device->name;
340 rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
346 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
350 RTE_ETH_FOREACH_DEV(i) {
351 if (!rte_eth_devices[i].device)
354 ret = strncmp(name, rte_eth_devices[i].device->name,
365 rte_eth_dev_is_detachable(uint8_t port_id)
369 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
371 dev_flags = rte_eth_devices[port_id].data->dev_flags;
372 if ((dev_flags & RTE_ETH_DEV_DETACHABLE) &&
373 (!(dev_flags & RTE_ETH_DEV_BONDED_SLAVE)))
379 /* attach the new device, then store port_id of the device */
381 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
384 int current = rte_eth_dev_count();
388 if ((devargs == NULL) || (port_id == NULL)) {
393 /* parse devargs, then retrieve device name and args */
394 if (rte_eal_parse_devargs_str(devargs, &name, &args))
397 ret = rte_eal_dev_attach(name, args);
401 /* no point looking at the port count if no port exists */
402 if (!rte_eth_dev_count()) {
403 RTE_LOG(ERR, EAL, "No port found for device (%s)\n", name);
408 /* if nothing happened, there is a bug here, since some driver told us
409 * it did attach a device, but did not create a port.
411 if (current == rte_eth_dev_count()) {
416 *port_id = eth_dev_last_created_port;
425 /* detach the device, then store the name of the device */
427 rte_eth_dev_detach(uint8_t port_id, char *name)
436 /* FIXME: move this to eal, once device flags are relocated there */
437 if (rte_eth_dev_is_detachable(port_id))
440 snprintf(name, RTE_DEV_NAME_MAX_LEN, "%s",
441 rte_eth_devices[port_id].device->name);
443 ret = rte_eal_dev_detach(rte_eth_devices[port_id].device);
447 rte_eth_devices[port_id].state = RTE_ETH_DEV_UNUSED;
455 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
457 uint16_t old_nb_queues = dev->data->nb_rx_queues;
461 if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */
462 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
463 sizeof(dev->data->rx_queues[0]) * nb_queues,
464 RTE_CACHE_LINE_SIZE);
465 if (dev->data->rx_queues == NULL) {
466 dev->data->nb_rx_queues = 0;
469 } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */
470 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
472 rxq = dev->data->rx_queues;
474 for (i = nb_queues; i < old_nb_queues; i++)
475 (*dev->dev_ops->rx_queue_release)(rxq[i]);
476 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
477 RTE_CACHE_LINE_SIZE);
480 if (nb_queues > old_nb_queues) {
481 uint16_t new_qs = nb_queues - old_nb_queues;
483 memset(rxq + old_nb_queues, 0,
484 sizeof(rxq[0]) * new_qs);
487 dev->data->rx_queues = rxq;
489 } else if (dev->data->rx_queues != NULL && nb_queues == 0) {
490 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
492 rxq = dev->data->rx_queues;
494 for (i = nb_queues; i < old_nb_queues; i++)
495 (*dev->dev_ops->rx_queue_release)(rxq[i]);
497 rte_free(dev->data->rx_queues);
498 dev->data->rx_queues = NULL;
500 dev->data->nb_rx_queues = nb_queues;
505 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
507 struct rte_eth_dev *dev;
509 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
511 dev = &rte_eth_devices[port_id];
512 if (rx_queue_id >= dev->data->nb_rx_queues) {
513 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
517 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
519 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
520 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
521 " already started\n",
522 rx_queue_id, port_id);
526 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
531 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
533 struct rte_eth_dev *dev;
535 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
537 dev = &rte_eth_devices[port_id];
538 if (rx_queue_id >= dev->data->nb_rx_queues) {
539 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
543 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
545 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
546 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
547 " already stopped\n",
548 rx_queue_id, port_id);
552 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
557 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
559 struct rte_eth_dev *dev;
561 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
563 dev = &rte_eth_devices[port_id];
564 if (tx_queue_id >= dev->data->nb_tx_queues) {
565 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
569 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
571 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
572 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
573 " already started\n",
574 tx_queue_id, port_id);
578 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
583 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
585 struct rte_eth_dev *dev;
587 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
589 dev = &rte_eth_devices[port_id];
590 if (tx_queue_id >= dev->data->nb_tx_queues) {
591 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
595 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
597 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
598 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
599 " already stopped\n",
600 tx_queue_id, port_id);
604 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
609 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
611 uint16_t old_nb_queues = dev->data->nb_tx_queues;
615 if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */
616 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
617 sizeof(dev->data->tx_queues[0]) * nb_queues,
618 RTE_CACHE_LINE_SIZE);
619 if (dev->data->tx_queues == NULL) {
620 dev->data->nb_tx_queues = 0;
623 } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */
624 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
626 txq = dev->data->tx_queues;
628 for (i = nb_queues; i < old_nb_queues; i++)
629 (*dev->dev_ops->tx_queue_release)(txq[i]);
630 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
631 RTE_CACHE_LINE_SIZE);
634 if (nb_queues > old_nb_queues) {
635 uint16_t new_qs = nb_queues - old_nb_queues;
637 memset(txq + old_nb_queues, 0,
638 sizeof(txq[0]) * new_qs);
641 dev->data->tx_queues = txq;
643 } else if (dev->data->tx_queues != NULL && nb_queues == 0) {
644 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
646 txq = dev->data->tx_queues;
648 for (i = nb_queues; i < old_nb_queues; i++)
649 (*dev->dev_ops->tx_queue_release)(txq[i]);
651 rte_free(dev->data->tx_queues);
652 dev->data->tx_queues = NULL;
654 dev->data->nb_tx_queues = nb_queues;
659 rte_eth_speed_bitflag(uint32_t speed, int duplex)
662 case ETH_SPEED_NUM_10M:
663 return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD;
664 case ETH_SPEED_NUM_100M:
665 return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD;
666 case ETH_SPEED_NUM_1G:
667 return ETH_LINK_SPEED_1G;
668 case ETH_SPEED_NUM_2_5G:
669 return ETH_LINK_SPEED_2_5G;
670 case ETH_SPEED_NUM_5G:
671 return ETH_LINK_SPEED_5G;
672 case ETH_SPEED_NUM_10G:
673 return ETH_LINK_SPEED_10G;
674 case ETH_SPEED_NUM_20G:
675 return ETH_LINK_SPEED_20G;
676 case ETH_SPEED_NUM_25G:
677 return ETH_LINK_SPEED_25G;
678 case ETH_SPEED_NUM_40G:
679 return ETH_LINK_SPEED_40G;
680 case ETH_SPEED_NUM_50G:
681 return ETH_LINK_SPEED_50G;
682 case ETH_SPEED_NUM_56G:
683 return ETH_LINK_SPEED_56G;
684 case ETH_SPEED_NUM_100G:
685 return ETH_LINK_SPEED_100G;
692 * A conversion function from rxmode bitfield API.
695 rte_eth_convert_rx_offload_bitfield(const struct rte_eth_rxmode *rxmode,
696 uint64_t *rx_offloads)
698 uint64_t offloads = 0;
700 if (rxmode->header_split == 1)
701 offloads |= DEV_RX_OFFLOAD_HEADER_SPLIT;
702 if (rxmode->hw_ip_checksum == 1)
703 offloads |= DEV_RX_OFFLOAD_CHECKSUM;
704 if (rxmode->hw_vlan_filter == 1)
705 offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
706 if (rxmode->hw_vlan_strip == 1)
707 offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
708 if (rxmode->hw_vlan_extend == 1)
709 offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
710 if (rxmode->jumbo_frame == 1)
711 offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
712 if (rxmode->hw_strip_crc == 1)
713 offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
714 if (rxmode->enable_scatter == 1)
715 offloads |= DEV_RX_OFFLOAD_SCATTER;
716 if (rxmode->enable_lro == 1)
717 offloads |= DEV_RX_OFFLOAD_TCP_LRO;
719 *rx_offloads = offloads;
723 * A conversion function from rxmode offloads API.
726 rte_eth_convert_rx_offloads(const uint64_t rx_offloads,
727 struct rte_eth_rxmode *rxmode)
730 if (rx_offloads & DEV_RX_OFFLOAD_HEADER_SPLIT)
731 rxmode->header_split = 1;
733 rxmode->header_split = 0;
734 if (rx_offloads & DEV_RX_OFFLOAD_CHECKSUM)
735 rxmode->hw_ip_checksum = 1;
737 rxmode->hw_ip_checksum = 0;
738 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
739 rxmode->hw_vlan_filter = 1;
741 rxmode->hw_vlan_filter = 0;
742 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
743 rxmode->hw_vlan_strip = 1;
745 rxmode->hw_vlan_strip = 0;
746 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND)
747 rxmode->hw_vlan_extend = 1;
749 rxmode->hw_vlan_extend = 0;
750 if (rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME)
751 rxmode->jumbo_frame = 1;
753 rxmode->jumbo_frame = 0;
754 if (rx_offloads & DEV_RX_OFFLOAD_CRC_STRIP)
755 rxmode->hw_strip_crc = 1;
757 rxmode->hw_strip_crc = 0;
758 if (rx_offloads & DEV_RX_OFFLOAD_SCATTER)
759 rxmode->enable_scatter = 1;
761 rxmode->enable_scatter = 0;
762 if (rx_offloads & DEV_RX_OFFLOAD_TCP_LRO)
763 rxmode->enable_lro = 1;
765 rxmode->enable_lro = 0;
769 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
770 const struct rte_eth_conf *dev_conf)
772 struct rte_eth_dev *dev;
773 struct rte_eth_dev_info dev_info;
774 struct rte_eth_conf local_conf = *dev_conf;
777 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
779 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
781 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
782 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
786 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
788 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
789 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
793 dev = &rte_eth_devices[port_id];
795 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
796 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
798 if (dev->data->dev_started) {
800 "port %d must be stopped to allow configuration\n", port_id);
805 * Convert between the offloads API to enable PMDs to support
808 if ((dev_conf->rxmode.ignore_offload_bitfield == 0)) {
809 rte_eth_convert_rx_offload_bitfield(
810 &dev_conf->rxmode, &local_conf.rxmode.offloads);
812 rte_eth_convert_rx_offloads(dev_conf->rxmode.offloads,
816 /* Copy the dev_conf parameter into the dev structure */
817 memcpy(&dev->data->dev_conf, &local_conf, sizeof(dev->data->dev_conf));
820 * Check that the numbers of RX and TX queues are not greater
821 * than the maximum number of RX and TX queues supported by the
824 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
826 if (nb_rx_q == 0 && nb_tx_q == 0) {
827 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d both rx and tx queue cannot be 0\n", port_id);
831 if (nb_rx_q > dev_info.max_rx_queues) {
832 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
833 port_id, nb_rx_q, dev_info.max_rx_queues);
837 if (nb_tx_q > dev_info.max_tx_queues) {
838 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
839 port_id, nb_tx_q, dev_info.max_tx_queues);
843 /* Check that the device supports requested interrupts */
844 if ((dev_conf->intr_conf.lsc == 1) &&
845 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
846 RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
847 dev->device->driver->name);
850 if ((dev_conf->intr_conf.rmv == 1) &&
851 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_RMV))) {
852 RTE_PMD_DEBUG_TRACE("driver %s does not support rmv\n",
853 dev->device->driver->name);
858 * If jumbo frames are enabled, check that the maximum RX packet
859 * length is supported by the configured device.
861 if (local_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
862 if (dev_conf->rxmode.max_rx_pkt_len >
863 dev_info.max_rx_pktlen) {
864 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
865 " > max valid value %u\n",
867 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
868 (unsigned)dev_info.max_rx_pktlen);
870 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
871 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
872 " < min valid value %u\n",
874 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
875 (unsigned)ETHER_MIN_LEN);
879 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
880 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
881 /* Use default value */
882 dev->data->dev_conf.rxmode.max_rx_pkt_len =
887 * Setup new number of RX/TX queues and reconfigure device.
889 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
891 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
896 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
898 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
900 rte_eth_dev_rx_queue_config(dev, 0);
904 diag = (*dev->dev_ops->dev_configure)(dev);
906 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
908 rte_eth_dev_rx_queue_config(dev, 0);
909 rte_eth_dev_tx_queue_config(dev, 0);
913 /* Initialize Rx profiling if enabled at compilation time. */
914 diag = __rte_eth_profile_rx_init(port_id, dev);
916 RTE_PMD_DEBUG_TRACE("port%d __rte_eth_profile_rx_init = %d\n",
918 rte_eth_dev_rx_queue_config(dev, 0);
919 rte_eth_dev_tx_queue_config(dev, 0);
927 _rte_eth_dev_reset(struct rte_eth_dev *dev)
929 if (dev->data->dev_started) {
931 "port %d must be stopped to allow reset\n",
936 rte_eth_dev_rx_queue_config(dev, 0);
937 rte_eth_dev_tx_queue_config(dev, 0);
939 memset(&dev->data->dev_conf, 0, sizeof(dev->data->dev_conf));
943 rte_eth_dev_config_restore(uint8_t port_id)
945 struct rte_eth_dev *dev;
946 struct rte_eth_dev_info dev_info;
947 struct ether_addr *addr;
952 dev = &rte_eth_devices[port_id];
954 rte_eth_dev_info_get(port_id, &dev_info);
956 /* replay MAC address configuration including default MAC */
957 addr = &dev->data->mac_addrs[0];
958 if (*dev->dev_ops->mac_addr_set != NULL)
959 (*dev->dev_ops->mac_addr_set)(dev, addr);
960 else if (*dev->dev_ops->mac_addr_add != NULL)
961 (*dev->dev_ops->mac_addr_add)(dev, addr, 0, pool);
963 if (*dev->dev_ops->mac_addr_add != NULL) {
964 for (i = 1; i < dev_info.max_mac_addrs; i++) {
965 addr = &dev->data->mac_addrs[i];
967 /* skip zero address */
968 if (is_zero_ether_addr(addr))
972 pool_mask = dev->data->mac_pool_sel[i];
975 if (pool_mask & 1ULL)
976 (*dev->dev_ops->mac_addr_add)(dev,
984 /* replay promiscuous configuration */
985 if (rte_eth_promiscuous_get(port_id) == 1)
986 rte_eth_promiscuous_enable(port_id);
987 else if (rte_eth_promiscuous_get(port_id) == 0)
988 rte_eth_promiscuous_disable(port_id);
990 /* replay all multicast configuration */
991 if (rte_eth_allmulticast_get(port_id) == 1)
992 rte_eth_allmulticast_enable(port_id);
993 else if (rte_eth_allmulticast_get(port_id) == 0)
994 rte_eth_allmulticast_disable(port_id);
998 rte_eth_dev_start(uint8_t port_id)
1000 struct rte_eth_dev *dev;
1003 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1005 dev = &rte_eth_devices[port_id];
1007 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1009 if (dev->data->dev_started != 0) {
1010 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1011 " already started\n",
1016 diag = (*dev->dev_ops->dev_start)(dev);
1018 dev->data->dev_started = 1;
1022 rte_eth_dev_config_restore(port_id);
1024 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1025 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1026 (*dev->dev_ops->link_update)(dev, 0);
1032 rte_eth_dev_stop(uint8_t port_id)
1034 struct rte_eth_dev *dev;
1036 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1037 dev = &rte_eth_devices[port_id];
1039 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1041 if (dev->data->dev_started == 0) {
1042 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1043 " already stopped\n",
1048 dev->data->dev_started = 0;
1049 (*dev->dev_ops->dev_stop)(dev);
1053 rte_eth_dev_set_link_up(uint8_t port_id)
1055 struct rte_eth_dev *dev;
1057 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1059 dev = &rte_eth_devices[port_id];
1061 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1062 return (*dev->dev_ops->dev_set_link_up)(dev);
1066 rte_eth_dev_set_link_down(uint8_t port_id)
1068 struct rte_eth_dev *dev;
1070 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1072 dev = &rte_eth_devices[port_id];
1074 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1075 return (*dev->dev_ops->dev_set_link_down)(dev);
1079 rte_eth_dev_close(uint8_t port_id)
1081 struct rte_eth_dev *dev;
1083 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1084 dev = &rte_eth_devices[port_id];
1086 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1087 dev->data->dev_started = 0;
1088 (*dev->dev_ops->dev_close)(dev);
1090 dev->data->nb_rx_queues = 0;
1091 rte_free(dev->data->rx_queues);
1092 dev->data->rx_queues = NULL;
1093 dev->data->nb_tx_queues = 0;
1094 rte_free(dev->data->tx_queues);
1095 dev->data->tx_queues = NULL;
1099 rte_eth_dev_reset(uint8_t port_id)
1101 struct rte_eth_dev *dev;
1104 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1105 dev = &rte_eth_devices[port_id];
1107 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_reset, -ENOTSUP);
1109 rte_eth_dev_stop(port_id);
1110 ret = dev->dev_ops->dev_reset(dev);
1116 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1117 uint16_t nb_rx_desc, unsigned int socket_id,
1118 const struct rte_eth_rxconf *rx_conf,
1119 struct rte_mempool *mp)
1122 uint32_t mbp_buf_size;
1123 struct rte_eth_dev *dev;
1124 struct rte_eth_dev_info dev_info;
1125 struct rte_eth_rxconf local_conf;
1128 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1130 dev = &rte_eth_devices[port_id];
1131 if (rx_queue_id >= dev->data->nb_rx_queues) {
1132 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1136 if (dev->data->dev_started) {
1137 RTE_PMD_DEBUG_TRACE(
1138 "port %d must be stopped to allow configuration\n", port_id);
1142 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1143 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1146 * Check the size of the mbuf data buffer.
1147 * This value must be provided in the private data of the memory pool.
1148 * First check that the memory pool has a valid private data.
1150 rte_eth_dev_info_get(port_id, &dev_info);
1151 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1152 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1153 mp->name, (int) mp->private_data_size,
1154 (int) sizeof(struct rte_pktmbuf_pool_private));
1157 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1159 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1160 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1161 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1165 (int)(RTE_PKTMBUF_HEADROOM +
1166 dev_info.min_rx_bufsize),
1167 (int)RTE_PKTMBUF_HEADROOM,
1168 (int)dev_info.min_rx_bufsize);
1172 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1173 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1174 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1176 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1177 "should be: <= %hu, = %hu, and a product of %hu\n",
1179 dev_info.rx_desc_lim.nb_max,
1180 dev_info.rx_desc_lim.nb_min,
1181 dev_info.rx_desc_lim.nb_align);
1185 rxq = dev->data->rx_queues;
1186 if (rxq[rx_queue_id]) {
1187 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release,
1189 (*dev->dev_ops->rx_queue_release)(rxq[rx_queue_id]);
1190 rxq[rx_queue_id] = NULL;
1193 if (rx_conf == NULL)
1194 rx_conf = &dev_info.default_rxconf;
1196 local_conf = *rx_conf;
1197 if (dev->data->dev_conf.rxmode.ignore_offload_bitfield == 0) {
1199 * Reflect port offloads to queue offloads in order for
1200 * offloads to not be discarded.
1202 rte_eth_convert_rx_offload_bitfield(&dev->data->dev_conf.rxmode,
1203 &local_conf.offloads);
1206 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1207 socket_id, &local_conf, mp);
1209 if (!dev->data->min_rx_buf_size ||
1210 dev->data->min_rx_buf_size > mbp_buf_size)
1211 dev->data->min_rx_buf_size = mbp_buf_size;
1218 * A conversion function from txq_flags API.
1221 rte_eth_convert_txq_flags(const uint32_t txq_flags, uint64_t *tx_offloads)
1223 uint64_t offloads = 0;
1225 if (!(txq_flags & ETH_TXQ_FLAGS_NOMULTSEGS))
1226 offloads |= DEV_TX_OFFLOAD_MULTI_SEGS;
1227 if (!(txq_flags & ETH_TXQ_FLAGS_NOVLANOFFL))
1228 offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
1229 if (!(txq_flags & ETH_TXQ_FLAGS_NOXSUMSCTP))
1230 offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
1231 if (!(txq_flags & ETH_TXQ_FLAGS_NOXSUMUDP))
1232 offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
1233 if (!(txq_flags & ETH_TXQ_FLAGS_NOXSUMTCP))
1234 offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
1235 if ((txq_flags & ETH_TXQ_FLAGS_NOREFCOUNT) &&
1236 (txq_flags & ETH_TXQ_FLAGS_NOMULTMEMP))
1237 offloads |= DEV_TX_OFFLOAD_MBUF_FAST_FREE;
1239 *tx_offloads = offloads;
1243 * A conversion function from offloads API.
1246 rte_eth_convert_txq_offloads(const uint64_t tx_offloads, uint32_t *txq_flags)
1250 if (!(tx_offloads & DEV_TX_OFFLOAD_MULTI_SEGS))
1251 flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
1252 if (!(tx_offloads & DEV_TX_OFFLOAD_VLAN_INSERT))
1253 flags |= ETH_TXQ_FLAGS_NOVLANOFFL;
1254 if (!(tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM))
1255 flags |= ETH_TXQ_FLAGS_NOXSUMSCTP;
1256 if (!(tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM))
1257 flags |= ETH_TXQ_FLAGS_NOXSUMUDP;
1258 if (!(tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM))
1259 flags |= ETH_TXQ_FLAGS_NOXSUMTCP;
1260 if (tx_offloads & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
1261 flags |= (ETH_TXQ_FLAGS_NOREFCOUNT | ETH_TXQ_FLAGS_NOMULTMEMP);
1267 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1268 uint16_t nb_tx_desc, unsigned int socket_id,
1269 const struct rte_eth_txconf *tx_conf)
1271 struct rte_eth_dev *dev;
1272 struct rte_eth_dev_info dev_info;
1273 struct rte_eth_txconf local_conf;
1276 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1278 dev = &rte_eth_devices[port_id];
1279 if (tx_queue_id >= dev->data->nb_tx_queues) {
1280 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1284 if (dev->data->dev_started) {
1285 RTE_PMD_DEBUG_TRACE(
1286 "port %d must be stopped to allow configuration\n", port_id);
1290 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1291 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1293 rte_eth_dev_info_get(port_id, &dev_info);
1295 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1296 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1297 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1298 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1299 "should be: <= %hu, = %hu, and a product of %hu\n",
1301 dev_info.tx_desc_lim.nb_max,
1302 dev_info.tx_desc_lim.nb_min,
1303 dev_info.tx_desc_lim.nb_align);
1307 txq = dev->data->tx_queues;
1308 if (txq[tx_queue_id]) {
1309 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release,
1311 (*dev->dev_ops->tx_queue_release)(txq[tx_queue_id]);
1312 txq[tx_queue_id] = NULL;
1315 if (tx_conf == NULL)
1316 tx_conf = &dev_info.default_txconf;
1319 * Convert between the offloads API to enable PMDs to support
1322 local_conf = *tx_conf;
1323 if (tx_conf->txq_flags & ETH_TXQ_FLAGS_IGNORE) {
1324 rte_eth_convert_txq_offloads(tx_conf->offloads,
1325 &local_conf.txq_flags);
1326 /* Keep the ignore flag. */
1327 local_conf.txq_flags |= ETH_TXQ_FLAGS_IGNORE;
1329 rte_eth_convert_txq_flags(tx_conf->txq_flags,
1330 &local_conf.offloads);
1333 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1334 socket_id, &local_conf);
1338 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
1339 void *userdata __rte_unused)
1343 for (i = 0; i < unsent; i++)
1344 rte_pktmbuf_free(pkts[i]);
1348 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
1351 uint64_t *count = userdata;
1354 for (i = 0; i < unsent; i++)
1355 rte_pktmbuf_free(pkts[i]);
1361 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
1362 buffer_tx_error_fn cbfn, void *userdata)
1364 buffer->error_callback = cbfn;
1365 buffer->error_userdata = userdata;
1370 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
1377 buffer->size = size;
1378 if (buffer->error_callback == NULL) {
1379 ret = rte_eth_tx_buffer_set_err_callback(
1380 buffer, rte_eth_tx_buffer_drop_callback, NULL);
1387 rte_eth_tx_done_cleanup(uint8_t port_id, uint16_t queue_id, uint32_t free_cnt)
1389 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1391 /* Validate Input Data. Bail if not valid or not supported. */
1392 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1393 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_done_cleanup, -ENOTSUP);
1395 /* Call driver to free pending mbufs. */
1396 return (*dev->dev_ops->tx_done_cleanup)(dev->data->tx_queues[queue_id],
1401 rte_eth_promiscuous_enable(uint8_t port_id)
1403 struct rte_eth_dev *dev;
1405 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1406 dev = &rte_eth_devices[port_id];
1408 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1409 (*dev->dev_ops->promiscuous_enable)(dev);
1410 dev->data->promiscuous = 1;
1414 rte_eth_promiscuous_disable(uint8_t port_id)
1416 struct rte_eth_dev *dev;
1418 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1419 dev = &rte_eth_devices[port_id];
1421 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1422 dev->data->promiscuous = 0;
1423 (*dev->dev_ops->promiscuous_disable)(dev);
1427 rte_eth_promiscuous_get(uint8_t port_id)
1429 struct rte_eth_dev *dev;
1431 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1433 dev = &rte_eth_devices[port_id];
1434 return dev->data->promiscuous;
1438 rte_eth_allmulticast_enable(uint8_t port_id)
1440 struct rte_eth_dev *dev;
1442 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1443 dev = &rte_eth_devices[port_id];
1445 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1446 (*dev->dev_ops->allmulticast_enable)(dev);
1447 dev->data->all_multicast = 1;
1451 rte_eth_allmulticast_disable(uint8_t port_id)
1453 struct rte_eth_dev *dev;
1455 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1456 dev = &rte_eth_devices[port_id];
1458 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1459 dev->data->all_multicast = 0;
1460 (*dev->dev_ops->allmulticast_disable)(dev);
1464 rte_eth_allmulticast_get(uint8_t port_id)
1466 struct rte_eth_dev *dev;
1468 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1470 dev = &rte_eth_devices[port_id];
1471 return dev->data->all_multicast;
1475 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1476 struct rte_eth_link *link)
1478 struct rte_eth_link *dst = link;
1479 struct rte_eth_link *src = &(dev->data->dev_link);
1481 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1482 *(uint64_t *)src) == 0)
1489 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1491 struct rte_eth_dev *dev;
1493 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1494 dev = &rte_eth_devices[port_id];
1496 if (dev->data->dev_conf.intr_conf.lsc != 0)
1497 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1499 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1500 (*dev->dev_ops->link_update)(dev, 1);
1501 *eth_link = dev->data->dev_link;
1506 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1508 struct rte_eth_dev *dev;
1510 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1511 dev = &rte_eth_devices[port_id];
1513 if (dev->data->dev_conf.intr_conf.lsc != 0)
1514 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1516 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1517 (*dev->dev_ops->link_update)(dev, 0);
1518 *eth_link = dev->data->dev_link;
1523 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1525 struct rte_eth_dev *dev;
1527 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1529 dev = &rte_eth_devices[port_id];
1530 memset(stats, 0, sizeof(*stats));
1532 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1533 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1534 (*dev->dev_ops->stats_get)(dev, stats);
1539 rte_eth_stats_reset(uint8_t port_id)
1541 struct rte_eth_dev *dev;
1543 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1544 dev = &rte_eth_devices[port_id];
1546 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1547 (*dev->dev_ops->stats_reset)(dev);
1548 dev->data->rx_mbuf_alloc_failed = 0;
1552 get_xstats_count(uint8_t port_id)
1554 struct rte_eth_dev *dev;
1557 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1558 dev = &rte_eth_devices[port_id];
1559 if (dev->dev_ops->xstats_get_names_by_id != NULL) {
1560 count = (*dev->dev_ops->xstats_get_names_by_id)(dev, NULL,
1565 if (dev->dev_ops->xstats_get_names != NULL) {
1566 count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0);
1572 count += RTE_NB_STATS;
1573 count += RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
1575 count += RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
1581 rte_eth_xstats_get_id_by_name(uint8_t port_id, const char *xstat_name,
1584 int cnt_xstats, idx_xstat;
1586 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1589 RTE_PMD_DEBUG_TRACE("Error: id pointer is NULL\n");
1594 RTE_PMD_DEBUG_TRACE("Error: xstat_name pointer is NULL\n");
1599 cnt_xstats = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
1600 if (cnt_xstats < 0) {
1601 RTE_PMD_DEBUG_TRACE("Error: Cannot get count of xstats\n");
1605 /* Get id-name lookup table */
1606 struct rte_eth_xstat_name xstats_names[cnt_xstats];
1608 if (cnt_xstats != rte_eth_xstats_get_names_by_id(
1609 port_id, xstats_names, cnt_xstats, NULL)) {
1610 RTE_PMD_DEBUG_TRACE("Error: Cannot get xstats lookup\n");
1614 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
1615 if (!strcmp(xstats_names[idx_xstat].name, xstat_name)) {
1625 rte_eth_xstats_get_names_by_id(uint8_t port_id,
1626 struct rte_eth_xstat_name *xstats_names, unsigned int size,
1629 /* Get all xstats */
1631 struct rte_eth_dev *dev;
1632 int cnt_used_entries;
1633 int cnt_expected_entries;
1634 int cnt_driver_entries;
1635 uint32_t idx, id_queue;
1638 cnt_expected_entries = get_xstats_count(port_id);
1639 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1640 (int)size < cnt_expected_entries)
1641 return cnt_expected_entries;
1643 /* port_id checked in get_xstats_count() */
1644 dev = &rte_eth_devices[port_id];
1645 cnt_used_entries = 0;
1647 for (idx = 0; idx < RTE_NB_STATS; idx++) {
1648 snprintf(xstats_names[cnt_used_entries].name,
1649 sizeof(xstats_names[0].name),
1650 "%s", rte_stats_strings[idx].name);
1653 num_q = RTE_MIN(dev->data->nb_rx_queues,
1654 RTE_ETHDEV_QUEUE_STAT_CNTRS);
1655 for (id_queue = 0; id_queue < num_q; id_queue++) {
1656 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1657 snprintf(xstats_names[cnt_used_entries].name,
1658 sizeof(xstats_names[0].name),
1661 rte_rxq_stats_strings[idx].name);
1666 num_q = RTE_MIN(dev->data->nb_tx_queues,
1667 RTE_ETHDEV_QUEUE_STAT_CNTRS);
1668 for (id_queue = 0; id_queue < num_q; id_queue++) {
1669 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
1670 snprintf(xstats_names[cnt_used_entries].name,
1671 sizeof(xstats_names[0].name),
1674 rte_txq_stats_strings[idx].name);
1679 if (dev->dev_ops->xstats_get_names_by_id != NULL) {
1680 /* If there are any driver-specific xstats, append them
1683 cnt_driver_entries =
1684 (*dev->dev_ops->xstats_get_names_by_id)(
1686 xstats_names + cnt_used_entries,
1688 size - cnt_used_entries);
1689 if (cnt_driver_entries < 0)
1690 return cnt_driver_entries;
1691 cnt_used_entries += cnt_driver_entries;
1693 } else if (dev->dev_ops->xstats_get_names != NULL) {
1694 /* If there are any driver-specific xstats, append them
1697 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
1699 xstats_names + cnt_used_entries,
1700 size - cnt_used_entries);
1701 if (cnt_driver_entries < 0)
1702 return cnt_driver_entries;
1703 cnt_used_entries += cnt_driver_entries;
1706 return cnt_used_entries;
1708 /* Get only xstats given by IDS */
1711 struct rte_eth_xstat_name *xstats_names_copy;
1713 len = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
1716 malloc(sizeof(struct rte_eth_xstat_name) * len);
1717 if (!xstats_names_copy) {
1718 RTE_PMD_DEBUG_TRACE(
1719 "ERROR: can't allocate memory for values_copy\n");
1720 free(xstats_names_copy);
1724 rte_eth_xstats_get_names_by_id(port_id, xstats_names_copy,
1727 for (i = 0; i < size; i++) {
1728 if (ids[i] >= len) {
1729 RTE_PMD_DEBUG_TRACE(
1730 "ERROR: id value isn't valid\n");
1733 strcpy(xstats_names[i].name,
1734 xstats_names_copy[ids[i]].name);
1736 free(xstats_names_copy);
1742 rte_eth_xstats_get_names(uint8_t port_id,
1743 struct rte_eth_xstat_name *xstats_names,
1746 struct rte_eth_dev *dev;
1747 int cnt_used_entries;
1748 int cnt_expected_entries;
1749 int cnt_driver_entries;
1750 uint32_t idx, id_queue;
1753 cnt_expected_entries = get_xstats_count(port_id);
1754 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1755 (int)size < cnt_expected_entries)
1756 return cnt_expected_entries;
1758 /* port_id checked in get_xstats_count() */
1759 dev = &rte_eth_devices[port_id];
1760 cnt_used_entries = 0;
1762 for (idx = 0; idx < RTE_NB_STATS; idx++) {
1763 snprintf(xstats_names[cnt_used_entries].name,
1764 sizeof(xstats_names[0].name),
1765 "%s", rte_stats_strings[idx].name);
1768 num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1769 for (id_queue = 0; id_queue < num_q; id_queue++) {
1770 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1771 snprintf(xstats_names[cnt_used_entries].name,
1772 sizeof(xstats_names[0].name),
1774 id_queue, rte_rxq_stats_strings[idx].name);
1779 num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1780 for (id_queue = 0; id_queue < num_q; id_queue++) {
1781 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
1782 snprintf(xstats_names[cnt_used_entries].name,
1783 sizeof(xstats_names[0].name),
1785 id_queue, rte_txq_stats_strings[idx].name);
1790 if (dev->dev_ops->xstats_get_names != NULL) {
1791 /* If there are any driver-specific xstats, append them
1794 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
1796 xstats_names + cnt_used_entries,
1797 size - cnt_used_entries);
1798 if (cnt_driver_entries < 0)
1799 return cnt_driver_entries;
1800 cnt_used_entries += cnt_driver_entries;
1803 return cnt_used_entries;
1806 /* retrieve ethdev extended statistics */
1808 rte_eth_xstats_get_by_id(uint8_t port_id, const uint64_t *ids, uint64_t *values,
1811 /* If need all xstats */
1813 struct rte_eth_stats eth_stats;
1814 struct rte_eth_dev *dev;
1815 unsigned int count = 0, i, q;
1816 signed int xcount = 0;
1817 uint64_t val, *stats_ptr;
1818 uint16_t nb_rxqs, nb_txqs;
1820 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1821 dev = &rte_eth_devices[port_id];
1823 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues,
1824 RTE_ETHDEV_QUEUE_STAT_CNTRS);
1825 nb_txqs = RTE_MIN(dev->data->nb_tx_queues,
1826 RTE_ETHDEV_QUEUE_STAT_CNTRS);
1828 /* Return generic statistics */
1829 count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
1830 (nb_txqs * RTE_NB_TXQ_STATS);
1833 /* implemented by the driver */
1834 if (dev->dev_ops->xstats_get_by_id != NULL) {
1835 /* Retrieve the xstats from the driver at the end of the
1836 * xstats struct. Retrieve all xstats.
1838 xcount = (*dev->dev_ops->xstats_get_by_id)(dev,
1840 values ? values + count : NULL,
1841 (n > count) ? n - count : 0);
1845 /* implemented by the driver */
1846 } else if (dev->dev_ops->xstats_get != NULL) {
1847 /* Retrieve the xstats from the driver at the end of the
1848 * xstats struct. Retrieve all xstats.
1849 * Compatibility for PMD without xstats_get_by_ids
1851 unsigned int size = (n > count) ? n - count : 1;
1852 struct rte_eth_xstat xstats[size];
1854 xcount = (*dev->dev_ops->xstats_get)(dev,
1855 values ? xstats : NULL, size);
1861 for (i = 0 ; i < (unsigned int)xcount; i++)
1862 values[i + count] = xstats[i].value;
1865 if (n < count + xcount || values == NULL)
1866 return count + xcount;
1868 /* now fill the xstats structure */
1870 rte_eth_stats_get(port_id, ð_stats);
1873 for (i = 0; i < RTE_NB_STATS; i++) {
1874 stats_ptr = RTE_PTR_ADD(ð_stats,
1875 rte_stats_strings[i].offset);
1877 values[count++] = val;
1881 for (q = 0; q < nb_rxqs; q++) {
1882 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1883 stats_ptr = RTE_PTR_ADD(ð_stats,
1884 rte_rxq_stats_strings[i].offset +
1885 q * sizeof(uint64_t));
1887 values[count++] = val;
1892 for (q = 0; q < nb_txqs; q++) {
1893 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1894 stats_ptr = RTE_PTR_ADD(ð_stats,
1895 rte_txq_stats_strings[i].offset +
1896 q * sizeof(uint64_t));
1898 values[count++] = val;
1902 return count + xcount;
1904 /* Need only xstats given by IDS array */
1907 uint64_t *values_copy;
1909 size = rte_eth_xstats_get_by_id(port_id, NULL, NULL, 0);
1911 values_copy = malloc(sizeof(*values_copy) * size);
1913 RTE_PMD_DEBUG_TRACE(
1914 "ERROR: can't allocate memory for values_copy\n");
1918 rte_eth_xstats_get_by_id(port_id, NULL, values_copy, size);
1920 for (i = 0; i < n; i++) {
1921 if (ids[i] >= size) {
1922 RTE_PMD_DEBUG_TRACE(
1923 "ERROR: id value isn't valid\n");
1926 values[i] = values_copy[ids[i]];
1934 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstat *xstats,
1937 struct rte_eth_stats eth_stats;
1938 struct rte_eth_dev *dev;
1939 unsigned int count = 0, i, q;
1940 signed int xcount = 0;
1941 uint64_t val, *stats_ptr;
1942 uint16_t nb_rxqs, nb_txqs;
1944 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1946 dev = &rte_eth_devices[port_id];
1948 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1949 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1951 /* Return generic statistics */
1952 count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
1953 (nb_txqs * RTE_NB_TXQ_STATS);
1955 /* implemented by the driver */
1956 if (dev->dev_ops->xstats_get != NULL) {
1957 /* Retrieve the xstats from the driver at the end of the
1960 xcount = (*dev->dev_ops->xstats_get)(dev,
1961 xstats ? xstats + count : NULL,
1962 (n > count) ? n - count : 0);
1968 if (n < count + xcount || xstats == NULL)
1969 return count + xcount;
1971 /* now fill the xstats structure */
1973 rte_eth_stats_get(port_id, ð_stats);
1976 for (i = 0; i < RTE_NB_STATS; i++) {
1977 stats_ptr = RTE_PTR_ADD(ð_stats,
1978 rte_stats_strings[i].offset);
1980 xstats[count++].value = val;
1984 for (q = 0; q < nb_rxqs; q++) {
1985 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1986 stats_ptr = RTE_PTR_ADD(ð_stats,
1987 rte_rxq_stats_strings[i].offset +
1988 q * sizeof(uint64_t));
1990 xstats[count++].value = val;
1995 for (q = 0; q < nb_txqs; q++) {
1996 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1997 stats_ptr = RTE_PTR_ADD(ð_stats,
1998 rte_txq_stats_strings[i].offset +
1999 q * sizeof(uint64_t));
2001 xstats[count++].value = val;
2005 for (i = 0; i < count; i++)
2007 /* add an offset to driver-specific stats */
2008 for ( ; i < count + xcount; i++)
2009 xstats[i].id += count;
2011 return count + xcount;
2014 /* reset ethdev extended statistics */
2016 rte_eth_xstats_reset(uint8_t port_id)
2018 struct rte_eth_dev *dev;
2020 RTE_ETH_VALID_PORTID_OR_RET(port_id);
2021 dev = &rte_eth_devices[port_id];
2023 /* implemented by the driver */
2024 if (dev->dev_ops->xstats_reset != NULL) {
2025 (*dev->dev_ops->xstats_reset)(dev);
2029 /* fallback to default */
2030 rte_eth_stats_reset(port_id);
2034 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
2037 struct rte_eth_dev *dev;
2039 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2041 dev = &rte_eth_devices[port_id];
2043 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
2044 return (*dev->dev_ops->queue_stats_mapping_set)
2045 (dev, queue_id, stat_idx, is_rx);
2050 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
2053 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
2059 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
2062 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
2067 rte_eth_dev_fw_version_get(uint8_t port_id, char *fw_version, size_t fw_size)
2069 struct rte_eth_dev *dev;
2071 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2072 dev = &rte_eth_devices[port_id];
2074 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP);
2075 return (*dev->dev_ops->fw_version_get)(dev, fw_version, fw_size);
2079 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
2081 struct rte_eth_dev *dev;
2082 const struct rte_eth_desc_lim lim = {
2083 .nb_max = UINT16_MAX,
2088 RTE_ETH_VALID_PORTID_OR_RET(port_id);
2089 dev = &rte_eth_devices[port_id];
2091 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
2092 dev_info->rx_desc_lim = lim;
2093 dev_info->tx_desc_lim = lim;
2095 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
2096 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
2097 dev_info->driver_name = dev->device->driver->name;
2098 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
2099 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
2103 rte_eth_dev_get_supported_ptypes(uint8_t port_id, uint32_t ptype_mask,
2104 uint32_t *ptypes, int num)
2107 struct rte_eth_dev *dev;
2108 const uint32_t *all_ptypes;
2110 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2111 dev = &rte_eth_devices[port_id];
2112 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
2113 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
2118 for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
2119 if (all_ptypes[i] & ptype_mask) {
2121 ptypes[j] = all_ptypes[i];
2129 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
2131 struct rte_eth_dev *dev;
2133 RTE_ETH_VALID_PORTID_OR_RET(port_id);
2134 dev = &rte_eth_devices[port_id];
2135 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
2140 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
2142 struct rte_eth_dev *dev;
2144 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2146 dev = &rte_eth_devices[port_id];
2147 *mtu = dev->data->mtu;
2152 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
2155 struct rte_eth_dev *dev;
2157 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2158 dev = &rte_eth_devices[port_id];
2159 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
2161 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
2163 dev->data->mtu = mtu;
2169 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
2171 struct rte_eth_dev *dev;
2174 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2175 dev = &rte_eth_devices[port_id];
2176 if (!(dev->data->dev_conf.rxmode.offloads &
2177 DEV_RX_OFFLOAD_VLAN_FILTER)) {
2178 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
2182 if (vlan_id > 4095) {
2183 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
2184 port_id, (unsigned) vlan_id);
2187 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
2189 ret = (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
2191 struct rte_vlan_filter_conf *vfc;
2195 vfc = &dev->data->vlan_filter_conf;
2196 vidx = vlan_id / 64;
2197 vbit = vlan_id % 64;
2200 vfc->ids[vidx] |= UINT64_C(1) << vbit;
2202 vfc->ids[vidx] &= ~(UINT64_C(1) << vbit);
2209 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
2211 struct rte_eth_dev *dev;
2213 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2214 dev = &rte_eth_devices[port_id];
2215 if (rx_queue_id >= dev->data->nb_rx_queues) {
2216 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
2220 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
2221 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
2227 rte_eth_dev_set_vlan_ether_type(uint8_t port_id,
2228 enum rte_vlan_type vlan_type,
2231 struct rte_eth_dev *dev;
2233 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2234 dev = &rte_eth_devices[port_id];
2235 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
2237 return (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type, tpid);
2241 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
2243 struct rte_eth_dev *dev;
2248 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2249 dev = &rte_eth_devices[port_id];
2251 /*check which option changed by application*/
2252 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
2253 org = !!(dev->data->dev_conf.rxmode.offloads &
2254 DEV_RX_OFFLOAD_VLAN_STRIP);
2257 dev->data->dev_conf.rxmode.offloads |=
2258 DEV_RX_OFFLOAD_VLAN_STRIP;
2260 dev->data->dev_conf.rxmode.offloads &=
2261 ~DEV_RX_OFFLOAD_VLAN_STRIP;
2262 mask |= ETH_VLAN_STRIP_MASK;
2265 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
2266 org = !!(dev->data->dev_conf.rxmode.offloads &
2267 DEV_RX_OFFLOAD_VLAN_FILTER);
2270 dev->data->dev_conf.rxmode.offloads |=
2271 DEV_RX_OFFLOAD_VLAN_FILTER;
2273 dev->data->dev_conf.rxmode.offloads &=
2274 ~DEV_RX_OFFLOAD_VLAN_FILTER;
2275 mask |= ETH_VLAN_FILTER_MASK;
2278 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
2279 org = !!(dev->data->dev_conf.rxmode.offloads &
2280 DEV_RX_OFFLOAD_VLAN_EXTEND);
2283 dev->data->dev_conf.rxmode.offloads |=
2284 DEV_RX_OFFLOAD_VLAN_EXTEND;
2286 dev->data->dev_conf.rxmode.offloads &=
2287 ~DEV_RX_OFFLOAD_VLAN_EXTEND;
2288 mask |= ETH_VLAN_EXTEND_MASK;
2295 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
2298 * Convert to the offload bitfield API just in case the underlying PMD
2299 * still supporting it.
2301 rte_eth_convert_rx_offloads(dev->data->dev_conf.rxmode.offloads,
2302 &dev->data->dev_conf.rxmode);
2303 (*dev->dev_ops->vlan_offload_set)(dev, mask);
2309 rte_eth_dev_get_vlan_offload(uint8_t port_id)
2311 struct rte_eth_dev *dev;
2314 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2315 dev = &rte_eth_devices[port_id];
2317 if (dev->data->dev_conf.rxmode.offloads &
2318 DEV_RX_OFFLOAD_VLAN_STRIP)
2319 ret |= ETH_VLAN_STRIP_OFFLOAD;
2321 if (dev->data->dev_conf.rxmode.offloads &
2322 DEV_RX_OFFLOAD_VLAN_FILTER)
2323 ret |= ETH_VLAN_FILTER_OFFLOAD;
2325 if (dev->data->dev_conf.rxmode.offloads &
2326 DEV_RX_OFFLOAD_VLAN_EXTEND)
2327 ret |= ETH_VLAN_EXTEND_OFFLOAD;
2333 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
2335 struct rte_eth_dev *dev;
2337 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2338 dev = &rte_eth_devices[port_id];
2339 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
2340 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
2346 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2348 struct rte_eth_dev *dev;
2350 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2351 dev = &rte_eth_devices[port_id];
2352 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2353 memset(fc_conf, 0, sizeof(*fc_conf));
2354 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
2358 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2360 struct rte_eth_dev *dev;
2362 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2363 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2364 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2368 dev = &rte_eth_devices[port_id];
2369 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2370 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
2374 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
2376 struct rte_eth_dev *dev;
2378 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2379 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2380 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2384 dev = &rte_eth_devices[port_id];
2385 /* High water, low water validation are device specific */
2386 if (*dev->dev_ops->priority_flow_ctrl_set)
2387 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
2392 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2400 num = (reta_size + RTE_RETA_GROUP_SIZE - 1) / RTE_RETA_GROUP_SIZE;
2401 for (i = 0; i < num; i++) {
2402 if (reta_conf[i].mask)
2410 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2414 uint16_t i, idx, shift;
2420 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
2424 for (i = 0; i < reta_size; i++) {
2425 idx = i / RTE_RETA_GROUP_SIZE;
2426 shift = i % RTE_RETA_GROUP_SIZE;
2427 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2428 (reta_conf[idx].reta[shift] >= max_rxq)) {
2429 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2430 "the maximum rxq index: %u\n", idx, shift,
2431 reta_conf[idx].reta[shift], max_rxq);
2440 rte_eth_dev_rss_reta_update(uint8_t port_id,
2441 struct rte_eth_rss_reta_entry64 *reta_conf,
2444 struct rte_eth_dev *dev;
2447 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2448 /* Check mask bits */
2449 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2453 dev = &rte_eth_devices[port_id];
2455 /* Check entry value */
2456 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2457 dev->data->nb_rx_queues);
2461 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2462 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2466 rte_eth_dev_rss_reta_query(uint8_t port_id,
2467 struct rte_eth_rss_reta_entry64 *reta_conf,
2470 struct rte_eth_dev *dev;
2473 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2475 /* Check mask bits */
2476 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2480 dev = &rte_eth_devices[port_id];
2481 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2482 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2486 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2488 struct rte_eth_dev *dev;
2490 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2491 dev = &rte_eth_devices[port_id];
2492 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2493 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2497 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2498 struct rte_eth_rss_conf *rss_conf)
2500 struct rte_eth_dev *dev;
2502 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2503 dev = &rte_eth_devices[port_id];
2504 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2505 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2509 rte_eth_dev_udp_tunnel_port_add(uint8_t port_id,
2510 struct rte_eth_udp_tunnel *udp_tunnel)
2512 struct rte_eth_dev *dev;
2514 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2515 if (udp_tunnel == NULL) {
2516 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2520 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2521 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2525 dev = &rte_eth_devices[port_id];
2526 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
2527 return (*dev->dev_ops->udp_tunnel_port_add)(dev, udp_tunnel);
2531 rte_eth_dev_udp_tunnel_port_delete(uint8_t port_id,
2532 struct rte_eth_udp_tunnel *udp_tunnel)
2534 struct rte_eth_dev *dev;
2536 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2537 dev = &rte_eth_devices[port_id];
2539 if (udp_tunnel == NULL) {
2540 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2544 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2545 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2549 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
2550 return (*dev->dev_ops->udp_tunnel_port_del)(dev, udp_tunnel);
2554 rte_eth_led_on(uint8_t port_id)
2556 struct rte_eth_dev *dev;
2558 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2559 dev = &rte_eth_devices[port_id];
2560 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2561 return (*dev->dev_ops->dev_led_on)(dev);
2565 rte_eth_led_off(uint8_t port_id)
2567 struct rte_eth_dev *dev;
2569 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2570 dev = &rte_eth_devices[port_id];
2571 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2572 return (*dev->dev_ops->dev_led_off)(dev);
2576 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2580 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2582 struct rte_eth_dev_info dev_info;
2583 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2586 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2587 rte_eth_dev_info_get(port_id, &dev_info);
2589 for (i = 0; i < dev_info.max_mac_addrs; i++)
2590 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2596 static const struct ether_addr null_mac_addr;
2599 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2602 struct rte_eth_dev *dev;
2607 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2608 dev = &rte_eth_devices[port_id];
2609 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2611 if (is_zero_ether_addr(addr)) {
2612 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2616 if (pool >= ETH_64_POOLS) {
2617 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2621 index = get_mac_addr_index(port_id, addr);
2623 index = get_mac_addr_index(port_id, &null_mac_addr);
2625 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2630 pool_mask = dev->data->mac_pool_sel[index];
2632 /* Check if both MAC address and pool is already there, and do nothing */
2633 if (pool_mask & (1ULL << pool))
2638 ret = (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2641 /* Update address in NIC data structure */
2642 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2644 /* Update pool bitmap in NIC data structure */
2645 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2652 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2654 struct rte_eth_dev *dev;
2657 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2658 dev = &rte_eth_devices[port_id];
2659 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2661 index = get_mac_addr_index(port_id, addr);
2663 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2665 } else if (index < 0)
2666 return 0; /* Do nothing if address wasn't found */
2669 (*dev->dev_ops->mac_addr_remove)(dev, index);
2671 /* Update address in NIC data structure */
2672 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2674 /* reset pool bitmap */
2675 dev->data->mac_pool_sel[index] = 0;
2681 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2683 struct rte_eth_dev *dev;
2685 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2687 if (!is_valid_assigned_ether_addr(addr))
2690 dev = &rte_eth_devices[port_id];
2691 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2693 /* Update default address in NIC data structure */
2694 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2696 (*dev->dev_ops->mac_addr_set)(dev, addr);
2703 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2707 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2709 struct rte_eth_dev_info dev_info;
2710 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2713 rte_eth_dev_info_get(port_id, &dev_info);
2714 if (!dev->data->hash_mac_addrs)
2717 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2718 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2719 ETHER_ADDR_LEN) == 0)
2726 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2731 struct rte_eth_dev *dev;
2733 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2735 dev = &rte_eth_devices[port_id];
2736 if (is_zero_ether_addr(addr)) {
2737 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2742 index = get_hash_mac_addr_index(port_id, addr);
2743 /* Check if it's already there, and do nothing */
2744 if ((index >= 0) && (on))
2749 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2750 "set in UTA\n", port_id);
2754 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2756 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2762 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2763 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2765 /* Update address in NIC data structure */
2767 ether_addr_copy(addr,
2768 &dev->data->hash_mac_addrs[index]);
2770 ether_addr_copy(&null_mac_addr,
2771 &dev->data->hash_mac_addrs[index]);
2778 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2780 struct rte_eth_dev *dev;
2782 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2784 dev = &rte_eth_devices[port_id];
2786 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2787 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2790 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2793 struct rte_eth_dev *dev;
2794 struct rte_eth_dev_info dev_info;
2795 struct rte_eth_link link;
2797 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2799 dev = &rte_eth_devices[port_id];
2800 rte_eth_dev_info_get(port_id, &dev_info);
2801 link = dev->data->dev_link;
2803 if (queue_idx > dev_info.max_tx_queues) {
2804 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2805 "invalid queue id=%d\n", port_id, queue_idx);
2809 if (tx_rate > link.link_speed) {
2810 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2811 "bigger than link speed= %d\n",
2812 tx_rate, link.link_speed);
2816 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2817 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2821 rte_eth_mirror_rule_set(uint8_t port_id,
2822 struct rte_eth_mirror_conf *mirror_conf,
2823 uint8_t rule_id, uint8_t on)
2825 struct rte_eth_dev *dev;
2827 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2828 if (mirror_conf->rule_type == 0) {
2829 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2833 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2834 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2839 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2840 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2841 (mirror_conf->pool_mask == 0)) {
2842 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2846 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2847 mirror_conf->vlan.vlan_mask == 0) {
2848 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2852 dev = &rte_eth_devices[port_id];
2853 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2855 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2859 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2861 struct rte_eth_dev *dev;
2863 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2865 dev = &rte_eth_devices[port_id];
2866 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2868 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2872 rte_eth_dev_callback_register(uint8_t port_id,
2873 enum rte_eth_event_type event,
2874 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2876 struct rte_eth_dev *dev;
2877 struct rte_eth_dev_callback *user_cb;
2882 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2884 dev = &rte_eth_devices[port_id];
2885 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2887 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2888 if (user_cb->cb_fn == cb_fn &&
2889 user_cb->cb_arg == cb_arg &&
2890 user_cb->event == event) {
2895 /* create a new callback. */
2896 if (user_cb == NULL) {
2897 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2898 sizeof(struct rte_eth_dev_callback), 0);
2899 if (user_cb != NULL) {
2900 user_cb->cb_fn = cb_fn;
2901 user_cb->cb_arg = cb_arg;
2902 user_cb->event = event;
2903 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2907 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2908 return (user_cb == NULL) ? -ENOMEM : 0;
2912 rte_eth_dev_callback_unregister(uint8_t port_id,
2913 enum rte_eth_event_type event,
2914 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2917 struct rte_eth_dev *dev;
2918 struct rte_eth_dev_callback *cb, *next;
2923 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2925 dev = &rte_eth_devices[port_id];
2926 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2929 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2931 next = TAILQ_NEXT(cb, next);
2933 if (cb->cb_fn != cb_fn || cb->event != event ||
2934 (cb->cb_arg != (void *)-1 &&
2935 cb->cb_arg != cb_arg))
2939 * if this callback is not executing right now,
2942 if (cb->active == 0) {
2943 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2950 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2955 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2956 enum rte_eth_event_type event, void *cb_arg, void *ret_param)
2958 struct rte_eth_dev_callback *cb_lst;
2959 struct rte_eth_dev_callback dev_cb;
2962 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2963 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2964 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2969 dev_cb.cb_arg = cb_arg;
2970 if (ret_param != NULL)
2971 dev_cb.ret_param = ret_param;
2973 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2974 rc = dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2975 dev_cb.cb_arg, dev_cb.ret_param);
2976 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2979 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2984 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
2987 struct rte_eth_dev *dev;
2988 struct rte_intr_handle *intr_handle;
2992 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2994 dev = &rte_eth_devices[port_id];
2996 if (!dev->intr_handle) {
2997 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
3001 intr_handle = dev->intr_handle;
3002 if (!intr_handle->intr_vec) {
3003 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
3007 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
3008 vec = intr_handle->intr_vec[qid];
3009 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
3010 if (rc && rc != -EEXIST) {
3011 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
3012 " op %d epfd %d vec %u\n",
3013 port_id, qid, op, epfd, vec);
3020 const struct rte_memzone *
3021 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
3022 uint16_t queue_id, size_t size, unsigned align,
3025 char z_name[RTE_MEMZONE_NAMESIZE];
3026 const struct rte_memzone *mz;
3028 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
3029 dev->device->driver->name, ring_name,
3030 dev->data->port_id, queue_id);
3032 mz = rte_memzone_lookup(z_name);
3036 if (rte_xen_dom0_supported())
3037 return rte_memzone_reserve_bounded(z_name, size, socket_id,
3038 0, align, RTE_PGSIZE_2M);
3040 return rte_memzone_reserve_aligned(z_name, size, socket_id,
3045 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
3046 int epfd, int op, void *data)
3049 struct rte_eth_dev *dev;
3050 struct rte_intr_handle *intr_handle;
3053 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3055 dev = &rte_eth_devices[port_id];
3056 if (queue_id >= dev->data->nb_rx_queues) {
3057 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
3061 if (!dev->intr_handle) {
3062 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
3066 intr_handle = dev->intr_handle;
3067 if (!intr_handle->intr_vec) {
3068 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
3072 vec = intr_handle->intr_vec[queue_id];
3073 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
3074 if (rc && rc != -EEXIST) {
3075 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
3076 " op %d epfd %d vec %u\n",
3077 port_id, queue_id, op, epfd, vec);
3085 rte_eth_dev_rx_intr_enable(uint8_t port_id,
3088 struct rte_eth_dev *dev;
3090 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3092 dev = &rte_eth_devices[port_id];
3094 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
3095 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
3099 rte_eth_dev_rx_intr_disable(uint8_t port_id,
3102 struct rte_eth_dev *dev;
3104 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3106 dev = &rte_eth_devices[port_id];
3108 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
3109 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
3114 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
3116 struct rte_eth_dev *dev;
3118 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3120 dev = &rte_eth_devices[port_id];
3121 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3122 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3123 RTE_ETH_FILTER_NOP, NULL);
3127 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
3128 enum rte_filter_op filter_op, void *arg)
3130 struct rte_eth_dev *dev;
3132 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3134 dev = &rte_eth_devices[port_id];
3135 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3136 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
3140 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
3141 rte_rx_callback_fn fn, void *user_param)
3143 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3144 rte_errno = ENOTSUP;
3147 /* check input parameters */
3148 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3149 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3153 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3161 cb->param = user_param;
3163 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3164 /* Add the callbacks in fifo order. */
3165 struct rte_eth_rxtx_callback *tail =
3166 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3169 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3176 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3182 rte_eth_add_first_rx_callback(uint8_t port_id, uint16_t queue_id,
3183 rte_rx_callback_fn fn, void *user_param)
3185 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3186 rte_errno = ENOTSUP;
3189 /* check input parameters */
3190 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3191 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3196 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3204 cb->param = user_param;
3206 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3207 /* Add the callbacks at fisrt position*/
3208 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3210 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3211 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3217 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
3218 rte_tx_callback_fn fn, void *user_param)
3220 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3221 rte_errno = ENOTSUP;
3224 /* check input parameters */
3225 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3226 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3231 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3239 cb->param = user_param;
3241 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3242 /* Add the callbacks in fifo order. */
3243 struct rte_eth_rxtx_callback *tail =
3244 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3247 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3254 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3260 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3261 struct rte_eth_rxtx_callback *user_cb)
3263 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3266 /* Check input parameters. */
3267 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3268 if (user_cb == NULL ||
3269 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
3272 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3273 struct rte_eth_rxtx_callback *cb;
3274 struct rte_eth_rxtx_callback **prev_cb;
3277 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3278 prev_cb = &dev->post_rx_burst_cbs[queue_id];
3279 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3281 if (cb == user_cb) {
3282 /* Remove the user cb from the callback list. */
3283 *prev_cb = cb->next;
3288 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3294 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3295 struct rte_eth_rxtx_callback *user_cb)
3297 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3300 /* Check input parameters. */
3301 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3302 if (user_cb == NULL ||
3303 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
3306 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3308 struct rte_eth_rxtx_callback *cb;
3309 struct rte_eth_rxtx_callback **prev_cb;
3311 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3312 prev_cb = &dev->pre_tx_burst_cbs[queue_id];
3313 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3315 if (cb == user_cb) {
3316 /* Remove the user cb from the callback list. */
3317 *prev_cb = cb->next;
3322 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3328 rte_eth_rx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3329 struct rte_eth_rxq_info *qinfo)
3331 struct rte_eth_dev *dev;
3333 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3338 dev = &rte_eth_devices[port_id];
3339 if (queue_id >= dev->data->nb_rx_queues) {
3340 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3344 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3346 memset(qinfo, 0, sizeof(*qinfo));
3347 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3352 rte_eth_tx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3353 struct rte_eth_txq_info *qinfo)
3355 struct rte_eth_dev *dev;
3357 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3362 dev = &rte_eth_devices[port_id];
3363 if (queue_id >= dev->data->nb_tx_queues) {
3364 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3368 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3370 memset(qinfo, 0, sizeof(*qinfo));
3371 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3376 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3377 struct ether_addr *mc_addr_set,
3378 uint32_t nb_mc_addr)
3380 struct rte_eth_dev *dev;
3382 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3384 dev = &rte_eth_devices[port_id];
3385 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3386 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3390 rte_eth_timesync_enable(uint8_t port_id)
3392 struct rte_eth_dev *dev;
3394 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3395 dev = &rte_eth_devices[port_id];
3397 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3398 return (*dev->dev_ops->timesync_enable)(dev);
3402 rte_eth_timesync_disable(uint8_t port_id)
3404 struct rte_eth_dev *dev;
3406 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3407 dev = &rte_eth_devices[port_id];
3409 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3410 return (*dev->dev_ops->timesync_disable)(dev);
3414 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3417 struct rte_eth_dev *dev;
3419 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3420 dev = &rte_eth_devices[port_id];
3422 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3423 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3427 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3429 struct rte_eth_dev *dev;
3431 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3432 dev = &rte_eth_devices[port_id];
3434 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3435 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3439 rte_eth_timesync_adjust_time(uint8_t port_id, int64_t delta)
3441 struct rte_eth_dev *dev;
3443 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3444 dev = &rte_eth_devices[port_id];
3446 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3447 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3451 rte_eth_timesync_read_time(uint8_t port_id, struct timespec *timestamp)
3453 struct rte_eth_dev *dev;
3455 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3456 dev = &rte_eth_devices[port_id];
3458 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3459 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3463 rte_eth_timesync_write_time(uint8_t port_id, const struct timespec *timestamp)
3465 struct rte_eth_dev *dev;
3467 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3468 dev = &rte_eth_devices[port_id];
3470 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3471 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3475 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3477 struct rte_eth_dev *dev;
3479 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3481 dev = &rte_eth_devices[port_id];
3482 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3483 return (*dev->dev_ops->get_reg)(dev, info);
3487 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3489 struct rte_eth_dev *dev;
3491 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3493 dev = &rte_eth_devices[port_id];
3494 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3495 return (*dev->dev_ops->get_eeprom_length)(dev);
3499 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3501 struct rte_eth_dev *dev;
3503 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3505 dev = &rte_eth_devices[port_id];
3506 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3507 return (*dev->dev_ops->get_eeprom)(dev, info);
3511 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3513 struct rte_eth_dev *dev;
3515 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3517 dev = &rte_eth_devices[port_id];
3518 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3519 return (*dev->dev_ops->set_eeprom)(dev, info);
3523 rte_eth_dev_get_dcb_info(uint8_t port_id,
3524 struct rte_eth_dcb_info *dcb_info)
3526 struct rte_eth_dev *dev;
3528 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3530 dev = &rte_eth_devices[port_id];
3531 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3533 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3534 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3538 rte_eth_dev_l2_tunnel_eth_type_conf(uint8_t port_id,
3539 struct rte_eth_l2_tunnel_conf *l2_tunnel)
3541 struct rte_eth_dev *dev;
3543 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3544 if (l2_tunnel == NULL) {
3545 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3549 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3550 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
3554 dev = &rte_eth_devices[port_id];
3555 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
3557 return (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev, l2_tunnel);
3561 rte_eth_dev_l2_tunnel_offload_set(uint8_t port_id,
3562 struct rte_eth_l2_tunnel_conf *l2_tunnel,
3566 struct rte_eth_dev *dev;
3568 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3570 if (l2_tunnel == NULL) {
3571 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3575 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3576 RTE_PMD_DEBUG_TRACE("Invalid tunnel type.\n");
3581 RTE_PMD_DEBUG_TRACE("Mask should have a value.\n");
3585 dev = &rte_eth_devices[port_id];
3586 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
3588 return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);
3592 rte_eth_dev_adjust_nb_desc(uint16_t *nb_desc,
3593 const struct rte_eth_desc_lim *desc_lim)
3595 if (desc_lim->nb_align != 0)
3596 *nb_desc = RTE_ALIGN_CEIL(*nb_desc, desc_lim->nb_align);
3598 if (desc_lim->nb_max != 0)
3599 *nb_desc = RTE_MIN(*nb_desc, desc_lim->nb_max);
3601 *nb_desc = RTE_MAX(*nb_desc, desc_lim->nb_min);
3605 rte_eth_dev_adjust_nb_rx_tx_desc(uint8_t port_id,
3606 uint16_t *nb_rx_desc,
3607 uint16_t *nb_tx_desc)
3609 struct rte_eth_dev *dev;
3610 struct rte_eth_dev_info dev_info;
3612 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3614 dev = &rte_eth_devices[port_id];
3615 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
3617 rte_eth_dev_info_get(port_id, &dev_info);
3619 if (nb_rx_desc != NULL)
3620 rte_eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim);
3622 if (nb_tx_desc != NULL)
3623 rte_eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim);