4 * Copyright(c) 2010-2016 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"
71 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
72 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
73 static struct rte_eth_dev_data *rte_eth_dev_data;
74 static uint8_t eth_dev_last_created_port;
75 static uint8_t nb_ports;
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 enum rte_eth_event_type event; /**< Interrupt event type */
133 uint32_t active; /**< Callback is executing */
142 rte_eth_find_next(uint8_t port_id)
144 while (port_id < RTE_MAX_ETHPORTS &&
145 rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED)
148 if (port_id >= RTE_MAX_ETHPORTS)
149 return RTE_MAX_ETHPORTS;
155 rte_eth_dev_data_alloc(void)
157 const unsigned flags = 0;
158 const struct rte_memzone *mz;
160 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
161 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
162 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
163 rte_socket_id(), flags);
165 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
167 rte_panic("Cannot allocate memzone for ethernet port data\n");
169 rte_eth_dev_data = mz->addr;
170 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
171 memset(rte_eth_dev_data, 0,
172 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
176 rte_eth_dev_allocated(const char *name)
180 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
181 if ((rte_eth_devices[i].state == RTE_ETH_DEV_ATTACHED) &&
182 strcmp(rte_eth_devices[i].data->name, name) == 0)
183 return &rte_eth_devices[i];
189 rte_eth_dev_find_free_port(void)
193 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
194 if (rte_eth_devices[i].state == RTE_ETH_DEV_UNUSED)
197 return RTE_MAX_ETHPORTS;
200 static struct rte_eth_dev *
201 eth_dev_get(uint8_t port_id)
203 struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
205 eth_dev->data = &rte_eth_dev_data[port_id];
206 eth_dev->state = RTE_ETH_DEV_ATTACHED;
207 TAILQ_INIT(&(eth_dev->link_intr_cbs));
209 eth_dev_last_created_port = port_id;
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;
288 rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
289 struct rte_pci_device *pci_dev)
291 struct eth_driver *eth_drv;
292 struct rte_eth_dev *eth_dev;
293 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
297 eth_drv = (struct eth_driver *)pci_drv;
299 rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
300 sizeof(ethdev_name));
302 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
303 eth_dev = rte_eth_dev_allocate(ethdev_name);
307 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
308 eth_drv->dev_private_size,
309 RTE_CACHE_LINE_SIZE);
310 if (eth_dev->data->dev_private == NULL)
311 rte_panic("Cannot allocate memzone for private port data\n");
313 eth_dev = rte_eth_dev_attach_secondary(ethdev_name);
314 if (eth_dev == NULL) {
316 * if we failed to attach a device, it means the
317 * device is skipped in primary process, due to
318 * some errors. If so, we return a positive value,
319 * to let EAL skip it for the secondary process
325 eth_dev->device = &pci_dev->device;
326 eth_dev->intr_handle = &pci_dev->intr_handle;
327 eth_dev->driver = eth_drv;
329 /* Invoke PMD device initialization function */
330 diag = (*eth_drv->eth_dev_init)(eth_dev);
334 RTE_PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%x device_id=0x%x) failed\n",
335 pci_drv->driver.name,
336 (unsigned) pci_dev->id.vendor_id,
337 (unsigned) pci_dev->id.device_id);
338 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
339 rte_free(eth_dev->data->dev_private);
340 rte_eth_dev_release_port(eth_dev);
345 rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
347 const struct eth_driver *eth_drv;
348 struct rte_eth_dev *eth_dev;
349 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
355 rte_eal_pci_device_name(&pci_dev->addr, ethdev_name,
356 sizeof(ethdev_name));
358 eth_dev = rte_eth_dev_allocated(ethdev_name);
362 eth_drv = (const struct eth_driver *)pci_dev->driver;
364 /* Invoke PMD device uninit function */
365 if (*eth_drv->eth_dev_uninit) {
366 ret = (*eth_drv->eth_dev_uninit)(eth_dev);
371 /* free ether device */
372 rte_eth_dev_release_port(eth_dev);
374 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
375 rte_free(eth_dev->data->dev_private);
377 eth_dev->device = NULL;
378 eth_dev->driver = NULL;
379 eth_dev->data = NULL;
385 rte_eth_dev_is_valid_port(uint8_t port_id)
387 if (port_id >= RTE_MAX_ETHPORTS ||
388 rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED)
395 rte_eth_dev_socket_id(uint8_t port_id)
397 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
398 return rte_eth_devices[port_id].data->numa_node;
402 rte_eth_dev_count(void)
408 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
412 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
415 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
419 /* shouldn't check 'rte_eth_devices[i].data',
420 * because it might be overwritten by VDEV PMD */
421 tmp = rte_eth_dev_data[port_id].name;
427 rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
432 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
439 *port_id = RTE_MAX_ETHPORTS;
440 RTE_ETH_FOREACH_DEV(i) {
442 rte_eth_dev_data[i].name, strlen(name))) {
453 rte_eth_dev_is_detachable(uint8_t port_id)
457 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
459 switch (rte_eth_devices[port_id].data->kdrv) {
460 case RTE_KDRV_IGB_UIO:
461 case RTE_KDRV_UIO_GENERIC:
462 case RTE_KDRV_NIC_UIO:
469 dev_flags = rte_eth_devices[port_id].data->dev_flags;
470 if ((dev_flags & RTE_ETH_DEV_DETACHABLE) &&
471 (!(dev_flags & RTE_ETH_DEV_BONDED_SLAVE)))
477 /* attach the new device, then store port_id of the device */
479 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
482 int current = rte_eth_dev_count();
486 if ((devargs == NULL) || (port_id == NULL)) {
491 /* parse devargs, then retrieve device name and args */
492 if (rte_eal_parse_devargs_str(devargs, &name, &args))
495 ret = rte_eal_dev_attach(name, args);
499 /* no point looking at the port count if no port exists */
500 if (!rte_eth_dev_count()) {
501 RTE_LOG(ERR, EAL, "No port found for device (%s)\n", name);
506 /* if nothing happened, there is a bug here, since some driver told us
507 * it did attach a device, but did not create a port.
509 if (current == rte_eth_dev_count()) {
514 *port_id = eth_dev_last_created_port;
523 /* detach the device, then store the name of the device */
525 rte_eth_dev_detach(uint8_t port_id, char *name)
534 /* FIXME: move this to eal, once device flags are relocated there */
535 if (rte_eth_dev_is_detachable(port_id))
538 snprintf(name, sizeof(rte_eth_devices[port_id].data->name),
539 "%s", rte_eth_devices[port_id].data->name);
540 ret = rte_eal_dev_detach(name);
551 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
553 uint16_t old_nb_queues = dev->data->nb_rx_queues;
557 if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */
558 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
559 sizeof(dev->data->rx_queues[0]) * nb_queues,
560 RTE_CACHE_LINE_SIZE);
561 if (dev->data->rx_queues == NULL) {
562 dev->data->nb_rx_queues = 0;
565 } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */
566 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
568 rxq = dev->data->rx_queues;
570 for (i = nb_queues; i < old_nb_queues; i++)
571 (*dev->dev_ops->rx_queue_release)(rxq[i]);
572 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
573 RTE_CACHE_LINE_SIZE);
576 if (nb_queues > old_nb_queues) {
577 uint16_t new_qs = nb_queues - old_nb_queues;
579 memset(rxq + old_nb_queues, 0,
580 sizeof(rxq[0]) * new_qs);
583 dev->data->rx_queues = rxq;
585 } else if (dev->data->rx_queues != NULL && nb_queues == 0) {
586 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
588 rxq = dev->data->rx_queues;
590 for (i = nb_queues; i < old_nb_queues; i++)
591 (*dev->dev_ops->rx_queue_release)(rxq[i]);
593 rte_free(dev->data->rx_queues);
594 dev->data->rx_queues = NULL;
596 dev->data->nb_rx_queues = nb_queues;
601 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
603 struct rte_eth_dev *dev;
605 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
607 dev = &rte_eth_devices[port_id];
608 if (rx_queue_id >= dev->data->nb_rx_queues) {
609 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
613 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
615 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
616 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
617 " already started\n",
618 rx_queue_id, port_id);
622 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
627 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
629 struct rte_eth_dev *dev;
631 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
633 dev = &rte_eth_devices[port_id];
634 if (rx_queue_id >= dev->data->nb_rx_queues) {
635 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
639 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
641 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
642 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
643 " already stopped\n",
644 rx_queue_id, port_id);
648 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
653 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
655 struct rte_eth_dev *dev;
657 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
659 dev = &rte_eth_devices[port_id];
660 if (tx_queue_id >= dev->data->nb_tx_queues) {
661 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
665 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
667 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
668 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
669 " already started\n",
670 tx_queue_id, port_id);
674 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
679 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
681 struct rte_eth_dev *dev;
683 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
685 dev = &rte_eth_devices[port_id];
686 if (tx_queue_id >= dev->data->nb_tx_queues) {
687 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
691 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
693 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
694 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
695 " already stopped\n",
696 tx_queue_id, port_id);
700 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
705 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
707 uint16_t old_nb_queues = dev->data->nb_tx_queues;
711 if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */
712 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
713 sizeof(dev->data->tx_queues[0]) * nb_queues,
714 RTE_CACHE_LINE_SIZE);
715 if (dev->data->tx_queues == NULL) {
716 dev->data->nb_tx_queues = 0;
719 } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */
720 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
722 txq = dev->data->tx_queues;
724 for (i = nb_queues; i < old_nb_queues; i++)
725 (*dev->dev_ops->tx_queue_release)(txq[i]);
726 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
727 RTE_CACHE_LINE_SIZE);
730 if (nb_queues > old_nb_queues) {
731 uint16_t new_qs = nb_queues - old_nb_queues;
733 memset(txq + old_nb_queues, 0,
734 sizeof(txq[0]) * new_qs);
737 dev->data->tx_queues = txq;
739 } else if (dev->data->tx_queues != NULL && nb_queues == 0) {
740 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
742 txq = dev->data->tx_queues;
744 for (i = nb_queues; i < old_nb_queues; i++)
745 (*dev->dev_ops->tx_queue_release)(txq[i]);
747 rte_free(dev->data->tx_queues);
748 dev->data->tx_queues = NULL;
750 dev->data->nb_tx_queues = nb_queues;
755 rte_eth_speed_bitflag(uint32_t speed, int duplex)
758 case ETH_SPEED_NUM_10M:
759 return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD;
760 case ETH_SPEED_NUM_100M:
761 return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD;
762 case ETH_SPEED_NUM_1G:
763 return ETH_LINK_SPEED_1G;
764 case ETH_SPEED_NUM_2_5G:
765 return ETH_LINK_SPEED_2_5G;
766 case ETH_SPEED_NUM_5G:
767 return ETH_LINK_SPEED_5G;
768 case ETH_SPEED_NUM_10G:
769 return ETH_LINK_SPEED_10G;
770 case ETH_SPEED_NUM_20G:
771 return ETH_LINK_SPEED_20G;
772 case ETH_SPEED_NUM_25G:
773 return ETH_LINK_SPEED_25G;
774 case ETH_SPEED_NUM_40G:
775 return ETH_LINK_SPEED_40G;
776 case ETH_SPEED_NUM_50G:
777 return ETH_LINK_SPEED_50G;
778 case ETH_SPEED_NUM_56G:
779 return ETH_LINK_SPEED_56G;
780 case ETH_SPEED_NUM_100G:
781 return ETH_LINK_SPEED_100G;
788 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
789 const struct rte_eth_conf *dev_conf)
791 struct rte_eth_dev *dev;
792 struct rte_eth_dev_info dev_info;
795 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
797 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
799 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
800 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
804 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
806 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
807 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
811 dev = &rte_eth_devices[port_id];
813 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
814 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
816 if (dev->data->dev_started) {
818 "port %d must be stopped to allow configuration\n", port_id);
822 /* Copy the dev_conf parameter into the dev structure */
823 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
826 * Check that the numbers of RX and TX queues are not greater
827 * than the maximum number of RX and TX queues supported by the
830 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
832 if (nb_rx_q == 0 && nb_tx_q == 0) {
833 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d both rx and tx queue cannot be 0\n", port_id);
837 if (nb_rx_q > dev_info.max_rx_queues) {
838 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
839 port_id, nb_rx_q, dev_info.max_rx_queues);
843 if (nb_tx_q > dev_info.max_tx_queues) {
844 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
845 port_id, nb_tx_q, dev_info.max_tx_queues);
850 * If link state interrupt is enabled, check that the
851 * device supports it.
853 if ((dev_conf->intr_conf.lsc == 1) &&
854 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
855 RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
856 dev->data->drv_name);
861 * If jumbo frames are enabled, check that the maximum RX packet
862 * length is supported by the configured device.
864 if (dev_conf->rxmode.jumbo_frame == 1) {
865 if (dev_conf->rxmode.max_rx_pkt_len >
866 dev_info.max_rx_pktlen) {
867 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
868 " > max valid value %u\n",
870 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
871 (unsigned)dev_info.max_rx_pktlen);
873 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
874 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
875 " < min valid value %u\n",
877 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
878 (unsigned)ETHER_MIN_LEN);
882 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
883 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
884 /* Use default value */
885 dev->data->dev_conf.rxmode.max_rx_pkt_len =
890 * Setup new number of RX/TX queues and reconfigure device.
892 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
894 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
899 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
901 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
903 rte_eth_dev_rx_queue_config(dev, 0);
907 diag = (*dev->dev_ops->dev_configure)(dev);
909 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
911 rte_eth_dev_rx_queue_config(dev, 0);
912 rte_eth_dev_tx_queue_config(dev, 0);
920 _rte_eth_dev_reset(struct rte_eth_dev *dev)
922 if (dev->data->dev_started) {
924 "port %d must be stopped to allow reset\n",
929 rte_eth_dev_rx_queue_config(dev, 0);
930 rte_eth_dev_tx_queue_config(dev, 0);
932 memset(&dev->data->dev_conf, 0, sizeof(dev->data->dev_conf));
936 rte_eth_dev_config_restore(uint8_t port_id)
938 struct rte_eth_dev *dev;
939 struct rte_eth_dev_info dev_info;
940 struct ether_addr *addr;
945 dev = &rte_eth_devices[port_id];
947 rte_eth_dev_info_get(port_id, &dev_info);
949 /* replay MAC address configuration including default MAC */
950 addr = &dev->data->mac_addrs[0];
951 if (*dev->dev_ops->mac_addr_set != NULL)
952 (*dev->dev_ops->mac_addr_set)(dev, addr);
953 else if (*dev->dev_ops->mac_addr_add != NULL)
954 (*dev->dev_ops->mac_addr_add)(dev, addr, 0, pool);
956 if (*dev->dev_ops->mac_addr_add != NULL) {
957 for (i = 1; i < dev_info.max_mac_addrs; i++) {
958 addr = &dev->data->mac_addrs[i];
960 /* skip zero address */
961 if (is_zero_ether_addr(addr))
965 pool_mask = dev->data->mac_pool_sel[i];
968 if (pool_mask & 1ULL)
969 (*dev->dev_ops->mac_addr_add)(dev,
977 /* replay promiscuous configuration */
978 if (rte_eth_promiscuous_get(port_id) == 1)
979 rte_eth_promiscuous_enable(port_id);
980 else if (rte_eth_promiscuous_get(port_id) == 0)
981 rte_eth_promiscuous_disable(port_id);
983 /* replay all multicast configuration */
984 if (rte_eth_allmulticast_get(port_id) == 1)
985 rte_eth_allmulticast_enable(port_id);
986 else if (rte_eth_allmulticast_get(port_id) == 0)
987 rte_eth_allmulticast_disable(port_id);
991 rte_eth_dev_start(uint8_t port_id)
993 struct rte_eth_dev *dev;
996 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
998 dev = &rte_eth_devices[port_id];
1000 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1002 if (dev->data->dev_started != 0) {
1003 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1004 " already started\n",
1009 diag = (*dev->dev_ops->dev_start)(dev);
1011 dev->data->dev_started = 1;
1015 rte_eth_dev_config_restore(port_id);
1017 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1018 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1019 (*dev->dev_ops->link_update)(dev, 0);
1025 rte_eth_dev_stop(uint8_t port_id)
1027 struct rte_eth_dev *dev;
1029 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1030 dev = &rte_eth_devices[port_id];
1032 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1034 if (dev->data->dev_started == 0) {
1035 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1036 " already stopped\n",
1041 dev->data->dev_started = 0;
1042 (*dev->dev_ops->dev_stop)(dev);
1046 rte_eth_dev_set_link_up(uint8_t port_id)
1048 struct rte_eth_dev *dev;
1050 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1052 dev = &rte_eth_devices[port_id];
1054 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1055 return (*dev->dev_ops->dev_set_link_up)(dev);
1059 rte_eth_dev_set_link_down(uint8_t port_id)
1061 struct rte_eth_dev *dev;
1063 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1065 dev = &rte_eth_devices[port_id];
1067 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1068 return (*dev->dev_ops->dev_set_link_down)(dev);
1072 rte_eth_dev_close(uint8_t port_id)
1074 struct rte_eth_dev *dev;
1076 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1077 dev = &rte_eth_devices[port_id];
1079 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1080 dev->data->dev_started = 0;
1081 (*dev->dev_ops->dev_close)(dev);
1083 rte_free(dev->data->rx_queues);
1084 dev->data->rx_queues = NULL;
1085 rte_free(dev->data->tx_queues);
1086 dev->data->tx_queues = NULL;
1090 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1091 uint16_t nb_rx_desc, unsigned int socket_id,
1092 const struct rte_eth_rxconf *rx_conf,
1093 struct rte_mempool *mp)
1096 uint32_t mbp_buf_size;
1097 struct rte_eth_dev *dev;
1098 struct rte_eth_dev_info dev_info;
1101 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1103 dev = &rte_eth_devices[port_id];
1104 if (rx_queue_id >= dev->data->nb_rx_queues) {
1105 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1109 if (dev->data->dev_started) {
1110 RTE_PMD_DEBUG_TRACE(
1111 "port %d must be stopped to allow configuration\n", port_id);
1115 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1116 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1119 * Check the size of the mbuf data buffer.
1120 * This value must be provided in the private data of the memory pool.
1121 * First check that the memory pool has a valid private data.
1123 rte_eth_dev_info_get(port_id, &dev_info);
1124 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1125 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1126 mp->name, (int) mp->private_data_size,
1127 (int) sizeof(struct rte_pktmbuf_pool_private));
1130 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1132 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1133 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1134 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1138 (int)(RTE_PKTMBUF_HEADROOM +
1139 dev_info.min_rx_bufsize),
1140 (int)RTE_PKTMBUF_HEADROOM,
1141 (int)dev_info.min_rx_bufsize);
1145 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1146 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1147 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1149 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1150 "should be: <= %hu, = %hu, and a product of %hu\n",
1152 dev_info.rx_desc_lim.nb_max,
1153 dev_info.rx_desc_lim.nb_min,
1154 dev_info.rx_desc_lim.nb_align);
1158 rxq = dev->data->rx_queues;
1159 if (rxq[rx_queue_id]) {
1160 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release,
1162 (*dev->dev_ops->rx_queue_release)(rxq[rx_queue_id]);
1163 rxq[rx_queue_id] = NULL;
1166 if (rx_conf == NULL)
1167 rx_conf = &dev_info.default_rxconf;
1169 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1170 socket_id, rx_conf, mp);
1172 if (!dev->data->min_rx_buf_size ||
1173 dev->data->min_rx_buf_size > mbp_buf_size)
1174 dev->data->min_rx_buf_size = mbp_buf_size;
1181 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1182 uint16_t nb_tx_desc, unsigned int socket_id,
1183 const struct rte_eth_txconf *tx_conf)
1185 struct rte_eth_dev *dev;
1186 struct rte_eth_dev_info dev_info;
1189 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1191 dev = &rte_eth_devices[port_id];
1192 if (tx_queue_id >= dev->data->nb_tx_queues) {
1193 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1197 if (dev->data->dev_started) {
1198 RTE_PMD_DEBUG_TRACE(
1199 "port %d must be stopped to allow configuration\n", port_id);
1203 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1204 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1206 rte_eth_dev_info_get(port_id, &dev_info);
1208 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1209 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1210 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1211 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1212 "should be: <= %hu, = %hu, and a product of %hu\n",
1214 dev_info.tx_desc_lim.nb_max,
1215 dev_info.tx_desc_lim.nb_min,
1216 dev_info.tx_desc_lim.nb_align);
1220 txq = dev->data->tx_queues;
1221 if (txq[tx_queue_id]) {
1222 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release,
1224 (*dev->dev_ops->tx_queue_release)(txq[tx_queue_id]);
1225 txq[tx_queue_id] = NULL;
1228 if (tx_conf == NULL)
1229 tx_conf = &dev_info.default_txconf;
1231 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1232 socket_id, tx_conf);
1236 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
1237 void *userdata __rte_unused)
1241 for (i = 0; i < unsent; i++)
1242 rte_pktmbuf_free(pkts[i]);
1246 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
1249 uint64_t *count = userdata;
1252 for (i = 0; i < unsent; i++)
1253 rte_pktmbuf_free(pkts[i]);
1259 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
1260 buffer_tx_error_fn cbfn, void *userdata)
1262 buffer->error_callback = cbfn;
1263 buffer->error_userdata = userdata;
1268 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
1275 buffer->size = size;
1276 if (buffer->error_callback == NULL) {
1277 ret = rte_eth_tx_buffer_set_err_callback(
1278 buffer, rte_eth_tx_buffer_drop_callback, NULL);
1285 rte_eth_tx_done_cleanup(uint8_t port_id, uint16_t queue_id, uint32_t free_cnt)
1287 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1289 /* Validate Input Data. Bail if not valid or not supported. */
1290 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1291 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_done_cleanup, -ENOTSUP);
1293 /* Call driver to free pending mbufs. */
1294 return (*dev->dev_ops->tx_done_cleanup)(dev->data->tx_queues[queue_id],
1299 rte_eth_promiscuous_enable(uint8_t port_id)
1301 struct rte_eth_dev *dev;
1303 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1304 dev = &rte_eth_devices[port_id];
1306 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1307 (*dev->dev_ops->promiscuous_enable)(dev);
1308 dev->data->promiscuous = 1;
1312 rte_eth_promiscuous_disable(uint8_t port_id)
1314 struct rte_eth_dev *dev;
1316 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1317 dev = &rte_eth_devices[port_id];
1319 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1320 dev->data->promiscuous = 0;
1321 (*dev->dev_ops->promiscuous_disable)(dev);
1325 rte_eth_promiscuous_get(uint8_t port_id)
1327 struct rte_eth_dev *dev;
1329 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1331 dev = &rte_eth_devices[port_id];
1332 return dev->data->promiscuous;
1336 rte_eth_allmulticast_enable(uint8_t port_id)
1338 struct rte_eth_dev *dev;
1340 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1341 dev = &rte_eth_devices[port_id];
1343 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1344 (*dev->dev_ops->allmulticast_enable)(dev);
1345 dev->data->all_multicast = 1;
1349 rte_eth_allmulticast_disable(uint8_t port_id)
1351 struct rte_eth_dev *dev;
1353 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1354 dev = &rte_eth_devices[port_id];
1356 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1357 dev->data->all_multicast = 0;
1358 (*dev->dev_ops->allmulticast_disable)(dev);
1362 rte_eth_allmulticast_get(uint8_t port_id)
1364 struct rte_eth_dev *dev;
1366 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1368 dev = &rte_eth_devices[port_id];
1369 return dev->data->all_multicast;
1373 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1374 struct rte_eth_link *link)
1376 struct rte_eth_link *dst = link;
1377 struct rte_eth_link *src = &(dev->data->dev_link);
1379 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1380 *(uint64_t *)src) == 0)
1387 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1389 struct rte_eth_dev *dev;
1391 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1392 dev = &rte_eth_devices[port_id];
1394 if (dev->data->dev_conf.intr_conf.lsc != 0)
1395 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1397 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1398 (*dev->dev_ops->link_update)(dev, 1);
1399 *eth_link = dev->data->dev_link;
1404 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1406 struct rte_eth_dev *dev;
1408 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1409 dev = &rte_eth_devices[port_id];
1411 if (dev->data->dev_conf.intr_conf.lsc != 0)
1412 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1414 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1415 (*dev->dev_ops->link_update)(dev, 0);
1416 *eth_link = dev->data->dev_link;
1421 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1423 struct rte_eth_dev *dev;
1425 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1427 dev = &rte_eth_devices[port_id];
1428 memset(stats, 0, sizeof(*stats));
1430 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1431 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1432 (*dev->dev_ops->stats_get)(dev, stats);
1437 rte_eth_stats_reset(uint8_t port_id)
1439 struct rte_eth_dev *dev;
1441 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1442 dev = &rte_eth_devices[port_id];
1444 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1445 (*dev->dev_ops->stats_reset)(dev);
1446 dev->data->rx_mbuf_alloc_failed = 0;
1450 get_xstats_count(uint8_t port_id)
1452 struct rte_eth_dev *dev;
1455 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1456 dev = &rte_eth_devices[port_id];
1457 if (dev->dev_ops->xstats_get_names != NULL) {
1458 count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0);
1463 count += RTE_NB_STATS;
1464 count += RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
1466 count += RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS) *
1472 rte_eth_xstats_get_names(uint8_t port_id,
1473 struct rte_eth_xstat_name *xstats_names,
1476 struct rte_eth_dev *dev;
1477 int cnt_used_entries;
1478 int cnt_expected_entries;
1479 int cnt_driver_entries;
1480 uint32_t idx, id_queue;
1483 cnt_expected_entries = get_xstats_count(port_id);
1484 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1485 (int)size < cnt_expected_entries)
1486 return cnt_expected_entries;
1488 /* port_id checked in get_xstats_count() */
1489 dev = &rte_eth_devices[port_id];
1490 cnt_used_entries = 0;
1492 for (idx = 0; idx < RTE_NB_STATS; idx++) {
1493 snprintf(xstats_names[cnt_used_entries].name,
1494 sizeof(xstats_names[0].name),
1495 "%s", rte_stats_strings[idx].name);
1498 num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1499 for (id_queue = 0; id_queue < num_q; id_queue++) {
1500 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1501 snprintf(xstats_names[cnt_used_entries].name,
1502 sizeof(xstats_names[0].name),
1504 id_queue, rte_rxq_stats_strings[idx].name);
1509 num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1510 for (id_queue = 0; id_queue < num_q; id_queue++) {
1511 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
1512 snprintf(xstats_names[cnt_used_entries].name,
1513 sizeof(xstats_names[0].name),
1515 id_queue, rte_txq_stats_strings[idx].name);
1520 if (dev->dev_ops->xstats_get_names != NULL) {
1521 /* If there are any driver-specific xstats, append them
1524 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
1526 xstats_names + cnt_used_entries,
1527 size - cnt_used_entries);
1528 if (cnt_driver_entries < 0)
1529 return cnt_driver_entries;
1530 cnt_used_entries += cnt_driver_entries;
1533 return cnt_used_entries;
1536 /* retrieve ethdev extended statistics */
1538 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstat *xstats,
1541 struct rte_eth_stats eth_stats;
1542 struct rte_eth_dev *dev;
1543 unsigned count = 0, i, q;
1545 uint64_t val, *stats_ptr;
1546 uint16_t nb_rxqs, nb_txqs;
1548 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1550 dev = &rte_eth_devices[port_id];
1552 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1553 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1555 /* Return generic statistics */
1556 count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
1557 (nb_txqs * RTE_NB_TXQ_STATS);
1559 /* implemented by the driver */
1560 if (dev->dev_ops->xstats_get != NULL) {
1561 /* Retrieve the xstats from the driver at the end of the
1564 xcount = (*dev->dev_ops->xstats_get)(dev,
1565 xstats ? xstats + count : NULL,
1566 (n > count) ? n - count : 0);
1572 if (n < count + xcount || xstats == NULL)
1573 return count + xcount;
1575 /* now fill the xstats structure */
1577 rte_eth_stats_get(port_id, ð_stats);
1580 for (i = 0; i < RTE_NB_STATS; i++) {
1581 stats_ptr = RTE_PTR_ADD(ð_stats,
1582 rte_stats_strings[i].offset);
1584 xstats[count++].value = val;
1588 for (q = 0; q < nb_rxqs; q++) {
1589 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1590 stats_ptr = RTE_PTR_ADD(ð_stats,
1591 rte_rxq_stats_strings[i].offset +
1592 q * sizeof(uint64_t));
1594 xstats[count++].value = val;
1599 for (q = 0; q < nb_txqs; q++) {
1600 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1601 stats_ptr = RTE_PTR_ADD(ð_stats,
1602 rte_txq_stats_strings[i].offset +
1603 q * sizeof(uint64_t));
1605 xstats[count++].value = val;
1609 for (i = 0; i < count; i++)
1611 /* add an offset to driver-specific stats */
1612 for ( ; i < count + xcount; i++)
1613 xstats[i].id += count;
1615 return count + xcount;
1618 /* reset ethdev extended statistics */
1620 rte_eth_xstats_reset(uint8_t port_id)
1622 struct rte_eth_dev *dev;
1624 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1625 dev = &rte_eth_devices[port_id];
1627 /* implemented by the driver */
1628 if (dev->dev_ops->xstats_reset != NULL) {
1629 (*dev->dev_ops->xstats_reset)(dev);
1633 /* fallback to default */
1634 rte_eth_stats_reset(port_id);
1638 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1641 struct rte_eth_dev *dev;
1643 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1645 dev = &rte_eth_devices[port_id];
1647 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1648 return (*dev->dev_ops->queue_stats_mapping_set)
1649 (dev, queue_id, stat_idx, is_rx);
1654 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1657 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1663 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1666 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1671 rte_eth_dev_fw_version_get(uint8_t port_id, char *fw_version, size_t fw_size)
1673 struct rte_eth_dev *dev;
1675 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1676 dev = &rte_eth_devices[port_id];
1678 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP);
1679 return (*dev->dev_ops->fw_version_get)(dev, fw_version, fw_size);
1683 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1685 struct rte_eth_dev *dev;
1686 const struct rte_eth_desc_lim lim = {
1687 .nb_max = UINT16_MAX,
1692 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1693 dev = &rte_eth_devices[port_id];
1695 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1696 dev_info->rx_desc_lim = lim;
1697 dev_info->tx_desc_lim = lim;
1699 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1700 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1701 dev_info->driver_name = dev->data->drv_name;
1702 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
1703 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
1707 rte_eth_dev_get_supported_ptypes(uint8_t port_id, uint32_t ptype_mask,
1708 uint32_t *ptypes, int num)
1711 struct rte_eth_dev *dev;
1712 const uint32_t *all_ptypes;
1714 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1715 dev = &rte_eth_devices[port_id];
1716 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
1717 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
1722 for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
1723 if (all_ptypes[i] & ptype_mask) {
1725 ptypes[j] = all_ptypes[i];
1733 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1735 struct rte_eth_dev *dev;
1737 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1738 dev = &rte_eth_devices[port_id];
1739 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1744 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1746 struct rte_eth_dev *dev;
1748 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1750 dev = &rte_eth_devices[port_id];
1751 *mtu = dev->data->mtu;
1756 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1759 struct rte_eth_dev *dev;
1761 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1762 dev = &rte_eth_devices[port_id];
1763 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1765 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1767 dev->data->mtu = mtu;
1773 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1775 struct rte_eth_dev *dev;
1777 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1778 dev = &rte_eth_devices[port_id];
1779 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1780 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1784 if (vlan_id > 4095) {
1785 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1786 port_id, (unsigned) vlan_id);
1789 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1791 return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1795 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1797 struct rte_eth_dev *dev;
1799 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1800 dev = &rte_eth_devices[port_id];
1801 if (rx_queue_id >= dev->data->nb_rx_queues) {
1802 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1806 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1807 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1813 rte_eth_dev_set_vlan_ether_type(uint8_t port_id,
1814 enum rte_vlan_type vlan_type,
1817 struct rte_eth_dev *dev;
1819 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1820 dev = &rte_eth_devices[port_id];
1821 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1823 return (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type, tpid);
1827 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1829 struct rte_eth_dev *dev;
1834 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1835 dev = &rte_eth_devices[port_id];
1837 /*check which option changed by application*/
1838 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1839 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1841 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1842 mask |= ETH_VLAN_STRIP_MASK;
1845 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1846 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1848 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1849 mask |= ETH_VLAN_FILTER_MASK;
1852 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1853 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1855 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1856 mask |= ETH_VLAN_EXTEND_MASK;
1863 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1864 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1870 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1872 struct rte_eth_dev *dev;
1875 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1876 dev = &rte_eth_devices[port_id];
1878 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1879 ret |= ETH_VLAN_STRIP_OFFLOAD;
1881 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1882 ret |= ETH_VLAN_FILTER_OFFLOAD;
1884 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1885 ret |= ETH_VLAN_EXTEND_OFFLOAD;
1891 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1893 struct rte_eth_dev *dev;
1895 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1896 dev = &rte_eth_devices[port_id];
1897 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1898 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1904 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1906 struct rte_eth_dev *dev;
1908 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1909 dev = &rte_eth_devices[port_id];
1910 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1911 memset(fc_conf, 0, sizeof(*fc_conf));
1912 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1916 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1918 struct rte_eth_dev *dev;
1920 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1921 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1922 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1926 dev = &rte_eth_devices[port_id];
1927 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1928 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1932 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1934 struct rte_eth_dev *dev;
1936 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1937 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1938 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1942 dev = &rte_eth_devices[port_id];
1943 /* High water, low water validation are device specific */
1944 if (*dev->dev_ops->priority_flow_ctrl_set)
1945 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1950 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
1958 num = (reta_size + RTE_RETA_GROUP_SIZE - 1) / RTE_RETA_GROUP_SIZE;
1959 for (i = 0; i < num; i++) {
1960 if (reta_conf[i].mask)
1968 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
1972 uint16_t i, idx, shift;
1978 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
1982 for (i = 0; i < reta_size; i++) {
1983 idx = i / RTE_RETA_GROUP_SIZE;
1984 shift = i % RTE_RETA_GROUP_SIZE;
1985 if ((reta_conf[idx].mask & (1ULL << shift)) &&
1986 (reta_conf[idx].reta[shift] >= max_rxq)) {
1987 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
1988 "the maximum rxq index: %u\n", idx, shift,
1989 reta_conf[idx].reta[shift], max_rxq);
1998 rte_eth_dev_rss_reta_update(uint8_t port_id,
1999 struct rte_eth_rss_reta_entry64 *reta_conf,
2002 struct rte_eth_dev *dev;
2005 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2006 /* Check mask bits */
2007 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2011 dev = &rte_eth_devices[port_id];
2013 /* Check entry value */
2014 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2015 dev->data->nb_rx_queues);
2019 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2020 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2024 rte_eth_dev_rss_reta_query(uint8_t port_id,
2025 struct rte_eth_rss_reta_entry64 *reta_conf,
2028 struct rte_eth_dev *dev;
2031 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2033 /* Check mask bits */
2034 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2038 dev = &rte_eth_devices[port_id];
2039 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2040 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2044 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2046 struct rte_eth_dev *dev;
2047 uint16_t rss_hash_protos;
2049 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2050 rss_hash_protos = rss_conf->rss_hf;
2051 if ((rss_hash_protos != 0) &&
2052 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2053 RTE_PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2057 dev = &rte_eth_devices[port_id];
2058 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2059 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2063 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2064 struct rte_eth_rss_conf *rss_conf)
2066 struct rte_eth_dev *dev;
2068 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2069 dev = &rte_eth_devices[port_id];
2070 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2071 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2075 rte_eth_dev_udp_tunnel_port_add(uint8_t port_id,
2076 struct rte_eth_udp_tunnel *udp_tunnel)
2078 struct rte_eth_dev *dev;
2080 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2081 if (udp_tunnel == NULL) {
2082 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2086 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2087 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2091 dev = &rte_eth_devices[port_id];
2092 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
2093 return (*dev->dev_ops->udp_tunnel_port_add)(dev, udp_tunnel);
2097 rte_eth_dev_udp_tunnel_port_delete(uint8_t port_id,
2098 struct rte_eth_udp_tunnel *udp_tunnel)
2100 struct rte_eth_dev *dev;
2102 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2103 dev = &rte_eth_devices[port_id];
2105 if (udp_tunnel == NULL) {
2106 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2110 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2111 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2115 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
2116 return (*dev->dev_ops->udp_tunnel_port_del)(dev, udp_tunnel);
2120 rte_eth_led_on(uint8_t port_id)
2122 struct rte_eth_dev *dev;
2124 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2125 dev = &rte_eth_devices[port_id];
2126 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2127 return (*dev->dev_ops->dev_led_on)(dev);
2131 rte_eth_led_off(uint8_t port_id)
2133 struct rte_eth_dev *dev;
2135 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2136 dev = &rte_eth_devices[port_id];
2137 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2138 return (*dev->dev_ops->dev_led_off)(dev);
2142 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2146 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2148 struct rte_eth_dev_info dev_info;
2149 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2152 rte_eth_dev_info_get(port_id, &dev_info);
2154 for (i = 0; i < dev_info.max_mac_addrs; i++)
2155 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2161 static const struct ether_addr null_mac_addr;
2164 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2167 struct rte_eth_dev *dev;
2171 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2172 dev = &rte_eth_devices[port_id];
2173 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2175 if (is_zero_ether_addr(addr)) {
2176 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2180 if (pool >= ETH_64_POOLS) {
2181 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2185 index = get_mac_addr_index(port_id, addr);
2187 index = get_mac_addr_index(port_id, &null_mac_addr);
2189 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2194 pool_mask = dev->data->mac_pool_sel[index];
2196 /* Check if both MAC address and pool is already there, and do nothing */
2197 if (pool_mask & (1ULL << pool))
2202 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2204 /* Update address in NIC data structure */
2205 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2207 /* Update pool bitmap in NIC data structure */
2208 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2214 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2216 struct rte_eth_dev *dev;
2219 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2220 dev = &rte_eth_devices[port_id];
2221 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2223 index = get_mac_addr_index(port_id, addr);
2225 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2227 } else if (index < 0)
2228 return 0; /* Do nothing if address wasn't found */
2231 (*dev->dev_ops->mac_addr_remove)(dev, index);
2233 /* Update address in NIC data structure */
2234 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2236 /* reset pool bitmap */
2237 dev->data->mac_pool_sel[index] = 0;
2243 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2245 struct rte_eth_dev *dev;
2247 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2249 if (!is_valid_assigned_ether_addr(addr))
2252 dev = &rte_eth_devices[port_id];
2253 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2255 /* Update default address in NIC data structure */
2256 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2258 (*dev->dev_ops->mac_addr_set)(dev, addr);
2265 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2269 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2271 struct rte_eth_dev_info dev_info;
2272 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2275 rte_eth_dev_info_get(port_id, &dev_info);
2276 if (!dev->data->hash_mac_addrs)
2279 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2280 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2281 ETHER_ADDR_LEN) == 0)
2288 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2293 struct rte_eth_dev *dev;
2295 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2297 dev = &rte_eth_devices[port_id];
2298 if (is_zero_ether_addr(addr)) {
2299 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2304 index = get_hash_mac_addr_index(port_id, addr);
2305 /* Check if it's already there, and do nothing */
2306 if ((index >= 0) && (on))
2311 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2312 "set in UTA\n", port_id);
2316 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2318 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2324 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2325 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2327 /* Update address in NIC data structure */
2329 ether_addr_copy(addr,
2330 &dev->data->hash_mac_addrs[index]);
2332 ether_addr_copy(&null_mac_addr,
2333 &dev->data->hash_mac_addrs[index]);
2340 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2342 struct rte_eth_dev *dev;
2344 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2346 dev = &rte_eth_devices[port_id];
2348 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2349 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2352 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2355 struct rte_eth_dev *dev;
2356 struct rte_eth_dev_info dev_info;
2357 struct rte_eth_link link;
2359 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2361 dev = &rte_eth_devices[port_id];
2362 rte_eth_dev_info_get(port_id, &dev_info);
2363 link = dev->data->dev_link;
2365 if (queue_idx > dev_info.max_tx_queues) {
2366 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2367 "invalid queue id=%d\n", port_id, queue_idx);
2371 if (tx_rate > link.link_speed) {
2372 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2373 "bigger than link speed= %d\n",
2374 tx_rate, link.link_speed);
2378 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2379 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2383 rte_eth_mirror_rule_set(uint8_t port_id,
2384 struct rte_eth_mirror_conf *mirror_conf,
2385 uint8_t rule_id, uint8_t on)
2387 struct rte_eth_dev *dev;
2389 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2390 if (mirror_conf->rule_type == 0) {
2391 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2395 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2396 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2401 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2402 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2403 (mirror_conf->pool_mask == 0)) {
2404 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2408 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2409 mirror_conf->vlan.vlan_mask == 0) {
2410 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2414 dev = &rte_eth_devices[port_id];
2415 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2417 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2421 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2423 struct rte_eth_dev *dev;
2425 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2427 dev = &rte_eth_devices[port_id];
2428 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2430 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2434 rte_eth_dev_callback_register(uint8_t port_id,
2435 enum rte_eth_event_type event,
2436 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2438 struct rte_eth_dev *dev;
2439 struct rte_eth_dev_callback *user_cb;
2444 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2446 dev = &rte_eth_devices[port_id];
2447 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2449 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2450 if (user_cb->cb_fn == cb_fn &&
2451 user_cb->cb_arg == cb_arg &&
2452 user_cb->event == event) {
2457 /* create a new callback. */
2458 if (user_cb == NULL) {
2459 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2460 sizeof(struct rte_eth_dev_callback), 0);
2461 if (user_cb != NULL) {
2462 user_cb->cb_fn = cb_fn;
2463 user_cb->cb_arg = cb_arg;
2464 user_cb->event = event;
2465 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2469 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2470 return (user_cb == NULL) ? -ENOMEM : 0;
2474 rte_eth_dev_callback_unregister(uint8_t port_id,
2475 enum rte_eth_event_type event,
2476 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2479 struct rte_eth_dev *dev;
2480 struct rte_eth_dev_callback *cb, *next;
2485 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2487 dev = &rte_eth_devices[port_id];
2488 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2491 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2493 next = TAILQ_NEXT(cb, next);
2495 if (cb->cb_fn != cb_fn || cb->event != event ||
2496 (cb->cb_arg != (void *)-1 &&
2497 cb->cb_arg != cb_arg))
2501 * if this callback is not executing right now,
2504 if (cb->active == 0) {
2505 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2512 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2517 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2518 enum rte_eth_event_type event, void *cb_arg)
2520 struct rte_eth_dev_callback *cb_lst;
2521 struct rte_eth_dev_callback dev_cb;
2523 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2524 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2525 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2530 dev_cb.cb_arg = cb_arg;
2532 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2533 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2535 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2538 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2542 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
2545 struct rte_eth_dev *dev;
2546 struct rte_intr_handle *intr_handle;
2550 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2552 dev = &rte_eth_devices[port_id];
2554 if (!dev->intr_handle) {
2555 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
2559 intr_handle = dev->intr_handle;
2560 if (!intr_handle->intr_vec) {
2561 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2565 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2566 vec = intr_handle->intr_vec[qid];
2567 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2568 if (rc && rc != -EEXIST) {
2569 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2570 " op %d epfd %d vec %u\n",
2571 port_id, qid, op, epfd, vec);
2578 const struct rte_memzone *
2579 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2580 uint16_t queue_id, size_t size, unsigned align,
2583 char z_name[RTE_MEMZONE_NAMESIZE];
2584 const struct rte_memzone *mz;
2586 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2587 dev->data->drv_name, ring_name,
2588 dev->data->port_id, queue_id);
2590 mz = rte_memzone_lookup(z_name);
2594 if (rte_xen_dom0_supported())
2595 return rte_memzone_reserve_bounded(z_name, size, socket_id,
2596 0, align, RTE_PGSIZE_2M);
2598 return rte_memzone_reserve_aligned(z_name, size, socket_id,
2603 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
2604 int epfd, int op, void *data)
2607 struct rte_eth_dev *dev;
2608 struct rte_intr_handle *intr_handle;
2611 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2613 dev = &rte_eth_devices[port_id];
2614 if (queue_id >= dev->data->nb_rx_queues) {
2615 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
2619 if (!dev->intr_handle) {
2620 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
2624 intr_handle = dev->intr_handle;
2625 if (!intr_handle->intr_vec) {
2626 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2630 vec = intr_handle->intr_vec[queue_id];
2631 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2632 if (rc && rc != -EEXIST) {
2633 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2634 " op %d epfd %d vec %u\n",
2635 port_id, queue_id, op, epfd, vec);
2643 rte_eth_dev_rx_intr_enable(uint8_t port_id,
2646 struct rte_eth_dev *dev;
2648 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2650 dev = &rte_eth_devices[port_id];
2652 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
2653 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
2657 rte_eth_dev_rx_intr_disable(uint8_t port_id,
2660 struct rte_eth_dev *dev;
2662 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2664 dev = &rte_eth_devices[port_id];
2666 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
2667 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
2670 #ifdef RTE_NIC_BYPASS
2671 int rte_eth_dev_bypass_init(uint8_t port_id)
2673 struct rte_eth_dev *dev;
2675 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2677 dev = &rte_eth_devices[port_id];
2678 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2679 (*dev->dev_ops->bypass_init)(dev);
2684 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2686 struct rte_eth_dev *dev;
2688 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2690 dev = &rte_eth_devices[port_id];
2691 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2692 (*dev->dev_ops->bypass_state_show)(dev, state);
2697 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2699 struct rte_eth_dev *dev;
2701 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2703 dev = &rte_eth_devices[port_id];
2704 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2705 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2710 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2712 struct rte_eth_dev *dev;
2714 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2716 dev = &rte_eth_devices[port_id];
2717 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2718 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2723 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2725 struct rte_eth_dev *dev;
2727 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2729 dev = &rte_eth_devices[port_id];
2731 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2732 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2737 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2739 struct rte_eth_dev *dev;
2741 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2743 dev = &rte_eth_devices[port_id];
2745 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2746 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2751 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2753 struct rte_eth_dev *dev;
2755 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2757 dev = &rte_eth_devices[port_id];
2759 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2760 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2765 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2767 struct rte_eth_dev *dev;
2769 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2771 dev = &rte_eth_devices[port_id];
2773 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2774 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2779 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2781 struct rte_eth_dev *dev;
2783 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2785 dev = &rte_eth_devices[port_id];
2787 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2788 (*dev->dev_ops->bypass_wd_reset)(dev);
2794 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
2796 struct rte_eth_dev *dev;
2798 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2800 dev = &rte_eth_devices[port_id];
2801 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2802 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
2803 RTE_ETH_FILTER_NOP, NULL);
2807 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
2808 enum rte_filter_op filter_op, void *arg)
2810 struct rte_eth_dev *dev;
2812 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2814 dev = &rte_eth_devices[port_id];
2815 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2816 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
2820 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
2821 rte_rx_callback_fn fn, void *user_param)
2823 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2824 rte_errno = ENOTSUP;
2827 /* check input parameters */
2828 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2829 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2833 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2841 cb->param = user_param;
2843 rte_spinlock_lock(&rte_eth_rx_cb_lock);
2844 /* Add the callbacks in fifo order. */
2845 struct rte_eth_rxtx_callback *tail =
2846 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2849 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2856 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
2862 rte_eth_add_first_rx_callback(uint8_t port_id, uint16_t queue_id,
2863 rte_rx_callback_fn fn, void *user_param)
2865 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2866 rte_errno = ENOTSUP;
2869 /* check input parameters */
2870 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2871 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2876 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2884 cb->param = user_param;
2886 rte_spinlock_lock(&rte_eth_rx_cb_lock);
2887 /* Add the callbacks at fisrt position*/
2888 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2890 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2891 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
2897 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
2898 rte_tx_callback_fn fn, void *user_param)
2900 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2901 rte_errno = ENOTSUP;
2904 /* check input parameters */
2905 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2906 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
2911 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2919 cb->param = user_param;
2921 rte_spinlock_lock(&rte_eth_tx_cb_lock);
2922 /* Add the callbacks in fifo order. */
2923 struct rte_eth_rxtx_callback *tail =
2924 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
2927 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
2934 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
2940 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
2941 struct rte_eth_rxtx_callback *user_cb)
2943 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2946 /* Check input parameters. */
2947 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2948 if (user_cb == NULL ||
2949 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
2952 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2953 struct rte_eth_rxtx_callback *cb;
2954 struct rte_eth_rxtx_callback **prev_cb;
2957 rte_spinlock_lock(&rte_eth_rx_cb_lock);
2958 prev_cb = &dev->post_rx_burst_cbs[queue_id];
2959 for (; *prev_cb != NULL; prev_cb = &cb->next) {
2961 if (cb == user_cb) {
2962 /* Remove the user cb from the callback list. */
2963 *prev_cb = cb->next;
2968 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
2974 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
2975 struct rte_eth_rxtx_callback *user_cb)
2977 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2980 /* Check input parameters. */
2981 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2982 if (user_cb == NULL ||
2983 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
2986 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2988 struct rte_eth_rxtx_callback *cb;
2989 struct rte_eth_rxtx_callback **prev_cb;
2991 rte_spinlock_lock(&rte_eth_tx_cb_lock);
2992 prev_cb = &dev->pre_tx_burst_cbs[queue_id];
2993 for (; *prev_cb != NULL; prev_cb = &cb->next) {
2995 if (cb == user_cb) {
2996 /* Remove the user cb from the callback list. */
2997 *prev_cb = cb->next;
3002 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3008 rte_eth_rx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3009 struct rte_eth_rxq_info *qinfo)
3011 struct rte_eth_dev *dev;
3013 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3018 dev = &rte_eth_devices[port_id];
3019 if (queue_id >= dev->data->nb_rx_queues) {
3020 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3024 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3026 memset(qinfo, 0, sizeof(*qinfo));
3027 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3032 rte_eth_tx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3033 struct rte_eth_txq_info *qinfo)
3035 struct rte_eth_dev *dev;
3037 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3042 dev = &rte_eth_devices[port_id];
3043 if (queue_id >= dev->data->nb_tx_queues) {
3044 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3048 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3050 memset(qinfo, 0, sizeof(*qinfo));
3051 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3056 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3057 struct ether_addr *mc_addr_set,
3058 uint32_t nb_mc_addr)
3060 struct rte_eth_dev *dev;
3062 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3064 dev = &rte_eth_devices[port_id];
3065 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3066 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3070 rte_eth_timesync_enable(uint8_t port_id)
3072 struct rte_eth_dev *dev;
3074 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3075 dev = &rte_eth_devices[port_id];
3077 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3078 return (*dev->dev_ops->timesync_enable)(dev);
3082 rte_eth_timesync_disable(uint8_t port_id)
3084 struct rte_eth_dev *dev;
3086 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3087 dev = &rte_eth_devices[port_id];
3089 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3090 return (*dev->dev_ops->timesync_disable)(dev);
3094 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3097 struct rte_eth_dev *dev;
3099 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3100 dev = &rte_eth_devices[port_id];
3102 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3103 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3107 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3109 struct rte_eth_dev *dev;
3111 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3112 dev = &rte_eth_devices[port_id];
3114 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3115 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3119 rte_eth_timesync_adjust_time(uint8_t port_id, int64_t delta)
3121 struct rte_eth_dev *dev;
3123 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3124 dev = &rte_eth_devices[port_id];
3126 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3127 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3131 rte_eth_timesync_read_time(uint8_t port_id, struct timespec *timestamp)
3133 struct rte_eth_dev *dev;
3135 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3136 dev = &rte_eth_devices[port_id];
3138 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3139 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3143 rte_eth_timesync_write_time(uint8_t port_id, const struct timespec *timestamp)
3145 struct rte_eth_dev *dev;
3147 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3148 dev = &rte_eth_devices[port_id];
3150 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3151 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3155 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3157 struct rte_eth_dev *dev;
3159 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3161 dev = &rte_eth_devices[port_id];
3162 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3163 return (*dev->dev_ops->get_reg)(dev, info);
3167 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3169 struct rte_eth_dev *dev;
3171 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3173 dev = &rte_eth_devices[port_id];
3174 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3175 return (*dev->dev_ops->get_eeprom_length)(dev);
3179 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3181 struct rte_eth_dev *dev;
3183 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3185 dev = &rte_eth_devices[port_id];
3186 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3187 return (*dev->dev_ops->get_eeprom)(dev, info);
3191 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3193 struct rte_eth_dev *dev;
3195 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3197 dev = &rte_eth_devices[port_id];
3198 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3199 return (*dev->dev_ops->set_eeprom)(dev, info);
3203 rte_eth_dev_get_dcb_info(uint8_t port_id,
3204 struct rte_eth_dcb_info *dcb_info)
3206 struct rte_eth_dev *dev;
3208 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3210 dev = &rte_eth_devices[port_id];
3211 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3213 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3214 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3218 rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_dev)
3220 if ((eth_dev == NULL) || (pci_dev == NULL)) {
3221 RTE_PMD_DEBUG_TRACE("NULL pointer eth_dev=%p pci_dev=%p\n",
3226 eth_dev->intr_handle = &pci_dev->intr_handle;
3228 eth_dev->data->dev_flags = 0;
3229 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
3230 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
3232 eth_dev->data->kdrv = pci_dev->kdrv;
3233 eth_dev->data->numa_node = pci_dev->device.numa_node;
3234 eth_dev->data->drv_name = pci_dev->driver->driver.name;
3238 rte_eth_dev_l2_tunnel_eth_type_conf(uint8_t port_id,
3239 struct rte_eth_l2_tunnel_conf *l2_tunnel)
3241 struct rte_eth_dev *dev;
3243 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3244 if (l2_tunnel == NULL) {
3245 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3249 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3250 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
3254 dev = &rte_eth_devices[port_id];
3255 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
3257 return (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev, l2_tunnel);
3261 rte_eth_dev_l2_tunnel_offload_set(uint8_t port_id,
3262 struct rte_eth_l2_tunnel_conf *l2_tunnel,
3266 struct rte_eth_dev *dev;
3268 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3270 if (l2_tunnel == NULL) {
3271 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3275 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3276 RTE_PMD_DEBUG_TRACE("Invalid tunnel type.\n");
3281 RTE_PMD_DEBUG_TRACE("Mask should have a value.\n");
3285 dev = &rte_eth_devices[port_id];
3286 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
3288 return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);