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)
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;
259 rte_eth_dev_create_unique_device_name(char *name, size_t size,
260 struct rte_pci_device *pci_dev)
264 if ((name == NULL) || (pci_dev == NULL))
267 ret = snprintf(name, size, "%d:%d.%d",
268 pci_dev->addr.bus, pci_dev->addr.devid,
269 pci_dev->addr.function);
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);
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)
430 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
432 uint16_t old_nb_queues = dev->data->nb_rx_queues;
436 if (dev->data->rx_queues == NULL) { /* first time configuration */
437 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
438 sizeof(dev->data->rx_queues[0]) * nb_queues,
439 RTE_CACHE_LINE_SIZE);
440 if (dev->data->rx_queues == NULL) {
441 dev->data->nb_rx_queues = 0;
444 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
445 dev->post_rx_burst_cbs = rte_zmalloc(
446 "ethdev->post_rx_burst_cbs",
447 sizeof(*dev->post_rx_burst_cbs) * nb_queues,
448 RTE_CACHE_LINE_SIZE);
449 if (dev->post_rx_burst_cbs == NULL) {
450 rte_free(dev->data->rx_queues);
451 dev->data->rx_queues = NULL;
452 dev->data->nb_rx_queues = 0;
457 } else { /* re-configure */
458 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
460 rxq = dev->data->rx_queues;
462 for (i = nb_queues; i < old_nb_queues; i++)
463 (*dev->dev_ops->rx_queue_release)(rxq[i]);
464 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
465 RTE_CACHE_LINE_SIZE);
468 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
469 dev->post_rx_burst_cbs = rte_realloc(
470 dev->post_rx_burst_cbs,
471 sizeof(*dev->post_rx_burst_cbs) *
472 nb_queues, RTE_CACHE_LINE_SIZE);
473 if (dev->post_rx_burst_cbs == NULL)
476 if (nb_queues > old_nb_queues) {
477 uint16_t new_qs = nb_queues - old_nb_queues;
478 memset(rxq + old_nb_queues, 0,
479 sizeof(rxq[0]) * new_qs);
480 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
481 memset(dev->post_rx_burst_cbs + old_nb_queues, 0,
482 sizeof(dev->post_rx_burst_cbs[0]) * new_qs);
486 dev->data->rx_queues = rxq;
489 dev->data->nb_rx_queues = nb_queues;
494 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
496 struct rte_eth_dev *dev;
498 /* This function is only safe when called from the primary process
499 * in a multi-process setup*/
500 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
502 if (!rte_eth_dev_is_valid_port(port_id)) {
503 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
507 dev = &rte_eth_devices[port_id];
508 if (rx_queue_id >= dev->data->nb_rx_queues) {
509 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
513 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
515 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
520 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
522 struct rte_eth_dev *dev;
524 /* This function is only safe when called from the primary process
525 * in a multi-process setup*/
526 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
528 if (!rte_eth_dev_is_valid_port(port_id)) {
529 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
533 dev = &rte_eth_devices[port_id];
534 if (rx_queue_id >= dev->data->nb_rx_queues) {
535 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
539 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
541 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
546 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
548 struct rte_eth_dev *dev;
550 /* This function is only safe when called from the primary process
551 * in a multi-process setup*/
552 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
554 if (!rte_eth_dev_is_valid_port(port_id)) {
555 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
559 dev = &rte_eth_devices[port_id];
560 if (tx_queue_id >= dev->data->nb_tx_queues) {
561 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
565 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
567 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
572 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
574 struct rte_eth_dev *dev;
576 /* This function is only safe when called from the primary process
577 * in a multi-process setup*/
578 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
580 if (!rte_eth_dev_is_valid_port(port_id)) {
581 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
585 dev = &rte_eth_devices[port_id];
586 if (tx_queue_id >= dev->data->nb_tx_queues) {
587 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
591 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
593 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
598 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
600 uint16_t old_nb_queues = dev->data->nb_tx_queues;
604 if (dev->data->tx_queues == NULL) { /* first time configuration */
605 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
606 sizeof(dev->data->tx_queues[0]) * nb_queues,
607 RTE_CACHE_LINE_SIZE);
608 if (dev->data->tx_queues == NULL) {
609 dev->data->nb_tx_queues = 0;
612 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
613 dev->pre_tx_burst_cbs = rte_zmalloc(
614 "ethdev->pre_tx_burst_cbs",
615 sizeof(*dev->pre_tx_burst_cbs) * nb_queues,
616 RTE_CACHE_LINE_SIZE);
617 if (dev->pre_tx_burst_cbs == NULL) {
618 rte_free(dev->data->tx_queues);
619 dev->data->tx_queues = NULL;
620 dev->data->nb_tx_queues = 0;
625 } else { /* re-configure */
626 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
628 txq = dev->data->tx_queues;
630 for (i = nb_queues; i < old_nb_queues; i++)
631 (*dev->dev_ops->tx_queue_release)(txq[i]);
632 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
633 RTE_CACHE_LINE_SIZE);
636 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
637 dev->pre_tx_burst_cbs = rte_realloc(
638 dev->pre_tx_burst_cbs,
639 sizeof(*dev->pre_tx_burst_cbs) *
640 nb_queues, RTE_CACHE_LINE_SIZE);
641 if (dev->pre_tx_burst_cbs == NULL)
644 if (nb_queues > old_nb_queues) {
645 uint16_t new_qs = nb_queues - old_nb_queues;
646 memset(txq + old_nb_queues, 0,
647 sizeof(txq[0]) * new_qs);
648 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
649 memset(dev->pre_tx_burst_cbs + old_nb_queues, 0,
650 sizeof(dev->pre_tx_burst_cbs[0]) * new_qs);
654 dev->data->tx_queues = txq;
657 dev->data->nb_tx_queues = nb_queues;
662 rte_eth_dev_check_vf_rss_rxq_num(uint8_t port_id, uint16_t nb_rx_q)
664 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
668 RTE_ETH_DEV_SRIOV(dev).active =
672 RTE_ETH_DEV_SRIOV(dev).active =
679 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = nb_rx_q;
680 RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx =
681 dev->pci_dev->max_vfs * nb_rx_q;
687 rte_eth_dev_check_mq_mode(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
688 const struct rte_eth_conf *dev_conf)
690 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
692 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
693 /* check multi-queue mode */
694 if ((dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) ||
695 (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB_RSS) ||
696 (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB)) {
697 /* SRIOV only works in VMDq enable mode */
698 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
700 "wrong VMDQ mq_mode rx %u tx %u\n",
702 dev_conf->rxmode.mq_mode,
703 dev_conf->txmode.mq_mode);
707 switch (dev_conf->rxmode.mq_mode) {
708 case ETH_MQ_RX_VMDQ_DCB:
709 case ETH_MQ_RX_VMDQ_DCB_RSS:
710 /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
711 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
713 "unsupported VMDQ mq_mode rx %u\n",
714 port_id, dev_conf->rxmode.mq_mode);
717 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
719 "Rx mq mode is changed from:"
720 "mq_mode %u into VMDQ mq_mode %u\n",
722 dev_conf->rxmode.mq_mode,
723 dev->data->dev_conf.rxmode.mq_mode);
724 case ETH_MQ_RX_VMDQ_RSS:
725 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_RSS;
726 if (nb_rx_q <= RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)
727 if (rte_eth_dev_check_vf_rss_rxq_num(port_id, nb_rx_q) != 0) {
728 PMD_DEBUG_TRACE("ethdev port_id=%d"
729 " SRIOV active, invalid queue"
730 " number for VMDQ RSS, allowed"
731 " value are 1, 2 or 4\n",
736 default: /* ETH_MQ_RX_VMDQ_ONLY or ETH_MQ_RX_NONE */
737 /* if nothing mq mode configure, use default scheme */
738 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
739 if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
740 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
744 switch (dev_conf->txmode.mq_mode) {
745 case ETH_MQ_TX_VMDQ_DCB:
746 /* DCB VMDQ in SRIOV mode, not implement yet */
747 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
749 "unsupported VMDQ mq_mode tx %u\n",
750 port_id, dev_conf->txmode.mq_mode);
752 default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
753 /* if nothing mq mode configure, use default scheme */
754 dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
758 /* check valid queue number */
759 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
760 (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
761 PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
762 "queue number must less equal to %d\n",
763 port_id, RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
767 /* For vmdb+dcb mode check our configuration before we go further */
768 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB) {
769 const struct rte_eth_vmdq_dcb_conf *conf;
771 if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
772 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
774 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
777 conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
778 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
779 conf->nb_queue_pools == ETH_32_POOLS)) {
780 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
781 "nb_queue_pools must be %d or %d\n",
782 port_id, ETH_16_POOLS, ETH_32_POOLS);
786 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
787 const struct rte_eth_vmdq_dcb_tx_conf *conf;
789 if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
790 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
792 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
795 conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
796 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
797 conf->nb_queue_pools == ETH_32_POOLS)) {
798 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
799 "nb_queue_pools != %d or nb_queue_pools "
801 port_id, ETH_16_POOLS, ETH_32_POOLS);
806 /* For DCB mode check our configuration before we go further */
807 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) {
808 const struct rte_eth_dcb_rx_conf *conf;
810 if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
811 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
813 port_id, ETH_DCB_NUM_QUEUES);
816 conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
817 if (! (conf->nb_tcs == ETH_4_TCS ||
818 conf->nb_tcs == ETH_8_TCS)) {
819 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
820 "nb_tcs != %d or nb_tcs "
822 port_id, ETH_4_TCS, ETH_8_TCS);
827 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
828 const struct rte_eth_dcb_tx_conf *conf;
830 if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
831 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
833 port_id, ETH_DCB_NUM_QUEUES);
836 conf = &(dev_conf->tx_adv_conf.dcb_tx_conf);
837 if (! (conf->nb_tcs == ETH_4_TCS ||
838 conf->nb_tcs == ETH_8_TCS)) {
839 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
840 "nb_tcs != %d or nb_tcs "
842 port_id, ETH_4_TCS, ETH_8_TCS);
851 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
852 const struct rte_eth_conf *dev_conf)
854 struct rte_eth_dev *dev;
855 struct rte_eth_dev_info dev_info;
858 /* This function is only safe when called from the primary process
859 * in a multi-process setup*/
860 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
862 if (!rte_eth_dev_is_valid_port(port_id)) {
863 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
867 dev = &rte_eth_devices[port_id];
869 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
870 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
872 if (dev->data->dev_started) {
874 "port %d must be stopped to allow configuration\n", port_id);
879 * Check that the numbers of RX and TX queues are not greater
880 * than the maximum number of RX and TX queues supported by the
883 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
884 if (nb_rx_q > dev_info.max_rx_queues) {
885 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
886 port_id, nb_rx_q, dev_info.max_rx_queues);
890 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
894 if (nb_tx_q > dev_info.max_tx_queues) {
895 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
896 port_id, nb_tx_q, dev_info.max_tx_queues);
900 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
904 /* Copy the dev_conf parameter into the dev structure */
905 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
908 * If link state interrupt is enabled, check that the
909 * device supports it.
911 if (dev_conf->intr_conf.lsc == 1) {
912 const struct rte_pci_driver *pci_drv = &dev->driver->pci_drv;
914 if (!(pci_drv->drv_flags & RTE_PCI_DRV_INTR_LSC)) {
915 PMD_DEBUG_TRACE("driver %s does not support lsc\n",
922 * If jumbo frames are enabled, check that the maximum RX packet
923 * length is supported by the configured device.
925 if (dev_conf->rxmode.jumbo_frame == 1) {
926 if (dev_conf->rxmode.max_rx_pkt_len >
927 dev_info.max_rx_pktlen) {
928 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
929 " > max valid value %u\n",
931 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
932 (unsigned)dev_info.max_rx_pktlen);
935 else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
936 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
937 " < min valid value %u\n",
939 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
940 (unsigned)ETHER_MIN_LEN);
944 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
945 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
946 /* Use default value */
947 dev->data->dev_conf.rxmode.max_rx_pkt_len =
951 /* multipe queue mode checking */
952 diag = rte_eth_dev_check_mq_mode(port_id, nb_rx_q, nb_tx_q, dev_conf);
954 PMD_DEBUG_TRACE("port%d rte_eth_dev_check_mq_mode = %d\n",
960 * Setup new number of RX/TX queues and reconfigure device.
962 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
964 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
969 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
971 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
973 rte_eth_dev_rx_queue_config(dev, 0);
977 diag = (*dev->dev_ops->dev_configure)(dev);
979 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
981 rte_eth_dev_rx_queue_config(dev, 0);
982 rte_eth_dev_tx_queue_config(dev, 0);
990 rte_eth_dev_config_restore(uint8_t port_id)
992 struct rte_eth_dev *dev;
993 struct rte_eth_dev_info dev_info;
994 struct ether_addr addr;
998 dev = &rte_eth_devices[port_id];
1000 rte_eth_dev_info_get(port_id, &dev_info);
1002 if (RTE_ETH_DEV_SRIOV(dev).active)
1003 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
1005 /* replay MAC address configuration */
1006 for (i = 0; i < dev_info.max_mac_addrs; i++) {
1007 addr = dev->data->mac_addrs[i];
1009 /* skip zero address */
1010 if (is_zero_ether_addr(&addr))
1013 /* add address to the hardware */
1014 if (*dev->dev_ops->mac_addr_add &&
1015 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
1016 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
1018 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
1020 /* exit the loop but not return an error */
1025 /* replay promiscuous configuration */
1026 if (rte_eth_promiscuous_get(port_id) == 1)
1027 rte_eth_promiscuous_enable(port_id);
1028 else if (rte_eth_promiscuous_get(port_id) == 0)
1029 rte_eth_promiscuous_disable(port_id);
1031 /* replay allmulticast configuration */
1032 if (rte_eth_allmulticast_get(port_id) == 1)
1033 rte_eth_allmulticast_enable(port_id);
1034 else if (rte_eth_allmulticast_get(port_id) == 0)
1035 rte_eth_allmulticast_disable(port_id);
1039 rte_eth_dev_start(uint8_t port_id)
1041 struct rte_eth_dev *dev;
1044 /* This function is only safe when called from the primary process
1045 * in a multi-process setup*/
1046 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1048 if (!rte_eth_dev_is_valid_port(port_id)) {
1049 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1053 dev = &rte_eth_devices[port_id];
1055 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1057 if (dev->data->dev_started != 0) {
1058 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1059 " already started\n",
1064 diag = (*dev->dev_ops->dev_start)(dev);
1066 dev->data->dev_started = 1;
1070 rte_eth_dev_config_restore(port_id);
1072 if (dev->data->dev_conf.intr_conf.lsc != 0) {
1073 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1074 (*dev->dev_ops->link_update)(dev, 0);
1080 rte_eth_dev_stop(uint8_t port_id)
1082 struct rte_eth_dev *dev;
1084 /* This function is only safe when called from the primary process
1085 * in a multi-process setup*/
1086 PROC_PRIMARY_OR_RET();
1088 if (!rte_eth_dev_is_valid_port(port_id)) {
1089 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1093 dev = &rte_eth_devices[port_id];
1095 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1097 if (dev->data->dev_started == 0) {
1098 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1099 " already stopped\n",
1104 dev->data->dev_started = 0;
1105 (*dev->dev_ops->dev_stop)(dev);
1109 rte_eth_dev_set_link_up(uint8_t port_id)
1111 struct rte_eth_dev *dev;
1113 /* This function is only safe when called from the primary process
1114 * in a multi-process setup*/
1115 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1117 if (!rte_eth_dev_is_valid_port(port_id)) {
1118 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1122 dev = &rte_eth_devices[port_id];
1124 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1125 return (*dev->dev_ops->dev_set_link_up)(dev);
1129 rte_eth_dev_set_link_down(uint8_t port_id)
1131 struct rte_eth_dev *dev;
1133 /* This function is only safe when called from the primary process
1134 * in a multi-process setup*/
1135 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1137 if (!rte_eth_dev_is_valid_port(port_id)) {
1138 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1142 dev = &rte_eth_devices[port_id];
1144 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1145 return (*dev->dev_ops->dev_set_link_down)(dev);
1149 rte_eth_dev_close(uint8_t port_id)
1151 struct rte_eth_dev *dev;
1153 /* This function is only safe when called from the primary process
1154 * in a multi-process setup*/
1155 PROC_PRIMARY_OR_RET();
1157 if (!rte_eth_dev_is_valid_port(port_id)) {
1158 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1162 dev = &rte_eth_devices[port_id];
1164 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1165 dev->data->dev_started = 0;
1166 (*dev->dev_ops->dev_close)(dev);
1170 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1171 uint16_t nb_rx_desc, unsigned int socket_id,
1172 const struct rte_eth_rxconf *rx_conf,
1173 struct rte_mempool *mp)
1176 uint32_t mbp_buf_size;
1177 struct rte_eth_dev *dev;
1178 struct rte_pktmbuf_pool_private *mbp_priv;
1179 struct rte_eth_dev_info dev_info;
1181 /* This function is only safe when called from the primary process
1182 * in a multi-process setup*/
1183 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1185 if (!rte_eth_dev_is_valid_port(port_id)) {
1186 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1190 dev = &rte_eth_devices[port_id];
1191 if (rx_queue_id >= dev->data->nb_rx_queues) {
1192 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1196 if (dev->data->dev_started) {
1198 "port %d must be stopped to allow configuration\n", port_id);
1202 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1203 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1206 * Check the size of the mbuf data buffer.
1207 * This value must be provided in the private data of the memory pool.
1208 * First check that the memory pool has a valid private data.
1210 rte_eth_dev_info_get(port_id, &dev_info);
1211 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1212 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1213 mp->name, (int) mp->private_data_size,
1214 (int) sizeof(struct rte_pktmbuf_pool_private));
1217 mbp_priv = rte_mempool_get_priv(mp);
1218 mbp_buf_size = mbp_priv->mbuf_data_room_size;
1220 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1221 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1222 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1226 (int)(RTE_PKTMBUF_HEADROOM +
1227 dev_info.min_rx_bufsize),
1228 (int)RTE_PKTMBUF_HEADROOM,
1229 (int)dev_info.min_rx_bufsize);
1233 if (rx_conf == NULL)
1234 rx_conf = &dev_info.default_rxconf;
1236 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1237 socket_id, rx_conf, mp);
1239 if (!dev->data->min_rx_buf_size ||
1240 dev->data->min_rx_buf_size > mbp_buf_size)
1241 dev->data->min_rx_buf_size = mbp_buf_size;
1248 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1249 uint16_t nb_tx_desc, unsigned int socket_id,
1250 const struct rte_eth_txconf *tx_conf)
1252 struct rte_eth_dev *dev;
1253 struct rte_eth_dev_info dev_info;
1255 /* This function is only safe when called from the primary process
1256 * in a multi-process setup*/
1257 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1259 if (!rte_eth_dev_is_valid_port(port_id)) {
1260 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1264 dev = &rte_eth_devices[port_id];
1265 if (tx_queue_id >= dev->data->nb_tx_queues) {
1266 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1270 if (dev->data->dev_started) {
1272 "port %d must be stopped to allow configuration\n", port_id);
1276 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1277 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1279 rte_eth_dev_info_get(port_id, &dev_info);
1281 if (tx_conf == NULL)
1282 tx_conf = &dev_info.default_txconf;
1284 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1285 socket_id, tx_conf);
1289 rte_eth_promiscuous_enable(uint8_t port_id)
1291 struct rte_eth_dev *dev;
1293 if (!rte_eth_dev_is_valid_port(port_id)) {
1294 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1298 dev = &rte_eth_devices[port_id];
1300 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1301 (*dev->dev_ops->promiscuous_enable)(dev);
1302 dev->data->promiscuous = 1;
1306 rte_eth_promiscuous_disable(uint8_t port_id)
1308 struct rte_eth_dev *dev;
1310 if (!rte_eth_dev_is_valid_port(port_id)) {
1311 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1315 dev = &rte_eth_devices[port_id];
1317 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1318 dev->data->promiscuous = 0;
1319 (*dev->dev_ops->promiscuous_disable)(dev);
1323 rte_eth_promiscuous_get(uint8_t port_id)
1325 struct rte_eth_dev *dev;
1327 if (!rte_eth_dev_is_valid_port(port_id)) {
1328 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1332 dev = &rte_eth_devices[port_id];
1333 return dev->data->promiscuous;
1337 rte_eth_allmulticast_enable(uint8_t port_id)
1339 struct rte_eth_dev *dev;
1341 if (!rte_eth_dev_is_valid_port(port_id)) {
1342 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1346 dev = &rte_eth_devices[port_id];
1348 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1349 (*dev->dev_ops->allmulticast_enable)(dev);
1350 dev->data->all_multicast = 1;
1354 rte_eth_allmulticast_disable(uint8_t port_id)
1356 struct rte_eth_dev *dev;
1358 if (!rte_eth_dev_is_valid_port(port_id)) {
1359 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1363 dev = &rte_eth_devices[port_id];
1365 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1366 dev->data->all_multicast = 0;
1367 (*dev->dev_ops->allmulticast_disable)(dev);
1371 rte_eth_allmulticast_get(uint8_t port_id)
1373 struct rte_eth_dev *dev;
1375 if (!rte_eth_dev_is_valid_port(port_id)) {
1376 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1380 dev = &rte_eth_devices[port_id];
1381 return dev->data->all_multicast;
1385 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1386 struct rte_eth_link *link)
1388 struct rte_eth_link *dst = link;
1389 struct rte_eth_link *src = &(dev->data->dev_link);
1391 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1392 *(uint64_t *)src) == 0)
1399 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1401 struct rte_eth_dev *dev;
1403 if (!rte_eth_dev_is_valid_port(port_id)) {
1404 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1408 dev = &rte_eth_devices[port_id];
1410 if (dev->data->dev_conf.intr_conf.lsc != 0)
1411 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1413 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1414 (*dev->dev_ops->link_update)(dev, 1);
1415 *eth_link = dev->data->dev_link;
1420 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1422 struct rte_eth_dev *dev;
1424 if (!rte_eth_dev_is_valid_port(port_id)) {
1425 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1429 dev = &rte_eth_devices[port_id];
1431 if (dev->data->dev_conf.intr_conf.lsc != 0)
1432 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1434 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1435 (*dev->dev_ops->link_update)(dev, 0);
1436 *eth_link = dev->data->dev_link;
1441 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1443 struct rte_eth_dev *dev;
1445 if (!rte_eth_dev_is_valid_port(port_id)) {
1446 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1450 dev = &rte_eth_devices[port_id];
1451 memset(stats, 0, sizeof(*stats));
1453 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1454 (*dev->dev_ops->stats_get)(dev, stats);
1455 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1460 rte_eth_stats_reset(uint8_t port_id)
1462 struct rte_eth_dev *dev;
1464 if (!rte_eth_dev_is_valid_port(port_id)) {
1465 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1469 dev = &rte_eth_devices[port_id];
1471 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1472 (*dev->dev_ops->stats_reset)(dev);
1475 /* retrieve ethdev extended statistics */
1477 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1480 struct rte_eth_stats eth_stats;
1481 struct rte_eth_dev *dev;
1482 unsigned count, i, q;
1486 if (!rte_eth_dev_is_valid_port(port_id)) {
1487 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1491 dev = &rte_eth_devices[port_id];
1493 /* implemented by the driver */
1494 if (dev->dev_ops->xstats_get != NULL)
1495 return (*dev->dev_ops->xstats_get)(dev, xstats, n);
1497 /* else, return generic statistics */
1498 count = RTE_NB_STATS;
1499 count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
1500 count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
1504 /* now fill the xstats structure */
1507 memset(ð_stats, 0, sizeof(eth_stats));
1508 rte_eth_stats_get(port_id, ð_stats);
1511 for (i = 0; i < RTE_NB_STATS; i++) {
1512 stats_ptr = (char *)ð_stats + rte_stats_strings[i].offset;
1513 val = *(uint64_t *)stats_ptr;
1514 snprintf(xstats[count].name, sizeof(xstats[count].name),
1515 "%s", rte_stats_strings[i].name);
1516 xstats[count++].value = val;
1520 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1521 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1522 stats_ptr = (char *)ð_stats;
1523 stats_ptr += rte_rxq_stats_strings[i].offset;
1524 stats_ptr += q * sizeof(uint64_t);
1525 val = *(uint64_t *)stats_ptr;
1526 snprintf(xstats[count].name, sizeof(xstats[count].name),
1527 "rx_queue_%u_%s", q,
1528 rte_rxq_stats_strings[i].name);
1529 xstats[count++].value = val;
1534 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1535 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1536 stats_ptr = (char *)ð_stats;
1537 stats_ptr += rte_txq_stats_strings[i].offset;
1538 stats_ptr += q * sizeof(uint64_t);
1539 val = *(uint64_t *)stats_ptr;
1540 snprintf(xstats[count].name, sizeof(xstats[count].name),
1541 "tx_queue_%u_%s", q,
1542 rte_txq_stats_strings[i].name);
1543 xstats[count++].value = val;
1550 /* reset ethdev extended statistics */
1552 rte_eth_xstats_reset(uint8_t port_id)
1554 struct rte_eth_dev *dev;
1556 if (!rte_eth_dev_is_valid_port(port_id)) {
1557 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1561 dev = &rte_eth_devices[port_id];
1563 /* implemented by the driver */
1564 if (dev->dev_ops->xstats_reset != NULL) {
1565 (*dev->dev_ops->xstats_reset)(dev);
1569 /* fallback to default */
1570 rte_eth_stats_reset(port_id);
1574 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1577 struct rte_eth_dev *dev;
1579 if (!rte_eth_dev_is_valid_port(port_id)) {
1580 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1584 dev = &rte_eth_devices[port_id];
1586 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1587 return (*dev->dev_ops->queue_stats_mapping_set)
1588 (dev, queue_id, stat_idx, is_rx);
1593 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1596 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1602 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1605 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1611 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1613 struct rte_eth_dev *dev;
1615 if (!rte_eth_dev_is_valid_port(port_id)) {
1616 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1620 dev = &rte_eth_devices[port_id];
1622 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1624 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1625 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1626 dev_info->pci_dev = dev->pci_dev;
1628 dev_info->driver_name = dev->driver->pci_drv.name;
1632 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1634 struct rte_eth_dev *dev;
1636 if (!rte_eth_dev_is_valid_port(port_id)) {
1637 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1641 dev = &rte_eth_devices[port_id];
1642 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1647 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1649 struct rte_eth_dev *dev;
1651 if (!rte_eth_dev_is_valid_port(port_id)) {
1652 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1656 dev = &rte_eth_devices[port_id];
1657 *mtu = dev->data->mtu;
1662 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1665 struct rte_eth_dev *dev;
1667 if (!rte_eth_dev_is_valid_port(port_id)) {
1668 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1672 dev = &rte_eth_devices[port_id];
1673 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1675 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1677 dev->data->mtu = mtu;
1683 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1685 struct rte_eth_dev *dev;
1687 if (!rte_eth_dev_is_valid_port(port_id)) {
1688 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1692 dev = &rte_eth_devices[port_id];
1693 if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1694 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1698 if (vlan_id > 4095) {
1699 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1700 port_id, (unsigned) vlan_id);
1703 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1704 (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1709 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1711 struct rte_eth_dev *dev;
1713 if (!rte_eth_dev_is_valid_port(port_id)) {
1714 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1718 dev = &rte_eth_devices[port_id];
1719 if (rx_queue_id >= dev->data->nb_rx_queues) {
1720 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1724 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1725 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1731 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1733 struct rte_eth_dev *dev;
1735 if (!rte_eth_dev_is_valid_port(port_id)) {
1736 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1740 dev = &rte_eth_devices[port_id];
1741 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1742 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1748 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1750 struct rte_eth_dev *dev;
1755 if (!rte_eth_dev_is_valid_port(port_id)) {
1756 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1760 dev = &rte_eth_devices[port_id];
1762 /*check which option changed by application*/
1763 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1764 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1766 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1767 mask |= ETH_VLAN_STRIP_MASK;
1770 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1771 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1773 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1774 mask |= ETH_VLAN_FILTER_MASK;
1777 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1778 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1780 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1781 mask |= ETH_VLAN_EXTEND_MASK;
1788 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1789 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1795 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1797 struct rte_eth_dev *dev;
1800 if (!rte_eth_dev_is_valid_port(port_id)) {
1801 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1805 dev = &rte_eth_devices[port_id];
1807 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1808 ret |= ETH_VLAN_STRIP_OFFLOAD ;
1810 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1811 ret |= ETH_VLAN_FILTER_OFFLOAD ;
1813 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1814 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
1820 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1822 struct rte_eth_dev *dev;
1824 if (!rte_eth_dev_is_valid_port(port_id)) {
1825 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1829 dev = &rte_eth_devices[port_id];
1830 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1831 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1837 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1838 struct rte_fdir_filter *fdir_filter,
1841 struct rte_eth_dev *dev;
1843 if (!rte_eth_dev_is_valid_port(port_id)) {
1844 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1848 dev = &rte_eth_devices[port_id];
1850 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1851 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1852 port_id, dev->data->dev_conf.fdir_conf.mode);
1856 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1857 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1858 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1859 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1860 "None l4type, source & destinations ports " \
1861 "should be null!\n");
1865 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1866 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1871 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1872 struct rte_fdir_filter *fdir_filter,
1875 struct rte_eth_dev *dev;
1877 if (!rte_eth_dev_is_valid_port(port_id)) {
1878 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1882 dev = &rte_eth_devices[port_id];
1884 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1885 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1886 port_id, dev->data->dev_conf.fdir_conf.mode);
1890 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1891 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1892 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1893 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1894 "None l4type, source & destinations ports " \
1895 "should be null!\n");
1899 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
1900 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
1906 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
1907 struct rte_fdir_filter *fdir_filter)
1909 struct rte_eth_dev *dev;
1911 if (!rte_eth_dev_is_valid_port(port_id)) {
1912 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1916 dev = &rte_eth_devices[port_id];
1918 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1919 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1920 port_id, dev->data->dev_conf.fdir_conf.mode);
1924 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1925 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1926 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1927 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1928 "None l4type source & destinations ports " \
1929 "should be null!\n");
1933 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
1934 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
1938 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
1940 struct rte_eth_dev *dev;
1942 if (!rte_eth_dev_is_valid_port(port_id)) {
1943 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1947 dev = &rte_eth_devices[port_id];
1948 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1949 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1953 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
1955 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
1960 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
1961 struct rte_fdir_filter *fdir_filter,
1962 uint16_t soft_id, uint8_t queue,
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];
1974 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1975 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1976 port_id, dev->data->dev_conf.fdir_conf.mode);
1980 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1981 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1982 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1983 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1984 "None l4type, source & destinations ports " \
1985 "should be null!\n");
1989 /* For now IPv6 is not supported with perfect filter */
1990 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1993 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
1994 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
2000 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
2001 struct rte_fdir_filter *fdir_filter,
2002 uint16_t soft_id, uint8_t queue,
2005 struct rte_eth_dev *dev;
2007 if (!rte_eth_dev_is_valid_port(port_id)) {
2008 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2012 dev = &rte_eth_devices[port_id];
2014 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
2015 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2016 port_id, dev->data->dev_conf.fdir_conf.mode);
2020 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2021 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2022 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2023 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
2024 "None l4type, source & destinations ports " \
2025 "should be null!\n");
2029 /* For now IPv6 is not supported with perfect filter */
2030 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2033 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
2034 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
2035 soft_id, queue, drop);
2039 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
2040 struct rte_fdir_filter *fdir_filter,
2043 struct rte_eth_dev *dev;
2045 if (!rte_eth_dev_is_valid_port(port_id)) {
2046 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2050 dev = &rte_eth_devices[port_id];
2052 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
2053 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
2054 port_id, dev->data->dev_conf.fdir_conf.mode);
2058 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
2059 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2060 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2061 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
2062 "None l4type, source & destinations ports " \
2063 "should be null!\n");
2067 /* For now IPv6 is not supported with perfect filter */
2068 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2071 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
2072 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
2077 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
2079 struct rte_eth_dev *dev;
2081 if (!rte_eth_dev_is_valid_port(port_id)) {
2082 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2086 dev = &rte_eth_devices[port_id];
2087 if (! (dev->data->dev_conf.fdir_conf.mode)) {
2088 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
2092 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
2093 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
2097 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2099 struct rte_eth_dev *dev;
2101 if (!rte_eth_dev_is_valid_port(port_id)) {
2102 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2106 dev = &rte_eth_devices[port_id];
2107 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2108 memset(fc_conf, 0, sizeof(*fc_conf));
2109 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
2113 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2115 struct rte_eth_dev *dev;
2117 if (!rte_eth_dev_is_valid_port(port_id)) {
2118 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2122 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2123 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2127 dev = &rte_eth_devices[port_id];
2128 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2129 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
2133 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
2135 struct rte_eth_dev *dev;
2137 if (!rte_eth_dev_is_valid_port(port_id)) {
2138 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2142 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2143 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2147 dev = &rte_eth_devices[port_id];
2148 /* High water, low water validation are device specific */
2149 if (*dev->dev_ops->priority_flow_ctrl_set)
2150 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
2155 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2163 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
2164 PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
2165 RTE_RETA_GROUP_SIZE);
2169 num = reta_size / RTE_RETA_GROUP_SIZE;
2170 for (i = 0; i < num; i++) {
2171 if (reta_conf[i].mask)
2179 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2183 uint16_t i, idx, shift;
2189 PMD_DEBUG_TRACE("No receive queue is available\n");
2193 for (i = 0; i < reta_size; i++) {
2194 idx = i / RTE_RETA_GROUP_SIZE;
2195 shift = i % RTE_RETA_GROUP_SIZE;
2196 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2197 (reta_conf[idx].reta[shift] >= max_rxq)) {
2198 PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2199 "the maximum rxq index: %u\n", idx, shift,
2200 reta_conf[idx].reta[shift], max_rxq);
2209 rte_eth_dev_rss_reta_update(uint8_t port_id,
2210 struct rte_eth_rss_reta_entry64 *reta_conf,
2213 struct rte_eth_dev *dev;
2216 if (!rte_eth_dev_is_valid_port(port_id)) {
2217 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2221 /* Check mask bits */
2222 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2226 dev = &rte_eth_devices[port_id];
2228 /* Check entry value */
2229 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2230 dev->data->nb_rx_queues);
2234 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2235 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2239 rte_eth_dev_rss_reta_query(uint8_t port_id,
2240 struct rte_eth_rss_reta_entry64 *reta_conf,
2243 struct rte_eth_dev *dev;
2246 if (port_id >= nb_ports) {
2247 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2251 /* Check mask bits */
2252 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2256 dev = &rte_eth_devices[port_id];
2257 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2258 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2262 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2264 struct rte_eth_dev *dev;
2265 uint16_t rss_hash_protos;
2267 if (!rte_eth_dev_is_valid_port(port_id)) {
2268 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2272 rss_hash_protos = rss_conf->rss_hf;
2273 if ((rss_hash_protos != 0) &&
2274 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2275 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2279 dev = &rte_eth_devices[port_id];
2280 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2281 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2285 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2286 struct rte_eth_rss_conf *rss_conf)
2288 struct rte_eth_dev *dev;
2290 if (!rte_eth_dev_is_valid_port(port_id)) {
2291 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2295 dev = &rte_eth_devices[port_id];
2296 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2297 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2301 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
2302 struct rte_eth_udp_tunnel *udp_tunnel)
2304 struct rte_eth_dev *dev;
2306 if (!rte_eth_dev_is_valid_port(port_id)) {
2307 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2311 if (udp_tunnel == NULL) {
2312 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2316 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2317 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2321 dev = &rte_eth_devices[port_id];
2322 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
2323 return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
2327 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
2328 struct rte_eth_udp_tunnel *udp_tunnel)
2330 struct rte_eth_dev *dev;
2332 if (!rte_eth_dev_is_valid_port(port_id)) {
2333 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2337 dev = &rte_eth_devices[port_id];
2339 if (udp_tunnel == NULL) {
2340 PMD_DEBUG_TRACE("Invalid udp_tunnel parametr\n");
2344 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2345 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2349 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2350 return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2354 rte_eth_led_on(uint8_t port_id)
2356 struct rte_eth_dev *dev;
2358 if (!rte_eth_dev_is_valid_port(port_id)) {
2359 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2363 dev = &rte_eth_devices[port_id];
2364 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2365 return ((*dev->dev_ops->dev_led_on)(dev));
2369 rte_eth_led_off(uint8_t port_id)
2371 struct rte_eth_dev *dev;
2373 if (!rte_eth_dev_is_valid_port(port_id)) {
2374 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2378 dev = &rte_eth_devices[port_id];
2379 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2380 return ((*dev->dev_ops->dev_led_off)(dev));
2384 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2388 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2390 struct rte_eth_dev_info dev_info;
2391 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2394 rte_eth_dev_info_get(port_id, &dev_info);
2396 for (i = 0; i < dev_info.max_mac_addrs; i++)
2397 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2403 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
2406 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2409 struct rte_eth_dev *dev;
2413 if (!rte_eth_dev_is_valid_port(port_id)) {
2414 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2418 dev = &rte_eth_devices[port_id];
2419 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2421 if (is_zero_ether_addr(addr)) {
2422 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2426 if (pool >= ETH_64_POOLS) {
2427 PMD_DEBUG_TRACE("pool id must be 0-%d\n",ETH_64_POOLS - 1);
2431 index = get_mac_addr_index(port_id, addr);
2433 index = get_mac_addr_index(port_id, &null_mac_addr);
2435 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2440 pool_mask = dev->data->mac_pool_sel[index];
2442 /* Check if both MAC address and pool is alread there, and do nothing */
2443 if (pool_mask & (1ULL << pool))
2448 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2450 /* Update address in NIC data structure */
2451 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2453 /* Update pool bitmap in NIC data structure */
2454 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2460 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2462 struct rte_eth_dev *dev;
2465 if (!rte_eth_dev_is_valid_port(port_id)) {
2466 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2470 dev = &rte_eth_devices[port_id];
2471 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2473 index = get_mac_addr_index(port_id, addr);
2475 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2476 return (-EADDRINUSE);
2477 } else if (index < 0)
2478 return 0; /* Do nothing if address wasn't found */
2481 (*dev->dev_ops->mac_addr_remove)(dev, index);
2483 /* Update address in NIC data structure */
2484 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2486 /* reset pool bitmap */
2487 dev->data->mac_pool_sel[index] = 0;
2493 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2494 uint16_t rx_mode, uint8_t on)
2497 struct rte_eth_dev *dev;
2498 struct rte_eth_dev_info dev_info;
2500 if (!rte_eth_dev_is_valid_port(port_id)) {
2501 PMD_DEBUG_TRACE("set VF RX mode:Invalid port_id=%d\n",
2506 dev = &rte_eth_devices[port_id];
2507 rte_eth_dev_info_get(port_id, &dev_info);
2509 num_vfs = dev_info.max_vfs;
2512 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2517 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2520 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2521 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2525 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2529 get_hash_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2531 struct rte_eth_dev_info dev_info;
2532 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2535 rte_eth_dev_info_get(port_id, &dev_info);
2536 if (!dev->data->hash_mac_addrs)
2539 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2540 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2541 ETHER_ADDR_LEN) == 0)
2548 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2553 struct rte_eth_dev *dev;
2555 if (!rte_eth_dev_is_valid_port(port_id)) {
2556 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2561 dev = &rte_eth_devices[port_id];
2562 if (is_zero_ether_addr(addr)) {
2563 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2568 index = get_hash_mac_addr_index(port_id, addr);
2569 /* Check if it's already there, and do nothing */
2570 if ((index >= 0) && (on))
2575 PMD_DEBUG_TRACE("port %d: the MAC address was not"
2576 "set in UTA\n", port_id);
2580 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2582 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2588 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2589 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2591 /* Update address in NIC data structure */
2593 ether_addr_copy(addr,
2594 &dev->data->hash_mac_addrs[index]);
2596 ether_addr_copy(&null_mac_addr,
2597 &dev->data->hash_mac_addrs[index]);
2604 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2606 struct rte_eth_dev *dev;
2608 if (!rte_eth_dev_is_valid_port(port_id)) {
2609 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2614 dev = &rte_eth_devices[port_id];
2616 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2617 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2621 rte_eth_dev_set_vf_rx(uint8_t port_id,uint16_t vf, uint8_t on)
2624 struct rte_eth_dev *dev;
2625 struct rte_eth_dev_info dev_info;
2627 if (!rte_eth_dev_is_valid_port(port_id)) {
2628 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2632 dev = &rte_eth_devices[port_id];
2633 rte_eth_dev_info_get(port_id, &dev_info);
2635 num_vfs = dev_info.max_vfs;
2638 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2642 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2643 return (*dev->dev_ops->set_vf_rx)(dev, vf,on);
2647 rte_eth_dev_set_vf_tx(uint8_t port_id,uint16_t vf, uint8_t on)
2650 struct rte_eth_dev *dev;
2651 struct rte_eth_dev_info dev_info;
2653 if (!rte_eth_dev_is_valid_port(port_id)) {
2654 PMD_DEBUG_TRACE("set pool tx:Invalid port_id=%d\n", port_id);
2658 dev = &rte_eth_devices[port_id];
2659 rte_eth_dev_info_get(port_id, &dev_info);
2661 num_vfs = dev_info.max_vfs;
2664 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2668 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2669 return (*dev->dev_ops->set_vf_tx)(dev, vf,on);
2673 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2674 uint64_t vf_mask,uint8_t vlan_on)
2676 struct rte_eth_dev *dev;
2678 if (!rte_eth_dev_is_valid_port(port_id)) {
2679 PMD_DEBUG_TRACE("VF VLAN filter:invalid port id=%d\n",
2683 dev = &rte_eth_devices[port_id];
2685 if(vlan_id > ETHER_MAX_VLAN_ID)
2687 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2693 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2697 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2698 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2702 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2705 struct rte_eth_dev *dev;
2706 struct rte_eth_dev_info dev_info;
2707 struct rte_eth_link link;
2709 if (!rte_eth_dev_is_valid_port(port_id)) {
2710 PMD_DEBUG_TRACE("set queue rate limit:invalid port id=%d\n",
2715 dev = &rte_eth_devices[port_id];
2716 rte_eth_dev_info_get(port_id, &dev_info);
2717 link = dev->data->dev_link;
2719 if (queue_idx > dev_info.max_tx_queues) {
2720 PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2721 "invalid queue id=%d\n", port_id, queue_idx);
2725 if (tx_rate > link.link_speed) {
2726 PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2727 "bigger than link speed= %d\n",
2728 tx_rate, link.link_speed);
2732 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2733 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2736 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2739 struct rte_eth_dev *dev;
2740 struct rte_eth_dev_info dev_info;
2741 struct rte_eth_link link;
2746 if (!rte_eth_dev_is_valid_port(port_id)) {
2747 PMD_DEBUG_TRACE("set VF rate limit:invalid port id=%d\n",
2752 dev = &rte_eth_devices[port_id];
2753 rte_eth_dev_info_get(port_id, &dev_info);
2754 link = dev->data->dev_link;
2756 if (vf > dev_info.max_vfs) {
2757 PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2758 "invalid vf id=%d\n", port_id, vf);
2762 if (tx_rate > link.link_speed) {
2763 PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2764 "bigger than link speed= %d\n",
2765 tx_rate, link.link_speed);
2769 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2770 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2774 rte_eth_mirror_rule_set(uint8_t port_id,
2775 struct rte_eth_vmdq_mirror_conf *mirror_conf,
2776 uint8_t rule_id, uint8_t on)
2778 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2780 if (!rte_eth_dev_is_valid_port(port_id)) {
2781 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2785 if (mirror_conf->rule_type_mask == 0) {
2786 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2790 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2791 PMD_DEBUG_TRACE("Invalid dst pool, pool id must"
2792 "be 0-%d\n",ETH_64_POOLS - 1);
2796 if ((mirror_conf->rule_type_mask & ETH_VMDQ_POOL_MIRROR) &&
2797 (mirror_conf->pool_mask == 0)) {
2798 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not"
2803 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2805 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2806 ETH_VMDQ_NUM_MIRROR_RULE - 1);
2810 dev = &rte_eth_devices[port_id];
2811 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2813 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2817 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2819 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2821 if (!rte_eth_dev_is_valid_port(port_id)) {
2822 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2826 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2828 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2829 ETH_VMDQ_NUM_MIRROR_RULE-1);
2833 dev = &rte_eth_devices[port_id];
2834 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2836 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2839 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2841 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2842 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2844 struct rte_eth_dev *dev;
2846 if (!rte_eth_dev_is_valid_port(port_id)) {
2847 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2851 dev = &rte_eth_devices[port_id];
2852 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);
2853 if (queue_id >= dev->data->nb_rx_queues) {
2854 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2857 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2862 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2863 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2865 struct rte_eth_dev *dev;
2867 if (!rte_eth_dev_is_valid_port(port_id)) {
2868 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2872 dev = &rte_eth_devices[port_id];
2874 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0);
2875 if (queue_id >= dev->data->nb_tx_queues) {
2876 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2879 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2884 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2886 struct rte_eth_dev *dev;
2888 if (!rte_eth_dev_is_valid_port(port_id)) {
2889 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2893 dev = &rte_eth_devices[port_id];
2894 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0);
2895 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2899 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2901 struct rte_eth_dev *dev;
2903 if (!rte_eth_dev_is_valid_port(port_id)) {
2904 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2908 dev = &rte_eth_devices[port_id];
2909 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2910 return (*dev->dev_ops->rx_descriptor_done)( \
2911 dev->data->rx_queues[queue_id], offset);
2916 rte_eth_dev_callback_register(uint8_t port_id,
2917 enum rte_eth_event_type event,
2918 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2920 struct rte_eth_dev *dev;
2921 struct rte_eth_dev_callback *user_cb;
2926 if (!rte_eth_dev_is_valid_port(port_id)) {
2927 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2931 dev = &rte_eth_devices[port_id];
2932 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2934 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2935 if (user_cb->cb_fn == cb_fn &&
2936 user_cb->cb_arg == cb_arg &&
2937 user_cb->event == event) {
2942 /* create a new callback. */
2943 if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2944 sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
2945 user_cb->cb_fn = cb_fn;
2946 user_cb->cb_arg = cb_arg;
2947 user_cb->event = event;
2948 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2951 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2952 return ((user_cb == NULL) ? -ENOMEM : 0);
2956 rte_eth_dev_callback_unregister(uint8_t port_id,
2957 enum rte_eth_event_type event,
2958 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2961 struct rte_eth_dev *dev;
2962 struct rte_eth_dev_callback *cb, *next;
2967 if (!rte_eth_dev_is_valid_port(port_id)) {
2968 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2972 dev = &rte_eth_devices[port_id];
2973 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2976 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2978 next = TAILQ_NEXT(cb, next);
2980 if (cb->cb_fn != cb_fn || cb->event != event ||
2981 (cb->cb_arg != (void *)-1 &&
2982 cb->cb_arg != cb_arg))
2986 * if this callback is not executing right now,
2989 if (cb->active == 0) {
2990 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2997 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3002 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
3003 enum rte_eth_event_type event)
3005 struct rte_eth_dev_callback *cb_lst;
3006 struct rte_eth_dev_callback dev_cb;
3008 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3009 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
3010 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
3014 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3015 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
3017 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3020 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3022 #ifdef RTE_NIC_BYPASS
3023 int rte_eth_dev_bypass_init(uint8_t port_id)
3025 struct rte_eth_dev *dev;
3027 if (!rte_eth_dev_is_valid_port(port_id)) {
3028 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3032 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3033 PMD_DEBUG_TRACE("Invalid port device\n");
3037 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
3038 (*dev->dev_ops->bypass_init)(dev);
3043 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
3045 struct rte_eth_dev *dev;
3047 if (!rte_eth_dev_is_valid_port(port_id)) {
3048 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3052 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3053 PMD_DEBUG_TRACE("Invalid port device\n");
3056 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
3057 (*dev->dev_ops->bypass_state_show)(dev, state);
3062 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
3064 struct rte_eth_dev *dev;
3066 if (!rte_eth_dev_is_valid_port(port_id)) {
3067 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3071 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3072 PMD_DEBUG_TRACE("Invalid port device\n");
3076 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
3077 (*dev->dev_ops->bypass_state_set)(dev, new_state);
3082 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
3084 struct rte_eth_dev *dev;
3086 if (!rte_eth_dev_is_valid_port(port_id)) {
3087 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3091 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3092 PMD_DEBUG_TRACE("Invalid port device\n");
3096 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
3097 (*dev->dev_ops->bypass_event_show)(dev, event, state);
3102 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
3104 struct rte_eth_dev *dev;
3106 if (!rte_eth_dev_is_valid_port(port_id)) {
3107 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3111 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3112 PMD_DEBUG_TRACE("Invalid port device\n");
3116 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
3117 (*dev->dev_ops->bypass_event_set)(dev, event, state);
3122 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
3124 struct rte_eth_dev *dev;
3126 if (!rte_eth_dev_is_valid_port(port_id)) {
3127 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3131 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3132 PMD_DEBUG_TRACE("Invalid port device\n");
3136 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
3137 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
3142 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
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 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3152 PMD_DEBUG_TRACE("Invalid port device\n");
3156 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
3157 (*dev->dev_ops->bypass_ver_show)(dev, ver);
3162 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
3164 struct rte_eth_dev *dev;
3166 if (!rte_eth_dev_is_valid_port(port_id)) {
3167 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3171 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3172 PMD_DEBUG_TRACE("Invalid port device\n");
3176 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
3177 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
3182 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
3184 struct rte_eth_dev *dev;
3186 if (!rte_eth_dev_is_valid_port(port_id)) {
3187 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3191 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3192 PMD_DEBUG_TRACE("Invalid port device\n");
3196 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
3197 (*dev->dev_ops->bypass_wd_reset)(dev);
3203 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
3205 struct rte_eth_dev *dev;
3207 if (!rte_eth_dev_is_valid_port(port_id)) {
3208 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3212 dev = &rte_eth_devices[port_id];
3213 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3214 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3215 RTE_ETH_FILTER_NOP, NULL);
3219 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
3220 enum rte_filter_op filter_op, void *arg)
3222 struct rte_eth_dev *dev;
3224 if (!rte_eth_dev_is_valid_port(port_id)) {
3225 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3229 dev = &rte_eth_devices[port_id];
3230 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3231 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
3235 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
3236 rte_rxtx_callback_fn fn, void *user_param)
3238 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3239 rte_errno = ENOTSUP;
3242 /* check input parameters */
3243 if (port_id >= nb_ports || fn == NULL ||
3244 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3249 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3257 cb->param = user_param;
3258 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3259 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3264 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
3265 rte_rxtx_callback_fn fn, void *user_param)
3267 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3268 rte_errno = ENOTSUP;
3271 /* check input parameters */
3272 if (port_id >= nb_ports || fn == NULL ||
3273 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3278 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3286 cb->param = user_param;
3287 cb->next = rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3288 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3293 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3294 struct rte_eth_rxtx_callback *user_cb)
3296 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3299 /* Check input parameters. */
3300 if (port_id >= nb_ports || user_cb == NULL ||
3301 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3305 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3306 struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
3307 struct rte_eth_rxtx_callback *prev_cb;
3309 /* Reset head pointer and remove user cb if first in the list. */
3310 if (cb == user_cb) {
3311 dev->post_rx_burst_cbs[queue_id] = user_cb->next;
3315 /* Remove the user cb from the callback list. */
3320 if (cb == user_cb) {
3321 prev_cb->next = user_cb->next;
3325 } while (cb != NULL);
3327 /* Callback wasn't found. */
3332 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3333 struct rte_eth_rxtx_callback *user_cb)
3335 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3338 /* Check input parameters. */
3339 if (port_id >= nb_ports || user_cb == NULL ||
3340 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3344 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3345 struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
3346 struct rte_eth_rxtx_callback *prev_cb;
3348 /* Reset head pointer and remove user cb if first in the list. */
3349 if (cb == user_cb) {
3350 dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
3354 /* Remove the user cb from the callback list. */
3359 if (cb == user_cb) {
3360 prev_cb->next = user_cb->next;
3364 } while (cb != NULL);
3366 /* Callback wasn't found. */