4 * Copyright(c) 2010-2015 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>
62 #include <rte_mempool.h>
63 #include <rte_malloc.h>
65 #include <rte_errno.h>
66 #include <rte_spinlock.h>
67 #include <rte_string_fns.h>
69 #include "rte_ether.h"
70 #include "rte_ethdev.h"
72 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
73 #define PMD_DEBUG_TRACE(fmt, args...) do { \
74 RTE_LOG(ERR, PMD, "%s: " fmt, __func__, ## args); \
77 #define PMD_DEBUG_TRACE(fmt, args...)
80 /* Macros for checking for restricting functions to primary instance only */
81 #define PROC_PRIMARY_OR_ERR_RET(retval) do { \
82 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
83 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
88 #define PROC_PRIMARY_OR_RET() do { \
89 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
90 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
95 /* Macros to check for invalid function pointers in dev_ops structure */
96 #define FUNC_PTR_OR_ERR_RET(func, retval) do { \
97 if ((func) == NULL) { \
98 PMD_DEBUG_TRACE("Function not supported\n"); \
103 #define FUNC_PTR_OR_RET(func) do { \
104 if ((func) == NULL) { \
105 PMD_DEBUG_TRACE("Function not supported\n"); \
110 /* Macros to check for valid port */
111 #define VALID_PORTID_OR_ERR_RET(port_id, retval) do { \
112 if (!rte_eth_dev_is_valid_port(port_id)) { \
113 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); \
118 #define VALID_PORTID_OR_RET(port_id) do { \
119 if (!rte_eth_dev_is_valid_port(port_id)) { \
120 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); \
125 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
126 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
127 static struct rte_eth_dev_data *rte_eth_dev_data;
128 static uint8_t nb_ports;
130 /* spinlock for eth device callbacks */
131 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
133 /* store statistics names and its offset in stats structure */
134 struct rte_eth_xstats_name_off {
135 char name[RTE_ETH_XSTATS_NAME_SIZE];
139 static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
140 {"rx_good_packets", offsetof(struct rte_eth_stats, ipackets)},
141 {"tx_good_packets", offsetof(struct rte_eth_stats, opackets)},
142 {"rx_good_bytes", offsetof(struct rte_eth_stats, ibytes)},
143 {"tx_good_bytes", offsetof(struct rte_eth_stats, obytes)},
144 {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
145 {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
146 {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats,
150 #define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
152 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
153 {"packets", offsetof(struct rte_eth_stats, q_ipackets)},
154 {"bytes", offsetof(struct rte_eth_stats, q_ibytes)},
155 {"errors", offsetof(struct rte_eth_stats, q_errors)},
158 #define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) / \
159 sizeof(rte_rxq_stats_strings[0]))
161 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
162 {"packets", offsetof(struct rte_eth_stats, q_opackets)},
163 {"bytes", offsetof(struct rte_eth_stats, q_obytes)},
165 #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) / \
166 sizeof(rte_txq_stats_strings[0]))
170 * The user application callback description.
172 * It contains callback address to be registered by user application,
173 * the pointer to the parameters for callback, and the event type.
175 struct rte_eth_dev_callback {
176 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
177 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
178 void *cb_arg; /**< Parameter for callback */
179 enum rte_eth_event_type event; /**< Interrupt event type */
180 uint32_t active; /**< Callback is executing */
194 rte_eth_dev_data_alloc(void)
196 const unsigned flags = 0;
197 const struct rte_memzone *mz;
199 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
200 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
201 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
202 rte_socket_id(), flags);
204 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
206 rte_panic("Cannot allocate memzone for ethernet port data\n");
208 rte_eth_dev_data = mz->addr;
209 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
210 memset(rte_eth_dev_data, 0,
211 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
215 rte_eth_dev_allocated(const char *name)
219 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
220 if ((rte_eth_devices[i].attached == DEV_ATTACHED) &&
221 strcmp(rte_eth_devices[i].data->name, name) == 0)
222 return &rte_eth_devices[i];
228 rte_eth_dev_find_free_port(void)
232 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
233 if (rte_eth_devices[i].attached == DEV_DETACHED)
236 return RTE_MAX_ETHPORTS;
240 rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
243 struct rte_eth_dev *eth_dev;
245 port_id = rte_eth_dev_find_free_port();
246 if (port_id == RTE_MAX_ETHPORTS) {
247 PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
251 if (rte_eth_dev_data == NULL)
252 rte_eth_dev_data_alloc();
254 if (rte_eth_dev_allocated(name) != NULL) {
255 PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n",
260 eth_dev = &rte_eth_devices[port_id];
261 eth_dev->data = &rte_eth_dev_data[port_id];
262 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
263 eth_dev->data->port_id = port_id;
264 eth_dev->attached = DEV_ATTACHED;
265 eth_dev->dev_type = type;
271 rte_eth_dev_create_unique_device_name(char *name, size_t size,
272 struct rte_pci_device *pci_dev)
276 if ((name == NULL) || (pci_dev == NULL))
279 ret = snprintf(name, size, "%d:%d.%d",
280 pci_dev->addr.bus, pci_dev->addr.devid,
281 pci_dev->addr.function);
288 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
293 eth_dev->attached = DEV_DETACHED;
299 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
300 struct rte_pci_device *pci_dev)
302 struct eth_driver *eth_drv;
303 struct rte_eth_dev *eth_dev;
304 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
308 eth_drv = (struct eth_driver *)pci_drv;
310 /* Create unique Ethernet device name using PCI address */
311 rte_eth_dev_create_unique_device_name(ethdev_name,
312 sizeof(ethdev_name), pci_dev);
314 eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
318 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
319 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
320 eth_drv->dev_private_size,
321 RTE_CACHE_LINE_SIZE);
322 if (eth_dev->data->dev_private == NULL)
323 rte_panic("Cannot allocate memzone for private port data\n");
325 eth_dev->pci_dev = pci_dev;
326 eth_dev->driver = eth_drv;
327 eth_dev->data->rx_mbuf_alloc_failed = 0;
329 /* init user callbacks */
330 TAILQ_INIT(&(eth_dev->link_intr_cbs));
333 * Set the default MTU.
335 eth_dev->data->mtu = ETHER_MTU;
337 /* Invoke PMD device initialization function */
338 diag = (*eth_drv->eth_dev_init)(eth_dev);
342 PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x) failed\n",
344 (unsigned) pci_dev->id.vendor_id,
345 (unsigned) pci_dev->id.device_id);
346 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
347 rte_free(eth_dev->data->dev_private);
348 rte_eth_dev_release_port(eth_dev);
353 rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
355 const struct eth_driver *eth_drv;
356 struct rte_eth_dev *eth_dev;
357 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
363 /* Create unique Ethernet device name using PCI address */
364 rte_eth_dev_create_unique_device_name(ethdev_name,
365 sizeof(ethdev_name), pci_dev);
367 eth_dev = rte_eth_dev_allocated(ethdev_name);
371 eth_drv = (const struct eth_driver *)pci_dev->driver;
373 /* Invoke PMD device uninit function */
374 if (*eth_drv->eth_dev_uninit) {
375 ret = (*eth_drv->eth_dev_uninit)(eth_dev);
380 /* free ether device */
381 rte_eth_dev_release_port(eth_dev);
383 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
384 rte_free(eth_dev->data->dev_private);
386 eth_dev->pci_dev = NULL;
387 eth_dev->driver = NULL;
388 eth_dev->data = NULL;
394 * Register an Ethernet [Poll Mode] driver.
396 * Function invoked by the initialization function of an Ethernet driver
397 * to simultaneously register itself as a PCI driver and as an Ethernet
399 * Invokes the rte_eal_pci_register() function to register the *pci_drv*
400 * structure embedded in the *eth_drv* structure, after having stored the
401 * address of the rte_eth_dev_init() function in the *devinit* field of
402 * the *pci_drv* structure.
403 * During the PCI probing phase, the rte_eth_dev_init() function is
404 * invoked for each PCI [Ethernet device] matching the embedded PCI
405 * identifiers provided by the driver.
408 rte_eth_driver_register(struct eth_driver *eth_drv)
410 eth_drv->pci_drv.devinit = rte_eth_dev_init;
411 eth_drv->pci_drv.devuninit = rte_eth_dev_uninit;
412 rte_eal_pci_register(ð_drv->pci_drv);
416 rte_eth_dev_is_valid_port(uint8_t port_id)
418 if (port_id >= RTE_MAX_ETHPORTS ||
419 rte_eth_devices[port_id].attached != DEV_ATTACHED)
426 rte_eth_dev_socket_id(uint8_t port_id)
428 if (!rte_eth_dev_is_valid_port(port_id))
430 return rte_eth_devices[port_id].pci_dev->numa_node;
434 rte_eth_dev_count(void)
439 static enum rte_eth_dev_type
440 rte_eth_dev_get_device_type(uint8_t port_id)
442 if (!rte_eth_dev_is_valid_port(port_id))
443 return RTE_ETH_DEV_UNKNOWN;
444 return rte_eth_devices[port_id].dev_type;
448 rte_eth_dev_save(struct rte_eth_dev *devs, size_t size)
450 if ((devs == NULL) ||
451 (size != sizeof(struct rte_eth_dev) * RTE_MAX_ETHPORTS))
454 /* save current rte_eth_devices */
455 memcpy(devs, rte_eth_devices, size);
460 rte_eth_dev_get_changed_port(struct rte_eth_dev *devs, uint8_t *port_id)
462 if ((devs == NULL) || (port_id == NULL))
465 /* check which port was attached or detached */
466 for (*port_id = 0; *port_id < RTE_MAX_ETHPORTS; (*port_id)++, devs++) {
467 if (rte_eth_devices[*port_id].attached ^ devs->attached)
474 rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr)
476 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
479 PMD_DEBUG_TRACE("Null pointer is specified\n");
483 *addr = rte_eth_devices[port_id].pci_dev->addr;
488 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
492 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
495 PMD_DEBUG_TRACE("Null pointer is specified\n");
499 /* shouldn't check 'rte_eth_devices[i].data',
500 * because it might be overwritten by VDEV PMD */
501 tmp = rte_eth_dev_data[port_id].name;
507 rte_eth_dev_is_detachable(uint8_t port_id)
511 if (!rte_eth_dev_is_valid_port(port_id)) {
512 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
516 if (rte_eth_devices[port_id].dev_type == RTE_ETH_DEV_PCI) {
517 switch (rte_eth_devices[port_id].pci_dev->kdrv) {
518 case RTE_KDRV_IGB_UIO:
519 case RTE_KDRV_UIO_GENERIC:
520 case RTE_KDRV_NIC_UIO:
528 drv_flags = rte_eth_devices[port_id].driver->pci_drv.drv_flags;
529 return !(drv_flags & RTE_PCI_DRV_DETACHABLE);
532 /* attach the new physical device, then store port_id of the device */
534 rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
537 struct rte_eth_dev devs[RTE_MAX_ETHPORTS];
539 if ((addr == NULL) || (port_id == NULL))
542 /* save current port status */
543 if (rte_eth_dev_save(devs, sizeof(devs)))
545 /* re-construct pci_device_list */
546 if (rte_eal_pci_scan())
548 /* invoke probe func of the driver can handle the new device.
550 * rte_eal_pci_probe_one() should return port_id.
551 * And rte_eth_dev_save() and rte_eth_dev_get_changed_port()
552 * should be removed. */
553 if (rte_eal_pci_probe_one(addr))
555 /* get port_id enabled by above procedures */
556 if (rte_eth_dev_get_changed_port(devs, &new_port_id))
559 *port_id = new_port_id;
562 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
566 /* detach the new physical device, then store pci_addr of the device */
568 rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
570 struct rte_pci_addr freed_addr;
571 struct rte_pci_addr vp;
576 /* check whether the driver supports detach feature, or not */
577 if (rte_eth_dev_is_detachable(port_id))
580 /* get pci address by port id */
581 if (rte_eth_dev_get_addr_by_port(port_id, &freed_addr))
584 /* Zeroed pci addr means the port comes from virtual device */
585 vp.domain = vp.bus = vp.devid = vp.function = 0;
586 if (rte_eal_compare_pci_addr(&vp, &freed_addr) == 0)
589 /* invoke devuninit func of the pci driver,
590 * also remove the device from pci_device_list */
591 if (rte_eal_pci_detach(&freed_addr))
597 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
601 /* attach the new virtual device, then store port_id of the device */
603 rte_eth_dev_attach_vdev(const char *vdevargs, uint8_t *port_id)
605 char *name = NULL, *args = NULL;
607 struct rte_eth_dev devs[RTE_MAX_ETHPORTS];
610 if ((vdevargs == NULL) || (port_id == NULL))
613 /* parse vdevargs, then retrieve device name and args */
614 if (rte_eal_parse_devargs_str(vdevargs, &name, &args))
617 /* save current port status */
618 if (rte_eth_dev_save(devs, sizeof(devs)))
620 /* walk around dev_driver_list to find the driver of the device,
621 * then invoke probe function o the driver.
623 * rte_eal_vdev_init() should return port_id,
624 * And rte_eth_dev_save() and rte_eth_dev_get_changed_port()
625 * should be removed. */
626 if (rte_eal_vdev_init(name, args))
628 /* get port_id enabled by above procedures */
629 if (rte_eth_dev_get_changed_port(devs, &new_port_id))
632 *port_id = new_port_id;
640 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
644 /* detach the new virtual device, then store the name of the device */
646 rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
648 char name[RTE_ETH_NAME_MAX_LEN];
650 if (vdevname == NULL)
653 /* check whether the driver supports detach feature, or not */
654 if (rte_eth_dev_is_detachable(port_id))
657 /* get device name by port id */
658 if (rte_eth_dev_get_name_by_port(port_id, name))
660 /* walk around dev_driver_list to find the driver of the device,
661 * then invoke uninit function of the driver */
662 if (rte_eal_vdev_uninit(name))
665 strncpy(vdevname, name, sizeof(name));
668 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
672 /* attach the new device, then store port_id of the device */
674 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
676 struct rte_pci_addr addr;
678 if ((devargs == NULL) || (port_id == NULL))
681 if (eal_parse_pci_DomBDF(devargs, &addr) == 0)
682 return rte_eth_dev_attach_pdev(&addr, port_id);
684 return rte_eth_dev_attach_vdev(devargs, port_id);
687 /* detach the device, then store the name of the device */
689 rte_eth_dev_detach(uint8_t port_id, char *name)
691 struct rte_pci_addr addr;
697 if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {
698 ret = rte_eth_dev_get_addr_by_port(port_id, &addr);
702 ret = rte_eth_dev_detach_pdev(port_id, &addr);
704 snprintf(name, RTE_ETH_NAME_MAX_LEN,
706 addr.domain, addr.bus,
707 addr.devid, addr.function);
711 return rte_eth_dev_detach_vdev(port_id, name);
715 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
717 uint16_t old_nb_queues = dev->data->nb_rx_queues;
721 if (dev->data->rx_queues == NULL) { /* first time configuration */
722 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
723 sizeof(dev->data->rx_queues[0]) * nb_queues,
724 RTE_CACHE_LINE_SIZE);
725 if (dev->data->rx_queues == NULL) {
726 dev->data->nb_rx_queues = 0;
729 } else { /* re-configure */
730 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
732 rxq = dev->data->rx_queues;
734 for (i = nb_queues; i < old_nb_queues; i++)
735 (*dev->dev_ops->rx_queue_release)(rxq[i]);
736 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
737 RTE_CACHE_LINE_SIZE);
740 if (nb_queues > old_nb_queues) {
741 uint16_t new_qs = nb_queues - old_nb_queues;
743 memset(rxq + old_nb_queues, 0,
744 sizeof(rxq[0]) * new_qs);
747 dev->data->rx_queues = rxq;
750 dev->data->nb_rx_queues = nb_queues;
755 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
757 struct rte_eth_dev *dev;
759 /* This function is only safe when called from the primary process
760 * in a multi-process setup*/
761 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
763 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
765 dev = &rte_eth_devices[port_id];
766 if (rx_queue_id >= dev->data->nb_rx_queues) {
767 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
771 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
773 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
778 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
780 struct rte_eth_dev *dev;
782 /* This function is only safe when called from the primary process
783 * in a multi-process setup*/
784 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
786 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
788 dev = &rte_eth_devices[port_id];
789 if (rx_queue_id >= dev->data->nb_rx_queues) {
790 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
794 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
796 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
801 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
803 struct rte_eth_dev *dev;
805 /* This function is only safe when called from the primary process
806 * in a multi-process setup*/
807 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
809 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
811 dev = &rte_eth_devices[port_id];
812 if (tx_queue_id >= dev->data->nb_tx_queues) {
813 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
817 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
819 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
824 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
826 struct rte_eth_dev *dev;
828 /* This function is only safe when called from the primary process
829 * in a multi-process setup*/
830 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
832 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
834 dev = &rte_eth_devices[port_id];
835 if (tx_queue_id >= dev->data->nb_tx_queues) {
836 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
840 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
842 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
847 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
849 uint16_t old_nb_queues = dev->data->nb_tx_queues;
853 if (dev->data->tx_queues == NULL) { /* first time configuration */
854 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
855 sizeof(dev->data->tx_queues[0]) * nb_queues,
856 RTE_CACHE_LINE_SIZE);
857 if (dev->data->tx_queues == NULL) {
858 dev->data->nb_tx_queues = 0;
861 } else { /* re-configure */
862 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
864 txq = dev->data->tx_queues;
866 for (i = nb_queues; i < old_nb_queues; i++)
867 (*dev->dev_ops->tx_queue_release)(txq[i]);
868 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
869 RTE_CACHE_LINE_SIZE);
872 if (nb_queues > old_nb_queues) {
873 uint16_t new_qs = nb_queues - old_nb_queues;
875 memset(txq + old_nb_queues, 0,
876 sizeof(txq[0]) * new_qs);
879 dev->data->tx_queues = txq;
882 dev->data->nb_tx_queues = nb_queues;
887 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
888 const struct rte_eth_conf *dev_conf)
890 struct rte_eth_dev *dev;
891 struct rte_eth_dev_info dev_info;
894 /* This function is only safe when called from the primary process
895 * in a multi-process setup*/
896 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
898 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
900 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
902 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
903 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
907 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
909 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
910 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
914 dev = &rte_eth_devices[port_id];
916 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
917 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
919 if (dev->data->dev_started) {
921 "port %d must be stopped to allow configuration\n", port_id);
926 * Check that the numbers of RX and TX queues are not greater
927 * than the maximum number of RX and TX queues supported by the
930 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
931 if (nb_rx_q > dev_info.max_rx_queues) {
932 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
933 port_id, nb_rx_q, dev_info.max_rx_queues);
937 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
941 if (nb_tx_q > dev_info.max_tx_queues) {
942 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
943 port_id, nb_tx_q, dev_info.max_tx_queues);
947 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
951 /* Copy the dev_conf parameter into the dev structure */
952 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
955 * If link state interrupt is enabled, check that the
956 * device supports it.
958 if (dev_conf->intr_conf.lsc == 1) {
959 const struct rte_pci_driver *pci_drv = &dev->driver->pci_drv;
961 if (!(pci_drv->drv_flags & RTE_PCI_DRV_INTR_LSC)) {
962 PMD_DEBUG_TRACE("driver %s does not support lsc\n",
969 * If jumbo frames are enabled, check that the maximum RX packet
970 * length is supported by the configured device.
972 if (dev_conf->rxmode.jumbo_frame == 1) {
973 if (dev_conf->rxmode.max_rx_pkt_len >
974 dev_info.max_rx_pktlen) {
975 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
976 " > max valid value %u\n",
978 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
979 (unsigned)dev_info.max_rx_pktlen);
981 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
982 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
983 " < min valid value %u\n",
985 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
986 (unsigned)ETHER_MIN_LEN);
990 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
991 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
992 /* Use default value */
993 dev->data->dev_conf.rxmode.max_rx_pkt_len =
998 * Setup new number of RX/TX queues and reconfigure device.
1000 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
1002 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
1007 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
1009 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
1011 rte_eth_dev_rx_queue_config(dev, 0);
1015 diag = (*dev->dev_ops->dev_configure)(dev);
1017 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
1019 rte_eth_dev_rx_queue_config(dev, 0);
1020 rte_eth_dev_tx_queue_config(dev, 0);
1028 rte_eth_dev_config_restore(uint8_t port_id)
1030 struct rte_eth_dev *dev;
1031 struct rte_eth_dev_info dev_info;
1032 struct ether_addr addr;
1036 dev = &rte_eth_devices[port_id];
1038 rte_eth_dev_info_get(port_id, &dev_info);
1040 if (RTE_ETH_DEV_SRIOV(dev).active)
1041 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
1043 /* replay MAC address configuration */
1044 for (i = 0; i < dev_info.max_mac_addrs; i++) {
1045 addr = dev->data->mac_addrs[i];
1047 /* skip zero address */
1048 if (is_zero_ether_addr(&addr))
1051 /* add address to the hardware */
1052 if (*dev->dev_ops->mac_addr_add &&
1053 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
1054 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
1056 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
1058 /* exit the loop but not return an error */
1063 /* replay promiscuous configuration */
1064 if (rte_eth_promiscuous_get(port_id) == 1)
1065 rte_eth_promiscuous_enable(port_id);
1066 else if (rte_eth_promiscuous_get(port_id) == 0)
1067 rte_eth_promiscuous_disable(port_id);
1069 /* replay all multicast configuration */
1070 if (rte_eth_allmulticast_get(port_id) == 1)
1071 rte_eth_allmulticast_enable(port_id);
1072 else if (rte_eth_allmulticast_get(port_id) == 0)
1073 rte_eth_allmulticast_disable(port_id);
1077 rte_eth_dev_start(uint8_t port_id)
1079 struct rte_eth_dev *dev;
1082 /* This function is only safe when called from the primary process
1083 * in a multi-process setup*/
1084 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1086 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1088 dev = &rte_eth_devices[port_id];
1090 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1092 if (dev->data->dev_started != 0) {
1093 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1094 " already started\n",
1099 diag = (*dev->dev_ops->dev_start)(dev);
1101 dev->data->dev_started = 1;
1105 rte_eth_dev_config_restore(port_id);
1107 if (dev->data->dev_conf.intr_conf.lsc != 0) {
1108 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1109 (*dev->dev_ops->link_update)(dev, 0);
1115 rte_eth_dev_stop(uint8_t port_id)
1117 struct rte_eth_dev *dev;
1119 /* This function is only safe when called from the primary process
1120 * in a multi-process setup*/
1121 PROC_PRIMARY_OR_RET();
1123 VALID_PORTID_OR_RET(port_id);
1124 dev = &rte_eth_devices[port_id];
1126 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1128 if (dev->data->dev_started == 0) {
1129 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1130 " already stopped\n",
1135 dev->data->dev_started = 0;
1136 (*dev->dev_ops->dev_stop)(dev);
1140 rte_eth_dev_set_link_up(uint8_t port_id)
1142 struct rte_eth_dev *dev;
1144 /* This function is only safe when called from the primary process
1145 * in a multi-process setup*/
1146 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1148 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1150 dev = &rte_eth_devices[port_id];
1152 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1153 return (*dev->dev_ops->dev_set_link_up)(dev);
1157 rte_eth_dev_set_link_down(uint8_t port_id)
1159 struct rte_eth_dev *dev;
1161 /* This function is only safe when called from the primary process
1162 * in a multi-process setup*/
1163 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1165 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1167 dev = &rte_eth_devices[port_id];
1169 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1170 return (*dev->dev_ops->dev_set_link_down)(dev);
1174 rte_eth_dev_close(uint8_t port_id)
1176 struct rte_eth_dev *dev;
1178 /* This function is only safe when called from the primary process
1179 * in a multi-process setup*/
1180 PROC_PRIMARY_OR_RET();
1182 VALID_PORTID_OR_RET(port_id);
1183 dev = &rte_eth_devices[port_id];
1185 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1186 dev->data->dev_started = 0;
1187 (*dev->dev_ops->dev_close)(dev);
1189 rte_free(dev->data->rx_queues);
1190 dev->data->rx_queues = NULL;
1191 rte_free(dev->data->tx_queues);
1192 dev->data->tx_queues = NULL;
1196 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1197 uint16_t nb_rx_desc, unsigned int socket_id,
1198 const struct rte_eth_rxconf *rx_conf,
1199 struct rte_mempool *mp)
1202 uint32_t mbp_buf_size;
1203 struct rte_eth_dev *dev;
1204 struct rte_eth_dev_info dev_info;
1206 /* This function is only safe when called from the primary process
1207 * in a multi-process setup*/
1208 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1210 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1212 dev = &rte_eth_devices[port_id];
1213 if (rx_queue_id >= dev->data->nb_rx_queues) {
1214 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1218 if (dev->data->dev_started) {
1220 "port %d must be stopped to allow configuration\n", port_id);
1224 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1225 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1228 * Check the size of the mbuf data buffer.
1229 * This value must be provided in the private data of the memory pool.
1230 * First check that the memory pool has a valid private data.
1232 rte_eth_dev_info_get(port_id, &dev_info);
1233 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1234 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1235 mp->name, (int) mp->private_data_size,
1236 (int) sizeof(struct rte_pktmbuf_pool_private));
1239 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1241 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1242 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1243 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1247 (int)(RTE_PKTMBUF_HEADROOM +
1248 dev_info.min_rx_bufsize),
1249 (int)RTE_PKTMBUF_HEADROOM,
1250 (int)dev_info.min_rx_bufsize);
1254 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1255 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1256 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1258 PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1259 "should be: <= %hu, = %hu, and a product of %hu\n",
1261 dev_info.rx_desc_lim.nb_max,
1262 dev_info.rx_desc_lim.nb_min,
1263 dev_info.rx_desc_lim.nb_align);
1267 if (rx_conf == NULL)
1268 rx_conf = &dev_info.default_rxconf;
1270 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1271 socket_id, rx_conf, mp);
1273 if (!dev->data->min_rx_buf_size ||
1274 dev->data->min_rx_buf_size > mbp_buf_size)
1275 dev->data->min_rx_buf_size = mbp_buf_size;
1282 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1283 uint16_t nb_tx_desc, unsigned int socket_id,
1284 const struct rte_eth_txconf *tx_conf)
1286 struct rte_eth_dev *dev;
1287 struct rte_eth_dev_info dev_info;
1289 /* This function is only safe when called from the primary process
1290 * in a multi-process setup*/
1291 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1293 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1295 dev = &rte_eth_devices[port_id];
1296 if (tx_queue_id >= dev->data->nb_tx_queues) {
1297 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1301 if (dev->data->dev_started) {
1303 "port %d must be stopped to allow configuration\n", port_id);
1307 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1308 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1310 rte_eth_dev_info_get(port_id, &dev_info);
1312 if (tx_conf == NULL)
1313 tx_conf = &dev_info.default_txconf;
1315 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1316 socket_id, tx_conf);
1320 rte_eth_promiscuous_enable(uint8_t port_id)
1322 struct rte_eth_dev *dev;
1324 VALID_PORTID_OR_RET(port_id);
1325 dev = &rte_eth_devices[port_id];
1327 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1328 (*dev->dev_ops->promiscuous_enable)(dev);
1329 dev->data->promiscuous = 1;
1333 rte_eth_promiscuous_disable(uint8_t port_id)
1335 struct rte_eth_dev *dev;
1337 VALID_PORTID_OR_RET(port_id);
1338 dev = &rte_eth_devices[port_id];
1340 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1341 dev->data->promiscuous = 0;
1342 (*dev->dev_ops->promiscuous_disable)(dev);
1346 rte_eth_promiscuous_get(uint8_t port_id)
1348 struct rte_eth_dev *dev;
1350 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1352 dev = &rte_eth_devices[port_id];
1353 return dev->data->promiscuous;
1357 rte_eth_allmulticast_enable(uint8_t port_id)
1359 struct rte_eth_dev *dev;
1361 VALID_PORTID_OR_RET(port_id);
1362 dev = &rte_eth_devices[port_id];
1364 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1365 (*dev->dev_ops->allmulticast_enable)(dev);
1366 dev->data->all_multicast = 1;
1370 rte_eth_allmulticast_disable(uint8_t port_id)
1372 struct rte_eth_dev *dev;
1374 VALID_PORTID_OR_RET(port_id);
1375 dev = &rte_eth_devices[port_id];
1377 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1378 dev->data->all_multicast = 0;
1379 (*dev->dev_ops->allmulticast_disable)(dev);
1383 rte_eth_allmulticast_get(uint8_t port_id)
1385 struct rte_eth_dev *dev;
1387 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1389 dev = &rte_eth_devices[port_id];
1390 return dev->data->all_multicast;
1394 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1395 struct rte_eth_link *link)
1397 struct rte_eth_link *dst = link;
1398 struct rte_eth_link *src = &(dev->data->dev_link);
1400 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1401 *(uint64_t *)src) == 0)
1408 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1410 struct rte_eth_dev *dev;
1412 VALID_PORTID_OR_RET(port_id);
1413 dev = &rte_eth_devices[port_id];
1415 if (dev->data->dev_conf.intr_conf.lsc != 0)
1416 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1418 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1419 (*dev->dev_ops->link_update)(dev, 1);
1420 *eth_link = dev->data->dev_link;
1425 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1427 struct rte_eth_dev *dev;
1429 VALID_PORTID_OR_RET(port_id);
1430 dev = &rte_eth_devices[port_id];
1432 if (dev->data->dev_conf.intr_conf.lsc != 0)
1433 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1435 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1436 (*dev->dev_ops->link_update)(dev, 0);
1437 *eth_link = dev->data->dev_link;
1442 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1444 struct rte_eth_dev *dev;
1446 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1448 dev = &rte_eth_devices[port_id];
1449 memset(stats, 0, sizeof(*stats));
1451 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1452 (*dev->dev_ops->stats_get)(dev, stats);
1453 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1458 rte_eth_stats_reset(uint8_t port_id)
1460 struct rte_eth_dev *dev;
1462 VALID_PORTID_OR_RET(port_id);
1463 dev = &rte_eth_devices[port_id];
1465 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1466 (*dev->dev_ops->stats_reset)(dev);
1469 /* retrieve ethdev extended statistics */
1471 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1474 struct rte_eth_stats eth_stats;
1475 struct rte_eth_dev *dev;
1476 unsigned count = 0, i, q;
1478 uint64_t val, *stats_ptr;
1480 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1482 dev = &rte_eth_devices[port_id];
1484 /* Return generic statistics */
1485 count = RTE_NB_STATS;
1487 /* implemented by the driver */
1488 if (dev->dev_ops->xstats_get != NULL) {
1489 /* Retrieve the xstats from the driver at the end of the
1492 xcount = (*dev->dev_ops->xstats_get)(dev, &xstats[count],
1493 (n > count) ? n - count : 0);
1498 count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
1499 count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
1502 if (n < count + xcount)
1503 return count + xcount;
1505 /* now fill the xstats structure */
1507 rte_eth_stats_get(port_id, ð_stats);
1510 for (i = 0; i < RTE_NB_STATS; i++) {
1511 stats_ptr = RTE_PTR_ADD(ð_stats,
1512 rte_stats_strings[i].offset);
1514 snprintf(xstats[count].name, sizeof(xstats[count].name),
1515 "%s", rte_stats_strings[i].name);
1516 xstats[count++].value = val;
1519 /* if xstats_get() is implemented by the PMD, the Q stats are done */
1520 if (dev->dev_ops->xstats_get != NULL)
1521 return count + xcount;
1524 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1525 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1526 stats_ptr = RTE_PTR_ADD(ð_stats,
1527 rte_rxq_stats_strings[i].offset +
1528 q * sizeof(uint64_t));
1530 snprintf(xstats[count].name, sizeof(xstats[count].name),
1532 rte_rxq_stats_strings[i].name);
1533 xstats[count++].value = val;
1538 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1539 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1540 stats_ptr = RTE_PTR_ADD(ð_stats,
1541 rte_txq_stats_strings[i].offset +
1542 q * sizeof(uint64_t));
1544 snprintf(xstats[count].name, sizeof(xstats[count].name),
1546 rte_txq_stats_strings[i].name);
1547 xstats[count++].value = val;
1551 return count + xcount;
1554 /* reset ethdev extended statistics */
1556 rte_eth_xstats_reset(uint8_t port_id)
1558 struct rte_eth_dev *dev;
1560 VALID_PORTID_OR_RET(port_id);
1561 dev = &rte_eth_devices[port_id];
1563 /* implemented by the driver */
1564 if (dev->dev_ops->xstats_reset != NULL) {
1565 (*dev->dev_ops->xstats_reset)(dev);
1569 /* fallback to default */
1570 rte_eth_stats_reset(port_id);
1574 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1577 struct rte_eth_dev *dev;
1579 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1581 dev = &rte_eth_devices[port_id];
1583 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1584 return (*dev->dev_ops->queue_stats_mapping_set)
1585 (dev, queue_id, stat_idx, is_rx);
1590 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1593 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1599 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1602 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1608 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1610 struct rte_eth_dev *dev;
1611 const struct rte_eth_desc_lim lim = {
1612 .nb_max = UINT16_MAX,
1617 VALID_PORTID_OR_RET(port_id);
1618 dev = &rte_eth_devices[port_id];
1620 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1621 dev_info->rx_desc_lim = lim;
1622 dev_info->tx_desc_lim = lim;
1624 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1625 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1626 dev_info->pci_dev = dev->pci_dev;
1628 dev_info->driver_name = dev->driver->pci_drv.name;
1632 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1634 struct rte_eth_dev *dev;
1636 VALID_PORTID_OR_RET(port_id);
1637 dev = &rte_eth_devices[port_id];
1638 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1643 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1645 struct rte_eth_dev *dev;
1647 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1649 dev = &rte_eth_devices[port_id];
1650 *mtu = dev->data->mtu;
1655 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1658 struct rte_eth_dev *dev;
1660 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1661 dev = &rte_eth_devices[port_id];
1662 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1664 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1666 dev->data->mtu = mtu;
1672 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1674 struct rte_eth_dev *dev;
1676 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1677 dev = &rte_eth_devices[port_id];
1678 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1679 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1683 if (vlan_id > 4095) {
1684 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1685 port_id, (unsigned) vlan_id);
1688 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1690 return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1694 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1696 struct rte_eth_dev *dev;
1698 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1699 dev = &rte_eth_devices[port_id];
1700 if (rx_queue_id >= dev->data->nb_rx_queues) {
1701 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1705 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1706 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1712 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1714 struct rte_eth_dev *dev;
1716 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1717 dev = &rte_eth_devices[port_id];
1718 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1719 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1725 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1727 struct rte_eth_dev *dev;
1732 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1733 dev = &rte_eth_devices[port_id];
1735 /*check which option changed by application*/
1736 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1737 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1739 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1740 mask |= ETH_VLAN_STRIP_MASK;
1743 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1744 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1746 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1747 mask |= ETH_VLAN_FILTER_MASK;
1750 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1751 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1753 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1754 mask |= ETH_VLAN_EXTEND_MASK;
1761 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1762 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1768 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1770 struct rte_eth_dev *dev;
1773 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1774 dev = &rte_eth_devices[port_id];
1776 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1777 ret |= ETH_VLAN_STRIP_OFFLOAD;
1779 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1780 ret |= ETH_VLAN_FILTER_OFFLOAD;
1782 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1783 ret |= ETH_VLAN_EXTEND_OFFLOAD;
1789 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1791 struct rte_eth_dev *dev;
1793 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1794 dev = &rte_eth_devices[port_id];
1795 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1796 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1802 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1804 struct rte_eth_dev *dev;
1806 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1807 dev = &rte_eth_devices[port_id];
1808 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1809 memset(fc_conf, 0, sizeof(*fc_conf));
1810 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1814 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1816 struct rte_eth_dev *dev;
1818 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1819 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1820 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1824 dev = &rte_eth_devices[port_id];
1825 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1826 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1830 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1832 struct rte_eth_dev *dev;
1834 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1835 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1836 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1840 dev = &rte_eth_devices[port_id];
1841 /* High water, low water validation are device specific */
1842 if (*dev->dev_ops->priority_flow_ctrl_set)
1843 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1848 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
1856 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
1857 PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
1858 RTE_RETA_GROUP_SIZE);
1862 num = reta_size / RTE_RETA_GROUP_SIZE;
1863 for (i = 0; i < num; i++) {
1864 if (reta_conf[i].mask)
1872 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
1876 uint16_t i, idx, shift;
1882 PMD_DEBUG_TRACE("No receive queue is available\n");
1886 for (i = 0; i < reta_size; i++) {
1887 idx = i / RTE_RETA_GROUP_SIZE;
1888 shift = i % RTE_RETA_GROUP_SIZE;
1889 if ((reta_conf[idx].mask & (1ULL << shift)) &&
1890 (reta_conf[idx].reta[shift] >= max_rxq)) {
1891 PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
1892 "the maximum rxq index: %u\n", idx, shift,
1893 reta_conf[idx].reta[shift], max_rxq);
1902 rte_eth_dev_rss_reta_update(uint8_t port_id,
1903 struct rte_eth_rss_reta_entry64 *reta_conf,
1906 struct rte_eth_dev *dev;
1909 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1910 /* Check mask bits */
1911 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
1915 dev = &rte_eth_devices[port_id];
1917 /* Check entry value */
1918 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
1919 dev->data->nb_rx_queues);
1923 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
1924 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
1928 rte_eth_dev_rss_reta_query(uint8_t port_id,
1929 struct rte_eth_rss_reta_entry64 *reta_conf,
1932 struct rte_eth_dev *dev;
1935 if (port_id >= nb_ports) {
1936 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1940 /* Check mask bits */
1941 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
1945 dev = &rte_eth_devices[port_id];
1946 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
1947 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
1951 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
1953 struct rte_eth_dev *dev;
1954 uint16_t rss_hash_protos;
1956 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1957 rss_hash_protos = rss_conf->rss_hf;
1958 if ((rss_hash_protos != 0) &&
1959 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
1960 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
1964 dev = &rte_eth_devices[port_id];
1965 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
1966 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
1970 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
1971 struct rte_eth_rss_conf *rss_conf)
1973 struct rte_eth_dev *dev;
1975 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1976 dev = &rte_eth_devices[port_id];
1977 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
1978 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
1982 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
1983 struct rte_eth_udp_tunnel *udp_tunnel)
1985 struct rte_eth_dev *dev;
1987 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1988 if (udp_tunnel == NULL) {
1989 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
1993 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
1994 PMD_DEBUG_TRACE("Invalid tunnel type\n");
1998 dev = &rte_eth_devices[port_id];
1999 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
2000 return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
2004 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
2005 struct rte_eth_udp_tunnel *udp_tunnel)
2007 struct rte_eth_dev *dev;
2009 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2010 dev = &rte_eth_devices[port_id];
2012 if (udp_tunnel == NULL) {
2013 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2017 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2018 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2022 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2023 return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2027 rte_eth_led_on(uint8_t port_id)
2029 struct rte_eth_dev *dev;
2031 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2032 dev = &rte_eth_devices[port_id];
2033 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2034 return (*dev->dev_ops->dev_led_on)(dev);
2038 rte_eth_led_off(uint8_t port_id)
2040 struct rte_eth_dev *dev;
2042 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2043 dev = &rte_eth_devices[port_id];
2044 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2045 return (*dev->dev_ops->dev_led_off)(dev);
2049 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2053 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2055 struct rte_eth_dev_info dev_info;
2056 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2059 rte_eth_dev_info_get(port_id, &dev_info);
2061 for (i = 0; i < dev_info.max_mac_addrs; i++)
2062 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2068 static const struct ether_addr null_mac_addr;
2071 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2074 struct rte_eth_dev *dev;
2078 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2079 dev = &rte_eth_devices[port_id];
2080 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2082 if (is_zero_ether_addr(addr)) {
2083 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2087 if (pool >= ETH_64_POOLS) {
2088 PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2092 index = get_mac_addr_index(port_id, addr);
2094 index = get_mac_addr_index(port_id, &null_mac_addr);
2096 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2101 pool_mask = dev->data->mac_pool_sel[index];
2103 /* Check if both MAC address and pool is already there, and do nothing */
2104 if (pool_mask & (1ULL << pool))
2109 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2111 /* Update address in NIC data structure */
2112 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2114 /* Update pool bitmap in NIC data structure */
2115 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2121 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2123 struct rte_eth_dev *dev;
2126 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2127 dev = &rte_eth_devices[port_id];
2128 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2130 index = get_mac_addr_index(port_id, addr);
2132 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2134 } else if (index < 0)
2135 return 0; /* Do nothing if address wasn't found */
2138 (*dev->dev_ops->mac_addr_remove)(dev, index);
2140 /* Update address in NIC data structure */
2141 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2143 /* reset pool bitmap */
2144 dev->data->mac_pool_sel[index] = 0;
2150 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2152 struct rte_eth_dev *dev;
2154 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2156 if (!is_valid_assigned_ether_addr(addr))
2159 dev = &rte_eth_devices[port_id];
2160 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2162 /* Update default address in NIC data structure */
2163 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2165 (*dev->dev_ops->mac_addr_set)(dev, addr);
2171 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2172 uint16_t rx_mode, uint8_t on)
2175 struct rte_eth_dev *dev;
2176 struct rte_eth_dev_info dev_info;
2178 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2180 dev = &rte_eth_devices[port_id];
2181 rte_eth_dev_info_get(port_id, &dev_info);
2183 num_vfs = dev_info.max_vfs;
2185 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2190 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2193 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2194 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2198 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2202 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2204 struct rte_eth_dev_info dev_info;
2205 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2208 rte_eth_dev_info_get(port_id, &dev_info);
2209 if (!dev->data->hash_mac_addrs)
2212 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2213 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2214 ETHER_ADDR_LEN) == 0)
2221 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2226 struct rte_eth_dev *dev;
2228 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2230 dev = &rte_eth_devices[port_id];
2231 if (is_zero_ether_addr(addr)) {
2232 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2237 index = get_hash_mac_addr_index(port_id, addr);
2238 /* Check if it's already there, and do nothing */
2239 if ((index >= 0) && (on))
2244 PMD_DEBUG_TRACE("port %d: the MAC address was not "
2245 "set in UTA\n", port_id);
2249 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2251 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2257 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2258 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2260 /* Update address in NIC data structure */
2262 ether_addr_copy(addr,
2263 &dev->data->hash_mac_addrs[index]);
2265 ether_addr_copy(&null_mac_addr,
2266 &dev->data->hash_mac_addrs[index]);
2273 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2275 struct rte_eth_dev *dev;
2277 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2279 dev = &rte_eth_devices[port_id];
2281 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2282 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2286 rte_eth_dev_set_vf_rx(uint8_t port_id, uint16_t vf, uint8_t on)
2289 struct rte_eth_dev *dev;
2290 struct rte_eth_dev_info dev_info;
2292 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2294 dev = &rte_eth_devices[port_id];
2295 rte_eth_dev_info_get(port_id, &dev_info);
2297 num_vfs = dev_info.max_vfs;
2299 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2303 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2304 return (*dev->dev_ops->set_vf_rx)(dev, vf, on);
2308 rte_eth_dev_set_vf_tx(uint8_t port_id, uint16_t vf, uint8_t on)
2311 struct rte_eth_dev *dev;
2312 struct rte_eth_dev_info dev_info;
2314 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2316 dev = &rte_eth_devices[port_id];
2317 rte_eth_dev_info_get(port_id, &dev_info);
2319 num_vfs = dev_info.max_vfs;
2321 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2325 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2326 return (*dev->dev_ops->set_vf_tx)(dev, vf, on);
2330 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2331 uint64_t vf_mask, uint8_t vlan_on)
2333 struct rte_eth_dev *dev;
2335 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2337 dev = &rte_eth_devices[port_id];
2339 if (vlan_id > ETHER_MAX_VLAN_ID) {
2340 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2346 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2350 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2351 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2355 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2358 struct rte_eth_dev *dev;
2359 struct rte_eth_dev_info dev_info;
2360 struct rte_eth_link link;
2362 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2364 dev = &rte_eth_devices[port_id];
2365 rte_eth_dev_info_get(port_id, &dev_info);
2366 link = dev->data->dev_link;
2368 if (queue_idx > dev_info.max_tx_queues) {
2369 PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2370 "invalid queue id=%d\n", port_id, queue_idx);
2374 if (tx_rate > link.link_speed) {
2375 PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2376 "bigger than link speed= %d\n",
2377 tx_rate, link.link_speed);
2381 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2382 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2385 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2388 struct rte_eth_dev *dev;
2389 struct rte_eth_dev_info dev_info;
2390 struct rte_eth_link link;
2395 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2397 dev = &rte_eth_devices[port_id];
2398 rte_eth_dev_info_get(port_id, &dev_info);
2399 link = dev->data->dev_link;
2401 if (vf > dev_info.max_vfs) {
2402 PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2403 "invalid vf id=%d\n", port_id, vf);
2407 if (tx_rate > link.link_speed) {
2408 PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2409 "bigger than link speed= %d\n",
2410 tx_rate, link.link_speed);
2414 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2415 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2419 rte_eth_mirror_rule_set(uint8_t port_id,
2420 struct rte_eth_mirror_conf *mirror_conf,
2421 uint8_t rule_id, uint8_t on)
2423 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2425 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2426 if (mirror_conf->rule_type == 0) {
2427 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2431 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2432 PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2437 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2438 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2439 (mirror_conf->pool_mask == 0)) {
2440 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2444 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2445 mirror_conf->vlan.vlan_mask == 0) {
2446 PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2450 dev = &rte_eth_devices[port_id];
2451 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2453 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2457 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2459 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2461 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2463 dev = &rte_eth_devices[port_id];
2464 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2466 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2469 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2471 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2472 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2474 struct rte_eth_dev *dev;
2476 VALID_PORTID_OR_ERR_RET(port_id, 0);
2478 dev = &rte_eth_devices[port_id];
2479 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);
2480 if (queue_id >= dev->data->nb_rx_queues) {
2481 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2484 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2489 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2490 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2492 struct rte_eth_dev *dev;
2494 VALID_PORTID_OR_ERR_RET(port_id, 0);
2496 dev = &rte_eth_devices[port_id];
2498 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0);
2499 if (queue_id >= dev->data->nb_tx_queues) {
2500 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2503 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2508 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2510 struct rte_eth_dev *dev;
2512 VALID_PORTID_OR_ERR_RET(port_id, 0);
2514 dev = &rte_eth_devices[port_id];
2515 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0);
2516 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2520 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2522 struct rte_eth_dev *dev;
2524 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2526 dev = &rte_eth_devices[port_id];
2527 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2528 return (*dev->dev_ops->rx_descriptor_done)(dev->data->rx_queues[queue_id],
2534 rte_eth_dev_callback_register(uint8_t port_id,
2535 enum rte_eth_event_type event,
2536 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2538 struct rte_eth_dev *dev;
2539 struct rte_eth_dev_callback *user_cb;
2544 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2546 dev = &rte_eth_devices[port_id];
2547 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2549 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2550 if (user_cb->cb_fn == cb_fn &&
2551 user_cb->cb_arg == cb_arg &&
2552 user_cb->event == event) {
2557 /* create a new callback. */
2558 if (user_cb == NULL)
2559 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2560 sizeof(struct rte_eth_dev_callback), 0);
2561 if (user_cb != NULL) {
2562 user_cb->cb_fn = cb_fn;
2563 user_cb->cb_arg = cb_arg;
2564 user_cb->event = event;
2565 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2568 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2569 return (user_cb == NULL) ? -ENOMEM : 0;
2573 rte_eth_dev_callback_unregister(uint8_t port_id,
2574 enum rte_eth_event_type event,
2575 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2578 struct rte_eth_dev *dev;
2579 struct rte_eth_dev_callback *cb, *next;
2584 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2586 dev = &rte_eth_devices[port_id];
2587 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2590 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2592 next = TAILQ_NEXT(cb, next);
2594 if (cb->cb_fn != cb_fn || cb->event != event ||
2595 (cb->cb_arg != (void *)-1 &&
2596 cb->cb_arg != cb_arg))
2600 * if this callback is not executing right now,
2603 if (cb->active == 0) {
2604 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2611 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2616 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2617 enum rte_eth_event_type event)
2619 struct rte_eth_dev_callback *cb_lst;
2620 struct rte_eth_dev_callback dev_cb;
2622 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2623 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2624 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2628 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2629 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2631 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2634 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2638 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
2641 struct rte_eth_dev *dev;
2642 struct rte_intr_handle *intr_handle;
2646 if (!rte_eth_dev_is_valid_port(port_id)) {
2647 PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
2651 dev = &rte_eth_devices[port_id];
2652 intr_handle = &dev->pci_dev->intr_handle;
2653 if (!intr_handle->intr_vec) {
2654 PMD_DEBUG_TRACE("RX Intr vector unset\n");
2658 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2659 vec = intr_handle->intr_vec[qid];
2660 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2661 if (rc && rc != -EEXIST) {
2662 PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2663 " op %d epfd %d vec %u\n",
2664 port_id, qid, op, epfd, vec);
2672 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
2673 int epfd, int op, void *data)
2676 struct rte_eth_dev *dev;
2677 struct rte_intr_handle *intr_handle;
2680 if (!rte_eth_dev_is_valid_port(port_id)) {
2681 PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
2685 dev = &rte_eth_devices[port_id];
2686 if (queue_id >= dev->data->nb_rx_queues) {
2687 PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
2691 intr_handle = &dev->pci_dev->intr_handle;
2692 if (!intr_handle->intr_vec) {
2693 PMD_DEBUG_TRACE("RX Intr vector unset\n");
2697 vec = intr_handle->intr_vec[queue_id];
2698 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2699 if (rc && rc != -EEXIST) {
2700 PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2701 " op %d epfd %d vec %u\n",
2702 port_id, queue_id, op, epfd, vec);
2710 rte_eth_dev_rx_intr_enable(uint8_t port_id,
2713 struct rte_eth_dev *dev;
2715 if (!rte_eth_dev_is_valid_port(port_id)) {
2716 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2720 dev = &rte_eth_devices[port_id];
2722 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
2723 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
2727 rte_eth_dev_rx_intr_disable(uint8_t port_id,
2730 struct rte_eth_dev *dev;
2732 if (!rte_eth_dev_is_valid_port(port_id)) {
2733 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2737 dev = &rte_eth_devices[port_id];
2739 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
2740 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
2743 #ifdef RTE_NIC_BYPASS
2744 int rte_eth_dev_bypass_init(uint8_t port_id)
2746 struct rte_eth_dev *dev;
2748 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2750 dev = &rte_eth_devices[port_id];
2751 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2752 (*dev->dev_ops->bypass_init)(dev);
2757 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2759 struct rte_eth_dev *dev;
2761 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2763 dev = &rte_eth_devices[port_id];
2764 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2765 (*dev->dev_ops->bypass_state_show)(dev, state);
2770 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2772 struct rte_eth_dev *dev;
2774 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2776 dev = &rte_eth_devices[port_id];
2777 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2778 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2783 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2785 struct rte_eth_dev *dev;
2787 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2789 dev = &rte_eth_devices[port_id];
2790 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2791 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2796 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2798 struct rte_eth_dev *dev;
2800 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2802 dev = &rte_eth_devices[port_id];
2804 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2805 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2810 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2812 struct rte_eth_dev *dev;
2814 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2816 dev = &rte_eth_devices[port_id];
2818 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2819 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2824 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2826 struct rte_eth_dev *dev;
2828 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2830 dev = &rte_eth_devices[port_id];
2832 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2833 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2838 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2840 struct rte_eth_dev *dev;
2842 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2844 dev = &rte_eth_devices[port_id];
2846 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2847 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2852 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2854 struct rte_eth_dev *dev;
2856 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2858 dev = &rte_eth_devices[port_id];
2860 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2861 (*dev->dev_ops->bypass_wd_reset)(dev);
2867 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
2869 struct rte_eth_dev *dev;
2871 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2873 dev = &rte_eth_devices[port_id];
2874 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2875 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
2876 RTE_ETH_FILTER_NOP, NULL);
2880 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
2881 enum rte_filter_op filter_op, void *arg)
2883 struct rte_eth_dev *dev;
2885 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2887 dev = &rte_eth_devices[port_id];
2888 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2889 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
2893 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
2894 rte_rx_callback_fn fn, void *user_param)
2896 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2897 rte_errno = ENOTSUP;
2900 /* check input parameters */
2901 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2902 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2907 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2915 cb->param = user_param;
2917 /* Add the callbacks in fifo order. */
2918 struct rte_eth_rxtx_callback *tail =
2919 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2922 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2934 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
2935 rte_tx_callback_fn fn, void *user_param)
2937 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2938 rte_errno = ENOTSUP;
2941 /* check input parameters */
2942 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2943 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
2948 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2956 cb->param = user_param;
2958 /* Add the callbacks in fifo order. */
2959 struct rte_eth_rxtx_callback *tail =
2960 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
2963 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
2975 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
2976 struct rte_eth_rxtx_callback *user_cb)
2978 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2981 /* Check input parameters. */
2982 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
2983 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2987 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2988 struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
2989 struct rte_eth_rxtx_callback *prev_cb;
2991 /* Reset head pointer and remove user cb if first in the list. */
2992 if (cb == user_cb) {
2993 dev->post_rx_burst_cbs[queue_id] = user_cb->next;
2997 /* Remove the user cb from the callback list. */
3002 if (cb == user_cb) {
3003 prev_cb->next = user_cb->next;
3007 } while (cb != NULL);
3009 /* Callback wasn't found. */
3014 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3015 struct rte_eth_rxtx_callback *user_cb)
3017 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3020 /* Check input parameters. */
3021 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
3022 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3026 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3027 struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
3028 struct rte_eth_rxtx_callback *prev_cb;
3030 /* Reset head pointer and remove user cb if first in the list. */
3031 if (cb == user_cb) {
3032 dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
3036 /* Remove the user cb from the callback list. */
3041 if (cb == user_cb) {
3042 prev_cb->next = user_cb->next;
3046 } while (cb != NULL);
3048 /* Callback wasn't found. */
3053 rte_eth_rx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3054 struct rte_eth_rxq_info *qinfo)
3056 struct rte_eth_dev *dev;
3058 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3063 dev = &rte_eth_devices[port_id];
3064 if (queue_id >= dev->data->nb_rx_queues) {
3065 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3069 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3071 memset(qinfo, 0, sizeof(*qinfo));
3072 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3077 rte_eth_tx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3078 struct rte_eth_txq_info *qinfo)
3080 struct rte_eth_dev *dev;
3082 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3087 dev = &rte_eth_devices[port_id];
3088 if (queue_id >= dev->data->nb_tx_queues) {
3089 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3093 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3095 memset(qinfo, 0, sizeof(*qinfo));
3096 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3101 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3102 struct ether_addr *mc_addr_set,
3103 uint32_t nb_mc_addr)
3105 struct rte_eth_dev *dev;
3107 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3109 dev = &rte_eth_devices[port_id];
3110 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3111 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3115 rte_eth_timesync_enable(uint8_t port_id)
3117 struct rte_eth_dev *dev;
3119 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3120 dev = &rte_eth_devices[port_id];
3122 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3123 return (*dev->dev_ops->timesync_enable)(dev);
3127 rte_eth_timesync_disable(uint8_t port_id)
3129 struct rte_eth_dev *dev;
3131 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3132 dev = &rte_eth_devices[port_id];
3134 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3135 return (*dev->dev_ops->timesync_disable)(dev);
3139 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3142 struct rte_eth_dev *dev;
3144 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3145 dev = &rte_eth_devices[port_id];
3147 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3148 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3152 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3154 struct rte_eth_dev *dev;
3156 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3157 dev = &rte_eth_devices[port_id];
3159 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3160 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3164 rte_eth_dev_get_reg_length(uint8_t port_id)
3166 struct rte_eth_dev *dev;
3168 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3170 dev = &rte_eth_devices[port_id];
3171 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg_length, -ENOTSUP);
3172 return (*dev->dev_ops->get_reg_length)(dev);
3176 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3178 struct rte_eth_dev *dev;
3180 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3182 dev = &rte_eth_devices[port_id];
3183 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3184 return (*dev->dev_ops->get_reg)(dev, info);
3188 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3190 struct rte_eth_dev *dev;
3192 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3194 dev = &rte_eth_devices[port_id];
3195 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3196 return (*dev->dev_ops->get_eeprom_length)(dev);
3200 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3202 struct rte_eth_dev *dev;
3204 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3206 dev = &rte_eth_devices[port_id];
3207 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3208 return (*dev->dev_ops->get_eeprom)(dev, info);
3212 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3214 struct rte_eth_dev *dev;
3216 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3218 dev = &rte_eth_devices[port_id];
3219 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3220 return (*dev->dev_ops->set_eeprom)(dev, info);
3224 rte_eth_dev_get_dcb_info(uint8_t port_id,
3225 struct rte_eth_dcb_info *dcb_info)
3227 struct rte_eth_dev *dev;
3229 if (!rte_eth_dev_is_valid_port(port_id)) {
3230 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3234 dev = &rte_eth_devices[port_id];
3235 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3237 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3238 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);