4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/types.h>
35 #include <sys/queue.h>
44 #include <netinet/in.h>
46 #include <rte_byteorder.h>
48 #include <rte_debug.h>
49 #include <rte_interrupts.h>
51 #include <rte_memory.h>
52 #include <rte_memcpy.h>
53 #include <rte_memzone.h>
54 #include <rte_launch.h>
56 #include <rte_per_lcore.h>
57 #include <rte_lcore.h>
58 #include <rte_atomic.h>
59 #include <rte_branch_prediction.h>
60 #include <rte_common.h>
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 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
73 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
74 static struct rte_eth_dev_data *rte_eth_dev_data;
75 static uint8_t nb_ports;
77 /* spinlock for eth device callbacks */
78 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
80 /* spinlock for add/remove rx callbacks */
81 static rte_spinlock_t rte_eth_rx_cb_lock = RTE_SPINLOCK_INITIALIZER;
83 /* spinlock for add/remove tx callbacks */
84 static rte_spinlock_t rte_eth_tx_cb_lock = RTE_SPINLOCK_INITIALIZER;
86 /* store statistics names and its offset in stats structure */
87 struct rte_eth_xstats_name_off {
88 char name[RTE_ETH_XSTATS_NAME_SIZE];
92 static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
93 {"rx_good_packets", offsetof(struct rte_eth_stats, ipackets)},
94 {"tx_good_packets", offsetof(struct rte_eth_stats, opackets)},
95 {"rx_good_bytes", offsetof(struct rte_eth_stats, ibytes)},
96 {"tx_good_bytes", offsetof(struct rte_eth_stats, obytes)},
97 {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
98 {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
99 {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats,
103 #define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
105 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
106 {"packets", offsetof(struct rte_eth_stats, q_ipackets)},
107 {"bytes", offsetof(struct rte_eth_stats, q_ibytes)},
108 {"errors", offsetof(struct rte_eth_stats, q_errors)},
111 #define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) / \
112 sizeof(rte_rxq_stats_strings[0]))
114 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
115 {"packets", offsetof(struct rte_eth_stats, q_opackets)},
116 {"bytes", offsetof(struct rte_eth_stats, q_obytes)},
118 #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) / \
119 sizeof(rte_txq_stats_strings[0]))
123 * The user application callback description.
125 * It contains callback address to be registered by user application,
126 * the pointer to the parameters for callback, and the event type.
128 struct rte_eth_dev_callback {
129 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
130 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
131 void *cb_arg; /**< Parameter for callback */
132 enum rte_eth_event_type event; /**< Interrupt event type */
133 uint32_t active; /**< Callback is executing */
147 rte_eth_dev_data_alloc(void)
149 const unsigned flags = 0;
150 const struct rte_memzone *mz;
152 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
153 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
154 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
155 rte_socket_id(), flags);
157 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
159 rte_panic("Cannot allocate memzone for ethernet port data\n");
161 rte_eth_dev_data = mz->addr;
162 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
163 memset(rte_eth_dev_data, 0,
164 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
168 rte_eth_dev_allocated(const char *name)
172 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
173 if ((rte_eth_devices[i].attached == DEV_ATTACHED) &&
174 strcmp(rte_eth_devices[i].data->name, name) == 0)
175 return &rte_eth_devices[i];
181 rte_eth_dev_find_free_port(void)
185 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
186 if (rte_eth_devices[i].attached == DEV_DETACHED)
189 return RTE_MAX_ETHPORTS;
193 rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
196 struct rte_eth_dev *eth_dev;
198 port_id = rte_eth_dev_find_free_port();
199 if (port_id == RTE_MAX_ETHPORTS) {
200 RTE_PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
204 if (rte_eth_dev_data == NULL)
205 rte_eth_dev_data_alloc();
207 if (rte_eth_dev_allocated(name) != NULL) {
208 RTE_PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n",
213 eth_dev = &rte_eth_devices[port_id];
214 eth_dev->data = &rte_eth_dev_data[port_id];
215 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
216 eth_dev->data->port_id = port_id;
217 eth_dev->attached = DEV_ATTACHED;
218 eth_dev->dev_type = type;
224 rte_eth_dev_create_unique_device_name(char *name, size_t size,
225 struct rte_pci_device *pci_dev)
229 ret = snprintf(name, size, "%d:%d.%d",
230 pci_dev->addr.bus, pci_dev->addr.devid,
231 pci_dev->addr.function);
238 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
243 eth_dev->attached = DEV_DETACHED;
249 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
250 struct rte_pci_device *pci_dev)
252 struct eth_driver *eth_drv;
253 struct rte_eth_dev *eth_dev;
254 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
258 eth_drv = (struct eth_driver *)pci_drv;
260 /* Create unique Ethernet device name using PCI address */
261 rte_eth_dev_create_unique_device_name(ethdev_name,
262 sizeof(ethdev_name), pci_dev);
264 eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
268 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
269 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
270 eth_drv->dev_private_size,
271 RTE_CACHE_LINE_SIZE);
272 if (eth_dev->data->dev_private == NULL)
273 rte_panic("Cannot allocate memzone for private port data\n");
275 eth_dev->pci_dev = pci_dev;
276 eth_dev->driver = eth_drv;
277 eth_dev->data->rx_mbuf_alloc_failed = 0;
279 /* init user callbacks */
280 TAILQ_INIT(&(eth_dev->link_intr_cbs));
283 * Set the default MTU.
285 eth_dev->data->mtu = ETHER_MTU;
287 /* Invoke PMD device initialization function */
288 diag = (*eth_drv->eth_dev_init)(eth_dev);
292 RTE_PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x) failed\n",
294 (unsigned) pci_dev->id.vendor_id,
295 (unsigned) pci_dev->id.device_id);
296 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
297 rte_free(eth_dev->data->dev_private);
298 rte_eth_dev_release_port(eth_dev);
303 rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
305 const struct eth_driver *eth_drv;
306 struct rte_eth_dev *eth_dev;
307 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
313 /* Create unique Ethernet device name using PCI address */
314 rte_eth_dev_create_unique_device_name(ethdev_name,
315 sizeof(ethdev_name), pci_dev);
317 eth_dev = rte_eth_dev_allocated(ethdev_name);
321 eth_drv = (const struct eth_driver *)pci_dev->driver;
323 /* Invoke PMD device uninit function */
324 if (*eth_drv->eth_dev_uninit) {
325 ret = (*eth_drv->eth_dev_uninit)(eth_dev);
330 /* free ether device */
331 rte_eth_dev_release_port(eth_dev);
333 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
334 rte_free(eth_dev->data->dev_private);
336 eth_dev->pci_dev = NULL;
337 eth_dev->driver = NULL;
338 eth_dev->data = NULL;
344 * Register an Ethernet [Poll Mode] driver.
346 * Function invoked by the initialization function of an Ethernet driver
347 * to simultaneously register itself as a PCI driver and as an Ethernet
349 * Invokes the rte_eal_pci_register() function to register the *pci_drv*
350 * structure embedded in the *eth_drv* structure, after having stored the
351 * address of the rte_eth_dev_init() function in the *devinit* field of
352 * the *pci_drv* structure.
353 * During the PCI probing phase, the rte_eth_dev_init() function is
354 * invoked for each PCI [Ethernet device] matching the embedded PCI
355 * identifiers provided by the driver.
358 rte_eth_driver_register(struct eth_driver *eth_drv)
360 eth_drv->pci_drv.devinit = rte_eth_dev_init;
361 eth_drv->pci_drv.devuninit = rte_eth_dev_uninit;
362 rte_eal_pci_register(ð_drv->pci_drv);
366 rte_eth_dev_is_valid_port(uint8_t port_id)
368 if (port_id >= RTE_MAX_ETHPORTS ||
369 rte_eth_devices[port_id].attached != DEV_ATTACHED)
376 rte_eth_dev_socket_id(uint8_t port_id)
378 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
379 return rte_eth_devices[port_id].data->numa_node;
383 rte_eth_dev_count(void)
388 static enum rte_eth_dev_type
389 rte_eth_dev_get_device_type(uint8_t port_id)
391 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, RTE_ETH_DEV_UNKNOWN);
392 return rte_eth_devices[port_id].dev_type;
396 rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr)
398 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
401 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
405 *addr = rte_eth_devices[port_id].pci_dev->addr;
410 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
414 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
417 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
421 /* shouldn't check 'rte_eth_devices[i].data',
422 * because it might be overwritten by VDEV PMD */
423 tmp = rte_eth_dev_data[port_id].name;
429 rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
434 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
438 *port_id = RTE_MAX_ETHPORTS;
440 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
443 rte_eth_dev_data[i].name, strlen(name))) {
454 rte_eth_dev_get_port_by_addr(const struct rte_pci_addr *addr, uint8_t *port_id)
457 struct rte_pci_device *pci_dev = NULL;
460 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
464 *port_id = RTE_MAX_ETHPORTS;
466 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
468 pci_dev = rte_eth_devices[i].pci_dev;
471 !rte_eal_compare_pci_addr(&pci_dev->addr, addr)) {
482 rte_eth_dev_is_detachable(uint8_t port_id)
486 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
488 switch (rte_eth_devices[port_id].data->kdrv) {
489 case RTE_KDRV_IGB_UIO:
490 case RTE_KDRV_UIO_GENERIC:
491 case RTE_KDRV_NIC_UIO:
498 dev_flags = rte_eth_devices[port_id].data->dev_flags;
499 if ((dev_flags & RTE_ETH_DEV_DETACHABLE) &&
500 (!(dev_flags & RTE_ETH_DEV_BONDED_SLAVE)))
506 /* attach the new physical device, then store port_id of the device */
508 rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
510 /* re-construct pci_device_list */
511 if (rte_eal_pci_scan())
513 /* Invoke probe func of the driver can handle the new device. */
514 if (rte_eal_pci_probe_one(addr))
517 if (rte_eth_dev_get_port_by_addr(addr, port_id))
525 /* detach the new physical device, then store pci_addr of the device */
527 rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
529 struct rte_pci_addr freed_addr;
530 struct rte_pci_addr vp;
532 /* get pci address by port id */
533 if (rte_eth_dev_get_addr_by_port(port_id, &freed_addr))
536 /* Zeroed pci addr means the port comes from virtual device */
537 vp.domain = vp.bus = vp.devid = vp.function = 0;
538 if (rte_eal_compare_pci_addr(&vp, &freed_addr) == 0)
541 /* invoke devuninit func of the pci driver,
542 * also remove the device from pci_device_list */
543 if (rte_eal_pci_detach(&freed_addr))
552 /* attach the new virtual device, then store port_id of the device */
554 rte_eth_dev_attach_vdev(const char *vdevargs, uint8_t *port_id)
556 char *name = NULL, *args = NULL;
559 /* parse vdevargs, then retrieve device name and args */
560 if (rte_eal_parse_devargs_str(vdevargs, &name, &args))
563 /* walk around dev_driver_list to find the driver of the device,
564 * then invoke probe function of the driver.
565 * rte_eal_vdev_init() updates port_id allocated after
568 if (rte_eal_vdev_init(name, args))
571 if (rte_eth_dev_get_port_by_name(name, port_id))
582 /* detach the new virtual device, then store the name of the device */
584 rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
586 char name[RTE_ETH_NAME_MAX_LEN];
588 /* get device name by port id */
589 if (rte_eth_dev_get_name_by_port(port_id, name))
591 /* walk around dev_driver_list to find the driver of the device,
592 * then invoke uninit function of the driver */
593 if (rte_eal_vdev_uninit(name))
596 strncpy(vdevname, name, sizeof(name));
602 /* attach the new device, then store port_id of the device */
604 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
606 struct rte_pci_addr addr;
609 if ((devargs == NULL) || (port_id == NULL)) {
614 if (eal_parse_pci_DomBDF(devargs, &addr) == 0) {
615 ret = rte_eth_dev_attach_pdev(&addr, port_id);
619 ret = rte_eth_dev_attach_vdev(devargs, port_id);
626 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
630 /* detach the device, then store the name of the device */
632 rte_eth_dev_detach(uint8_t port_id, char *name)
634 struct rte_pci_addr addr;
642 /* check whether the driver supports detach feature, or not */
643 if (rte_eth_dev_is_detachable(port_id))
646 if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {
647 ret = rte_eth_dev_get_addr_by_port(port_id, &addr);
651 ret = rte_eth_dev_detach_pdev(port_id, &addr);
655 snprintf(name, RTE_ETH_NAME_MAX_LEN,
657 addr.domain, addr.bus,
658 addr.devid, addr.function);
660 ret = rte_eth_dev_detach_vdev(port_id, name);
668 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
673 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
675 uint16_t old_nb_queues = dev->data->nb_rx_queues;
679 if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */
680 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
681 sizeof(dev->data->rx_queues[0]) * nb_queues,
682 RTE_CACHE_LINE_SIZE);
683 if (dev->data->rx_queues == NULL) {
684 dev->data->nb_rx_queues = 0;
687 } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */
688 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
690 rxq = dev->data->rx_queues;
692 for (i = nb_queues; i < old_nb_queues; i++)
693 (*dev->dev_ops->rx_queue_release)(rxq[i]);
694 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
695 RTE_CACHE_LINE_SIZE);
698 if (nb_queues > old_nb_queues) {
699 uint16_t new_qs = nb_queues - old_nb_queues;
701 memset(rxq + old_nb_queues, 0,
702 sizeof(rxq[0]) * new_qs);
705 dev->data->rx_queues = rxq;
707 } else if (dev->data->rx_queues != NULL && nb_queues == 0) {
708 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
710 rxq = dev->data->rx_queues;
712 for (i = nb_queues; i < old_nb_queues; i++)
713 (*dev->dev_ops->rx_queue_release)(rxq[i]);
715 dev->data->nb_rx_queues = nb_queues;
720 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
722 struct rte_eth_dev *dev;
724 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
726 dev = &rte_eth_devices[port_id];
727 if (rx_queue_id >= dev->data->nb_rx_queues) {
728 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
732 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
734 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
735 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
736 " already started\n",
737 rx_queue_id, port_id);
741 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
746 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
748 struct rte_eth_dev *dev;
750 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
752 dev = &rte_eth_devices[port_id];
753 if (rx_queue_id >= dev->data->nb_rx_queues) {
754 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
758 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
760 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
761 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
762 " already stopped\n",
763 rx_queue_id, port_id);
767 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
772 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
774 struct rte_eth_dev *dev;
776 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
778 dev = &rte_eth_devices[port_id];
779 if (tx_queue_id >= dev->data->nb_tx_queues) {
780 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
784 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
786 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
787 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
788 " already started\n",
789 tx_queue_id, port_id);
793 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
798 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
800 struct rte_eth_dev *dev;
802 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
804 dev = &rte_eth_devices[port_id];
805 if (tx_queue_id >= dev->data->nb_tx_queues) {
806 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
810 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
812 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
813 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
814 " already stopped\n",
815 tx_queue_id, port_id);
819 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
824 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
826 uint16_t old_nb_queues = dev->data->nb_tx_queues;
830 if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */
831 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
832 sizeof(dev->data->tx_queues[0]) * nb_queues,
833 RTE_CACHE_LINE_SIZE);
834 if (dev->data->tx_queues == NULL) {
835 dev->data->nb_tx_queues = 0;
838 } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */
839 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
841 txq = dev->data->tx_queues;
843 for (i = nb_queues; i < old_nb_queues; i++)
844 (*dev->dev_ops->tx_queue_release)(txq[i]);
845 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
846 RTE_CACHE_LINE_SIZE);
849 if (nb_queues > old_nb_queues) {
850 uint16_t new_qs = nb_queues - old_nb_queues;
852 memset(txq + old_nb_queues, 0,
853 sizeof(txq[0]) * new_qs);
856 dev->data->tx_queues = txq;
858 } else if (dev->data->tx_queues != NULL && nb_queues == 0) {
859 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
861 txq = dev->data->tx_queues;
863 for (i = nb_queues; i < old_nb_queues; i++)
864 (*dev->dev_ops->tx_queue_release)(txq[i]);
866 dev->data->nb_tx_queues = nb_queues;
871 rte_eth_speed_bitflag(uint32_t speed, int duplex)
874 case ETH_SPEED_NUM_10M:
875 return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD;
876 case ETH_SPEED_NUM_100M:
877 return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD;
878 case ETH_SPEED_NUM_1G:
879 return ETH_LINK_SPEED_1G;
880 case ETH_SPEED_NUM_2_5G:
881 return ETH_LINK_SPEED_2_5G;
882 case ETH_SPEED_NUM_5G:
883 return ETH_LINK_SPEED_5G;
884 case ETH_SPEED_NUM_10G:
885 return ETH_LINK_SPEED_10G;
886 case ETH_SPEED_NUM_20G:
887 return ETH_LINK_SPEED_20G;
888 case ETH_SPEED_NUM_25G:
889 return ETH_LINK_SPEED_25G;
890 case ETH_SPEED_NUM_40G:
891 return ETH_LINK_SPEED_40G;
892 case ETH_SPEED_NUM_50G:
893 return ETH_LINK_SPEED_50G;
894 case ETH_SPEED_NUM_56G:
895 return ETH_LINK_SPEED_56G;
896 case ETH_SPEED_NUM_100G:
897 return ETH_LINK_SPEED_100G;
904 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
905 const struct rte_eth_conf *dev_conf)
907 struct rte_eth_dev *dev;
908 struct rte_eth_dev_info dev_info;
911 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
913 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
915 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
916 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
920 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
922 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
923 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
927 dev = &rte_eth_devices[port_id];
929 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
930 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
932 if (dev->data->dev_started) {
934 "port %d must be stopped to allow configuration\n", port_id);
938 /* Copy the dev_conf parameter into the dev structure */
939 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
942 * Check that the numbers of RX and TX queues are not greater
943 * than the maximum number of RX and TX queues supported by the
946 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
948 if (nb_rx_q == 0 && nb_tx_q == 0) {
949 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d both rx and tx queue cannot be 0\n", port_id);
953 if (nb_rx_q > dev_info.max_rx_queues) {
954 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
955 port_id, nb_rx_q, dev_info.max_rx_queues);
959 if (nb_tx_q > dev_info.max_tx_queues) {
960 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
961 port_id, nb_tx_q, dev_info.max_tx_queues);
966 * If link state interrupt is enabled, check that the
967 * device supports it.
969 if ((dev_conf->intr_conf.lsc == 1) &&
970 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
971 RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
972 dev->data->drv_name);
977 * If jumbo frames are enabled, check that the maximum RX packet
978 * length is supported by the configured device.
980 if (dev_conf->rxmode.jumbo_frame == 1) {
981 if (dev_conf->rxmode.max_rx_pkt_len >
982 dev_info.max_rx_pktlen) {
983 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
984 " > max valid value %u\n",
986 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
987 (unsigned)dev_info.max_rx_pktlen);
989 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
990 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
991 " < min valid value %u\n",
993 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
994 (unsigned)ETHER_MIN_LEN);
998 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
999 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
1000 /* Use default value */
1001 dev->data->dev_conf.rxmode.max_rx_pkt_len =
1006 * Setup new number of RX/TX queues and reconfigure device.
1008 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
1010 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
1015 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
1017 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
1019 rte_eth_dev_rx_queue_config(dev, 0);
1023 diag = (*dev->dev_ops->dev_configure)(dev);
1025 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
1027 rte_eth_dev_rx_queue_config(dev, 0);
1028 rte_eth_dev_tx_queue_config(dev, 0);
1036 rte_eth_dev_config_restore(uint8_t port_id)
1038 struct rte_eth_dev *dev;
1039 struct rte_eth_dev_info dev_info;
1040 struct ether_addr addr;
1044 dev = &rte_eth_devices[port_id];
1046 rte_eth_dev_info_get(port_id, &dev_info);
1048 if (RTE_ETH_DEV_SRIOV(dev).active)
1049 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
1051 /* replay MAC address configuration */
1052 for (i = 0; i < dev_info.max_mac_addrs; i++) {
1053 addr = dev->data->mac_addrs[i];
1055 /* skip zero address */
1056 if (is_zero_ether_addr(&addr))
1059 /* add address to the hardware */
1060 if (*dev->dev_ops->mac_addr_add &&
1061 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
1062 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
1064 RTE_PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
1066 /* exit the loop but not return an error */
1071 /* replay promiscuous configuration */
1072 if (rte_eth_promiscuous_get(port_id) == 1)
1073 rte_eth_promiscuous_enable(port_id);
1074 else if (rte_eth_promiscuous_get(port_id) == 0)
1075 rte_eth_promiscuous_disable(port_id);
1077 /* replay all multicast configuration */
1078 if (rte_eth_allmulticast_get(port_id) == 1)
1079 rte_eth_allmulticast_enable(port_id);
1080 else if (rte_eth_allmulticast_get(port_id) == 0)
1081 rte_eth_allmulticast_disable(port_id);
1085 rte_eth_dev_start(uint8_t port_id)
1087 struct rte_eth_dev *dev;
1090 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1092 dev = &rte_eth_devices[port_id];
1094 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1096 if (dev->data->dev_started != 0) {
1097 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1098 " already started\n",
1103 diag = (*dev->dev_ops->dev_start)(dev);
1105 dev->data->dev_started = 1;
1109 rte_eth_dev_config_restore(port_id);
1111 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1112 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1113 (*dev->dev_ops->link_update)(dev, 0);
1119 rte_eth_dev_stop(uint8_t port_id)
1121 struct rte_eth_dev *dev;
1123 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1124 dev = &rte_eth_devices[port_id];
1126 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1128 if (dev->data->dev_started == 0) {
1129 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1130 " already stopped\n",
1135 dev->data->dev_started = 0;
1136 (*dev->dev_ops->dev_stop)(dev);
1140 rte_eth_dev_set_link_up(uint8_t port_id)
1142 struct rte_eth_dev *dev;
1144 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1146 dev = &rte_eth_devices[port_id];
1148 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1149 return (*dev->dev_ops->dev_set_link_up)(dev);
1153 rte_eth_dev_set_link_down(uint8_t port_id)
1155 struct rte_eth_dev *dev;
1157 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1159 dev = &rte_eth_devices[port_id];
1161 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1162 return (*dev->dev_ops->dev_set_link_down)(dev);
1166 rte_eth_dev_close(uint8_t port_id)
1168 struct rte_eth_dev *dev;
1170 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1171 dev = &rte_eth_devices[port_id];
1173 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1174 dev->data->dev_started = 0;
1175 (*dev->dev_ops->dev_close)(dev);
1177 rte_free(dev->data->rx_queues);
1178 dev->data->rx_queues = NULL;
1179 rte_free(dev->data->tx_queues);
1180 dev->data->tx_queues = NULL;
1184 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1185 uint16_t nb_rx_desc, unsigned int socket_id,
1186 const struct rte_eth_rxconf *rx_conf,
1187 struct rte_mempool *mp)
1190 uint32_t mbp_buf_size;
1191 struct rte_eth_dev *dev;
1192 struct rte_eth_dev_info dev_info;
1194 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1196 dev = &rte_eth_devices[port_id];
1197 if (rx_queue_id >= dev->data->nb_rx_queues) {
1198 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1202 if (dev->data->dev_started) {
1203 RTE_PMD_DEBUG_TRACE(
1204 "port %d must be stopped to allow configuration\n", port_id);
1208 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1209 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1212 * Check the size of the mbuf data buffer.
1213 * This value must be provided in the private data of the memory pool.
1214 * First check that the memory pool has a valid private data.
1216 rte_eth_dev_info_get(port_id, &dev_info);
1217 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1218 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1219 mp->name, (int) mp->private_data_size,
1220 (int) sizeof(struct rte_pktmbuf_pool_private));
1223 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1225 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1226 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1227 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1231 (int)(RTE_PKTMBUF_HEADROOM +
1232 dev_info.min_rx_bufsize),
1233 (int)RTE_PKTMBUF_HEADROOM,
1234 (int)dev_info.min_rx_bufsize);
1238 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1239 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1240 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1242 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1243 "should be: <= %hu, = %hu, and a product of %hu\n",
1245 dev_info.rx_desc_lim.nb_max,
1246 dev_info.rx_desc_lim.nb_min,
1247 dev_info.rx_desc_lim.nb_align);
1251 if (rx_conf == NULL)
1252 rx_conf = &dev_info.default_rxconf;
1254 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1255 socket_id, rx_conf, mp);
1257 if (!dev->data->min_rx_buf_size ||
1258 dev->data->min_rx_buf_size > mbp_buf_size)
1259 dev->data->min_rx_buf_size = mbp_buf_size;
1266 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1267 uint16_t nb_tx_desc, unsigned int socket_id,
1268 const struct rte_eth_txconf *tx_conf)
1270 struct rte_eth_dev *dev;
1271 struct rte_eth_dev_info dev_info;
1273 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1275 dev = &rte_eth_devices[port_id];
1276 if (tx_queue_id >= dev->data->nb_tx_queues) {
1277 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1281 if (dev->data->dev_started) {
1282 RTE_PMD_DEBUG_TRACE(
1283 "port %d must be stopped to allow configuration\n", port_id);
1287 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1288 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1290 rte_eth_dev_info_get(port_id, &dev_info);
1292 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1293 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1294 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1295 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1296 "should be: <= %hu, = %hu, and a product of %hu\n",
1298 dev_info.tx_desc_lim.nb_max,
1299 dev_info.tx_desc_lim.nb_min,
1300 dev_info.tx_desc_lim.nb_align);
1304 if (tx_conf == NULL)
1305 tx_conf = &dev_info.default_txconf;
1307 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1308 socket_id, tx_conf);
1312 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
1313 void *userdata __rte_unused)
1317 for (i = 0; i < unsent; i++)
1318 rte_pktmbuf_free(pkts[i]);
1322 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
1325 uint64_t *count = userdata;
1328 for (i = 0; i < unsent; i++)
1329 rte_pktmbuf_free(pkts[i]);
1335 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
1336 buffer_tx_error_fn cbfn, void *userdata)
1338 buffer->error_callback = cbfn;
1339 buffer->error_userdata = userdata;
1344 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
1351 buffer->size = size;
1352 if (buffer->error_callback == NULL) {
1353 ret = rte_eth_tx_buffer_set_err_callback(
1354 buffer, rte_eth_tx_buffer_drop_callback, NULL);
1361 rte_eth_promiscuous_enable(uint8_t port_id)
1363 struct rte_eth_dev *dev;
1365 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1366 dev = &rte_eth_devices[port_id];
1368 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1369 (*dev->dev_ops->promiscuous_enable)(dev);
1370 dev->data->promiscuous = 1;
1374 rte_eth_promiscuous_disable(uint8_t port_id)
1376 struct rte_eth_dev *dev;
1378 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1379 dev = &rte_eth_devices[port_id];
1381 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1382 dev->data->promiscuous = 0;
1383 (*dev->dev_ops->promiscuous_disable)(dev);
1387 rte_eth_promiscuous_get(uint8_t port_id)
1389 struct rte_eth_dev *dev;
1391 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1393 dev = &rte_eth_devices[port_id];
1394 return dev->data->promiscuous;
1398 rte_eth_allmulticast_enable(uint8_t port_id)
1400 struct rte_eth_dev *dev;
1402 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1403 dev = &rte_eth_devices[port_id];
1405 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1406 (*dev->dev_ops->allmulticast_enable)(dev);
1407 dev->data->all_multicast = 1;
1411 rte_eth_allmulticast_disable(uint8_t port_id)
1413 struct rte_eth_dev *dev;
1415 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1416 dev = &rte_eth_devices[port_id];
1418 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1419 dev->data->all_multicast = 0;
1420 (*dev->dev_ops->allmulticast_disable)(dev);
1424 rte_eth_allmulticast_get(uint8_t port_id)
1426 struct rte_eth_dev *dev;
1428 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1430 dev = &rte_eth_devices[port_id];
1431 return dev->data->all_multicast;
1435 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1436 struct rte_eth_link *link)
1438 struct rte_eth_link *dst = link;
1439 struct rte_eth_link *src = &(dev->data->dev_link);
1441 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1442 *(uint64_t *)src) == 0)
1449 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1451 struct rte_eth_dev *dev;
1453 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1454 dev = &rte_eth_devices[port_id];
1456 if (dev->data->dev_conf.intr_conf.lsc != 0)
1457 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1459 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1460 (*dev->dev_ops->link_update)(dev, 1);
1461 *eth_link = dev->data->dev_link;
1466 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1468 struct rte_eth_dev *dev;
1470 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1471 dev = &rte_eth_devices[port_id];
1473 if (dev->data->dev_conf.intr_conf.lsc != 0)
1474 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1476 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1477 (*dev->dev_ops->link_update)(dev, 0);
1478 *eth_link = dev->data->dev_link;
1483 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1485 struct rte_eth_dev *dev;
1487 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1489 dev = &rte_eth_devices[port_id];
1490 memset(stats, 0, sizeof(*stats));
1492 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1493 (*dev->dev_ops->stats_get)(dev, stats);
1494 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1499 rte_eth_stats_reset(uint8_t port_id)
1501 struct rte_eth_dev *dev;
1503 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1504 dev = &rte_eth_devices[port_id];
1506 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1507 (*dev->dev_ops->stats_reset)(dev);
1508 dev->data->rx_mbuf_alloc_failed = 0;
1512 get_xstats_count(uint8_t port_id)
1514 struct rte_eth_dev *dev;
1517 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1518 dev = &rte_eth_devices[port_id];
1519 if (dev->dev_ops->xstats_get_names != NULL) {
1520 count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0);
1525 count += RTE_NB_STATS;
1526 count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
1527 count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
1532 rte_eth_xstats_get_names(uint8_t port_id,
1533 struct rte_eth_xstat_name *xstats_names,
1536 struct rte_eth_dev *dev;
1537 int cnt_used_entries;
1538 int cnt_expected_entries;
1539 uint32_t idx, id_queue;
1541 cnt_expected_entries = get_xstats_count(port_id);
1542 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1543 (int)size < cnt_expected_entries)
1544 return cnt_expected_entries;
1546 /* port_id checked in get_xstats_count() */
1547 dev = &rte_eth_devices[port_id];
1548 if (dev->dev_ops->xstats_get_names != NULL) {
1549 cnt_used_entries = (*dev->dev_ops->xstats_get_names)(
1550 dev, xstats_names, size);
1551 if (cnt_used_entries < 0)
1552 return cnt_used_entries;
1554 /* Driver itself does not support extended stats, but
1555 * still have basic stats.
1557 cnt_used_entries = 0;
1559 for (idx = 0; idx < RTE_NB_STATS; idx++) {
1560 xstats_names[cnt_used_entries].id = cnt_used_entries;
1561 snprintf(xstats_names[cnt_used_entries].name,
1562 sizeof(xstats_names[0].name),
1563 "%s", rte_stats_strings[idx].name);
1566 for (id_queue = 0; id_queue < dev->data->nb_rx_queues; id_queue++) {
1567 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1568 xstats_names[cnt_used_entries].id = cnt_used_entries;
1569 snprintf(xstats_names[cnt_used_entries].name,
1570 sizeof(xstats_names[0].name),
1572 id_queue, rte_rxq_stats_strings[idx].name);
1577 for (id_queue = 0; id_queue < dev->data->nb_tx_queues; id_queue++) {
1578 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
1579 xstats_names[cnt_used_entries].id = cnt_used_entries;
1580 snprintf(xstats_names[cnt_used_entries].name,
1581 sizeof(xstats_names[0].name),
1583 id_queue, rte_txq_stats_strings[idx].name);
1587 return cnt_used_entries;
1590 /* retrieve ethdev extended statistics */
1592 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstat *xstats,
1595 struct rte_eth_stats eth_stats;
1596 struct rte_eth_dev *dev;
1597 unsigned count = 0, i, q;
1599 uint64_t val, *stats_ptr;
1601 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1603 dev = &rte_eth_devices[port_id];
1605 /* Return generic statistics */
1606 count = RTE_NB_STATS + (dev->data->nb_rx_queues * RTE_NB_RXQ_STATS) +
1607 (dev->data->nb_tx_queues * RTE_NB_TXQ_STATS);
1609 /* implemented by the driver */
1610 if (dev->dev_ops->xstats_get != NULL) {
1611 /* Retrieve the xstats from the driver at the end of the
1614 xcount = (*dev->dev_ops->xstats_get)(dev,
1615 xstats ? xstats + count : NULL,
1616 (n > count) ? n - count : 0);
1622 if (n < count + xcount || xstats == NULL)
1623 return count + xcount;
1625 /* now fill the xstats structure */
1627 rte_eth_stats_get(port_id, ð_stats);
1630 for (i = 0; i < RTE_NB_STATS; i++) {
1631 stats_ptr = RTE_PTR_ADD(ð_stats,
1632 rte_stats_strings[i].offset);
1634 xstats[count].id = count + xcount;
1635 xstats[count++].value = val;
1639 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1640 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1641 stats_ptr = RTE_PTR_ADD(ð_stats,
1642 rte_rxq_stats_strings[i].offset +
1643 q * sizeof(uint64_t));
1645 xstats[count].id = count + xcount;
1646 xstats[count++].value = val;
1651 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1652 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1653 stats_ptr = RTE_PTR_ADD(ð_stats,
1654 rte_txq_stats_strings[i].offset +
1655 q * sizeof(uint64_t));
1657 xstats[count].id = count + xcount;
1658 xstats[count++].value = val;
1662 return count + xcount;
1665 /* reset ethdev extended statistics */
1667 rte_eth_xstats_reset(uint8_t port_id)
1669 struct rte_eth_dev *dev;
1671 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1672 dev = &rte_eth_devices[port_id];
1674 /* implemented by the driver */
1675 if (dev->dev_ops->xstats_reset != NULL) {
1676 (*dev->dev_ops->xstats_reset)(dev);
1680 /* fallback to default */
1681 rte_eth_stats_reset(port_id);
1685 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1688 struct rte_eth_dev *dev;
1690 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1692 dev = &rte_eth_devices[port_id];
1694 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1695 return (*dev->dev_ops->queue_stats_mapping_set)
1696 (dev, queue_id, stat_idx, is_rx);
1701 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1704 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1710 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1713 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1718 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1720 struct rte_eth_dev *dev;
1721 const struct rte_eth_desc_lim lim = {
1722 .nb_max = UINT16_MAX,
1727 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1728 dev = &rte_eth_devices[port_id];
1730 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1731 dev_info->rx_desc_lim = lim;
1732 dev_info->tx_desc_lim = lim;
1734 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1735 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1736 dev_info->pci_dev = dev->pci_dev;
1737 dev_info->driver_name = dev->data->drv_name;
1738 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
1739 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
1743 rte_eth_dev_get_supported_ptypes(uint8_t port_id, uint32_t ptype_mask,
1744 uint32_t *ptypes, int num)
1747 struct rte_eth_dev *dev;
1748 const uint32_t *all_ptypes;
1750 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1751 dev = &rte_eth_devices[port_id];
1752 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
1753 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
1758 for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
1759 if (all_ptypes[i] & ptype_mask) {
1761 ptypes[j] = all_ptypes[i];
1769 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1771 struct rte_eth_dev *dev;
1773 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1774 dev = &rte_eth_devices[port_id];
1775 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1780 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1782 struct rte_eth_dev *dev;
1784 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1786 dev = &rte_eth_devices[port_id];
1787 *mtu = dev->data->mtu;
1792 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1795 struct rte_eth_dev *dev;
1797 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1798 dev = &rte_eth_devices[port_id];
1799 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1801 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1803 dev->data->mtu = mtu;
1809 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1811 struct rte_eth_dev *dev;
1813 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1814 dev = &rte_eth_devices[port_id];
1815 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1816 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1820 if (vlan_id > 4095) {
1821 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1822 port_id, (unsigned) vlan_id);
1825 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1827 return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1831 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1833 struct rte_eth_dev *dev;
1835 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1836 dev = &rte_eth_devices[port_id];
1837 if (rx_queue_id >= dev->data->nb_rx_queues) {
1838 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1842 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1843 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1849 rte_eth_dev_set_vlan_ether_type(uint8_t port_id,
1850 enum rte_vlan_type vlan_type,
1853 struct rte_eth_dev *dev;
1855 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1856 dev = &rte_eth_devices[port_id];
1857 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1859 return (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type, tpid);
1863 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1865 struct rte_eth_dev *dev;
1870 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1871 dev = &rte_eth_devices[port_id];
1873 /*check which option changed by application*/
1874 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1875 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1877 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1878 mask |= ETH_VLAN_STRIP_MASK;
1881 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1882 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1884 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1885 mask |= ETH_VLAN_FILTER_MASK;
1888 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1889 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1891 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1892 mask |= ETH_VLAN_EXTEND_MASK;
1899 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1900 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1906 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1908 struct rte_eth_dev *dev;
1911 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1912 dev = &rte_eth_devices[port_id];
1914 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1915 ret |= ETH_VLAN_STRIP_OFFLOAD;
1917 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1918 ret |= ETH_VLAN_FILTER_OFFLOAD;
1920 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1921 ret |= ETH_VLAN_EXTEND_OFFLOAD;
1927 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1929 struct rte_eth_dev *dev;
1931 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1932 dev = &rte_eth_devices[port_id];
1933 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1934 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1940 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1942 struct rte_eth_dev *dev;
1944 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1945 dev = &rte_eth_devices[port_id];
1946 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1947 memset(fc_conf, 0, sizeof(*fc_conf));
1948 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1952 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1954 struct rte_eth_dev *dev;
1956 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1957 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1958 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1962 dev = &rte_eth_devices[port_id];
1963 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1964 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1968 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1970 struct rte_eth_dev *dev;
1972 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1973 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1974 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1978 dev = &rte_eth_devices[port_id];
1979 /* High water, low water validation are device specific */
1980 if (*dev->dev_ops->priority_flow_ctrl_set)
1981 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1986 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
1994 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
1995 RTE_PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
1996 RTE_RETA_GROUP_SIZE);
2000 num = reta_size / RTE_RETA_GROUP_SIZE;
2001 for (i = 0; i < num; i++) {
2002 if (reta_conf[i].mask)
2010 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2014 uint16_t i, idx, shift;
2020 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
2024 for (i = 0; i < reta_size; i++) {
2025 idx = i / RTE_RETA_GROUP_SIZE;
2026 shift = i % RTE_RETA_GROUP_SIZE;
2027 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2028 (reta_conf[idx].reta[shift] >= max_rxq)) {
2029 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2030 "the maximum rxq index: %u\n", idx, shift,
2031 reta_conf[idx].reta[shift], max_rxq);
2040 rte_eth_dev_rss_reta_update(uint8_t port_id,
2041 struct rte_eth_rss_reta_entry64 *reta_conf,
2044 struct rte_eth_dev *dev;
2047 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2048 /* Check mask bits */
2049 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2053 dev = &rte_eth_devices[port_id];
2055 /* Check entry value */
2056 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2057 dev->data->nb_rx_queues);
2061 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2062 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2066 rte_eth_dev_rss_reta_query(uint8_t port_id,
2067 struct rte_eth_rss_reta_entry64 *reta_conf,
2070 struct rte_eth_dev *dev;
2073 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2075 /* Check mask bits */
2076 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2080 dev = &rte_eth_devices[port_id];
2081 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2082 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2086 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2088 struct rte_eth_dev *dev;
2089 uint16_t rss_hash_protos;
2091 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2092 rss_hash_protos = rss_conf->rss_hf;
2093 if ((rss_hash_protos != 0) &&
2094 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2095 RTE_PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2099 dev = &rte_eth_devices[port_id];
2100 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2101 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2105 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2106 struct rte_eth_rss_conf *rss_conf)
2108 struct rte_eth_dev *dev;
2110 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2111 dev = &rte_eth_devices[port_id];
2112 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2113 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2117 rte_eth_dev_udp_tunnel_port_add(uint8_t port_id,
2118 struct rte_eth_udp_tunnel *udp_tunnel)
2120 struct rte_eth_dev *dev;
2122 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2123 if (udp_tunnel == NULL) {
2124 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2128 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2129 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2133 dev = &rte_eth_devices[port_id];
2134 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
2135 return (*dev->dev_ops->udp_tunnel_port_add)(dev, udp_tunnel);
2139 rte_eth_dev_udp_tunnel_port_delete(uint8_t port_id,
2140 struct rte_eth_udp_tunnel *udp_tunnel)
2142 struct rte_eth_dev *dev;
2144 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2145 dev = &rte_eth_devices[port_id];
2147 if (udp_tunnel == NULL) {
2148 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2152 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2153 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2157 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
2158 return (*dev->dev_ops->udp_tunnel_port_del)(dev, udp_tunnel);
2162 rte_eth_led_on(uint8_t port_id)
2164 struct rte_eth_dev *dev;
2166 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2167 dev = &rte_eth_devices[port_id];
2168 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2169 return (*dev->dev_ops->dev_led_on)(dev);
2173 rte_eth_led_off(uint8_t port_id)
2175 struct rte_eth_dev *dev;
2177 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2178 dev = &rte_eth_devices[port_id];
2179 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2180 return (*dev->dev_ops->dev_led_off)(dev);
2184 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2188 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2190 struct rte_eth_dev_info dev_info;
2191 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2194 rte_eth_dev_info_get(port_id, &dev_info);
2196 for (i = 0; i < dev_info.max_mac_addrs; i++)
2197 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2203 static const struct ether_addr null_mac_addr;
2206 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2209 struct rte_eth_dev *dev;
2213 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2214 dev = &rte_eth_devices[port_id];
2215 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2217 if (is_zero_ether_addr(addr)) {
2218 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2222 if (pool >= ETH_64_POOLS) {
2223 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2227 index = get_mac_addr_index(port_id, addr);
2229 index = get_mac_addr_index(port_id, &null_mac_addr);
2231 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2236 pool_mask = dev->data->mac_pool_sel[index];
2238 /* Check if both MAC address and pool is already there, and do nothing */
2239 if (pool_mask & (1ULL << pool))
2244 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2246 /* Update address in NIC data structure */
2247 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2249 /* Update pool bitmap in NIC data structure */
2250 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2256 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2258 struct rte_eth_dev *dev;
2261 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2262 dev = &rte_eth_devices[port_id];
2263 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2265 index = get_mac_addr_index(port_id, addr);
2267 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2269 } else if (index < 0)
2270 return 0; /* Do nothing if address wasn't found */
2273 (*dev->dev_ops->mac_addr_remove)(dev, index);
2275 /* Update address in NIC data structure */
2276 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2278 /* reset pool bitmap */
2279 dev->data->mac_pool_sel[index] = 0;
2285 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2287 struct rte_eth_dev *dev;
2289 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2291 if (!is_valid_assigned_ether_addr(addr))
2294 dev = &rte_eth_devices[port_id];
2295 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2297 /* Update default address in NIC data structure */
2298 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2300 (*dev->dev_ops->mac_addr_set)(dev, addr);
2306 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2307 uint16_t rx_mode, uint8_t on)
2310 struct rte_eth_dev *dev;
2311 struct rte_eth_dev_info dev_info;
2313 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2315 dev = &rte_eth_devices[port_id];
2316 rte_eth_dev_info_get(port_id, &dev_info);
2318 num_vfs = dev_info.max_vfs;
2320 RTE_PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2325 RTE_PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2328 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2329 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2333 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2337 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2339 struct rte_eth_dev_info dev_info;
2340 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2343 rte_eth_dev_info_get(port_id, &dev_info);
2344 if (!dev->data->hash_mac_addrs)
2347 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2348 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2349 ETHER_ADDR_LEN) == 0)
2356 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2361 struct rte_eth_dev *dev;
2363 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2365 dev = &rte_eth_devices[port_id];
2366 if (is_zero_ether_addr(addr)) {
2367 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2372 index = get_hash_mac_addr_index(port_id, addr);
2373 /* Check if it's already there, and do nothing */
2374 if ((index >= 0) && (on))
2379 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2380 "set in UTA\n", port_id);
2384 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2386 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2392 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2393 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2395 /* Update address in NIC data structure */
2397 ether_addr_copy(addr,
2398 &dev->data->hash_mac_addrs[index]);
2400 ether_addr_copy(&null_mac_addr,
2401 &dev->data->hash_mac_addrs[index]);
2408 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2410 struct rte_eth_dev *dev;
2412 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2414 dev = &rte_eth_devices[port_id];
2416 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2417 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2421 rte_eth_dev_set_vf_rx(uint8_t port_id, uint16_t vf, uint8_t on)
2424 struct rte_eth_dev *dev;
2425 struct rte_eth_dev_info dev_info;
2427 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2429 dev = &rte_eth_devices[port_id];
2430 rte_eth_dev_info_get(port_id, &dev_info);
2432 num_vfs = dev_info.max_vfs;
2434 RTE_PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2438 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2439 return (*dev->dev_ops->set_vf_rx)(dev, vf, on);
2443 rte_eth_dev_set_vf_tx(uint8_t port_id, uint16_t vf, uint8_t on)
2446 struct rte_eth_dev *dev;
2447 struct rte_eth_dev_info dev_info;
2449 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2451 dev = &rte_eth_devices[port_id];
2452 rte_eth_dev_info_get(port_id, &dev_info);
2454 num_vfs = dev_info.max_vfs;
2456 RTE_PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2460 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2461 return (*dev->dev_ops->set_vf_tx)(dev, vf, on);
2465 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2466 uint64_t vf_mask, uint8_t vlan_on)
2468 struct rte_eth_dev *dev;
2470 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2472 dev = &rte_eth_devices[port_id];
2474 if (vlan_id > ETHER_MAX_VLAN_ID) {
2475 RTE_PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2481 RTE_PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2485 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2486 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2490 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2493 struct rte_eth_dev *dev;
2494 struct rte_eth_dev_info dev_info;
2495 struct rte_eth_link link;
2497 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2499 dev = &rte_eth_devices[port_id];
2500 rte_eth_dev_info_get(port_id, &dev_info);
2501 link = dev->data->dev_link;
2503 if (queue_idx > dev_info.max_tx_queues) {
2504 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2505 "invalid queue id=%d\n", port_id, queue_idx);
2509 if (tx_rate > link.link_speed) {
2510 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2511 "bigger than link speed= %d\n",
2512 tx_rate, link.link_speed);
2516 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2517 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2520 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2523 struct rte_eth_dev *dev;
2524 struct rte_eth_dev_info dev_info;
2525 struct rte_eth_link link;
2530 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2532 dev = &rte_eth_devices[port_id];
2533 rte_eth_dev_info_get(port_id, &dev_info);
2534 link = dev->data->dev_link;
2536 if (vf > dev_info.max_vfs) {
2537 RTE_PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2538 "invalid vf id=%d\n", port_id, vf);
2542 if (tx_rate > link.link_speed) {
2543 RTE_PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2544 "bigger than link speed= %d\n",
2545 tx_rate, link.link_speed);
2549 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2550 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2554 rte_eth_mirror_rule_set(uint8_t port_id,
2555 struct rte_eth_mirror_conf *mirror_conf,
2556 uint8_t rule_id, uint8_t on)
2558 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2560 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2561 if (mirror_conf->rule_type == 0) {
2562 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2566 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2567 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2572 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2573 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2574 (mirror_conf->pool_mask == 0)) {
2575 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2579 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2580 mirror_conf->vlan.vlan_mask == 0) {
2581 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2585 dev = &rte_eth_devices[port_id];
2586 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2588 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2592 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2594 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2596 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2598 dev = &rte_eth_devices[port_id];
2599 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2601 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2605 rte_eth_dev_callback_register(uint8_t port_id,
2606 enum rte_eth_event_type event,
2607 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2609 struct rte_eth_dev *dev;
2610 struct rte_eth_dev_callback *user_cb;
2615 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2617 dev = &rte_eth_devices[port_id];
2618 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2620 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2621 if (user_cb->cb_fn == cb_fn &&
2622 user_cb->cb_arg == cb_arg &&
2623 user_cb->event == event) {
2628 /* create a new callback. */
2629 if (user_cb == NULL)
2630 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2631 sizeof(struct rte_eth_dev_callback), 0);
2632 if (user_cb != NULL) {
2633 user_cb->cb_fn = cb_fn;
2634 user_cb->cb_arg = cb_arg;
2635 user_cb->event = event;
2636 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2639 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2640 return (user_cb == NULL) ? -ENOMEM : 0;
2644 rte_eth_dev_callback_unregister(uint8_t port_id,
2645 enum rte_eth_event_type event,
2646 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2649 struct rte_eth_dev *dev;
2650 struct rte_eth_dev_callback *cb, *next;
2655 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2657 dev = &rte_eth_devices[port_id];
2658 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2661 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2663 next = TAILQ_NEXT(cb, next);
2665 if (cb->cb_fn != cb_fn || cb->event != event ||
2666 (cb->cb_arg != (void *)-1 &&
2667 cb->cb_arg != cb_arg))
2671 * if this callback is not executing right now,
2674 if (cb->active == 0) {
2675 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2682 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2687 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2688 enum rte_eth_event_type event)
2690 struct rte_eth_dev_callback *cb_lst;
2691 struct rte_eth_dev_callback dev_cb;
2693 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2694 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2695 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2699 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2700 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2702 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2705 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2709 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
2712 struct rte_eth_dev *dev;
2713 struct rte_intr_handle *intr_handle;
2717 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2719 dev = &rte_eth_devices[port_id];
2720 intr_handle = &dev->pci_dev->intr_handle;
2721 if (!intr_handle->intr_vec) {
2722 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2726 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2727 vec = intr_handle->intr_vec[qid];
2728 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2729 if (rc && rc != -EEXIST) {
2730 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2731 " op %d epfd %d vec %u\n",
2732 port_id, qid, op, epfd, vec);
2739 const struct rte_memzone *
2740 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2741 uint16_t queue_id, size_t size, unsigned align,
2744 char z_name[RTE_MEMZONE_NAMESIZE];
2745 const struct rte_memzone *mz;
2747 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2748 dev->driver->pci_drv.name, ring_name,
2749 dev->data->port_id, queue_id);
2751 mz = rte_memzone_lookup(z_name);
2755 if (rte_xen_dom0_supported())
2756 return rte_memzone_reserve_bounded(z_name, size, socket_id,
2757 0, align, RTE_PGSIZE_2M);
2759 return rte_memzone_reserve_aligned(z_name, size, socket_id,
2764 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
2765 int epfd, int op, void *data)
2768 struct rte_eth_dev *dev;
2769 struct rte_intr_handle *intr_handle;
2772 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2774 dev = &rte_eth_devices[port_id];
2775 if (queue_id >= dev->data->nb_rx_queues) {
2776 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
2780 intr_handle = &dev->pci_dev->intr_handle;
2781 if (!intr_handle->intr_vec) {
2782 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2786 vec = intr_handle->intr_vec[queue_id];
2787 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2788 if (rc && rc != -EEXIST) {
2789 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2790 " op %d epfd %d vec %u\n",
2791 port_id, queue_id, op, epfd, vec);
2799 rte_eth_dev_rx_intr_enable(uint8_t port_id,
2802 struct rte_eth_dev *dev;
2804 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2806 dev = &rte_eth_devices[port_id];
2808 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
2809 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
2813 rte_eth_dev_rx_intr_disable(uint8_t port_id,
2816 struct rte_eth_dev *dev;
2818 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2820 dev = &rte_eth_devices[port_id];
2822 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
2823 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
2826 #ifdef RTE_NIC_BYPASS
2827 int rte_eth_dev_bypass_init(uint8_t port_id)
2829 struct rte_eth_dev *dev;
2831 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2833 dev = &rte_eth_devices[port_id];
2834 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2835 (*dev->dev_ops->bypass_init)(dev);
2840 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2842 struct rte_eth_dev *dev;
2844 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2846 dev = &rte_eth_devices[port_id];
2847 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2848 (*dev->dev_ops->bypass_state_show)(dev, state);
2853 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2855 struct rte_eth_dev *dev;
2857 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2859 dev = &rte_eth_devices[port_id];
2860 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2861 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2866 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2868 struct rte_eth_dev *dev;
2870 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2872 dev = &rte_eth_devices[port_id];
2873 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2874 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2879 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2881 struct rte_eth_dev *dev;
2883 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2885 dev = &rte_eth_devices[port_id];
2887 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2888 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2893 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2895 struct rte_eth_dev *dev;
2897 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2899 dev = &rte_eth_devices[port_id];
2901 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2902 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2907 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2909 struct rte_eth_dev *dev;
2911 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2913 dev = &rte_eth_devices[port_id];
2915 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2916 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2921 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2923 struct rte_eth_dev *dev;
2925 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2927 dev = &rte_eth_devices[port_id];
2929 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2930 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2935 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2937 struct rte_eth_dev *dev;
2939 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2941 dev = &rte_eth_devices[port_id];
2943 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2944 (*dev->dev_ops->bypass_wd_reset)(dev);
2950 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
2952 struct rte_eth_dev *dev;
2954 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2956 dev = &rte_eth_devices[port_id];
2957 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2958 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
2959 RTE_ETH_FILTER_NOP, NULL);
2963 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
2964 enum rte_filter_op filter_op, void *arg)
2966 struct rte_eth_dev *dev;
2968 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2970 dev = &rte_eth_devices[port_id];
2971 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2972 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
2976 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
2977 rte_rx_callback_fn fn, void *user_param)
2979 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2980 rte_errno = ENOTSUP;
2983 /* check input parameters */
2984 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2985 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2989 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2997 cb->param = user_param;
2999 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3000 /* Add the callbacks in fifo order. */
3001 struct rte_eth_rxtx_callback *tail =
3002 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3005 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3012 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3018 rte_eth_add_first_rx_callback(uint8_t port_id, uint16_t queue_id,
3019 rte_rx_callback_fn fn, void *user_param)
3021 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3022 rte_errno = ENOTSUP;
3025 /* check input parameters */
3026 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3027 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3032 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3040 cb->param = user_param;
3042 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3043 /* Add the callbacks at fisrt position*/
3044 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3046 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3047 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3053 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
3054 rte_tx_callback_fn fn, void *user_param)
3056 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3057 rte_errno = ENOTSUP;
3060 /* check input parameters */
3061 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3062 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3067 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3075 cb->param = user_param;
3077 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3078 /* Add the callbacks in fifo order. */
3079 struct rte_eth_rxtx_callback *tail =
3080 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3083 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3090 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3096 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3097 struct rte_eth_rxtx_callback *user_cb)
3099 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3102 /* Check input parameters. */
3103 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3104 if (user_cb == NULL ||
3105 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
3108 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3109 struct rte_eth_rxtx_callback *cb;
3110 struct rte_eth_rxtx_callback **prev_cb;
3113 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3114 prev_cb = &dev->post_rx_burst_cbs[queue_id];
3115 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3117 if (cb == user_cb) {
3118 /* Remove the user cb from the callback list. */
3119 *prev_cb = cb->next;
3124 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3130 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3131 struct rte_eth_rxtx_callback *user_cb)
3133 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3136 /* Check input parameters. */
3137 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3138 if (user_cb == NULL ||
3139 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
3142 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3144 struct rte_eth_rxtx_callback *cb;
3145 struct rte_eth_rxtx_callback **prev_cb;
3147 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3148 prev_cb = &dev->pre_tx_burst_cbs[queue_id];
3149 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3151 if (cb == user_cb) {
3152 /* Remove the user cb from the callback list. */
3153 *prev_cb = cb->next;
3158 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3164 rte_eth_rx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3165 struct rte_eth_rxq_info *qinfo)
3167 struct rte_eth_dev *dev;
3169 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3174 dev = &rte_eth_devices[port_id];
3175 if (queue_id >= dev->data->nb_rx_queues) {
3176 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3180 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3182 memset(qinfo, 0, sizeof(*qinfo));
3183 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3188 rte_eth_tx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3189 struct rte_eth_txq_info *qinfo)
3191 struct rte_eth_dev *dev;
3193 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3198 dev = &rte_eth_devices[port_id];
3199 if (queue_id >= dev->data->nb_tx_queues) {
3200 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3204 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3206 memset(qinfo, 0, sizeof(*qinfo));
3207 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3212 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3213 struct ether_addr *mc_addr_set,
3214 uint32_t nb_mc_addr)
3216 struct rte_eth_dev *dev;
3218 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3220 dev = &rte_eth_devices[port_id];
3221 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3222 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3226 rte_eth_timesync_enable(uint8_t port_id)
3228 struct rte_eth_dev *dev;
3230 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3231 dev = &rte_eth_devices[port_id];
3233 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3234 return (*dev->dev_ops->timesync_enable)(dev);
3238 rte_eth_timesync_disable(uint8_t port_id)
3240 struct rte_eth_dev *dev;
3242 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3243 dev = &rte_eth_devices[port_id];
3245 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3246 return (*dev->dev_ops->timesync_disable)(dev);
3250 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3253 struct rte_eth_dev *dev;
3255 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3256 dev = &rte_eth_devices[port_id];
3258 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3259 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3263 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3265 struct rte_eth_dev *dev;
3267 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3268 dev = &rte_eth_devices[port_id];
3270 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3271 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3275 rte_eth_timesync_adjust_time(uint8_t port_id, int64_t delta)
3277 struct rte_eth_dev *dev;
3279 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3280 dev = &rte_eth_devices[port_id];
3282 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3283 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3287 rte_eth_timesync_read_time(uint8_t port_id, struct timespec *timestamp)
3289 struct rte_eth_dev *dev;
3291 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3292 dev = &rte_eth_devices[port_id];
3294 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3295 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3299 rte_eth_timesync_write_time(uint8_t port_id, const struct timespec *timestamp)
3301 struct rte_eth_dev *dev;
3303 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3304 dev = &rte_eth_devices[port_id];
3306 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3307 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3311 rte_eth_dev_get_reg_length(uint8_t port_id)
3313 struct rte_eth_dev *dev;
3315 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3317 dev = &rte_eth_devices[port_id];
3318 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg_length, -ENOTSUP);
3319 return (*dev->dev_ops->get_reg_length)(dev);
3323 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3325 struct rte_eth_dev *dev;
3327 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3329 dev = &rte_eth_devices[port_id];
3330 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3331 return (*dev->dev_ops->get_reg)(dev, info);
3335 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3337 struct rte_eth_dev *dev;
3339 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3341 dev = &rte_eth_devices[port_id];
3342 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3343 return (*dev->dev_ops->get_eeprom_length)(dev);
3347 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3349 struct rte_eth_dev *dev;
3351 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3353 dev = &rte_eth_devices[port_id];
3354 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3355 return (*dev->dev_ops->get_eeprom)(dev, info);
3359 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3361 struct rte_eth_dev *dev;
3363 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3365 dev = &rte_eth_devices[port_id];
3366 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3367 return (*dev->dev_ops->set_eeprom)(dev, info);
3371 rte_eth_dev_get_dcb_info(uint8_t port_id,
3372 struct rte_eth_dcb_info *dcb_info)
3374 struct rte_eth_dev *dev;
3376 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3378 dev = &rte_eth_devices[port_id];
3379 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3381 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3382 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3386 rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_dev)
3388 if ((eth_dev == NULL) || (pci_dev == NULL)) {
3389 RTE_PMD_DEBUG_TRACE("NULL pointer eth_dev=%p pci_dev=%p\n",
3394 eth_dev->data->dev_flags = 0;
3395 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
3396 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
3397 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_DETACHABLE)
3398 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
3400 eth_dev->data->kdrv = pci_dev->kdrv;
3401 eth_dev->data->numa_node = pci_dev->numa_node;
3402 eth_dev->data->drv_name = pci_dev->driver->name;
3406 rte_eth_dev_l2_tunnel_eth_type_conf(uint8_t port_id,
3407 struct rte_eth_l2_tunnel_conf *l2_tunnel)
3409 struct rte_eth_dev *dev;
3411 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3412 if (l2_tunnel == NULL) {
3413 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3417 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3418 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
3422 dev = &rte_eth_devices[port_id];
3423 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
3425 return (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev, l2_tunnel);
3429 rte_eth_dev_l2_tunnel_offload_set(uint8_t port_id,
3430 struct rte_eth_l2_tunnel_conf *l2_tunnel,
3434 struct rte_eth_dev *dev;
3436 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3438 if (l2_tunnel == NULL) {
3439 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3443 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3444 RTE_PMD_DEBUG_TRACE("Invalid tunnel type.\n");
3449 RTE_PMD_DEBUG_TRACE("Mask should have a value.\n");
3453 dev = &rte_eth_devices[port_id];
3454 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
3456 return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);