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 RTE_PMD_DEBUG_TRACE(fmt, args...) do { \
74 RTE_LOG(ERR, PMD, "%s: " fmt, __func__, ## args); \
77 #define RTE_PMD_DEBUG_TRACE(fmt, args...)
80 /* Macros for checking for restricting functions to primary instance only */
81 #define RTE_PROC_PRIMARY_OR_ERR_RET(retval) do { \
82 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
83 RTE_PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
88 #define RTE_PROC_PRIMARY_OR_RET() do { \
89 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
90 RTE_PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
95 /* Macros to check for invalid function pointers in dev_ops structure */
96 #define RTE_FUNC_PTR_OR_ERR_RET(func, retval) do { \
97 if ((func) == NULL) { \
98 RTE_PMD_DEBUG_TRACE("Function not supported\n"); \
103 #define RTE_FUNC_PTR_OR_RET(func) do { \
104 if ((func) == NULL) { \
105 RTE_PMD_DEBUG_TRACE("Function not supported\n"); \
110 /* Macros to check for valid port */
111 #define RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, retval) do { \
112 if (!rte_eth_dev_is_valid_port(port_id)) { \
113 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); \
118 #define RTE_ETH_VALID_PORTID_OR_RET(port_id) do { \
119 if (!rte_eth_dev_is_valid_port(port_id)) { \
120 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); \
126 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
127 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
128 static struct rte_eth_dev_data *rte_eth_dev_data;
129 static uint8_t nb_ports;
131 /* spinlock for eth device callbacks */
132 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
134 /* store statistics names and its offset in stats structure */
135 struct rte_eth_xstats_name_off {
136 char name[RTE_ETH_XSTATS_NAME_SIZE];
140 static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
141 {"rx_good_packets", offsetof(struct rte_eth_stats, ipackets)},
142 {"tx_good_packets", offsetof(struct rte_eth_stats, opackets)},
143 {"rx_good_bytes", offsetof(struct rte_eth_stats, ibytes)},
144 {"tx_good_bytes", offsetof(struct rte_eth_stats, obytes)},
145 {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
146 {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
147 {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats,
151 #define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
153 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
154 {"packets", offsetof(struct rte_eth_stats, q_ipackets)},
155 {"bytes", offsetof(struct rte_eth_stats, q_ibytes)},
156 {"errors", offsetof(struct rte_eth_stats, q_errors)},
159 #define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) / \
160 sizeof(rte_rxq_stats_strings[0]))
162 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
163 {"packets", offsetof(struct rte_eth_stats, q_opackets)},
164 {"bytes", offsetof(struct rte_eth_stats, q_obytes)},
166 #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) / \
167 sizeof(rte_txq_stats_strings[0]))
171 * The user application callback description.
173 * It contains callback address to be registered by user application,
174 * the pointer to the parameters for callback, and the event type.
176 struct rte_eth_dev_callback {
177 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
178 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
179 void *cb_arg; /**< Parameter for callback */
180 enum rte_eth_event_type event; /**< Interrupt event type */
181 uint32_t active; /**< Callback is executing */
195 rte_eth_dev_data_alloc(void)
197 const unsigned flags = 0;
198 const struct rte_memzone *mz;
200 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
201 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
202 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
203 rte_socket_id(), flags);
205 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
207 rte_panic("Cannot allocate memzone for ethernet port data\n");
209 rte_eth_dev_data = mz->addr;
210 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
211 memset(rte_eth_dev_data, 0,
212 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
216 rte_eth_dev_allocated(const char *name)
220 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
221 if ((rte_eth_devices[i].attached == DEV_ATTACHED) &&
222 strcmp(rte_eth_devices[i].data->name, name) == 0)
223 return &rte_eth_devices[i];
229 rte_eth_dev_find_free_port(void)
233 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
234 if (rte_eth_devices[i].attached == DEV_DETACHED)
237 return RTE_MAX_ETHPORTS;
241 rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
244 struct rte_eth_dev *eth_dev;
246 port_id = rte_eth_dev_find_free_port();
247 if (port_id == RTE_MAX_ETHPORTS) {
248 RTE_PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
252 if (rte_eth_dev_data == NULL)
253 rte_eth_dev_data_alloc();
255 if (rte_eth_dev_allocated(name) != NULL) {
256 RTE_PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n",
261 eth_dev = &rte_eth_devices[port_id];
262 eth_dev->data = &rte_eth_dev_data[port_id];
263 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
264 eth_dev->data->port_id = port_id;
265 eth_dev->attached = DEV_ATTACHED;
266 eth_dev->dev_type = type;
272 rte_eth_dev_create_unique_device_name(char *name, size_t size,
273 struct rte_pci_device *pci_dev)
277 if ((name == NULL) || (pci_dev == NULL))
280 ret = snprintf(name, size, "%d:%d.%d",
281 pci_dev->addr.bus, pci_dev->addr.devid,
282 pci_dev->addr.function);
289 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
294 eth_dev->attached = DEV_DETACHED;
300 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
301 struct rte_pci_device *pci_dev)
303 struct eth_driver *eth_drv;
304 struct rte_eth_dev *eth_dev;
305 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
309 eth_drv = (struct eth_driver *)pci_drv;
311 /* Create unique Ethernet device name using PCI address */
312 rte_eth_dev_create_unique_device_name(ethdev_name,
313 sizeof(ethdev_name), pci_dev);
315 eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
319 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
320 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
321 eth_drv->dev_private_size,
322 RTE_CACHE_LINE_SIZE);
323 if (eth_dev->data->dev_private == NULL)
324 rte_panic("Cannot allocate memzone for private port data\n");
326 eth_dev->pci_dev = pci_dev;
327 eth_dev->driver = eth_drv;
328 eth_dev->data->rx_mbuf_alloc_failed = 0;
330 /* init user callbacks */
331 TAILQ_INIT(&(eth_dev->link_intr_cbs));
334 * Set the default MTU.
336 eth_dev->data->mtu = ETHER_MTU;
338 /* Invoke PMD device initialization function */
339 diag = (*eth_drv->eth_dev_init)(eth_dev);
343 RTE_PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x) failed\n",
345 (unsigned) pci_dev->id.vendor_id,
346 (unsigned) pci_dev->id.device_id);
347 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
348 rte_free(eth_dev->data->dev_private);
349 rte_eth_dev_release_port(eth_dev);
354 rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
356 const struct eth_driver *eth_drv;
357 struct rte_eth_dev *eth_dev;
358 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
364 /* Create unique Ethernet device name using PCI address */
365 rte_eth_dev_create_unique_device_name(ethdev_name,
366 sizeof(ethdev_name), pci_dev);
368 eth_dev = rte_eth_dev_allocated(ethdev_name);
372 eth_drv = (const struct eth_driver *)pci_dev->driver;
374 /* Invoke PMD device uninit function */
375 if (*eth_drv->eth_dev_uninit) {
376 ret = (*eth_drv->eth_dev_uninit)(eth_dev);
381 /* free ether device */
382 rte_eth_dev_release_port(eth_dev);
384 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
385 rte_free(eth_dev->data->dev_private);
387 eth_dev->pci_dev = NULL;
388 eth_dev->driver = NULL;
389 eth_dev->data = NULL;
395 * Register an Ethernet [Poll Mode] driver.
397 * Function invoked by the initialization function of an Ethernet driver
398 * to simultaneously register itself as a PCI driver and as an Ethernet
400 * Invokes the rte_eal_pci_register() function to register the *pci_drv*
401 * structure embedded in the *eth_drv* structure, after having stored the
402 * address of the rte_eth_dev_init() function in the *devinit* field of
403 * the *pci_drv* structure.
404 * During the PCI probing phase, the rte_eth_dev_init() function is
405 * invoked for each PCI [Ethernet device] matching the embedded PCI
406 * identifiers provided by the driver.
409 rte_eth_driver_register(struct eth_driver *eth_drv)
411 eth_drv->pci_drv.devinit = rte_eth_dev_init;
412 eth_drv->pci_drv.devuninit = rte_eth_dev_uninit;
413 rte_eal_pci_register(ð_drv->pci_drv);
417 rte_eth_dev_is_valid_port(uint8_t port_id)
419 if (port_id >= RTE_MAX_ETHPORTS ||
420 rte_eth_devices[port_id].attached != DEV_ATTACHED)
427 rte_eth_dev_socket_id(uint8_t port_id)
429 if (!rte_eth_dev_is_valid_port(port_id))
431 return rte_eth_devices[port_id].data->numa_node;
435 rte_eth_dev_count(void)
440 static enum rte_eth_dev_type
441 rte_eth_dev_get_device_type(uint8_t port_id)
443 if (!rte_eth_dev_is_valid_port(port_id))
444 return RTE_ETH_DEV_UNKNOWN;
445 return rte_eth_devices[port_id].dev_type;
449 rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr)
451 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
454 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
458 *addr = rte_eth_devices[port_id].pci_dev->addr;
463 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
467 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
470 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
474 /* shouldn't check 'rte_eth_devices[i].data',
475 * because it might be overwritten by VDEV PMD */
476 tmp = rte_eth_dev_data[port_id].name;
482 rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
487 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
491 *port_id = RTE_MAX_ETHPORTS;
493 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
496 rte_eth_dev_data[i].name, strlen(name))) {
507 rte_eth_dev_get_port_by_addr(const struct rte_pci_addr *addr, uint8_t *port_id)
510 struct rte_pci_device *pci_dev = NULL;
513 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
517 *port_id = RTE_MAX_ETHPORTS;
519 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
521 pci_dev = rte_eth_devices[i].pci_dev;
524 !rte_eal_compare_pci_addr(&pci_dev->addr, addr)) {
535 rte_eth_dev_is_detachable(uint8_t port_id)
539 if (!rte_eth_dev_is_valid_port(port_id)) {
540 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
544 switch (rte_eth_devices[port_id].data->kdrv) {
545 case RTE_KDRV_IGB_UIO:
546 case RTE_KDRV_UIO_GENERIC:
547 case RTE_KDRV_NIC_UIO:
554 dev_flags = rte_eth_devices[port_id].data->dev_flags;
555 return !(dev_flags & RTE_ETH_DEV_DETACHABLE);
558 /* attach the new physical device, then store port_id of the device */
560 rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
562 if ((addr == NULL) || (port_id == NULL))
565 /* re-construct pci_device_list */
566 if (rte_eal_pci_scan())
568 /* Invoke probe func of the driver can handle the new device. */
569 if (rte_eal_pci_probe_one(addr))
572 if (rte_eth_dev_get_port_by_addr(addr, port_id))
577 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
581 /* detach the new physical device, then store pci_addr of the device */
583 rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
585 struct rte_pci_addr freed_addr;
586 struct rte_pci_addr vp;
591 /* check whether the driver supports detach feature, or not */
592 if (rte_eth_dev_is_detachable(port_id))
595 /* get pci address by port id */
596 if (rte_eth_dev_get_addr_by_port(port_id, &freed_addr))
599 /* Zeroed pci addr means the port comes from virtual device */
600 vp.domain = vp.bus = vp.devid = vp.function = 0;
601 if (rte_eal_compare_pci_addr(&vp, &freed_addr) == 0)
604 /* invoke devuninit func of the pci driver,
605 * also remove the device from pci_device_list */
606 if (rte_eal_pci_detach(&freed_addr))
612 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
616 /* attach the new virtual device, then store port_id of the device */
618 rte_eth_dev_attach_vdev(const char *vdevargs, uint8_t *port_id)
620 char *name = NULL, *args = NULL;
623 if ((vdevargs == NULL) || (port_id == NULL))
626 /* parse vdevargs, then retrieve device name and args */
627 if (rte_eal_parse_devargs_str(vdevargs, &name, &args))
630 /* walk around dev_driver_list to find the driver of the device,
631 * then invoke probe function of the driver.
632 * rte_eal_vdev_init() updates port_id allocated after
635 if (rte_eal_vdev_init(name, args))
638 if (rte_eth_dev_get_port_by_name(name, port_id))
649 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
653 /* detach the new virtual device, then store the name of the device */
655 rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
657 char name[RTE_ETH_NAME_MAX_LEN];
659 if (vdevname == NULL)
662 /* check whether the driver supports detach feature, or not */
663 if (rte_eth_dev_is_detachable(port_id))
666 /* get device name by port id */
667 if (rte_eth_dev_get_name_by_port(port_id, name))
669 /* walk around dev_driver_list to find the driver of the device,
670 * then invoke uninit function of the driver */
671 if (rte_eal_vdev_uninit(name))
674 strncpy(vdevname, name, sizeof(name));
677 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
681 /* attach the new device, then store port_id of the device */
683 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
685 struct rte_pci_addr addr;
687 if ((devargs == NULL) || (port_id == NULL))
690 if (eal_parse_pci_DomBDF(devargs, &addr) == 0)
691 return rte_eth_dev_attach_pdev(&addr, port_id);
693 return rte_eth_dev_attach_vdev(devargs, port_id);
696 /* detach the device, then store the name of the device */
698 rte_eth_dev_detach(uint8_t port_id, char *name)
700 struct rte_pci_addr addr;
706 if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {
707 ret = rte_eth_dev_get_addr_by_port(port_id, &addr);
711 ret = rte_eth_dev_detach_pdev(port_id, &addr);
713 snprintf(name, RTE_ETH_NAME_MAX_LEN,
715 addr.domain, addr.bus,
716 addr.devid, addr.function);
720 return rte_eth_dev_detach_vdev(port_id, name);
724 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
726 uint16_t old_nb_queues = dev->data->nb_rx_queues;
730 if (dev->data->rx_queues == NULL) { /* first time configuration */
731 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
732 sizeof(dev->data->rx_queues[0]) * nb_queues,
733 RTE_CACHE_LINE_SIZE);
734 if (dev->data->rx_queues == NULL) {
735 dev->data->nb_rx_queues = 0;
738 } else { /* re-configure */
739 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
741 rxq = dev->data->rx_queues;
743 for (i = nb_queues; i < old_nb_queues; i++)
744 (*dev->dev_ops->rx_queue_release)(rxq[i]);
745 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
746 RTE_CACHE_LINE_SIZE);
749 if (nb_queues > old_nb_queues) {
750 uint16_t new_qs = nb_queues - old_nb_queues;
752 memset(rxq + old_nb_queues, 0,
753 sizeof(rxq[0]) * new_qs);
756 dev->data->rx_queues = rxq;
759 dev->data->nb_rx_queues = nb_queues;
764 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
766 struct rte_eth_dev *dev;
768 /* This function is only safe when called from the primary process
769 * in a multi-process setup*/
770 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
772 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
774 dev = &rte_eth_devices[port_id];
775 if (rx_queue_id >= dev->data->nb_rx_queues) {
776 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
780 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
782 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
783 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
784 " already started\n",
785 rx_queue_id, port_id);
789 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
794 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
796 struct rte_eth_dev *dev;
798 /* This function is only safe when called from the primary process
799 * in a multi-process setup*/
800 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
802 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
804 dev = &rte_eth_devices[port_id];
805 if (rx_queue_id >= dev->data->nb_rx_queues) {
806 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
810 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
812 if (dev->data->rx_queue_state[rx_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 rx_queue_id, port_id);
819 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
824 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
826 struct rte_eth_dev *dev;
828 /* This function is only safe when called from the primary process
829 * in a multi-process setup*/
830 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
832 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
834 dev = &rte_eth_devices[port_id];
835 if (tx_queue_id >= dev->data->nb_tx_queues) {
836 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
840 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
842 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
843 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
844 " already started\n",
845 tx_queue_id, port_id);
849 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
854 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
856 struct rte_eth_dev *dev;
858 /* This function is only safe when called from the primary process
859 * in a multi-process setup*/
860 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
862 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
864 dev = &rte_eth_devices[port_id];
865 if (tx_queue_id >= dev->data->nb_tx_queues) {
866 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
870 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
872 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
873 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
874 " already stopped\n",
875 tx_queue_id, port_id);
879 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
884 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
886 uint16_t old_nb_queues = dev->data->nb_tx_queues;
890 if (dev->data->tx_queues == NULL) { /* first time configuration */
891 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
892 sizeof(dev->data->tx_queues[0]) * nb_queues,
893 RTE_CACHE_LINE_SIZE);
894 if (dev->data->tx_queues == NULL) {
895 dev->data->nb_tx_queues = 0;
898 } else { /* re-configure */
899 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
901 txq = dev->data->tx_queues;
903 for (i = nb_queues; i < old_nb_queues; i++)
904 (*dev->dev_ops->tx_queue_release)(txq[i]);
905 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
906 RTE_CACHE_LINE_SIZE);
909 if (nb_queues > old_nb_queues) {
910 uint16_t new_qs = nb_queues - old_nb_queues;
912 memset(txq + old_nb_queues, 0,
913 sizeof(txq[0]) * new_qs);
916 dev->data->tx_queues = txq;
919 dev->data->nb_tx_queues = nb_queues;
924 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
925 const struct rte_eth_conf *dev_conf)
927 struct rte_eth_dev *dev;
928 struct rte_eth_dev_info dev_info;
931 /* This function is only safe when called from the primary process
932 * in a multi-process setup*/
933 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
935 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
937 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
939 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
940 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
944 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
946 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
947 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
951 dev = &rte_eth_devices[port_id];
953 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
954 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
956 if (dev->data->dev_started) {
958 "port %d must be stopped to allow configuration\n", port_id);
963 * Check that the numbers of RX and TX queues are not greater
964 * than the maximum number of RX and TX queues supported by the
967 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
968 if (nb_rx_q > dev_info.max_rx_queues) {
969 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
970 port_id, nb_rx_q, dev_info.max_rx_queues);
974 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
978 if (nb_tx_q > dev_info.max_tx_queues) {
979 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
980 port_id, nb_tx_q, dev_info.max_tx_queues);
984 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
988 /* Copy the dev_conf parameter into the dev structure */
989 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
992 * If link state interrupt is enabled, check that the
993 * device supports it.
995 if ((dev_conf->intr_conf.lsc == 1) &&
996 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
997 RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
998 dev->data->drv_name);
1003 * If jumbo frames are enabled, check that the maximum RX packet
1004 * length is supported by the configured device.
1006 if (dev_conf->rxmode.jumbo_frame == 1) {
1007 if (dev_conf->rxmode.max_rx_pkt_len >
1008 dev_info.max_rx_pktlen) {
1009 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
1010 " > max valid value %u\n",
1012 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
1013 (unsigned)dev_info.max_rx_pktlen);
1015 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
1016 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
1017 " < min valid value %u\n",
1019 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
1020 (unsigned)ETHER_MIN_LEN);
1024 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
1025 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
1026 /* Use default value */
1027 dev->data->dev_conf.rxmode.max_rx_pkt_len =
1032 * Setup new number of RX/TX queues and reconfigure device.
1034 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
1036 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
1041 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
1043 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
1045 rte_eth_dev_rx_queue_config(dev, 0);
1049 diag = (*dev->dev_ops->dev_configure)(dev);
1051 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
1053 rte_eth_dev_rx_queue_config(dev, 0);
1054 rte_eth_dev_tx_queue_config(dev, 0);
1062 rte_eth_dev_config_restore(uint8_t port_id)
1064 struct rte_eth_dev *dev;
1065 struct rte_eth_dev_info dev_info;
1066 struct ether_addr addr;
1070 dev = &rte_eth_devices[port_id];
1072 rte_eth_dev_info_get(port_id, &dev_info);
1074 if (RTE_ETH_DEV_SRIOV(dev).active)
1075 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
1077 /* replay MAC address configuration */
1078 for (i = 0; i < dev_info.max_mac_addrs; i++) {
1079 addr = dev->data->mac_addrs[i];
1081 /* skip zero address */
1082 if (is_zero_ether_addr(&addr))
1085 /* add address to the hardware */
1086 if (*dev->dev_ops->mac_addr_add &&
1087 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
1088 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
1090 RTE_PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
1092 /* exit the loop but not return an error */
1097 /* replay promiscuous configuration */
1098 if (rte_eth_promiscuous_get(port_id) == 1)
1099 rte_eth_promiscuous_enable(port_id);
1100 else if (rte_eth_promiscuous_get(port_id) == 0)
1101 rte_eth_promiscuous_disable(port_id);
1103 /* replay all multicast configuration */
1104 if (rte_eth_allmulticast_get(port_id) == 1)
1105 rte_eth_allmulticast_enable(port_id);
1106 else if (rte_eth_allmulticast_get(port_id) == 0)
1107 rte_eth_allmulticast_disable(port_id);
1111 rte_eth_dev_start(uint8_t port_id)
1113 struct rte_eth_dev *dev;
1116 /* This function is only safe when called from the primary process
1117 * in a multi-process setup*/
1118 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1120 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1122 dev = &rte_eth_devices[port_id];
1124 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1126 if (dev->data->dev_started != 0) {
1127 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1128 " already started\n",
1133 diag = (*dev->dev_ops->dev_start)(dev);
1135 dev->data->dev_started = 1;
1139 rte_eth_dev_config_restore(port_id);
1141 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1142 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1143 (*dev->dev_ops->link_update)(dev, 0);
1149 rte_eth_dev_stop(uint8_t port_id)
1151 struct rte_eth_dev *dev;
1153 /* This function is only safe when called from the primary process
1154 * in a multi-process setup*/
1155 RTE_PROC_PRIMARY_OR_RET();
1157 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1158 dev = &rte_eth_devices[port_id];
1160 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1162 if (dev->data->dev_started == 0) {
1163 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1164 " already stopped\n",
1169 dev->data->dev_started = 0;
1170 (*dev->dev_ops->dev_stop)(dev);
1174 rte_eth_dev_set_link_up(uint8_t port_id)
1176 struct rte_eth_dev *dev;
1178 /* This function is only safe when called from the primary process
1179 * in a multi-process setup*/
1180 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1182 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1184 dev = &rte_eth_devices[port_id];
1186 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1187 return (*dev->dev_ops->dev_set_link_up)(dev);
1191 rte_eth_dev_set_link_down(uint8_t port_id)
1193 struct rte_eth_dev *dev;
1195 /* This function is only safe when called from the primary process
1196 * in a multi-process setup*/
1197 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1199 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1201 dev = &rte_eth_devices[port_id];
1203 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1204 return (*dev->dev_ops->dev_set_link_down)(dev);
1208 rte_eth_dev_close(uint8_t port_id)
1210 struct rte_eth_dev *dev;
1212 /* This function is only safe when called from the primary process
1213 * in a multi-process setup*/
1214 RTE_PROC_PRIMARY_OR_RET();
1216 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1217 dev = &rte_eth_devices[port_id];
1219 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1220 dev->data->dev_started = 0;
1221 (*dev->dev_ops->dev_close)(dev);
1223 rte_free(dev->data->rx_queues);
1224 dev->data->rx_queues = NULL;
1225 rte_free(dev->data->tx_queues);
1226 dev->data->tx_queues = NULL;
1230 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1231 uint16_t nb_rx_desc, unsigned int socket_id,
1232 const struct rte_eth_rxconf *rx_conf,
1233 struct rte_mempool *mp)
1236 uint32_t mbp_buf_size;
1237 struct rte_eth_dev *dev;
1238 struct rte_eth_dev_info dev_info;
1240 /* This function is only safe when called from the primary process
1241 * in a multi-process setup*/
1242 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1244 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1246 dev = &rte_eth_devices[port_id];
1247 if (rx_queue_id >= dev->data->nb_rx_queues) {
1248 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1252 if (dev->data->dev_started) {
1253 RTE_PMD_DEBUG_TRACE(
1254 "port %d must be stopped to allow configuration\n", port_id);
1258 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1259 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1262 * Check the size of the mbuf data buffer.
1263 * This value must be provided in the private data of the memory pool.
1264 * First check that the memory pool has a valid private data.
1266 rte_eth_dev_info_get(port_id, &dev_info);
1267 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1268 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1269 mp->name, (int) mp->private_data_size,
1270 (int) sizeof(struct rte_pktmbuf_pool_private));
1273 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1275 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1276 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1277 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1281 (int)(RTE_PKTMBUF_HEADROOM +
1282 dev_info.min_rx_bufsize),
1283 (int)RTE_PKTMBUF_HEADROOM,
1284 (int)dev_info.min_rx_bufsize);
1288 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1289 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1290 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1292 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1293 "should be: <= %hu, = %hu, and a product of %hu\n",
1295 dev_info.rx_desc_lim.nb_max,
1296 dev_info.rx_desc_lim.nb_min,
1297 dev_info.rx_desc_lim.nb_align);
1301 if (rx_conf == NULL)
1302 rx_conf = &dev_info.default_rxconf;
1304 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1305 socket_id, rx_conf, mp);
1307 if (!dev->data->min_rx_buf_size ||
1308 dev->data->min_rx_buf_size > mbp_buf_size)
1309 dev->data->min_rx_buf_size = mbp_buf_size;
1316 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1317 uint16_t nb_tx_desc, unsigned int socket_id,
1318 const struct rte_eth_txconf *tx_conf)
1320 struct rte_eth_dev *dev;
1321 struct rte_eth_dev_info dev_info;
1323 /* This function is only safe when called from the primary process
1324 * in a multi-process setup*/
1325 RTE_PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1327 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1329 dev = &rte_eth_devices[port_id];
1330 if (tx_queue_id >= dev->data->nb_tx_queues) {
1331 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1335 if (dev->data->dev_started) {
1336 RTE_PMD_DEBUG_TRACE(
1337 "port %d must be stopped to allow configuration\n", port_id);
1341 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1342 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1344 rte_eth_dev_info_get(port_id, &dev_info);
1346 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1347 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1348 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1349 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1350 "should be: <= %hu, = %hu, and a product of %hu\n",
1352 dev_info.tx_desc_lim.nb_max,
1353 dev_info.tx_desc_lim.nb_min,
1354 dev_info.tx_desc_lim.nb_align);
1358 if (tx_conf == NULL)
1359 tx_conf = &dev_info.default_txconf;
1361 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1362 socket_id, tx_conf);
1366 rte_eth_promiscuous_enable(uint8_t port_id)
1368 struct rte_eth_dev *dev;
1370 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1371 dev = &rte_eth_devices[port_id];
1373 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1374 (*dev->dev_ops->promiscuous_enable)(dev);
1375 dev->data->promiscuous = 1;
1379 rte_eth_promiscuous_disable(uint8_t port_id)
1381 struct rte_eth_dev *dev;
1383 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1384 dev = &rte_eth_devices[port_id];
1386 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1387 dev->data->promiscuous = 0;
1388 (*dev->dev_ops->promiscuous_disable)(dev);
1392 rte_eth_promiscuous_get(uint8_t port_id)
1394 struct rte_eth_dev *dev;
1396 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1398 dev = &rte_eth_devices[port_id];
1399 return dev->data->promiscuous;
1403 rte_eth_allmulticast_enable(uint8_t port_id)
1405 struct rte_eth_dev *dev;
1407 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1408 dev = &rte_eth_devices[port_id];
1410 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1411 (*dev->dev_ops->allmulticast_enable)(dev);
1412 dev->data->all_multicast = 1;
1416 rte_eth_allmulticast_disable(uint8_t port_id)
1418 struct rte_eth_dev *dev;
1420 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1421 dev = &rte_eth_devices[port_id];
1423 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1424 dev->data->all_multicast = 0;
1425 (*dev->dev_ops->allmulticast_disable)(dev);
1429 rte_eth_allmulticast_get(uint8_t port_id)
1431 struct rte_eth_dev *dev;
1433 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1435 dev = &rte_eth_devices[port_id];
1436 return dev->data->all_multicast;
1440 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1441 struct rte_eth_link *link)
1443 struct rte_eth_link *dst = link;
1444 struct rte_eth_link *src = &(dev->data->dev_link);
1446 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1447 *(uint64_t *)src) == 0)
1454 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1456 struct rte_eth_dev *dev;
1458 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1459 dev = &rte_eth_devices[port_id];
1461 if (dev->data->dev_conf.intr_conf.lsc != 0)
1462 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1464 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1465 (*dev->dev_ops->link_update)(dev, 1);
1466 *eth_link = dev->data->dev_link;
1471 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1473 struct rte_eth_dev *dev;
1475 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1476 dev = &rte_eth_devices[port_id];
1478 if (dev->data->dev_conf.intr_conf.lsc != 0)
1479 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1481 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1482 (*dev->dev_ops->link_update)(dev, 0);
1483 *eth_link = dev->data->dev_link;
1488 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1490 struct rte_eth_dev *dev;
1492 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1494 dev = &rte_eth_devices[port_id];
1495 memset(stats, 0, sizeof(*stats));
1497 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1498 (*dev->dev_ops->stats_get)(dev, stats);
1499 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1504 rte_eth_stats_reset(uint8_t port_id)
1506 struct rte_eth_dev *dev;
1508 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1509 dev = &rte_eth_devices[port_id];
1511 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1512 (*dev->dev_ops->stats_reset)(dev);
1515 /* retrieve ethdev extended statistics */
1517 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1520 struct rte_eth_stats eth_stats;
1521 struct rte_eth_dev *dev;
1522 unsigned count = 0, i, q;
1524 uint64_t val, *stats_ptr;
1526 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1528 dev = &rte_eth_devices[port_id];
1530 /* Return generic statistics */
1531 count = RTE_NB_STATS + (dev->data->nb_rx_queues * RTE_NB_RXQ_STATS) +
1532 (dev->data->nb_tx_queues * RTE_NB_TXQ_STATS);
1534 /* implemented by the driver */
1535 if (dev->dev_ops->xstats_get != NULL) {
1536 /* Retrieve the xstats from the driver at the end of the
1539 xcount = (*dev->dev_ops->xstats_get)(dev, &xstats[count],
1540 (n > count) ? n - count : 0);
1546 if (n < count + xcount)
1547 return count + xcount;
1549 /* now fill the xstats structure */
1551 rte_eth_stats_get(port_id, ð_stats);
1554 for (i = 0; i < RTE_NB_STATS; i++) {
1555 stats_ptr = RTE_PTR_ADD(ð_stats,
1556 rte_stats_strings[i].offset);
1558 snprintf(xstats[count].name, sizeof(xstats[count].name),
1559 "%s", rte_stats_strings[i].name);
1560 xstats[count++].value = val;
1564 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1565 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1566 stats_ptr = RTE_PTR_ADD(ð_stats,
1567 rte_rxq_stats_strings[i].offset +
1568 q * sizeof(uint64_t));
1570 snprintf(xstats[count].name, sizeof(xstats[count].name),
1572 rte_rxq_stats_strings[i].name);
1573 xstats[count++].value = val;
1578 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1579 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1580 stats_ptr = RTE_PTR_ADD(ð_stats,
1581 rte_txq_stats_strings[i].offset +
1582 q * sizeof(uint64_t));
1584 snprintf(xstats[count].name, sizeof(xstats[count].name),
1586 rte_txq_stats_strings[i].name);
1587 xstats[count++].value = val;
1591 return count + xcount;
1594 /* reset ethdev extended statistics */
1596 rte_eth_xstats_reset(uint8_t port_id)
1598 struct rte_eth_dev *dev;
1600 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1601 dev = &rte_eth_devices[port_id];
1603 /* implemented by the driver */
1604 if (dev->dev_ops->xstats_reset != NULL) {
1605 (*dev->dev_ops->xstats_reset)(dev);
1609 /* fallback to default */
1610 rte_eth_stats_reset(port_id);
1614 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1617 struct rte_eth_dev *dev;
1619 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1621 dev = &rte_eth_devices[port_id];
1623 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1624 return (*dev->dev_ops->queue_stats_mapping_set)
1625 (dev, queue_id, stat_idx, is_rx);
1630 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1633 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1639 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1642 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1648 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1650 struct rte_eth_dev *dev;
1651 const struct rte_eth_desc_lim lim = {
1652 .nb_max = UINT16_MAX,
1657 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1658 dev = &rte_eth_devices[port_id];
1660 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1661 dev_info->rx_desc_lim = lim;
1662 dev_info->tx_desc_lim = lim;
1664 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1665 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1666 dev_info->pci_dev = dev->pci_dev;
1667 dev_info->driver_name = dev->data->drv_name;
1671 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1673 struct rte_eth_dev *dev;
1675 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1676 dev = &rte_eth_devices[port_id];
1677 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1682 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1684 struct rte_eth_dev *dev;
1686 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1688 dev = &rte_eth_devices[port_id];
1689 *mtu = dev->data->mtu;
1694 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1697 struct rte_eth_dev *dev;
1699 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1700 dev = &rte_eth_devices[port_id];
1701 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1703 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1705 dev->data->mtu = mtu;
1711 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1713 struct rte_eth_dev *dev;
1715 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1716 dev = &rte_eth_devices[port_id];
1717 if (!(dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1718 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1722 if (vlan_id > 4095) {
1723 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1724 port_id, (unsigned) vlan_id);
1727 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1729 return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1733 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1735 struct rte_eth_dev *dev;
1737 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1738 dev = &rte_eth_devices[port_id];
1739 if (rx_queue_id >= dev->data->nb_rx_queues) {
1740 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1744 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1745 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1751 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1753 struct rte_eth_dev *dev;
1755 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1756 dev = &rte_eth_devices[port_id];
1757 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1758 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1764 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1766 struct rte_eth_dev *dev;
1771 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1772 dev = &rte_eth_devices[port_id];
1774 /*check which option changed by application*/
1775 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1776 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1778 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1779 mask |= ETH_VLAN_STRIP_MASK;
1782 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1783 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1785 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1786 mask |= ETH_VLAN_FILTER_MASK;
1789 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1790 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1792 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1793 mask |= ETH_VLAN_EXTEND_MASK;
1800 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1801 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1807 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1809 struct rte_eth_dev *dev;
1812 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1813 dev = &rte_eth_devices[port_id];
1815 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1816 ret |= ETH_VLAN_STRIP_OFFLOAD;
1818 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1819 ret |= ETH_VLAN_FILTER_OFFLOAD;
1821 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1822 ret |= ETH_VLAN_EXTEND_OFFLOAD;
1828 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1830 struct rte_eth_dev *dev;
1832 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1833 dev = &rte_eth_devices[port_id];
1834 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1835 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1841 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1843 struct rte_eth_dev *dev;
1845 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1846 dev = &rte_eth_devices[port_id];
1847 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1848 memset(fc_conf, 0, sizeof(*fc_conf));
1849 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1853 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1855 struct rte_eth_dev *dev;
1857 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1858 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1859 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1863 dev = &rte_eth_devices[port_id];
1864 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1865 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1869 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1871 struct rte_eth_dev *dev;
1873 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1874 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1875 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1879 dev = &rte_eth_devices[port_id];
1880 /* High water, low water validation are device specific */
1881 if (*dev->dev_ops->priority_flow_ctrl_set)
1882 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1887 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
1895 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
1896 RTE_PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
1897 RTE_RETA_GROUP_SIZE);
1901 num = reta_size / RTE_RETA_GROUP_SIZE;
1902 for (i = 0; i < num; i++) {
1903 if (reta_conf[i].mask)
1911 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
1915 uint16_t i, idx, shift;
1921 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
1925 for (i = 0; i < reta_size; i++) {
1926 idx = i / RTE_RETA_GROUP_SIZE;
1927 shift = i % RTE_RETA_GROUP_SIZE;
1928 if ((reta_conf[idx].mask & (1ULL << shift)) &&
1929 (reta_conf[idx].reta[shift] >= max_rxq)) {
1930 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
1931 "the maximum rxq index: %u\n", idx, shift,
1932 reta_conf[idx].reta[shift], max_rxq);
1941 rte_eth_dev_rss_reta_update(uint8_t port_id,
1942 struct rte_eth_rss_reta_entry64 *reta_conf,
1945 struct rte_eth_dev *dev;
1948 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1949 /* Check mask bits */
1950 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
1954 dev = &rte_eth_devices[port_id];
1956 /* Check entry value */
1957 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
1958 dev->data->nb_rx_queues);
1962 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
1963 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
1967 rte_eth_dev_rss_reta_query(uint8_t port_id,
1968 struct rte_eth_rss_reta_entry64 *reta_conf,
1971 struct rte_eth_dev *dev;
1974 if (port_id >= nb_ports) {
1975 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1979 /* Check mask bits */
1980 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
1984 dev = &rte_eth_devices[port_id];
1985 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
1986 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
1990 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
1992 struct rte_eth_dev *dev;
1993 uint16_t rss_hash_protos;
1995 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1996 rss_hash_protos = rss_conf->rss_hf;
1997 if ((rss_hash_protos != 0) &&
1998 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
1999 RTE_PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2003 dev = &rte_eth_devices[port_id];
2004 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2005 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2009 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2010 struct rte_eth_rss_conf *rss_conf)
2012 struct rte_eth_dev *dev;
2014 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2015 dev = &rte_eth_devices[port_id];
2016 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2017 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2021 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
2022 struct rte_eth_udp_tunnel *udp_tunnel)
2024 struct rte_eth_dev *dev;
2026 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2027 if (udp_tunnel == NULL) {
2028 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2032 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2033 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2037 dev = &rte_eth_devices[port_id];
2038 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
2039 return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
2043 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
2044 struct rte_eth_udp_tunnel *udp_tunnel)
2046 struct rte_eth_dev *dev;
2048 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2049 dev = &rte_eth_devices[port_id];
2051 if (udp_tunnel == NULL) {
2052 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2056 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2057 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2061 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2062 return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2066 rte_eth_led_on(uint8_t port_id)
2068 struct rte_eth_dev *dev;
2070 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2071 dev = &rte_eth_devices[port_id];
2072 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2073 return (*dev->dev_ops->dev_led_on)(dev);
2077 rte_eth_led_off(uint8_t port_id)
2079 struct rte_eth_dev *dev;
2081 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2082 dev = &rte_eth_devices[port_id];
2083 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2084 return (*dev->dev_ops->dev_led_off)(dev);
2088 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2092 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2094 struct rte_eth_dev_info dev_info;
2095 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2098 rte_eth_dev_info_get(port_id, &dev_info);
2100 for (i = 0; i < dev_info.max_mac_addrs; i++)
2101 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2107 static const struct ether_addr null_mac_addr;
2110 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2113 struct rte_eth_dev *dev;
2117 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2118 dev = &rte_eth_devices[port_id];
2119 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2121 if (is_zero_ether_addr(addr)) {
2122 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2126 if (pool >= ETH_64_POOLS) {
2127 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2131 index = get_mac_addr_index(port_id, addr);
2133 index = get_mac_addr_index(port_id, &null_mac_addr);
2135 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2140 pool_mask = dev->data->mac_pool_sel[index];
2142 /* Check if both MAC address and pool is already there, and do nothing */
2143 if (pool_mask & (1ULL << pool))
2148 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2150 /* Update address in NIC data structure */
2151 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2153 /* Update pool bitmap in NIC data structure */
2154 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2160 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2162 struct rte_eth_dev *dev;
2165 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2166 dev = &rte_eth_devices[port_id];
2167 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2169 index = get_mac_addr_index(port_id, addr);
2171 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2173 } else if (index < 0)
2174 return 0; /* Do nothing if address wasn't found */
2177 (*dev->dev_ops->mac_addr_remove)(dev, index);
2179 /* Update address in NIC data structure */
2180 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2182 /* reset pool bitmap */
2183 dev->data->mac_pool_sel[index] = 0;
2189 rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
2191 struct rte_eth_dev *dev;
2193 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2195 if (!is_valid_assigned_ether_addr(addr))
2198 dev = &rte_eth_devices[port_id];
2199 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
2201 /* Update default address in NIC data structure */
2202 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
2204 (*dev->dev_ops->mac_addr_set)(dev, addr);
2210 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2211 uint16_t rx_mode, uint8_t on)
2214 struct rte_eth_dev *dev;
2215 struct rte_eth_dev_info dev_info;
2217 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2219 dev = &rte_eth_devices[port_id];
2220 rte_eth_dev_info_get(port_id, &dev_info);
2222 num_vfs = dev_info.max_vfs;
2224 RTE_PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2229 RTE_PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2232 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2233 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2237 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2241 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2243 struct rte_eth_dev_info dev_info;
2244 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2247 rte_eth_dev_info_get(port_id, &dev_info);
2248 if (!dev->data->hash_mac_addrs)
2251 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2252 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2253 ETHER_ADDR_LEN) == 0)
2260 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2265 struct rte_eth_dev *dev;
2267 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2269 dev = &rte_eth_devices[port_id];
2270 if (is_zero_ether_addr(addr)) {
2271 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2276 index = get_hash_mac_addr_index(port_id, addr);
2277 /* Check if it's already there, and do nothing */
2278 if ((index >= 0) && (on))
2283 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
2284 "set in UTA\n", port_id);
2288 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2290 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2296 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2297 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2299 /* Update address in NIC data structure */
2301 ether_addr_copy(addr,
2302 &dev->data->hash_mac_addrs[index]);
2304 ether_addr_copy(&null_mac_addr,
2305 &dev->data->hash_mac_addrs[index]);
2312 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2314 struct rte_eth_dev *dev;
2316 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2318 dev = &rte_eth_devices[port_id];
2320 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2321 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2325 rte_eth_dev_set_vf_rx(uint8_t port_id, uint16_t vf, uint8_t on)
2328 struct rte_eth_dev *dev;
2329 struct rte_eth_dev_info dev_info;
2331 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2333 dev = &rte_eth_devices[port_id];
2334 rte_eth_dev_info_get(port_id, &dev_info);
2336 num_vfs = dev_info.max_vfs;
2338 RTE_PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2342 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2343 return (*dev->dev_ops->set_vf_rx)(dev, vf, on);
2347 rte_eth_dev_set_vf_tx(uint8_t port_id, uint16_t vf, uint8_t on)
2350 struct rte_eth_dev *dev;
2351 struct rte_eth_dev_info dev_info;
2353 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2355 dev = &rte_eth_devices[port_id];
2356 rte_eth_dev_info_get(port_id, &dev_info);
2358 num_vfs = dev_info.max_vfs;
2360 RTE_PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2364 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2365 return (*dev->dev_ops->set_vf_tx)(dev, vf, on);
2369 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2370 uint64_t vf_mask, uint8_t vlan_on)
2372 struct rte_eth_dev *dev;
2374 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2376 dev = &rte_eth_devices[port_id];
2378 if (vlan_id > ETHER_MAX_VLAN_ID) {
2379 RTE_PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2385 RTE_PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2389 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2390 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2394 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2397 struct rte_eth_dev *dev;
2398 struct rte_eth_dev_info dev_info;
2399 struct rte_eth_link link;
2401 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2403 dev = &rte_eth_devices[port_id];
2404 rte_eth_dev_info_get(port_id, &dev_info);
2405 link = dev->data->dev_link;
2407 if (queue_idx > dev_info.max_tx_queues) {
2408 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2409 "invalid queue id=%d\n", port_id, queue_idx);
2413 if (tx_rate > link.link_speed) {
2414 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2415 "bigger than link speed= %d\n",
2416 tx_rate, link.link_speed);
2420 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2421 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2424 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2427 struct rte_eth_dev *dev;
2428 struct rte_eth_dev_info dev_info;
2429 struct rte_eth_link link;
2434 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2436 dev = &rte_eth_devices[port_id];
2437 rte_eth_dev_info_get(port_id, &dev_info);
2438 link = dev->data->dev_link;
2440 if (vf > dev_info.max_vfs) {
2441 RTE_PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2442 "invalid vf id=%d\n", port_id, vf);
2446 if (tx_rate > link.link_speed) {
2447 RTE_PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2448 "bigger than link speed= %d\n",
2449 tx_rate, link.link_speed);
2453 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2454 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2458 rte_eth_mirror_rule_set(uint8_t port_id,
2459 struct rte_eth_mirror_conf *mirror_conf,
2460 uint8_t rule_id, uint8_t on)
2462 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2464 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2465 if (mirror_conf->rule_type == 0) {
2466 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2470 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2471 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
2476 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
2477 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
2478 (mirror_conf->pool_mask == 0)) {
2479 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
2483 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
2484 mirror_conf->vlan.vlan_mask == 0) {
2485 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
2489 dev = &rte_eth_devices[port_id];
2490 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2492 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2496 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2498 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2500 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2502 dev = &rte_eth_devices[port_id];
2503 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2505 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2508 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2510 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2511 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2513 struct rte_eth_dev *dev;
2515 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0);
2517 dev = &rte_eth_devices[port_id];
2518 RTE_FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);
2519 if (queue_id >= dev->data->nb_rx_queues) {
2520 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2523 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2528 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2529 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2531 struct rte_eth_dev *dev;
2533 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0);
2535 dev = &rte_eth_devices[port_id];
2537 RTE_FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0);
2538 if (queue_id >= dev->data->nb_tx_queues) {
2539 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2542 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2547 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2549 struct rte_eth_dev *dev;
2551 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0);
2553 dev = &rte_eth_devices[port_id];
2554 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0);
2555 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2559 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2561 struct rte_eth_dev *dev;
2563 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2565 dev = &rte_eth_devices[port_id];
2566 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2567 return (*dev->dev_ops->rx_descriptor_done)(dev->data->rx_queues[queue_id],
2573 rte_eth_dev_callback_register(uint8_t port_id,
2574 enum rte_eth_event_type event,
2575 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2577 struct rte_eth_dev *dev;
2578 struct rte_eth_dev_callback *user_cb;
2583 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2585 dev = &rte_eth_devices[port_id];
2586 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2588 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2589 if (user_cb->cb_fn == cb_fn &&
2590 user_cb->cb_arg == cb_arg &&
2591 user_cb->event == event) {
2596 /* create a new callback. */
2597 if (user_cb == NULL)
2598 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2599 sizeof(struct rte_eth_dev_callback), 0);
2600 if (user_cb != NULL) {
2601 user_cb->cb_fn = cb_fn;
2602 user_cb->cb_arg = cb_arg;
2603 user_cb->event = event;
2604 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2607 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2608 return (user_cb == NULL) ? -ENOMEM : 0;
2612 rte_eth_dev_callback_unregister(uint8_t port_id,
2613 enum rte_eth_event_type event,
2614 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2617 struct rte_eth_dev *dev;
2618 struct rte_eth_dev_callback *cb, *next;
2623 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2625 dev = &rte_eth_devices[port_id];
2626 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2629 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2631 next = TAILQ_NEXT(cb, next);
2633 if (cb->cb_fn != cb_fn || cb->event != event ||
2634 (cb->cb_arg != (void *)-1 &&
2635 cb->cb_arg != cb_arg))
2639 * if this callback is not executing right now,
2642 if (cb->active == 0) {
2643 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2650 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2655 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2656 enum rte_eth_event_type event)
2658 struct rte_eth_dev_callback *cb_lst;
2659 struct rte_eth_dev_callback dev_cb;
2661 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2662 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2663 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2667 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2668 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2670 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2673 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2677 rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
2680 struct rte_eth_dev *dev;
2681 struct rte_intr_handle *intr_handle;
2685 if (!rte_eth_dev_is_valid_port(port_id)) {
2686 RTE_PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
2690 dev = &rte_eth_devices[port_id];
2691 intr_handle = &dev->pci_dev->intr_handle;
2692 if (!intr_handle->intr_vec) {
2693 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2697 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
2698 vec = intr_handle->intr_vec[qid];
2699 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2700 if (rc && rc != -EEXIST) {
2701 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2702 " op %d epfd %d vec %u\n",
2703 port_id, qid, op, epfd, vec);
2710 const struct rte_memzone *
2711 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
2712 uint16_t queue_id, size_t size, unsigned align,
2715 char z_name[RTE_MEMZONE_NAMESIZE];
2716 const struct rte_memzone *mz;
2718 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
2719 dev->driver->pci_drv.name, ring_name,
2720 dev->data->port_id, queue_id);
2722 mz = rte_memzone_lookup(z_name);
2726 if (is_xen_dom0_supported())
2727 return rte_memzone_reserve_bounded(z_name, size, socket_id,
2728 0, align, RTE_PGSIZE_2M);
2730 return rte_memzone_reserve_aligned(z_name, size, socket_id,
2735 rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
2736 int epfd, int op, void *data)
2739 struct rte_eth_dev *dev;
2740 struct rte_intr_handle *intr_handle;
2743 if (!rte_eth_dev_is_valid_port(port_id)) {
2744 RTE_PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
2748 dev = &rte_eth_devices[port_id];
2749 if (queue_id >= dev->data->nb_rx_queues) {
2750 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
2754 intr_handle = &dev->pci_dev->intr_handle;
2755 if (!intr_handle->intr_vec) {
2756 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
2760 vec = intr_handle->intr_vec[queue_id];
2761 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
2762 if (rc && rc != -EEXIST) {
2763 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
2764 " op %d epfd %d vec %u\n",
2765 port_id, queue_id, op, epfd, vec);
2773 rte_eth_dev_rx_intr_enable(uint8_t port_id,
2776 struct rte_eth_dev *dev;
2778 if (!rte_eth_dev_is_valid_port(port_id)) {
2779 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2783 dev = &rte_eth_devices[port_id];
2785 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
2786 return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
2790 rte_eth_dev_rx_intr_disable(uint8_t port_id,
2793 struct rte_eth_dev *dev;
2795 if (!rte_eth_dev_is_valid_port(port_id)) {
2796 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2800 dev = &rte_eth_devices[port_id];
2802 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
2803 return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
2806 #ifdef RTE_NIC_BYPASS
2807 int rte_eth_dev_bypass_init(uint8_t port_id)
2809 struct rte_eth_dev *dev;
2811 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2813 dev = &rte_eth_devices[port_id];
2814 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2815 (*dev->dev_ops->bypass_init)(dev);
2820 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2822 struct rte_eth_dev *dev;
2824 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2826 dev = &rte_eth_devices[port_id];
2827 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2828 (*dev->dev_ops->bypass_state_show)(dev, state);
2833 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2835 struct rte_eth_dev *dev;
2837 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2839 dev = &rte_eth_devices[port_id];
2840 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2841 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2846 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2848 struct rte_eth_dev *dev;
2850 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2852 dev = &rte_eth_devices[port_id];
2853 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2854 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2859 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2861 struct rte_eth_dev *dev;
2863 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2865 dev = &rte_eth_devices[port_id];
2867 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2868 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2873 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2875 struct rte_eth_dev *dev;
2877 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2879 dev = &rte_eth_devices[port_id];
2881 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2882 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2887 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2889 struct rte_eth_dev *dev;
2891 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2893 dev = &rte_eth_devices[port_id];
2895 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2896 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2901 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2903 struct rte_eth_dev *dev;
2905 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2907 dev = &rte_eth_devices[port_id];
2909 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2910 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2915 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2917 struct rte_eth_dev *dev;
2919 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2921 dev = &rte_eth_devices[port_id];
2923 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2924 (*dev->dev_ops->bypass_wd_reset)(dev);
2930 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
2932 struct rte_eth_dev *dev;
2934 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2936 dev = &rte_eth_devices[port_id];
2937 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2938 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
2939 RTE_ETH_FILTER_NOP, NULL);
2943 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
2944 enum rte_filter_op filter_op, void *arg)
2946 struct rte_eth_dev *dev;
2948 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2950 dev = &rte_eth_devices[port_id];
2951 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
2952 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
2956 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
2957 rte_rx_callback_fn fn, void *user_param)
2959 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
2960 rte_errno = ENOTSUP;
2963 /* check input parameters */
2964 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
2965 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
2970 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
2978 cb->param = user_param;
2980 /* Add the callbacks in fifo order. */
2981 struct rte_eth_rxtx_callback *tail =
2982 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
2985 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
2997 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
2998 rte_tx_callback_fn fn, void *user_param)
3000 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3001 rte_errno = ENOTSUP;
3004 /* check input parameters */
3005 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3006 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3011 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3019 cb->param = user_param;
3021 /* Add the callbacks in fifo order. */
3022 struct rte_eth_rxtx_callback *tail =
3023 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3026 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3038 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3039 struct rte_eth_rxtx_callback *user_cb)
3041 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3044 /* Check input parameters. */
3045 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
3046 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3050 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3051 struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
3052 struct rte_eth_rxtx_callback *prev_cb;
3054 /* Reset head pointer and remove user cb if first in the list. */
3055 if (cb == user_cb) {
3056 dev->post_rx_burst_cbs[queue_id] = user_cb->next;
3060 /* Remove the user cb from the callback list. */
3065 if (cb == user_cb) {
3066 prev_cb->next = user_cb->next;
3070 } while (cb != NULL);
3072 /* Callback wasn't found. */
3077 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3078 struct rte_eth_rxtx_callback *user_cb)
3080 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3083 /* Check input parameters. */
3084 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
3085 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3089 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3090 struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
3091 struct rte_eth_rxtx_callback *prev_cb;
3093 /* Reset head pointer and remove user cb if first in the list. */
3094 if (cb == user_cb) {
3095 dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
3099 /* Remove the user cb from the callback list. */
3104 if (cb == user_cb) {
3105 prev_cb->next = user_cb->next;
3109 } while (cb != NULL);
3111 /* Callback wasn't found. */
3116 rte_eth_rx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3117 struct rte_eth_rxq_info *qinfo)
3119 struct rte_eth_dev *dev;
3121 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3126 dev = &rte_eth_devices[port_id];
3127 if (queue_id >= dev->data->nb_rx_queues) {
3128 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3132 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3134 memset(qinfo, 0, sizeof(*qinfo));
3135 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3140 rte_eth_tx_queue_info_get(uint8_t port_id, uint16_t queue_id,
3141 struct rte_eth_txq_info *qinfo)
3143 struct rte_eth_dev *dev;
3145 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3150 dev = &rte_eth_devices[port_id];
3151 if (queue_id >= dev->data->nb_tx_queues) {
3152 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3156 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3158 memset(qinfo, 0, sizeof(*qinfo));
3159 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3164 rte_eth_dev_set_mc_addr_list(uint8_t port_id,
3165 struct ether_addr *mc_addr_set,
3166 uint32_t nb_mc_addr)
3168 struct rte_eth_dev *dev;
3170 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3172 dev = &rte_eth_devices[port_id];
3173 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3174 return dev->dev_ops->set_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
3178 rte_eth_timesync_enable(uint8_t port_id)
3180 struct rte_eth_dev *dev;
3182 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3183 dev = &rte_eth_devices[port_id];
3185 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3186 return (*dev->dev_ops->timesync_enable)(dev);
3190 rte_eth_timesync_disable(uint8_t port_id)
3192 struct rte_eth_dev *dev;
3194 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3195 dev = &rte_eth_devices[port_id];
3197 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3198 return (*dev->dev_ops->timesync_disable)(dev);
3202 rte_eth_timesync_read_rx_timestamp(uint8_t port_id, struct timespec *timestamp,
3205 struct rte_eth_dev *dev;
3207 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3208 dev = &rte_eth_devices[port_id];
3210 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3211 return (*dev->dev_ops->timesync_read_rx_timestamp)(dev, timestamp, flags);
3215 rte_eth_timesync_read_tx_timestamp(uint8_t port_id, struct timespec *timestamp)
3217 struct rte_eth_dev *dev;
3219 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3220 dev = &rte_eth_devices[port_id];
3222 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3223 return (*dev->dev_ops->timesync_read_tx_timestamp)(dev, timestamp);
3227 rte_eth_timesync_adjust_time(uint8_t port_id, int64_t delta)
3229 struct rte_eth_dev *dev;
3231 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3232 dev = &rte_eth_devices[port_id];
3234 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3235 return (*dev->dev_ops->timesync_adjust_time)(dev, delta);
3239 rte_eth_timesync_read_time(uint8_t port_id, struct timespec *timestamp)
3241 struct rte_eth_dev *dev;
3243 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3244 dev = &rte_eth_devices[port_id];
3246 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3247 return (*dev->dev_ops->timesync_read_time)(dev, timestamp);
3251 rte_eth_timesync_write_time(uint8_t port_id, const 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_write_time, -ENOTSUP);
3259 return (*dev->dev_ops->timesync_write_time)(dev, timestamp);
3263 rte_eth_dev_get_reg_length(uint8_t port_id)
3265 struct rte_eth_dev *dev;
3267 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3269 dev = &rte_eth_devices[port_id];
3270 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg_length, -ENOTSUP);
3271 return (*dev->dev_ops->get_reg_length)(dev);
3275 rte_eth_dev_get_reg_info(uint8_t port_id, struct rte_dev_reg_info *info)
3277 struct rte_eth_dev *dev;
3279 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3281 dev = &rte_eth_devices[port_id];
3282 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3283 return (*dev->dev_ops->get_reg)(dev, info);
3287 rte_eth_dev_get_eeprom_length(uint8_t port_id)
3289 struct rte_eth_dev *dev;
3291 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3293 dev = &rte_eth_devices[port_id];
3294 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3295 return (*dev->dev_ops->get_eeprom_length)(dev);
3299 rte_eth_dev_get_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
3301 struct rte_eth_dev *dev;
3303 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3305 dev = &rte_eth_devices[port_id];
3306 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3307 return (*dev->dev_ops->get_eeprom)(dev, info);
3311 rte_eth_dev_set_eeprom(uint8_t port_id, struct rte_dev_eeprom_info *info)
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->set_eeprom, -ENOTSUP);
3319 return (*dev->dev_ops->set_eeprom)(dev, info);
3323 rte_eth_dev_get_dcb_info(uint8_t port_id,
3324 struct rte_eth_dcb_info *dcb_info)
3326 struct rte_eth_dev *dev;
3328 if (!rte_eth_dev_is_valid_port(port_id)) {
3329 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3333 dev = &rte_eth_devices[port_id];
3334 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3336 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3337 return (*dev->dev_ops->get_dcb_info)(dev, dcb_info);
3341 rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_dev)
3343 if ((eth_dev == NULL) || (pci_dev == NULL)) {
3344 RTE_PMD_DEBUG_TRACE("NULL pointer eth_dev=%p pci_dev=%p\n",
3349 eth_dev->data->dev_flags = 0;
3350 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
3351 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
3352 if (pci_dev->driver->drv_flags & RTE_PCI_DRV_DETACHABLE)
3353 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
3355 eth_dev->data->kdrv = pci_dev->kdrv;
3356 eth_dev->data->numa_node = pci_dev->numa_node;
3357 eth_dev->data->drv_name = pci_dev->driver->name;