4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/types.h>
35 #include <sys/queue.h>
44 #include <netinet/in.h>
46 #include <rte_byteorder.h>
48 #include <rte_debug.h>
49 #include <rte_interrupts.h>
51 #include <rte_memory.h>
52 #include <rte_memcpy.h>
53 #include <rte_memzone.h>
54 #include <rte_launch.h>
56 #include <rte_per_lcore.h>
57 #include <rte_lcore.h>
58 #include <rte_atomic.h>
59 #include <rte_branch_prediction.h>
60 #include <rte_common.h>
62 #include <rte_mempool.h>
63 #include <rte_malloc.h>
65 #include <rte_errno.h>
66 #include <rte_spinlock.h>
67 #include <rte_string_fns.h>
69 #include "rte_ether.h"
70 #include "rte_ethdev.h"
72 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
73 #define PMD_DEBUG_TRACE(fmt, args...) do { \
74 RTE_LOG(ERR, PMD, "%s: " fmt, __func__, ## args); \
77 #define PMD_DEBUG_TRACE(fmt, args...)
80 /* Macros for checking for restricting functions to primary instance only */
81 #define PROC_PRIMARY_OR_ERR_RET(retval) do { \
82 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
83 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
87 #define PROC_PRIMARY_OR_RET() do { \
88 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
89 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
94 /* Macros to check for invlaid function pointers in dev_ops structure */
95 #define FUNC_PTR_OR_ERR_RET(func, retval) do { \
96 if ((func) == NULL) { \
97 PMD_DEBUG_TRACE("Function not supported\n"); \
101 #define FUNC_PTR_OR_RET(func) do { \
102 if ((func) == NULL) { \
103 PMD_DEBUG_TRACE("Function not supported\n"); \
108 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
109 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
110 static struct rte_eth_dev_data *rte_eth_dev_data = NULL;
111 static uint8_t nb_ports = 0;
113 /* spinlock for eth device callbacks */
114 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
116 /* store statistics names and its offset in stats structure */
117 struct rte_eth_xstats_name_off {
118 char name[RTE_ETH_XSTATS_NAME_SIZE];
122 static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
123 {"rx_packets", offsetof(struct rte_eth_stats, ipackets)},
124 {"tx_packets", offsetof(struct rte_eth_stats, opackets)},
125 {"rx_bytes", offsetof(struct rte_eth_stats, ibytes)},
126 {"tx_bytes", offsetof(struct rte_eth_stats, obytes)},
127 {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
128 {"rx_missed_errors", offsetof(struct rte_eth_stats, imissed)},
129 {"rx_crc_errors", offsetof(struct rte_eth_stats, ibadcrc)},
130 {"rx_bad_length_errors", offsetof(struct rte_eth_stats, ibadlen)},
131 {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
132 {"alloc_rx_buff_failed", offsetof(struct rte_eth_stats, rx_nombuf)},
133 {"fdir_match", offsetof(struct rte_eth_stats, fdirmatch)},
134 {"fdir_miss", offsetof(struct rte_eth_stats, fdirmiss)},
135 {"tx_flow_control_xon", offsetof(struct rte_eth_stats, tx_pause_xon)},
136 {"rx_flow_control_xon", offsetof(struct rte_eth_stats, rx_pause_xon)},
137 {"tx_flow_control_xoff", offsetof(struct rte_eth_stats, tx_pause_xoff)},
138 {"rx_flow_control_xoff", offsetof(struct rte_eth_stats, rx_pause_xoff)},
140 #define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
142 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
143 {"rx_packets", offsetof(struct rte_eth_stats, q_ipackets)},
144 {"rx_bytes", offsetof(struct rte_eth_stats, q_ibytes)},
146 #define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) / \
147 sizeof(rte_rxq_stats_strings[0]))
149 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
150 {"tx_packets", offsetof(struct rte_eth_stats, q_opackets)},
151 {"tx_bytes", offsetof(struct rte_eth_stats, q_obytes)},
152 {"tx_errors", offsetof(struct rte_eth_stats, q_errors)},
154 #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) / \
155 sizeof(rte_txq_stats_strings[0]))
159 * The user application callback description.
161 * It contains callback address to be registered by user application,
162 * the pointer to the parameters for callback, and the event type.
164 struct rte_eth_dev_callback {
165 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
166 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
167 void *cb_arg; /**< Parameter for callback */
168 enum rte_eth_event_type event; /**< Interrupt event type */
169 uint32_t active; /**< Callback is executing */
183 rte_eth_dev_data_alloc(void)
185 const unsigned flags = 0;
186 const struct rte_memzone *mz;
188 if (rte_eal_process_type() == RTE_PROC_PRIMARY){
189 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
190 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
191 rte_socket_id(), flags);
193 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
195 rte_panic("Cannot allocate memzone for ethernet port data\n");
197 rte_eth_dev_data = mz->addr;
198 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
199 memset(rte_eth_dev_data, 0,
200 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
204 rte_eth_dev_allocated(const char *name)
208 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
209 if ((rte_eth_devices[i].attached == DEV_ATTACHED) &&
210 strcmp(rte_eth_devices[i].data->name, name) == 0)
211 return &rte_eth_devices[i];
217 rte_eth_dev_find_free_port(void)
221 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
222 if (rte_eth_devices[i].attached == DEV_DETACHED)
225 return RTE_MAX_ETHPORTS;
229 rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
232 struct rte_eth_dev *eth_dev;
234 port_id = rte_eth_dev_find_free_port();
235 if (port_id == RTE_MAX_ETHPORTS) {
236 PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
240 if (rte_eth_dev_data == NULL)
241 rte_eth_dev_data_alloc();
243 if (rte_eth_dev_allocated(name) != NULL) {
244 PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n", name);
248 eth_dev = &rte_eth_devices[port_id];
249 eth_dev->data = &rte_eth_dev_data[port_id];
250 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
251 eth_dev->data->port_id = port_id;
252 eth_dev->attached = DEV_ATTACHED;
253 eth_dev->dev_type = type;
259 rte_eth_dev_create_unique_device_name(char *name, size_t size,
260 struct rte_pci_device *pci_dev)
264 if ((name == NULL) || (pci_dev == NULL))
267 ret = snprintf(name, size, "%d:%d.%d",
268 pci_dev->addr.bus, pci_dev->addr.devid,
269 pci_dev->addr.function);
276 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
281 eth_dev->attached = 0;
287 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
288 struct rte_pci_device *pci_dev)
290 struct eth_driver *eth_drv;
291 struct rte_eth_dev *eth_dev;
292 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
296 eth_drv = (struct eth_driver *)pci_drv;
298 /* Create unique Ethernet device name using PCI address */
299 rte_eth_dev_create_unique_device_name(ethdev_name,
300 sizeof(ethdev_name), pci_dev);
302 eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
306 if (rte_eal_process_type() == RTE_PROC_PRIMARY){
307 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
308 eth_drv->dev_private_size,
309 RTE_CACHE_LINE_SIZE);
310 if (eth_dev->data->dev_private == NULL)
311 rte_panic("Cannot allocate memzone for private port data\n");
313 eth_dev->pci_dev = pci_dev;
314 eth_dev->driver = eth_drv;
315 eth_dev->data->rx_mbuf_alloc_failed = 0;
317 /* init user callbacks */
318 TAILQ_INIT(&(eth_dev->link_intr_cbs));
321 * Set the default MTU.
323 eth_dev->data->mtu = ETHER_MTU;
325 /* Invoke PMD device initialization function */
326 diag = (*eth_drv->eth_dev_init)(eth_dev);
330 PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x)"
331 " failed\n", pci_drv->name,
332 (unsigned) pci_dev->id.vendor_id,
333 (unsigned) pci_dev->id.device_id);
334 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
335 rte_free(eth_dev->data->dev_private);
336 eth_dev->attached = DEV_DETACHED;
342 rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
344 const struct eth_driver *eth_drv;
345 struct rte_eth_dev *eth_dev;
346 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
352 /* Create unique Ethernet device name using PCI address */
353 rte_eth_dev_create_unique_device_name(ethdev_name,
354 sizeof(ethdev_name), pci_dev);
356 eth_dev = rte_eth_dev_allocated(ethdev_name);
360 eth_drv = (const struct eth_driver *)pci_dev->driver;
362 /* Invoke PMD device uninit function */
363 if (*eth_drv->eth_dev_uninit) {
364 ret = (*eth_drv->eth_dev_uninit)(eth_dev);
369 /* free ether device */
370 rte_eth_dev_release_port(eth_dev);
372 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
373 rte_free(eth_dev->data->dev_private);
375 eth_dev->pci_dev = NULL;
376 eth_dev->driver = NULL;
377 eth_dev->data = NULL;
383 * Register an Ethernet [Poll Mode] driver.
385 * Function invoked by the initialization function of an Ethernet driver
386 * to simultaneously register itself as a PCI driver and as an Ethernet
388 * Invokes the rte_eal_pci_register() function to register the *pci_drv*
389 * structure embedded in the *eth_drv* structure, after having stored the
390 * address of the rte_eth_dev_init() function in the *devinit* field of
391 * the *pci_drv* structure.
392 * During the PCI probing phase, the rte_eth_dev_init() function is
393 * invoked for each PCI [Ethernet device] matching the embedded PCI
394 * identifiers provided by the driver.
397 rte_eth_driver_register(struct eth_driver *eth_drv)
399 eth_drv->pci_drv.devinit = rte_eth_dev_init;
400 eth_drv->pci_drv.devuninit = rte_eth_dev_uninit;
401 rte_eal_pci_register(ð_drv->pci_drv);
405 rte_eth_dev_is_valid_port(uint8_t port_id)
407 if (port_id >= RTE_MAX_ETHPORTS ||
408 rte_eth_devices[port_id].attached != DEV_ATTACHED)
415 rte_eth_dev_socket_id(uint8_t port_id)
417 if (!rte_eth_dev_is_valid_port(port_id))
419 return rte_eth_devices[port_id].pci_dev->numa_node;
423 rte_eth_dev_count(void)
428 /* So far, DPDK hotplug function only supports linux */
429 #ifdef RTE_LIBRTE_EAL_HOTPLUG
431 static enum rte_eth_dev_type
432 rte_eth_dev_get_device_type(uint8_t port_id)
434 if (!rte_eth_dev_is_valid_port(port_id))
435 return RTE_ETH_DEV_UNKNOWN;
436 return rte_eth_devices[port_id].dev_type;
440 rte_eth_dev_save(struct rte_eth_dev *devs, size_t size)
442 if ((devs == NULL) ||
443 (size != sizeof(struct rte_eth_dev) * RTE_MAX_ETHPORTS))
446 /* save current rte_eth_devices */
447 memcpy(devs, rte_eth_devices, size);
452 rte_eth_dev_get_changed_port(struct rte_eth_dev *devs, uint8_t *port_id)
454 if ((devs == NULL) || (port_id == NULL))
457 /* check which port was attached or detached */
458 for (*port_id = 0; *port_id < RTE_MAX_ETHPORTS; (*port_id)++, devs++) {
459 if (rte_eth_devices[*port_id].attached ^ devs->attached)
466 rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr)
468 if (!rte_eth_dev_is_valid_port(port_id)) {
469 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
474 PMD_DEBUG_TRACE("Null pointer is specified\n");
478 *addr = rte_eth_devices[port_id].pci_dev->addr;
483 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
487 if (!rte_eth_dev_is_valid_port(port_id)) {
488 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
493 PMD_DEBUG_TRACE("Null pointer is specified\n");
497 /* shouldn't check 'rte_eth_devices[i].data',
498 * because it might be overwritten by VDEV PMD */
499 tmp = rte_eth_dev_data[port_id].name;
505 rte_eth_dev_is_detachable(uint8_t port_id)
509 if (port_id >= RTE_MAX_ETHPORTS) {
510 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
514 if (rte_eth_devices[port_id].dev_type == RTE_ETH_DEV_PCI) {
515 switch (rte_eth_devices[port_id].pci_dev->kdrv) {
516 case RTE_KDRV_IGB_UIO:
517 case RTE_KDRV_UIO_GENERIC:
525 drv_flags = rte_eth_devices[port_id].driver->pci_drv.drv_flags;
526 return !(drv_flags & RTE_PCI_DRV_DETACHABLE);
529 /* attach the new physical device, then store port_id of the device */
531 rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
534 struct rte_eth_dev devs[RTE_MAX_ETHPORTS];
536 if ((addr == NULL) || (port_id == NULL))
539 /* save current port status */
540 if (rte_eth_dev_save(devs, sizeof(devs)))
542 /* re-construct pci_device_list */
543 if (rte_eal_pci_scan())
545 /* invoke probe func of the driver can handle the new device.
547 * rte_eal_pci_probe_one() should return port_id.
548 * And rte_eth_dev_save() and rte_eth_dev_get_changed_port()
549 * should be removed. */
550 if (rte_eal_pci_probe_one(addr))
552 /* get port_id enabled by above procedures */
553 if (rte_eth_dev_get_changed_port(devs, &new_port_id))
556 *port_id = new_port_id;
559 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
563 /* detach the new physical device, then store pci_addr of the device */
565 rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
567 struct rte_pci_addr freed_addr;
568 struct rte_pci_addr vp;
573 /* check whether the driver supports detach feature, or not */
574 if (rte_eth_dev_is_detachable(port_id))
577 /* get pci address by port id */
578 if (rte_eth_dev_get_addr_by_port(port_id, &freed_addr))
581 /* Zerod pci addr means the port comes from virtual device */
582 vp.domain = vp.bus = vp.devid = vp.function = 0;
583 if (rte_eal_compare_pci_addr(&vp, &freed_addr) == 0)
586 /* invoke close func of the driver,
587 * also remove the device from pci_device_list */
588 if (rte_eal_pci_close_one(&freed_addr))
594 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
598 /* attach the new virtual device, then store port_id of the device */
600 rte_eth_dev_attach_vdev(const char *vdevargs, uint8_t *port_id)
602 char *name = NULL, *args = NULL;
604 struct rte_eth_dev devs[RTE_MAX_ETHPORTS];
607 if ((vdevargs == NULL) || (port_id == NULL))
610 /* parse vdevargs, then retrieve device name and args */
611 if (rte_eal_parse_devargs_str(vdevargs, &name, &args))
614 /* save current port status */
615 if (rte_eth_dev_save(devs, sizeof(devs)))
617 /* walk around dev_driver_list to find the driver of the device,
618 * then invoke probe function o the driver.
620 * rte_eal_vdev_init() should return port_id,
621 * And rte_eth_dev_save() and rte_eth_dev_get_changed_port()
622 * should be removed. */
623 if (rte_eal_vdev_init(name, args))
625 /* get port_id enabled by above procedures */
626 if (rte_eth_dev_get_changed_port(devs, &new_port_id))
629 *port_id = new_port_id;
637 RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
641 /* detach the new virtual device, then store the name of the device */
643 rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
645 char name[RTE_ETH_NAME_MAX_LEN];
647 if (vdevname == NULL)
650 /* check whether the driver supports detach feature, or not */
651 if (rte_eth_dev_is_detachable(port_id))
654 /* get device name by port id */
655 if (rte_eth_dev_get_name_by_port(port_id, name))
657 /* walk around dev_driver_list to find the driver of the device,
658 * then invoke close function o the driver */
659 if (rte_eal_vdev_uninit(name))
662 strncpy(vdevname, name, sizeof(name));
665 RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
669 /* attach the new device, then store port_id of the device */
671 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
673 struct rte_pci_addr addr;
675 if ((devargs == NULL) || (port_id == NULL))
678 if (eal_parse_pci_DomBDF(devargs, &addr) == 0)
679 return rte_eth_dev_attach_pdev(&addr, port_id);
681 return rte_eth_dev_attach_vdev(devargs, port_id);
684 /* detach the device, then store the name of the device */
686 rte_eth_dev_detach(uint8_t port_id, char *name)
688 struct rte_pci_addr addr;
694 if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {
695 ret = rte_eth_dev_get_addr_by_port(port_id, &addr);
699 ret = rte_eth_dev_detach_pdev(port_id, &addr);
701 snprintf(name, RTE_ETH_NAME_MAX_LEN,
703 addr.domain, addr.bus,
704 addr.devid, addr.function);
708 return rte_eth_dev_detach_vdev(port_id, name);
710 #else /* RTE_LIBRTE_EAL_HOTPLUG */
712 rte_eth_dev_attach(const char *devargs __rte_unused,
713 uint8_t *port_id __rte_unused)
715 RTE_LOG(ERR, EAL, "Hotplug support isn't enabled\n");
719 /* detach the device, then store the name of the device */
721 rte_eth_dev_detach(uint8_t port_id __rte_unused,
722 char *name __rte_unused)
724 RTE_LOG(ERR, EAL, "Hotplug support isn't enabled\n");
727 #endif /* RTE_LIBRTE_EAL_HOTPLUG */
730 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
732 uint16_t old_nb_queues = dev->data->nb_rx_queues;
736 if (dev->data->rx_queues == NULL) { /* first time configuration */
737 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
738 sizeof(dev->data->rx_queues[0]) * nb_queues,
739 RTE_CACHE_LINE_SIZE);
740 if (dev->data->rx_queues == NULL) {
741 dev->data->nb_rx_queues = 0;
744 } else { /* re-configure */
745 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
747 rxq = dev->data->rx_queues;
749 for (i = nb_queues; i < old_nb_queues; i++)
750 (*dev->dev_ops->rx_queue_release)(rxq[i]);
751 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
752 RTE_CACHE_LINE_SIZE);
755 if (nb_queues > old_nb_queues) {
756 uint16_t new_qs = nb_queues - old_nb_queues;
757 memset(rxq + old_nb_queues, 0,
758 sizeof(rxq[0]) * new_qs);
761 dev->data->rx_queues = rxq;
764 dev->data->nb_rx_queues = nb_queues;
769 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
771 struct rte_eth_dev *dev;
773 /* This function is only safe when called from the primary process
774 * in a multi-process setup*/
775 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
777 if (!rte_eth_dev_is_valid_port(port_id)) {
778 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
782 dev = &rte_eth_devices[port_id];
783 if (rx_queue_id >= dev->data->nb_rx_queues) {
784 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
788 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
790 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
795 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
797 struct rte_eth_dev *dev;
799 /* This function is only safe when called from the primary process
800 * in a multi-process setup*/
801 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
803 if (!rte_eth_dev_is_valid_port(port_id)) {
804 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
808 dev = &rte_eth_devices[port_id];
809 if (rx_queue_id >= dev->data->nb_rx_queues) {
810 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
814 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
816 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
821 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
823 struct rte_eth_dev *dev;
825 /* This function is only safe when called from the primary process
826 * in a multi-process setup*/
827 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
829 if (!rte_eth_dev_is_valid_port(port_id)) {
830 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
834 dev = &rte_eth_devices[port_id];
835 if (tx_queue_id >= dev->data->nb_tx_queues) {
836 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
840 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
842 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
847 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
849 struct rte_eth_dev *dev;
851 /* This function is only safe when called from the primary process
852 * in a multi-process setup*/
853 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
855 if (!rte_eth_dev_is_valid_port(port_id)) {
856 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
860 dev = &rte_eth_devices[port_id];
861 if (tx_queue_id >= dev->data->nb_tx_queues) {
862 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
866 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
868 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
873 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
875 uint16_t old_nb_queues = dev->data->nb_tx_queues;
879 if (dev->data->tx_queues == NULL) { /* first time configuration */
880 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
881 sizeof(dev->data->tx_queues[0]) * nb_queues,
882 RTE_CACHE_LINE_SIZE);
883 if (dev->data->tx_queues == NULL) {
884 dev->data->nb_tx_queues = 0;
887 } else { /* re-configure */
888 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
890 txq = dev->data->tx_queues;
892 for (i = nb_queues; i < old_nb_queues; i++)
893 (*dev->dev_ops->tx_queue_release)(txq[i]);
894 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
895 RTE_CACHE_LINE_SIZE);
898 if (nb_queues > old_nb_queues) {
899 uint16_t new_qs = nb_queues - old_nb_queues;
900 memset(txq + old_nb_queues, 0,
901 sizeof(txq[0]) * new_qs);
904 dev->data->tx_queues = txq;
907 dev->data->nb_tx_queues = nb_queues;
912 rte_eth_dev_check_vf_rss_rxq_num(uint8_t port_id, uint16_t nb_rx_q)
914 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
918 RTE_ETH_DEV_SRIOV(dev).active =
922 RTE_ETH_DEV_SRIOV(dev).active =
929 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = nb_rx_q;
930 RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx =
931 dev->pci_dev->max_vfs * nb_rx_q;
937 rte_eth_dev_check_mq_mode(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
938 const struct rte_eth_conf *dev_conf)
940 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
942 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
943 /* check multi-queue mode */
944 if ((dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) ||
945 (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB_RSS) ||
946 (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB)) {
947 /* SRIOV only works in VMDq enable mode */
948 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
950 "wrong VMDQ mq_mode rx %u tx %u\n",
952 dev_conf->rxmode.mq_mode,
953 dev_conf->txmode.mq_mode);
957 switch (dev_conf->rxmode.mq_mode) {
958 case ETH_MQ_RX_VMDQ_DCB:
959 case ETH_MQ_RX_VMDQ_DCB_RSS:
960 /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
961 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
963 "unsupported VMDQ mq_mode rx %u\n",
964 port_id, dev_conf->rxmode.mq_mode);
967 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
969 "Rx mq mode is changed from:"
970 "mq_mode %u into VMDQ mq_mode %u\n",
972 dev_conf->rxmode.mq_mode,
973 dev->data->dev_conf.rxmode.mq_mode);
974 case ETH_MQ_RX_VMDQ_RSS:
975 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_RSS;
976 if (nb_rx_q <= RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)
977 if (rte_eth_dev_check_vf_rss_rxq_num(port_id, nb_rx_q) != 0) {
978 PMD_DEBUG_TRACE("ethdev port_id=%d"
979 " SRIOV active, invalid queue"
980 " number for VMDQ RSS, allowed"
981 " value are 1, 2 or 4\n",
986 default: /* ETH_MQ_RX_VMDQ_ONLY or ETH_MQ_RX_NONE */
987 /* if nothing mq mode configure, use default scheme */
988 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
989 if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
990 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
994 switch (dev_conf->txmode.mq_mode) {
995 case ETH_MQ_TX_VMDQ_DCB:
996 /* DCB VMDQ in SRIOV mode, not implement yet */
997 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
999 "unsupported VMDQ mq_mode tx %u\n",
1000 port_id, dev_conf->txmode.mq_mode);
1002 default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
1003 /* if nothing mq mode configure, use default scheme */
1004 dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
1008 /* check valid queue number */
1009 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
1010 (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
1011 PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
1012 "queue number must less equal to %d\n",
1013 port_id, RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
1017 /* For vmdb+dcb mode check our configuration before we go further */
1018 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB) {
1019 const struct rte_eth_vmdq_dcb_conf *conf;
1021 if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
1022 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
1024 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
1027 conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
1028 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
1029 conf->nb_queue_pools == ETH_32_POOLS)) {
1030 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
1031 "nb_queue_pools must be %d or %d\n",
1032 port_id, ETH_16_POOLS, ETH_32_POOLS);
1036 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
1037 const struct rte_eth_vmdq_dcb_tx_conf *conf;
1039 if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
1040 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
1042 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
1045 conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
1046 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
1047 conf->nb_queue_pools == ETH_32_POOLS)) {
1048 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
1049 "nb_queue_pools != %d or nb_queue_pools "
1051 port_id, ETH_16_POOLS, ETH_32_POOLS);
1056 /* For DCB mode check our configuration before we go further */
1057 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) {
1058 const struct rte_eth_dcb_rx_conf *conf;
1060 if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
1061 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
1063 port_id, ETH_DCB_NUM_QUEUES);
1066 conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
1067 if (! (conf->nb_tcs == ETH_4_TCS ||
1068 conf->nb_tcs == ETH_8_TCS)) {
1069 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
1070 "nb_tcs != %d or nb_tcs "
1072 port_id, ETH_4_TCS, ETH_8_TCS);
1077 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
1078 const struct rte_eth_dcb_tx_conf *conf;
1080 if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
1081 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
1083 port_id, ETH_DCB_NUM_QUEUES);
1086 conf = &(dev_conf->tx_adv_conf.dcb_tx_conf);
1087 if (! (conf->nb_tcs == ETH_4_TCS ||
1088 conf->nb_tcs == ETH_8_TCS)) {
1089 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
1090 "nb_tcs != %d or nb_tcs "
1092 port_id, ETH_4_TCS, ETH_8_TCS);
1101 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
1102 const struct rte_eth_conf *dev_conf)
1104 struct rte_eth_dev *dev;
1105 struct rte_eth_dev_info dev_info;
1108 /* This function is only safe when called from the primary process
1109 * in a multi-process setup*/
1110 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1112 if (!rte_eth_dev_is_valid_port(port_id)) {
1113 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1117 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
1119 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
1120 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
1124 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
1126 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
1127 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
1131 dev = &rte_eth_devices[port_id];
1133 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1134 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
1136 if (dev->data->dev_started) {
1138 "port %d must be stopped to allow configuration\n", port_id);
1143 * Check that the numbers of RX and TX queues are not greater
1144 * than the maximum number of RX and TX queues supported by the
1145 * configured device.
1147 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
1148 if (nb_rx_q > dev_info.max_rx_queues) {
1149 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
1150 port_id, nb_rx_q, dev_info.max_rx_queues);
1154 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
1158 if (nb_tx_q > dev_info.max_tx_queues) {
1159 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
1160 port_id, nb_tx_q, dev_info.max_tx_queues);
1164 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
1168 /* Copy the dev_conf parameter into the dev structure */
1169 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
1172 * If link state interrupt is enabled, check that the
1173 * device supports it.
1175 if (dev_conf->intr_conf.lsc == 1) {
1176 const struct rte_pci_driver *pci_drv = &dev->driver->pci_drv;
1178 if (!(pci_drv->drv_flags & RTE_PCI_DRV_INTR_LSC)) {
1179 PMD_DEBUG_TRACE("driver %s does not support lsc\n",
1186 * If jumbo frames are enabled, check that the maximum RX packet
1187 * length is supported by the configured device.
1189 if (dev_conf->rxmode.jumbo_frame == 1) {
1190 if (dev_conf->rxmode.max_rx_pkt_len >
1191 dev_info.max_rx_pktlen) {
1192 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
1193 " > max valid value %u\n",
1195 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
1196 (unsigned)dev_info.max_rx_pktlen);
1199 else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
1200 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
1201 " < min valid value %u\n",
1203 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
1204 (unsigned)ETHER_MIN_LEN);
1208 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
1209 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
1210 /* Use default value */
1211 dev->data->dev_conf.rxmode.max_rx_pkt_len =
1215 /* multipe queue mode checking */
1216 diag = rte_eth_dev_check_mq_mode(port_id, nb_rx_q, nb_tx_q, dev_conf);
1218 PMD_DEBUG_TRACE("port%d rte_eth_dev_check_mq_mode = %d\n",
1224 * Setup new number of RX/TX queues and reconfigure device.
1226 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
1228 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
1233 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
1235 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
1237 rte_eth_dev_rx_queue_config(dev, 0);
1241 diag = (*dev->dev_ops->dev_configure)(dev);
1243 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
1245 rte_eth_dev_rx_queue_config(dev, 0);
1246 rte_eth_dev_tx_queue_config(dev, 0);
1254 rte_eth_dev_config_restore(uint8_t port_id)
1256 struct rte_eth_dev *dev;
1257 struct rte_eth_dev_info dev_info;
1258 struct ether_addr addr;
1262 dev = &rte_eth_devices[port_id];
1264 rte_eth_dev_info_get(port_id, &dev_info);
1266 if (RTE_ETH_DEV_SRIOV(dev).active)
1267 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
1269 /* replay MAC address configuration */
1270 for (i = 0; i < dev_info.max_mac_addrs; i++) {
1271 addr = dev->data->mac_addrs[i];
1273 /* skip zero address */
1274 if (is_zero_ether_addr(&addr))
1277 /* add address to the hardware */
1278 if (*dev->dev_ops->mac_addr_add &&
1279 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
1280 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
1282 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
1284 /* exit the loop but not return an error */
1289 /* replay promiscuous configuration */
1290 if (rte_eth_promiscuous_get(port_id) == 1)
1291 rte_eth_promiscuous_enable(port_id);
1292 else if (rte_eth_promiscuous_get(port_id) == 0)
1293 rte_eth_promiscuous_disable(port_id);
1295 /* replay allmulticast configuration */
1296 if (rte_eth_allmulticast_get(port_id) == 1)
1297 rte_eth_allmulticast_enable(port_id);
1298 else if (rte_eth_allmulticast_get(port_id) == 0)
1299 rte_eth_allmulticast_disable(port_id);
1303 rte_eth_dev_start(uint8_t port_id)
1305 struct rte_eth_dev *dev;
1308 /* This function is only safe when called from the primary process
1309 * in a multi-process setup*/
1310 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1312 if (!rte_eth_dev_is_valid_port(port_id)) {
1313 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1317 dev = &rte_eth_devices[port_id];
1319 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1321 if (dev->data->dev_started != 0) {
1322 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1323 " already started\n",
1328 diag = (*dev->dev_ops->dev_start)(dev);
1330 dev->data->dev_started = 1;
1334 rte_eth_dev_config_restore(port_id);
1336 if (dev->data->dev_conf.intr_conf.lsc != 0) {
1337 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1338 (*dev->dev_ops->link_update)(dev, 0);
1344 rte_eth_dev_stop(uint8_t port_id)
1346 struct rte_eth_dev *dev;
1348 /* This function is only safe when called from the primary process
1349 * in a multi-process setup*/
1350 PROC_PRIMARY_OR_RET();
1352 if (!rte_eth_dev_is_valid_port(port_id)) {
1353 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1357 dev = &rte_eth_devices[port_id];
1359 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1361 if (dev->data->dev_started == 0) {
1362 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1363 " already stopped\n",
1368 dev->data->dev_started = 0;
1369 (*dev->dev_ops->dev_stop)(dev);
1373 rte_eth_dev_set_link_up(uint8_t port_id)
1375 struct rte_eth_dev *dev;
1377 /* This function is only safe when called from the primary process
1378 * in a multi-process setup*/
1379 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1381 if (!rte_eth_dev_is_valid_port(port_id)) {
1382 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1386 dev = &rte_eth_devices[port_id];
1388 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1389 return (*dev->dev_ops->dev_set_link_up)(dev);
1393 rte_eth_dev_set_link_down(uint8_t port_id)
1395 struct rte_eth_dev *dev;
1397 /* This function is only safe when called from the primary process
1398 * in a multi-process setup*/
1399 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1401 if (!rte_eth_dev_is_valid_port(port_id)) {
1402 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1406 dev = &rte_eth_devices[port_id];
1408 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1409 return (*dev->dev_ops->dev_set_link_down)(dev);
1413 rte_eth_dev_close(uint8_t port_id)
1415 struct rte_eth_dev *dev;
1417 /* This function is only safe when called from the primary process
1418 * in a multi-process setup*/
1419 PROC_PRIMARY_OR_RET();
1421 if (!rte_eth_dev_is_valid_port(port_id)) {
1422 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1426 dev = &rte_eth_devices[port_id];
1428 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1429 dev->data->dev_started = 0;
1430 (*dev->dev_ops->dev_close)(dev);
1434 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1435 uint16_t nb_rx_desc, unsigned int socket_id,
1436 const struct rte_eth_rxconf *rx_conf,
1437 struct rte_mempool *mp)
1440 uint32_t mbp_buf_size;
1441 struct rte_eth_dev *dev;
1442 struct rte_eth_dev_info dev_info;
1444 /* This function is only safe when called from the primary process
1445 * in a multi-process setup*/
1446 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1448 if (!rte_eth_dev_is_valid_port(port_id)) {
1449 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1453 dev = &rte_eth_devices[port_id];
1454 if (rx_queue_id >= dev->data->nb_rx_queues) {
1455 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1459 if (dev->data->dev_started) {
1461 "port %d must be stopped to allow configuration\n", port_id);
1465 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1466 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1469 * Check the size of the mbuf data buffer.
1470 * This value must be provided in the private data of the memory pool.
1471 * First check that the memory pool has a valid private data.
1473 rte_eth_dev_info_get(port_id, &dev_info);
1474 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1475 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1476 mp->name, (int) mp->private_data_size,
1477 (int) sizeof(struct rte_pktmbuf_pool_private));
1480 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1482 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1483 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1484 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1488 (int)(RTE_PKTMBUF_HEADROOM +
1489 dev_info.min_rx_bufsize),
1490 (int)RTE_PKTMBUF_HEADROOM,
1491 (int)dev_info.min_rx_bufsize);
1495 if (rx_conf == NULL)
1496 rx_conf = &dev_info.default_rxconf;
1498 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1499 socket_id, rx_conf, mp);
1501 if (!dev->data->min_rx_buf_size ||
1502 dev->data->min_rx_buf_size > mbp_buf_size)
1503 dev->data->min_rx_buf_size = mbp_buf_size;
1510 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1511 uint16_t nb_tx_desc, unsigned int socket_id,
1512 const struct rte_eth_txconf *tx_conf)
1514 struct rte_eth_dev *dev;
1515 struct rte_eth_dev_info dev_info;
1517 /* This function is only safe when called from the primary process
1518 * in a multi-process setup*/
1519 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1521 if (!rte_eth_dev_is_valid_port(port_id)) {
1522 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1526 dev = &rte_eth_devices[port_id];
1527 if (tx_queue_id >= dev->data->nb_tx_queues) {
1528 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1532 if (dev->data->dev_started) {
1534 "port %d must be stopped to allow configuration\n", port_id);
1538 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1539 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1541 rte_eth_dev_info_get(port_id, &dev_info);
1543 if (tx_conf == NULL)
1544 tx_conf = &dev_info.default_txconf;
1546 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1547 socket_id, tx_conf);
1551 rte_eth_promiscuous_enable(uint8_t port_id)
1553 struct rte_eth_dev *dev;
1555 if (!rte_eth_dev_is_valid_port(port_id)) {
1556 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1560 dev = &rte_eth_devices[port_id];
1562 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1563 (*dev->dev_ops->promiscuous_enable)(dev);
1564 dev->data->promiscuous = 1;
1568 rte_eth_promiscuous_disable(uint8_t port_id)
1570 struct rte_eth_dev *dev;
1572 if (!rte_eth_dev_is_valid_port(port_id)) {
1573 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1577 dev = &rte_eth_devices[port_id];
1579 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1580 dev->data->promiscuous = 0;
1581 (*dev->dev_ops->promiscuous_disable)(dev);
1585 rte_eth_promiscuous_get(uint8_t port_id)
1587 struct rte_eth_dev *dev;
1589 if (!rte_eth_dev_is_valid_port(port_id)) {
1590 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1594 dev = &rte_eth_devices[port_id];
1595 return dev->data->promiscuous;
1599 rte_eth_allmulticast_enable(uint8_t port_id)
1601 struct rte_eth_dev *dev;
1603 if (!rte_eth_dev_is_valid_port(port_id)) {
1604 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1608 dev = &rte_eth_devices[port_id];
1610 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1611 (*dev->dev_ops->allmulticast_enable)(dev);
1612 dev->data->all_multicast = 1;
1616 rte_eth_allmulticast_disable(uint8_t port_id)
1618 struct rte_eth_dev *dev;
1620 if (!rte_eth_dev_is_valid_port(port_id)) {
1621 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1625 dev = &rte_eth_devices[port_id];
1627 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1628 dev->data->all_multicast = 0;
1629 (*dev->dev_ops->allmulticast_disable)(dev);
1633 rte_eth_allmulticast_get(uint8_t port_id)
1635 struct rte_eth_dev *dev;
1637 if (!rte_eth_dev_is_valid_port(port_id)) {
1638 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1642 dev = &rte_eth_devices[port_id];
1643 return dev->data->all_multicast;
1647 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1648 struct rte_eth_link *link)
1650 struct rte_eth_link *dst = link;
1651 struct rte_eth_link *src = &(dev->data->dev_link);
1653 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1654 *(uint64_t *)src) == 0)
1661 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1663 struct rte_eth_dev *dev;
1665 if (!rte_eth_dev_is_valid_port(port_id)) {
1666 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1670 dev = &rte_eth_devices[port_id];
1672 if (dev->data->dev_conf.intr_conf.lsc != 0)
1673 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1675 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1676 (*dev->dev_ops->link_update)(dev, 1);
1677 *eth_link = dev->data->dev_link;
1682 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1684 struct rte_eth_dev *dev;
1686 if (!rte_eth_dev_is_valid_port(port_id)) {
1687 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1691 dev = &rte_eth_devices[port_id];
1693 if (dev->data->dev_conf.intr_conf.lsc != 0)
1694 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1696 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1697 (*dev->dev_ops->link_update)(dev, 0);
1698 *eth_link = dev->data->dev_link;
1703 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1705 struct rte_eth_dev *dev;
1707 if (!rte_eth_dev_is_valid_port(port_id)) {
1708 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1712 dev = &rte_eth_devices[port_id];
1713 memset(stats, 0, sizeof(*stats));
1715 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1716 (*dev->dev_ops->stats_get)(dev, stats);
1717 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1722 rte_eth_stats_reset(uint8_t port_id)
1724 struct rte_eth_dev *dev;
1726 if (!rte_eth_dev_is_valid_port(port_id)) {
1727 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1731 dev = &rte_eth_devices[port_id];
1733 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1734 (*dev->dev_ops->stats_reset)(dev);
1737 /* retrieve ethdev extended statistics */
1739 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1742 struct rte_eth_stats eth_stats;
1743 struct rte_eth_dev *dev;
1744 unsigned count, i, q;
1748 if (!rte_eth_dev_is_valid_port(port_id)) {
1749 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1753 dev = &rte_eth_devices[port_id];
1755 /* implemented by the driver */
1756 if (dev->dev_ops->xstats_get != NULL)
1757 return (*dev->dev_ops->xstats_get)(dev, xstats, n);
1759 /* else, return generic statistics */
1760 count = RTE_NB_STATS;
1761 count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
1762 count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
1766 /* now fill the xstats structure */
1769 memset(ð_stats, 0, sizeof(eth_stats));
1770 rte_eth_stats_get(port_id, ð_stats);
1773 for (i = 0; i < RTE_NB_STATS; i++) {
1774 stats_ptr = (char *)ð_stats + rte_stats_strings[i].offset;
1775 val = *(uint64_t *)stats_ptr;
1776 snprintf(xstats[count].name, sizeof(xstats[count].name),
1777 "%s", rte_stats_strings[i].name);
1778 xstats[count++].value = val;
1782 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1783 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1784 stats_ptr = (char *)ð_stats;
1785 stats_ptr += rte_rxq_stats_strings[i].offset;
1786 stats_ptr += q * sizeof(uint64_t);
1787 val = *(uint64_t *)stats_ptr;
1788 snprintf(xstats[count].name, sizeof(xstats[count].name),
1789 "rx_queue_%u_%s", q,
1790 rte_rxq_stats_strings[i].name);
1791 xstats[count++].value = val;
1796 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1797 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1798 stats_ptr = (char *)ð_stats;
1799 stats_ptr += rte_txq_stats_strings[i].offset;
1800 stats_ptr += q * sizeof(uint64_t);
1801 val = *(uint64_t *)stats_ptr;
1802 snprintf(xstats[count].name, sizeof(xstats[count].name),
1803 "tx_queue_%u_%s", q,
1804 rte_txq_stats_strings[i].name);
1805 xstats[count++].value = val;
1812 /* reset ethdev extended statistics */
1814 rte_eth_xstats_reset(uint8_t port_id)
1816 struct rte_eth_dev *dev;
1818 if (!rte_eth_dev_is_valid_port(port_id)) {
1819 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1823 dev = &rte_eth_devices[port_id];
1825 /* implemented by the driver */
1826 if (dev->dev_ops->xstats_reset != NULL) {
1827 (*dev->dev_ops->xstats_reset)(dev);
1831 /* fallback to default */
1832 rte_eth_stats_reset(port_id);
1836 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1839 struct rte_eth_dev *dev;
1841 if (!rte_eth_dev_is_valid_port(port_id)) {
1842 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1846 dev = &rte_eth_devices[port_id];
1848 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1849 return (*dev->dev_ops->queue_stats_mapping_set)
1850 (dev, queue_id, stat_idx, is_rx);
1855 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1858 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1864 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1867 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1873 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1875 struct rte_eth_dev *dev;
1877 if (!rte_eth_dev_is_valid_port(port_id)) {
1878 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1882 dev = &rte_eth_devices[port_id];
1884 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1886 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1887 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1888 dev_info->pci_dev = dev->pci_dev;
1890 dev_info->driver_name = dev->driver->pci_drv.name;
1894 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1896 struct rte_eth_dev *dev;
1898 if (!rte_eth_dev_is_valid_port(port_id)) {
1899 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1903 dev = &rte_eth_devices[port_id];
1904 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1909 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1911 struct rte_eth_dev *dev;
1913 if (!rte_eth_dev_is_valid_port(port_id)) {
1914 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1918 dev = &rte_eth_devices[port_id];
1919 *mtu = dev->data->mtu;
1924 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1927 struct rte_eth_dev *dev;
1929 if (!rte_eth_dev_is_valid_port(port_id)) {
1930 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1934 dev = &rte_eth_devices[port_id];
1935 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1937 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1939 dev->data->mtu = mtu;
1945 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1947 struct rte_eth_dev *dev;
1949 if (!rte_eth_dev_is_valid_port(port_id)) {
1950 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1954 dev = &rte_eth_devices[port_id];
1955 if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1956 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1960 if (vlan_id > 4095) {
1961 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1962 port_id, (unsigned) vlan_id);
1965 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1967 return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1971 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1973 struct rte_eth_dev *dev;
1975 if (!rte_eth_dev_is_valid_port(port_id)) {
1976 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1980 dev = &rte_eth_devices[port_id];
1981 if (rx_queue_id >= dev->data->nb_rx_queues) {
1982 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1986 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1987 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1993 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1995 struct rte_eth_dev *dev;
1997 if (!rte_eth_dev_is_valid_port(port_id)) {
1998 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2002 dev = &rte_eth_devices[port_id];
2003 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
2004 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
2010 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
2012 struct rte_eth_dev *dev;
2017 if (!rte_eth_dev_is_valid_port(port_id)) {
2018 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2022 dev = &rte_eth_devices[port_id];
2024 /*check which option changed by application*/
2025 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
2026 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
2028 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
2029 mask |= ETH_VLAN_STRIP_MASK;
2032 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
2033 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
2035 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
2036 mask |= ETH_VLAN_FILTER_MASK;
2039 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
2040 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
2042 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
2043 mask |= ETH_VLAN_EXTEND_MASK;
2050 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
2051 (*dev->dev_ops->vlan_offload_set)(dev, mask);
2057 rte_eth_dev_get_vlan_offload(uint8_t port_id)
2059 struct rte_eth_dev *dev;
2062 if (!rte_eth_dev_is_valid_port(port_id)) {
2063 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2067 dev = &rte_eth_devices[port_id];
2069 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
2070 ret |= ETH_VLAN_STRIP_OFFLOAD ;
2072 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
2073 ret |= ETH_VLAN_FILTER_OFFLOAD ;
2075 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
2076 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
2082 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
2084 struct rte_eth_dev *dev;
2086 if (!rte_eth_dev_is_valid_port(port_id)) {
2087 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2091 dev = &rte_eth_devices[port_id];
2092 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
2093 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
2099 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
2100 struct rte_fdir_filter *fdir_filter,
2103 struct rte_eth_dev *dev;
2105 if (!rte_eth_dev_is_valid_port(port_id)) {
2106 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2110 dev = &rte_eth_devices[port_id];
2112 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
2113 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2114 port_id, dev->data->dev_conf.fdir_conf.mode);
2118 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2119 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2120 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2121 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
2122 "None l4type, source & destinations ports " \
2123 "should be null!\n");
2127 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
2128 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
2133 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
2134 struct rte_fdir_filter *fdir_filter,
2137 struct rte_eth_dev *dev;
2139 if (!rte_eth_dev_is_valid_port(port_id)) {
2140 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2144 dev = &rte_eth_devices[port_id];
2146 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
2147 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2148 port_id, dev->data->dev_conf.fdir_conf.mode);
2152 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2153 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2154 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2155 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
2156 "None l4type, source & destinations ports " \
2157 "should be null!\n");
2161 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
2162 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
2168 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
2169 struct rte_fdir_filter *fdir_filter)
2171 struct rte_eth_dev *dev;
2173 if (!rte_eth_dev_is_valid_port(port_id)) {
2174 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2178 dev = &rte_eth_devices[port_id];
2180 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
2181 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2182 port_id, dev->data->dev_conf.fdir_conf.mode);
2186 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2187 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2188 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2189 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
2190 "None l4type source & destinations ports " \
2191 "should be null!\n");
2195 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
2196 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
2200 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
2202 struct rte_eth_dev *dev;
2204 if (!rte_eth_dev_is_valid_port(port_id)) {
2205 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2209 dev = &rte_eth_devices[port_id];
2210 if (! (dev->data->dev_conf.fdir_conf.mode)) {
2211 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
2215 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
2217 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
2222 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
2223 struct rte_fdir_filter *fdir_filter,
2224 uint16_t soft_id, uint8_t queue,
2227 struct rte_eth_dev *dev;
2229 if (!rte_eth_dev_is_valid_port(port_id)) {
2230 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2234 dev = &rte_eth_devices[port_id];
2236 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
2237 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2238 port_id, dev->data->dev_conf.fdir_conf.mode);
2242 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2243 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2244 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2245 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
2246 "None l4type, source & destinations ports " \
2247 "should be null!\n");
2251 /* For now IPv6 is not supported with perfect filter */
2252 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2255 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
2256 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
2262 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
2263 struct rte_fdir_filter *fdir_filter,
2264 uint16_t soft_id, uint8_t queue,
2267 struct rte_eth_dev *dev;
2269 if (!rte_eth_dev_is_valid_port(port_id)) {
2270 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2274 dev = &rte_eth_devices[port_id];
2276 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
2277 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2278 port_id, dev->data->dev_conf.fdir_conf.mode);
2282 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2283 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2284 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2285 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
2286 "None l4type, source & destinations ports " \
2287 "should be null!\n");
2291 /* For now IPv6 is not supported with perfect filter */
2292 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2295 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
2296 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
2297 soft_id, queue, drop);
2301 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
2302 struct rte_fdir_filter *fdir_filter,
2305 struct rte_eth_dev *dev;
2307 if (!rte_eth_dev_is_valid_port(port_id)) {
2308 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2312 dev = &rte_eth_devices[port_id];
2314 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
2315 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2316 port_id, dev->data->dev_conf.fdir_conf.mode);
2320 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2321 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2322 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2323 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
2324 "None l4type, source & destinations ports " \
2325 "should be null!\n");
2329 /* For now IPv6 is not supported with perfect filter */
2330 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2333 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
2334 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
2339 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
2341 struct rte_eth_dev *dev;
2343 if (!rte_eth_dev_is_valid_port(port_id)) {
2344 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2348 dev = &rte_eth_devices[port_id];
2349 if (! (dev->data->dev_conf.fdir_conf.mode)) {
2350 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
2354 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
2355 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
2359 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2361 struct rte_eth_dev *dev;
2363 if (!rte_eth_dev_is_valid_port(port_id)) {
2364 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2368 dev = &rte_eth_devices[port_id];
2369 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2370 memset(fc_conf, 0, sizeof(*fc_conf));
2371 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
2375 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2377 struct rte_eth_dev *dev;
2379 if (!rte_eth_dev_is_valid_port(port_id)) {
2380 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2384 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2385 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2389 dev = &rte_eth_devices[port_id];
2390 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2391 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
2395 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
2397 struct rte_eth_dev *dev;
2399 if (!rte_eth_dev_is_valid_port(port_id)) {
2400 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2404 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2405 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2409 dev = &rte_eth_devices[port_id];
2410 /* High water, low water validation are device specific */
2411 if (*dev->dev_ops->priority_flow_ctrl_set)
2412 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
2417 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2425 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
2426 PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
2427 RTE_RETA_GROUP_SIZE);
2431 num = reta_size / RTE_RETA_GROUP_SIZE;
2432 for (i = 0; i < num; i++) {
2433 if (reta_conf[i].mask)
2441 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2445 uint16_t i, idx, shift;
2451 PMD_DEBUG_TRACE("No receive queue is available\n");
2455 for (i = 0; i < reta_size; i++) {
2456 idx = i / RTE_RETA_GROUP_SIZE;
2457 shift = i % RTE_RETA_GROUP_SIZE;
2458 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2459 (reta_conf[idx].reta[shift] >= max_rxq)) {
2460 PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2461 "the maximum rxq index: %u\n", idx, shift,
2462 reta_conf[idx].reta[shift], max_rxq);
2471 rte_eth_dev_rss_reta_update(uint8_t port_id,
2472 struct rte_eth_rss_reta_entry64 *reta_conf,
2475 struct rte_eth_dev *dev;
2478 if (!rte_eth_dev_is_valid_port(port_id)) {
2479 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2483 /* Check mask bits */
2484 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2488 dev = &rte_eth_devices[port_id];
2490 /* Check entry value */
2491 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2492 dev->data->nb_rx_queues);
2496 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2497 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2501 rte_eth_dev_rss_reta_query(uint8_t port_id,
2502 struct rte_eth_rss_reta_entry64 *reta_conf,
2505 struct rte_eth_dev *dev;
2508 if (port_id >= nb_ports) {
2509 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2513 /* Check mask bits */
2514 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2518 dev = &rte_eth_devices[port_id];
2519 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2520 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2524 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2526 struct rte_eth_dev *dev;
2527 uint16_t rss_hash_protos;
2529 if (!rte_eth_dev_is_valid_port(port_id)) {
2530 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2534 rss_hash_protos = rss_conf->rss_hf;
2535 if ((rss_hash_protos != 0) &&
2536 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2537 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2541 dev = &rte_eth_devices[port_id];
2542 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2543 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2547 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2548 struct rte_eth_rss_conf *rss_conf)
2550 struct rte_eth_dev *dev;
2552 if (!rte_eth_dev_is_valid_port(port_id)) {
2553 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2557 dev = &rte_eth_devices[port_id];
2558 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2559 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2563 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
2564 struct rte_eth_udp_tunnel *udp_tunnel)
2566 struct rte_eth_dev *dev;
2568 if (!rte_eth_dev_is_valid_port(port_id)) {
2569 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2573 if (udp_tunnel == NULL) {
2574 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2578 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2579 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2583 dev = &rte_eth_devices[port_id];
2584 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
2585 return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
2589 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
2590 struct rte_eth_udp_tunnel *udp_tunnel)
2592 struct rte_eth_dev *dev;
2594 if (!rte_eth_dev_is_valid_port(port_id)) {
2595 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2599 dev = &rte_eth_devices[port_id];
2601 if (udp_tunnel == NULL) {
2602 PMD_DEBUG_TRACE("Invalid udp_tunnel parametr\n");
2606 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2607 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2611 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2612 return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2616 rte_eth_led_on(uint8_t port_id)
2618 struct rte_eth_dev *dev;
2620 if (!rte_eth_dev_is_valid_port(port_id)) {
2621 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2625 dev = &rte_eth_devices[port_id];
2626 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2627 return (*dev->dev_ops->dev_led_on)(dev);
2631 rte_eth_led_off(uint8_t port_id)
2633 struct rte_eth_dev *dev;
2635 if (!rte_eth_dev_is_valid_port(port_id)) {
2636 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2640 dev = &rte_eth_devices[port_id];
2641 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2642 return (*dev->dev_ops->dev_led_off)(dev);
2646 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2650 get_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2652 struct rte_eth_dev_info dev_info;
2653 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2656 rte_eth_dev_info_get(port_id, &dev_info);
2658 for (i = 0; i < dev_info.max_mac_addrs; i++)
2659 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2665 static const struct ether_addr null_mac_addr;
2668 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2671 struct rte_eth_dev *dev;
2675 if (!rte_eth_dev_is_valid_port(port_id)) {
2676 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2680 dev = &rte_eth_devices[port_id];
2681 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2683 if (is_zero_ether_addr(addr)) {
2684 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2688 if (pool >= ETH_64_POOLS) {
2689 PMD_DEBUG_TRACE("pool id must be 0-%d\n",ETH_64_POOLS - 1);
2693 index = get_mac_addr_index(port_id, addr);
2695 index = get_mac_addr_index(port_id, &null_mac_addr);
2697 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2702 pool_mask = dev->data->mac_pool_sel[index];
2704 /* Check if both MAC address and pool is alread there, and do nothing */
2705 if (pool_mask & (1ULL << pool))
2710 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2712 /* Update address in NIC data structure */
2713 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2715 /* Update pool bitmap in NIC data structure */
2716 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2722 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2724 struct rte_eth_dev *dev;
2727 if (!rte_eth_dev_is_valid_port(port_id)) {
2728 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2732 dev = &rte_eth_devices[port_id];
2733 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2735 index = get_mac_addr_index(port_id, addr);
2737 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2739 } else if (index < 0)
2740 return 0; /* Do nothing if address wasn't found */
2743 (*dev->dev_ops->mac_addr_remove)(dev, index);
2745 /* Update address in NIC data structure */
2746 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2748 /* reset pool bitmap */
2749 dev->data->mac_pool_sel[index] = 0;
2755 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2756 uint16_t rx_mode, uint8_t on)
2759 struct rte_eth_dev *dev;
2760 struct rte_eth_dev_info dev_info;
2762 if (!rte_eth_dev_is_valid_port(port_id)) {
2763 PMD_DEBUG_TRACE("set VF RX mode:Invalid port_id=%d\n",
2768 dev = &rte_eth_devices[port_id];
2769 rte_eth_dev_info_get(port_id, &dev_info);
2771 num_vfs = dev_info.max_vfs;
2774 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2779 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2782 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2783 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2787 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2791 get_hash_mac_addr_index(uint8_t port_id, const struct ether_addr *addr)
2793 struct rte_eth_dev_info dev_info;
2794 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2797 rte_eth_dev_info_get(port_id, &dev_info);
2798 if (!dev->data->hash_mac_addrs)
2801 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2802 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2803 ETHER_ADDR_LEN) == 0)
2810 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2815 struct rte_eth_dev *dev;
2817 if (!rte_eth_dev_is_valid_port(port_id)) {
2818 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2823 dev = &rte_eth_devices[port_id];
2824 if (is_zero_ether_addr(addr)) {
2825 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2830 index = get_hash_mac_addr_index(port_id, addr);
2831 /* Check if it's already there, and do nothing */
2832 if ((index >= 0) && (on))
2837 PMD_DEBUG_TRACE("port %d: the MAC address was not"
2838 "set in UTA\n", port_id);
2842 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2844 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2850 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2851 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2853 /* Update address in NIC data structure */
2855 ether_addr_copy(addr,
2856 &dev->data->hash_mac_addrs[index]);
2858 ether_addr_copy(&null_mac_addr,
2859 &dev->data->hash_mac_addrs[index]);
2866 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2868 struct rte_eth_dev *dev;
2870 if (!rte_eth_dev_is_valid_port(port_id)) {
2871 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2876 dev = &rte_eth_devices[port_id];
2878 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2879 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2883 rte_eth_dev_set_vf_rx(uint8_t port_id,uint16_t vf, uint8_t on)
2886 struct rte_eth_dev *dev;
2887 struct rte_eth_dev_info dev_info;
2889 if (!rte_eth_dev_is_valid_port(port_id)) {
2890 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2894 dev = &rte_eth_devices[port_id];
2895 rte_eth_dev_info_get(port_id, &dev_info);
2897 num_vfs = dev_info.max_vfs;
2900 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2904 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2905 return (*dev->dev_ops->set_vf_rx)(dev, vf,on);
2909 rte_eth_dev_set_vf_tx(uint8_t port_id,uint16_t vf, uint8_t on)
2912 struct rte_eth_dev *dev;
2913 struct rte_eth_dev_info dev_info;
2915 if (!rte_eth_dev_is_valid_port(port_id)) {
2916 PMD_DEBUG_TRACE("set pool tx:Invalid port_id=%d\n", port_id);
2920 dev = &rte_eth_devices[port_id];
2921 rte_eth_dev_info_get(port_id, &dev_info);
2923 num_vfs = dev_info.max_vfs;
2926 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2930 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2931 return (*dev->dev_ops->set_vf_tx)(dev, vf,on);
2935 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2936 uint64_t vf_mask,uint8_t vlan_on)
2938 struct rte_eth_dev *dev;
2940 if (!rte_eth_dev_is_valid_port(port_id)) {
2941 PMD_DEBUG_TRACE("VF VLAN filter:invalid port id=%d\n",
2945 dev = &rte_eth_devices[port_id];
2947 if(vlan_id > ETHER_MAX_VLAN_ID)
2949 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2955 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2959 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2960 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2964 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2967 struct rte_eth_dev *dev;
2968 struct rte_eth_dev_info dev_info;
2969 struct rte_eth_link link;
2971 if (!rte_eth_dev_is_valid_port(port_id)) {
2972 PMD_DEBUG_TRACE("set queue rate limit:invalid port id=%d\n",
2977 dev = &rte_eth_devices[port_id];
2978 rte_eth_dev_info_get(port_id, &dev_info);
2979 link = dev->data->dev_link;
2981 if (queue_idx > dev_info.max_tx_queues) {
2982 PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2983 "invalid queue id=%d\n", port_id, queue_idx);
2987 if (tx_rate > link.link_speed) {
2988 PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2989 "bigger than link speed= %d\n",
2990 tx_rate, link.link_speed);
2994 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2995 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2998 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
3001 struct rte_eth_dev *dev;
3002 struct rte_eth_dev_info dev_info;
3003 struct rte_eth_link link;
3008 if (!rte_eth_dev_is_valid_port(port_id)) {
3009 PMD_DEBUG_TRACE("set VF rate limit:invalid port id=%d\n",
3014 dev = &rte_eth_devices[port_id];
3015 rte_eth_dev_info_get(port_id, &dev_info);
3016 link = dev->data->dev_link;
3018 if (vf > dev_info.max_vfs) {
3019 PMD_DEBUG_TRACE("set VF rate limit:port %d: "
3020 "invalid vf id=%d\n", port_id, vf);
3024 if (tx_rate > link.link_speed) {
3025 PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
3026 "bigger than link speed= %d\n",
3027 tx_rate, link.link_speed);
3031 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
3032 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
3036 rte_eth_mirror_rule_set(uint8_t port_id,
3037 struct rte_eth_vmdq_mirror_conf *mirror_conf,
3038 uint8_t rule_id, uint8_t on)
3040 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3042 if (!rte_eth_dev_is_valid_port(port_id)) {
3043 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3047 if (mirror_conf->rule_type_mask == 0) {
3048 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
3052 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
3053 PMD_DEBUG_TRACE("Invalid dst pool, pool id must"
3054 "be 0-%d\n",ETH_64_POOLS - 1);
3058 if ((mirror_conf->rule_type_mask & ETH_VMDQ_POOL_MIRROR) &&
3059 (mirror_conf->pool_mask == 0)) {
3060 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not"
3065 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
3067 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
3068 ETH_VMDQ_NUM_MIRROR_RULE - 1);
3072 dev = &rte_eth_devices[port_id];
3073 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
3075 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
3079 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
3081 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3083 if (!rte_eth_dev_is_valid_port(port_id)) {
3084 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3088 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
3090 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
3091 ETH_VMDQ_NUM_MIRROR_RULE-1);
3095 dev = &rte_eth_devices[port_id];
3096 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
3098 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
3101 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
3103 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
3104 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
3106 struct rte_eth_dev *dev;
3108 if (!rte_eth_dev_is_valid_port(port_id)) {
3109 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3113 dev = &rte_eth_devices[port_id];
3114 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);
3115 if (queue_id >= dev->data->nb_rx_queues) {
3116 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3119 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
3124 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
3125 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
3127 struct rte_eth_dev *dev;
3129 if (!rte_eth_dev_is_valid_port(port_id)) {
3130 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3134 dev = &rte_eth_devices[port_id];
3136 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0);
3137 if (queue_id >= dev->data->nb_tx_queues) {
3138 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3141 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
3146 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
3148 struct rte_eth_dev *dev;
3150 if (!rte_eth_dev_is_valid_port(port_id)) {
3151 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3155 dev = &rte_eth_devices[port_id];
3156 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0);
3157 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
3161 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
3163 struct rte_eth_dev *dev;
3165 if (!rte_eth_dev_is_valid_port(port_id)) {
3166 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3170 dev = &rte_eth_devices[port_id];
3171 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
3172 return (*dev->dev_ops->rx_descriptor_done)( \
3173 dev->data->rx_queues[queue_id], offset);
3178 rte_eth_dev_callback_register(uint8_t port_id,
3179 enum rte_eth_event_type event,
3180 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
3182 struct rte_eth_dev *dev;
3183 struct rte_eth_dev_callback *user_cb;
3188 if (!rte_eth_dev_is_valid_port(port_id)) {
3189 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3193 dev = &rte_eth_devices[port_id];
3194 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3196 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
3197 if (user_cb->cb_fn == cb_fn &&
3198 user_cb->cb_arg == cb_arg &&
3199 user_cb->event == event) {
3204 /* create a new callback. */
3205 if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
3206 sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
3207 user_cb->cb_fn = cb_fn;
3208 user_cb->cb_arg = cb_arg;
3209 user_cb->event = event;
3210 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
3213 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3214 return (user_cb == NULL) ? -ENOMEM : 0;
3218 rte_eth_dev_callback_unregister(uint8_t port_id,
3219 enum rte_eth_event_type event,
3220 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
3223 struct rte_eth_dev *dev;
3224 struct rte_eth_dev_callback *cb, *next;
3229 if (!rte_eth_dev_is_valid_port(port_id)) {
3230 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3234 dev = &rte_eth_devices[port_id];
3235 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3238 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
3240 next = TAILQ_NEXT(cb, next);
3242 if (cb->cb_fn != cb_fn || cb->event != event ||
3243 (cb->cb_arg != (void *)-1 &&
3244 cb->cb_arg != cb_arg))
3248 * if this callback is not executing right now,
3251 if (cb->active == 0) {
3252 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
3259 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3264 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
3265 enum rte_eth_event_type event)
3267 struct rte_eth_dev_callback *cb_lst;
3268 struct rte_eth_dev_callback dev_cb;
3270 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3271 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
3272 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
3276 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3277 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
3279 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3282 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3284 #ifdef RTE_NIC_BYPASS
3285 int rte_eth_dev_bypass_init(uint8_t port_id)
3287 struct rte_eth_dev *dev;
3289 if (!rte_eth_dev_is_valid_port(port_id)) {
3290 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3294 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3295 PMD_DEBUG_TRACE("Invalid port device\n");
3299 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
3300 (*dev->dev_ops->bypass_init)(dev);
3305 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
3307 struct rte_eth_dev *dev;
3309 if (!rte_eth_dev_is_valid_port(port_id)) {
3310 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3314 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3315 PMD_DEBUG_TRACE("Invalid port device\n");
3318 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
3319 (*dev->dev_ops->bypass_state_show)(dev, state);
3324 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
3326 struct rte_eth_dev *dev;
3328 if (!rte_eth_dev_is_valid_port(port_id)) {
3329 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3333 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3334 PMD_DEBUG_TRACE("Invalid port device\n");
3338 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
3339 (*dev->dev_ops->bypass_state_set)(dev, new_state);
3344 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
3346 struct rte_eth_dev *dev;
3348 if (!rte_eth_dev_is_valid_port(port_id)) {
3349 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3353 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3354 PMD_DEBUG_TRACE("Invalid port device\n");
3358 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
3359 (*dev->dev_ops->bypass_event_show)(dev, event, state);
3364 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
3366 struct rte_eth_dev *dev;
3368 if (!rte_eth_dev_is_valid_port(port_id)) {
3369 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3373 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3374 PMD_DEBUG_TRACE("Invalid port device\n");
3378 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
3379 (*dev->dev_ops->bypass_event_set)(dev, event, state);
3384 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
3386 struct rte_eth_dev *dev;
3388 if (!rte_eth_dev_is_valid_port(port_id)) {
3389 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3393 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3394 PMD_DEBUG_TRACE("Invalid port device\n");
3398 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
3399 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
3404 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
3406 struct rte_eth_dev *dev;
3408 if (!rte_eth_dev_is_valid_port(port_id)) {
3409 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3413 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3414 PMD_DEBUG_TRACE("Invalid port device\n");
3418 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
3419 (*dev->dev_ops->bypass_ver_show)(dev, ver);
3424 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
3426 struct rte_eth_dev *dev;
3428 if (!rte_eth_dev_is_valid_port(port_id)) {
3429 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3433 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3434 PMD_DEBUG_TRACE("Invalid port device\n");
3438 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
3439 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
3444 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
3446 struct rte_eth_dev *dev;
3448 if (!rte_eth_dev_is_valid_port(port_id)) {
3449 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3453 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3454 PMD_DEBUG_TRACE("Invalid port device\n");
3458 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
3459 (*dev->dev_ops->bypass_wd_reset)(dev);
3465 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
3467 struct rte_eth_dev *dev;
3469 if (!rte_eth_dev_is_valid_port(port_id)) {
3470 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3474 dev = &rte_eth_devices[port_id];
3475 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3476 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3477 RTE_ETH_FILTER_NOP, NULL);
3481 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
3482 enum rte_filter_op filter_op, void *arg)
3484 struct rte_eth_dev *dev;
3486 if (!rte_eth_dev_is_valid_port(port_id)) {
3487 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3491 dev = &rte_eth_devices[port_id];
3492 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3493 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
3497 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
3498 rte_rx_callback_fn fn, void *user_param)
3500 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3501 rte_errno = ENOTSUP;
3504 /* check input parameters */
3505 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3506 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3511 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3519 cb->param = user_param;
3520 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3521 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3526 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
3527 rte_tx_callback_fn fn, void *user_param)
3529 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3530 rte_errno = ENOTSUP;
3533 /* check input parameters */
3534 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3535 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3540 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3548 cb->param = user_param;
3549 cb->next = rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3550 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3555 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3556 struct rte_eth_rxtx_callback *user_cb)
3558 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3561 /* Check input parameters. */
3562 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
3563 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3567 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3568 struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
3569 struct rte_eth_rxtx_callback *prev_cb;
3571 /* Reset head pointer and remove user cb if first in the list. */
3572 if (cb == user_cb) {
3573 dev->post_rx_burst_cbs[queue_id] = user_cb->next;
3577 /* Remove the user cb from the callback list. */
3582 if (cb == user_cb) {
3583 prev_cb->next = user_cb->next;
3587 } while (cb != NULL);
3589 /* Callback wasn't found. */
3594 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3595 struct rte_eth_rxtx_callback *user_cb)
3597 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3600 /* Check input parameters. */
3601 if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
3602 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3606 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3607 struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
3608 struct rte_eth_rxtx_callback *prev_cb;
3610 /* Reset head pointer and remove user cb if first in the list. */
3611 if (cb == user_cb) {
3612 dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
3616 /* Remove the user cb from the callback list. */
3621 if (cb == user_cb) {
3622 prev_cb->next = user_cb->next;
3626 } while (cb != NULL);
3628 /* Callback wasn't found. */