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>
45 #include <rte_byteorder.h>
47 #include <rte_debug.h>
48 #include <rte_interrupts.h>
50 #include <rte_memory.h>
51 #include <rte_memcpy.h>
52 #include <rte_memzone.h>
53 #include <rte_launch.h>
54 #include <rte_tailq.h>
56 #include <rte_per_lcore.h>
57 #include <rte_lcore.h>
58 #include <rte_atomic.h>
59 #include <rte_branch_prediction.h>
60 #include <rte_common.h>
62 #include <rte_mempool.h>
63 #include <rte_malloc.h>
65 #include <rte_errno.h>
66 #include <rte_spinlock.h>
68 #include "rte_ether.h"
69 #include "rte_ethdev.h"
71 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
72 #define PMD_DEBUG_TRACE(fmt, args...) do { \
73 RTE_LOG(ERR, PMD, "%s: " fmt, __func__, ## args); \
76 #define PMD_DEBUG_TRACE(fmt, args...)
79 /* Macros for checking for restricting functions to primary instance only */
80 #define PROC_PRIMARY_OR_ERR_RET(retval) do { \
81 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
82 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
86 #define PROC_PRIMARY_OR_RET() do { \
87 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
88 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
93 /* Macros to check for invlaid function pointers in dev_ops structure */
94 #define FUNC_PTR_OR_ERR_RET(func, retval) do { \
95 if ((func) == NULL) { \
96 PMD_DEBUG_TRACE("Function not supported\n"); \
100 #define FUNC_PTR_OR_RET(func) do { \
101 if ((func) == NULL) { \
102 PMD_DEBUG_TRACE("Function not supported\n"); \
107 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
108 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
109 static struct rte_eth_dev_data *rte_eth_dev_data = NULL;
110 static uint8_t nb_ports = 0;
112 /* spinlock for eth device callbacks */
113 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
116 * The user application callback description.
118 * It contains callback address to be registered by user application,
119 * the pointer to the parameters for callback, and the event type.
121 struct rte_eth_dev_callback {
122 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
123 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
124 void *cb_arg; /**< Parameter for callback */
125 enum rte_eth_event_type event; /**< Interrupt event type */
126 uint32_t active; /**< Callback is executing */
135 rte_eth_dev_data_alloc(void)
137 const unsigned flags = 0;
138 const struct rte_memzone *mz;
140 if (rte_eal_process_type() == RTE_PROC_PRIMARY){
141 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
142 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
143 rte_socket_id(), flags);
145 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
147 rte_panic("Cannot allocate memzone for ethernet port data\n");
149 rte_eth_dev_data = mz->addr;
150 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
151 memset(rte_eth_dev_data, 0,
152 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
156 rte_eth_dev_allocate(void)
158 struct rte_eth_dev *eth_dev;
160 if (nb_ports == RTE_MAX_ETHPORTS) {
161 PMD_DEBUG_TRACE("Reached maximum number of ethernet ports\n");
165 if (rte_eth_dev_data == NULL)
166 rte_eth_dev_data_alloc();
168 eth_dev = &rte_eth_devices[nb_ports];
169 eth_dev->data = &rte_eth_dev_data[nb_ports];
170 eth_dev->data->port_id = nb_ports++;
175 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
176 struct rte_pci_device *pci_dev)
178 struct eth_driver *eth_drv;
179 struct rte_eth_dev *eth_dev;
182 eth_drv = (struct eth_driver *)pci_drv;
184 eth_dev = rte_eth_dev_allocate();
188 if (rte_eal_process_type() == RTE_PROC_PRIMARY){
189 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
190 eth_drv->dev_private_size,
192 if (eth_dev->data->dev_private == NULL)
193 rte_panic("Cannot allocate memzone for private port data\n");
195 eth_dev->pci_dev = pci_dev;
196 eth_dev->driver = eth_drv;
197 eth_dev->data->rx_mbuf_alloc_failed = 0;
199 /* init user callbacks */
200 TAILQ_INIT(&(eth_dev->callbacks));
203 * Set the default maximum frame size.
205 eth_dev->data->max_frame_size = ETHER_MAX_LEN;
207 /* Invoke PMD device initialization function */
208 diag = (*eth_drv->eth_dev_init)(eth_drv, eth_dev);
212 PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x)"
213 " failed\n", pci_drv->name,
214 (unsigned) pci_dev->id.vendor_id,
215 (unsigned) pci_dev->id.device_id);
216 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
217 rte_free(eth_dev->data->dev_private);
223 * Register an Ethernet [Poll Mode] driver.
225 * Function invoked by the initialization function of an Ethernet driver
226 * to simultaneously register itself as a PCI driver and as an Ethernet
228 * Invokes the rte_eal_pci_register() function to register the *pci_drv*
229 * structure embedded in the *eth_drv* structure, after having stored the
230 * address of the rte_eth_dev_init() function in the *devinit* field of
231 * the *pci_drv* structure.
232 * During the PCI probing phase, the rte_eth_dev_init() function is
233 * invoked for each PCI [Ethernet device] matching the embedded PCI
234 * identifiers provided by the driver.
237 rte_eth_driver_register(struct eth_driver *eth_drv)
239 eth_drv->pci_drv.devinit = rte_eth_dev_init;
240 rte_eal_pci_register(ð_drv->pci_drv);
244 rte_eth_dev_socket_id(uint8_t port_id)
246 if (port_id >= nb_ports)
248 return rte_eth_devices[port_id].pci_dev->numa_node;
252 rte_eth_dev_count(void)
258 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
260 uint16_t old_nb_queues = dev->data->nb_rx_queues;
264 if (dev->data->rx_queues == NULL) { /* first time configuration */
265 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
266 sizeof(dev->data->rx_queues[0]) * nb_queues,
268 if (dev->data->rx_queues == NULL) {
269 dev->data->nb_rx_queues = 0;
272 } else { /* re-configure */
273 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
275 rxq = dev->data->rx_queues;
277 for (i = nb_queues; i < old_nb_queues; i++)
278 (*dev->dev_ops->rx_queue_release)(rxq[i]);
279 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
284 if (nb_queues > old_nb_queues)
285 memset(rxq + old_nb_queues, 0,
286 sizeof(rxq[0]) * (nb_queues - old_nb_queues));
288 dev->data->rx_queues = rxq;
291 dev->data->nb_rx_queues = nb_queues;
296 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
298 struct rte_eth_dev *dev;
300 /* This function is only safe when called from the primary process
301 * in a multi-process setup*/
302 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
304 if (port_id >= nb_ports) {
305 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
309 dev = &rte_eth_devices[port_id];
310 if (rx_queue_id >= dev->data->nb_rx_queues) {
311 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
315 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
317 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
322 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
324 struct rte_eth_dev *dev;
326 /* This function is only safe when called from the primary process
327 * in a multi-process setup*/
328 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
330 if (port_id >= nb_ports) {
331 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
335 dev = &rte_eth_devices[port_id];
336 if (rx_queue_id >= dev->data->nb_rx_queues) {
337 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
341 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
343 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
348 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
350 struct rte_eth_dev *dev;
352 /* This function is only safe when called from the primary process
353 * in a multi-process setup*/
354 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
356 if (port_id >= nb_ports) {
357 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
361 dev = &rte_eth_devices[port_id];
362 if (tx_queue_id >= dev->data->nb_tx_queues) {
363 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
367 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
369 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
374 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
376 struct rte_eth_dev *dev;
378 /* This function is only safe when called from the primary process
379 * in a multi-process setup*/
380 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
382 if (port_id >= nb_ports) {
383 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
387 dev = &rte_eth_devices[port_id];
388 if (tx_queue_id >= dev->data->nb_tx_queues) {
389 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
393 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
395 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
400 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
402 uint16_t old_nb_queues = dev->data->nb_tx_queues;
406 if (dev->data->tx_queues == NULL) { /* first time configuration */
407 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
408 sizeof(dev->data->tx_queues[0]) * nb_queues,
410 if (dev->data->tx_queues == NULL) {
411 dev->data->nb_tx_queues = 0;
414 } else { /* re-configure */
415 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
417 txq = dev->data->tx_queues;
419 for (i = nb_queues; i < old_nb_queues; i++)
420 (*dev->dev_ops->tx_queue_release)(txq[i]);
421 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
426 if (nb_queues > old_nb_queues)
427 memset(txq + old_nb_queues, 0,
428 sizeof(txq[0]) * (nb_queues - old_nb_queues));
430 dev->data->tx_queues = txq;
433 dev->data->nb_tx_queues = nb_queues;
438 rte_eth_dev_check_mq_mode(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
439 const struct rte_eth_conf *dev_conf)
441 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
443 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
444 /* check multi-queue mode */
445 if ((dev_conf->rxmode.mq_mode == ETH_MQ_RX_RSS) ||
446 (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) ||
447 (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB_RSS) ||
448 (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB)) {
449 /* SRIOV only works in VMDq enable mode */
450 PMD_DEBUG_TRACE("ethdev port_id=%hhu SRIOV active, "
451 "wrong VMDQ mq_mode rx %u tx %u\n",
453 dev_conf->rxmode.mq_mode,
454 dev_conf->txmode.mq_mode);
458 switch (dev_conf->rxmode.mq_mode) {
459 case ETH_MQ_RX_VMDQ_RSS:
460 case ETH_MQ_RX_VMDQ_DCB:
461 case ETH_MQ_RX_VMDQ_DCB_RSS:
462 /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
463 PMD_DEBUG_TRACE("ethdev port_id=%hhu SRIOV active, "
464 "unsupported VMDQ mq_mode rx %u\n",
465 port_id, dev_conf->rxmode.mq_mode);
467 default: /* ETH_MQ_RX_VMDQ_ONLY or ETH_MQ_RX_NONE */
468 /* if nothing mq mode configure, use default scheme */
469 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
470 if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
471 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
475 switch (dev_conf->txmode.mq_mode) {
476 case ETH_MQ_TX_VMDQ_DCB:
477 /* DCB VMDQ in SRIOV mode, not implement yet */
478 PMD_DEBUG_TRACE("ethdev port_id=%hhu SRIOV active, "
479 "unsupported VMDQ mq_mode tx %u\n",
480 port_id, dev_conf->txmode.mq_mode);
482 default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
483 /* if nothing mq mode configure, use default scheme */
484 dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
485 if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
486 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
490 /* check valid queue number */
491 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
492 (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
493 PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
494 "queue number must less equal to %d\n",
495 port_id, RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
499 /* For vmdb+dcb mode check our configuration before we go further */
500 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB) {
501 const struct rte_eth_vmdq_dcb_conf *conf;
503 if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
504 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
506 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
509 conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
510 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
511 conf->nb_queue_pools == ETH_32_POOLS)) {
512 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
513 "nb_queue_pools must be %d or %d\n",
514 port_id, ETH_16_POOLS, ETH_32_POOLS);
518 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
519 const struct rte_eth_vmdq_dcb_tx_conf *conf;
521 if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
522 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
524 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
527 conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
528 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
529 conf->nb_queue_pools == ETH_32_POOLS)) {
530 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
531 "nb_queue_pools != %d or nb_queue_pools "
533 port_id, ETH_16_POOLS, ETH_32_POOLS);
538 /* For DCB mode check our configuration before we go further */
539 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) {
540 const struct rte_eth_dcb_rx_conf *conf;
542 if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
543 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
545 port_id, ETH_DCB_NUM_QUEUES);
548 conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
549 if (! (conf->nb_tcs == ETH_4_TCS ||
550 conf->nb_tcs == ETH_8_TCS)) {
551 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
552 "nb_tcs != %d or nb_tcs "
554 port_id, ETH_4_TCS, ETH_8_TCS);
559 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
560 const struct rte_eth_dcb_tx_conf *conf;
562 if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
563 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
565 port_id, ETH_DCB_NUM_QUEUES);
568 conf = &(dev_conf->tx_adv_conf.dcb_tx_conf);
569 if (! (conf->nb_tcs == ETH_4_TCS ||
570 conf->nb_tcs == ETH_8_TCS)) {
571 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
572 "nb_tcs != %d or nb_tcs "
574 port_id, ETH_4_TCS, ETH_8_TCS);
583 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
584 const struct rte_eth_conf *dev_conf)
586 struct rte_eth_dev *dev;
587 struct rte_eth_dev_info dev_info;
590 /* This function is only safe when called from the primary process
591 * in a multi-process setup*/
592 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
594 if (port_id >= nb_ports || port_id >= RTE_MAX_ETHPORTS) {
595 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
598 dev = &rte_eth_devices[port_id];
600 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
601 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
603 if (dev->data->dev_started) {
605 "port %d must be stopped to allow configuration\n", port_id);
610 * Check that the numbers of RX and TX queues are not greater
611 * than the maximum number of RX and TX queues supported by the
614 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
615 if (nb_rx_q > dev_info.max_rx_queues) {
616 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
617 port_id, nb_rx_q, dev_info.max_rx_queues);
621 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
625 if (nb_tx_q > dev_info.max_tx_queues) {
626 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
627 port_id, nb_tx_q, dev_info.max_tx_queues);
631 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
635 /* Copy the dev_conf parameter into the dev structure */
636 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
639 * If jumbo frames are enabled, check that the maximum RX packet
640 * length is supported by the configured device.
642 if (dev_conf->rxmode.jumbo_frame == 1) {
643 if (dev_conf->rxmode.max_rx_pkt_len >
644 dev_info.max_rx_pktlen) {
645 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
646 " > max valid value %u\n",
648 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
649 (unsigned)dev_info.max_rx_pktlen);
652 else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
653 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
654 " < min valid value %u\n",
656 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
657 (unsigned)ETHER_MIN_LEN);
661 /* Use default value */
662 dev->data->dev_conf.rxmode.max_rx_pkt_len = ETHER_MAX_LEN;
664 /* multipe queue mode checking */
665 diag = rte_eth_dev_check_mq_mode(port_id, nb_rx_q, nb_tx_q, dev_conf);
667 PMD_DEBUG_TRACE("port%d rte_eth_dev_check_mq_mode = %d\n",
673 * Setup new number of RX/TX queues and reconfigure device.
675 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
677 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
682 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
684 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
686 rte_eth_dev_rx_queue_config(dev, 0);
690 diag = (*dev->dev_ops->dev_configure)(dev);
692 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
694 rte_eth_dev_rx_queue_config(dev, 0);
695 rte_eth_dev_tx_queue_config(dev, 0);
703 rte_eth_dev_config_restore(uint8_t port_id)
705 struct rte_eth_dev *dev;
706 struct rte_eth_dev_info dev_info;
707 struct ether_addr addr;
711 dev = &rte_eth_devices[port_id];
713 rte_eth_dev_info_get(port_id, &dev_info);
715 if (RTE_ETH_DEV_SRIOV(dev).active)
716 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
718 /* replay MAC address configuration */
719 for (i = 0; i < dev_info.max_mac_addrs; i++) {
720 addr = dev->data->mac_addrs[i];
722 /* skip zero address */
723 if (is_zero_ether_addr(&addr))
726 /* add address to the hardware */
727 if (*dev->dev_ops->mac_addr_add)
728 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
730 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
732 /* exit the loop but not return an error */
737 /* replay promiscuous configuration */
738 if (rte_eth_promiscuous_get(port_id) == 1)
739 rte_eth_promiscuous_enable(port_id);
740 else if (rte_eth_promiscuous_get(port_id) == 0)
741 rte_eth_promiscuous_disable(port_id);
743 /* replay allmulticast configuration */
744 if (rte_eth_allmulticast_get(port_id) == 1)
745 rte_eth_allmulticast_enable(port_id);
746 else if (rte_eth_allmulticast_get(port_id) == 0)
747 rte_eth_allmulticast_disable(port_id);
751 rte_eth_dev_start(uint8_t port_id)
753 struct rte_eth_dev *dev;
756 /* This function is only safe when called from the primary process
757 * in a multi-process setup*/
758 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
760 if (port_id >= nb_ports) {
761 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
764 dev = &rte_eth_devices[port_id];
766 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
767 diag = (*dev->dev_ops->dev_start)(dev);
769 dev->data->dev_started = 1;
773 rte_eth_dev_config_restore(port_id);
779 rte_eth_dev_stop(uint8_t port_id)
781 struct rte_eth_dev *dev;
783 /* This function is only safe when called from the primary process
784 * in a multi-process setup*/
785 PROC_PRIMARY_OR_RET();
787 if (port_id >= nb_ports) {
788 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
791 dev = &rte_eth_devices[port_id];
793 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
794 dev->data->dev_started = 0;
795 (*dev->dev_ops->dev_stop)(dev);
799 rte_eth_dev_close(uint8_t port_id)
801 struct rte_eth_dev *dev;
803 /* This function is only safe when called from the primary process
804 * in a multi-process setup*/
805 PROC_PRIMARY_OR_RET();
807 if (port_id >= nb_ports) {
808 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
812 dev = &rte_eth_devices[port_id];
814 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
815 dev->data->dev_started = 0;
816 (*dev->dev_ops->dev_close)(dev);
820 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
821 uint16_t nb_rx_desc, unsigned int socket_id,
822 const struct rte_eth_rxconf *rx_conf,
823 struct rte_mempool *mp)
825 struct rte_eth_dev *dev;
826 struct rte_pktmbuf_pool_private *mbp_priv;
827 struct rte_eth_dev_info dev_info;
829 /* This function is only safe when called from the primary process
830 * in a multi-process setup*/
831 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
833 if (port_id >= nb_ports) {
834 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
837 dev = &rte_eth_devices[port_id];
838 if (rx_queue_id >= dev->data->nb_rx_queues) {
839 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
843 if (dev->data->dev_started) {
845 "port %d must be stopped to allow configuration\n", port_id);
849 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
850 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
853 * Check the size of the mbuf data buffer.
854 * This value must be provided in the private data of the memory pool.
855 * First check that the memory pool has a valid private data.
857 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
858 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
859 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
860 mp->name, (int) mp->private_data_size,
861 (int) sizeof(struct rte_pktmbuf_pool_private));
864 mbp_priv = rte_mempool_get_priv(mp);
865 if ((uint32_t) (mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM) <
866 dev_info.min_rx_bufsize) {
867 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
868 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
871 (int)mbp_priv->mbuf_data_room_size,
872 (int)(RTE_PKTMBUF_HEADROOM +
873 dev_info.min_rx_bufsize),
874 (int)RTE_PKTMBUF_HEADROOM,
875 (int)dev_info.min_rx_bufsize);
879 return (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
880 socket_id, rx_conf, mp);
884 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
885 uint16_t nb_tx_desc, unsigned int socket_id,
886 const struct rte_eth_txconf *tx_conf)
888 struct rte_eth_dev *dev;
890 /* This function is only safe when called from the primary process
891 * in a multi-process setup*/
892 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
894 if (port_id >= RTE_MAX_ETHPORTS || port_id >= nb_ports) {
895 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
898 dev = &rte_eth_devices[port_id];
899 if (tx_queue_id >= dev->data->nb_tx_queues) {
900 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
904 if (dev->data->dev_started) {
906 "port %d must be stopped to allow configuration\n", port_id);
910 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
911 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
916 rte_eth_promiscuous_enable(uint8_t port_id)
918 struct rte_eth_dev *dev;
920 if (port_id >= nb_ports) {
921 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
924 dev = &rte_eth_devices[port_id];
926 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
927 (*dev->dev_ops->promiscuous_enable)(dev);
928 dev->data->promiscuous = 1;
932 rte_eth_promiscuous_disable(uint8_t port_id)
934 struct rte_eth_dev *dev;
936 if (port_id >= nb_ports) {
937 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
940 dev = &rte_eth_devices[port_id];
942 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
943 dev->data->promiscuous = 0;
944 (*dev->dev_ops->promiscuous_disable)(dev);
948 rte_eth_promiscuous_get(uint8_t port_id)
950 struct rte_eth_dev *dev;
952 if (port_id >= nb_ports) {
953 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
957 dev = &rte_eth_devices[port_id];
958 return dev->data->promiscuous;
962 rte_eth_allmulticast_enable(uint8_t port_id)
964 struct rte_eth_dev *dev;
966 if (port_id >= nb_ports) {
967 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
970 dev = &rte_eth_devices[port_id];
972 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
973 (*dev->dev_ops->allmulticast_enable)(dev);
974 dev->data->all_multicast = 1;
978 rte_eth_allmulticast_disable(uint8_t port_id)
980 struct rte_eth_dev *dev;
982 if (port_id >= nb_ports) {
983 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
986 dev = &rte_eth_devices[port_id];
988 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
989 dev->data->all_multicast = 0;
990 (*dev->dev_ops->allmulticast_disable)(dev);
994 rte_eth_allmulticast_get(uint8_t port_id)
996 struct rte_eth_dev *dev;
998 if (port_id >= nb_ports) {
999 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1003 dev = &rte_eth_devices[port_id];
1004 return dev->data->all_multicast;
1008 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1009 struct rte_eth_link *link)
1011 struct rte_eth_link *dst = link;
1012 struct rte_eth_link *src = &(dev->data->dev_link);
1014 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1015 *(uint64_t *)src) == 0)
1022 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1024 struct rte_eth_dev *dev;
1026 if (port_id >= nb_ports) {
1027 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1030 dev = &rte_eth_devices[port_id];
1031 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1033 if (dev->data->dev_conf.intr_conf.lsc != 0)
1034 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1036 (*dev->dev_ops->link_update)(dev, 1);
1037 *eth_link = dev->data->dev_link;
1042 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1044 struct rte_eth_dev *dev;
1046 if (port_id >= nb_ports) {
1047 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1050 dev = &rte_eth_devices[port_id];
1051 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1053 if (dev->data->dev_conf.intr_conf.lsc != 0)
1054 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1056 (*dev->dev_ops->link_update)(dev, 0);
1057 *eth_link = dev->data->dev_link;
1062 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1064 struct rte_eth_dev *dev;
1066 if (port_id >= nb_ports) {
1067 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1070 dev = &rte_eth_devices[port_id];
1071 memset(stats, 0, sizeof(*stats));
1073 FUNC_PTR_OR_RET(*dev->dev_ops->stats_get);
1074 (*dev->dev_ops->stats_get)(dev, stats);
1075 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1079 rte_eth_stats_reset(uint8_t port_id)
1081 struct rte_eth_dev *dev;
1083 if (port_id >= nb_ports) {
1084 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1087 dev = &rte_eth_devices[port_id];
1089 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1090 (*dev->dev_ops->stats_reset)(dev);
1095 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1098 struct rte_eth_dev *dev;
1100 if (port_id >= nb_ports) {
1101 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1104 dev = &rte_eth_devices[port_id];
1106 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1107 return (*dev->dev_ops->queue_stats_mapping_set)
1108 (dev, queue_id, stat_idx, is_rx);
1113 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1116 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1122 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1125 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1131 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1133 struct rte_eth_dev *dev;
1135 if (port_id >= nb_ports) {
1136 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1139 dev = &rte_eth_devices[port_id];
1141 /* Default device offload capabilities to zero */
1142 dev_info->rx_offload_capa = 0;
1143 dev_info->tx_offload_capa = 0;
1144 dev_info->if_index = 0;
1145 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1146 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1147 dev_info->pci_dev = dev->pci_dev;
1149 dev_info->driver_name = dev->driver->pci_drv.name;
1153 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1155 struct rte_eth_dev *dev;
1157 if (port_id >= nb_ports) {
1158 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1161 dev = &rte_eth_devices[port_id];
1162 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1166 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1168 struct rte_eth_dev *dev;
1170 if (port_id >= nb_ports) {
1171 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1174 dev = &rte_eth_devices[port_id];
1175 if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1176 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1180 if (vlan_id > 4095) {
1181 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1182 port_id, (unsigned) vlan_id);
1185 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1186 (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1191 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1193 struct rte_eth_dev *dev;
1195 if (port_id >= nb_ports) {
1196 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1200 dev = &rte_eth_devices[port_id];
1201 if (rx_queue_id >= dev->data->nb_rx_queues) {
1202 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1206 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1207 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1213 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1215 struct rte_eth_dev *dev;
1217 if (port_id >= nb_ports) {
1218 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1222 dev = &rte_eth_devices[port_id];
1223 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1224 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1230 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1232 struct rte_eth_dev *dev;
1237 if (port_id >= nb_ports) {
1238 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1242 dev = &rte_eth_devices[port_id];
1244 /*check which option changed by application*/
1245 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1246 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1248 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1249 mask |= ETH_VLAN_STRIP_MASK;
1252 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1253 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1255 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1256 mask |= ETH_VLAN_FILTER_MASK;
1259 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1260 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1262 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1263 mask |= ETH_VLAN_EXTEND_MASK;
1270 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1271 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1277 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1279 struct rte_eth_dev *dev;
1282 if (port_id >= nb_ports) {
1283 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1287 dev = &rte_eth_devices[port_id];
1289 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1290 ret |= ETH_VLAN_STRIP_OFFLOAD ;
1292 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1293 ret |= ETH_VLAN_FILTER_OFFLOAD ;
1295 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1296 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
1303 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1304 struct rte_fdir_filter *fdir_filter,
1307 struct rte_eth_dev *dev;
1309 if (port_id >= nb_ports) {
1310 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1314 dev = &rte_eth_devices[port_id];
1316 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1317 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1318 port_id, dev->data->dev_conf.fdir_conf.mode);
1322 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1323 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1324 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1325 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1326 "None l4type, source & destinations ports " \
1327 "should be null!\n");
1331 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1332 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1337 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1338 struct rte_fdir_filter *fdir_filter,
1341 struct rte_eth_dev *dev;
1343 if (port_id >= nb_ports) {
1344 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1348 dev = &rte_eth_devices[port_id];
1350 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1351 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1352 port_id, dev->data->dev_conf.fdir_conf.mode);
1356 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1357 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1358 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1359 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1360 "None l4type, source & destinations ports " \
1361 "should be null!\n");
1365 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
1366 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
1372 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
1373 struct rte_fdir_filter *fdir_filter)
1375 struct rte_eth_dev *dev;
1377 if (port_id >= nb_ports) {
1378 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1382 dev = &rte_eth_devices[port_id];
1384 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1385 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1386 port_id, dev->data->dev_conf.fdir_conf.mode);
1390 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1391 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1392 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1393 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1394 "None l4type source & destinations ports " \
1395 "should be null!\n");
1399 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
1400 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
1404 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
1406 struct rte_eth_dev *dev;
1408 if (port_id >= nb_ports) {
1409 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1413 dev = &rte_eth_devices[port_id];
1414 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1415 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1419 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
1421 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
1426 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
1427 struct rte_fdir_filter *fdir_filter,
1428 uint16_t soft_id, uint8_t queue,
1431 struct rte_eth_dev *dev;
1433 if (port_id >= nb_ports) {
1434 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1438 dev = &rte_eth_devices[port_id];
1440 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1441 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1442 port_id, dev->data->dev_conf.fdir_conf.mode);
1446 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1447 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1448 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1449 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1450 "None l4type, source & destinations ports " \
1451 "should be null!\n");
1455 /* For now IPv6 is not supported with perfect filter */
1456 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1459 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
1460 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
1466 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
1467 struct rte_fdir_filter *fdir_filter,
1468 uint16_t soft_id, uint8_t queue,
1471 struct rte_eth_dev *dev;
1473 if (port_id >= nb_ports) {
1474 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1478 dev = &rte_eth_devices[port_id];
1480 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1481 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1482 port_id, dev->data->dev_conf.fdir_conf.mode);
1486 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1487 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1488 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1489 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1490 "None l4type, source & destinations ports " \
1491 "should be null!\n");
1495 /* For now IPv6 is not supported with perfect filter */
1496 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1499 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
1500 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
1501 soft_id, queue, drop);
1505 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
1506 struct rte_fdir_filter *fdir_filter,
1509 struct rte_eth_dev *dev;
1511 if (port_id >= nb_ports) {
1512 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1516 dev = &rte_eth_devices[port_id];
1518 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1519 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1520 port_id, dev->data->dev_conf.fdir_conf.mode);
1524 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1525 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1526 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1527 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1528 "None l4type, source & destinations ports " \
1529 "should be null!\n");
1533 /* For now IPv6 is not supported with perfect filter */
1534 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1537 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
1538 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
1543 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
1545 struct rte_eth_dev *dev;
1547 if (port_id >= nb_ports) {
1548 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1552 dev = &rte_eth_devices[port_id];
1553 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1554 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1558 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
1559 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
1563 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1565 struct rte_eth_dev *dev;
1567 if (port_id >= nb_ports) {
1568 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1572 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1573 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1577 dev = &rte_eth_devices[port_id];
1578 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1579 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1583 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1585 struct rte_eth_dev *dev;
1587 if (port_id >= nb_ports) {
1588 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1592 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1593 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1597 dev = &rte_eth_devices[port_id];
1598 /* High water, low water validation are device specific */
1599 if (*dev->dev_ops->priority_flow_ctrl_set)
1600 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1605 rte_eth_dev_rss_reta_update(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
1607 struct rte_eth_dev *dev;
1611 if (port_id >= nb_ports) {
1612 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1616 /* Invalid mask bit(s) setting */
1617 if ((reta_conf->mask_lo == 0) && (reta_conf->mask_hi == 0)) {
1618 PMD_DEBUG_TRACE("Invalid update mask bits for port=%d\n",port_id);
1622 dev = &rte_eth_devices[port_id];
1623 max_rxq = (dev->data->nb_rx_queues <= ETH_RSS_RETA_MAX_QUEUE) ?
1624 dev->data->nb_rx_queues : ETH_RSS_RETA_MAX_QUEUE;
1625 if (reta_conf->mask_lo != 0) {
1626 for (i = 0; i < ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
1627 if ((reta_conf->mask_lo & (1ULL << i)) &&
1628 (reta_conf->reta[i] >= max_rxq)) {
1629 PMD_DEBUG_TRACE("RETA hash index output"
1630 "configration for port=%d,invalid"
1631 "queue=%d\n",port_id,reta_conf->reta[i]);
1638 if (reta_conf->mask_hi != 0) {
1639 for (i = 0; i< ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
1640 j = (uint8_t)(i + ETH_RSS_RETA_NUM_ENTRIES/2);
1642 /* Check if the max entry >= 128 */
1643 if ((reta_conf->mask_hi & (1ULL << i)) &&
1644 (reta_conf->reta[j] >= max_rxq)) {
1645 PMD_DEBUG_TRACE("RETA hash index output"
1646 "configration for port=%d,invalid"
1647 "queue=%d\n",port_id,reta_conf->reta[j]);
1654 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
1655 return (*dev->dev_ops->reta_update)(dev, reta_conf);
1659 rte_eth_dev_rss_reta_query(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
1661 struct rte_eth_dev *dev;
1663 if (port_id >= nb_ports) {
1664 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1668 if((reta_conf->mask_lo == 0) && (reta_conf->mask_hi == 0)) {
1669 PMD_DEBUG_TRACE("Invalid update mask bits for the port=%d\n",port_id);
1673 dev = &rte_eth_devices[port_id];
1674 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
1675 return (*dev->dev_ops->reta_query)(dev, reta_conf);
1679 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
1681 struct rte_eth_dev *dev;
1682 uint16_t rss_hash_protos;
1684 if (port_id >= nb_ports) {
1685 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1688 rss_hash_protos = rss_conf->rss_hf;
1689 if ((rss_hash_protos != 0) &&
1690 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
1691 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
1695 dev = &rte_eth_devices[port_id];
1696 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
1697 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
1701 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
1702 struct rte_eth_rss_conf *rss_conf)
1704 struct rte_eth_dev *dev;
1706 if (port_id >= nb_ports) {
1707 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1710 dev = &rte_eth_devices[port_id];
1711 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
1712 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
1716 rte_eth_led_on(uint8_t port_id)
1718 struct rte_eth_dev *dev;
1720 if (port_id >= nb_ports) {
1721 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1725 dev = &rte_eth_devices[port_id];
1726 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
1727 return ((*dev->dev_ops->dev_led_on)(dev));
1731 rte_eth_led_off(uint8_t port_id)
1733 struct rte_eth_dev *dev;
1735 if (port_id >= nb_ports) {
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->dev_led_off, -ENOTSUP);
1742 return ((*dev->dev_ops->dev_led_off)(dev));
1746 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
1750 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
1752 struct rte_eth_dev_info dev_info;
1753 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1756 rte_eth_dev_info_get(port_id, &dev_info);
1758 for (i = 0; i < dev_info.max_mac_addrs; i++)
1759 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
1765 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
1768 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
1771 struct rte_eth_dev *dev;
1775 if (port_id >= nb_ports) {
1776 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1779 dev = &rte_eth_devices[port_id];
1780 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
1782 if (is_zero_ether_addr(addr)) {
1783 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
1787 if (pool >= ETH_64_POOLS) {
1788 PMD_DEBUG_TRACE("pool id must be 0-%d\n",ETH_64_POOLS - 1);
1792 index = get_mac_addr_index(port_id, addr);
1794 index = get_mac_addr_index(port_id, &null_mac_addr);
1796 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
1801 pool_mask = dev->data->mac_pool_sel[index];
1803 /* Check if both MAC address and pool is alread there, and do nothing */
1804 if (pool_mask & (1ULL << pool))
1809 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
1811 /* Update address in NIC data structure */
1812 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
1814 /* Update pool bitmap in NIC data structure */
1815 dev->data->mac_pool_sel[index] |= (1ULL << pool);
1821 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
1823 struct rte_eth_dev *dev;
1826 if (port_id >= nb_ports) {
1827 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->mac_addr_remove, -ENOTSUP);
1833 index = get_mac_addr_index(port_id, addr);
1835 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
1836 return (-EADDRINUSE);
1837 } else if (index < 0)
1838 return 0; /* Do nothing if address wasn't found */
1841 (*dev->dev_ops->mac_addr_remove)(dev, index);
1843 /* Update address in NIC data structure */
1844 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
1850 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
1851 uint16_t rx_mode, uint8_t on)
1854 struct rte_eth_dev *dev;
1855 struct rte_eth_dev_info dev_info;
1857 if (port_id >= nb_ports) {
1858 PMD_DEBUG_TRACE("set VF RX mode:Invalid port_id=%d\n",
1863 dev = &rte_eth_devices[port_id];
1864 rte_eth_dev_info_get(port_id, &dev_info);
1866 num_vfs = dev_info.max_vfs;
1869 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
1874 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
1877 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
1878 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
1882 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
1886 get_hash_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
1888 struct rte_eth_dev_info dev_info;
1889 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1892 rte_eth_dev_info_get(port_id, &dev_info);
1893 if (!dev->data->hash_mac_addrs)
1896 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
1897 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
1898 ETHER_ADDR_LEN) == 0)
1905 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
1910 struct rte_eth_dev *dev;
1912 if (port_id >= nb_ports) {
1913 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
1918 dev = &rte_eth_devices[port_id];
1919 if (is_zero_ether_addr(addr)) {
1920 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
1925 index = get_hash_mac_addr_index(port_id, addr);
1926 /* Check if it's already there, and do nothing */
1927 if ((index >= 0) && (on))
1932 PMD_DEBUG_TRACE("port %d: the MAC address was not"
1933 "set in UTA\n", port_id);
1937 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
1939 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
1945 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
1946 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
1948 /* Update address in NIC data structure */
1950 ether_addr_copy(addr,
1951 &dev->data->hash_mac_addrs[index]);
1953 ether_addr_copy(&null_mac_addr,
1954 &dev->data->hash_mac_addrs[index]);
1961 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
1963 struct rte_eth_dev *dev;
1965 if (port_id >= nb_ports) {
1966 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
1971 dev = &rte_eth_devices[port_id];
1973 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
1974 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
1978 rte_eth_dev_set_vf_rx(uint8_t port_id,uint16_t vf, uint8_t on)
1981 struct rte_eth_dev *dev;
1982 struct rte_eth_dev_info dev_info;
1984 if (port_id >= nb_ports) {
1985 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1989 dev = &rte_eth_devices[port_id];
1990 rte_eth_dev_info_get(port_id, &dev_info);
1992 num_vfs = dev_info.max_vfs;
1995 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
1999 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2000 return (*dev->dev_ops->set_vf_rx)(dev, vf,on);
2004 rte_eth_dev_set_vf_tx(uint8_t port_id,uint16_t vf, uint8_t on)
2007 struct rte_eth_dev *dev;
2008 struct rte_eth_dev_info dev_info;
2010 if (port_id >= nb_ports) {
2011 PMD_DEBUG_TRACE("set pool tx:Invalid port_id=%d\n", port_id);
2015 dev = &rte_eth_devices[port_id];
2016 rte_eth_dev_info_get(port_id, &dev_info);
2018 num_vfs = dev_info.max_vfs;
2021 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2025 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2026 return (*dev->dev_ops->set_vf_tx)(dev, vf,on);
2030 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2031 uint64_t vf_mask,uint8_t vlan_on)
2033 struct rte_eth_dev *dev;
2035 if (port_id >= nb_ports) {
2036 PMD_DEBUG_TRACE("VF VLAN filter:invalid port id=%d\n",
2040 dev = &rte_eth_devices[port_id];
2042 if(vlan_id > ETHER_MAX_VLAN_ID)
2044 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2050 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2054 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2055 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2060 rte_eth_mirror_rule_set(uint8_t port_id,
2061 struct rte_eth_vmdq_mirror_conf *mirror_conf,
2062 uint8_t rule_id, uint8_t on)
2064 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2066 if (port_id >= nb_ports) {
2067 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2071 if (mirror_conf->rule_type_mask == 0) {
2072 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2076 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2077 PMD_DEBUG_TRACE("Invalid dst pool, pool id must"
2078 "be 0-%d\n",ETH_64_POOLS - 1);
2082 if ((mirror_conf->rule_type_mask & ETH_VMDQ_POOL_MIRROR) &&
2083 (mirror_conf->pool_mask == 0)) {
2084 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not"
2089 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2091 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2092 ETH_VMDQ_NUM_MIRROR_RULE - 1);
2096 dev = &rte_eth_devices[port_id];
2097 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2099 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2103 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2105 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2107 if (port_id >= nb_ports) {
2108 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2112 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2114 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2115 ETH_VMDQ_NUM_MIRROR_RULE-1);
2119 dev = &rte_eth_devices[port_id];
2120 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2122 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2125 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2127 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2128 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2130 struct rte_eth_dev *dev;
2132 if (port_id >= nb_ports) {
2133 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2136 dev = &rte_eth_devices[port_id];
2137 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, -ENOTSUP);
2138 if (queue_id >= dev->data->nb_rx_queues) {
2139 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2142 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2147 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2148 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2150 struct rte_eth_dev *dev;
2152 if (port_id >= nb_ports) {
2153 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2156 dev = &rte_eth_devices[port_id];
2158 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, -ENOTSUP);
2159 if (queue_id >= dev->data->nb_tx_queues) {
2160 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2163 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2168 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2170 struct rte_eth_dev *dev;
2172 if (port_id >= nb_ports) {
2173 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2176 dev = &rte_eth_devices[port_id];
2177 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, -ENOTSUP);
2178 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2182 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2184 struct rte_eth_dev *dev;
2186 if (port_id >= nb_ports) {
2187 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2190 dev = &rte_eth_devices[port_id];
2191 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2192 return (*dev->dev_ops->rx_descriptor_done)( \
2193 dev->data->rx_queues[queue_id], offset);
2198 rte_eth_dev_callback_register(uint8_t port_id,
2199 enum rte_eth_event_type event,
2200 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2202 struct rte_eth_dev *dev;
2203 struct rte_eth_dev_callback *user_cb;
2207 if (port_id >= nb_ports) {
2208 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2212 dev = &rte_eth_devices[port_id];
2213 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2215 TAILQ_FOREACH(user_cb, &(dev->callbacks), next) {
2216 if (user_cb->cb_fn == cb_fn &&
2217 user_cb->cb_arg == cb_arg &&
2218 user_cb->event == event) {
2223 /* create a new callback. */
2224 if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2225 sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
2226 user_cb->cb_fn = cb_fn;
2227 user_cb->cb_arg = cb_arg;
2228 user_cb->event = event;
2229 TAILQ_INSERT_TAIL(&(dev->callbacks), user_cb, next);
2232 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2233 return ((user_cb == NULL) ? -ENOMEM : 0);
2237 rte_eth_dev_callback_unregister(uint8_t port_id,
2238 enum rte_eth_event_type event,
2239 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2242 struct rte_eth_dev *dev;
2243 struct rte_eth_dev_callback *cb, *next;
2247 if (port_id >= nb_ports) {
2248 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2252 dev = &rte_eth_devices[port_id];
2253 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2256 for (cb = TAILQ_FIRST(&dev->callbacks); cb != NULL; cb = next) {
2258 next = TAILQ_NEXT(cb, next);
2260 if (cb->cb_fn != cb_fn || cb->event != event ||
2261 (cb->cb_arg != (void *)-1 &&
2262 cb->cb_arg != cb_arg))
2266 * if this callback is not executing right now,
2269 if (cb->active == 0) {
2270 TAILQ_REMOVE(&(dev->callbacks), cb, next);
2277 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2282 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2283 enum rte_eth_event_type event)
2285 struct rte_eth_dev_callback *cb_lst;
2286 struct rte_eth_dev_callback dev_cb;
2288 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2289 TAILQ_FOREACH(cb_lst, &(dev->callbacks), next) {
2290 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2294 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2295 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2297 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2300 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2302 #ifdef RTE_NIC_BYPASS
2303 int rte_eth_dev_bypass_init(uint8_t port_id)
2305 struct rte_eth_dev *dev;
2307 if (port_id >= nb_ports) {
2308 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2312 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2313 PMD_DEBUG_TRACE("Invalid port device\n");
2317 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2318 (*dev->dev_ops->bypass_init)(dev);
2323 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2325 struct rte_eth_dev *dev;
2327 if (port_id >= nb_ports) {
2328 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2332 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2333 PMD_DEBUG_TRACE("Invalid port device\n");
2336 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2337 (*dev->dev_ops->bypass_state_show)(dev, state);
2342 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2344 struct rte_eth_dev *dev;
2346 if (port_id >= nb_ports) {
2347 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2351 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2352 PMD_DEBUG_TRACE("Invalid port device\n");
2356 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2357 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2362 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2364 struct rte_eth_dev *dev;
2366 if (port_id >= nb_ports) {
2367 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2371 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2372 PMD_DEBUG_TRACE("Invalid port device\n");
2376 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2377 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2382 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2384 struct rte_eth_dev *dev;
2386 if (port_id >= nb_ports) {
2387 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2391 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2392 PMD_DEBUG_TRACE("Invalid port device\n");
2396 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2397 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2402 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2404 struct rte_eth_dev *dev;
2406 if (port_id >= nb_ports) {
2407 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2411 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2412 PMD_DEBUG_TRACE("Invalid port device\n");
2416 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2417 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2422 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2424 struct rte_eth_dev *dev;
2426 if (port_id >= nb_ports) {
2427 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2431 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2432 PMD_DEBUG_TRACE("Invalid port device\n");
2436 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2437 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2442 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2444 struct rte_eth_dev *dev;
2446 if (port_id >= nb_ports) {
2447 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2451 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2452 PMD_DEBUG_TRACE("Invalid port device\n");
2456 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2457 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2462 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2464 struct rte_eth_dev *dev;
2466 if (port_id >= nb_ports) {
2467 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2471 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2472 PMD_DEBUG_TRACE("Invalid port device\n");
2476 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2477 (*dev->dev_ops->bypass_wd_reset)(dev);