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_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 static enum rte_eth_dev_type
447 rte_eth_dev_get_device_type(uint8_t port_id)
449 if (!rte_eth_dev_is_valid_port(port_id))
450 return RTE_ETH_DEV_UNKNOWN;
451 return rte_eth_devices[port_id].dev_type;
455 rte_eth_dev_save(struct rte_eth_dev *devs, size_t size)
457 if ((devs == NULL) ||
458 (size != sizeof(struct rte_eth_dev) * RTE_MAX_ETHPORTS))
461 /* save current rte_eth_devices */
462 memcpy(devs, rte_eth_devices, size);
467 rte_eth_dev_get_changed_port(struct rte_eth_dev *devs, uint8_t *port_id)
469 if ((devs == NULL) || (port_id == NULL))
472 /* check which port was attached or detached */
473 for (*port_id = 0; *port_id < RTE_MAX_ETHPORTS; (*port_id)++, devs++) {
474 if (rte_eth_devices[*port_id].attached ^ devs->attached)
481 rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr)
483 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
486 PMD_DEBUG_TRACE("Null pointer is specified\n");
490 *addr = rte_eth_devices[port_id].pci_dev->addr;
495 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
499 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
502 PMD_DEBUG_TRACE("Null pointer is specified\n");
506 /* shouldn't check 'rte_eth_devices[i].data',
507 * because it might be overwritten by VDEV PMD */
508 tmp = rte_eth_dev_data[port_id].name;
514 rte_eth_dev_is_detachable(uint8_t port_id)
518 if (port_id >= RTE_MAX_ETHPORTS) {
519 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
523 if (rte_eth_devices[port_id].dev_type == RTE_ETH_DEV_PCI) {
524 switch (rte_eth_devices[port_id].pci_dev->kdrv) {
525 case RTE_KDRV_IGB_UIO:
526 case RTE_KDRV_UIO_GENERIC:
527 case RTE_KDRV_NIC_UIO:
535 drv_flags = rte_eth_devices[port_id].driver->pci_drv.drv_flags;
536 return !(drv_flags & RTE_PCI_DRV_DETACHABLE);
539 /* attach the new physical device, then store port_id of the device */
541 rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
544 struct rte_eth_dev devs[RTE_MAX_ETHPORTS];
546 if ((addr == NULL) || (port_id == NULL))
549 /* save current port status */
550 if (rte_eth_dev_save(devs, sizeof(devs)))
552 /* re-construct pci_device_list */
553 if (rte_eal_pci_scan())
555 /* invoke probe func of the driver can handle the new device.
557 * rte_eal_pci_probe_one() should return port_id.
558 * And rte_eth_dev_save() and rte_eth_dev_get_changed_port()
559 * should be removed. */
560 if (rte_eal_pci_probe_one(addr))
562 /* get port_id enabled by above procedures */
563 if (rte_eth_dev_get_changed_port(devs, &new_port_id))
566 *port_id = new_port_id;
569 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
573 /* detach the new physical device, then store pci_addr of the device */
575 rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
577 struct rte_pci_addr freed_addr;
578 struct rte_pci_addr vp;
583 /* check whether the driver supports detach feature, or not */
584 if (rte_eth_dev_is_detachable(port_id))
587 /* get pci address by port id */
588 if (rte_eth_dev_get_addr_by_port(port_id, &freed_addr))
591 /* Zeroed pci addr means the port comes from virtual device */
592 vp.domain = vp.bus = vp.devid = vp.function = 0;
593 if (rte_eal_compare_pci_addr(&vp, &freed_addr) == 0)
596 /* invoke close func of the driver,
597 * also remove the device from pci_device_list */
598 if (rte_eal_pci_close_one(&freed_addr))
604 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
608 /* attach the new virtual device, then store port_id of the device */
610 rte_eth_dev_attach_vdev(const char *vdevargs, uint8_t *port_id)
612 char *name = NULL, *args = NULL;
614 struct rte_eth_dev devs[RTE_MAX_ETHPORTS];
617 if ((vdevargs == NULL) || (port_id == NULL))
620 /* parse vdevargs, then retrieve device name and args */
621 if (rte_eal_parse_devargs_str(vdevargs, &name, &args))
624 /* save current port status */
625 if (rte_eth_dev_save(devs, sizeof(devs)))
627 /* walk around dev_driver_list to find the driver of the device,
628 * then invoke probe function o the driver.
630 * rte_eal_vdev_init() should return port_id,
631 * And rte_eth_dev_save() and rte_eth_dev_get_changed_port()
632 * should be removed. */
633 if (rte_eal_vdev_init(name, args))
635 /* get port_id enabled by above procedures */
636 if (rte_eth_dev_get_changed_port(devs, &new_port_id))
639 *port_id = new_port_id;
647 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
651 /* detach the new virtual device, then store the name of the device */
653 rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
655 char name[RTE_ETH_NAME_MAX_LEN];
657 if (vdevname == NULL)
660 /* check whether the driver supports detach feature, or not */
661 if (rte_eth_dev_is_detachable(port_id))
664 /* get device name by port id */
665 if (rte_eth_dev_get_name_by_port(port_id, name))
667 /* walk around dev_driver_list to find the driver of the device,
668 * then invoke close function o the driver */
669 if (rte_eal_vdev_uninit(name))
672 strncpy(vdevname, name, sizeof(name));
675 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
679 /* attach the new device, then store port_id of the device */
681 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
683 struct rte_pci_addr addr;
685 if ((devargs == NULL) || (port_id == NULL))
688 if (eal_parse_pci_DomBDF(devargs, &addr) == 0)
689 return rte_eth_dev_attach_pdev(&addr, port_id);
691 return rte_eth_dev_attach_vdev(devargs, port_id);
694 /* detach the device, then store the name of the device */
696 rte_eth_dev_detach(uint8_t port_id, char *name)
698 struct rte_pci_addr addr;
704 if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {
705 ret = rte_eth_dev_get_addr_by_port(port_id, &addr);
709 ret = rte_eth_dev_detach_pdev(port_id, &addr);
711 snprintf(name, RTE_ETH_NAME_MAX_LEN,
713 addr.domain, addr.bus,
714 addr.devid, addr.function);
718 return rte_eth_dev_detach_vdev(port_id, name);
722 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
724 uint16_t old_nb_queues = dev->data->nb_rx_queues;
728 if (dev->data->rx_queues == NULL) { /* first time configuration */
729 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
730 sizeof(dev->data->rx_queues[0]) * nb_queues,
731 RTE_CACHE_LINE_SIZE);
732 if (dev->data->rx_queues == NULL) {
733 dev->data->nb_rx_queues = 0;
736 } else { /* re-configure */
737 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
739 rxq = dev->data->rx_queues;
741 for (i = nb_queues; i < old_nb_queues; i++)
742 (*dev->dev_ops->rx_queue_release)(rxq[i]);
743 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
744 RTE_CACHE_LINE_SIZE);
747 if (nb_queues > old_nb_queues) {
748 uint16_t new_qs = nb_queues - old_nb_queues;
750 memset(rxq + old_nb_queues, 0,
751 sizeof(rxq[0]) * new_qs);
754 dev->data->rx_queues = rxq;
757 dev->data->nb_rx_queues = nb_queues;
762 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
764 struct rte_eth_dev *dev;
766 /* This function is only safe when called from the primary process
767 * in a multi-process setup*/
768 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
770 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
772 dev = &rte_eth_devices[port_id];
773 if (rx_queue_id >= dev->data->nb_rx_queues) {
774 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
778 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
780 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
785 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
787 struct rte_eth_dev *dev;
789 /* This function is only safe when called from the primary process
790 * in a multi-process setup*/
791 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
793 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
795 dev = &rte_eth_devices[port_id];
796 if (rx_queue_id >= dev->data->nb_rx_queues) {
797 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
801 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
803 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
808 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
810 struct rte_eth_dev *dev;
812 /* This function is only safe when called from the primary process
813 * in a multi-process setup*/
814 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
816 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
818 dev = &rte_eth_devices[port_id];
819 if (tx_queue_id >= dev->data->nb_tx_queues) {
820 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
824 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
826 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
831 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
833 struct rte_eth_dev *dev;
835 /* This function is only safe when called from the primary process
836 * in a multi-process setup*/
837 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
839 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
841 dev = &rte_eth_devices[port_id];
842 if (tx_queue_id >= dev->data->nb_tx_queues) {
843 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
847 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
849 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
854 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
856 uint16_t old_nb_queues = dev->data->nb_tx_queues;
860 if (dev->data->tx_queues == NULL) { /* first time configuration */
861 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
862 sizeof(dev->data->tx_queues[0]) * nb_queues,
863 RTE_CACHE_LINE_SIZE);
864 if (dev->data->tx_queues == NULL) {
865 dev->data->nb_tx_queues = 0;
868 } else { /* re-configure */
869 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
871 txq = dev->data->tx_queues;
873 for (i = nb_queues; i < old_nb_queues; i++)
874 (*dev->dev_ops->tx_queue_release)(txq[i]);
875 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
876 RTE_CACHE_LINE_SIZE);
879 if (nb_queues > old_nb_queues) {
880 uint16_t new_qs = nb_queues - old_nb_queues;
882 memset(txq + old_nb_queues, 0,
883 sizeof(txq[0]) * new_qs);
886 dev->data->tx_queues = txq;
889 dev->data->nb_tx_queues = nb_queues;
894 rte_eth_dev_check_vf_rss_rxq_num(uint8_t port_id, uint16_t nb_rx_q)
896 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
901 RTE_ETH_DEV_SRIOV(dev).active =
905 RTE_ETH_DEV_SRIOV(dev).active =
912 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = nb_rx_q;
913 RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx =
914 dev->pci_dev->max_vfs * nb_rx_q;
920 rte_eth_dev_check_mq_mode(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
921 const struct rte_eth_conf *dev_conf)
923 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
925 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
926 /* check multi-queue mode */
927 if ((dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) ||
928 (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB_RSS) ||
929 (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB)) {
930 /* SRIOV only works in VMDq enable mode */
931 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
933 "wrong VMDQ mq_mode rx %u tx %u\n",
935 dev_conf->rxmode.mq_mode,
936 dev_conf->txmode.mq_mode);
940 switch (dev_conf->rxmode.mq_mode) {
941 case ETH_MQ_RX_VMDQ_DCB:
942 case ETH_MQ_RX_VMDQ_DCB_RSS:
943 /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
944 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
946 "unsupported VMDQ mq_mode rx %u\n",
947 port_id, dev_conf->rxmode.mq_mode);
950 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
952 "Rx mq mode is changed from:"
953 "mq_mode %u into VMDQ mq_mode %u\n",
955 dev_conf->rxmode.mq_mode,
956 dev->data->dev_conf.rxmode.mq_mode);
957 case ETH_MQ_RX_VMDQ_RSS:
958 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_RSS;
959 if (nb_rx_q <= RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)
960 if (rte_eth_dev_check_vf_rss_rxq_num(port_id, nb_rx_q) != 0) {
961 PMD_DEBUG_TRACE("ethdev port_id=%d"
962 " SRIOV active, invalid queue"
963 " number for VMDQ RSS, allowed"
964 " value are 1, 2 or 4\n",
969 default: /* ETH_MQ_RX_VMDQ_ONLY or ETH_MQ_RX_NONE */
970 /* if nothing mq mode configure, use default scheme */
971 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
972 if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
973 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
977 switch (dev_conf->txmode.mq_mode) {
978 case ETH_MQ_TX_VMDQ_DCB:
979 /* DCB VMDQ in SRIOV mode, not implement yet */
980 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
982 "unsupported VMDQ mq_mode tx %u\n",
983 port_id, dev_conf->txmode.mq_mode);
985 default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
986 /* if nothing mq mode configure, use default scheme */
987 dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
991 /* check valid queue number */
992 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
993 (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
994 PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
995 "queue number must less equal to %d\n",
997 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
1001 /* For vmdb+dcb mode check our configuration before we go further */
1002 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB) {
1003 const struct rte_eth_vmdq_dcb_conf *conf;
1005 if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
1006 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
1008 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
1011 conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
1012 if (!(conf->nb_queue_pools == ETH_16_POOLS ||
1013 conf->nb_queue_pools == ETH_32_POOLS)) {
1014 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
1015 "nb_queue_pools must be %d or %d\n",
1016 port_id, ETH_16_POOLS, ETH_32_POOLS);
1020 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
1021 const struct rte_eth_vmdq_dcb_tx_conf *conf;
1023 if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
1024 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
1026 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
1029 conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
1030 if (!(conf->nb_queue_pools == ETH_16_POOLS ||
1031 conf->nb_queue_pools == ETH_32_POOLS)) {
1032 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
1033 "nb_queue_pools != %d or nb_queue_pools "
1035 port_id, ETH_16_POOLS, ETH_32_POOLS);
1040 /* For DCB mode check our configuration before we go further */
1041 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) {
1042 const struct rte_eth_dcb_rx_conf *conf;
1044 if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
1045 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
1047 port_id, ETH_DCB_NUM_QUEUES);
1050 conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
1051 if (!(conf->nb_tcs == ETH_4_TCS ||
1052 conf->nb_tcs == ETH_8_TCS)) {
1053 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
1054 "nb_tcs != %d or nb_tcs "
1056 port_id, ETH_4_TCS, ETH_8_TCS);
1061 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
1062 const struct rte_eth_dcb_tx_conf *conf;
1064 if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
1065 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
1067 port_id, ETH_DCB_NUM_QUEUES);
1070 conf = &(dev_conf->tx_adv_conf.dcb_tx_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);
1085 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
1086 const struct rte_eth_conf *dev_conf)
1088 struct rte_eth_dev *dev;
1089 struct rte_eth_dev_info dev_info;
1092 /* This function is only safe when called from the primary process
1093 * in a multi-process setup*/
1094 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1096 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1098 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
1100 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
1101 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
1105 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
1107 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
1108 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
1112 dev = &rte_eth_devices[port_id];
1114 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1115 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
1117 if (dev->data->dev_started) {
1119 "port %d must be stopped to allow configuration\n", port_id);
1124 * Check that the numbers of RX and TX queues are not greater
1125 * than the maximum number of RX and TX queues supported by the
1126 * configured device.
1128 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
1129 if (nb_rx_q > dev_info.max_rx_queues) {
1130 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
1131 port_id, nb_rx_q, dev_info.max_rx_queues);
1135 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
1139 if (nb_tx_q > dev_info.max_tx_queues) {
1140 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
1141 port_id, nb_tx_q, dev_info.max_tx_queues);
1145 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
1149 /* Copy the dev_conf parameter into the dev structure */
1150 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
1153 * If link state interrupt is enabled, check that the
1154 * device supports it.
1156 if (dev_conf->intr_conf.lsc == 1) {
1157 const struct rte_pci_driver *pci_drv = &dev->driver->pci_drv;
1159 if (!(pci_drv->drv_flags & RTE_PCI_DRV_INTR_LSC)) {
1160 PMD_DEBUG_TRACE("driver %s does not support lsc\n",
1167 * If jumbo frames are enabled, check that the maximum RX packet
1168 * length is supported by the configured device.
1170 if (dev_conf->rxmode.jumbo_frame == 1) {
1171 if (dev_conf->rxmode.max_rx_pkt_len >
1172 dev_info.max_rx_pktlen) {
1173 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
1174 " > max valid value %u\n",
1176 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
1177 (unsigned)dev_info.max_rx_pktlen);
1179 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
1180 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
1181 " < min valid value %u\n",
1183 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
1184 (unsigned)ETHER_MIN_LEN);
1188 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
1189 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
1190 /* Use default value */
1191 dev->data->dev_conf.rxmode.max_rx_pkt_len =
1195 /* multiple queue mode checking */
1196 diag = rte_eth_dev_check_mq_mode(port_id, nb_rx_q, nb_tx_q, dev_conf);
1198 PMD_DEBUG_TRACE("port%d rte_eth_dev_check_mq_mode = %d\n",
1204 * Setup new number of RX/TX queues and reconfigure device.
1206 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
1208 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
1213 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
1215 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
1217 rte_eth_dev_rx_queue_config(dev, 0);
1221 diag = (*dev->dev_ops->dev_configure)(dev);
1223 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
1225 rte_eth_dev_rx_queue_config(dev, 0);
1226 rte_eth_dev_tx_queue_config(dev, 0);
1234 rte_eth_dev_config_restore(uint8_t port_id)
1236 struct rte_eth_dev *dev;
1237 struct rte_eth_dev_info dev_info;
1238 struct ether_addr addr;
1242 dev = &rte_eth_devices[port_id];
1244 rte_eth_dev_info_get(port_id, &dev_info);
1246 if (RTE_ETH_DEV_SRIOV(dev).active)
1247 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
1249 /* replay MAC address configuration */
1250 for (i = 0; i < dev_info.max_mac_addrs; i++) {
1251 addr = dev->data->mac_addrs[i];
1253 /* skip zero address */
1254 if (is_zero_ether_addr(&addr))
1257 /* add address to the hardware */
1258 if (*dev->dev_ops->mac_addr_add &&
1259 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
1260 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
1262 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
1264 /* exit the loop but not return an error */
1269 /* replay promiscuous configuration */
1270 if (rte_eth_promiscuous_get(port_id) == 1)
1271 rte_eth_promiscuous_enable(port_id);
1272 else if (rte_eth_promiscuous_get(port_id) == 0)
1273 rte_eth_promiscuous_disable(port_id);
1275 /* replay all multicast configuration */
1276 if (rte_eth_allmulticast_get(port_id) == 1)
1277 rte_eth_allmulticast_enable(port_id);
1278 else if (rte_eth_allmulticast_get(port_id) == 0)
1279 rte_eth_allmulticast_disable(port_id);
1283 rte_eth_dev_start(uint8_t port_id)
1285 struct rte_eth_dev *dev;
1288 /* This function is only safe when called from the primary process
1289 * in a multi-process setup*/
1290 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1292 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1294 dev = &rte_eth_devices[port_id];
1296 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1298 if (dev->data->dev_started != 0) {
1299 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1300 " already started\n",
1305 diag = (*dev->dev_ops->dev_start)(dev);
1307 dev->data->dev_started = 1;
1311 rte_eth_dev_config_restore(port_id);
1313 if (dev->data->dev_conf.intr_conf.lsc != 0) {
1314 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1315 (*dev->dev_ops->link_update)(dev, 0);
1321 rte_eth_dev_stop(uint8_t port_id)
1323 struct rte_eth_dev *dev;
1325 /* This function is only safe when called from the primary process
1326 * in a multi-process setup*/
1327 PROC_PRIMARY_OR_RET();
1329 VALID_PORTID_OR_RET(port_id);
1330 dev = &rte_eth_devices[port_id];
1332 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1334 if (dev->data->dev_started == 0) {
1335 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1336 " already stopped\n",
1341 dev->data->dev_started = 0;
1342 (*dev->dev_ops->dev_stop)(dev);
1346 rte_eth_dev_set_link_up(uint8_t port_id)
1348 struct rte_eth_dev *dev;
1350 /* This function is only safe when called from the primary process
1351 * in a multi-process setup*/
1352 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1354 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1356 dev = &rte_eth_devices[port_id];
1358 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1359 return (*dev->dev_ops->dev_set_link_up)(dev);
1363 rte_eth_dev_set_link_down(uint8_t port_id)
1365 struct rte_eth_dev *dev;
1367 /* This function is only safe when called from the primary process
1368 * in a multi-process setup*/
1369 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1371 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1373 dev = &rte_eth_devices[port_id];
1375 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1376 return (*dev->dev_ops->dev_set_link_down)(dev);
1380 rte_eth_dev_close(uint8_t port_id)
1382 struct rte_eth_dev *dev;
1384 /* This function is only safe when called from the primary process
1385 * in a multi-process setup*/
1386 PROC_PRIMARY_OR_RET();
1388 VALID_PORTID_OR_RET(port_id);
1389 dev = &rte_eth_devices[port_id];
1391 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1392 dev->data->dev_started = 0;
1393 (*dev->dev_ops->dev_close)(dev);
1397 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1398 uint16_t nb_rx_desc, unsigned int socket_id,
1399 const struct rte_eth_rxconf *rx_conf,
1400 struct rte_mempool *mp)
1403 uint32_t mbp_buf_size;
1404 struct rte_eth_dev *dev;
1405 struct rte_eth_dev_info dev_info;
1407 /* This function is only safe when called from the primary process
1408 * in a multi-process setup*/
1409 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1411 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1413 dev = &rte_eth_devices[port_id];
1414 if (rx_queue_id >= dev->data->nb_rx_queues) {
1415 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1419 if (dev->data->dev_started) {
1421 "port %d must be stopped to allow configuration\n", port_id);
1425 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1426 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1429 * Check the size of the mbuf data buffer.
1430 * This value must be provided in the private data of the memory pool.
1431 * First check that the memory pool has a valid private data.
1433 rte_eth_dev_info_get(port_id, &dev_info);
1434 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1435 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1436 mp->name, (int) mp->private_data_size,
1437 (int) sizeof(struct rte_pktmbuf_pool_private));
1440 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1442 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1443 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1444 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1448 (int)(RTE_PKTMBUF_HEADROOM +
1449 dev_info.min_rx_bufsize),
1450 (int)RTE_PKTMBUF_HEADROOM,
1451 (int)dev_info.min_rx_bufsize);
1455 if (rx_conf == NULL)
1456 rx_conf = &dev_info.default_rxconf;
1458 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1459 socket_id, rx_conf, mp);
1461 if (!dev->data->min_rx_buf_size ||
1462 dev->data->min_rx_buf_size > mbp_buf_size)
1463 dev->data->min_rx_buf_size = mbp_buf_size;
1470 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1471 uint16_t nb_tx_desc, unsigned int socket_id,
1472 const struct rte_eth_txconf *tx_conf)
1474 struct rte_eth_dev *dev;
1475 struct rte_eth_dev_info dev_info;
1477 /* This function is only safe when called from the primary process
1478 * in a multi-process setup*/
1479 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1481 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1483 dev = &rte_eth_devices[port_id];
1484 if (tx_queue_id >= dev->data->nb_tx_queues) {
1485 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1489 if (dev->data->dev_started) {
1491 "port %d must be stopped to allow configuration\n", port_id);
1495 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1496 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1498 rte_eth_dev_info_get(port_id, &dev_info);
1500 if (tx_conf == NULL)
1501 tx_conf = &dev_info.default_txconf;
1503 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1504 socket_id, tx_conf);
1508 rte_eth_promiscuous_enable(uint8_t port_id)
1510 struct rte_eth_dev *dev;
1512 VALID_PORTID_OR_RET(port_id);
1513 dev = &rte_eth_devices[port_id];
1515 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1516 (*dev->dev_ops->promiscuous_enable)(dev);
1517 dev->data->promiscuous = 1;
1521 rte_eth_promiscuous_disable(uint8_t port_id)
1523 struct rte_eth_dev *dev;
1525 VALID_PORTID_OR_RET(port_id);
1526 dev = &rte_eth_devices[port_id];
1528 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1529 dev->data->promiscuous = 0;
1530 (*dev->dev_ops->promiscuous_disable)(dev);
1534 rte_eth_promiscuous_get(uint8_t port_id)
1536 struct rte_eth_dev *dev;
1538 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1540 dev = &rte_eth_devices[port_id];
1541 return dev->data->promiscuous;
1545 rte_eth_allmulticast_enable(uint8_t port_id)
1547 struct rte_eth_dev *dev;
1549 VALID_PORTID_OR_RET(port_id);
1550 dev = &rte_eth_devices[port_id];
1552 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1553 (*dev->dev_ops->allmulticast_enable)(dev);
1554 dev->data->all_multicast = 1;
1558 rte_eth_allmulticast_disable(uint8_t port_id)
1560 struct rte_eth_dev *dev;
1562 VALID_PORTID_OR_RET(port_id);
1563 dev = &rte_eth_devices[port_id];
1565 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1566 dev->data->all_multicast = 0;
1567 (*dev->dev_ops->allmulticast_disable)(dev);
1571 rte_eth_allmulticast_get(uint8_t port_id)
1573 struct rte_eth_dev *dev;
1575 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1577 dev = &rte_eth_devices[port_id];
1578 return dev->data->all_multicast;
1582 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1583 struct rte_eth_link *link)
1585 struct rte_eth_link *dst = link;
1586 struct rte_eth_link *src = &(dev->data->dev_link);
1588 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1589 *(uint64_t *)src) == 0)
1596 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1598 struct rte_eth_dev *dev;
1600 VALID_PORTID_OR_RET(port_id);
1601 dev = &rte_eth_devices[port_id];
1603 if (dev->data->dev_conf.intr_conf.lsc != 0)
1604 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1606 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1607 (*dev->dev_ops->link_update)(dev, 1);
1608 *eth_link = dev->data->dev_link;
1613 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1615 struct rte_eth_dev *dev;
1617 VALID_PORTID_OR_RET(port_id);
1618 dev = &rte_eth_devices[port_id];
1620 if (dev->data->dev_conf.intr_conf.lsc != 0)
1621 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1623 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1624 (*dev->dev_ops->link_update)(dev, 0);
1625 *eth_link = dev->data->dev_link;
1630 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1632 struct rte_eth_dev *dev;
1634 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1636 dev = &rte_eth_devices[port_id];
1637 memset(stats, 0, sizeof(*stats));
1639 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1640 (*dev->dev_ops->stats_get)(dev, stats);
1641 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1646 rte_eth_stats_reset(uint8_t port_id)
1648 struct rte_eth_dev *dev;
1650 VALID_PORTID_OR_RET(port_id);
1651 dev = &rte_eth_devices[port_id];
1653 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1654 (*dev->dev_ops->stats_reset)(dev);
1657 /* retrieve ethdev extended statistics */
1659 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1662 struct rte_eth_stats eth_stats;
1663 struct rte_eth_dev *dev;
1664 unsigned count, i, q;
1665 uint64_t val, *stats_ptr;
1667 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1669 dev = &rte_eth_devices[port_id];
1671 /* implemented by the driver */
1672 if (dev->dev_ops->xstats_get != NULL)
1673 return (*dev->dev_ops->xstats_get)(dev, xstats, n);
1675 /* else, return generic statistics */
1676 count = RTE_NB_STATS;
1677 count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
1678 count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
1682 /* now fill the xstats structure */
1685 rte_eth_stats_get(port_id, ð_stats);
1688 for (i = 0; i < RTE_NB_STATS; i++) {
1689 stats_ptr = RTE_PTR_ADD(ð_stats,
1690 rte_stats_strings[i].offset);
1692 snprintf(xstats[count].name, sizeof(xstats[count].name),
1693 "%s", rte_stats_strings[i].name);
1694 xstats[count++].value = val;
1698 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1699 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1700 stats_ptr = RTE_PTR_ADD(ð_stats,
1701 rte_rxq_stats_strings[i].offset +
1702 q * sizeof(uint64_t));
1704 snprintf(xstats[count].name, sizeof(xstats[count].name),
1705 "rx_queue_%u_%s", q,
1706 rte_rxq_stats_strings[i].name);
1707 xstats[count++].value = val;
1712 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1713 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1714 stats_ptr = RTE_PTR_ADD(ð_stats,
1715 rte_txq_stats_strings[i].offset +
1716 q * sizeof(uint64_t));
1718 snprintf(xstats[count].name, sizeof(xstats[count].name),
1719 "tx_queue_%u_%s", q,
1720 rte_txq_stats_strings[i].name);
1721 xstats[count++].value = val;
1728 /* reset ethdev extended statistics */
1730 rte_eth_xstats_reset(uint8_t port_id)
1732 struct rte_eth_dev *dev;
1734 VALID_PORTID_OR_RET(port_id);
1735 dev = &rte_eth_devices[port_id];
1737 /* implemented by the driver */
1738 if (dev->dev_ops->xstats_reset != NULL) {
1739 (*dev->dev_ops->xstats_reset)(dev);
1743 /* fallback to default */
1744 rte_eth_stats_reset(port_id);
1748 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1751 struct rte_eth_dev *dev;
1753 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1755 dev = &rte_eth_devices[port_id];
1757 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1758 return (*dev->dev_ops->queue_stats_mapping_set)
1759 (dev, queue_id, stat_idx, is_rx);
1764 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1767 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1773 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1776 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1782 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1784 struct rte_eth_dev *dev;
1786 VALID_PORTID_OR_RET(port_id);
1787 dev = &rte_eth_devices[port_id];
1789 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1791 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1792 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1793 dev_info->pci_dev = dev->pci_dev;
1795 dev_info->driver_name = dev->driver->pci_drv.name;
1799 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1801 struct rte_eth_dev *dev;
1803 VALID_PORTID_OR_RET(port_id);
1804 dev = &rte_eth_devices[port_id];
1805 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1810 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1812 struct rte_eth_dev *dev;
1814 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1816 dev = &rte_eth_devices[port_id];
1817 *mtu = dev->data->mtu;
1822 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1825 struct rte_eth_dev *dev;
1827 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1828 dev = &rte_eth_devices[port_id];
1829 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1831 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1833 dev->data->mtu = mtu;
1839 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1841 struct rte_eth_dev *dev;
1843 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1844 dev = &rte_eth_devices[port_id];
1845 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1846 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1850 if (vlan_id > 4095) {
1851 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1852 port_id, (unsigned) vlan_id);
1855 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1857 return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1861 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1863 struct rte_eth_dev *dev;
1865 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1866 dev = &rte_eth_devices[port_id];
1867 if (rx_queue_id >= dev->data->nb_rx_queues) {
1868 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1872 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1873 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1879 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1881 struct rte_eth_dev *dev;
1883 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1884 dev = &rte_eth_devices[port_id];
1885 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1886 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1892 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1894 struct rte_eth_dev *dev;
1899 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1900 dev = &rte_eth_devices[port_id];
1902 /*check which option changed by application*/
1903 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1904 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1906 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1907 mask |= ETH_VLAN_STRIP_MASK;
1910 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1911 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1913 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1914 mask |= ETH_VLAN_FILTER_MASK;
1917 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1918 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1920 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1921 mask |= ETH_VLAN_EXTEND_MASK;
1928 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1929 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1935 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1937 struct rte_eth_dev *dev;
1940 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1941 dev = &rte_eth_devices[port_id];
1943 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1944 ret |= ETH_VLAN_STRIP_OFFLOAD;
1946 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1947 ret |= ETH_VLAN_FILTER_OFFLOAD;
1949 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1950 ret |= ETH_VLAN_EXTEND_OFFLOAD;
1956 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1958 struct rte_eth_dev *dev;
1960 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1961 dev = &rte_eth_devices[port_id];
1962 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1963 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1969 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1970 struct rte_fdir_filter *fdir_filter,
1973 struct rte_eth_dev *dev;
1975 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1976 dev = &rte_eth_devices[port_id];
1978 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1979 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1980 port_id, dev->data->dev_conf.fdir_conf.mode);
1984 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1985 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1986 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1987 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
1988 "None l4type, source & destinations ports "
1989 "should be null!\n");
1993 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1994 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1999 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
2000 struct rte_fdir_filter *fdir_filter,
2003 struct rte_eth_dev *dev;
2005 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2006 dev = &rte_eth_devices[port_id];
2008 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
2009 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2010 port_id, dev->data->dev_conf.fdir_conf.mode);
2014 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2015 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2016 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2017 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
2018 "None l4type, source & destinations ports "
2019 "should be null!\n");
2023 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
2024 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
2030 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
2031 struct rte_fdir_filter *fdir_filter)
2033 struct rte_eth_dev *dev;
2035 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2036 dev = &rte_eth_devices[port_id];
2038 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
2039 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2040 port_id, dev->data->dev_conf.fdir_conf.mode);
2044 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2045 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2046 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2047 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
2048 "None l4type source & destinations ports "
2049 "should be null!\n");
2053 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
2054 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
2058 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
2060 struct rte_eth_dev *dev;
2062 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2063 dev = &rte_eth_devices[port_id];
2064 if (!(dev->data->dev_conf.fdir_conf.mode)) {
2065 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
2069 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
2071 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
2076 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
2077 struct rte_fdir_filter *fdir_filter,
2078 uint16_t soft_id, uint8_t queue,
2081 struct rte_eth_dev *dev;
2083 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2084 dev = &rte_eth_devices[port_id];
2086 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
2087 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2088 port_id, dev->data->dev_conf.fdir_conf.mode);
2092 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2093 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2094 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2095 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
2096 "None l4type, source & destinations ports "
2097 "should be null!\n");
2101 /* For now IPv6 is not supported with perfect filter */
2102 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2105 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
2106 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
2112 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
2113 struct rte_fdir_filter *fdir_filter,
2114 uint16_t soft_id, uint8_t queue,
2117 struct rte_eth_dev *dev;
2119 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2120 dev = &rte_eth_devices[port_id];
2122 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
2123 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2124 port_id, dev->data->dev_conf.fdir_conf.mode);
2128 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2129 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2130 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2131 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
2132 "None l4type, source & destinations ports "
2133 "should be null!\n");
2137 /* For now IPv6 is not supported with perfect filter */
2138 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2141 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
2142 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
2143 soft_id, queue, drop);
2147 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
2148 struct rte_fdir_filter *fdir_filter,
2151 struct rte_eth_dev *dev;
2153 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2154 dev = &rte_eth_devices[port_id];
2156 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
2157 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2158 port_id, dev->data->dev_conf.fdir_conf.mode);
2162 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2163 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2164 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2165 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and "
2166 "None l4type, source & destinations ports "
2167 "should be null!\n");
2171 /* For now IPv6 is not supported with perfect filter */
2172 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2175 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
2176 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
2181 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
2183 struct rte_eth_dev *dev;
2185 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2186 dev = &rte_eth_devices[port_id];
2187 if (!(dev->data->dev_conf.fdir_conf.mode)) {
2188 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
2192 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
2193 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
2197 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2199 struct rte_eth_dev *dev;
2201 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2202 dev = &rte_eth_devices[port_id];
2203 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2204 memset(fc_conf, 0, sizeof(*fc_conf));
2205 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
2209 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2211 struct rte_eth_dev *dev;
2213 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2214 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2215 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2219 dev = &rte_eth_devices[port_id];
2220 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2221 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
2225 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
2227 struct rte_eth_dev *dev;
2229 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2230 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2231 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2235 dev = &rte_eth_devices[port_id];
2236 /* High water, low water validation are device specific */
2237 if (*dev->dev_ops->priority_flow_ctrl_set)
2238 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
2243 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2251 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
2252 PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
2253 RTE_RETA_GROUP_SIZE);
2257 num = reta_size / RTE_RETA_GROUP_SIZE;
2258 for (i = 0; i < num; i++) {
2259 if (reta_conf[i].mask)
2267 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2271 uint16_t i, idx, shift;
2277 PMD_DEBUG_TRACE("No receive queue is available\n");
2281 for (i = 0; i < reta_size; i++) {
2282 idx = i / RTE_RETA_GROUP_SIZE;
2283 shift = i % RTE_RETA_GROUP_SIZE;
2284 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2285 (reta_conf[idx].reta[shift] >= max_rxq)) {
2286 PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2287 "the maximum rxq index: %u\n", idx, shift,
2288 reta_conf[idx].reta[shift], max_rxq);
2297 rte_eth_dev_rss_reta_update(uint8_t port_id,
2298 struct rte_eth_rss_reta_entry64 *reta_conf,
2301 struct rte_eth_dev *dev;
2304 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2305 /* Check mask bits */
2306 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2310 dev = &rte_eth_devices[port_id];
2312 /* Check entry value */
2313 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2314 dev->data->nb_rx_queues);
2318 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2319 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2323 rte_eth_dev_rss_reta_query(uint8_t port_id,
2324 struct rte_eth_rss_reta_entry64 *reta_conf,
2327 struct rte_eth_dev *dev;
2330 if (port_id >= nb_ports) {
2331 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2335 /* Check mask bits */
2336 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2340 dev = &rte_eth_devices[port_id];
2341 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2342 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2346 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2348 struct rte_eth_dev *dev;
2349 uint16_t rss_hash_protos;
2351 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2352 rss_hash_protos = rss_conf->rss_hf;
2353 if ((rss_hash_protos != 0) &&
2354 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2355 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2359 dev = &rte_eth_devices[port_id];
2360 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2361 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2365 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2366 struct rte_eth_rss_conf *rss_conf)
2368 struct rte_eth_dev *dev;
2370 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2371 dev = &rte_eth_devices[port_id];
2372 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2373 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2377 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
2378 struct rte_eth_udp_tunnel *udp_tunnel)
2380 struct rte_eth_dev *dev;
2382 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2383 if (udp_tunnel == NULL) {
2384 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2388 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2389 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2393 dev = &rte_eth_devices[port_id];
2394 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
2395 return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
2399 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
2400 struct rte_eth_udp_tunnel *udp_tunnel)
2402 struct rte_eth_dev *dev;
2404 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2405 dev = &rte_eth_devices[port_id];
2407 if (udp_tunnel == NULL) {
2408 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2412 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2413 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2417 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2418 return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2422 rte_eth_led_on(uint8_t port_id)
2424 struct rte_eth_dev *dev;
2426 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2427 dev = &rte_eth_devices[port_id];
2428 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2429 return (*dev->dev_ops->dev_led_on)(dev);
2433 rte_eth_led_off(uint8_t port_id)
2435 struct rte_eth_dev *dev;
2437 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2438 dev = &rte_eth_devices[port_id];
2439 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2440 return (*dev->dev_ops->dev_led_off)(dev);
2444 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2448 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2450 struct rte_eth_dev_info dev_info;
2451 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2454 rte_eth_dev_info_get(port_id, &dev_info);
2456 for (i = 0; i < dev_info.max_mac_addrs; i++)
2457 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2463 static const struct ether_addr null_mac_addr;
2466 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2469 struct rte_eth_dev *dev;
2473 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2474 dev = &rte_eth_devices[port_id];
2475 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2477 if (is_zero_ether_addr(addr)) {
2478 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2482 if (pool >= ETH_64_POOLS) {
2483 PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2487 index = get_mac_addr_index(port_id, addr);
2489 index = get_mac_addr_index(port_id, &null_mac_addr);
2491 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2496 pool_mask = dev->data->mac_pool_sel[index];
2498 /* Check if both MAC address and pool is already there, and do nothing */
2499 if (pool_mask & (1ULL << pool))
2504 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2506 /* Update address in NIC data structure */
2507 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2509 /* Update pool bitmap in NIC data structure */
2510 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2516 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2518 struct rte_eth_dev *dev;
2521 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2522 dev = &rte_eth_devices[port_id];
2523 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2525 index = get_mac_addr_index(port_id, addr);
2527 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2529 } else if (index < 0)
2530 return 0; /* Do nothing if address wasn't found */
2533 (*dev->dev_ops->mac_addr_remove)(dev, index);
2535 /* Update address in NIC data structure */
2536 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2538 /* reset pool bitmap */
2539 dev->data->mac_pool_sel[index] = 0;
2545 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2546 uint16_t rx_mode, uint8_t on)
2549 struct rte_eth_dev *dev;
2550 struct rte_eth_dev_info dev_info;
2552 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2554 dev = &rte_eth_devices[port_id];
2555 rte_eth_dev_info_get(port_id, &dev_info);
2557 num_vfs = dev_info.max_vfs;
2559 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2564 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2567 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2568 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2572 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2576 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2578 struct rte_eth_dev_info dev_info;
2579 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2582 rte_eth_dev_info_get(port_id, &dev_info);
2583 if (!dev->data->hash_mac_addrs)
2586 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2587 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2588 ETHER_ADDR_LEN) == 0)
2595 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2600 struct rte_eth_dev *dev;
2602 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2604 dev = &rte_eth_devices[port_id];
2605 if (is_zero_ether_addr(addr)) {
2606 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2611 index = get_hash_mac_addr_index(port_id, addr);
2612 /* Check if it's already there, and do nothing */
2613 if ((index >= 0) && (on))
2618 PMD_DEBUG_TRACE("port %d: the MAC address was not "
2619 "set in UTA\n", port_id);
2623 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2625 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2631 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2632 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2634 /* Update address in NIC data structure */
2636 ether_addr_copy(addr,
2637 &dev->data->hash_mac_addrs[index]);
2639 ether_addr_copy(&null_mac_addr,
2640 &dev->data->hash_mac_addrs[index]);
2647 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2649 struct rte_eth_dev *dev;
2651 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2653 dev = &rte_eth_devices[port_id];
2655 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2656 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2660 rte_eth_dev_set_vf_rx(uint8_t port_id, uint16_t vf, uint8_t on)
2663 struct rte_eth_dev *dev;
2664 struct rte_eth_dev_info dev_info;
2666 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2668 dev = &rte_eth_devices[port_id];
2669 rte_eth_dev_info_get(port_id, &dev_info);
2671 num_vfs = dev_info.max_vfs;
2673 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2677 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2678 return (*dev->dev_ops->set_vf_rx)(dev, vf, on);
2682 rte_eth_dev_set_vf_tx(uint8_t port_id, uint16_t vf, uint8_t on)
2685 struct rte_eth_dev *dev;
2686 struct rte_eth_dev_info dev_info;
2688 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2690 dev = &rte_eth_devices[port_id];
2691 rte_eth_dev_info_get(port_id, &dev_info);
2693 num_vfs = dev_info.max_vfs;
2695 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2699 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2700 return (*dev->dev_ops->set_vf_tx)(dev, vf, on);
2704 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2705 uint64_t vf_mask, uint8_t vlan_on)
2707 struct rte_eth_dev *dev;
2709 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2711 dev = &rte_eth_devices[port_id];
2713 if (vlan_id > ETHER_MAX_VLAN_ID) {
2714 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2720 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2724 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2725 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2729 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2732 struct rte_eth_dev *dev;
2733 struct rte_eth_dev_info dev_info;
2734 struct rte_eth_link link;
2736 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2738 dev = &rte_eth_devices[port_id];
2739 rte_eth_dev_info_get(port_id, &dev_info);
2740 link = dev->data->dev_link;
2742 if (queue_idx > dev_info.max_tx_queues) {
2743 PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2744 "invalid queue id=%d\n", port_id, queue_idx);
2748 if (tx_rate > link.link_speed) {
2749 PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2750 "bigger than link speed= %d\n",
2751 tx_rate, link.link_speed);
2755 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2756 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2759 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2762 struct rte_eth_dev *dev;
2763 struct rte_eth_dev_info dev_info;
2764 struct rte_eth_link link;
2769 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2771 dev = &rte_eth_devices[port_id];
2772 rte_eth_dev_info_get(port_id, &dev_info);
2773 link = dev->data->dev_link;
2775 if (vf > dev_info.max_vfs) {
2776 PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2777 "invalid vf id=%d\n", port_id, vf);
2781 if (tx_rate > link.link_speed) {
2782 PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2783 "bigger than link speed= %d\n",
2784 tx_rate, link.link_speed);
2788 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2789 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2793 rte_eth_mirror_rule_set(uint8_t port_id,
2794 struct rte_eth_mirror_conf *mirror_conf,
2795 uint8_t rule_id, uint8_t on)
2797 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2799 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2800 if (mirror_conf->rule_type == 0) {
2801 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2805 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2806 PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2811 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2812 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2813 (mirror_conf->pool_mask == 0)) {
2814 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2818 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2819 mirror_conf->vlan.vlan_mask == 0) {
2820 PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2824 dev = &rte_eth_devices[port_id];
2825 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2827 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2831 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2833 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2835 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2837 dev = &rte_eth_devices[port_id];
2838 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2840 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2843 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2845 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2846 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2848 struct rte_eth_dev *dev;
2850 VALID_PORTID_OR_ERR_RET(port_id, 0);
2852 dev = &rte_eth_devices[port_id];
2853 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);
2854 if (queue_id >= dev->data->nb_rx_queues) {
2855 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2858 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2863 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2864 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2866 struct rte_eth_dev *dev;
2868 VALID_PORTID_OR_ERR_RET(port_id, 0);
2870 dev = &rte_eth_devices[port_id];
2872 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0);
2873 if (queue_id >= dev->data->nb_tx_queues) {
2874 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2877 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2882 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2884 struct rte_eth_dev *dev;
2886 VALID_PORTID_OR_ERR_RET(port_id, 0);
2888 dev = &rte_eth_devices[port_id];
2889 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0);
2890 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2894 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2896 struct rte_eth_dev *dev;
2898 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2900 dev = &rte_eth_devices[port_id];
2901 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2902 return (*dev->dev_ops->rx_descriptor_done)(dev->data->rx_queues[queue_id],
2908 rte_eth_dev_callback_register(uint8_t port_id,
2909 enum rte_eth_event_type event,
2910 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2912 struct rte_eth_dev *dev;
2913 struct rte_eth_dev_callback *user_cb;
2918 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2920 dev = &rte_eth_devices[port_id];
2921 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2923 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2924 if (user_cb->cb_fn == cb_fn &&
2925 user_cb->cb_arg == cb_arg &&
2926 user_cb->event == event) {
2931 /* create a new callback. */
2932 if (user_cb == NULL &&
2933 (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2934 sizeof(struct rte_eth_dev_callback), 0))) {
2935 user_cb->cb_fn = cb_fn;
2936 user_cb->cb_arg = cb_arg;
2937 user_cb->event = event;
2938 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2941 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2942 return (user_cb == NULL) ? -ENOMEM : 0;
2946 rte_eth_dev_callback_unregister(uint8_t port_id,
2947 enum rte_eth_event_type event,
2948 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2951 struct rte_eth_dev *dev;
2952 struct rte_eth_dev_callback *cb, *next;
2957 VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2959 dev = &rte_eth_devices[port_id];
2960 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2963 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2965 next = TAILQ_NEXT(cb, next);
2967 if (cb->cb_fn != cb_fn || cb->event != event ||
2968 (cb->cb_arg != (void *)-1 &&
2969 cb->cb_arg != cb_arg))
2973 * if this callback is not executing right now,
2976 if (cb->active == 0) {
2977 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2984 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2989 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2990 enum rte_eth_event_type event)
2992 struct rte_eth_dev_callback *cb_lst;
2993 struct rte_eth_dev_callback dev_cb;
2995 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2996 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2997 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
3001 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3002 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
3004 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3007 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3009 #ifdef RTE_NIC_BYPASS
3010 int rte_eth_dev_bypass_init(uint8_t port_id)
3012 struct rte_eth_dev *dev;
3014 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3016 dev = &rte_eth_devices[port_id];
3017 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
3018 (*dev->dev_ops->bypass_init)(dev);
3023 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
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_state_show, -ENOTSUP);
3031 (*dev->dev_ops->bypass_state_show)(dev, state);
3036 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_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_set, -ENOTSUP);
3044 (*dev->dev_ops->bypass_state_set)(dev, new_state);
3049 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *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_show, -ENOTSUP);
3057 (*dev->dev_ops->bypass_event_show)(dev, event, state);
3062 rte_eth_dev_bypass_event_store(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];
3070 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
3071 (*dev->dev_ops->bypass_event_set)(dev, event, state);
3076 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
3078 struct rte_eth_dev *dev;
3080 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3082 dev = &rte_eth_devices[port_id];
3084 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
3085 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
3090 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
3092 struct rte_eth_dev *dev;
3094 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3096 dev = &rte_eth_devices[port_id];
3098 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
3099 (*dev->dev_ops->bypass_ver_show)(dev, ver);
3104 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
3106 struct rte_eth_dev *dev;
3108 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3110 dev = &rte_eth_devices[port_id];
3112 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
3113 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
3118 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
3120 struct rte_eth_dev *dev;
3122 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3124 dev = &rte_eth_devices[port_id];
3126 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
3127 (*dev->dev_ops->bypass_wd_reset)(dev);
3133 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
3135 struct rte_eth_dev *dev;
3137 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3139 dev = &rte_eth_devices[port_id];
3140 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3141 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3142 RTE_ETH_FILTER_NOP, NULL);
3146 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
3147 enum rte_filter_op filter_op, void *arg)
3149 struct rte_eth_dev *dev;
3151 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3153 dev = &rte_eth_devices[port_id];
3154 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3155 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
3159 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
3160 rte_rx_callback_fn fn, void *user_param)
3162 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3163 rte_errno = ENOTSUP;
3166 /* check input parameters */
3167 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3168 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3173 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3181 cb->param = user_param;
3183 /* Add the callbacks in fifo order. */
3184 struct rte_eth_rxtx_callback *tail =
3185 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3188 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3200 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
3201 rte_tx_callback_fn fn, void *user_param)
3203 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3204 rte_errno = ENOTSUP;
3207 /* check input parameters */
3208 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3209 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3214 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3222 cb->param = user_param;
3224 /* Add the callbacks in fifo order. */
3225 struct rte_eth_rxtx_callback *tail =
3226 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3229 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3241 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3242 struct rte_eth_rxtx_callback *user_cb)
3244 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3247 /* Check input parameters. */
3248 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
3249 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3253 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3254 struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
3255 struct rte_eth_rxtx_callback *prev_cb;
3257 /* Reset head pointer and remove user cb if first in the list. */
3258 if (cb == user_cb) {
3259 dev->post_rx_burst_cbs[queue_id] = user_cb->next;
3263 /* Remove the user cb from the callback list. */
3268 if (cb == user_cb) {
3269 prev_cb->next = user_cb->next;
3273 } while (cb != NULL);
3275 /* Callback wasn't found. */
3280 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3281 struct rte_eth_rxtx_callback *user_cb)
3283 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3286 /* Check input parameters. */
3287 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
3288 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3292 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3293 struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
3294 struct rte_eth_rxtx_callback *prev_cb;
3296 /* Reset head pointer and remove user cb if first in the list. */
3297 if (cb == user_cb) {
3298 dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
3302 /* Remove the user cb from the callback list. */
3307 if (cb == user_cb) {
3308 prev_cb->next = user_cb->next;
3312 } while (cb != NULL);
3314 /* Callback wasn't found. */
3319 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3320 struct ether_addr *mc_addr_set,
3321 uint32_t nb_mc_addr)
3323 struct rte_eth_dev *dev;
3325 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3327 dev = &rte_eth_devices[port_id];
3328 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3329 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3333 rte_eth_timesync_enable(uint8_t port_id)
3335 struct rte_eth_dev *dev;
3337 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3338 dev = &rte_eth_devices[port_id];
3340 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3341 return (*dev->dev_ops->timesync_enable)(dev);
3345 rte_eth_timesync_disable(uint8_t port_id)
3347 struct rte_eth_dev *dev;
3349 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3350 dev = &rte_eth_devices[port_id];
3352 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3353 return (*dev->dev_ops->timesync_disable)(dev);
3357 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3360 struct rte_eth_dev *dev;
3362 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3363 dev = &rte_eth_devices[port_id];
3365 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3366 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3370 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3372 struct rte_eth_dev *dev;
3374 VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3375 dev = &rte_eth_devices[port_id];
3377 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3378 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);