4 * Copyright(c) 2010-2014 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_missed_errors", offsetof(struct rte_eth_stats, imissed)},
146 {"rx_crc_errors", offsetof(struct rte_eth_stats, ibadcrc)},
147 {"rx_bad_length_errors", offsetof(struct rte_eth_stats, ibadlen)},
148 {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
149 {"alloc_rx_buff_failed", offsetof(struct rte_eth_stats, rx_nombuf)},
150 {"fdir_match", offsetof(struct rte_eth_stats, fdirmatch)},
151 {"fdir_miss", offsetof(struct rte_eth_stats, fdirmiss)},
152 {"tx_flow_control_xon", offsetof(struct rte_eth_stats, tx_pause_xon)},
153 {"rx_flow_control_xon", offsetof(struct rte_eth_stats, rx_pause_xon)},
154 {"tx_flow_control_xoff", offsetof(struct rte_eth_stats, tx_pause_xoff)},
155 {"rx_flow_control_xoff", offsetof(struct rte_eth_stats, rx_pause_xoff)},
157 #define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
159 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
160 {"rx_packets", offsetof(struct rte_eth_stats, q_ipackets)},
161 {"rx_bytes", offsetof(struct rte_eth_stats, q_ibytes)},
163 #define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) / \
164 sizeof(rte_rxq_stats_strings[0]))
166 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
167 {"tx_packets", offsetof(struct rte_eth_stats, q_opackets)},
168 {"tx_bytes", offsetof(struct rte_eth_stats, q_obytes)},
169 {"tx_errors", offsetof(struct rte_eth_stats, q_errors)},
171 #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) / \
172 sizeof(rte_txq_stats_strings[0]))
176 * The user application callback description.
178 * It contains callback address to be registered by user application,
179 * the pointer to the parameters for callback, and the event type.
181 struct rte_eth_dev_callback {
182 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
183 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
184 void *cb_arg; /**< Parameter for callback */
185 enum rte_eth_event_type event; /**< Interrupt event type */
186 uint32_t active; /**< Callback is executing */
200 rte_eth_dev_data_alloc(void)
202 const unsigned flags = 0;
203 const struct rte_memzone *mz;
205 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
206 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
207 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
208 rte_socket_id(), flags);
210 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
212 rte_panic("Cannot allocate memzone for ethernet port data\n");
214 rte_eth_dev_data = mz->addr;
215 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
216 memset(rte_eth_dev_data, 0,
217 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
221 rte_eth_dev_allocated(const char *name)
225 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
226 if ((rte_eth_devices[i].attached == DEV_ATTACHED) &&
227 strcmp(rte_eth_devices[i].data->name, name) == 0)
228 return &rte_eth_devices[i];
234 rte_eth_dev_find_free_port(void)
238 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
239 if (rte_eth_devices[i].attached == DEV_DETACHED)
242 return RTE_MAX_ETHPORTS;
246 rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
249 struct rte_eth_dev *eth_dev;
251 port_id = rte_eth_dev_find_free_port();
252 if (port_id == RTE_MAX_ETHPORTS) {
253 PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
257 if (rte_eth_dev_data == NULL)
258 rte_eth_dev_data_alloc();
260 if (rte_eth_dev_allocated(name) != NULL) {
261 PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n",
266 eth_dev = &rte_eth_devices[port_id];
267 eth_dev->data = &rte_eth_dev_data[port_id];
268 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
269 eth_dev->data->port_id = port_id;
270 eth_dev->attached = DEV_ATTACHED;
271 eth_dev->dev_type = type;
277 rte_eth_dev_create_unique_device_name(char *name, size_t size,
278 struct rte_pci_device *pci_dev)
282 if ((name == NULL) || (pci_dev == NULL))
285 ret = snprintf(name, size, "%d:%d.%d",
286 pci_dev->addr.bus, pci_dev->addr.devid,
287 pci_dev->addr.function);
294 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
299 eth_dev->attached = 0;
305 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
306 struct rte_pci_device *pci_dev)
308 struct eth_driver *eth_drv;
309 struct rte_eth_dev *eth_dev;
310 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
314 eth_drv = (struct eth_driver *)pci_drv;
316 /* Create unique Ethernet device name using PCI address */
317 rte_eth_dev_create_unique_device_name(ethdev_name,
318 sizeof(ethdev_name), pci_dev);
320 eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
324 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
325 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
326 eth_drv->dev_private_size,
327 RTE_CACHE_LINE_SIZE);
328 if (eth_dev->data->dev_private == NULL)
329 rte_panic("Cannot allocate memzone for private port data\n");
331 eth_dev->pci_dev = pci_dev;
332 eth_dev->driver = eth_drv;
333 eth_dev->data->rx_mbuf_alloc_failed = 0;
335 /* init user callbacks */
336 TAILQ_INIT(&(eth_dev->link_intr_cbs));
339 * Set the default MTU.
341 eth_dev->data->mtu = ETHER_MTU;
343 /* Invoke PMD device initialization function */
344 diag = (*eth_drv->eth_dev_init)(eth_dev);
348 PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x) failed\n",
350 (unsigned) pci_dev->id.vendor_id,
351 (unsigned) pci_dev->id.device_id);
352 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
353 rte_free(eth_dev->data->dev_private);
354 eth_dev->attached = DEV_DETACHED;
360 rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
362 const struct eth_driver *eth_drv;
363 struct rte_eth_dev *eth_dev;
364 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
370 /* Create unique Ethernet device name using PCI address */
371 rte_eth_dev_create_unique_device_name(ethdev_name,
372 sizeof(ethdev_name), pci_dev);
374 eth_dev = rte_eth_dev_allocated(ethdev_name);
378 eth_drv = (const struct eth_driver *)pci_dev->driver;
380 /* Invoke PMD device uninit function */
381 if (*eth_drv->eth_dev_uninit) {
382 ret = (*eth_drv->eth_dev_uninit)(eth_dev);
387 /* free ether device */
388 rte_eth_dev_release_port(eth_dev);
390 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
391 rte_free(eth_dev->data->dev_private);
393 eth_dev->pci_dev = NULL;
394 eth_dev->driver = NULL;
395 eth_dev->data = NULL;
401 * Register an Ethernet [Poll Mode] driver.
403 * Function invoked by the initialization function of an Ethernet driver
404 * to simultaneously register itself as a PCI driver and as an Ethernet
406 * Invokes the rte_eal_pci_register() function to register the *pci_drv*
407 * structure embedded in the *eth_drv* structure, after having stored the
408 * address of the rte_eth_dev_init() function in the *devinit* field of
409 * the *pci_drv* structure.
410 * During the PCI probing phase, the rte_eth_dev_init() function is
411 * invoked for each PCI [Ethernet device] matching the embedded PCI
412 * identifiers provided by the driver.
415 rte_eth_driver_register(struct eth_driver *eth_drv)
417 eth_drv->pci_drv.devinit = rte_eth_dev_init;
418 eth_drv->pci_drv.devuninit = rte_eth_dev_uninit;
419 rte_eal_pci_register(ð_drv->pci_drv);
423 rte_eth_dev_is_valid_port(uint8_t port_id)
425 if (port_id >= RTE_MAX_ETHPORTS ||
426 rte_eth_devices[port_id].attached != DEV_ATTACHED)
433 rte_eth_dev_socket_id(uint8_t port_id)
435 if (!rte_eth_dev_is_valid_port(port_id))
437 return rte_eth_devices[port_id].pci_dev->numa_node;
441 rte_eth_dev_count(void)
446 /* So far, DPDK hotplug function only supports linux */
447 #ifdef RTE_LIBRTE_EAL_HOTPLUG
449 static enum rte_eth_dev_type
450 rte_eth_dev_get_device_type(uint8_t port_id)
452 if (!rte_eth_dev_is_valid_port(port_id))
453 return RTE_ETH_DEV_UNKNOWN;
454 return rte_eth_devices[port_id].dev_type;
458 rte_eth_dev_save(struct rte_eth_dev *devs, size_t size)
460 if ((devs == NULL) ||
461 (size != sizeof(struct rte_eth_dev) * RTE_MAX_ETHPORTS))
464 /* save current rte_eth_devices */
465 memcpy(devs, rte_eth_devices, size);
470 rte_eth_dev_get_changed_port(struct rte_eth_dev *devs, uint8_t *port_id)
472 if ((devs == NULL) || (port_id == NULL))
475 /* check which port was attached or detached */
476 for (*port_id = 0; *port_id < RTE_MAX_ETHPORTS; (*port_id)++, devs++) {
477 if (rte_eth_devices[*port_id].attached ^ devs->attached)
484 rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr)
486 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
489 PMD_DEBUG_TRACE("Null pointer is specified\n");
493 *addr = rte_eth_devices[port_id].pci_dev->addr;
498 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
502 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
505 PMD_DEBUG_TRACE("Null pointer is specified\n");
509 /* shouldn't check 'rte_eth_devices[i].data',
510 * because it might be overwritten by VDEV PMD */
511 tmp = rte_eth_dev_data[port_id].name;
517 rte_eth_dev_is_detachable(uint8_t port_id)
521 if (port_id >= RTE_MAX_ETHPORTS) {
522 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
526 if (rte_eth_devices[port_id].dev_type == RTE_ETH_DEV_PCI) {
527 switch (rte_eth_devices[port_id].pci_dev->kdrv) {
528 case RTE_KDRV_IGB_UIO:
529 case RTE_KDRV_UIO_GENERIC:
537 drv_flags = rte_eth_devices[port_id].driver->pci_drv.drv_flags;
538 return !(drv_flags & RTE_PCI_DRV_DETACHABLE);
541 /* attach the new physical device, then store port_id of the device */
543 rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
546 struct rte_eth_dev devs[RTE_MAX_ETHPORTS];
548 if ((addr == NULL) || (port_id == NULL))
551 /* save current port status */
552 if (rte_eth_dev_save(devs, sizeof(devs)))
554 /* re-construct pci_device_list */
555 if (rte_eal_pci_scan())
557 /* invoke probe func of the driver can handle the new device.
559 * rte_eal_pci_probe_one() should return port_id.
560 * And rte_eth_dev_save() and rte_eth_dev_get_changed_port()
561 * should be removed. */
562 if (rte_eal_pci_probe_one(addr))
564 /* get port_id enabled by above procedures */
565 if (rte_eth_dev_get_changed_port(devs, &new_port_id))
568 *port_id = new_port_id;
571 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
575 /* detach the new physical device, then store pci_addr of the device */
577 rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
579 struct rte_pci_addr freed_addr;
580 struct rte_pci_addr vp;
585 /* check whether the driver supports detach feature, or not */
586 if (rte_eth_dev_is_detachable(port_id))
589 /* get pci address by port id */
590 if (rte_eth_dev_get_addr_by_port(port_id, &freed_addr))
593 /* Zeroed pci addr means the port comes from virtual device */
594 vp.domain = vp.bus = vp.devid = vp.function = 0;
595 if (rte_eal_compare_pci_addr(&vp, &freed_addr) == 0)
598 /* invoke close func of the driver,
599 * also remove the device from pci_device_list */
600 if (rte_eal_pci_close_one(&freed_addr))
606 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
610 /* attach the new virtual device, then store port_id of the device */
612 rte_eth_dev_attach_vdev(const char *vdevargs, uint8_t *port_id)
614 char *name = NULL, *args = NULL;
616 struct rte_eth_dev devs[RTE_MAX_ETHPORTS];
619 if ((vdevargs == NULL) || (port_id == NULL))
622 /* parse vdevargs, then retrieve device name and args */
623 if (rte_eal_parse_devargs_str(vdevargs, &name, &args))
626 /* save current port status */
627 if (rte_eth_dev_save(devs, sizeof(devs)))
629 /* walk around dev_driver_list to find the driver of the device,
630 * then invoke probe function o the driver.
632 * rte_eal_vdev_init() should return port_id,
633 * And rte_eth_dev_save() and rte_eth_dev_get_changed_port()
634 * should be removed. */
635 if (rte_eal_vdev_init(name, args))
637 /* get port_id enabled by above procedures */
638 if (rte_eth_dev_get_changed_port(devs, &new_port_id))
641 *port_id = new_port_id;
649 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
653 /* detach the new virtual device, then store the name of the device */
655 rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
657 char name[RTE_ETH_NAME_MAX_LEN];
659 if (vdevname == NULL)
662 /* check whether the driver supports detach feature, or not */
663 if (rte_eth_dev_is_detachable(port_id))
666 /* get device name by port id */
667 if (rte_eth_dev_get_name_by_port(port_id, name))
669 /* walk around dev_driver_list to find the driver of the device,
670 * then invoke close function o the driver */
671 if (rte_eal_vdev_uninit(name))
674 strncpy(vdevname, name, sizeof(name));
677 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
681 /* attach the new device, then store port_id of the device */
683 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
685 struct rte_pci_addr addr;
687 if ((devargs == NULL) || (port_id == NULL))
690 if (eal_parse_pci_DomBDF(devargs, &addr) == 0)
691 return rte_eth_dev_attach_pdev(&addr, port_id);
693 return rte_eth_dev_attach_vdev(devargs, port_id);
696 /* detach the device, then store the name of the device */
698 rte_eth_dev_detach(uint8_t port_id, char *name)
700 struct rte_pci_addr addr;
706 if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {
707 ret = rte_eth_dev_get_addr_by_port(port_id, &addr);
711 ret = rte_eth_dev_detach_pdev(port_id, &addr);
713 snprintf(name, RTE_ETH_NAME_MAX_LEN,
715 addr.domain, addr.bus,
716 addr.devid, addr.function);
720 return rte_eth_dev_detach_vdev(port_id, name);
722 #else /* RTE_LIBRTE_EAL_HOTPLUG */
724 rte_eth_dev_attach(const char *devargs __rte_unused,
725 uint8_t *port_id __rte_unused)
727 RTE_LOG(ERR, EAL, "Hotplug support isn't enabled\n");
731 /* detach the device, then store the name of the device */
733 rte_eth_dev_detach(uint8_t port_id __rte_unused,
734 char *name __rte_unused)
736 RTE_LOG(ERR, EAL, "Hotplug support isn't enabled\n");
739 #endif /* RTE_LIBRTE_EAL_HOTPLUG */
742 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
744 uint16_t old_nb_queues = dev->data->nb_rx_queues;
748 if (dev->data->rx_queues == NULL) { /* first time configuration */
749 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
750 sizeof(dev->data->rx_queues[0]) * nb_queues,
751 RTE_CACHE_LINE_SIZE);
752 if (dev->data->rx_queues == NULL) {
753 dev->data->nb_rx_queues = 0;
756 } else { /* re-configure */
757 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
759 rxq = dev->data->rx_queues;
761 for (i = nb_queues; i < old_nb_queues; i++)
762 (*dev->dev_ops->rx_queue_release)(rxq[i]);
763 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
764 RTE_CACHE_LINE_SIZE);
767 if (nb_queues > old_nb_queues) {
768 uint16_t new_qs = nb_queues - old_nb_queues;
770 memset(rxq + old_nb_queues, 0,
771 sizeof(rxq[0]) * new_qs);
774 dev->data->rx_queues = rxq;
777 dev->data->nb_rx_queues = nb_queues;
782 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
784 struct rte_eth_dev *dev;
786 /* This function is only safe when called from the primary process
787 * in a multi-process setup*/
788 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
790 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
792 dev = &rte_eth_devices[port_id];
793 if (rx_queue_id >= dev->data->nb_rx_queues) {
794 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
798 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
800 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
805 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
807 struct rte_eth_dev *dev;
809 /* This function is only safe when called from the primary process
810 * in a multi-process setup*/
811 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
813 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
815 dev = &rte_eth_devices[port_id];
816 if (rx_queue_id >= dev->data->nb_rx_queues) {
817 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
821 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
823 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
828 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
830 struct rte_eth_dev *dev;
832 /* This function is only safe when called from the primary process
833 * in a multi-process setup*/
834 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
836 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
838 dev = &rte_eth_devices[port_id];
839 if (tx_queue_id >= dev->data->nb_tx_queues) {
840 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
844 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
846 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
851 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
853 struct rte_eth_dev *dev;
855 /* This function is only safe when called from the primary process
856 * in a multi-process setup*/
857 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
859 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
861 dev = &rte_eth_devices[port_id];
862 if (tx_queue_id >= dev->data->nb_tx_queues) {
863 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
867 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
869 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
874 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
876 uint16_t old_nb_queues = dev->data->nb_tx_queues;
880 if (dev->data->tx_queues == NULL) { /* first time configuration */
881 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
882 sizeof(dev->data->tx_queues[0]) * nb_queues,
883 RTE_CACHE_LINE_SIZE);
884 if (dev->data->tx_queues == NULL) {
885 dev->data->nb_tx_queues = 0;
888 } else { /* re-configure */
889 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
891 txq = dev->data->tx_queues;
893 for (i = nb_queues; i < old_nb_queues; i++)
894 (*dev->dev_ops->tx_queue_release)(txq[i]);
895 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
896 RTE_CACHE_LINE_SIZE);
899 if (nb_queues > old_nb_queues) {
900 uint16_t new_qs = nb_queues - old_nb_queues;
902 memset(txq + old_nb_queues, 0,
903 sizeof(txq[0]) * new_qs);
906 dev->data->tx_queues = txq;
909 dev->data->nb_tx_queues = nb_queues;
914 rte_eth_dev_check_vf_rss_rxq_num(uint8_t port_id, uint16_t nb_rx_q)
916 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
921 RTE_ETH_DEV_SRIOV(dev).active =
925 RTE_ETH_DEV_SRIOV(dev).active =
932 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = nb_rx_q;
933 RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx =
934 dev->pci_dev->max_vfs * nb_rx_q;
940 rte_eth_dev_check_mq_mode(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
941 const struct rte_eth_conf *dev_conf)
943 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
945 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
946 /* check multi-queue mode */
947 if ((dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) ||
948 (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB_RSS) ||
949 (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB)) {
950 /* SRIOV only works in VMDq enable mode */
951 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
953 "wrong VMDQ mq_mode rx %u tx %u\n",
955 dev_conf->rxmode.mq_mode,
956 dev_conf->txmode.mq_mode);
960 switch (dev_conf->rxmode.mq_mode) {
961 case ETH_MQ_RX_VMDQ_DCB:
962 case ETH_MQ_RX_VMDQ_DCB_RSS:
963 /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
964 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
966 "unsupported VMDQ mq_mode rx %u\n",
967 port_id, dev_conf->rxmode.mq_mode);
970 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
972 "Rx mq mode is changed from:"
973 "mq_mode %u into VMDQ mq_mode %u\n",
975 dev_conf->rxmode.mq_mode,
976 dev->data->dev_conf.rxmode.mq_mode);
977 case ETH_MQ_RX_VMDQ_RSS:
978 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_RSS;
979 if (nb_rx_q <= RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)
980 if (rte_eth_dev_check_vf_rss_rxq_num(port_id, nb_rx_q) != 0) {
981 PMD_DEBUG_TRACE("ethdev port_id=%d"
982 " SRIOV active, invalid queue"
983 " number for VMDQ RSS, allowed"
984 " value are 1, 2 or 4\n",
989 default: /* ETH_MQ_RX_VMDQ_ONLY or ETH_MQ_RX_NONE */
990 /* if nothing mq mode configure, use default scheme */
991 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
992 if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
993 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
997 switch (dev_conf->txmode.mq_mode) {
998 case ETH_MQ_TX_VMDQ_DCB:
999 /* DCB VMDQ in SRIOV mode, not implement yet */
1000 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
1002 "unsupported VMDQ mq_mode tx %u\n",
1003 port_id, dev_conf->txmode.mq_mode);
1005 default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
1006 /* if nothing mq mode configure, use default scheme */
1007 dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
1011 /* check valid queue number */
1012 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
1013 (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
1014 PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
1015 "queue number must less equal to %d\n",
1017 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
1021 /* For vmdb+dcb mode check our configuration before we go further */
1022 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB) {
1023 const struct rte_eth_vmdq_dcb_conf *conf;
1025 if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
1026 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
1028 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
1031 conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
1032 if (!(conf->nb_queue_pools == ETH_16_POOLS ||
1033 conf->nb_queue_pools == ETH_32_POOLS)) {
1034 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
1035 "nb_queue_pools must be %d or %d\n",
1036 port_id, ETH_16_POOLS, ETH_32_POOLS);
1040 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
1041 const struct rte_eth_vmdq_dcb_tx_conf *conf;
1043 if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
1044 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
1046 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
1049 conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
1050 if (!(conf->nb_queue_pools == ETH_16_POOLS ||
1051 conf->nb_queue_pools == ETH_32_POOLS)) {
1052 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
1053 "nb_queue_pools != %d or nb_queue_pools "
1055 port_id, ETH_16_POOLS, ETH_32_POOLS);
1060 /* For DCB mode check our configuration before we go further */
1061 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) {
1062 const struct rte_eth_dcb_rx_conf *conf;
1064 if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
1065 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
1067 port_id, ETH_DCB_NUM_QUEUES);
1070 conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
1071 if (!(conf->nb_tcs == ETH_4_TCS ||
1072 conf->nb_tcs == ETH_8_TCS)) {
1073 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
1074 "nb_tcs != %d or nb_tcs "
1076 port_id, ETH_4_TCS, ETH_8_TCS);
1081 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
1082 const struct rte_eth_dcb_tx_conf *conf;
1084 if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
1085 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
1087 port_id, ETH_DCB_NUM_QUEUES);
1090 conf = &(dev_conf->tx_adv_conf.dcb_tx_conf);
1091 if (!(conf->nb_tcs == ETH_4_TCS ||
1092 conf->nb_tcs == ETH_8_TCS)) {
1093 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
1094 "nb_tcs != %d or nb_tcs "
1096 port_id, ETH_4_TCS, ETH_8_TCS);
1105 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
1106 const struct rte_eth_conf *dev_conf)
1108 struct rte_eth_dev *dev;
1109 struct rte_eth_dev_info dev_info;
1112 /* This function is only safe when called from the primary process
1113 * in a multi-process setup*/
1114 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1116 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1118 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
1120 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
1121 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
1125 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
1127 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
1128 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
1132 dev = &rte_eth_devices[port_id];
1134 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1135 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
1137 if (dev->data->dev_started) {
1139 "port %d must be stopped to allow configuration\n", port_id);
1144 * Check that the numbers of RX and TX queues are not greater
1145 * than the maximum number of RX and TX queues supported by the
1146 * configured device.
1148 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
1149 if (nb_rx_q > dev_info.max_rx_queues) {
1150 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
1151 port_id, nb_rx_q, dev_info.max_rx_queues);
1155 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
1159 if (nb_tx_q > dev_info.max_tx_queues) {
1160 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
1161 port_id, nb_tx_q, dev_info.max_tx_queues);
1165 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
1169 /* Copy the dev_conf parameter into the dev structure */
1170 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
1173 * If link state interrupt is enabled, check that the
1174 * device supports it.
1176 if (dev_conf->intr_conf.lsc == 1) {
1177 const struct rte_pci_driver *pci_drv = &dev->driver->pci_drv;
1179 if (!(pci_drv->drv_flags & RTE_PCI_DRV_INTR_LSC)) {
1180 PMD_DEBUG_TRACE("driver %s does not support lsc\n",
1187 * If jumbo frames are enabled, check that the maximum RX packet
1188 * length is supported by the configured device.
1190 if (dev_conf->rxmode.jumbo_frame == 1) {
1191 if (dev_conf->rxmode.max_rx_pkt_len >
1192 dev_info.max_rx_pktlen) {
1193 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
1194 " > max valid value %u\n",
1196 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
1197 (unsigned)dev_info.max_rx_pktlen);
1199 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
1200 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
1201 " < min valid value %u\n",
1203 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
1204 (unsigned)ETHER_MIN_LEN);
1208 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
1209 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
1210 /* Use default value */
1211 dev->data->dev_conf.rxmode.max_rx_pkt_len =
1215 /* multiple queue mode checking */
1216 diag = rte_eth_dev_check_mq_mode(port_id, nb_rx_q, nb_tx_q, dev_conf);
1218 PMD_DEBUG_TRACE("port%d rte_eth_dev_check_mq_mode = %d\n",
1224 * Setup new number of RX/TX queues and reconfigure device.
1226 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
1228 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
1233 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
1235 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
1237 rte_eth_dev_rx_queue_config(dev, 0);
1241 diag = (*dev->dev_ops->dev_configure)(dev);
1243 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
1245 rte_eth_dev_rx_queue_config(dev, 0);
1246 rte_eth_dev_tx_queue_config(dev, 0);
1254 rte_eth_dev_config_restore(uint8_t port_id)
1256 struct rte_eth_dev *dev;
1257 struct rte_eth_dev_info dev_info;
1258 struct ether_addr addr;
1262 dev = &rte_eth_devices[port_id];
1264 rte_eth_dev_info_get(port_id, &dev_info);
1266 if (RTE_ETH_DEV_SRIOV(dev).active)
1267 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
1269 /* replay MAC address configuration */
1270 for (i = 0; i < dev_info.max_mac_addrs; i++) {
1271 addr = dev->data->mac_addrs[i];
1273 /* skip zero address */
1274 if (is_zero_ether_addr(&addr))
1277 /* add address to the hardware */
1278 if (*dev->dev_ops->mac_addr_add &&
1279 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
1280 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
1282 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
1284 /* exit the loop but not return an error */
1289 /* replay promiscuous configuration */
1290 if (rte_eth_promiscuous_get(port_id) == 1)
1291 rte_eth_promiscuous_enable(port_id);
1292 else if (rte_eth_promiscuous_get(port_id) == 0)
1293 rte_eth_promiscuous_disable(port_id);
1295 /* replay all multicast configuration */
1296 if (rte_eth_allmulticast_get(port_id) == 1)
1297 rte_eth_allmulticast_enable(port_id);
1298 else if (rte_eth_allmulticast_get(port_id) == 0)
1299 rte_eth_allmulticast_disable(port_id);
1303 rte_eth_dev_start(uint8_t port_id)
1305 struct rte_eth_dev *dev;
1308 /* This function is only safe when called from the primary process
1309 * in a multi-process setup*/
1310 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1312 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1314 dev = &rte_eth_devices[port_id];
1316 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1318 if (dev->data->dev_started != 0) {
1319 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1320 " already started\n",
1325 diag = (*dev->dev_ops->dev_start)(dev);
1327 dev->data->dev_started = 1;
1331 rte_eth_dev_config_restore(port_id);
1333 if (dev->data->dev_conf.intr_conf.lsc != 0) {
1334 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1335 (*dev->dev_ops->link_update)(dev, 0);
1341 rte_eth_dev_stop(uint8_t port_id)
1343 struct rte_eth_dev *dev;
1345 /* This function is only safe when called from the primary process
1346 * in a multi-process setup*/
1347 PROC_PRIMARY_OR_RET();
1349 VALID_PORTID_OR_RET(port_id);
1350 dev = &rte_eth_devices[port_id];
1352 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1354 if (dev->data->dev_started == 0) {
1355 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1356 " already stopped\n",
1361 dev->data->dev_started = 0;
1362 (*dev->dev_ops->dev_stop)(dev);
1366 rte_eth_dev_set_link_up(uint8_t port_id)
1368 struct rte_eth_dev *dev;
1370 /* This function is only safe when called from the primary process
1371 * in a multi-process setup*/
1372 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1374 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1376 dev = &rte_eth_devices[port_id];
1378 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1379 return (*dev->dev_ops->dev_set_link_up)(dev);
1383 rte_eth_dev_set_link_down(uint8_t port_id)
1385 struct rte_eth_dev *dev;
1387 /* This function is only safe when called from the primary process
1388 * in a multi-process setup*/
1389 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1391 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1393 dev = &rte_eth_devices[port_id];
1395 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1396 return (*dev->dev_ops->dev_set_link_down)(dev);
1400 rte_eth_dev_close(uint8_t port_id)
1402 struct rte_eth_dev *dev;
1404 /* This function is only safe when called from the primary process
1405 * in a multi-process setup*/
1406 PROC_PRIMARY_OR_RET();
1408 VALID_PORTID_OR_RET(port_id);
1409 dev = &rte_eth_devices[port_id];
1411 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1412 dev->data->dev_started = 0;
1413 (*dev->dev_ops->dev_close)(dev);
1417 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1418 uint16_t nb_rx_desc, unsigned int socket_id,
1419 const struct rte_eth_rxconf *rx_conf,
1420 struct rte_mempool *mp)
1423 uint32_t mbp_buf_size;
1424 struct rte_eth_dev *dev;
1425 struct rte_eth_dev_info dev_info;
1427 /* This function is only safe when called from the primary process
1428 * in a multi-process setup*/
1429 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1431 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1433 dev = &rte_eth_devices[port_id];
1434 if (rx_queue_id >= dev->data->nb_rx_queues) {
1435 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1439 if (dev->data->dev_started) {
1441 "port %d must be stopped to allow configuration\n", port_id);
1445 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1446 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1449 * Check the size of the mbuf data buffer.
1450 * This value must be provided in the private data of the memory pool.
1451 * First check that the memory pool has a valid private data.
1453 rte_eth_dev_info_get(port_id, &dev_info);
1454 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1455 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1456 mp->name, (int) mp->private_data_size,
1457 (int) sizeof(struct rte_pktmbuf_pool_private));
1460 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1462 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1463 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1464 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1468 (int)(RTE_PKTMBUF_HEADROOM +
1469 dev_info.min_rx_bufsize),
1470 (int)RTE_PKTMBUF_HEADROOM,
1471 (int)dev_info.min_rx_bufsize);
1475 if (rx_conf == NULL)
1476 rx_conf = &dev_info.default_rxconf;
1478 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1479 socket_id, rx_conf, mp);
1481 if (!dev->data->min_rx_buf_size ||
1482 dev->data->min_rx_buf_size > mbp_buf_size)
1483 dev->data->min_rx_buf_size = mbp_buf_size;
1490 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1491 uint16_t nb_tx_desc, unsigned int socket_id,
1492 const struct rte_eth_txconf *tx_conf)
1494 struct rte_eth_dev *dev;
1495 struct rte_eth_dev_info dev_info;
1497 /* This function is only safe when called from the primary process
1498 * in a multi-process setup*/
1499 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1501 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1503 dev = &rte_eth_devices[port_id];
1504 if (tx_queue_id >= dev->data->nb_tx_queues) {
1505 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1509 if (dev->data->dev_started) {
1511 "port %d must be stopped to allow configuration\n", port_id);
1515 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1516 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1518 rte_eth_dev_info_get(port_id, &dev_info);
1520 if (tx_conf == NULL)
1521 tx_conf = &dev_info.default_txconf;
1523 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1524 socket_id, tx_conf);
1528 rte_eth_promiscuous_enable(uint8_t port_id)
1530 struct rte_eth_dev *dev;
1532 VALID_PORTID_OR_RET(port_id);
1533 dev = &rte_eth_devices[port_id];
1535 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1536 (*dev->dev_ops->promiscuous_enable)(dev);
1537 dev->data->promiscuous = 1;
1541 rte_eth_promiscuous_disable(uint8_t port_id)
1543 struct rte_eth_dev *dev;
1545 VALID_PORTID_OR_RET(port_id);
1546 dev = &rte_eth_devices[port_id];
1548 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1549 dev->data->promiscuous = 0;
1550 (*dev->dev_ops->promiscuous_disable)(dev);
1554 rte_eth_promiscuous_get(uint8_t port_id)
1556 struct rte_eth_dev *dev;
1558 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1560 dev = &rte_eth_devices[port_id];
1561 return dev->data->promiscuous;
1565 rte_eth_allmulticast_enable(uint8_t port_id)
1567 struct rte_eth_dev *dev;
1569 VALID_PORTID_OR_RET(port_id);
1570 dev = &rte_eth_devices[port_id];
1572 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1573 (*dev->dev_ops->allmulticast_enable)(dev);
1574 dev->data->all_multicast = 1;
1578 rte_eth_allmulticast_disable(uint8_t port_id)
1580 struct rte_eth_dev *dev;
1582 VALID_PORTID_OR_RET(port_id);
1583 dev = &rte_eth_devices[port_id];
1585 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1586 dev->data->all_multicast = 0;
1587 (*dev->dev_ops->allmulticast_disable)(dev);
1591 rte_eth_allmulticast_get(uint8_t port_id)
1593 struct rte_eth_dev *dev;
1595 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1597 dev = &rte_eth_devices[port_id];
1598 return dev->data->all_multicast;
1602 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1603 struct rte_eth_link *link)
1605 struct rte_eth_link *dst = link;
1606 struct rte_eth_link *src = &(dev->data->dev_link);
1608 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1609 *(uint64_t *)src) == 0)
1616 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1618 struct rte_eth_dev *dev;
1620 VALID_PORTID_OR_RET(port_id);
1621 dev = &rte_eth_devices[port_id];
1623 if (dev->data->dev_conf.intr_conf.lsc != 0)
1624 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1626 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1627 (*dev->dev_ops->link_update)(dev, 1);
1628 *eth_link = dev->data->dev_link;
1633 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1635 struct rte_eth_dev *dev;
1637 VALID_PORTID_OR_RET(port_id);
1638 dev = &rte_eth_devices[port_id];
1640 if (dev->data->dev_conf.intr_conf.lsc != 0)
1641 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1643 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1644 (*dev->dev_ops->link_update)(dev, 0);
1645 *eth_link = dev->data->dev_link;
1650 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1652 struct rte_eth_dev *dev;
1654 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1656 dev = &rte_eth_devices[port_id];
1657 memset(stats, 0, sizeof(*stats));
1659 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1660 (*dev->dev_ops->stats_get)(dev, stats);
1661 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1666 rte_eth_stats_reset(uint8_t port_id)
1668 struct rte_eth_dev *dev;
1670 VALID_PORTID_OR_RET(port_id);
1671 dev = &rte_eth_devices[port_id];
1673 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1674 (*dev->dev_ops->stats_reset)(dev);
1677 /* retrieve ethdev extended statistics */
1679 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1682 struct rte_eth_stats eth_stats;
1683 struct rte_eth_dev *dev;
1684 unsigned count, i, q;
1685 uint64_t val, *stats_ptr;
1687 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1689 dev = &rte_eth_devices[port_id];
1691 /* implemented by the driver */
1692 if (dev->dev_ops->xstats_get != NULL)
1693 return (*dev->dev_ops->xstats_get)(dev, xstats, n);
1695 /* else, return generic statistics */
1696 count = RTE_NB_STATS;
1697 count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
1698 count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
1702 /* now fill the xstats structure */
1705 rte_eth_stats_get(port_id, ð_stats);
1708 for (i = 0; i < RTE_NB_STATS; i++) {
1709 stats_ptr = RTE_PTR_ADD(ð_stats,
1710 rte_stats_strings[i].offset);
1712 snprintf(xstats[count].name, sizeof(xstats[count].name),
1713 "%s", rte_stats_strings[i].name);
1714 xstats[count++].value = val;
1718 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1719 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1720 stats_ptr = RTE_PTR_ADD(ð_stats,
1721 rte_rxq_stats_strings[i].offset +
1722 q * sizeof(uint64_t));
1724 snprintf(xstats[count].name, sizeof(xstats[count].name),
1725 "rx_queue_%u_%s", q,
1726 rte_rxq_stats_strings[i].name);
1727 xstats[count++].value = val;
1732 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1733 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1734 stats_ptr = RTE_PTR_ADD(ð_stats,
1735 rte_txq_stats_strings[i].offset +
1736 q * sizeof(uint64_t));
1738 snprintf(xstats[count].name, sizeof(xstats[count].name),
1739 "tx_queue_%u_%s", q,
1740 rte_txq_stats_strings[i].name);
1741 xstats[count++].value = val;
1748 /* reset ethdev extended statistics */
1750 rte_eth_xstats_reset(uint8_t port_id)
1752 struct rte_eth_dev *dev;
1754 VALID_PORTID_OR_RET(port_id);
1755 dev = &rte_eth_devices[port_id];
1757 /* implemented by the driver */
1758 if (dev->dev_ops->xstats_reset != NULL) {
1759 (*dev->dev_ops->xstats_reset)(dev);
1763 /* fallback to default */
1764 rte_eth_stats_reset(port_id);
1768 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1771 struct rte_eth_dev *dev;
1773 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1775 dev = &rte_eth_devices[port_id];
1777 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1778 return (*dev->dev_ops->queue_stats_mapping_set)
1779 (dev, queue_id, stat_idx, is_rx);
1784 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1787 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1793 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1796 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1802 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1804 struct rte_eth_dev *dev;
1806 VALID_PORTID_OR_RET(port_id);
1807 dev = &rte_eth_devices[port_id];
1809 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1811 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1812 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1813 dev_info->pci_dev = dev->pci_dev;
1815 dev_info->driver_name = dev->driver->pci_drv.name;
1819 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1821 struct rte_eth_dev *dev;
1823 VALID_PORTID_OR_RET(port_id);
1824 dev = &rte_eth_devices[port_id];
1825 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1830 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1832 struct rte_eth_dev *dev;
1834 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1836 dev = &rte_eth_devices[port_id];
1837 *mtu = dev->data->mtu;
1842 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1845 struct rte_eth_dev *dev;
1847 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1848 dev = &rte_eth_devices[port_id];
1849 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1851 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1853 dev->data->mtu = mtu;
1859 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1861 struct rte_eth_dev *dev;
1863 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1864 dev = &rte_eth_devices[port_id];
1865 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1866 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1870 if (vlan_id > 4095) {
1871 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1872 port_id, (unsigned) vlan_id);
1875 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1877 return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1881 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1883 struct rte_eth_dev *dev;
1885 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1886 dev = &rte_eth_devices[port_id];
1887 if (rx_queue_id >= dev->data->nb_rx_queues) {
1888 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1892 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1893 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1899 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1901 struct rte_eth_dev *dev;
1903 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1904 dev = &rte_eth_devices[port_id];
1905 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1906 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1912 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1914 struct rte_eth_dev *dev;
1919 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1920 dev = &rte_eth_devices[port_id];
1922 /*check which option changed by application*/
1923 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1924 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1926 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1927 mask |= ETH_VLAN_STRIP_MASK;
1930 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1931 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1933 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1934 mask |= ETH_VLAN_FILTER_MASK;
1937 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1938 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1940 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1941 mask |= ETH_VLAN_EXTEND_MASK;
1948 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1949 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1955 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1957 struct rte_eth_dev *dev;
1960 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1961 dev = &rte_eth_devices[port_id];
1963 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1964 ret |= ETH_VLAN_STRIP_OFFLOAD;
1966 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1967 ret |= ETH_VLAN_FILTER_OFFLOAD;
1969 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1970 ret |= ETH_VLAN_EXTEND_OFFLOAD;
1976 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1978 struct rte_eth_dev *dev;
1980 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1981 dev = &rte_eth_devices[port_id];
1982 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1983 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1989 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1990 struct rte_fdir_filter *fdir_filter,
1993 struct rte_eth_dev *dev;
1995 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1996 dev = &rte_eth_devices[port_id];
1998 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1999 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2000 port_id, dev->data->dev_conf.fdir_conf.mode);
2004 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2005 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2006 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2007 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
2008 "None l4type, source & destinations ports "
2009 "should be null!\n");
2013 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
2014 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
2019 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
2020 struct rte_fdir_filter *fdir_filter,
2023 struct rte_eth_dev *dev;
2025 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2026 dev = &rte_eth_devices[port_id];
2028 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
2029 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2030 port_id, dev->data->dev_conf.fdir_conf.mode);
2034 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2035 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2036 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2037 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
2038 "None l4type, source & destinations ports "
2039 "should be null!\n");
2043 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
2044 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
2050 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
2051 struct rte_fdir_filter *fdir_filter)
2053 struct rte_eth_dev *dev;
2055 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2056 dev = &rte_eth_devices[port_id];
2058 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
2059 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2060 port_id, dev->data->dev_conf.fdir_conf.mode);
2064 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2065 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2066 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2067 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
2068 "None l4type source & destinations ports "
2069 "should be null!\n");
2073 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
2074 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
2078 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
2080 struct rte_eth_dev *dev;
2082 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2083 dev = &rte_eth_devices[port_id];
2084 if (!(dev->data->dev_conf.fdir_conf.mode)) {
2085 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
2089 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
2091 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
2096 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
2097 struct rte_fdir_filter *fdir_filter,
2098 uint16_t soft_id, uint8_t queue,
2101 struct rte_eth_dev *dev;
2103 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2104 dev = &rte_eth_devices[port_id];
2106 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
2107 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2108 port_id, dev->data->dev_conf.fdir_conf.mode);
2112 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2113 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2114 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2115 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
2116 "None l4type, source & destinations ports "
2117 "should be null!\n");
2121 /* For now IPv6 is not supported with perfect filter */
2122 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2125 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
2126 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
2132 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
2133 struct rte_fdir_filter *fdir_filter,
2134 uint16_t soft_id, uint8_t queue,
2137 struct rte_eth_dev *dev;
2139 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2140 dev = &rte_eth_devices[port_id];
2142 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
2143 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2144 port_id, dev->data->dev_conf.fdir_conf.mode);
2148 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2149 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2150 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2151 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
2152 "None l4type, source & destinations ports "
2153 "should be null!\n");
2157 /* For now IPv6 is not supported with perfect filter */
2158 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2161 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
2162 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
2163 soft_id, queue, drop);
2167 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
2168 struct rte_fdir_filter *fdir_filter,
2171 struct rte_eth_dev *dev;
2173 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2174 dev = &rte_eth_devices[port_id];
2176 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
2177 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2178 port_id, dev->data->dev_conf.fdir_conf.mode);
2182 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2183 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2184 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2185 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
2186 "None l4type, source & destinations ports "
2187 "should be null!\n");
2191 /* For now IPv6 is not supported with perfect filter */
2192 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2195 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
2196 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
2201 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
2203 struct rte_eth_dev *dev;
2205 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2206 dev = &rte_eth_devices[port_id];
2207 if (!(dev->data->dev_conf.fdir_conf.mode)) {
2208 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
2212 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
2213 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
2217 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2219 struct rte_eth_dev *dev;
2221 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2222 dev = &rte_eth_devices[port_id];
2223 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2224 memset(fc_conf, 0, sizeof(*fc_conf));
2225 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
2229 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2231 struct rte_eth_dev *dev;
2233 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2234 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2235 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2239 dev = &rte_eth_devices[port_id];
2240 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2241 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
2245 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
2247 struct rte_eth_dev *dev;
2249 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2250 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2251 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2255 dev = &rte_eth_devices[port_id];
2256 /* High water, low water validation are device specific */
2257 if (*dev->dev_ops->priority_flow_ctrl_set)
2258 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
2263 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2271 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
2272 PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
2273 RTE_RETA_GROUP_SIZE);
2277 num = reta_size / RTE_RETA_GROUP_SIZE;
2278 for (i = 0; i < num; i++) {
2279 if (reta_conf[i].mask)
2287 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2291 uint16_t i, idx, shift;
2297 PMD_DEBUG_TRACE("No receive queue is available\n");
2301 for (i = 0; i < reta_size; i++) {
2302 idx = i / RTE_RETA_GROUP_SIZE;
2303 shift = i % RTE_RETA_GROUP_SIZE;
2304 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2305 (reta_conf[idx].reta[shift] >= max_rxq)) {
2306 PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2307 "the maximum rxq index: %u\n", idx, shift,
2308 reta_conf[idx].reta[shift], max_rxq);
2317 rte_eth_dev_rss_reta_update(uint8_t port_id,
2318 struct rte_eth_rss_reta_entry64 *reta_conf,
2321 struct rte_eth_dev *dev;
2324 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2325 /* Check mask bits */
2326 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2330 dev = &rte_eth_devices[port_id];
2332 /* Check entry value */
2333 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2334 dev->data->nb_rx_queues);
2338 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2339 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2343 rte_eth_dev_rss_reta_query(uint8_t port_id,
2344 struct rte_eth_rss_reta_entry64 *reta_conf,
2347 struct rte_eth_dev *dev;
2350 if (port_id >= nb_ports) {
2351 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2355 /* Check mask bits */
2356 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2360 dev = &rte_eth_devices[port_id];
2361 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2362 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2366 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2368 struct rte_eth_dev *dev;
2369 uint16_t rss_hash_protos;
2371 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2372 rss_hash_protos = rss_conf->rss_hf;
2373 if ((rss_hash_protos != 0) &&
2374 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2375 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2379 dev = &rte_eth_devices[port_id];
2380 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2381 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2385 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2386 struct rte_eth_rss_conf *rss_conf)
2388 struct rte_eth_dev *dev;
2390 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2391 dev = &rte_eth_devices[port_id];
2392 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2393 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2397 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
2398 struct rte_eth_udp_tunnel *udp_tunnel)
2400 struct rte_eth_dev *dev;
2402 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2403 if (udp_tunnel == NULL) {
2404 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2408 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2409 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2413 dev = &rte_eth_devices[port_id];
2414 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
2415 return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
2419 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
2420 struct rte_eth_udp_tunnel *udp_tunnel)
2422 struct rte_eth_dev *dev;
2424 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2425 dev = &rte_eth_devices[port_id];
2427 if (udp_tunnel == NULL) {
2428 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2432 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2433 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2437 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2438 return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2442 rte_eth_led_on(uint8_t port_id)
2444 struct rte_eth_dev *dev;
2446 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2447 dev = &rte_eth_devices[port_id];
2448 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2449 return (*dev->dev_ops->dev_led_on)(dev);
2453 rte_eth_led_off(uint8_t port_id)
2455 struct rte_eth_dev *dev;
2457 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2458 dev = &rte_eth_devices[port_id];
2459 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2460 return (*dev->dev_ops->dev_led_off)(dev);
2464 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2468 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2470 struct rte_eth_dev_info dev_info;
2471 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2474 rte_eth_dev_info_get(port_id, &dev_info);
2476 for (i = 0; i < dev_info.max_mac_addrs; i++)
2477 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2483 static const struct ether_addr null_mac_addr;
2486 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2489 struct rte_eth_dev *dev;
2493 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2494 dev = &rte_eth_devices[port_id];
2495 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2497 if (is_zero_ether_addr(addr)) {
2498 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2502 if (pool >= ETH_64_POOLS) {
2503 PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2507 index = get_mac_addr_index(port_id, addr);
2509 index = get_mac_addr_index(port_id, &null_mac_addr);
2511 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2516 pool_mask = dev->data->mac_pool_sel[index];
2518 /* Check if both MAC address and pool is already there, and do nothing */
2519 if (pool_mask & (1ULL << pool))
2524 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2526 /* Update address in NIC data structure */
2527 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2529 /* Update pool bitmap in NIC data structure */
2530 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2536 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2538 struct rte_eth_dev *dev;
2541 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2542 dev = &rte_eth_devices[port_id];
2543 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2545 index = get_mac_addr_index(port_id, addr);
2547 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2549 } else if (index < 0)
2550 return 0; /* Do nothing if address wasn't found */
2553 (*dev->dev_ops->mac_addr_remove)(dev, index);
2555 /* Update address in NIC data structure */
2556 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2558 /* reset pool bitmap */
2559 dev->data->mac_pool_sel[index] = 0;
2565 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2566 uint16_t rx_mode, uint8_t on)
2569 struct rte_eth_dev *dev;
2570 struct rte_eth_dev_info dev_info;
2572 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2574 dev = &rte_eth_devices[port_id];
2575 rte_eth_dev_info_get(port_id, &dev_info);
2577 num_vfs = dev_info.max_vfs;
2579 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2584 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2587 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2588 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2592 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2596 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2598 struct rte_eth_dev_info dev_info;
2599 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2602 rte_eth_dev_info_get(port_id, &dev_info);
2603 if (!dev->data->hash_mac_addrs)
2606 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2607 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2608 ETHER_ADDR_LEN) == 0)
2615 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2620 struct rte_eth_dev *dev;
2622 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2624 dev = &rte_eth_devices[port_id];
2625 if (is_zero_ether_addr(addr)) {
2626 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2631 index = get_hash_mac_addr_index(port_id, addr);
2632 /* Check if it's already there, and do nothing */
2633 if ((index >= 0) && (on))
2638 PMD_DEBUG_TRACE("port %d: the MAC address was not "
2639 "set in UTA\n", port_id);
2643 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2645 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2651 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2652 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2654 /* Update address in NIC data structure */
2656 ether_addr_copy(addr,
2657 &dev->data->hash_mac_addrs[index]);
2659 ether_addr_copy(&null_mac_addr,
2660 &dev->data->hash_mac_addrs[index]);
2667 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2669 struct rte_eth_dev *dev;
2671 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2673 dev = &rte_eth_devices[port_id];
2675 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2676 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2680 rte_eth_dev_set_vf_rx(uint8_t port_id, uint16_t vf, uint8_t on)
2683 struct rte_eth_dev *dev;
2684 struct rte_eth_dev_info dev_info;
2686 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2688 dev = &rte_eth_devices[port_id];
2689 rte_eth_dev_info_get(port_id, &dev_info);
2691 num_vfs = dev_info.max_vfs;
2693 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2697 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2698 return (*dev->dev_ops->set_vf_rx)(dev, vf, on);
2702 rte_eth_dev_set_vf_tx(uint8_t port_id, uint16_t vf, uint8_t on)
2705 struct rte_eth_dev *dev;
2706 struct rte_eth_dev_info dev_info;
2708 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2710 dev = &rte_eth_devices[port_id];
2711 rte_eth_dev_info_get(port_id, &dev_info);
2713 num_vfs = dev_info.max_vfs;
2715 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2719 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2720 return (*dev->dev_ops->set_vf_tx)(dev, vf, on);
2724 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2725 uint64_t vf_mask, uint8_t vlan_on)
2727 struct rte_eth_dev *dev;
2729 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2731 dev = &rte_eth_devices[port_id];
2733 if (vlan_id > ETHER_MAX_VLAN_ID) {
2734 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2740 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2744 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2745 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2749 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2752 struct rte_eth_dev *dev;
2753 struct rte_eth_dev_info dev_info;
2754 struct rte_eth_link link;
2756 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2758 dev = &rte_eth_devices[port_id];
2759 rte_eth_dev_info_get(port_id, &dev_info);
2760 link = dev->data->dev_link;
2762 if (queue_idx > dev_info.max_tx_queues) {
2763 PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2764 "invalid queue id=%d\n", port_id, queue_idx);
2768 if (tx_rate > link.link_speed) {
2769 PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2770 "bigger than link speed= %d\n",
2771 tx_rate, link.link_speed);
2775 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2776 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2779 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2782 struct rte_eth_dev *dev;
2783 struct rte_eth_dev_info dev_info;
2784 struct rte_eth_link link;
2789 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2791 dev = &rte_eth_devices[port_id];
2792 rte_eth_dev_info_get(port_id, &dev_info);
2793 link = dev->data->dev_link;
2795 if (vf > dev_info.max_vfs) {
2796 PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2797 "invalid vf id=%d\n", port_id, vf);
2801 if (tx_rate > link.link_speed) {
2802 PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2803 "bigger than link speed= %d\n",
2804 tx_rate, link.link_speed);
2808 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2809 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2813 rte_eth_mirror_rule_set(uint8_t port_id,
2814 struct rte_eth_mirror_conf *mirror_conf,
2815 uint8_t rule_id, uint8_t on)
2817 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2819 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2820 if (mirror_conf->rule_type_mask == 0) {
2821 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2825 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2826 PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2831 if ((mirror_conf->rule_type_mask & ETH_VMDQ_POOL_MIRROR) &&
2832 (mirror_conf->pool_mask == 0)) {
2833 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2837 dev = &rte_eth_devices[port_id];
2838 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2840 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2844 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2846 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2848 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2850 dev = &rte_eth_devices[port_id];
2851 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2853 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2856 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2858 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2859 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2861 struct rte_eth_dev *dev;
2863 VALID_PORTID_OR_ERR_RET(port_id, 0);
2865 dev = &rte_eth_devices[port_id];
2866 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);
2867 if (queue_id >= dev->data->nb_rx_queues) {
2868 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2871 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2876 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2877 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2879 struct rte_eth_dev *dev;
2881 VALID_PORTID_OR_ERR_RET(port_id, 0);
2883 dev = &rte_eth_devices[port_id];
2885 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0);
2886 if (queue_id >= dev->data->nb_tx_queues) {
2887 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2890 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2895 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2897 struct rte_eth_dev *dev;
2899 VALID_PORTID_OR_ERR_RET(port_id, 0);
2901 dev = &rte_eth_devices[port_id];
2902 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0);
2903 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2907 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2909 struct rte_eth_dev *dev;
2911 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2913 dev = &rte_eth_devices[port_id];
2914 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2915 return (*dev->dev_ops->rx_descriptor_done)(dev->data->rx_queues[queue_id],
2921 rte_eth_dev_callback_register(uint8_t port_id,
2922 enum rte_eth_event_type event,
2923 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2925 struct rte_eth_dev *dev;
2926 struct rte_eth_dev_callback *user_cb;
2931 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2933 dev = &rte_eth_devices[port_id];
2934 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2936 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2937 if (user_cb->cb_fn == cb_fn &&
2938 user_cb->cb_arg == cb_arg &&
2939 user_cb->event == event) {
2944 /* create a new callback. */
2945 if (user_cb == NULL &&
2946 (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2947 sizeof(struct rte_eth_dev_callback), 0))) {
2948 user_cb->cb_fn = cb_fn;
2949 user_cb->cb_arg = cb_arg;
2950 user_cb->event = event;
2951 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2954 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2955 return (user_cb == NULL) ? -ENOMEM : 0;
2959 rte_eth_dev_callback_unregister(uint8_t port_id,
2960 enum rte_eth_event_type event,
2961 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2964 struct rte_eth_dev *dev;
2965 struct rte_eth_dev_callback *cb, *next;
2970 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2972 dev = &rte_eth_devices[port_id];
2973 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2976 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2978 next = TAILQ_NEXT(cb, next);
2980 if (cb->cb_fn != cb_fn || cb->event != event ||
2981 (cb->cb_arg != (void *)-1 &&
2982 cb->cb_arg != cb_arg))
2986 * if this callback is not executing right now,
2989 if (cb->active == 0) {
2990 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2997 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3002 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
3003 enum rte_eth_event_type event)
3005 struct rte_eth_dev_callback *cb_lst;
3006 struct rte_eth_dev_callback dev_cb;
3008 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3009 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
3010 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
3014 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3015 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
3017 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3020 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3022 #ifdef RTE_NIC_BYPASS
3023 int rte_eth_dev_bypass_init(uint8_t port_id)
3025 struct rte_eth_dev *dev;
3027 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3029 dev = &rte_eth_devices[port_id];
3030 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
3031 (*dev->dev_ops->bypass_init)(dev);
3036 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
3038 struct rte_eth_dev *dev;
3040 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3042 dev = &rte_eth_devices[port_id];
3043 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
3044 (*dev->dev_ops->bypass_state_show)(dev, state);
3049 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
3051 struct rte_eth_dev *dev;
3053 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3055 dev = &rte_eth_devices[port_id];
3056 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
3057 (*dev->dev_ops->bypass_state_set)(dev, new_state);
3062 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
3064 struct rte_eth_dev *dev;
3066 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3068 dev = &rte_eth_devices[port_id];
3069 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
3070 (*dev->dev_ops->bypass_event_show)(dev, event, state);
3075 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
3077 struct rte_eth_dev *dev;
3079 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3081 dev = &rte_eth_devices[port_id];
3083 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
3084 (*dev->dev_ops->bypass_event_set)(dev, event, state);
3089 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
3091 struct rte_eth_dev *dev;
3093 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3095 dev = &rte_eth_devices[port_id];
3097 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
3098 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
3103 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
3105 struct rte_eth_dev *dev;
3107 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3109 dev = &rte_eth_devices[port_id];
3111 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
3112 (*dev->dev_ops->bypass_ver_show)(dev, ver);
3117 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
3119 struct rte_eth_dev *dev;
3121 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3123 dev = &rte_eth_devices[port_id];
3125 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
3126 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
3131 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
3133 struct rte_eth_dev *dev;
3135 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3137 dev = &rte_eth_devices[port_id];
3139 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
3140 (*dev->dev_ops->bypass_wd_reset)(dev);
3146 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
3148 struct rte_eth_dev *dev;
3150 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3152 dev = &rte_eth_devices[port_id];
3153 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3154 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3155 RTE_ETH_FILTER_NOP, NULL);
3159 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
3160 enum rte_filter_op filter_op, void *arg)
3162 struct rte_eth_dev *dev;
3164 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3166 dev = &rte_eth_devices[port_id];
3167 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3168 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
3172 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
3173 rte_rx_callback_fn fn, void *user_param)
3175 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3176 rte_errno = ENOTSUP;
3179 /* check input parameters */
3180 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3181 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3186 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3194 cb->param = user_param;
3195 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3196 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3201 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
3202 rte_tx_callback_fn fn, void *user_param)
3204 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3205 rte_errno = ENOTSUP;
3208 /* check input parameters */
3209 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3210 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3215 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3223 cb->param = user_param;
3224 cb->next = rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3225 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3230 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3231 struct rte_eth_rxtx_callback *user_cb)
3233 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3236 /* Check input parameters. */
3237 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
3238 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3242 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3243 struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
3244 struct rte_eth_rxtx_callback *prev_cb;
3246 /* Reset head pointer and remove user cb if first in the list. */
3247 if (cb == user_cb) {
3248 dev->post_rx_burst_cbs[queue_id] = user_cb->next;
3252 /* Remove the user cb from the callback list. */
3257 if (cb == user_cb) {
3258 prev_cb->next = user_cb->next;
3262 } while (cb != NULL);
3264 /* Callback wasn't found. */
3269 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3270 struct rte_eth_rxtx_callback *user_cb)
3272 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3275 /* Check input parameters. */
3276 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
3277 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3281 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3282 struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
3283 struct rte_eth_rxtx_callback *prev_cb;
3285 /* Reset head pointer and remove user cb if first in the list. */
3286 if (cb == user_cb) {
3287 dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
3291 /* Remove the user cb from the callback list. */
3296 if (cb == user_cb) {
3297 prev_cb->next = user_cb->next;
3301 } while (cb != NULL);
3303 /* Callback wasn't found. */
3308 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3309 struct ether_addr *mc_addr_set,
3310 uint32_t nb_mc_addr)
3312 struct rte_eth_dev *dev;
3314 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3316 dev = &rte_eth_devices[port_id];
3317 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3318 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);