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_packets", offsetof(struct rte_eth_stats, ipackets)},
141 {"tx_packets", offsetof(struct rte_eth_stats, opackets)},
142 {"rx_bytes", offsetof(struct rte_eth_stats, ibytes)},
143 {"tx_bytes", offsetof(struct rte_eth_stats, obytes)},
144 {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
145 {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
146 {"alloc_rx_buff_failed", offsetof(struct rte_eth_stats, rx_nombuf)},
148 #define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
150 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
151 {"rx_packets", offsetof(struct rte_eth_stats, q_ipackets)},
152 {"rx_bytes", offsetof(struct rte_eth_stats, q_ibytes)},
154 #define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) / \
155 sizeof(rte_rxq_stats_strings[0]))
157 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
158 {"tx_packets", offsetof(struct rte_eth_stats, q_opackets)},
159 {"tx_bytes", offsetof(struct rte_eth_stats, q_obytes)},
160 {"tx_errors", offsetof(struct rte_eth_stats, q_errors)},
162 #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) / \
163 sizeof(rte_txq_stats_strings[0]))
167 * The user application callback description.
169 * It contains callback address to be registered by user application,
170 * the pointer to the parameters for callback, and the event type.
172 struct rte_eth_dev_callback {
173 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
174 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
175 void *cb_arg; /**< Parameter for callback */
176 enum rte_eth_event_type event; /**< Interrupt event type */
177 uint32_t active; /**< Callback is executing */
191 rte_eth_dev_data_alloc(void)
193 const unsigned flags = 0;
194 const struct rte_memzone *mz;
196 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
197 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
198 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
199 rte_socket_id(), flags);
201 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
203 rte_panic("Cannot allocate memzone for ethernet port data\n");
205 rte_eth_dev_data = mz->addr;
206 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
207 memset(rte_eth_dev_data, 0,
208 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
212 rte_eth_dev_allocated(const char *name)
216 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
217 if ((rte_eth_devices[i].attached == DEV_ATTACHED) &&
218 strcmp(rte_eth_devices[i].data->name, name) == 0)
219 return &rte_eth_devices[i];
225 rte_eth_dev_find_free_port(void)
229 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
230 if (rte_eth_devices[i].attached == DEV_DETACHED)
233 return RTE_MAX_ETHPORTS;
237 rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
240 struct rte_eth_dev *eth_dev;
242 port_id = rte_eth_dev_find_free_port();
243 if (port_id == RTE_MAX_ETHPORTS) {
244 PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
248 if (rte_eth_dev_data == NULL)
249 rte_eth_dev_data_alloc();
251 if (rte_eth_dev_allocated(name) != NULL) {
252 PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n",
257 eth_dev = &rte_eth_devices[port_id];
258 eth_dev->data = &rte_eth_dev_data[port_id];
259 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
260 eth_dev->data->port_id = port_id;
261 eth_dev->attached = DEV_ATTACHED;
262 eth_dev->dev_type = type;
268 rte_eth_dev_create_unique_device_name(char *name, size_t size,
269 struct rte_pci_device *pci_dev)
273 if ((name == NULL) || (pci_dev == NULL))
276 ret = snprintf(name, size, "%d:%d.%d",
277 pci_dev->addr.bus, pci_dev->addr.devid,
278 pci_dev->addr.function);
285 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
290 eth_dev->attached = DEV_DETACHED;
296 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
297 struct rte_pci_device *pci_dev)
299 struct eth_driver *eth_drv;
300 struct rte_eth_dev *eth_dev;
301 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
305 eth_drv = (struct eth_driver *)pci_drv;
307 /* Create unique Ethernet device name using PCI address */
308 rte_eth_dev_create_unique_device_name(ethdev_name,
309 sizeof(ethdev_name), pci_dev);
311 eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
315 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
316 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
317 eth_drv->dev_private_size,
318 RTE_CACHE_LINE_SIZE);
319 if (eth_dev->data->dev_private == NULL)
320 rte_panic("Cannot allocate memzone for private port data\n");
322 eth_dev->pci_dev = pci_dev;
323 eth_dev->driver = eth_drv;
324 eth_dev->data->rx_mbuf_alloc_failed = 0;
326 /* init user callbacks */
327 TAILQ_INIT(&(eth_dev->link_intr_cbs));
330 * Set the default MTU.
332 eth_dev->data->mtu = ETHER_MTU;
334 /* Invoke PMD device initialization function */
335 diag = (*eth_drv->eth_dev_init)(eth_dev);
339 PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x) failed\n",
341 (unsigned) pci_dev->id.vendor_id,
342 (unsigned) pci_dev->id.device_id);
343 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
344 rte_free(eth_dev->data->dev_private);
345 rte_eth_dev_release_port(eth_dev);
350 rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
352 const struct eth_driver *eth_drv;
353 struct rte_eth_dev *eth_dev;
354 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
360 /* Create unique Ethernet device name using PCI address */
361 rte_eth_dev_create_unique_device_name(ethdev_name,
362 sizeof(ethdev_name), pci_dev);
364 eth_dev = rte_eth_dev_allocated(ethdev_name);
368 eth_drv = (const struct eth_driver *)pci_dev->driver;
370 /* Invoke PMD device uninit function */
371 if (*eth_drv->eth_dev_uninit) {
372 ret = (*eth_drv->eth_dev_uninit)(eth_dev);
377 /* free ether device */
378 rte_eth_dev_release_port(eth_dev);
380 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
381 rte_free(eth_dev->data->dev_private);
383 eth_dev->pci_dev = NULL;
384 eth_dev->driver = NULL;
385 eth_dev->data = NULL;
391 * Register an Ethernet [Poll Mode] driver.
393 * Function invoked by the initialization function of an Ethernet driver
394 * to simultaneously register itself as a PCI driver and as an Ethernet
396 * Invokes the rte_eal_pci_register() function to register the *pci_drv*
397 * structure embedded in the *eth_drv* structure, after having stored the
398 * address of the rte_eth_dev_init() function in the *devinit* field of
399 * the *pci_drv* structure.
400 * During the PCI probing phase, the rte_eth_dev_init() function is
401 * invoked for each PCI [Ethernet device] matching the embedded PCI
402 * identifiers provided by the driver.
405 rte_eth_driver_register(struct eth_driver *eth_drv)
407 eth_drv->pci_drv.devinit = rte_eth_dev_init;
408 eth_drv->pci_drv.devuninit = rte_eth_dev_uninit;
409 rte_eal_pci_register(ð_drv->pci_drv);
413 rte_eth_dev_is_valid_port(uint8_t port_id)
415 if (port_id >= RTE_MAX_ETHPORTS ||
416 rte_eth_devices[port_id].attached != DEV_ATTACHED)
423 rte_eth_dev_socket_id(uint8_t port_id)
425 if (!rte_eth_dev_is_valid_port(port_id))
427 return rte_eth_devices[port_id].pci_dev->numa_node;
431 rte_eth_dev_count(void)
436 static enum rte_eth_dev_type
437 rte_eth_dev_get_device_type(uint8_t port_id)
439 if (!rte_eth_dev_is_valid_port(port_id))
440 return RTE_ETH_DEV_UNKNOWN;
441 return rte_eth_devices[port_id].dev_type;
445 rte_eth_dev_save(struct rte_eth_dev *devs, size_t size)
447 if ((devs == NULL) ||
448 (size != sizeof(struct rte_eth_dev) * RTE_MAX_ETHPORTS))
451 /* save current rte_eth_devices */
452 memcpy(devs, rte_eth_devices, size);
457 rte_eth_dev_get_changed_port(struct rte_eth_dev *devs, uint8_t *port_id)
459 if ((devs == NULL) || (port_id == NULL))
462 /* check which port was attached or detached */
463 for (*port_id = 0; *port_id < RTE_MAX_ETHPORTS; (*port_id)++, devs++) {
464 if (rte_eth_devices[*port_id].attached ^ devs->attached)
471 rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr)
473 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
476 PMD_DEBUG_TRACE("Null pointer is specified\n");
480 *addr = rte_eth_devices[port_id].pci_dev->addr;
485 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
489 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
492 PMD_DEBUG_TRACE("Null pointer is specified\n");
496 /* shouldn't check 'rte_eth_devices[i].data',
497 * because it might be overwritten by VDEV PMD */
498 tmp = rte_eth_dev_data[port_id].name;
504 rte_eth_dev_is_detachable(uint8_t port_id)
508 if (port_id >= RTE_MAX_ETHPORTS) {
509 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
513 if (rte_eth_devices[port_id].dev_type == RTE_ETH_DEV_PCI) {
514 switch (rte_eth_devices[port_id].pci_dev->kdrv) {
515 case RTE_KDRV_IGB_UIO:
516 case RTE_KDRV_UIO_GENERIC:
517 case RTE_KDRV_NIC_UIO:
525 drv_flags = rte_eth_devices[port_id].driver->pci_drv.drv_flags;
526 return !(drv_flags & RTE_PCI_DRV_DETACHABLE);
529 /* attach the new physical device, then store port_id of the device */
531 rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
534 struct rte_eth_dev devs[RTE_MAX_ETHPORTS];
536 if ((addr == NULL) || (port_id == NULL))
539 /* save current port status */
540 if (rte_eth_dev_save(devs, sizeof(devs)))
542 /* re-construct pci_device_list */
543 if (rte_eal_pci_scan())
545 /* invoke probe func of the driver can handle the new device.
547 * rte_eal_pci_probe_one() should return port_id.
548 * And rte_eth_dev_save() and rte_eth_dev_get_changed_port()
549 * should be removed. */
550 if (rte_eal_pci_probe_one(addr))
552 /* get port_id enabled by above procedures */
553 if (rte_eth_dev_get_changed_port(devs, &new_port_id))
556 *port_id = new_port_id;
559 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
563 /* detach the new physical device, then store pci_addr of the device */
565 rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
567 struct rte_pci_addr freed_addr;
568 struct rte_pci_addr vp;
573 /* check whether the driver supports detach feature, or not */
574 if (rte_eth_dev_is_detachable(port_id))
577 /* get pci address by port id */
578 if (rte_eth_dev_get_addr_by_port(port_id, &freed_addr))
581 /* Zeroed pci addr means the port comes from virtual device */
582 vp.domain = vp.bus = vp.devid = vp.function = 0;
583 if (rte_eal_compare_pci_addr(&vp, &freed_addr) == 0)
586 /* invoke devuninit func of the pci driver,
587 * also remove the device from pci_device_list */
588 if (rte_eal_pci_detach(&freed_addr))
594 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
598 /* attach the new virtual device, then store port_id of the device */
600 rte_eth_dev_attach_vdev(const char *vdevargs, uint8_t *port_id)
602 char *name = NULL, *args = NULL;
604 struct rte_eth_dev devs[RTE_MAX_ETHPORTS];
607 if ((vdevargs == NULL) || (port_id == NULL))
610 /* parse vdevargs, then retrieve device name and args */
611 if (rte_eal_parse_devargs_str(vdevargs, &name, &args))
614 /* save current port status */
615 if (rte_eth_dev_save(devs, sizeof(devs)))
617 /* walk around dev_driver_list to find the driver of the device,
618 * then invoke probe function o the driver.
620 * rte_eal_vdev_init() should return port_id,
621 * And rte_eth_dev_save() and rte_eth_dev_get_changed_port()
622 * should be removed. */
623 if (rte_eal_vdev_init(name, args))
625 /* get port_id enabled by above procedures */
626 if (rte_eth_dev_get_changed_port(devs, &new_port_id))
629 *port_id = new_port_id;
637 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
641 /* detach the new virtual device, then store the name of the device */
643 rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
645 char name[RTE_ETH_NAME_MAX_LEN];
647 if (vdevname == NULL)
650 /* check whether the driver supports detach feature, or not */
651 if (rte_eth_dev_is_detachable(port_id))
654 /* get device name by port id */
655 if (rte_eth_dev_get_name_by_port(port_id, name))
657 /* walk around dev_driver_list to find the driver of the device,
658 * then invoke uninit function of the driver */
659 if (rte_eal_vdev_uninit(name))
662 strncpy(vdevname, name, sizeof(name));
665 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
669 /* attach the new device, then store port_id of the device */
671 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
673 struct rte_pci_addr addr;
675 if ((devargs == NULL) || (port_id == NULL))
678 if (eal_parse_pci_DomBDF(devargs, &addr) == 0)
679 return rte_eth_dev_attach_pdev(&addr, port_id);
681 return rte_eth_dev_attach_vdev(devargs, port_id);
684 /* detach the device, then store the name of the device */
686 rte_eth_dev_detach(uint8_t port_id, char *name)
688 struct rte_pci_addr addr;
694 if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {
695 ret = rte_eth_dev_get_addr_by_port(port_id, &addr);
699 ret = rte_eth_dev_detach_pdev(port_id, &addr);
701 snprintf(name, RTE_ETH_NAME_MAX_LEN,
703 addr.domain, addr.bus,
704 addr.devid, addr.function);
708 return rte_eth_dev_detach_vdev(port_id, name);
712 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
714 uint16_t old_nb_queues = dev->data->nb_rx_queues;
718 if (dev->data->rx_queues == NULL) { /* first time configuration */
719 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
720 sizeof(dev->data->rx_queues[0]) * nb_queues,
721 RTE_CACHE_LINE_SIZE);
722 if (dev->data->rx_queues == NULL) {
723 dev->data->nb_rx_queues = 0;
726 } else { /* re-configure */
727 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
729 rxq = dev->data->rx_queues;
731 for (i = nb_queues; i < old_nb_queues; i++)
732 (*dev->dev_ops->rx_queue_release)(rxq[i]);
733 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
734 RTE_CACHE_LINE_SIZE);
737 if (nb_queues > old_nb_queues) {
738 uint16_t new_qs = nb_queues - old_nb_queues;
740 memset(rxq + old_nb_queues, 0,
741 sizeof(rxq[0]) * new_qs);
744 dev->data->rx_queues = rxq;
747 dev->data->nb_rx_queues = nb_queues;
752 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
754 struct rte_eth_dev *dev;
756 /* This function is only safe when called from the primary process
757 * in a multi-process setup*/
758 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
760 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
762 dev = &rte_eth_devices[port_id];
763 if (rx_queue_id >= dev->data->nb_rx_queues) {
764 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
768 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
770 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
775 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
777 struct rte_eth_dev *dev;
779 /* This function is only safe when called from the primary process
780 * in a multi-process setup*/
781 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
783 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
785 dev = &rte_eth_devices[port_id];
786 if (rx_queue_id >= dev->data->nb_rx_queues) {
787 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
791 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
793 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
798 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
800 struct rte_eth_dev *dev;
802 /* This function is only safe when called from the primary process
803 * in a multi-process setup*/
804 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
806 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
808 dev = &rte_eth_devices[port_id];
809 if (tx_queue_id >= dev->data->nb_tx_queues) {
810 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
814 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
816 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
821 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
823 struct rte_eth_dev *dev;
825 /* This function is only safe when called from the primary process
826 * in a multi-process setup*/
827 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
829 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
831 dev = &rte_eth_devices[port_id];
832 if (tx_queue_id >= dev->data->nb_tx_queues) {
833 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
837 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
839 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
844 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
846 uint16_t old_nb_queues = dev->data->nb_tx_queues;
850 if (dev->data->tx_queues == NULL) { /* first time configuration */
851 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
852 sizeof(dev->data->tx_queues[0]) * nb_queues,
853 RTE_CACHE_LINE_SIZE);
854 if (dev->data->tx_queues == NULL) {
855 dev->data->nb_tx_queues = 0;
858 } else { /* re-configure */
859 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
861 txq = dev->data->tx_queues;
863 for (i = nb_queues; i < old_nb_queues; i++)
864 (*dev->dev_ops->tx_queue_release)(txq[i]);
865 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
866 RTE_CACHE_LINE_SIZE);
869 if (nb_queues > old_nb_queues) {
870 uint16_t new_qs = nb_queues - old_nb_queues;
872 memset(txq + old_nb_queues, 0,
873 sizeof(txq[0]) * new_qs);
876 dev->data->tx_queues = txq;
879 dev->data->nb_tx_queues = nb_queues;
884 rte_eth_dev_check_vf_rss_rxq_num(uint8_t port_id, uint16_t nb_rx_q)
886 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
891 RTE_ETH_DEV_SRIOV(dev).active =
895 RTE_ETH_DEV_SRIOV(dev).active =
902 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = nb_rx_q;
903 RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx =
904 dev->pci_dev->max_vfs * nb_rx_q;
910 rte_eth_dev_check_mq_mode(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
911 const struct rte_eth_conf *dev_conf)
913 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
915 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
916 /* check multi-queue mode */
917 if ((dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) ||
918 (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB_RSS) ||
919 (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB)) {
920 /* SRIOV only works in VMDq enable mode */
921 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
923 "wrong VMDQ mq_mode rx %u tx %u\n",
925 dev_conf->rxmode.mq_mode,
926 dev_conf->txmode.mq_mode);
930 switch (dev_conf->rxmode.mq_mode) {
931 case ETH_MQ_RX_VMDQ_DCB:
932 case ETH_MQ_RX_VMDQ_DCB_RSS:
933 /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
934 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
936 "unsupported VMDQ mq_mode rx %u\n",
937 port_id, dev_conf->rxmode.mq_mode);
940 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
942 "Rx mq mode is changed from:"
943 "mq_mode %u into VMDQ mq_mode %u\n",
945 dev_conf->rxmode.mq_mode,
946 dev->data->dev_conf.rxmode.mq_mode);
947 case ETH_MQ_RX_VMDQ_RSS:
948 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_RSS;
949 if (nb_rx_q <= RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)
950 if (rte_eth_dev_check_vf_rss_rxq_num(port_id, nb_rx_q) != 0) {
951 PMD_DEBUG_TRACE("ethdev port_id=%d"
952 " SRIOV active, invalid queue"
953 " number for VMDQ RSS, allowed"
954 " value are 1, 2 or 4\n",
959 default: /* ETH_MQ_RX_VMDQ_ONLY or ETH_MQ_RX_NONE */
960 /* if nothing mq mode configure, use default scheme */
961 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
962 if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
963 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
967 switch (dev_conf->txmode.mq_mode) {
968 case ETH_MQ_TX_VMDQ_DCB:
969 /* DCB VMDQ in SRIOV mode, not implement yet */
970 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
972 "unsupported VMDQ mq_mode tx %u\n",
973 port_id, dev_conf->txmode.mq_mode);
975 default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
976 /* if nothing mq mode configure, use default scheme */
977 dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
981 /* check valid queue number */
982 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
983 (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
984 PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
985 "queue number must less equal to %d\n",
987 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
991 /* For vmdb+dcb mode check our configuration before we go further */
992 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB) {
993 const struct rte_eth_vmdq_dcb_conf *conf;
995 if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
996 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
998 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
1001 conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
1002 if (!(conf->nb_queue_pools == ETH_16_POOLS ||
1003 conf->nb_queue_pools == ETH_32_POOLS)) {
1004 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
1005 "nb_queue_pools must be %d or %d\n",
1006 port_id, ETH_16_POOLS, ETH_32_POOLS);
1010 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
1011 const struct rte_eth_vmdq_dcb_tx_conf *conf;
1013 if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
1014 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
1016 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
1019 conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
1020 if (!(conf->nb_queue_pools == ETH_16_POOLS ||
1021 conf->nb_queue_pools == ETH_32_POOLS)) {
1022 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
1023 "nb_queue_pools != %d or nb_queue_pools "
1025 port_id, ETH_16_POOLS, ETH_32_POOLS);
1030 /* For DCB mode check our configuration before we go further */
1031 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) {
1032 const struct rte_eth_dcb_rx_conf *conf;
1034 if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
1035 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
1037 port_id, ETH_DCB_NUM_QUEUES);
1040 conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
1041 if (!(conf->nb_tcs == ETH_4_TCS ||
1042 conf->nb_tcs == ETH_8_TCS)) {
1043 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
1044 "nb_tcs != %d or nb_tcs "
1046 port_id, ETH_4_TCS, ETH_8_TCS);
1051 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
1052 const struct rte_eth_dcb_tx_conf *conf;
1054 if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
1055 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
1057 port_id, ETH_DCB_NUM_QUEUES);
1060 conf = &(dev_conf->tx_adv_conf.dcb_tx_conf);
1061 if (!(conf->nb_tcs == ETH_4_TCS ||
1062 conf->nb_tcs == ETH_8_TCS)) {
1063 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
1064 "nb_tcs != %d or nb_tcs "
1066 port_id, ETH_4_TCS, ETH_8_TCS);
1075 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
1076 const struct rte_eth_conf *dev_conf)
1078 struct rte_eth_dev *dev;
1079 struct rte_eth_dev_info dev_info;
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 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
1090 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
1091 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
1095 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
1097 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
1098 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
1102 dev = &rte_eth_devices[port_id];
1104 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1105 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
1107 if (dev->data->dev_started) {
1109 "port %d must be stopped to allow configuration\n", port_id);
1114 * Check that the numbers of RX and TX queues are not greater
1115 * than the maximum number of RX and TX queues supported by the
1116 * configured device.
1118 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
1119 if (nb_rx_q > dev_info.max_rx_queues) {
1120 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
1121 port_id, nb_rx_q, dev_info.max_rx_queues);
1125 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
1129 if (nb_tx_q > dev_info.max_tx_queues) {
1130 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
1131 port_id, nb_tx_q, dev_info.max_tx_queues);
1135 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
1139 /* Copy the dev_conf parameter into the dev structure */
1140 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
1143 * If link state interrupt is enabled, check that the
1144 * device supports it.
1146 if (dev_conf->intr_conf.lsc == 1) {
1147 const struct rte_pci_driver *pci_drv = &dev->driver->pci_drv;
1149 if (!(pci_drv->drv_flags & RTE_PCI_DRV_INTR_LSC)) {
1150 PMD_DEBUG_TRACE("driver %s does not support lsc\n",
1157 * If jumbo frames are enabled, check that the maximum RX packet
1158 * length is supported by the configured device.
1160 if (dev_conf->rxmode.jumbo_frame == 1) {
1161 if (dev_conf->rxmode.max_rx_pkt_len >
1162 dev_info.max_rx_pktlen) {
1163 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
1164 " > max valid value %u\n",
1166 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
1167 (unsigned)dev_info.max_rx_pktlen);
1169 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
1170 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
1171 " < min valid value %u\n",
1173 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
1174 (unsigned)ETHER_MIN_LEN);
1178 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
1179 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
1180 /* Use default value */
1181 dev->data->dev_conf.rxmode.max_rx_pkt_len =
1185 /* multiple queue mode checking */
1186 diag = rte_eth_dev_check_mq_mode(port_id, nb_rx_q, nb_tx_q, dev_conf);
1188 PMD_DEBUG_TRACE("port%d rte_eth_dev_check_mq_mode = %d\n",
1194 * Setup new number of RX/TX queues and reconfigure device.
1196 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
1198 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
1203 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
1205 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
1207 rte_eth_dev_rx_queue_config(dev, 0);
1211 diag = (*dev->dev_ops->dev_configure)(dev);
1213 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
1215 rte_eth_dev_rx_queue_config(dev, 0);
1216 rte_eth_dev_tx_queue_config(dev, 0);
1224 rte_eth_dev_config_restore(uint8_t port_id)
1226 struct rte_eth_dev *dev;
1227 struct rte_eth_dev_info dev_info;
1228 struct ether_addr addr;
1232 dev = &rte_eth_devices[port_id];
1234 rte_eth_dev_info_get(port_id, &dev_info);
1236 if (RTE_ETH_DEV_SRIOV(dev).active)
1237 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
1239 /* replay MAC address configuration */
1240 for (i = 0; i < dev_info.max_mac_addrs; i++) {
1241 addr = dev->data->mac_addrs[i];
1243 /* skip zero address */
1244 if (is_zero_ether_addr(&addr))
1247 /* add address to the hardware */
1248 if (*dev->dev_ops->mac_addr_add &&
1249 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
1250 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
1252 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
1254 /* exit the loop but not return an error */
1259 /* replay promiscuous configuration */
1260 if (rte_eth_promiscuous_get(port_id) == 1)
1261 rte_eth_promiscuous_enable(port_id);
1262 else if (rte_eth_promiscuous_get(port_id) == 0)
1263 rte_eth_promiscuous_disable(port_id);
1265 /* replay all multicast configuration */
1266 if (rte_eth_allmulticast_get(port_id) == 1)
1267 rte_eth_allmulticast_enable(port_id);
1268 else if (rte_eth_allmulticast_get(port_id) == 0)
1269 rte_eth_allmulticast_disable(port_id);
1273 rte_eth_dev_start(uint8_t port_id)
1275 struct rte_eth_dev *dev;
1278 /* This function is only safe when called from the primary process
1279 * in a multi-process setup*/
1280 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1282 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1284 dev = &rte_eth_devices[port_id];
1286 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1288 if (dev->data->dev_started != 0) {
1289 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1290 " already started\n",
1295 diag = (*dev->dev_ops->dev_start)(dev);
1297 dev->data->dev_started = 1;
1301 rte_eth_dev_config_restore(port_id);
1303 if (dev->data->dev_conf.intr_conf.lsc != 0) {
1304 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1305 (*dev->dev_ops->link_update)(dev, 0);
1311 rte_eth_dev_stop(uint8_t port_id)
1313 struct rte_eth_dev *dev;
1315 /* This function is only safe when called from the primary process
1316 * in a multi-process setup*/
1317 PROC_PRIMARY_OR_RET();
1319 VALID_PORTID_OR_RET(port_id);
1320 dev = &rte_eth_devices[port_id];
1322 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1324 if (dev->data->dev_started == 0) {
1325 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1326 " already stopped\n",
1331 dev->data->dev_started = 0;
1332 (*dev->dev_ops->dev_stop)(dev);
1336 rte_eth_dev_set_link_up(uint8_t port_id)
1338 struct rte_eth_dev *dev;
1340 /* This function is only safe when called from the primary process
1341 * in a multi-process setup*/
1342 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1344 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1346 dev = &rte_eth_devices[port_id];
1348 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1349 return (*dev->dev_ops->dev_set_link_up)(dev);
1353 rte_eth_dev_set_link_down(uint8_t port_id)
1355 struct rte_eth_dev *dev;
1357 /* This function is only safe when called from the primary process
1358 * in a multi-process setup*/
1359 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1361 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1363 dev = &rte_eth_devices[port_id];
1365 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1366 return (*dev->dev_ops->dev_set_link_down)(dev);
1370 rte_eth_dev_close(uint8_t port_id)
1372 struct rte_eth_dev *dev;
1374 /* This function is only safe when called from the primary process
1375 * in a multi-process setup*/
1376 PROC_PRIMARY_OR_RET();
1378 VALID_PORTID_OR_RET(port_id);
1379 dev = &rte_eth_devices[port_id];
1381 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1382 dev->data->dev_started = 0;
1383 (*dev->dev_ops->dev_close)(dev);
1385 rte_free(dev->data->rx_queues);
1386 dev->data->rx_queues = NULL;
1387 rte_free(dev->data->tx_queues);
1388 dev->data->tx_queues = NULL;
1392 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1393 uint16_t nb_rx_desc, unsigned int socket_id,
1394 const struct rte_eth_rxconf *rx_conf,
1395 struct rte_mempool *mp)
1398 uint32_t mbp_buf_size;
1399 struct rte_eth_dev *dev;
1400 struct rte_eth_dev_info dev_info;
1402 /* This function is only safe when called from the primary process
1403 * in a multi-process setup*/
1404 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1406 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1408 dev = &rte_eth_devices[port_id];
1409 if (rx_queue_id >= dev->data->nb_rx_queues) {
1410 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1414 if (dev->data->dev_started) {
1416 "port %d must be stopped to allow configuration\n", port_id);
1420 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1421 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1424 * Check the size of the mbuf data buffer.
1425 * This value must be provided in the private data of the memory pool.
1426 * First check that the memory pool has a valid private data.
1428 rte_eth_dev_info_get(port_id, &dev_info);
1429 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1430 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1431 mp->name, (int) mp->private_data_size,
1432 (int) sizeof(struct rte_pktmbuf_pool_private));
1435 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1437 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1438 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1439 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1443 (int)(RTE_PKTMBUF_HEADROOM +
1444 dev_info.min_rx_bufsize),
1445 (int)RTE_PKTMBUF_HEADROOM,
1446 (int)dev_info.min_rx_bufsize);
1450 if (rx_conf == NULL)
1451 rx_conf = &dev_info.default_rxconf;
1453 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1454 socket_id, rx_conf, mp);
1456 if (!dev->data->min_rx_buf_size ||
1457 dev->data->min_rx_buf_size > mbp_buf_size)
1458 dev->data->min_rx_buf_size = mbp_buf_size;
1465 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1466 uint16_t nb_tx_desc, unsigned int socket_id,
1467 const struct rte_eth_txconf *tx_conf)
1469 struct rte_eth_dev *dev;
1470 struct rte_eth_dev_info dev_info;
1472 /* This function is only safe when called from the primary process
1473 * in a multi-process setup*/
1474 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1476 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1478 dev = &rte_eth_devices[port_id];
1479 if (tx_queue_id >= dev->data->nb_tx_queues) {
1480 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1484 if (dev->data->dev_started) {
1486 "port %d must be stopped to allow configuration\n", port_id);
1490 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1491 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1493 rte_eth_dev_info_get(port_id, &dev_info);
1495 if (tx_conf == NULL)
1496 tx_conf = &dev_info.default_txconf;
1498 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1499 socket_id, tx_conf);
1503 rte_eth_promiscuous_enable(uint8_t port_id)
1505 struct rte_eth_dev *dev;
1507 VALID_PORTID_OR_RET(port_id);
1508 dev = &rte_eth_devices[port_id];
1510 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1511 (*dev->dev_ops->promiscuous_enable)(dev);
1512 dev->data->promiscuous = 1;
1516 rte_eth_promiscuous_disable(uint8_t port_id)
1518 struct rte_eth_dev *dev;
1520 VALID_PORTID_OR_RET(port_id);
1521 dev = &rte_eth_devices[port_id];
1523 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1524 dev->data->promiscuous = 0;
1525 (*dev->dev_ops->promiscuous_disable)(dev);
1529 rte_eth_promiscuous_get(uint8_t port_id)
1531 struct rte_eth_dev *dev;
1533 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1535 dev = &rte_eth_devices[port_id];
1536 return dev->data->promiscuous;
1540 rte_eth_allmulticast_enable(uint8_t port_id)
1542 struct rte_eth_dev *dev;
1544 VALID_PORTID_OR_RET(port_id);
1545 dev = &rte_eth_devices[port_id];
1547 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1548 (*dev->dev_ops->allmulticast_enable)(dev);
1549 dev->data->all_multicast = 1;
1553 rte_eth_allmulticast_disable(uint8_t port_id)
1555 struct rte_eth_dev *dev;
1557 VALID_PORTID_OR_RET(port_id);
1558 dev = &rte_eth_devices[port_id];
1560 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1561 dev->data->all_multicast = 0;
1562 (*dev->dev_ops->allmulticast_disable)(dev);
1566 rte_eth_allmulticast_get(uint8_t port_id)
1568 struct rte_eth_dev *dev;
1570 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1572 dev = &rte_eth_devices[port_id];
1573 return dev->data->all_multicast;
1577 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1578 struct rte_eth_link *link)
1580 struct rte_eth_link *dst = link;
1581 struct rte_eth_link *src = &(dev->data->dev_link);
1583 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1584 *(uint64_t *)src) == 0)
1591 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1593 struct rte_eth_dev *dev;
1595 VALID_PORTID_OR_RET(port_id);
1596 dev = &rte_eth_devices[port_id];
1598 if (dev->data->dev_conf.intr_conf.lsc != 0)
1599 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1601 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1602 (*dev->dev_ops->link_update)(dev, 1);
1603 *eth_link = dev->data->dev_link;
1608 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1610 struct rte_eth_dev *dev;
1612 VALID_PORTID_OR_RET(port_id);
1613 dev = &rte_eth_devices[port_id];
1615 if (dev->data->dev_conf.intr_conf.lsc != 0)
1616 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1618 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1619 (*dev->dev_ops->link_update)(dev, 0);
1620 *eth_link = dev->data->dev_link;
1625 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1627 struct rte_eth_dev *dev;
1629 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1631 dev = &rte_eth_devices[port_id];
1632 memset(stats, 0, sizeof(*stats));
1634 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1635 (*dev->dev_ops->stats_get)(dev, stats);
1636 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1641 rte_eth_stats_reset(uint8_t port_id)
1643 struct rte_eth_dev *dev;
1645 VALID_PORTID_OR_RET(port_id);
1646 dev = &rte_eth_devices[port_id];
1648 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1649 (*dev->dev_ops->stats_reset)(dev);
1652 /* retrieve ethdev extended statistics */
1654 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1657 struct rte_eth_stats eth_stats;
1658 struct rte_eth_dev *dev;
1659 unsigned count = 0, i, q;
1661 uint64_t val, *stats_ptr;
1663 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1665 dev = &rte_eth_devices[port_id];
1667 /* Return generic statistics */
1668 count = RTE_NB_STATS;
1669 count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
1670 count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
1672 /* implemented by the driver */
1673 if (dev->dev_ops->xstats_get != NULL) {
1674 /* Retrieve the xstats from the driver at the end of the
1677 xcount = (*dev->dev_ops->xstats_get)(dev, &xstats[count],
1678 (n > count) ? n - count : 0);
1684 if (n < count + xcount)
1685 return count + xcount;
1687 /* now fill the xstats structure */
1689 rte_eth_stats_get(port_id, ð_stats);
1692 for (i = 0; i < RTE_NB_STATS; i++) {
1693 stats_ptr = RTE_PTR_ADD(ð_stats,
1694 rte_stats_strings[i].offset);
1696 snprintf(xstats[count].name, sizeof(xstats[count].name),
1697 "%s", rte_stats_strings[i].name);
1698 xstats[count++].value = val;
1702 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1703 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1704 stats_ptr = RTE_PTR_ADD(ð_stats,
1705 rte_rxq_stats_strings[i].offset +
1706 q * sizeof(uint64_t));
1708 snprintf(xstats[count].name, sizeof(xstats[count].name),
1709 "rx_queue_%u_%s", q,
1710 rte_rxq_stats_strings[i].name);
1711 xstats[count++].value = val;
1716 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1717 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1718 stats_ptr = RTE_PTR_ADD(ð_stats,
1719 rte_txq_stats_strings[i].offset +
1720 q * sizeof(uint64_t));
1722 snprintf(xstats[count].name, sizeof(xstats[count].name),
1723 "tx_queue_%u_%s", q,
1724 rte_txq_stats_strings[i].name);
1725 xstats[count++].value = val;
1729 return count + xcount;
1732 /* reset ethdev extended statistics */
1734 rte_eth_xstats_reset(uint8_t port_id)
1736 struct rte_eth_dev *dev;
1738 VALID_PORTID_OR_RET(port_id);
1739 dev = &rte_eth_devices[port_id];
1741 /* implemented by the driver */
1742 if (dev->dev_ops->xstats_reset != NULL) {
1743 (*dev->dev_ops->xstats_reset)(dev);
1747 /* fallback to default */
1748 rte_eth_stats_reset(port_id);
1752 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1755 struct rte_eth_dev *dev;
1757 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1759 dev = &rte_eth_devices[port_id];
1761 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1762 return (*dev->dev_ops->queue_stats_mapping_set)
1763 (dev, queue_id, stat_idx, is_rx);
1768 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1771 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1777 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1780 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1786 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1788 struct rte_eth_dev *dev;
1790 VALID_PORTID_OR_RET(port_id);
1791 dev = &rte_eth_devices[port_id];
1793 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1795 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1796 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1797 dev_info->pci_dev = dev->pci_dev;
1799 dev_info->driver_name = dev->driver->pci_drv.name;
1803 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1805 struct rte_eth_dev *dev;
1807 VALID_PORTID_OR_RET(port_id);
1808 dev = &rte_eth_devices[port_id];
1809 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1814 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1816 struct rte_eth_dev *dev;
1818 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1820 dev = &rte_eth_devices[port_id];
1821 *mtu = dev->data->mtu;
1826 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1829 struct rte_eth_dev *dev;
1831 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1832 dev = &rte_eth_devices[port_id];
1833 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1835 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1837 dev->data->mtu = mtu;
1843 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1845 struct rte_eth_dev *dev;
1847 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1848 dev = &rte_eth_devices[port_id];
1849 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1850 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1854 if (vlan_id > 4095) {
1855 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1856 port_id, (unsigned) vlan_id);
1859 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1861 return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1865 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1867 struct rte_eth_dev *dev;
1869 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1870 dev = &rte_eth_devices[port_id];
1871 if (rx_queue_id >= dev->data->nb_rx_queues) {
1872 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1876 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1877 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1883 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1885 struct rte_eth_dev *dev;
1887 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1888 dev = &rte_eth_devices[port_id];
1889 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1890 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1896 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1898 struct rte_eth_dev *dev;
1903 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1904 dev = &rte_eth_devices[port_id];
1906 /*check which option changed by application*/
1907 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1908 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1910 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1911 mask |= ETH_VLAN_STRIP_MASK;
1914 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1915 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1917 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1918 mask |= ETH_VLAN_FILTER_MASK;
1921 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1922 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1924 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1925 mask |= ETH_VLAN_EXTEND_MASK;
1932 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1933 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1939 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1941 struct rte_eth_dev *dev;
1944 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1945 dev = &rte_eth_devices[port_id];
1947 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1948 ret |= ETH_VLAN_STRIP_OFFLOAD;
1950 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1951 ret |= ETH_VLAN_FILTER_OFFLOAD;
1953 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1954 ret |= ETH_VLAN_EXTEND_OFFLOAD;
1960 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1962 struct rte_eth_dev *dev;
1964 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1965 dev = &rte_eth_devices[port_id];
1966 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1967 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1973 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1974 struct rte_fdir_filter *fdir_filter,
1977 struct rte_eth_dev *dev;
1979 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1980 dev = &rte_eth_devices[port_id];
1982 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1983 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1984 port_id, dev->data->dev_conf.fdir_conf.mode);
1988 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1989 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1990 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1991 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
1992 "None l4type, source & destinations ports "
1993 "should be null!\n");
1997 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1998 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
2003 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
2004 struct rte_fdir_filter *fdir_filter,
2007 struct rte_eth_dev *dev;
2009 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2010 dev = &rte_eth_devices[port_id];
2012 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
2013 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2014 port_id, dev->data->dev_conf.fdir_conf.mode);
2018 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2019 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2020 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2021 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
2022 "None l4type, source & destinations ports "
2023 "should be null!\n");
2027 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
2028 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
2034 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
2035 struct rte_fdir_filter *fdir_filter)
2037 struct rte_eth_dev *dev;
2039 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2040 dev = &rte_eth_devices[port_id];
2042 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
2043 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2044 port_id, dev->data->dev_conf.fdir_conf.mode);
2048 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2049 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2050 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2051 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
2052 "None l4type source & destinations ports "
2053 "should be null!\n");
2057 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
2058 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
2062 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
2064 struct rte_eth_dev *dev;
2066 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2067 dev = &rte_eth_devices[port_id];
2068 if (!(dev->data->dev_conf.fdir_conf.mode)) {
2069 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
2073 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
2075 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
2080 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
2081 struct rte_fdir_filter *fdir_filter,
2082 uint16_t soft_id, uint8_t queue,
2085 struct rte_eth_dev *dev;
2087 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2088 dev = &rte_eth_devices[port_id];
2090 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
2091 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2092 port_id, dev->data->dev_conf.fdir_conf.mode);
2096 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2097 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2098 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2099 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
2100 "None l4type, source & destinations ports "
2101 "should be null!\n");
2105 /* For now IPv6 is not supported with perfect filter */
2106 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2109 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
2110 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
2116 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
2117 struct rte_fdir_filter *fdir_filter,
2118 uint16_t soft_id, uint8_t queue,
2121 struct rte_eth_dev *dev;
2123 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2124 dev = &rte_eth_devices[port_id];
2126 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
2127 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2128 port_id, dev->data->dev_conf.fdir_conf.mode);
2132 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2133 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2134 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2135 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
2136 "None l4type, source & destinations ports "
2137 "should be null!\n");
2141 /* For now IPv6 is not supported with perfect filter */
2142 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2145 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
2146 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
2147 soft_id, queue, drop);
2151 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
2152 struct rte_fdir_filter *fdir_filter,
2155 struct rte_eth_dev *dev;
2157 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2158 dev = &rte_eth_devices[port_id];
2160 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
2161 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2162 port_id, dev->data->dev_conf.fdir_conf.mode);
2166 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2167 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2168 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2169 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
2170 "None l4type, source & destinations ports "
2171 "should be null!\n");
2175 /* For now IPv6 is not supported with perfect filter */
2176 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2179 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
2180 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
2185 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
2187 struct rte_eth_dev *dev;
2189 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2190 dev = &rte_eth_devices[port_id];
2191 if (!(dev->data->dev_conf.fdir_conf.mode)) {
2192 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
2196 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
2197 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
2201 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2203 struct rte_eth_dev *dev;
2205 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2206 dev = &rte_eth_devices[port_id];
2207 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2208 memset(fc_conf, 0, sizeof(*fc_conf));
2209 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
2213 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2215 struct rte_eth_dev *dev;
2217 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2218 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2219 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2223 dev = &rte_eth_devices[port_id];
2224 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2225 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
2229 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
2231 struct rte_eth_dev *dev;
2233 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2234 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2235 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2239 dev = &rte_eth_devices[port_id];
2240 /* High water, low water validation are device specific */
2241 if (*dev->dev_ops->priority_flow_ctrl_set)
2242 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
2247 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2255 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
2256 PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
2257 RTE_RETA_GROUP_SIZE);
2261 num = reta_size / RTE_RETA_GROUP_SIZE;
2262 for (i = 0; i < num; i++) {
2263 if (reta_conf[i].mask)
2271 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2275 uint16_t i, idx, shift;
2281 PMD_DEBUG_TRACE("No receive queue is available\n");
2285 for (i = 0; i < reta_size; i++) {
2286 idx = i / RTE_RETA_GROUP_SIZE;
2287 shift = i % RTE_RETA_GROUP_SIZE;
2288 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2289 (reta_conf[idx].reta[shift] >= max_rxq)) {
2290 PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2291 "the maximum rxq index: %u\n", idx, shift,
2292 reta_conf[idx].reta[shift], max_rxq);
2301 rte_eth_dev_rss_reta_update(uint8_t port_id,
2302 struct rte_eth_rss_reta_entry64 *reta_conf,
2305 struct rte_eth_dev *dev;
2308 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2309 /* Check mask bits */
2310 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2314 dev = &rte_eth_devices[port_id];
2316 /* Check entry value */
2317 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2318 dev->data->nb_rx_queues);
2322 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2323 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2327 rte_eth_dev_rss_reta_query(uint8_t port_id,
2328 struct rte_eth_rss_reta_entry64 *reta_conf,
2331 struct rte_eth_dev *dev;
2334 if (port_id >= nb_ports) {
2335 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2339 /* Check mask bits */
2340 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2344 dev = &rte_eth_devices[port_id];
2345 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2346 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2350 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2352 struct rte_eth_dev *dev;
2353 uint16_t rss_hash_protos;
2355 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2356 rss_hash_protos = rss_conf->rss_hf;
2357 if ((rss_hash_protos != 0) &&
2358 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2359 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2363 dev = &rte_eth_devices[port_id];
2364 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2365 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2369 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2370 struct rte_eth_rss_conf *rss_conf)
2372 struct rte_eth_dev *dev;
2374 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2375 dev = &rte_eth_devices[port_id];
2376 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2377 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2381 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
2382 struct rte_eth_udp_tunnel *udp_tunnel)
2384 struct rte_eth_dev *dev;
2386 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2387 if (udp_tunnel == NULL) {
2388 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2392 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2393 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2397 dev = &rte_eth_devices[port_id];
2398 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
2399 return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
2403 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
2404 struct rte_eth_udp_tunnel *udp_tunnel)
2406 struct rte_eth_dev *dev;
2408 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2409 dev = &rte_eth_devices[port_id];
2411 if (udp_tunnel == NULL) {
2412 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2416 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2417 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2421 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2422 return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2426 rte_eth_led_on(uint8_t port_id)
2428 struct rte_eth_dev *dev;
2430 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2431 dev = &rte_eth_devices[port_id];
2432 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2433 return (*dev->dev_ops->dev_led_on)(dev);
2437 rte_eth_led_off(uint8_t port_id)
2439 struct rte_eth_dev *dev;
2441 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2442 dev = &rte_eth_devices[port_id];
2443 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2444 return (*dev->dev_ops->dev_led_off)(dev);
2448 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2452 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2454 struct rte_eth_dev_info dev_info;
2455 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2458 rte_eth_dev_info_get(port_id, &dev_info);
2460 for (i = 0; i < dev_info.max_mac_addrs; i++)
2461 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2467 static const struct ether_addr null_mac_addr;
2470 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2473 struct rte_eth_dev *dev;
2477 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2478 dev = &rte_eth_devices[port_id];
2479 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2481 if (is_zero_ether_addr(addr)) {
2482 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2486 if (pool >= ETH_64_POOLS) {
2487 PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2491 index = get_mac_addr_index(port_id, addr);
2493 index = get_mac_addr_index(port_id, &null_mac_addr);
2495 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2500 pool_mask = dev->data->mac_pool_sel[index];
2502 /* Check if both MAC address and pool is already there, and do nothing */
2503 if (pool_mask & (1ULL << pool))
2508 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2510 /* Update address in NIC data structure */
2511 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2513 /* Update pool bitmap in NIC data structure */
2514 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2520 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2522 struct rte_eth_dev *dev;
2525 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2526 dev = &rte_eth_devices[port_id];
2527 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2529 index = get_mac_addr_index(port_id, addr);
2531 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2533 } else if (index < 0)
2534 return 0; /* Do nothing if address wasn't found */
2537 (*dev->dev_ops->mac_addr_remove)(dev, index);
2539 /* Update address in NIC data structure */
2540 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2542 /* reset pool bitmap */
2543 dev->data->mac_pool_sel[index] = 0;
2549 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2551 struct rte_eth_dev *dev;
2553 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2555 if (!is_valid_assigned_ether_addr(addr))
2558 dev = &rte_eth_devices[port_id];
2559 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2561 /* Update default address in NIC data structure */
2562 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2564 (*dev->dev_ops->mac_addr_set)(dev, addr);
2570 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2571 uint16_t rx_mode, uint8_t on)
2574 struct rte_eth_dev *dev;
2575 struct rte_eth_dev_info dev_info;
2577 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2579 dev = &rte_eth_devices[port_id];
2580 rte_eth_dev_info_get(port_id, &dev_info);
2582 num_vfs = dev_info.max_vfs;
2584 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2589 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2592 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2593 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2597 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2601 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2603 struct rte_eth_dev_info dev_info;
2604 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2607 rte_eth_dev_info_get(port_id, &dev_info);
2608 if (!dev->data->hash_mac_addrs)
2611 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2612 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2613 ETHER_ADDR_LEN) == 0)
2620 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2625 struct rte_eth_dev *dev;
2627 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2629 dev = &rte_eth_devices[port_id];
2630 if (is_zero_ether_addr(addr)) {
2631 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2636 index = get_hash_mac_addr_index(port_id, addr);
2637 /* Check if it's already there, and do nothing */
2638 if ((index >= 0) && (on))
2643 PMD_DEBUG_TRACE("port %d: the MAC address was not "
2644 "set in UTA\n", port_id);
2648 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2650 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2656 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2657 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2659 /* Update address in NIC data structure */
2661 ether_addr_copy(addr,
2662 &dev->data->hash_mac_addrs[index]);
2664 ether_addr_copy(&null_mac_addr,
2665 &dev->data->hash_mac_addrs[index]);
2672 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2674 struct rte_eth_dev *dev;
2676 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2678 dev = &rte_eth_devices[port_id];
2680 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2681 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2685 rte_eth_dev_set_vf_rx(uint8_t port_id, uint16_t vf, uint8_t on)
2688 struct rte_eth_dev *dev;
2689 struct rte_eth_dev_info dev_info;
2691 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2693 dev = &rte_eth_devices[port_id];
2694 rte_eth_dev_info_get(port_id, &dev_info);
2696 num_vfs = dev_info.max_vfs;
2698 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2702 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2703 return (*dev->dev_ops->set_vf_rx)(dev, vf, on);
2707 rte_eth_dev_set_vf_tx(uint8_t port_id, uint16_t vf, uint8_t on)
2710 struct rte_eth_dev *dev;
2711 struct rte_eth_dev_info dev_info;
2713 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2715 dev = &rte_eth_devices[port_id];
2716 rte_eth_dev_info_get(port_id, &dev_info);
2718 num_vfs = dev_info.max_vfs;
2720 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2724 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2725 return (*dev->dev_ops->set_vf_tx)(dev, vf, on);
2729 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2730 uint64_t vf_mask, uint8_t vlan_on)
2732 struct rte_eth_dev *dev;
2734 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2736 dev = &rte_eth_devices[port_id];
2738 if (vlan_id > ETHER_MAX_VLAN_ID) {
2739 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2745 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2749 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2750 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2754 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2757 struct rte_eth_dev *dev;
2758 struct rte_eth_dev_info dev_info;
2759 struct rte_eth_link link;
2761 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2763 dev = &rte_eth_devices[port_id];
2764 rte_eth_dev_info_get(port_id, &dev_info);
2765 link = dev->data->dev_link;
2767 if (queue_idx > dev_info.max_tx_queues) {
2768 PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2769 "invalid queue id=%d\n", port_id, queue_idx);
2773 if (tx_rate > link.link_speed) {
2774 PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2775 "bigger than link speed= %d\n",
2776 tx_rate, link.link_speed);
2780 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2781 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2784 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2787 struct rte_eth_dev *dev;
2788 struct rte_eth_dev_info dev_info;
2789 struct rte_eth_link link;
2794 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2796 dev = &rte_eth_devices[port_id];
2797 rte_eth_dev_info_get(port_id, &dev_info);
2798 link = dev->data->dev_link;
2800 if (vf > dev_info.max_vfs) {
2801 PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2802 "invalid vf id=%d\n", port_id, vf);
2806 if (tx_rate > link.link_speed) {
2807 PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2808 "bigger than link speed= %d\n",
2809 tx_rate, link.link_speed);
2813 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2814 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2818 rte_eth_mirror_rule_set(uint8_t port_id,
2819 struct rte_eth_mirror_conf *mirror_conf,
2820 uint8_t rule_id, uint8_t on)
2822 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2824 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2825 if (mirror_conf->rule_type == 0) {
2826 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2830 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2831 PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2836 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2837 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2838 (mirror_conf->pool_mask == 0)) {
2839 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2843 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2844 mirror_conf->vlan.vlan_mask == 0) {
2845 PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2849 dev = &rte_eth_devices[port_id];
2850 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2852 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2856 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2858 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2860 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2862 dev = &rte_eth_devices[port_id];
2863 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2865 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2868 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2870 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2871 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2873 struct rte_eth_dev *dev;
2875 VALID_PORTID_OR_ERR_RET(port_id, 0);
2877 dev = &rte_eth_devices[port_id];
2878 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);
2879 if (queue_id >= dev->data->nb_rx_queues) {
2880 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2883 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2888 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2889 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2891 struct rte_eth_dev *dev;
2893 VALID_PORTID_OR_ERR_RET(port_id, 0);
2895 dev = &rte_eth_devices[port_id];
2897 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0);
2898 if (queue_id >= dev->data->nb_tx_queues) {
2899 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2902 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2907 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2909 struct rte_eth_dev *dev;
2911 VALID_PORTID_OR_ERR_RET(port_id, 0);
2913 dev = &rte_eth_devices[port_id];
2914 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0);
2915 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2919 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2921 struct rte_eth_dev *dev;
2923 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2925 dev = &rte_eth_devices[port_id];
2926 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2927 return (*dev->dev_ops->rx_descriptor_done)(dev->data->rx_queues[queue_id],
2933 rte_eth_dev_callback_register(uint8_t port_id,
2934 enum rte_eth_event_type event,
2935 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2937 struct rte_eth_dev *dev;
2938 struct rte_eth_dev_callback *user_cb;
2943 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2945 dev = &rte_eth_devices[port_id];
2946 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2948 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2949 if (user_cb->cb_fn == cb_fn &&
2950 user_cb->cb_arg == cb_arg &&
2951 user_cb->event == event) {
2956 /* create a new callback. */
2957 if (user_cb == NULL)
2958 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2959 sizeof(struct rte_eth_dev_callback), 0);
2960 if (user_cb != NULL) {
2961 user_cb->cb_fn = cb_fn;
2962 user_cb->cb_arg = cb_arg;
2963 user_cb->event = event;
2964 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2967 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2968 return (user_cb == NULL) ? -ENOMEM : 0;
2972 rte_eth_dev_callback_unregister(uint8_t port_id,
2973 enum rte_eth_event_type event,
2974 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2977 struct rte_eth_dev *dev;
2978 struct rte_eth_dev_callback *cb, *next;
2983 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2985 dev = &rte_eth_devices[port_id];
2986 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2989 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2991 next = TAILQ_NEXT(cb, next);
2993 if (cb->cb_fn != cb_fn || cb->event != event ||
2994 (cb->cb_arg != (void *)-1 &&
2995 cb->cb_arg != cb_arg))
2999 * if this callback is not executing right now,
3002 if (cb->active == 0) {
3003 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
3010 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3015 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
3016 enum rte_eth_event_type event)
3018 struct rte_eth_dev_callback *cb_lst;
3019 struct rte_eth_dev_callback dev_cb;
3021 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3022 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
3023 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
3027 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3028 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
3030 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3033 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3038 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
3041 struct rte_eth_dev *dev;
3042 struct rte_intr_handle *intr_handle;
3046 if (!rte_eth_dev_is_valid_port(port_id)) {
3047 PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
3051 dev = &rte_eth_devices[port_id];
3052 intr_handle = &dev->pci_dev->intr_handle;
3053 if (!intr_handle->intr_vec) {
3054 PMD_DEBUG_TRACE("RX Intr vector unset\n");
3058 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
3059 vec = intr_handle->intr_vec[qid];
3060 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
3061 if (rc && rc != -EEXIST) {
3062 PMD_DEBUG_TRACE("p %u q %u rx ctl error"
3063 " op %d epfd %d vec %u\n",
3064 port_id, qid, op, epfd, vec);
3072 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
3073 int epfd, int op, void *data)
3076 struct rte_eth_dev *dev;
3077 struct rte_intr_handle *intr_handle;
3080 if (!rte_eth_dev_is_valid_port(port_id)) {
3081 PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
3085 dev = &rte_eth_devices[port_id];
3086 if (queue_id >= dev->data->nb_rx_queues) {
3087 PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
3091 intr_handle = &dev->pci_dev->intr_handle;
3092 if (!intr_handle->intr_vec) {
3093 PMD_DEBUG_TRACE("RX Intr vector unset\n");
3097 vec = intr_handle->intr_vec[queue_id];
3098 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
3099 if (rc && rc != -EEXIST) {
3100 PMD_DEBUG_TRACE("p %u q %u rx ctl error"
3101 " op %d epfd %d vec %u\n",
3102 port_id, queue_id, op, epfd, vec);
3110 rte_eth_dev_rx_intr_enable(uint8_t port_id,
3113 struct rte_eth_dev *dev;
3115 if (!rte_eth_dev_is_valid_port(port_id)) {
3116 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3120 dev = &rte_eth_devices[port_id];
3122 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
3123 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
3127 rte_eth_dev_rx_intr_disable(uint8_t port_id,
3130 struct rte_eth_dev *dev;
3132 if (!rte_eth_dev_is_valid_port(port_id)) {
3133 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3137 dev = &rte_eth_devices[port_id];
3139 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
3140 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
3144 rte_eth_dev_rx_intr_enable(uint8_t port_id, uint16_t queue_id)
3146 RTE_SET_USED(port_id);
3147 RTE_SET_USED(queue_id);
3152 rte_eth_dev_rx_intr_disable(uint8_t port_id, uint16_t queue_id)
3154 RTE_SET_USED(port_id);
3155 RTE_SET_USED(queue_id);
3160 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
3162 RTE_SET_USED(port_id);
3170 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
3171 int epfd, int op, void *data)
3173 RTE_SET_USED(port_id);
3174 RTE_SET_USED(queue_id);
3182 #ifdef RTE_NIC_BYPASS
3183 int rte_eth_dev_bypass_init(uint8_t port_id)
3185 struct rte_eth_dev *dev;
3187 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3189 dev = &rte_eth_devices[port_id];
3190 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
3191 (*dev->dev_ops->bypass_init)(dev);
3196 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
3198 struct rte_eth_dev *dev;
3200 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3202 dev = &rte_eth_devices[port_id];
3203 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
3204 (*dev->dev_ops->bypass_state_show)(dev, state);
3209 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
3211 struct rte_eth_dev *dev;
3213 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3215 dev = &rte_eth_devices[port_id];
3216 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
3217 (*dev->dev_ops->bypass_state_set)(dev, new_state);
3222 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
3224 struct rte_eth_dev *dev;
3226 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3228 dev = &rte_eth_devices[port_id];
3229 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
3230 (*dev->dev_ops->bypass_event_show)(dev, event, state);
3235 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
3237 struct rte_eth_dev *dev;
3239 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3241 dev = &rte_eth_devices[port_id];
3243 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
3244 (*dev->dev_ops->bypass_event_set)(dev, event, state);
3249 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
3251 struct rte_eth_dev *dev;
3253 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3255 dev = &rte_eth_devices[port_id];
3257 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
3258 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
3263 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
3265 struct rte_eth_dev *dev;
3267 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3269 dev = &rte_eth_devices[port_id];
3271 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
3272 (*dev->dev_ops->bypass_ver_show)(dev, ver);
3277 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
3279 struct rte_eth_dev *dev;
3281 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3283 dev = &rte_eth_devices[port_id];
3285 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
3286 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
3291 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
3293 struct rte_eth_dev *dev;
3295 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3297 dev = &rte_eth_devices[port_id];
3299 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
3300 (*dev->dev_ops->bypass_wd_reset)(dev);
3306 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
3308 struct rte_eth_dev *dev;
3310 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3312 dev = &rte_eth_devices[port_id];
3313 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3314 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3315 RTE_ETH_FILTER_NOP, NULL);
3319 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
3320 enum rte_filter_op filter_op, void *arg)
3322 struct rte_eth_dev *dev;
3324 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3326 dev = &rte_eth_devices[port_id];
3327 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3328 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
3332 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
3333 rte_rx_callback_fn fn, void *user_param)
3335 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3336 rte_errno = ENOTSUP;
3339 /* check input parameters */
3340 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3341 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3346 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3354 cb->param = user_param;
3356 /* Add the callbacks in fifo order. */
3357 struct rte_eth_rxtx_callback *tail =
3358 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3361 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3373 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
3374 rte_tx_callback_fn fn, void *user_param)
3376 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3377 rte_errno = ENOTSUP;
3380 /* check input parameters */
3381 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3382 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3387 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3395 cb->param = user_param;
3397 /* Add the callbacks in fifo order. */
3398 struct rte_eth_rxtx_callback *tail =
3399 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3402 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3414 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3415 struct rte_eth_rxtx_callback *user_cb)
3417 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3420 /* Check input parameters. */
3421 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
3422 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3426 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3427 struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
3428 struct rte_eth_rxtx_callback *prev_cb;
3430 /* Reset head pointer and remove user cb if first in the list. */
3431 if (cb == user_cb) {
3432 dev->post_rx_burst_cbs[queue_id] = user_cb->next;
3436 /* Remove the user cb from the callback list. */
3441 if (cb == user_cb) {
3442 prev_cb->next = user_cb->next;
3446 } while (cb != NULL);
3448 /* Callback wasn't found. */
3453 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3454 struct rte_eth_rxtx_callback *user_cb)
3456 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3459 /* Check input parameters. */
3460 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
3461 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3465 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3466 struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
3467 struct rte_eth_rxtx_callback *prev_cb;
3469 /* Reset head pointer and remove user cb if first in the list. */
3470 if (cb == user_cb) {
3471 dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
3475 /* Remove the user cb from the callback list. */
3480 if (cb == user_cb) {
3481 prev_cb->next = user_cb->next;
3485 } while (cb != NULL);
3487 /* Callback wasn't found. */
3492 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3493 struct ether_addr *mc_addr_set,
3494 uint32_t nb_mc_addr)
3496 struct rte_eth_dev *dev;
3498 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3500 dev = &rte_eth_devices[port_id];
3501 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3502 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3506 rte_eth_timesync_enable(uint8_t port_id)
3508 struct rte_eth_dev *dev;
3510 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3511 dev = &rte_eth_devices[port_id];
3513 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3514 return (*dev->dev_ops->timesync_enable)(dev);
3518 rte_eth_timesync_disable(uint8_t port_id)
3520 struct rte_eth_dev *dev;
3522 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3523 dev = &rte_eth_devices[port_id];
3525 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3526 return (*dev->dev_ops->timesync_disable)(dev);
3530 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3533 struct rte_eth_dev *dev;
3535 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3536 dev = &rte_eth_devices[port_id];
3538 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3539 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3543 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3545 struct rte_eth_dev *dev;
3547 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3548 dev = &rte_eth_devices[port_id];
3550 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3551 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3555 rte_eth_dev_get_reg_length(uint8_t port_id)
3557 struct rte_eth_dev *dev;
3559 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3561 dev = &rte_eth_devices[port_id];
3562 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg_length, -ENOTSUP);
3563 return (*dev->dev_ops->get_reg_length)(dev);
3567 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3569 struct rte_eth_dev *dev;
3571 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3573 dev = &rte_eth_devices[port_id];
3574 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3575 return (*dev->dev_ops->get_reg)(dev, info);
3579 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3581 struct rte_eth_dev *dev;
3583 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3585 dev = &rte_eth_devices[port_id];
3586 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3587 return (*dev->dev_ops->get_eeprom_length)(dev);
3591 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3593 struct rte_eth_dev *dev;
3595 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3597 dev = &rte_eth_devices[port_id];
3598 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3599 return (*dev->dev_ops->get_eeprom)(dev, info);
3603 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3605 struct rte_eth_dev *dev;
3607 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3609 dev = &rte_eth_devices[port_id];
3610 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3611 return (*dev->dev_ops->set_eeprom)(dev, info);