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>
55 #include <rte_tailq.h>
57 #include <rte_per_lcore.h>
58 #include <rte_lcore.h>
59 #include <rte_atomic.h>
60 #include <rte_branch_prediction.h>
61 #include <rte_common.h>
63 #include <rte_mempool.h>
64 #include <rte_malloc.h>
66 #include <rte_errno.h>
67 #include <rte_spinlock.h>
68 #include <rte_string_fns.h>
70 #include "rte_ether.h"
71 #include "rte_ethdev.h"
73 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
74 #define PMD_DEBUG_TRACE(fmt, args...) do { \
75 RTE_LOG(ERR, PMD, "%s: " fmt, __func__, ## args); \
78 #define PMD_DEBUG_TRACE(fmt, args...)
81 /* Macros for checking for restricting functions to primary instance only */
82 #define PROC_PRIMARY_OR_ERR_RET(retval) do { \
83 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
84 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
88 #define PROC_PRIMARY_OR_RET() do { \
89 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
90 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
95 /* Macros to check for invlaid function pointers in dev_ops structure */
96 #define FUNC_PTR_OR_ERR_RET(func, retval) do { \
97 if ((func) == NULL) { \
98 PMD_DEBUG_TRACE("Function not supported\n"); \
102 #define FUNC_PTR_OR_RET(func) do { \
103 if ((func) == NULL) { \
104 PMD_DEBUG_TRACE("Function not supported\n"); \
109 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
110 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
111 static struct rte_eth_dev_data *rte_eth_dev_data = NULL;
112 static uint8_t nb_ports = 0;
114 /* spinlock for eth device callbacks */
115 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
117 /* store statistics names and its offset in stats structure */
118 struct rte_eth_xstats_name_off {
119 char name[RTE_ETH_XSTATS_NAME_SIZE];
123 static struct rte_eth_xstats_name_off rte_stats_strings[] = {
124 {"rx_packets", offsetof(struct rte_eth_stats, ipackets)},
125 {"tx_packets", offsetof(struct rte_eth_stats, opackets)},
126 {"rx_bytes", offsetof(struct rte_eth_stats, ibytes)},
127 {"tx_bytes", offsetof(struct rte_eth_stats, obytes)},
128 {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
129 {"rx_missed_errors", offsetof(struct rte_eth_stats, imissed)},
130 {"rx_crc_errors", offsetof(struct rte_eth_stats, ibadcrc)},
131 {"rx_bad_length_errors", offsetof(struct rte_eth_stats, ibadlen)},
132 {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
133 {"alloc_rx_buff_failed", offsetof(struct rte_eth_stats, rx_nombuf)},
134 {"fdir_match", offsetof(struct rte_eth_stats, fdirmatch)},
135 {"fdir_miss", offsetof(struct rte_eth_stats, fdirmiss)},
136 {"tx_flow_control_xon", offsetof(struct rte_eth_stats, tx_pause_xon)},
137 {"rx_flow_control_xon", offsetof(struct rte_eth_stats, rx_pause_xon)},
138 {"tx_flow_control_xoff", offsetof(struct rte_eth_stats, tx_pause_xoff)},
139 {"rx_flow_control_xoff", offsetof(struct rte_eth_stats, rx_pause_xoff)},
141 #define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
143 static struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
144 {"rx_packets", offsetof(struct rte_eth_stats, q_ipackets)},
145 {"rx_bytes", offsetof(struct rte_eth_stats, q_ibytes)},
147 #define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) / \
148 sizeof(rte_rxq_stats_strings[0]))
150 static struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
151 {"tx_packets", offsetof(struct rte_eth_stats, q_opackets)},
152 {"tx_bytes", offsetof(struct rte_eth_stats, q_obytes)},
153 {"tx_errors", offsetof(struct rte_eth_stats, q_errors)},
155 #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) / \
156 sizeof(rte_txq_stats_strings[0]))
160 * The user application callback description.
162 * It contains callback address to be registered by user application,
163 * the pointer to the parameters for callback, and the event type.
165 struct rte_eth_dev_callback {
166 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
167 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
168 void *cb_arg; /**< Parameter for callback */
169 enum rte_eth_event_type event; /**< Interrupt event type */
170 uint32_t active; /**< Callback is executing */
184 rte_eth_dev_data_alloc(void)
186 const unsigned flags = 0;
187 const struct rte_memzone *mz;
189 if (rte_eal_process_type() == RTE_PROC_PRIMARY){
190 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
191 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
192 rte_socket_id(), flags);
194 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
196 rte_panic("Cannot allocate memzone for ethernet port data\n");
198 rte_eth_dev_data = mz->addr;
199 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
200 memset(rte_eth_dev_data, 0,
201 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
205 rte_eth_dev_allocated(const char *name)
209 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
210 if ((rte_eth_devices[i].attached == DEV_ATTACHED) &&
211 strcmp(rte_eth_devices[i].data->name, name) == 0)
212 return &rte_eth_devices[i];
218 rte_eth_dev_find_free_port(void)
222 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
223 if (rte_eth_devices[i].attached == DEV_DETACHED)
226 return RTE_MAX_ETHPORTS;
230 rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
233 struct rte_eth_dev *eth_dev;
235 port_id = rte_eth_dev_find_free_port();
236 if (port_id == RTE_MAX_ETHPORTS) {
237 PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
241 if (rte_eth_dev_data == NULL)
242 rte_eth_dev_data_alloc();
244 if (rte_eth_dev_allocated(name) != NULL) {
245 PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n", name);
249 eth_dev = &rte_eth_devices[port_id];
250 eth_dev->data = &rte_eth_dev_data[port_id];
251 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
252 eth_dev->data->port_id = port_id;
253 eth_dev->attached = DEV_ATTACHED;
254 eth_dev->dev_type = type;
260 rte_eth_dev_create_unique_device_name(char *name, size_t size,
261 struct rte_pci_device *pci_dev)
265 if ((name == NULL) || (pci_dev == NULL))
268 ret = snprintf(name, size, "%d:%d.%d",
269 pci_dev->addr.bus, pci_dev->addr.devid,
270 pci_dev->addr.function);
277 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
282 eth_dev->attached = 0;
288 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
289 struct rte_pci_device *pci_dev)
291 struct eth_driver *eth_drv;
292 struct rte_eth_dev *eth_dev;
293 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
297 eth_drv = (struct eth_driver *)pci_drv;
299 /* Create unique Ethernet device name using PCI address */
300 rte_eth_dev_create_unique_device_name(ethdev_name,
301 sizeof(ethdev_name), pci_dev);
303 eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
307 if (rte_eal_process_type() == RTE_PROC_PRIMARY){
308 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
309 eth_drv->dev_private_size,
310 RTE_CACHE_LINE_SIZE);
311 if (eth_dev->data->dev_private == NULL)
312 rte_panic("Cannot allocate memzone for private port data\n");
314 eth_dev->pci_dev = pci_dev;
315 eth_dev->driver = eth_drv;
316 eth_dev->data->rx_mbuf_alloc_failed = 0;
318 /* init user callbacks */
319 TAILQ_INIT(&(eth_dev->link_intr_cbs));
322 * Set the default MTU.
324 eth_dev->data->mtu = ETHER_MTU;
326 /* Invoke PMD device initialization function */
327 diag = (*eth_drv->eth_dev_init)(eth_drv, eth_dev);
331 PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x)"
332 " failed\n", pci_drv->name,
333 (unsigned) pci_dev->id.vendor_id,
334 (unsigned) pci_dev->id.device_id);
335 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
336 rte_free(eth_dev->data->dev_private);
337 eth_dev->attached = DEV_DETACHED;
343 rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
345 const struct eth_driver *eth_drv;
346 struct rte_eth_dev *eth_dev;
347 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
353 /* Create unique Ethernet device name using PCI address */
354 rte_eth_dev_create_unique_device_name(ethdev_name,
355 sizeof(ethdev_name), pci_dev);
357 eth_dev = rte_eth_dev_allocated(ethdev_name);
361 eth_drv = (const struct eth_driver *)pci_dev->driver;
363 /* Invoke PMD device uninit function */
364 if (*eth_drv->eth_dev_uninit) {
365 ret = (*eth_drv->eth_dev_uninit)(eth_drv, eth_dev);
370 /* free ether device */
371 rte_eth_dev_release_port(eth_dev);
373 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
374 rte_free(eth_dev->data->dev_private);
376 eth_dev->pci_dev = NULL;
377 eth_dev->driver = NULL;
378 eth_dev->data = NULL;
384 * Register an Ethernet [Poll Mode] driver.
386 * Function invoked by the initialization function of an Ethernet driver
387 * to simultaneously register itself as a PCI driver and as an Ethernet
389 * Invokes the rte_eal_pci_register() function to register the *pci_drv*
390 * structure embedded in the *eth_drv* structure, after having stored the
391 * address of the rte_eth_dev_init() function in the *devinit* field of
392 * the *pci_drv* structure.
393 * During the PCI probing phase, the rte_eth_dev_init() function is
394 * invoked for each PCI [Ethernet device] matching the embedded PCI
395 * identifiers provided by the driver.
398 rte_eth_driver_register(struct eth_driver *eth_drv)
400 eth_drv->pci_drv.devinit = rte_eth_dev_init;
401 eth_drv->pci_drv.devuninit = rte_eth_dev_uninit;
402 rte_eal_pci_register(ð_drv->pci_drv);
406 rte_eth_dev_is_valid_port(uint8_t port_id)
408 if (port_id >= RTE_MAX_ETHPORTS ||
409 rte_eth_devices[port_id].attached != DEV_ATTACHED)
416 rte_eth_dev_socket_id(uint8_t port_id)
418 if (!rte_eth_dev_is_valid_port(port_id))
420 return rte_eth_devices[port_id].pci_dev->numa_node;
424 rte_eth_dev_count(void)
429 static enum rte_eth_dev_type
430 rte_eth_dev_get_device_type(uint8_t port_id)
432 if (!rte_eth_dev_is_valid_port(port_id))
434 return rte_eth_devices[port_id].dev_type;
438 rte_eth_dev_save(struct rte_eth_dev *devs, size_t size)
440 if ((devs == NULL) ||
441 (size != sizeof(struct rte_eth_dev) * RTE_MAX_ETHPORTS))
444 /* save current rte_eth_devices */
445 memcpy(devs, rte_eth_devices, size);
450 rte_eth_dev_get_changed_port(struct rte_eth_dev *devs, uint8_t *port_id)
452 if ((devs == NULL) || (port_id == NULL))
455 /* check which port was attached or detached */
456 for (*port_id = 0; *port_id < RTE_MAX_ETHPORTS; (*port_id)++, devs++) {
457 if (rte_eth_devices[*port_id].attached ^ devs->attached)
464 rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr)
466 if (!rte_eth_dev_is_valid_port(port_id)) {
467 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
472 PMD_DEBUG_TRACE("Null pointer is specified\n");
476 *addr = rte_eth_devices[port_id].pci_dev->addr;
481 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
485 if (!rte_eth_dev_is_valid_port(port_id)) {
486 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
491 PMD_DEBUG_TRACE("Null pointer is specified\n");
495 /* shouldn't check 'rte_eth_devices[i].data',
496 * because it might be overwritten by VDEV PMD */
497 tmp = rte_eth_dev_data[port_id].name;
503 rte_eth_dev_is_detachable(uint8_t port_id)
507 if (port_id >= RTE_MAX_ETHPORTS) {
508 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
512 if (rte_eth_devices[port_id].dev_type == RTE_ETH_DEV_PCI) {
513 switch (rte_eth_devices[port_id].pci_dev->pt_driver) {
515 case RTE_PT_UIO_GENERIC:
523 drv_flags = rte_eth_devices[port_id].driver->pci_drv.drv_flags;
524 return !(drv_flags & RTE_PCI_DRV_DETACHABLE);
527 /* So far, DPDK hotplug function only supports linux */
528 #ifdef RTE_LIBRTE_EAL_HOTPLUG
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 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
745 dev->post_rx_burst_cbs = rte_zmalloc(
746 "ethdev->post_rx_burst_cbs",
747 sizeof(*dev->post_rx_burst_cbs) * nb_queues,
748 RTE_CACHE_LINE_SIZE);
749 if (dev->post_rx_burst_cbs == NULL) {
750 rte_free(dev->data->rx_queues);
751 dev->data->rx_queues = NULL;
752 dev->data->nb_rx_queues = 0;
757 } else { /* re-configure */
758 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
760 rxq = dev->data->rx_queues;
762 for (i = nb_queues; i < old_nb_queues; i++)
763 (*dev->dev_ops->rx_queue_release)(rxq[i]);
764 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
765 RTE_CACHE_LINE_SIZE);
768 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
769 dev->post_rx_burst_cbs = rte_realloc(
770 dev->post_rx_burst_cbs,
771 sizeof(*dev->post_rx_burst_cbs) *
772 nb_queues, RTE_CACHE_LINE_SIZE);
773 if (dev->post_rx_burst_cbs == NULL)
776 if (nb_queues > old_nb_queues) {
777 uint16_t new_qs = nb_queues - old_nb_queues;
778 memset(rxq + old_nb_queues, 0,
779 sizeof(rxq[0]) * new_qs);
780 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
781 memset(dev->post_rx_burst_cbs + old_nb_queues, 0,
782 sizeof(dev->post_rx_burst_cbs[0]) * new_qs);
786 dev->data->rx_queues = rxq;
789 dev->data->nb_rx_queues = nb_queues;
794 rte_eth_dev_rx_queue_start(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 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
802 if (!rte_eth_dev_is_valid_port(port_id)) {
803 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
807 dev = &rte_eth_devices[port_id];
808 if (rx_queue_id >= dev->data->nb_rx_queues) {
809 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
813 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
815 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
820 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
822 struct rte_eth_dev *dev;
824 /* This function is only safe when called from the primary process
825 * in a multi-process setup*/
826 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
828 if (!rte_eth_dev_is_valid_port(port_id)) {
829 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
833 dev = &rte_eth_devices[port_id];
834 if (rx_queue_id >= dev->data->nb_rx_queues) {
835 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
839 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
841 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
846 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
848 struct rte_eth_dev *dev;
850 /* This function is only safe when called from the primary process
851 * in a multi-process setup*/
852 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
854 if (!rte_eth_dev_is_valid_port(port_id)) {
855 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
859 dev = &rte_eth_devices[port_id];
860 if (tx_queue_id >= dev->data->nb_tx_queues) {
861 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
865 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
867 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
872 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
874 struct rte_eth_dev *dev;
876 /* This function is only safe when called from the primary process
877 * in a multi-process setup*/
878 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
880 if (!rte_eth_dev_is_valid_port(port_id)) {
881 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
885 dev = &rte_eth_devices[port_id];
886 if (tx_queue_id >= dev->data->nb_tx_queues) {
887 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
891 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
893 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
898 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
900 uint16_t old_nb_queues = dev->data->nb_tx_queues;
904 if (dev->data->tx_queues == NULL) { /* first time configuration */
905 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
906 sizeof(dev->data->tx_queues[0]) * nb_queues,
907 RTE_CACHE_LINE_SIZE);
908 if (dev->data->tx_queues == NULL) {
909 dev->data->nb_tx_queues = 0;
912 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
913 dev->pre_tx_burst_cbs = rte_zmalloc(
914 "ethdev->pre_tx_burst_cbs",
915 sizeof(*dev->pre_tx_burst_cbs) * nb_queues,
916 RTE_CACHE_LINE_SIZE);
917 if (dev->pre_tx_burst_cbs == NULL) {
918 rte_free(dev->data->tx_queues);
919 dev->data->tx_queues = NULL;
920 dev->data->nb_tx_queues = 0;
925 } else { /* re-configure */
926 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
928 txq = dev->data->tx_queues;
930 for (i = nb_queues; i < old_nb_queues; i++)
931 (*dev->dev_ops->tx_queue_release)(txq[i]);
932 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
933 RTE_CACHE_LINE_SIZE);
936 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
937 dev->pre_tx_burst_cbs = rte_realloc(
938 dev->pre_tx_burst_cbs,
939 sizeof(*dev->pre_tx_burst_cbs) *
940 nb_queues, RTE_CACHE_LINE_SIZE);
941 if (dev->pre_tx_burst_cbs == NULL)
944 if (nb_queues > old_nb_queues) {
945 uint16_t new_qs = nb_queues - old_nb_queues;
946 memset(txq + old_nb_queues, 0,
947 sizeof(txq[0]) * new_qs);
948 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
949 memset(dev->pre_tx_burst_cbs + old_nb_queues, 0,
950 sizeof(dev->pre_tx_burst_cbs[0]) * new_qs);
954 dev->data->tx_queues = txq;
957 dev->data->nb_tx_queues = nb_queues;
962 rte_eth_dev_check_vf_rss_rxq_num(uint8_t port_id, uint16_t nb_rx_q)
964 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
968 RTE_ETH_DEV_SRIOV(dev).active =
972 RTE_ETH_DEV_SRIOV(dev).active =
979 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = nb_rx_q;
980 RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx =
981 dev->pci_dev->max_vfs * nb_rx_q;
987 rte_eth_dev_check_mq_mode(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
988 const struct rte_eth_conf *dev_conf)
990 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
992 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
993 /* check multi-queue mode */
994 if ((dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) ||
995 (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB_RSS) ||
996 (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB)) {
997 /* SRIOV only works in VMDq enable mode */
998 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
1000 "wrong VMDQ mq_mode rx %u tx %u\n",
1002 dev_conf->rxmode.mq_mode,
1003 dev_conf->txmode.mq_mode);
1007 switch (dev_conf->rxmode.mq_mode) {
1008 case ETH_MQ_RX_VMDQ_DCB:
1009 case ETH_MQ_RX_VMDQ_DCB_RSS:
1010 /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
1011 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
1013 "unsupported VMDQ mq_mode rx %u\n",
1014 port_id, dev_conf->rxmode.mq_mode);
1017 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
1019 "Rx mq mode is changed from:"
1020 "mq_mode %u into VMDQ mq_mode %u\n",
1022 dev_conf->rxmode.mq_mode,
1023 dev->data->dev_conf.rxmode.mq_mode);
1024 case ETH_MQ_RX_VMDQ_RSS:
1025 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_RSS;
1026 if (nb_rx_q <= RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)
1027 if (rte_eth_dev_check_vf_rss_rxq_num(port_id, nb_rx_q) != 0) {
1028 PMD_DEBUG_TRACE("ethdev port_id=%d"
1029 " SRIOV active, invalid queue"
1030 " number for VMDQ RSS, allowed"
1031 " value are 1, 2 or 4\n",
1036 default: /* ETH_MQ_RX_VMDQ_ONLY or ETH_MQ_RX_NONE */
1037 /* if nothing mq mode configure, use default scheme */
1038 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
1039 if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
1040 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
1044 switch (dev_conf->txmode.mq_mode) {
1045 case ETH_MQ_TX_VMDQ_DCB:
1046 /* DCB VMDQ in SRIOV mode, not implement yet */
1047 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
1049 "unsupported VMDQ mq_mode tx %u\n",
1050 port_id, dev_conf->txmode.mq_mode);
1052 default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
1053 /* if nothing mq mode configure, use default scheme */
1054 dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
1058 /* check valid queue number */
1059 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
1060 (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
1061 PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
1062 "queue number must less equal to %d\n",
1063 port_id, RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
1067 /* For vmdb+dcb mode check our configuration before we go further */
1068 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB) {
1069 const struct rte_eth_vmdq_dcb_conf *conf;
1071 if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
1072 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
1074 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
1077 conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
1078 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
1079 conf->nb_queue_pools == ETH_32_POOLS)) {
1080 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
1081 "nb_queue_pools must be %d or %d\n",
1082 port_id, ETH_16_POOLS, ETH_32_POOLS);
1086 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
1087 const struct rte_eth_vmdq_dcb_tx_conf *conf;
1089 if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
1090 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
1092 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
1095 conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
1096 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
1097 conf->nb_queue_pools == ETH_32_POOLS)) {
1098 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
1099 "nb_queue_pools != %d or nb_queue_pools "
1101 port_id, ETH_16_POOLS, ETH_32_POOLS);
1106 /* For DCB mode check our configuration before we go further */
1107 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) {
1108 const struct rte_eth_dcb_rx_conf *conf;
1110 if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
1111 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
1113 port_id, ETH_DCB_NUM_QUEUES);
1116 conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
1117 if (! (conf->nb_tcs == ETH_4_TCS ||
1118 conf->nb_tcs == ETH_8_TCS)) {
1119 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
1120 "nb_tcs != %d or nb_tcs "
1122 port_id, ETH_4_TCS, ETH_8_TCS);
1127 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
1128 const struct rte_eth_dcb_tx_conf *conf;
1130 if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
1131 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
1133 port_id, ETH_DCB_NUM_QUEUES);
1136 conf = &(dev_conf->tx_adv_conf.dcb_tx_conf);
1137 if (! (conf->nb_tcs == ETH_4_TCS ||
1138 conf->nb_tcs == ETH_8_TCS)) {
1139 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
1140 "nb_tcs != %d or nb_tcs "
1142 port_id, ETH_4_TCS, ETH_8_TCS);
1151 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
1152 const struct rte_eth_conf *dev_conf)
1154 struct rte_eth_dev *dev;
1155 struct rte_eth_dev_info dev_info;
1158 /* This function is only safe when called from the primary process
1159 * in a multi-process setup*/
1160 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1162 if (!rte_eth_dev_is_valid_port(port_id)) {
1163 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1167 dev = &rte_eth_devices[port_id];
1169 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1170 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
1172 if (dev->data->dev_started) {
1174 "port %d must be stopped to allow configuration\n", port_id);
1179 * Check that the numbers of RX and TX queues are not greater
1180 * than the maximum number of RX and TX queues supported by the
1181 * configured device.
1183 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
1184 if (nb_rx_q > dev_info.max_rx_queues) {
1185 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
1186 port_id, nb_rx_q, dev_info.max_rx_queues);
1190 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
1194 if (nb_tx_q > dev_info.max_tx_queues) {
1195 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
1196 port_id, nb_tx_q, dev_info.max_tx_queues);
1200 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
1204 /* Copy the dev_conf parameter into the dev structure */
1205 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
1208 * If link state interrupt is enabled, check that the
1209 * device supports it.
1211 if (dev_conf->intr_conf.lsc == 1) {
1212 const struct rte_pci_driver *pci_drv = &dev->driver->pci_drv;
1214 if (!(pci_drv->drv_flags & RTE_PCI_DRV_INTR_LSC)) {
1215 PMD_DEBUG_TRACE("driver %s does not support lsc\n",
1222 * If jumbo frames are enabled, check that the maximum RX packet
1223 * length is supported by the configured device.
1225 if (dev_conf->rxmode.jumbo_frame == 1) {
1226 if (dev_conf->rxmode.max_rx_pkt_len >
1227 dev_info.max_rx_pktlen) {
1228 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
1229 " > max valid value %u\n",
1231 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
1232 (unsigned)dev_info.max_rx_pktlen);
1235 else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
1236 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
1237 " < min valid value %u\n",
1239 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
1240 (unsigned)ETHER_MIN_LEN);
1244 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
1245 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
1246 /* Use default value */
1247 dev->data->dev_conf.rxmode.max_rx_pkt_len =
1251 /* multipe queue mode checking */
1252 diag = rte_eth_dev_check_mq_mode(port_id, nb_rx_q, nb_tx_q, dev_conf);
1254 PMD_DEBUG_TRACE("port%d rte_eth_dev_check_mq_mode = %d\n",
1260 * Setup new number of RX/TX queues and reconfigure device.
1262 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
1264 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
1269 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
1271 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
1273 rte_eth_dev_rx_queue_config(dev, 0);
1277 diag = (*dev->dev_ops->dev_configure)(dev);
1279 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
1281 rte_eth_dev_rx_queue_config(dev, 0);
1282 rte_eth_dev_tx_queue_config(dev, 0);
1290 rte_eth_dev_config_restore(uint8_t port_id)
1292 struct rte_eth_dev *dev;
1293 struct rte_eth_dev_info dev_info;
1294 struct ether_addr addr;
1298 dev = &rte_eth_devices[port_id];
1300 rte_eth_dev_info_get(port_id, &dev_info);
1302 if (RTE_ETH_DEV_SRIOV(dev).active)
1303 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
1305 /* replay MAC address configuration */
1306 for (i = 0; i < dev_info.max_mac_addrs; i++) {
1307 addr = dev->data->mac_addrs[i];
1309 /* skip zero address */
1310 if (is_zero_ether_addr(&addr))
1313 /* add address to the hardware */
1314 if (*dev->dev_ops->mac_addr_add &&
1315 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
1316 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
1318 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
1320 /* exit the loop but not return an error */
1325 /* replay promiscuous configuration */
1326 if (rte_eth_promiscuous_get(port_id) == 1)
1327 rte_eth_promiscuous_enable(port_id);
1328 else if (rte_eth_promiscuous_get(port_id) == 0)
1329 rte_eth_promiscuous_disable(port_id);
1331 /* replay allmulticast configuration */
1332 if (rte_eth_allmulticast_get(port_id) == 1)
1333 rte_eth_allmulticast_enable(port_id);
1334 else if (rte_eth_allmulticast_get(port_id) == 0)
1335 rte_eth_allmulticast_disable(port_id);
1339 rte_eth_dev_start(uint8_t port_id)
1341 struct rte_eth_dev *dev;
1344 /* This function is only safe when called from the primary process
1345 * in a multi-process setup*/
1346 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1348 if (!rte_eth_dev_is_valid_port(port_id)) {
1349 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1353 dev = &rte_eth_devices[port_id];
1355 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1357 if (dev->data->dev_started != 0) {
1358 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1359 " already started\n",
1364 diag = (*dev->dev_ops->dev_start)(dev);
1366 dev->data->dev_started = 1;
1370 rte_eth_dev_config_restore(port_id);
1372 if (dev->data->dev_conf.intr_conf.lsc != 0) {
1373 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1374 (*dev->dev_ops->link_update)(dev, 0);
1380 rte_eth_dev_stop(uint8_t port_id)
1382 struct rte_eth_dev *dev;
1384 /* This function is only safe when called from the primary process
1385 * in a multi-process setup*/
1386 PROC_PRIMARY_OR_RET();
1388 if (!rte_eth_dev_is_valid_port(port_id)) {
1389 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1393 dev = &rte_eth_devices[port_id];
1395 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1397 if (dev->data->dev_started == 0) {
1398 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1399 " already stopped\n",
1404 dev->data->dev_started = 0;
1405 (*dev->dev_ops->dev_stop)(dev);
1409 rte_eth_dev_set_link_up(uint8_t port_id)
1411 struct rte_eth_dev *dev;
1413 /* This function is only safe when called from the primary process
1414 * in a multi-process setup*/
1415 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1417 if (!rte_eth_dev_is_valid_port(port_id)) {
1418 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1422 dev = &rte_eth_devices[port_id];
1424 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1425 return (*dev->dev_ops->dev_set_link_up)(dev);
1429 rte_eth_dev_set_link_down(uint8_t port_id)
1431 struct rte_eth_dev *dev;
1433 /* This function is only safe when called from the primary process
1434 * in a multi-process setup*/
1435 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1437 if (!rte_eth_dev_is_valid_port(port_id)) {
1438 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1442 dev = &rte_eth_devices[port_id];
1444 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1445 return (*dev->dev_ops->dev_set_link_down)(dev);
1449 rte_eth_dev_close(uint8_t port_id)
1451 struct rte_eth_dev *dev;
1453 /* This function is only safe when called from the primary process
1454 * in a multi-process setup*/
1455 PROC_PRIMARY_OR_RET();
1457 if (!rte_eth_dev_is_valid_port(port_id)) {
1458 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1462 dev = &rte_eth_devices[port_id];
1464 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1465 dev->data->dev_started = 0;
1466 (*dev->dev_ops->dev_close)(dev);
1470 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1471 uint16_t nb_rx_desc, unsigned int socket_id,
1472 const struct rte_eth_rxconf *rx_conf,
1473 struct rte_mempool *mp)
1476 uint32_t mbp_buf_size;
1477 struct rte_eth_dev *dev;
1478 struct rte_pktmbuf_pool_private *mbp_priv;
1479 struct rte_eth_dev_info dev_info;
1481 /* This function is only safe when called from the primary process
1482 * in a multi-process setup*/
1483 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1485 if (!rte_eth_dev_is_valid_port(port_id)) {
1486 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1490 dev = &rte_eth_devices[port_id];
1491 if (rx_queue_id >= dev->data->nb_rx_queues) {
1492 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1496 if (dev->data->dev_started) {
1498 "port %d must be stopped to allow configuration\n", port_id);
1502 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1503 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1506 * Check the size of the mbuf data buffer.
1507 * This value must be provided in the private data of the memory pool.
1508 * First check that the memory pool has a valid private data.
1510 rte_eth_dev_info_get(port_id, &dev_info);
1511 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1512 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1513 mp->name, (int) mp->private_data_size,
1514 (int) sizeof(struct rte_pktmbuf_pool_private));
1517 mbp_priv = rte_mempool_get_priv(mp);
1518 mbp_buf_size = mbp_priv->mbuf_data_room_size;
1520 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1521 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1522 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1526 (int)(RTE_PKTMBUF_HEADROOM +
1527 dev_info.min_rx_bufsize),
1528 (int)RTE_PKTMBUF_HEADROOM,
1529 (int)dev_info.min_rx_bufsize);
1533 if (rx_conf == NULL)
1534 rx_conf = &dev_info.default_rxconf;
1536 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1537 socket_id, rx_conf, mp);
1539 if (!dev->data->min_rx_buf_size ||
1540 dev->data->min_rx_buf_size > mbp_buf_size)
1541 dev->data->min_rx_buf_size = mbp_buf_size;
1548 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1549 uint16_t nb_tx_desc, unsigned int socket_id,
1550 const struct rte_eth_txconf *tx_conf)
1552 struct rte_eth_dev *dev;
1553 struct rte_eth_dev_info dev_info;
1555 /* This function is only safe when called from the primary process
1556 * in a multi-process setup*/
1557 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1559 if (!rte_eth_dev_is_valid_port(port_id)) {
1560 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1564 dev = &rte_eth_devices[port_id];
1565 if (tx_queue_id >= dev->data->nb_tx_queues) {
1566 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1570 if (dev->data->dev_started) {
1572 "port %d must be stopped to allow configuration\n", port_id);
1576 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1577 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1579 rte_eth_dev_info_get(port_id, &dev_info);
1581 if (tx_conf == NULL)
1582 tx_conf = &dev_info.default_txconf;
1584 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1585 socket_id, tx_conf);
1589 rte_eth_promiscuous_enable(uint8_t port_id)
1591 struct rte_eth_dev *dev;
1593 if (!rte_eth_dev_is_valid_port(port_id)) {
1594 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1598 dev = &rte_eth_devices[port_id];
1600 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1601 (*dev->dev_ops->promiscuous_enable)(dev);
1602 dev->data->promiscuous = 1;
1606 rte_eth_promiscuous_disable(uint8_t port_id)
1608 struct rte_eth_dev *dev;
1610 if (!rte_eth_dev_is_valid_port(port_id)) {
1611 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1615 dev = &rte_eth_devices[port_id];
1617 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1618 dev->data->promiscuous = 0;
1619 (*dev->dev_ops->promiscuous_disable)(dev);
1623 rte_eth_promiscuous_get(uint8_t port_id)
1625 struct rte_eth_dev *dev;
1627 if (!rte_eth_dev_is_valid_port(port_id)) {
1628 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1632 dev = &rte_eth_devices[port_id];
1633 return dev->data->promiscuous;
1637 rte_eth_allmulticast_enable(uint8_t port_id)
1639 struct rte_eth_dev *dev;
1641 if (!rte_eth_dev_is_valid_port(port_id)) {
1642 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1646 dev = &rte_eth_devices[port_id];
1648 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1649 (*dev->dev_ops->allmulticast_enable)(dev);
1650 dev->data->all_multicast = 1;
1654 rte_eth_allmulticast_disable(uint8_t port_id)
1656 struct rte_eth_dev *dev;
1658 if (!rte_eth_dev_is_valid_port(port_id)) {
1659 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1663 dev = &rte_eth_devices[port_id];
1665 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1666 dev->data->all_multicast = 0;
1667 (*dev->dev_ops->allmulticast_disable)(dev);
1671 rte_eth_allmulticast_get(uint8_t port_id)
1673 struct rte_eth_dev *dev;
1675 if (!rte_eth_dev_is_valid_port(port_id)) {
1676 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1680 dev = &rte_eth_devices[port_id];
1681 return dev->data->all_multicast;
1685 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1686 struct rte_eth_link *link)
1688 struct rte_eth_link *dst = link;
1689 struct rte_eth_link *src = &(dev->data->dev_link);
1691 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1692 *(uint64_t *)src) == 0)
1699 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1701 struct rte_eth_dev *dev;
1703 if (!rte_eth_dev_is_valid_port(port_id)) {
1704 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1708 dev = &rte_eth_devices[port_id];
1710 if (dev->data->dev_conf.intr_conf.lsc != 0)
1711 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1713 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1714 (*dev->dev_ops->link_update)(dev, 1);
1715 *eth_link = dev->data->dev_link;
1720 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1722 struct rte_eth_dev *dev;
1724 if (!rte_eth_dev_is_valid_port(port_id)) {
1725 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1729 dev = &rte_eth_devices[port_id];
1731 if (dev->data->dev_conf.intr_conf.lsc != 0)
1732 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1734 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1735 (*dev->dev_ops->link_update)(dev, 0);
1736 *eth_link = dev->data->dev_link;
1741 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1743 struct rte_eth_dev *dev;
1745 if (!rte_eth_dev_is_valid_port(port_id)) {
1746 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1750 dev = &rte_eth_devices[port_id];
1751 memset(stats, 0, sizeof(*stats));
1753 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1754 (*dev->dev_ops->stats_get)(dev, stats);
1755 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1760 rte_eth_stats_reset(uint8_t port_id)
1762 struct rte_eth_dev *dev;
1764 if (!rte_eth_dev_is_valid_port(port_id)) {
1765 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1769 dev = &rte_eth_devices[port_id];
1771 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1772 (*dev->dev_ops->stats_reset)(dev);
1775 /* retrieve ethdev extended statistics */
1777 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1780 struct rte_eth_stats eth_stats;
1781 struct rte_eth_dev *dev;
1782 unsigned count, i, q;
1786 if (!rte_eth_dev_is_valid_port(port_id)) {
1787 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1791 dev = &rte_eth_devices[port_id];
1793 /* implemented by the driver */
1794 if (dev->dev_ops->xstats_get != NULL)
1795 return (*dev->dev_ops->xstats_get)(dev, xstats, n);
1797 /* else, return generic statistics */
1798 count = RTE_NB_STATS;
1799 count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
1800 count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
1804 /* now fill the xstats structure */
1807 memset(ð_stats, 0, sizeof(eth_stats));
1808 rte_eth_stats_get(port_id, ð_stats);
1811 for (i = 0; i < RTE_NB_STATS; i++) {
1812 stats_ptr = (char *)ð_stats + rte_stats_strings[i].offset;
1813 val = *(uint64_t *)stats_ptr;
1814 snprintf(xstats[count].name, sizeof(xstats[count].name),
1815 "%s", rte_stats_strings[i].name);
1816 xstats[count++].value = val;
1820 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1821 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1822 stats_ptr = (char *)ð_stats;
1823 stats_ptr += rte_rxq_stats_strings[i].offset;
1824 stats_ptr += q * sizeof(uint64_t);
1825 val = *(uint64_t *)stats_ptr;
1826 snprintf(xstats[count].name, sizeof(xstats[count].name),
1827 "rx_queue_%u_%s", q,
1828 rte_rxq_stats_strings[i].name);
1829 xstats[count++].value = val;
1834 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1835 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1836 stats_ptr = (char *)ð_stats;
1837 stats_ptr += rte_txq_stats_strings[i].offset;
1838 stats_ptr += q * sizeof(uint64_t);
1839 val = *(uint64_t *)stats_ptr;
1840 snprintf(xstats[count].name, sizeof(xstats[count].name),
1841 "tx_queue_%u_%s", q,
1842 rte_txq_stats_strings[i].name);
1843 xstats[count++].value = val;
1850 /* reset ethdev extended statistics */
1852 rte_eth_xstats_reset(uint8_t port_id)
1854 struct rte_eth_dev *dev;
1856 if (!rte_eth_dev_is_valid_port(port_id)) {
1857 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1861 dev = &rte_eth_devices[port_id];
1863 /* implemented by the driver */
1864 if (dev->dev_ops->xstats_reset != NULL) {
1865 (*dev->dev_ops->xstats_reset)(dev);
1869 /* fallback to default */
1870 rte_eth_stats_reset(port_id);
1874 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1877 struct rte_eth_dev *dev;
1879 if (!rte_eth_dev_is_valid_port(port_id)) {
1880 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1884 dev = &rte_eth_devices[port_id];
1886 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1887 return (*dev->dev_ops->queue_stats_mapping_set)
1888 (dev, queue_id, stat_idx, is_rx);
1893 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1896 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1902 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1905 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1911 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1913 struct rte_eth_dev *dev;
1915 if (!rte_eth_dev_is_valid_port(port_id)) {
1916 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1920 dev = &rte_eth_devices[port_id];
1922 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1924 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1925 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1926 dev_info->pci_dev = dev->pci_dev;
1928 dev_info->driver_name = dev->driver->pci_drv.name;
1932 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1934 struct rte_eth_dev *dev;
1936 if (!rte_eth_dev_is_valid_port(port_id)) {
1937 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1941 dev = &rte_eth_devices[port_id];
1942 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1947 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1949 struct rte_eth_dev *dev;
1951 if (!rte_eth_dev_is_valid_port(port_id)) {
1952 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1956 dev = &rte_eth_devices[port_id];
1957 *mtu = dev->data->mtu;
1962 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1965 struct rte_eth_dev *dev;
1967 if (!rte_eth_dev_is_valid_port(port_id)) {
1968 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1972 dev = &rte_eth_devices[port_id];
1973 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1975 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1977 dev->data->mtu = mtu;
1983 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1985 struct rte_eth_dev *dev;
1987 if (!rte_eth_dev_is_valid_port(port_id)) {
1988 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1992 dev = &rte_eth_devices[port_id];
1993 if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1994 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1998 if (vlan_id > 4095) {
1999 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
2000 port_id, (unsigned) vlan_id);
2003 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
2004 (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
2009 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
2011 struct rte_eth_dev *dev;
2013 if (!rte_eth_dev_is_valid_port(port_id)) {
2014 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2018 dev = &rte_eth_devices[port_id];
2019 if (rx_queue_id >= dev->data->nb_rx_queues) {
2020 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
2024 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
2025 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
2031 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
2033 struct rte_eth_dev *dev;
2035 if (!rte_eth_dev_is_valid_port(port_id)) {
2036 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2040 dev = &rte_eth_devices[port_id];
2041 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
2042 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
2048 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
2050 struct rte_eth_dev *dev;
2055 if (!rte_eth_dev_is_valid_port(port_id)) {
2056 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2060 dev = &rte_eth_devices[port_id];
2062 /*check which option changed by application*/
2063 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
2064 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
2066 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
2067 mask |= ETH_VLAN_STRIP_MASK;
2070 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
2071 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
2073 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
2074 mask |= ETH_VLAN_FILTER_MASK;
2077 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
2078 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
2080 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
2081 mask |= ETH_VLAN_EXTEND_MASK;
2088 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
2089 (*dev->dev_ops->vlan_offload_set)(dev, mask);
2095 rte_eth_dev_get_vlan_offload(uint8_t port_id)
2097 struct rte_eth_dev *dev;
2100 if (!rte_eth_dev_is_valid_port(port_id)) {
2101 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2105 dev = &rte_eth_devices[port_id];
2107 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
2108 ret |= ETH_VLAN_STRIP_OFFLOAD ;
2110 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
2111 ret |= ETH_VLAN_FILTER_OFFLOAD ;
2113 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
2114 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
2120 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
2122 struct rte_eth_dev *dev;
2124 if (!rte_eth_dev_is_valid_port(port_id)) {
2125 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2129 dev = &rte_eth_devices[port_id];
2130 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
2131 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
2137 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
2138 struct rte_fdir_filter *fdir_filter,
2141 struct rte_eth_dev *dev;
2143 if (!rte_eth_dev_is_valid_port(port_id)) {
2144 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2148 dev = &rte_eth_devices[port_id];
2150 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
2151 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2152 port_id, dev->data->dev_conf.fdir_conf.mode);
2156 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2157 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2158 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2159 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
2160 "None l4type, source & destinations ports " \
2161 "should be null!\n");
2165 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
2166 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
2171 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
2172 struct rte_fdir_filter *fdir_filter,
2175 struct rte_eth_dev *dev;
2177 if (!rte_eth_dev_is_valid_port(port_id)) {
2178 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2182 dev = &rte_eth_devices[port_id];
2184 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
2185 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2186 port_id, dev->data->dev_conf.fdir_conf.mode);
2190 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2191 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2192 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2193 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
2194 "None l4type, source & destinations ports " \
2195 "should be null!\n");
2199 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
2200 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
2206 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
2207 struct rte_fdir_filter *fdir_filter)
2209 struct rte_eth_dev *dev;
2211 if (!rte_eth_dev_is_valid_port(port_id)) {
2212 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2216 dev = &rte_eth_devices[port_id];
2218 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
2219 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2220 port_id, dev->data->dev_conf.fdir_conf.mode);
2224 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2225 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2226 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2227 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
2228 "None l4type source & destinations ports " \
2229 "should be null!\n");
2233 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
2234 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
2238 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
2240 struct rte_eth_dev *dev;
2242 if (!rte_eth_dev_is_valid_port(port_id)) {
2243 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2247 dev = &rte_eth_devices[port_id];
2248 if (! (dev->data->dev_conf.fdir_conf.mode)) {
2249 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
2253 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
2255 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
2260 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
2261 struct rte_fdir_filter *fdir_filter,
2262 uint16_t soft_id, uint8_t queue,
2265 struct rte_eth_dev *dev;
2267 if (!rte_eth_dev_is_valid_port(port_id)) {
2268 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2272 dev = &rte_eth_devices[port_id];
2274 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
2275 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2276 port_id, dev->data->dev_conf.fdir_conf.mode);
2280 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2281 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2282 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2283 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
2284 "None l4type, source & destinations ports " \
2285 "should be null!\n");
2289 /* For now IPv6 is not supported with perfect filter */
2290 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2293 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
2294 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
2300 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
2301 struct rte_fdir_filter *fdir_filter,
2302 uint16_t soft_id, uint8_t queue,
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_update_perfect_filter, -ENOTSUP);
2334 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
2335 soft_id, queue, drop);
2339 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
2340 struct rte_fdir_filter *fdir_filter,
2343 struct rte_eth_dev *dev;
2345 if (!rte_eth_dev_is_valid_port(port_id)) {
2346 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2350 dev = &rte_eth_devices[port_id];
2352 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
2353 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2354 port_id, dev->data->dev_conf.fdir_conf.mode);
2358 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2359 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2360 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2361 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
2362 "None l4type, source & destinations ports " \
2363 "should be null!\n");
2367 /* For now IPv6 is not supported with perfect filter */
2368 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2371 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
2372 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
2377 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
2379 struct rte_eth_dev *dev;
2381 if (!rte_eth_dev_is_valid_port(port_id)) {
2382 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2386 dev = &rte_eth_devices[port_id];
2387 if (! (dev->data->dev_conf.fdir_conf.mode)) {
2388 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
2392 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
2393 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
2397 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2399 struct rte_eth_dev *dev;
2401 if (!rte_eth_dev_is_valid_port(port_id)) {
2402 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2406 dev = &rte_eth_devices[port_id];
2407 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2408 memset(fc_conf, 0, sizeof(*fc_conf));
2409 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
2413 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2415 struct rte_eth_dev *dev;
2417 if (!rte_eth_dev_is_valid_port(port_id)) {
2418 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2422 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2423 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2427 dev = &rte_eth_devices[port_id];
2428 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2429 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
2433 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
2435 struct rte_eth_dev *dev;
2437 if (!rte_eth_dev_is_valid_port(port_id)) {
2438 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2442 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2443 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2447 dev = &rte_eth_devices[port_id];
2448 /* High water, low water validation are device specific */
2449 if (*dev->dev_ops->priority_flow_ctrl_set)
2450 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
2455 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2463 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
2464 PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
2465 RTE_RETA_GROUP_SIZE);
2469 num = reta_size / RTE_RETA_GROUP_SIZE;
2470 for (i = 0; i < num; i++) {
2471 if (reta_conf[i].mask)
2479 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2483 uint16_t i, idx, shift;
2489 PMD_DEBUG_TRACE("No receive queue is available\n");
2493 for (i = 0; i < reta_size; i++) {
2494 idx = i / RTE_RETA_GROUP_SIZE;
2495 shift = i % RTE_RETA_GROUP_SIZE;
2496 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2497 (reta_conf[idx].reta[shift] >= max_rxq)) {
2498 PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2499 "the maximum rxq index: %u\n", idx, shift,
2500 reta_conf[idx].reta[shift], max_rxq);
2509 rte_eth_dev_rss_reta_update(uint8_t port_id,
2510 struct rte_eth_rss_reta_entry64 *reta_conf,
2513 struct rte_eth_dev *dev;
2516 if (!rte_eth_dev_is_valid_port(port_id)) {
2517 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2521 /* Check mask bits */
2522 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2526 dev = &rte_eth_devices[port_id];
2528 /* Check entry value */
2529 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2530 dev->data->nb_rx_queues);
2534 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2535 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2539 rte_eth_dev_rss_reta_query(uint8_t port_id,
2540 struct rte_eth_rss_reta_entry64 *reta_conf,
2543 struct rte_eth_dev *dev;
2546 if (port_id >= nb_ports) {
2547 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2551 /* Check mask bits */
2552 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2556 dev = &rte_eth_devices[port_id];
2557 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2558 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2562 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2564 struct rte_eth_dev *dev;
2565 uint16_t rss_hash_protos;
2567 if (!rte_eth_dev_is_valid_port(port_id)) {
2568 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2572 rss_hash_protos = rss_conf->rss_hf;
2573 if ((rss_hash_protos != 0) &&
2574 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2575 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2579 dev = &rte_eth_devices[port_id];
2580 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2581 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2585 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2586 struct rte_eth_rss_conf *rss_conf)
2588 struct rte_eth_dev *dev;
2590 if (!rte_eth_dev_is_valid_port(port_id)) {
2591 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2595 dev = &rte_eth_devices[port_id];
2596 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2597 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2601 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
2602 struct rte_eth_udp_tunnel *udp_tunnel)
2604 struct rte_eth_dev *dev;
2606 if (!rte_eth_dev_is_valid_port(port_id)) {
2607 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2611 if (udp_tunnel == NULL) {
2612 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2616 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2617 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2621 dev = &rte_eth_devices[port_id];
2622 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
2623 return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
2627 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
2628 struct rte_eth_udp_tunnel *udp_tunnel)
2630 struct rte_eth_dev *dev;
2632 if (!rte_eth_dev_is_valid_port(port_id)) {
2633 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2637 dev = &rte_eth_devices[port_id];
2639 if (udp_tunnel == NULL) {
2640 PMD_DEBUG_TRACE("Invalid udp_tunnel parametr\n");
2644 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2645 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2649 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2650 return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2654 rte_eth_led_on(uint8_t port_id)
2656 struct rte_eth_dev *dev;
2658 if (!rte_eth_dev_is_valid_port(port_id)) {
2659 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2663 dev = &rte_eth_devices[port_id];
2664 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2665 return ((*dev->dev_ops->dev_led_on)(dev));
2669 rte_eth_led_off(uint8_t port_id)
2671 struct rte_eth_dev *dev;
2673 if (!rte_eth_dev_is_valid_port(port_id)) {
2674 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2678 dev = &rte_eth_devices[port_id];
2679 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2680 return ((*dev->dev_ops->dev_led_off)(dev));
2684 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2688 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2690 struct rte_eth_dev_info dev_info;
2691 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2694 rte_eth_dev_info_get(port_id, &dev_info);
2696 for (i = 0; i < dev_info.max_mac_addrs; i++)
2697 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2703 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
2706 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2709 struct rte_eth_dev *dev;
2713 if (!rte_eth_dev_is_valid_port(port_id)) {
2714 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2718 dev = &rte_eth_devices[port_id];
2719 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2721 if (is_zero_ether_addr(addr)) {
2722 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2726 if (pool >= ETH_64_POOLS) {
2727 PMD_DEBUG_TRACE("pool id must be 0-%d\n",ETH_64_POOLS - 1);
2731 index = get_mac_addr_index(port_id, addr);
2733 index = get_mac_addr_index(port_id, &null_mac_addr);
2735 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2740 pool_mask = dev->data->mac_pool_sel[index];
2742 /* Check if both MAC address and pool is alread there, and do nothing */
2743 if (pool_mask & (1ULL << pool))
2748 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2750 /* Update address in NIC data structure */
2751 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2753 /* Update pool bitmap in NIC data structure */
2754 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2760 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2762 struct rte_eth_dev *dev;
2765 if (!rte_eth_dev_is_valid_port(port_id)) {
2766 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2770 dev = &rte_eth_devices[port_id];
2771 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2773 index = get_mac_addr_index(port_id, addr);
2775 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2776 return (-EADDRINUSE);
2777 } else if (index < 0)
2778 return 0; /* Do nothing if address wasn't found */
2781 (*dev->dev_ops->mac_addr_remove)(dev, index);
2783 /* Update address in NIC data structure */
2784 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2786 /* reset pool bitmap */
2787 dev->data->mac_pool_sel[index] = 0;
2793 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2794 uint16_t rx_mode, uint8_t on)
2797 struct rte_eth_dev *dev;
2798 struct rte_eth_dev_info dev_info;
2800 if (!rte_eth_dev_is_valid_port(port_id)) {
2801 PMD_DEBUG_TRACE("set VF RX mode:Invalid port_id=%d\n",
2806 dev = &rte_eth_devices[port_id];
2807 rte_eth_dev_info_get(port_id, &dev_info);
2809 num_vfs = dev_info.max_vfs;
2812 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2817 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2820 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2821 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2825 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2829 get_hash_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2831 struct rte_eth_dev_info dev_info;
2832 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2835 rte_eth_dev_info_get(port_id, &dev_info);
2836 if (!dev->data->hash_mac_addrs)
2839 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2840 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2841 ETHER_ADDR_LEN) == 0)
2848 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2853 struct rte_eth_dev *dev;
2855 if (!rte_eth_dev_is_valid_port(port_id)) {
2856 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2861 dev = &rte_eth_devices[port_id];
2862 if (is_zero_ether_addr(addr)) {
2863 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2868 index = get_hash_mac_addr_index(port_id, addr);
2869 /* Check if it's already there, and do nothing */
2870 if ((index >= 0) && (on))
2875 PMD_DEBUG_TRACE("port %d: the MAC address was not"
2876 "set in UTA\n", port_id);
2880 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2882 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2888 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2889 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2891 /* Update address in NIC data structure */
2893 ether_addr_copy(addr,
2894 &dev->data->hash_mac_addrs[index]);
2896 ether_addr_copy(&null_mac_addr,
2897 &dev->data->hash_mac_addrs[index]);
2904 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2906 struct rte_eth_dev *dev;
2908 if (!rte_eth_dev_is_valid_port(port_id)) {
2909 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2914 dev = &rte_eth_devices[port_id];
2916 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2917 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2921 rte_eth_dev_set_vf_rx(uint8_t port_id,uint16_t vf, uint8_t on)
2924 struct rte_eth_dev *dev;
2925 struct rte_eth_dev_info dev_info;
2927 if (!rte_eth_dev_is_valid_port(port_id)) {
2928 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2932 dev = &rte_eth_devices[port_id];
2933 rte_eth_dev_info_get(port_id, &dev_info);
2935 num_vfs = dev_info.max_vfs;
2938 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2942 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2943 return (*dev->dev_ops->set_vf_rx)(dev, vf,on);
2947 rte_eth_dev_set_vf_tx(uint8_t port_id,uint16_t vf, uint8_t on)
2950 struct rte_eth_dev *dev;
2951 struct rte_eth_dev_info dev_info;
2953 if (!rte_eth_dev_is_valid_port(port_id)) {
2954 PMD_DEBUG_TRACE("set pool tx:Invalid port_id=%d\n", port_id);
2958 dev = &rte_eth_devices[port_id];
2959 rte_eth_dev_info_get(port_id, &dev_info);
2961 num_vfs = dev_info.max_vfs;
2964 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2968 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2969 return (*dev->dev_ops->set_vf_tx)(dev, vf,on);
2973 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2974 uint64_t vf_mask,uint8_t vlan_on)
2976 struct rte_eth_dev *dev;
2978 if (!rte_eth_dev_is_valid_port(port_id)) {
2979 PMD_DEBUG_TRACE("VF VLAN filter:invalid port id=%d\n",
2983 dev = &rte_eth_devices[port_id];
2985 if(vlan_id > ETHER_MAX_VLAN_ID)
2987 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2993 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2997 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2998 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
3002 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
3005 struct rte_eth_dev *dev;
3006 struct rte_eth_dev_info dev_info;
3007 struct rte_eth_link link;
3009 if (!rte_eth_dev_is_valid_port(port_id)) {
3010 PMD_DEBUG_TRACE("set queue rate limit:invalid port id=%d\n",
3015 dev = &rte_eth_devices[port_id];
3016 rte_eth_dev_info_get(port_id, &dev_info);
3017 link = dev->data->dev_link;
3019 if (queue_idx > dev_info.max_tx_queues) {
3020 PMD_DEBUG_TRACE("set queue rate limit:port %d: "
3021 "invalid queue id=%d\n", port_id, queue_idx);
3025 if (tx_rate > link.link_speed) {
3026 PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
3027 "bigger than link speed= %d\n",
3028 tx_rate, link.link_speed);
3032 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
3033 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
3036 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
3039 struct rte_eth_dev *dev;
3040 struct rte_eth_dev_info dev_info;
3041 struct rte_eth_link link;
3046 if (!rte_eth_dev_is_valid_port(port_id)) {
3047 PMD_DEBUG_TRACE("set VF rate limit:invalid port id=%d\n",
3052 dev = &rte_eth_devices[port_id];
3053 rte_eth_dev_info_get(port_id, &dev_info);
3054 link = dev->data->dev_link;
3056 if (vf > dev_info.max_vfs) {
3057 PMD_DEBUG_TRACE("set VF rate limit:port %d: "
3058 "invalid vf id=%d\n", port_id, vf);
3062 if (tx_rate > link.link_speed) {
3063 PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
3064 "bigger than link speed= %d\n",
3065 tx_rate, link.link_speed);
3069 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
3070 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
3074 rte_eth_mirror_rule_set(uint8_t port_id,
3075 struct rte_eth_vmdq_mirror_conf *mirror_conf,
3076 uint8_t rule_id, uint8_t on)
3078 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3080 if (!rte_eth_dev_is_valid_port(port_id)) {
3081 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3085 if (mirror_conf->rule_type_mask == 0) {
3086 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
3090 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
3091 PMD_DEBUG_TRACE("Invalid dst pool, pool id must"
3092 "be 0-%d\n",ETH_64_POOLS - 1);
3096 if ((mirror_conf->rule_type_mask & ETH_VMDQ_POOL_MIRROR) &&
3097 (mirror_conf->pool_mask == 0)) {
3098 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not"
3103 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
3105 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
3106 ETH_VMDQ_NUM_MIRROR_RULE - 1);
3110 dev = &rte_eth_devices[port_id];
3111 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
3113 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
3117 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
3119 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3121 if (!rte_eth_dev_is_valid_port(port_id)) {
3122 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3126 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
3128 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
3129 ETH_VMDQ_NUM_MIRROR_RULE-1);
3133 dev = &rte_eth_devices[port_id];
3134 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
3136 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
3139 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
3141 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
3142 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
3144 struct rte_eth_dev *dev;
3146 if (!rte_eth_dev_is_valid_port(port_id)) {
3147 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3151 dev = &rte_eth_devices[port_id];
3152 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);
3153 if (queue_id >= dev->data->nb_rx_queues) {
3154 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3157 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
3162 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
3163 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
3165 struct rte_eth_dev *dev;
3167 if (!rte_eth_dev_is_valid_port(port_id)) {
3168 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3172 dev = &rte_eth_devices[port_id];
3174 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0);
3175 if (queue_id >= dev->data->nb_tx_queues) {
3176 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3179 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
3184 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
3186 struct rte_eth_dev *dev;
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 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0);
3195 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
3199 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
3201 struct rte_eth_dev *dev;
3203 if (!rte_eth_dev_is_valid_port(port_id)) {
3204 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3208 dev = &rte_eth_devices[port_id];
3209 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
3210 return (*dev->dev_ops->rx_descriptor_done)( \
3211 dev->data->rx_queues[queue_id], offset);
3216 rte_eth_dev_callback_register(uint8_t port_id,
3217 enum rte_eth_event_type event,
3218 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
3220 struct rte_eth_dev *dev;
3221 struct rte_eth_dev_callback *user_cb;
3226 if (!rte_eth_dev_is_valid_port(port_id)) {
3227 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3231 dev = &rte_eth_devices[port_id];
3232 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3234 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
3235 if (user_cb->cb_fn == cb_fn &&
3236 user_cb->cb_arg == cb_arg &&
3237 user_cb->event == event) {
3242 /* create a new callback. */
3243 if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
3244 sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
3245 user_cb->cb_fn = cb_fn;
3246 user_cb->cb_arg = cb_arg;
3247 user_cb->event = event;
3248 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
3251 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3252 return ((user_cb == NULL) ? -ENOMEM : 0);
3256 rte_eth_dev_callback_unregister(uint8_t port_id,
3257 enum rte_eth_event_type event,
3258 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
3261 struct rte_eth_dev *dev;
3262 struct rte_eth_dev_callback *cb, *next;
3267 if (!rte_eth_dev_is_valid_port(port_id)) {
3268 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3272 dev = &rte_eth_devices[port_id];
3273 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3276 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
3278 next = TAILQ_NEXT(cb, next);
3280 if (cb->cb_fn != cb_fn || cb->event != event ||
3281 (cb->cb_arg != (void *)-1 &&
3282 cb->cb_arg != cb_arg))
3286 * if this callback is not executing right now,
3289 if (cb->active == 0) {
3290 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
3297 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3302 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
3303 enum rte_eth_event_type event)
3305 struct rte_eth_dev_callback *cb_lst;
3306 struct rte_eth_dev_callback dev_cb;
3308 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3309 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
3310 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
3314 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3315 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
3317 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3320 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3322 #ifdef RTE_NIC_BYPASS
3323 int rte_eth_dev_bypass_init(uint8_t port_id)
3325 struct rte_eth_dev *dev;
3327 if (!rte_eth_dev_is_valid_port(port_id)) {
3328 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3332 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3333 PMD_DEBUG_TRACE("Invalid port device\n");
3337 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
3338 (*dev->dev_ops->bypass_init)(dev);
3343 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
3345 struct rte_eth_dev *dev;
3347 if (!rte_eth_dev_is_valid_port(port_id)) {
3348 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3352 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3353 PMD_DEBUG_TRACE("Invalid port device\n");
3356 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
3357 (*dev->dev_ops->bypass_state_show)(dev, state);
3362 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
3364 struct rte_eth_dev *dev;
3366 if (!rte_eth_dev_is_valid_port(port_id)) {
3367 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3371 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3372 PMD_DEBUG_TRACE("Invalid port device\n");
3376 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
3377 (*dev->dev_ops->bypass_state_set)(dev, new_state);
3382 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
3384 struct rte_eth_dev *dev;
3386 if (!rte_eth_dev_is_valid_port(port_id)) {
3387 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3391 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3392 PMD_DEBUG_TRACE("Invalid port device\n");
3396 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
3397 (*dev->dev_ops->bypass_event_show)(dev, event, state);
3402 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
3404 struct rte_eth_dev *dev;
3406 if (!rte_eth_dev_is_valid_port(port_id)) {
3407 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3411 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3412 PMD_DEBUG_TRACE("Invalid port device\n");
3416 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
3417 (*dev->dev_ops->bypass_event_set)(dev, event, state);
3422 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
3424 struct rte_eth_dev *dev;
3426 if (!rte_eth_dev_is_valid_port(port_id)) {
3427 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3431 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3432 PMD_DEBUG_TRACE("Invalid port device\n");
3436 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
3437 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
3442 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
3444 struct rte_eth_dev *dev;
3446 if (!rte_eth_dev_is_valid_port(port_id)) {
3447 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3451 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3452 PMD_DEBUG_TRACE("Invalid port device\n");
3456 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
3457 (*dev->dev_ops->bypass_ver_show)(dev, ver);
3462 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
3464 struct rte_eth_dev *dev;
3466 if (!rte_eth_dev_is_valid_port(port_id)) {
3467 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3471 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3472 PMD_DEBUG_TRACE("Invalid port device\n");
3476 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
3477 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
3482 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
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 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3492 PMD_DEBUG_TRACE("Invalid port device\n");
3496 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
3497 (*dev->dev_ops->bypass_wd_reset)(dev);
3503 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
3505 struct rte_eth_dev *dev;
3507 if (!rte_eth_dev_is_valid_port(port_id)) {
3508 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3512 dev = &rte_eth_devices[port_id];
3513 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3514 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3515 RTE_ETH_FILTER_NOP, NULL);
3519 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
3520 enum rte_filter_op filter_op, void *arg)
3522 struct rte_eth_dev *dev;
3524 if (!rte_eth_dev_is_valid_port(port_id)) {
3525 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3529 dev = &rte_eth_devices[port_id];
3530 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3531 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
3535 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
3536 rte_rxtx_callback_fn fn, void *user_param)
3538 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3539 rte_errno = ENOTSUP;
3542 /* check input parameters */
3543 if (port_id >= nb_ports || fn == NULL ||
3544 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3549 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3557 cb->param = user_param;
3558 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3559 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3564 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
3565 rte_rxtx_callback_fn fn, void *user_param)
3567 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3568 rte_errno = ENOTSUP;
3571 /* check input parameters */
3572 if (port_id >= nb_ports || fn == NULL ||
3573 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3578 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3586 cb->param = user_param;
3587 cb->next = rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3588 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3593 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3594 struct rte_eth_rxtx_callback *user_cb)
3596 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3599 /* Check input parameters. */
3600 if (port_id >= nb_ports || user_cb == NULL ||
3601 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3605 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3606 struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
3607 struct rte_eth_rxtx_callback *prev_cb;
3609 /* Reset head pointer and remove user cb if first in the list. */
3610 if (cb == user_cb) {
3611 dev->post_rx_burst_cbs[queue_id] = user_cb->next;
3615 /* Remove the user cb from the callback list. */
3620 if (cb == user_cb) {
3621 prev_cb->next = user_cb->next;
3625 } while (cb != NULL);
3627 /* Callback wasn't found. */
3632 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3633 struct rte_eth_rxtx_callback *user_cb)
3635 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3638 /* Check input parameters. */
3639 if (port_id >= nb_ports || user_cb == NULL ||
3640 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3644 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3645 struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
3646 struct rte_eth_rxtx_callback *prev_cb;
3648 /* Reset head pointer and remove user cb if first in the list. */
3649 if (cb == user_cb) {
3650 dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
3654 /* Remove the user cb from the callback list. */
3659 if (cb == user_cb) {
3660 prev_cb->next = user_cb->next;
3664 } while (cb != NULL);
3666 /* Callback wasn't found. */