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));
204 static struct rte_eth_dev *
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);
278 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
283 eth_dev->attached = 0;
289 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
290 struct rte_pci_device *pci_dev)
292 struct eth_driver *eth_drv;
293 struct rte_eth_dev *eth_dev;
294 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
298 eth_drv = (struct eth_driver *)pci_drv;
300 /* Create unique Ethernet device name using PCI address */
301 rte_eth_dev_create_unique_device_name(ethdev_name,
302 sizeof(ethdev_name), pci_dev);
304 eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
308 if (rte_eal_process_type() == RTE_PROC_PRIMARY){
309 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
310 eth_drv->dev_private_size,
311 RTE_CACHE_LINE_SIZE);
312 if (eth_dev->data->dev_private == NULL)
313 rte_panic("Cannot allocate memzone for private port data\n");
315 eth_dev->pci_dev = pci_dev;
316 eth_dev->driver = eth_drv;
317 eth_dev->data->rx_mbuf_alloc_failed = 0;
319 /* init user callbacks */
320 TAILQ_INIT(&(eth_dev->link_intr_cbs));
323 * Set the default MTU.
325 eth_dev->data->mtu = ETHER_MTU;
327 /* Invoke PMD device initialization function */
328 diag = (*eth_drv->eth_dev_init)(eth_drv, eth_dev);
332 PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x)"
333 " failed\n", pci_drv->name,
334 (unsigned) pci_dev->id.vendor_id,
335 (unsigned) pci_dev->id.device_id);
336 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
337 rte_free(eth_dev->data->dev_private);
338 eth_dev->attached = DEV_DETACHED;
344 rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
346 const struct eth_driver *eth_drv;
347 struct rte_eth_dev *eth_dev;
348 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
354 /* Create unique Ethernet device name using PCI address */
355 rte_eth_dev_create_unique_device_name(ethdev_name,
356 sizeof(ethdev_name), pci_dev);
358 eth_dev = rte_eth_dev_allocated(ethdev_name);
362 eth_drv = (const struct eth_driver *)pci_dev->driver;
364 /* Invoke PMD device uninit function */
365 if (*eth_drv->eth_dev_uninit) {
366 ret = (*eth_drv->eth_dev_uninit)(eth_drv, eth_dev);
371 /* free ether device */
372 rte_eth_dev_release_port(eth_dev);
374 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
375 rte_free(eth_dev->data->dev_private);
377 eth_dev->pci_dev = NULL;
378 eth_dev->driver = NULL;
379 eth_dev->data = NULL;
385 * Register an Ethernet [Poll Mode] driver.
387 * Function invoked by the initialization function of an Ethernet driver
388 * to simultaneously register itself as a PCI driver and as an Ethernet
390 * Invokes the rte_eal_pci_register() function to register the *pci_drv*
391 * structure embedded in the *eth_drv* structure, after having stored the
392 * address of the rte_eth_dev_init() function in the *devinit* field of
393 * the *pci_drv* structure.
394 * During the PCI probing phase, the rte_eth_dev_init() function is
395 * invoked for each PCI [Ethernet device] matching the embedded PCI
396 * identifiers provided by the driver.
399 rte_eth_driver_register(struct eth_driver *eth_drv)
401 eth_drv->pci_drv.devinit = rte_eth_dev_init;
402 eth_drv->pci_drv.devuninit = rte_eth_dev_uninit;
403 rte_eal_pci_register(ð_drv->pci_drv);
407 rte_eth_dev_is_valid_port(uint8_t port_id)
409 if (port_id >= RTE_MAX_ETHPORTS ||
410 rte_eth_devices[port_id].attached != DEV_ATTACHED)
417 rte_eth_dev_socket_id(uint8_t port_id)
419 if (!rte_eth_dev_is_valid_port(port_id))
421 return rte_eth_devices[port_id].pci_dev->numa_node;
425 rte_eth_dev_count(void)
431 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
433 uint16_t old_nb_queues = dev->data->nb_rx_queues;
437 if (dev->data->rx_queues == NULL) { /* first time configuration */
438 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
439 sizeof(dev->data->rx_queues[0]) * nb_queues,
440 RTE_CACHE_LINE_SIZE);
441 if (dev->data->rx_queues == NULL) {
442 dev->data->nb_rx_queues = 0;
445 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
446 dev->post_rx_burst_cbs = rte_zmalloc(
447 "ethdev->post_rx_burst_cbs",
448 sizeof(*dev->post_rx_burst_cbs) * nb_queues,
449 RTE_CACHE_LINE_SIZE);
450 if (dev->post_rx_burst_cbs == NULL) {
451 rte_free(dev->data->rx_queues);
452 dev->data->rx_queues = NULL;
453 dev->data->nb_rx_queues = 0;
458 } else { /* re-configure */
459 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
461 rxq = dev->data->rx_queues;
463 for (i = nb_queues; i < old_nb_queues; i++)
464 (*dev->dev_ops->rx_queue_release)(rxq[i]);
465 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
466 RTE_CACHE_LINE_SIZE);
469 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
470 dev->post_rx_burst_cbs = rte_realloc(
471 dev->post_rx_burst_cbs,
472 sizeof(*dev->post_rx_burst_cbs) *
473 nb_queues, RTE_CACHE_LINE_SIZE);
474 if (dev->post_rx_burst_cbs == NULL)
477 if (nb_queues > old_nb_queues) {
478 uint16_t new_qs = nb_queues - old_nb_queues;
479 memset(rxq + old_nb_queues, 0,
480 sizeof(rxq[0]) * new_qs);
481 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
482 memset(dev->post_rx_burst_cbs + old_nb_queues, 0,
483 sizeof(dev->post_rx_burst_cbs[0]) * new_qs);
487 dev->data->rx_queues = rxq;
490 dev->data->nb_rx_queues = nb_queues;
495 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
497 struct rte_eth_dev *dev;
499 /* This function is only safe when called from the primary process
500 * in a multi-process setup*/
501 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
503 if (!rte_eth_dev_is_valid_port(port_id)) {
504 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
508 dev = &rte_eth_devices[port_id];
509 if (rx_queue_id >= dev->data->nb_rx_queues) {
510 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
514 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
516 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
521 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
523 struct rte_eth_dev *dev;
525 /* This function is only safe when called from the primary process
526 * in a multi-process setup*/
527 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
529 if (!rte_eth_dev_is_valid_port(port_id)) {
530 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
534 dev = &rte_eth_devices[port_id];
535 if (rx_queue_id >= dev->data->nb_rx_queues) {
536 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
540 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
542 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
547 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
549 struct rte_eth_dev *dev;
551 /* This function is only safe when called from the primary process
552 * in a multi-process setup*/
553 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
555 if (!rte_eth_dev_is_valid_port(port_id)) {
556 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
560 dev = &rte_eth_devices[port_id];
561 if (tx_queue_id >= dev->data->nb_tx_queues) {
562 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
566 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
568 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
573 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
575 struct rte_eth_dev *dev;
577 /* This function is only safe when called from the primary process
578 * in a multi-process setup*/
579 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
581 if (!rte_eth_dev_is_valid_port(port_id)) {
582 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
586 dev = &rte_eth_devices[port_id];
587 if (tx_queue_id >= dev->data->nb_tx_queues) {
588 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
592 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
594 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
599 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
601 uint16_t old_nb_queues = dev->data->nb_tx_queues;
605 if (dev->data->tx_queues == NULL) { /* first time configuration */
606 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
607 sizeof(dev->data->tx_queues[0]) * nb_queues,
608 RTE_CACHE_LINE_SIZE);
609 if (dev->data->tx_queues == NULL) {
610 dev->data->nb_tx_queues = 0;
613 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
614 dev->pre_tx_burst_cbs = rte_zmalloc(
615 "ethdev->pre_tx_burst_cbs",
616 sizeof(*dev->pre_tx_burst_cbs) * nb_queues,
617 RTE_CACHE_LINE_SIZE);
618 if (dev->pre_tx_burst_cbs == NULL) {
619 rte_free(dev->data->tx_queues);
620 dev->data->tx_queues = NULL;
621 dev->data->nb_tx_queues = 0;
626 } else { /* re-configure */
627 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
629 txq = dev->data->tx_queues;
631 for (i = nb_queues; i < old_nb_queues; i++)
632 (*dev->dev_ops->tx_queue_release)(txq[i]);
633 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
634 RTE_CACHE_LINE_SIZE);
637 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
638 dev->pre_tx_burst_cbs = rte_realloc(
639 dev->pre_tx_burst_cbs,
640 sizeof(*dev->pre_tx_burst_cbs) *
641 nb_queues, RTE_CACHE_LINE_SIZE);
642 if (dev->pre_tx_burst_cbs == NULL)
645 if (nb_queues > old_nb_queues) {
646 uint16_t new_qs = nb_queues - old_nb_queues;
647 memset(txq + old_nb_queues, 0,
648 sizeof(txq[0]) * new_qs);
649 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
650 memset(dev->pre_tx_burst_cbs + old_nb_queues, 0,
651 sizeof(dev->pre_tx_burst_cbs[0]) * new_qs);
655 dev->data->tx_queues = txq;
658 dev->data->nb_tx_queues = nb_queues;
663 rte_eth_dev_check_vf_rss_rxq_num(uint8_t port_id, uint16_t nb_rx_q)
665 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
669 RTE_ETH_DEV_SRIOV(dev).active =
673 RTE_ETH_DEV_SRIOV(dev).active =
680 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = nb_rx_q;
681 RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx =
682 dev->pci_dev->max_vfs * nb_rx_q;
688 rte_eth_dev_check_mq_mode(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
689 const struct rte_eth_conf *dev_conf)
691 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
693 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
694 /* check multi-queue mode */
695 if ((dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) ||
696 (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB_RSS) ||
697 (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB)) {
698 /* SRIOV only works in VMDq enable mode */
699 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
701 "wrong VMDQ mq_mode rx %u tx %u\n",
703 dev_conf->rxmode.mq_mode,
704 dev_conf->txmode.mq_mode);
708 switch (dev_conf->rxmode.mq_mode) {
709 case ETH_MQ_RX_VMDQ_DCB:
710 case ETH_MQ_RX_VMDQ_DCB_RSS:
711 /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
712 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
714 "unsupported VMDQ mq_mode rx %u\n",
715 port_id, dev_conf->rxmode.mq_mode);
718 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
720 "Rx mq mode is changed from:"
721 "mq_mode %u into VMDQ mq_mode %u\n",
723 dev_conf->rxmode.mq_mode,
724 dev->data->dev_conf.rxmode.mq_mode);
725 case ETH_MQ_RX_VMDQ_RSS:
726 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_RSS;
727 if (nb_rx_q <= RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)
728 if (rte_eth_dev_check_vf_rss_rxq_num(port_id, nb_rx_q) != 0) {
729 PMD_DEBUG_TRACE("ethdev port_id=%d"
730 " SRIOV active, invalid queue"
731 " number for VMDQ RSS, allowed"
732 " value are 1, 2 or 4\n",
737 default: /* ETH_MQ_RX_VMDQ_ONLY or ETH_MQ_RX_NONE */
738 /* if nothing mq mode configure, use default scheme */
739 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
740 if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
741 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
745 switch (dev_conf->txmode.mq_mode) {
746 case ETH_MQ_TX_VMDQ_DCB:
747 /* DCB VMDQ in SRIOV mode, not implement yet */
748 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
750 "unsupported VMDQ mq_mode tx %u\n",
751 port_id, dev_conf->txmode.mq_mode);
753 default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
754 /* if nothing mq mode configure, use default scheme */
755 dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
759 /* check valid queue number */
760 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
761 (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
762 PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
763 "queue number must less equal to %d\n",
764 port_id, RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
768 /* For vmdb+dcb mode check our configuration before we go further */
769 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB) {
770 const struct rte_eth_vmdq_dcb_conf *conf;
772 if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
773 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
775 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
778 conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
779 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
780 conf->nb_queue_pools == ETH_32_POOLS)) {
781 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
782 "nb_queue_pools must be %d or %d\n",
783 port_id, ETH_16_POOLS, ETH_32_POOLS);
787 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
788 const struct rte_eth_vmdq_dcb_tx_conf *conf;
790 if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
791 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
793 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
796 conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
797 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
798 conf->nb_queue_pools == ETH_32_POOLS)) {
799 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
800 "nb_queue_pools != %d or nb_queue_pools "
802 port_id, ETH_16_POOLS, ETH_32_POOLS);
807 /* For DCB mode check our configuration before we go further */
808 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) {
809 const struct rte_eth_dcb_rx_conf *conf;
811 if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
812 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
814 port_id, ETH_DCB_NUM_QUEUES);
817 conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
818 if (! (conf->nb_tcs == ETH_4_TCS ||
819 conf->nb_tcs == ETH_8_TCS)) {
820 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
821 "nb_tcs != %d or nb_tcs "
823 port_id, ETH_4_TCS, ETH_8_TCS);
828 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
829 const struct rte_eth_dcb_tx_conf *conf;
831 if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
832 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
834 port_id, ETH_DCB_NUM_QUEUES);
837 conf = &(dev_conf->tx_adv_conf.dcb_tx_conf);
838 if (! (conf->nb_tcs == ETH_4_TCS ||
839 conf->nb_tcs == ETH_8_TCS)) {
840 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
841 "nb_tcs != %d or nb_tcs "
843 port_id, ETH_4_TCS, ETH_8_TCS);
852 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
853 const struct rte_eth_conf *dev_conf)
855 struct rte_eth_dev *dev;
856 struct rte_eth_dev_info dev_info;
859 /* This function is only safe when called from the primary process
860 * in a multi-process setup*/
861 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
863 if (!rte_eth_dev_is_valid_port(port_id)) {
864 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
868 dev = &rte_eth_devices[port_id];
870 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
871 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
873 if (dev->data->dev_started) {
875 "port %d must be stopped to allow configuration\n", port_id);
880 * Check that the numbers of RX and TX queues are not greater
881 * than the maximum number of RX and TX queues supported by the
884 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
885 if (nb_rx_q > dev_info.max_rx_queues) {
886 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
887 port_id, nb_rx_q, dev_info.max_rx_queues);
891 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
895 if (nb_tx_q > dev_info.max_tx_queues) {
896 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
897 port_id, nb_tx_q, dev_info.max_tx_queues);
901 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
905 /* Copy the dev_conf parameter into the dev structure */
906 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
909 * If link state interrupt is enabled, check that the
910 * device supports it.
912 if (dev_conf->intr_conf.lsc == 1) {
913 const struct rte_pci_driver *pci_drv = &dev->driver->pci_drv;
915 if (!(pci_drv->drv_flags & RTE_PCI_DRV_INTR_LSC)) {
916 PMD_DEBUG_TRACE("driver %s does not support lsc\n",
923 * If jumbo frames are enabled, check that the maximum RX packet
924 * length is supported by the configured device.
926 if (dev_conf->rxmode.jumbo_frame == 1) {
927 if (dev_conf->rxmode.max_rx_pkt_len >
928 dev_info.max_rx_pktlen) {
929 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
930 " > max valid value %u\n",
932 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
933 (unsigned)dev_info.max_rx_pktlen);
936 else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
937 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
938 " < min valid value %u\n",
940 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
941 (unsigned)ETHER_MIN_LEN);
945 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
946 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
947 /* Use default value */
948 dev->data->dev_conf.rxmode.max_rx_pkt_len =
952 /* multipe queue mode checking */
953 diag = rte_eth_dev_check_mq_mode(port_id, nb_rx_q, nb_tx_q, dev_conf);
955 PMD_DEBUG_TRACE("port%d rte_eth_dev_check_mq_mode = %d\n",
961 * Setup new number of RX/TX queues and reconfigure device.
963 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
965 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
970 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
972 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
974 rte_eth_dev_rx_queue_config(dev, 0);
978 diag = (*dev->dev_ops->dev_configure)(dev);
980 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
982 rte_eth_dev_rx_queue_config(dev, 0);
983 rte_eth_dev_tx_queue_config(dev, 0);
991 rte_eth_dev_config_restore(uint8_t port_id)
993 struct rte_eth_dev *dev;
994 struct rte_eth_dev_info dev_info;
995 struct ether_addr addr;
999 dev = &rte_eth_devices[port_id];
1001 rte_eth_dev_info_get(port_id, &dev_info);
1003 if (RTE_ETH_DEV_SRIOV(dev).active)
1004 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
1006 /* replay MAC address configuration */
1007 for (i = 0; i < dev_info.max_mac_addrs; i++) {
1008 addr = dev->data->mac_addrs[i];
1010 /* skip zero address */
1011 if (is_zero_ether_addr(&addr))
1014 /* add address to the hardware */
1015 if (*dev->dev_ops->mac_addr_add &&
1016 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
1017 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
1019 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
1021 /* exit the loop but not return an error */
1026 /* replay promiscuous configuration */
1027 if (rte_eth_promiscuous_get(port_id) == 1)
1028 rte_eth_promiscuous_enable(port_id);
1029 else if (rte_eth_promiscuous_get(port_id) == 0)
1030 rte_eth_promiscuous_disable(port_id);
1032 /* replay allmulticast configuration */
1033 if (rte_eth_allmulticast_get(port_id) == 1)
1034 rte_eth_allmulticast_enable(port_id);
1035 else if (rte_eth_allmulticast_get(port_id) == 0)
1036 rte_eth_allmulticast_disable(port_id);
1040 rte_eth_dev_start(uint8_t port_id)
1042 struct rte_eth_dev *dev;
1045 /* This function is only safe when called from the primary process
1046 * in a multi-process setup*/
1047 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1049 if (!rte_eth_dev_is_valid_port(port_id)) {
1050 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1054 dev = &rte_eth_devices[port_id];
1056 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1058 if (dev->data->dev_started != 0) {
1059 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1060 " already started\n",
1065 diag = (*dev->dev_ops->dev_start)(dev);
1067 dev->data->dev_started = 1;
1071 rte_eth_dev_config_restore(port_id);
1073 if (dev->data->dev_conf.intr_conf.lsc != 0) {
1074 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1075 (*dev->dev_ops->link_update)(dev, 0);
1081 rte_eth_dev_stop(uint8_t port_id)
1083 struct rte_eth_dev *dev;
1085 /* This function is only safe when called from the primary process
1086 * in a multi-process setup*/
1087 PROC_PRIMARY_OR_RET();
1089 if (!rte_eth_dev_is_valid_port(port_id)) {
1090 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1094 dev = &rte_eth_devices[port_id];
1096 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1098 if (dev->data->dev_started == 0) {
1099 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1100 " already stopped\n",
1105 dev->data->dev_started = 0;
1106 (*dev->dev_ops->dev_stop)(dev);
1110 rte_eth_dev_set_link_up(uint8_t port_id)
1112 struct rte_eth_dev *dev;
1114 /* This function is only safe when called from the primary process
1115 * in a multi-process setup*/
1116 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1118 if (!rte_eth_dev_is_valid_port(port_id)) {
1119 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1123 dev = &rte_eth_devices[port_id];
1125 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1126 return (*dev->dev_ops->dev_set_link_up)(dev);
1130 rte_eth_dev_set_link_down(uint8_t port_id)
1132 struct rte_eth_dev *dev;
1134 /* This function is only safe when called from the primary process
1135 * in a multi-process setup*/
1136 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1138 if (!rte_eth_dev_is_valid_port(port_id)) {
1139 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1143 dev = &rte_eth_devices[port_id];
1145 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1146 return (*dev->dev_ops->dev_set_link_down)(dev);
1150 rte_eth_dev_close(uint8_t port_id)
1152 struct rte_eth_dev *dev;
1154 /* This function is only safe when called from the primary process
1155 * in a multi-process setup*/
1156 PROC_PRIMARY_OR_RET();
1158 if (!rte_eth_dev_is_valid_port(port_id)) {
1159 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1163 dev = &rte_eth_devices[port_id];
1165 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1166 dev->data->dev_started = 0;
1167 (*dev->dev_ops->dev_close)(dev);
1171 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1172 uint16_t nb_rx_desc, unsigned int socket_id,
1173 const struct rte_eth_rxconf *rx_conf,
1174 struct rte_mempool *mp)
1177 uint32_t mbp_buf_size;
1178 struct rte_eth_dev *dev;
1179 struct rte_pktmbuf_pool_private *mbp_priv;
1180 struct rte_eth_dev_info dev_info;
1182 /* This function is only safe when called from the primary process
1183 * in a multi-process setup*/
1184 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1186 if (!rte_eth_dev_is_valid_port(port_id)) {
1187 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1191 dev = &rte_eth_devices[port_id];
1192 if (rx_queue_id >= dev->data->nb_rx_queues) {
1193 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1197 if (dev->data->dev_started) {
1199 "port %d must be stopped to allow configuration\n", port_id);
1203 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1204 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1207 * Check the size of the mbuf data buffer.
1208 * This value must be provided in the private data of the memory pool.
1209 * First check that the memory pool has a valid private data.
1211 rte_eth_dev_info_get(port_id, &dev_info);
1212 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1213 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1214 mp->name, (int) mp->private_data_size,
1215 (int) sizeof(struct rte_pktmbuf_pool_private));
1218 mbp_priv = rte_mempool_get_priv(mp);
1219 mbp_buf_size = mbp_priv->mbuf_data_room_size;
1221 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1222 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1223 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1227 (int)(RTE_PKTMBUF_HEADROOM +
1228 dev_info.min_rx_bufsize),
1229 (int)RTE_PKTMBUF_HEADROOM,
1230 (int)dev_info.min_rx_bufsize);
1234 if (rx_conf == NULL)
1235 rx_conf = &dev_info.default_rxconf;
1237 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1238 socket_id, rx_conf, mp);
1240 if (!dev->data->min_rx_buf_size ||
1241 dev->data->min_rx_buf_size > mbp_buf_size)
1242 dev->data->min_rx_buf_size = mbp_buf_size;
1249 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1250 uint16_t nb_tx_desc, unsigned int socket_id,
1251 const struct rte_eth_txconf *tx_conf)
1253 struct rte_eth_dev *dev;
1254 struct rte_eth_dev_info dev_info;
1256 /* This function is only safe when called from the primary process
1257 * in a multi-process setup*/
1258 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1260 if (!rte_eth_dev_is_valid_port(port_id)) {
1261 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1265 dev = &rte_eth_devices[port_id];
1266 if (tx_queue_id >= dev->data->nb_tx_queues) {
1267 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1271 if (dev->data->dev_started) {
1273 "port %d must be stopped to allow configuration\n", port_id);
1277 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1278 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1280 rte_eth_dev_info_get(port_id, &dev_info);
1282 if (tx_conf == NULL)
1283 tx_conf = &dev_info.default_txconf;
1285 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1286 socket_id, tx_conf);
1290 rte_eth_promiscuous_enable(uint8_t port_id)
1292 struct rte_eth_dev *dev;
1294 if (!rte_eth_dev_is_valid_port(port_id)) {
1295 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1299 dev = &rte_eth_devices[port_id];
1301 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1302 (*dev->dev_ops->promiscuous_enable)(dev);
1303 dev->data->promiscuous = 1;
1307 rte_eth_promiscuous_disable(uint8_t port_id)
1309 struct rte_eth_dev *dev;
1311 if (!rte_eth_dev_is_valid_port(port_id)) {
1312 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1316 dev = &rte_eth_devices[port_id];
1318 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1319 dev->data->promiscuous = 0;
1320 (*dev->dev_ops->promiscuous_disable)(dev);
1324 rte_eth_promiscuous_get(uint8_t port_id)
1326 struct rte_eth_dev *dev;
1328 if (!rte_eth_dev_is_valid_port(port_id)) {
1329 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1333 dev = &rte_eth_devices[port_id];
1334 return dev->data->promiscuous;
1338 rte_eth_allmulticast_enable(uint8_t port_id)
1340 struct rte_eth_dev *dev;
1342 if (!rte_eth_dev_is_valid_port(port_id)) {
1343 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1347 dev = &rte_eth_devices[port_id];
1349 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1350 (*dev->dev_ops->allmulticast_enable)(dev);
1351 dev->data->all_multicast = 1;
1355 rte_eth_allmulticast_disable(uint8_t port_id)
1357 struct rte_eth_dev *dev;
1359 if (!rte_eth_dev_is_valid_port(port_id)) {
1360 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1364 dev = &rte_eth_devices[port_id];
1366 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1367 dev->data->all_multicast = 0;
1368 (*dev->dev_ops->allmulticast_disable)(dev);
1372 rte_eth_allmulticast_get(uint8_t port_id)
1374 struct rte_eth_dev *dev;
1376 if (!rte_eth_dev_is_valid_port(port_id)) {
1377 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1381 dev = &rte_eth_devices[port_id];
1382 return dev->data->all_multicast;
1386 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1387 struct rte_eth_link *link)
1389 struct rte_eth_link *dst = link;
1390 struct rte_eth_link *src = &(dev->data->dev_link);
1392 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1393 *(uint64_t *)src) == 0)
1400 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1402 struct rte_eth_dev *dev;
1404 if (!rte_eth_dev_is_valid_port(port_id)) {
1405 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1409 dev = &rte_eth_devices[port_id];
1411 if (dev->data->dev_conf.intr_conf.lsc != 0)
1412 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1414 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1415 (*dev->dev_ops->link_update)(dev, 1);
1416 *eth_link = dev->data->dev_link;
1421 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1423 struct rte_eth_dev *dev;
1425 if (!rte_eth_dev_is_valid_port(port_id)) {
1426 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1430 dev = &rte_eth_devices[port_id];
1432 if (dev->data->dev_conf.intr_conf.lsc != 0)
1433 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1435 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1436 (*dev->dev_ops->link_update)(dev, 0);
1437 *eth_link = dev->data->dev_link;
1442 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1444 struct rte_eth_dev *dev;
1446 if (!rte_eth_dev_is_valid_port(port_id)) {
1447 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1451 dev = &rte_eth_devices[port_id];
1452 memset(stats, 0, sizeof(*stats));
1454 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1455 (*dev->dev_ops->stats_get)(dev, stats);
1456 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1461 rte_eth_stats_reset(uint8_t port_id)
1463 struct rte_eth_dev *dev;
1465 if (!rte_eth_dev_is_valid_port(port_id)) {
1466 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1470 dev = &rte_eth_devices[port_id];
1472 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1473 (*dev->dev_ops->stats_reset)(dev);
1476 /* retrieve ethdev extended statistics */
1478 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1481 struct rte_eth_stats eth_stats;
1482 struct rte_eth_dev *dev;
1483 unsigned count, i, q;
1487 if (!rte_eth_dev_is_valid_port(port_id)) {
1488 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1492 dev = &rte_eth_devices[port_id];
1494 /* implemented by the driver */
1495 if (dev->dev_ops->xstats_get != NULL)
1496 return (*dev->dev_ops->xstats_get)(dev, xstats, n);
1498 /* else, return generic statistics */
1499 count = RTE_NB_STATS;
1500 count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
1501 count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
1505 /* now fill the xstats structure */
1508 memset(ð_stats, 0, sizeof(eth_stats));
1509 rte_eth_stats_get(port_id, ð_stats);
1512 for (i = 0; i < RTE_NB_STATS; i++) {
1513 stats_ptr = (char *)ð_stats + rte_stats_strings[i].offset;
1514 val = *(uint64_t *)stats_ptr;
1515 snprintf(xstats[count].name, sizeof(xstats[count].name),
1516 "%s", rte_stats_strings[i].name);
1517 xstats[count++].value = val;
1521 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1522 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1523 stats_ptr = (char *)ð_stats;
1524 stats_ptr += rte_rxq_stats_strings[i].offset;
1525 stats_ptr += q * sizeof(uint64_t);
1526 val = *(uint64_t *)stats_ptr;
1527 snprintf(xstats[count].name, sizeof(xstats[count].name),
1528 "rx_queue_%u_%s", q,
1529 rte_rxq_stats_strings[i].name);
1530 xstats[count++].value = val;
1535 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1536 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1537 stats_ptr = (char *)ð_stats;
1538 stats_ptr += rte_txq_stats_strings[i].offset;
1539 stats_ptr += q * sizeof(uint64_t);
1540 val = *(uint64_t *)stats_ptr;
1541 snprintf(xstats[count].name, sizeof(xstats[count].name),
1542 "tx_queue_%u_%s", q,
1543 rte_txq_stats_strings[i].name);
1544 xstats[count++].value = val;
1551 /* reset ethdev extended statistics */
1553 rte_eth_xstats_reset(uint8_t port_id)
1555 struct rte_eth_dev *dev;
1557 if (!rte_eth_dev_is_valid_port(port_id)) {
1558 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1562 dev = &rte_eth_devices[port_id];
1564 /* implemented by the driver */
1565 if (dev->dev_ops->xstats_reset != NULL) {
1566 (*dev->dev_ops->xstats_reset)(dev);
1570 /* fallback to default */
1571 rte_eth_stats_reset(port_id);
1575 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1578 struct rte_eth_dev *dev;
1580 if (!rte_eth_dev_is_valid_port(port_id)) {
1581 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1585 dev = &rte_eth_devices[port_id];
1587 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1588 return (*dev->dev_ops->queue_stats_mapping_set)
1589 (dev, queue_id, stat_idx, is_rx);
1594 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1597 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1603 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1606 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1612 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1614 struct rte_eth_dev *dev;
1616 if (!rte_eth_dev_is_valid_port(port_id)) {
1617 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1621 dev = &rte_eth_devices[port_id];
1623 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1625 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1626 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1627 dev_info->pci_dev = dev->pci_dev;
1629 dev_info->driver_name = dev->driver->pci_drv.name;
1633 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
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 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1648 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1650 struct rte_eth_dev *dev;
1652 if (!rte_eth_dev_is_valid_port(port_id)) {
1653 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1657 dev = &rte_eth_devices[port_id];
1658 *mtu = dev->data->mtu;
1663 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1666 struct rte_eth_dev *dev;
1668 if (!rte_eth_dev_is_valid_port(port_id)) {
1669 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1673 dev = &rte_eth_devices[port_id];
1674 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1676 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1678 dev->data->mtu = mtu;
1684 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1686 struct rte_eth_dev *dev;
1688 if (!rte_eth_dev_is_valid_port(port_id)) {
1689 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1693 dev = &rte_eth_devices[port_id];
1694 if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1695 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1699 if (vlan_id > 4095) {
1700 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1701 port_id, (unsigned) vlan_id);
1704 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1705 (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1710 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1712 struct rte_eth_dev *dev;
1714 if (!rte_eth_dev_is_valid_port(port_id)) {
1715 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1719 dev = &rte_eth_devices[port_id];
1720 if (rx_queue_id >= dev->data->nb_rx_queues) {
1721 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1725 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1726 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1732 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1734 struct rte_eth_dev *dev;
1736 if (!rte_eth_dev_is_valid_port(port_id)) {
1737 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1741 dev = &rte_eth_devices[port_id];
1742 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1743 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1749 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1751 struct rte_eth_dev *dev;
1756 if (!rte_eth_dev_is_valid_port(port_id)) {
1757 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1761 dev = &rte_eth_devices[port_id];
1763 /*check which option changed by application*/
1764 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1765 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1767 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1768 mask |= ETH_VLAN_STRIP_MASK;
1771 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1772 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1774 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1775 mask |= ETH_VLAN_FILTER_MASK;
1778 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1779 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1781 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1782 mask |= ETH_VLAN_EXTEND_MASK;
1789 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1790 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1796 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1798 struct rte_eth_dev *dev;
1801 if (!rte_eth_dev_is_valid_port(port_id)) {
1802 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1806 dev = &rte_eth_devices[port_id];
1808 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1809 ret |= ETH_VLAN_STRIP_OFFLOAD ;
1811 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1812 ret |= ETH_VLAN_FILTER_OFFLOAD ;
1814 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1815 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
1821 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1823 struct rte_eth_dev *dev;
1825 if (!rte_eth_dev_is_valid_port(port_id)) {
1826 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1830 dev = &rte_eth_devices[port_id];
1831 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1832 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1838 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1839 struct rte_fdir_filter *fdir_filter,
1842 struct rte_eth_dev *dev;
1844 if (!rte_eth_dev_is_valid_port(port_id)) {
1845 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1849 dev = &rte_eth_devices[port_id];
1851 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1852 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1853 port_id, dev->data->dev_conf.fdir_conf.mode);
1857 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1858 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1859 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1860 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1861 "None l4type, source & destinations ports " \
1862 "should be null!\n");
1866 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1867 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1872 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1873 struct rte_fdir_filter *fdir_filter,
1876 struct rte_eth_dev *dev;
1878 if (!rte_eth_dev_is_valid_port(port_id)) {
1879 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1883 dev = &rte_eth_devices[port_id];
1885 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1886 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1887 port_id, dev->data->dev_conf.fdir_conf.mode);
1891 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1892 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1893 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1894 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1895 "None l4type, source & destinations ports " \
1896 "should be null!\n");
1900 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
1901 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
1907 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
1908 struct rte_fdir_filter *fdir_filter)
1910 struct rte_eth_dev *dev;
1912 if (!rte_eth_dev_is_valid_port(port_id)) {
1913 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1917 dev = &rte_eth_devices[port_id];
1919 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1920 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1921 port_id, dev->data->dev_conf.fdir_conf.mode);
1925 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1926 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1927 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1928 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1929 "None l4type source & destinations ports " \
1930 "should be null!\n");
1934 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
1935 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
1939 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
1941 struct rte_eth_dev *dev;
1943 if (!rte_eth_dev_is_valid_port(port_id)) {
1944 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1948 dev = &rte_eth_devices[port_id];
1949 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1950 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1954 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
1956 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
1961 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
1962 struct rte_fdir_filter *fdir_filter,
1963 uint16_t soft_id, uint8_t queue,
1966 struct rte_eth_dev *dev;
1968 if (!rte_eth_dev_is_valid_port(port_id)) {
1969 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1973 dev = &rte_eth_devices[port_id];
1975 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1976 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1977 port_id, dev->data->dev_conf.fdir_conf.mode);
1981 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1982 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1983 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1984 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1985 "None l4type, source & destinations ports " \
1986 "should be null!\n");
1990 /* For now IPv6 is not supported with perfect filter */
1991 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1994 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
1995 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
2001 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
2002 struct rte_fdir_filter *fdir_filter,
2003 uint16_t soft_id, uint8_t queue,
2006 struct rte_eth_dev *dev;
2008 if (!rte_eth_dev_is_valid_port(port_id)) {
2009 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2013 dev = &rte_eth_devices[port_id];
2015 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
2016 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2017 port_id, dev->data->dev_conf.fdir_conf.mode);
2021 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2022 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2023 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2024 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
2025 "None l4type, source & destinations ports " \
2026 "should be null!\n");
2030 /* For now IPv6 is not supported with perfect filter */
2031 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2034 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
2035 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
2036 soft_id, queue, drop);
2040 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
2041 struct rte_fdir_filter *fdir_filter,
2044 struct rte_eth_dev *dev;
2046 if (!rte_eth_dev_is_valid_port(port_id)) {
2047 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2051 dev = &rte_eth_devices[port_id];
2053 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
2054 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2055 port_id, dev->data->dev_conf.fdir_conf.mode);
2059 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2060 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2061 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2062 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
2063 "None l4type, source & destinations ports " \
2064 "should be null!\n");
2068 /* For now IPv6 is not supported with perfect filter */
2069 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2072 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
2073 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
2078 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
2080 struct rte_eth_dev *dev;
2082 if (!rte_eth_dev_is_valid_port(port_id)) {
2083 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2087 dev = &rte_eth_devices[port_id];
2088 if (! (dev->data->dev_conf.fdir_conf.mode)) {
2089 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
2093 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
2094 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
2098 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2100 struct rte_eth_dev *dev;
2102 if (!rte_eth_dev_is_valid_port(port_id)) {
2103 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2107 dev = &rte_eth_devices[port_id];
2108 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2109 memset(fc_conf, 0, sizeof(*fc_conf));
2110 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
2114 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2116 struct rte_eth_dev *dev;
2118 if (!rte_eth_dev_is_valid_port(port_id)) {
2119 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2123 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2124 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2128 dev = &rte_eth_devices[port_id];
2129 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2130 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
2134 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
2136 struct rte_eth_dev *dev;
2138 if (!rte_eth_dev_is_valid_port(port_id)) {
2139 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2143 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2144 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2148 dev = &rte_eth_devices[port_id];
2149 /* High water, low water validation are device specific */
2150 if (*dev->dev_ops->priority_flow_ctrl_set)
2151 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
2156 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2164 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
2165 PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
2166 RTE_RETA_GROUP_SIZE);
2170 num = reta_size / RTE_RETA_GROUP_SIZE;
2171 for (i = 0; i < num; i++) {
2172 if (reta_conf[i].mask)
2180 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2184 uint16_t i, idx, shift;
2190 PMD_DEBUG_TRACE("No receive queue is available\n");
2194 for (i = 0; i < reta_size; i++) {
2195 idx = i / RTE_RETA_GROUP_SIZE;
2196 shift = i % RTE_RETA_GROUP_SIZE;
2197 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2198 (reta_conf[idx].reta[shift] >= max_rxq)) {
2199 PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2200 "the maximum rxq index: %u\n", idx, shift,
2201 reta_conf[idx].reta[shift], max_rxq);
2210 rte_eth_dev_rss_reta_update(uint8_t port_id,
2211 struct rte_eth_rss_reta_entry64 *reta_conf,
2214 struct rte_eth_dev *dev;
2217 if (!rte_eth_dev_is_valid_port(port_id)) {
2218 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2222 /* Check mask bits */
2223 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2227 dev = &rte_eth_devices[port_id];
2229 /* Check entry value */
2230 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2231 dev->data->nb_rx_queues);
2235 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2236 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2240 rte_eth_dev_rss_reta_query(uint8_t port_id,
2241 struct rte_eth_rss_reta_entry64 *reta_conf,
2244 struct rte_eth_dev *dev;
2247 if (port_id >= nb_ports) {
2248 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2252 /* Check mask bits */
2253 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2257 dev = &rte_eth_devices[port_id];
2258 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2259 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2263 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2265 struct rte_eth_dev *dev;
2266 uint16_t rss_hash_protos;
2268 if (!rte_eth_dev_is_valid_port(port_id)) {
2269 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2273 rss_hash_protos = rss_conf->rss_hf;
2274 if ((rss_hash_protos != 0) &&
2275 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2276 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2280 dev = &rte_eth_devices[port_id];
2281 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2282 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2286 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2287 struct rte_eth_rss_conf *rss_conf)
2289 struct rte_eth_dev *dev;
2291 if (!rte_eth_dev_is_valid_port(port_id)) {
2292 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2296 dev = &rte_eth_devices[port_id];
2297 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2298 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2302 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
2303 struct rte_eth_udp_tunnel *udp_tunnel)
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 if (udp_tunnel == NULL) {
2313 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2317 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2318 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2322 dev = &rte_eth_devices[port_id];
2323 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
2324 return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
2328 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
2329 struct rte_eth_udp_tunnel *udp_tunnel)
2331 struct rte_eth_dev *dev;
2333 if (!rte_eth_dev_is_valid_port(port_id)) {
2334 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2338 dev = &rte_eth_devices[port_id];
2340 if (udp_tunnel == NULL) {
2341 PMD_DEBUG_TRACE("Invalid udp_tunnel parametr\n");
2345 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2346 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2350 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2351 return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2355 rte_eth_led_on(uint8_t port_id)
2357 struct rte_eth_dev *dev;
2359 if (!rte_eth_dev_is_valid_port(port_id)) {
2360 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2364 dev = &rte_eth_devices[port_id];
2365 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2366 return ((*dev->dev_ops->dev_led_on)(dev));
2370 rte_eth_led_off(uint8_t port_id)
2372 struct rte_eth_dev *dev;
2374 if (!rte_eth_dev_is_valid_port(port_id)) {
2375 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2379 dev = &rte_eth_devices[port_id];
2380 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2381 return ((*dev->dev_ops->dev_led_off)(dev));
2385 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2389 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2391 struct rte_eth_dev_info dev_info;
2392 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2395 rte_eth_dev_info_get(port_id, &dev_info);
2397 for (i = 0; i < dev_info.max_mac_addrs; i++)
2398 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2404 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
2407 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2410 struct rte_eth_dev *dev;
2414 if (!rte_eth_dev_is_valid_port(port_id)) {
2415 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2419 dev = &rte_eth_devices[port_id];
2420 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2422 if (is_zero_ether_addr(addr)) {
2423 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2427 if (pool >= ETH_64_POOLS) {
2428 PMD_DEBUG_TRACE("pool id must be 0-%d\n",ETH_64_POOLS - 1);
2432 index = get_mac_addr_index(port_id, addr);
2434 index = get_mac_addr_index(port_id, &null_mac_addr);
2436 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2441 pool_mask = dev->data->mac_pool_sel[index];
2443 /* Check if both MAC address and pool is alread there, and do nothing */
2444 if (pool_mask & (1ULL << pool))
2449 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2451 /* Update address in NIC data structure */
2452 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2454 /* Update pool bitmap in NIC data structure */
2455 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2461 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2463 struct rte_eth_dev *dev;
2466 if (!rte_eth_dev_is_valid_port(port_id)) {
2467 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2471 dev = &rte_eth_devices[port_id];
2472 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2474 index = get_mac_addr_index(port_id, addr);
2476 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2477 return (-EADDRINUSE);
2478 } else if (index < 0)
2479 return 0; /* Do nothing if address wasn't found */
2482 (*dev->dev_ops->mac_addr_remove)(dev, index);
2484 /* Update address in NIC data structure */
2485 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2487 /* reset pool bitmap */
2488 dev->data->mac_pool_sel[index] = 0;
2494 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2495 uint16_t rx_mode, uint8_t on)
2498 struct rte_eth_dev *dev;
2499 struct rte_eth_dev_info dev_info;
2501 if (!rte_eth_dev_is_valid_port(port_id)) {
2502 PMD_DEBUG_TRACE("set VF RX mode:Invalid port_id=%d\n",
2507 dev = &rte_eth_devices[port_id];
2508 rte_eth_dev_info_get(port_id, &dev_info);
2510 num_vfs = dev_info.max_vfs;
2513 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2518 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2521 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2522 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2526 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2530 get_hash_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2532 struct rte_eth_dev_info dev_info;
2533 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2536 rte_eth_dev_info_get(port_id, &dev_info);
2537 if (!dev->data->hash_mac_addrs)
2540 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2541 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2542 ETHER_ADDR_LEN) == 0)
2549 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2554 struct rte_eth_dev *dev;
2556 if (!rte_eth_dev_is_valid_port(port_id)) {
2557 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2562 dev = &rte_eth_devices[port_id];
2563 if (is_zero_ether_addr(addr)) {
2564 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2569 index = get_hash_mac_addr_index(port_id, addr);
2570 /* Check if it's already there, and do nothing */
2571 if ((index >= 0) && (on))
2576 PMD_DEBUG_TRACE("port %d: the MAC address was not"
2577 "set in UTA\n", port_id);
2581 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2583 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2589 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2590 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2592 /* Update address in NIC data structure */
2594 ether_addr_copy(addr,
2595 &dev->data->hash_mac_addrs[index]);
2597 ether_addr_copy(&null_mac_addr,
2598 &dev->data->hash_mac_addrs[index]);
2605 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2607 struct rte_eth_dev *dev;
2609 if (!rte_eth_dev_is_valid_port(port_id)) {
2610 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2615 dev = &rte_eth_devices[port_id];
2617 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2618 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2622 rte_eth_dev_set_vf_rx(uint8_t port_id,uint16_t vf, uint8_t on)
2625 struct rte_eth_dev *dev;
2626 struct rte_eth_dev_info dev_info;
2628 if (!rte_eth_dev_is_valid_port(port_id)) {
2629 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2633 dev = &rte_eth_devices[port_id];
2634 rte_eth_dev_info_get(port_id, &dev_info);
2636 num_vfs = dev_info.max_vfs;
2639 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2643 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2644 return (*dev->dev_ops->set_vf_rx)(dev, vf,on);
2648 rte_eth_dev_set_vf_tx(uint8_t port_id,uint16_t vf, uint8_t on)
2651 struct rte_eth_dev *dev;
2652 struct rte_eth_dev_info dev_info;
2654 if (!rte_eth_dev_is_valid_port(port_id)) {
2655 PMD_DEBUG_TRACE("set pool tx:Invalid port_id=%d\n", port_id);
2659 dev = &rte_eth_devices[port_id];
2660 rte_eth_dev_info_get(port_id, &dev_info);
2662 num_vfs = dev_info.max_vfs;
2665 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2669 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2670 return (*dev->dev_ops->set_vf_tx)(dev, vf,on);
2674 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2675 uint64_t vf_mask,uint8_t vlan_on)
2677 struct rte_eth_dev *dev;
2679 if (!rte_eth_dev_is_valid_port(port_id)) {
2680 PMD_DEBUG_TRACE("VF VLAN filter:invalid port id=%d\n",
2684 dev = &rte_eth_devices[port_id];
2686 if(vlan_id > ETHER_MAX_VLAN_ID)
2688 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2694 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2698 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2699 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2703 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2706 struct rte_eth_dev *dev;
2707 struct rte_eth_dev_info dev_info;
2708 struct rte_eth_link link;
2710 if (!rte_eth_dev_is_valid_port(port_id)) {
2711 PMD_DEBUG_TRACE("set queue rate limit:invalid port id=%d\n",
2716 dev = &rte_eth_devices[port_id];
2717 rte_eth_dev_info_get(port_id, &dev_info);
2718 link = dev->data->dev_link;
2720 if (queue_idx > dev_info.max_tx_queues) {
2721 PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2722 "invalid queue id=%d\n", port_id, queue_idx);
2726 if (tx_rate > link.link_speed) {
2727 PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2728 "bigger than link speed= %d\n",
2729 tx_rate, link.link_speed);
2733 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2734 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2737 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2740 struct rte_eth_dev *dev;
2741 struct rte_eth_dev_info dev_info;
2742 struct rte_eth_link link;
2747 if (!rte_eth_dev_is_valid_port(port_id)) {
2748 PMD_DEBUG_TRACE("set VF rate limit:invalid port id=%d\n",
2753 dev = &rte_eth_devices[port_id];
2754 rte_eth_dev_info_get(port_id, &dev_info);
2755 link = dev->data->dev_link;
2757 if (vf > dev_info.max_vfs) {
2758 PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2759 "invalid vf id=%d\n", port_id, vf);
2763 if (tx_rate > link.link_speed) {
2764 PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2765 "bigger than link speed= %d\n",
2766 tx_rate, link.link_speed);
2770 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2771 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2775 rte_eth_mirror_rule_set(uint8_t port_id,
2776 struct rte_eth_vmdq_mirror_conf *mirror_conf,
2777 uint8_t rule_id, uint8_t on)
2779 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2781 if (!rte_eth_dev_is_valid_port(port_id)) {
2782 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2786 if (mirror_conf->rule_type_mask == 0) {
2787 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2791 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2792 PMD_DEBUG_TRACE("Invalid dst pool, pool id must"
2793 "be 0-%d\n",ETH_64_POOLS - 1);
2797 if ((mirror_conf->rule_type_mask & ETH_VMDQ_POOL_MIRROR) &&
2798 (mirror_conf->pool_mask == 0)) {
2799 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not"
2804 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2806 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2807 ETH_VMDQ_NUM_MIRROR_RULE - 1);
2811 dev = &rte_eth_devices[port_id];
2812 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2814 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2818 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2820 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2822 if (!rte_eth_dev_is_valid_port(port_id)) {
2823 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2827 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2829 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2830 ETH_VMDQ_NUM_MIRROR_RULE-1);
2834 dev = &rte_eth_devices[port_id];
2835 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2837 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2840 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2842 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2843 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2845 struct rte_eth_dev *dev;
2847 if (!rte_eth_dev_is_valid_port(port_id)) {
2848 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2852 dev = &rte_eth_devices[port_id];
2853 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);
2854 if (queue_id >= dev->data->nb_rx_queues) {
2855 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2858 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2863 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2864 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2866 struct rte_eth_dev *dev;
2868 if (!rte_eth_dev_is_valid_port(port_id)) {
2869 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2873 dev = &rte_eth_devices[port_id];
2875 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0);
2876 if (queue_id >= dev->data->nb_tx_queues) {
2877 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2880 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2885 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2887 struct rte_eth_dev *dev;
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 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0);
2896 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2900 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2902 struct rte_eth_dev *dev;
2904 if (!rte_eth_dev_is_valid_port(port_id)) {
2905 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2909 dev = &rte_eth_devices[port_id];
2910 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2911 return (*dev->dev_ops->rx_descriptor_done)( \
2912 dev->data->rx_queues[queue_id], offset);
2917 rte_eth_dev_callback_register(uint8_t port_id,
2918 enum rte_eth_event_type event,
2919 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2921 struct rte_eth_dev *dev;
2922 struct rte_eth_dev_callback *user_cb;
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_spinlock_lock(&rte_eth_dev_cb_lock);
2935 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2936 if (user_cb->cb_fn == cb_fn &&
2937 user_cb->cb_arg == cb_arg &&
2938 user_cb->event == event) {
2943 /* create a new callback. */
2944 if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2945 sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
2946 user_cb->cb_fn = cb_fn;
2947 user_cb->cb_arg = cb_arg;
2948 user_cb->event = event;
2949 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2952 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2953 return ((user_cb == NULL) ? -ENOMEM : 0);
2957 rte_eth_dev_callback_unregister(uint8_t port_id,
2958 enum rte_eth_event_type event,
2959 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2962 struct rte_eth_dev *dev;
2963 struct rte_eth_dev_callback *cb, *next;
2968 if (!rte_eth_dev_is_valid_port(port_id)) {
2969 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2973 dev = &rte_eth_devices[port_id];
2974 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2977 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2979 next = TAILQ_NEXT(cb, next);
2981 if (cb->cb_fn != cb_fn || cb->event != event ||
2982 (cb->cb_arg != (void *)-1 &&
2983 cb->cb_arg != cb_arg))
2987 * if this callback is not executing right now,
2990 if (cb->active == 0) {
2991 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2998 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3003 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
3004 enum rte_eth_event_type event)
3006 struct rte_eth_dev_callback *cb_lst;
3007 struct rte_eth_dev_callback dev_cb;
3009 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3010 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
3011 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
3015 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3016 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
3018 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3021 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3023 #ifdef RTE_NIC_BYPASS
3024 int rte_eth_dev_bypass_init(uint8_t port_id)
3026 struct rte_eth_dev *dev;
3028 if (!rte_eth_dev_is_valid_port(port_id)) {
3029 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3033 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3034 PMD_DEBUG_TRACE("Invalid port device\n");
3038 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
3039 (*dev->dev_ops->bypass_init)(dev);
3044 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
3046 struct rte_eth_dev *dev;
3048 if (!rte_eth_dev_is_valid_port(port_id)) {
3049 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3053 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3054 PMD_DEBUG_TRACE("Invalid port device\n");
3057 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
3058 (*dev->dev_ops->bypass_state_show)(dev, state);
3063 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
3065 struct rte_eth_dev *dev;
3067 if (!rte_eth_dev_is_valid_port(port_id)) {
3068 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3072 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3073 PMD_DEBUG_TRACE("Invalid port device\n");
3077 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
3078 (*dev->dev_ops->bypass_state_set)(dev, new_state);
3083 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
3085 struct rte_eth_dev *dev;
3087 if (!rte_eth_dev_is_valid_port(port_id)) {
3088 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3092 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3093 PMD_DEBUG_TRACE("Invalid port device\n");
3097 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
3098 (*dev->dev_ops->bypass_event_show)(dev, event, state);
3103 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
3105 struct rte_eth_dev *dev;
3107 if (!rte_eth_dev_is_valid_port(port_id)) {
3108 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3112 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3113 PMD_DEBUG_TRACE("Invalid port device\n");
3117 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
3118 (*dev->dev_ops->bypass_event_set)(dev, event, state);
3123 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
3125 struct rte_eth_dev *dev;
3127 if (!rte_eth_dev_is_valid_port(port_id)) {
3128 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3132 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3133 PMD_DEBUG_TRACE("Invalid port device\n");
3137 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
3138 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
3143 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
3145 struct rte_eth_dev *dev;
3147 if (!rte_eth_dev_is_valid_port(port_id)) {
3148 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3152 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3153 PMD_DEBUG_TRACE("Invalid port device\n");
3157 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
3158 (*dev->dev_ops->bypass_ver_show)(dev, ver);
3163 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
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 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3173 PMD_DEBUG_TRACE("Invalid port device\n");
3177 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
3178 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
3183 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
3185 struct rte_eth_dev *dev;
3187 if (!rte_eth_dev_is_valid_port(port_id)) {
3188 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3192 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3193 PMD_DEBUG_TRACE("Invalid port device\n");
3197 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
3198 (*dev->dev_ops->bypass_wd_reset)(dev);
3204 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
3206 struct rte_eth_dev *dev;
3208 if (!rte_eth_dev_is_valid_port(port_id)) {
3209 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3213 dev = &rte_eth_devices[port_id];
3214 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3215 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3216 RTE_ETH_FILTER_NOP, NULL);
3220 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
3221 enum rte_filter_op filter_op, void *arg)
3223 struct rte_eth_dev *dev;
3225 if (!rte_eth_dev_is_valid_port(port_id)) {
3226 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3230 dev = &rte_eth_devices[port_id];
3231 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3232 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
3236 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
3237 rte_rxtx_callback_fn fn, void *user_param)
3239 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3240 rte_errno = ENOTSUP;
3243 /* check input parameters */
3244 if (port_id >= nb_ports || fn == NULL ||
3245 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3250 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3258 cb->param = user_param;
3259 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3260 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3265 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
3266 rte_rxtx_callback_fn fn, void *user_param)
3268 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3269 rte_errno = ENOTSUP;
3272 /* check input parameters */
3273 if (port_id >= nb_ports || fn == NULL ||
3274 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3279 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3287 cb->param = user_param;
3288 cb->next = rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3289 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3294 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3295 struct rte_eth_rxtx_callback *user_cb)
3297 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3300 /* Check input parameters. */
3301 if (port_id >= nb_ports || user_cb == NULL ||
3302 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3306 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3307 struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
3308 struct rte_eth_rxtx_callback *prev_cb;
3310 /* Reset head pointer and remove user cb if first in the list. */
3311 if (cb == user_cb) {
3312 dev->post_rx_burst_cbs[queue_id] = user_cb->next;
3316 /* Remove the user cb from the callback list. */
3321 if (cb == user_cb) {
3322 prev_cb->next = user_cb->next;
3326 } while (cb != NULL);
3328 /* Callback wasn't found. */
3333 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3334 struct rte_eth_rxtx_callback *user_cb)
3336 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3339 /* Check input parameters. */
3340 if (port_id >= nb_ports || user_cb == NULL ||
3341 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3345 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3346 struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
3347 struct rte_eth_rxtx_callback *prev_cb;
3349 /* Reset head pointer and remove user cb if first in the list. */
3350 if (cb == user_cb) {
3351 dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
3355 /* Remove the user cb from the callback list. */
3360 if (cb == user_cb) {
3361 prev_cb->next = user_cb->next;
3365 } while (cb != NULL);
3367 /* Callback wasn't found. */