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=%" PRIu8
452 "wrong VMDQ mq_mode rx %u tx %u\n",
454 dev_conf->rxmode.mq_mode,
455 dev_conf->txmode.mq_mode);
459 switch (dev_conf->rxmode.mq_mode) {
460 case ETH_MQ_RX_VMDQ_RSS:
461 case ETH_MQ_RX_VMDQ_DCB:
462 case ETH_MQ_RX_VMDQ_DCB_RSS:
463 /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
464 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
466 "unsupported VMDQ mq_mode rx %u\n",
467 port_id, dev_conf->rxmode.mq_mode);
469 default: /* ETH_MQ_RX_VMDQ_ONLY or ETH_MQ_RX_NONE */
470 /* if nothing mq mode configure, use default scheme */
471 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
472 if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
473 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
477 switch (dev_conf->txmode.mq_mode) {
478 case ETH_MQ_TX_VMDQ_DCB:
479 /* DCB VMDQ in SRIOV mode, not implement yet */
480 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
482 "unsupported VMDQ mq_mode tx %u\n",
483 port_id, dev_conf->txmode.mq_mode);
485 default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
486 /* if nothing mq mode configure, use default scheme */
487 dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
488 if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
489 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
493 /* check valid queue number */
494 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
495 (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
496 PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
497 "queue number must less equal to %d\n",
498 port_id, RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
502 /* For vmdb+dcb mode check our configuration before we go further */
503 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB) {
504 const struct rte_eth_vmdq_dcb_conf *conf;
506 if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
507 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
509 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
512 conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
513 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
514 conf->nb_queue_pools == ETH_32_POOLS)) {
515 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
516 "nb_queue_pools must be %d or %d\n",
517 port_id, ETH_16_POOLS, ETH_32_POOLS);
521 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
522 const struct rte_eth_vmdq_dcb_tx_conf *conf;
524 if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
525 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
527 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
530 conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
531 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
532 conf->nb_queue_pools == ETH_32_POOLS)) {
533 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
534 "nb_queue_pools != %d or nb_queue_pools "
536 port_id, ETH_16_POOLS, ETH_32_POOLS);
541 /* For DCB mode check our configuration before we go further */
542 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) {
543 const struct rte_eth_dcb_rx_conf *conf;
545 if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
546 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
548 port_id, ETH_DCB_NUM_QUEUES);
551 conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
552 if (! (conf->nb_tcs == ETH_4_TCS ||
553 conf->nb_tcs == ETH_8_TCS)) {
554 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
555 "nb_tcs != %d or nb_tcs "
557 port_id, ETH_4_TCS, ETH_8_TCS);
562 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
563 const struct rte_eth_dcb_tx_conf *conf;
565 if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
566 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
568 port_id, ETH_DCB_NUM_QUEUES);
571 conf = &(dev_conf->tx_adv_conf.dcb_tx_conf);
572 if (! (conf->nb_tcs == ETH_4_TCS ||
573 conf->nb_tcs == ETH_8_TCS)) {
574 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
575 "nb_tcs != %d or nb_tcs "
577 port_id, ETH_4_TCS, ETH_8_TCS);
586 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
587 const struct rte_eth_conf *dev_conf)
589 struct rte_eth_dev *dev;
590 struct rte_eth_dev_info dev_info;
593 /* This function is only safe when called from the primary process
594 * in a multi-process setup*/
595 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
597 if (port_id >= nb_ports || port_id >= RTE_MAX_ETHPORTS) {
598 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
601 dev = &rte_eth_devices[port_id];
603 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
604 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
606 if (dev->data->dev_started) {
608 "port %d must be stopped to allow configuration\n", port_id);
613 * Check that the numbers of RX and TX queues are not greater
614 * than the maximum number of RX and TX queues supported by the
617 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
618 if (nb_rx_q > dev_info.max_rx_queues) {
619 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
620 port_id, nb_rx_q, dev_info.max_rx_queues);
624 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
628 if (nb_tx_q > dev_info.max_tx_queues) {
629 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
630 port_id, nb_tx_q, dev_info.max_tx_queues);
634 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
638 /* Copy the dev_conf parameter into the dev structure */
639 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
642 * If jumbo frames are enabled, check that the maximum RX packet
643 * length is supported by the configured device.
645 if (dev_conf->rxmode.jumbo_frame == 1) {
646 if (dev_conf->rxmode.max_rx_pkt_len >
647 dev_info.max_rx_pktlen) {
648 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
649 " > max valid value %u\n",
651 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
652 (unsigned)dev_info.max_rx_pktlen);
655 else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
656 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
657 " < min valid value %u\n",
659 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
660 (unsigned)ETHER_MIN_LEN);
664 /* Use default value */
665 dev->data->dev_conf.rxmode.max_rx_pkt_len = ETHER_MAX_LEN;
667 /* multipe queue mode checking */
668 diag = rte_eth_dev_check_mq_mode(port_id, nb_rx_q, nb_tx_q, dev_conf);
670 PMD_DEBUG_TRACE("port%d rte_eth_dev_check_mq_mode = %d\n",
676 * Setup new number of RX/TX queues and reconfigure device.
678 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
680 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
685 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
687 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
689 rte_eth_dev_rx_queue_config(dev, 0);
693 diag = (*dev->dev_ops->dev_configure)(dev);
695 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
697 rte_eth_dev_rx_queue_config(dev, 0);
698 rte_eth_dev_tx_queue_config(dev, 0);
706 rte_eth_dev_config_restore(uint8_t port_id)
708 struct rte_eth_dev *dev;
709 struct rte_eth_dev_info dev_info;
710 struct ether_addr addr;
714 dev = &rte_eth_devices[port_id];
716 rte_eth_dev_info_get(port_id, &dev_info);
718 if (RTE_ETH_DEV_SRIOV(dev).active)
719 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
721 /* replay MAC address configuration */
722 for (i = 0; i < dev_info.max_mac_addrs; i++) {
723 addr = dev->data->mac_addrs[i];
725 /* skip zero address */
726 if (is_zero_ether_addr(&addr))
729 /* add address to the hardware */
730 if (*dev->dev_ops->mac_addr_add)
731 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
733 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
735 /* exit the loop but not return an error */
740 /* replay promiscuous configuration */
741 if (rte_eth_promiscuous_get(port_id) == 1)
742 rte_eth_promiscuous_enable(port_id);
743 else if (rte_eth_promiscuous_get(port_id) == 0)
744 rte_eth_promiscuous_disable(port_id);
746 /* replay allmulticast configuration */
747 if (rte_eth_allmulticast_get(port_id) == 1)
748 rte_eth_allmulticast_enable(port_id);
749 else if (rte_eth_allmulticast_get(port_id) == 0)
750 rte_eth_allmulticast_disable(port_id);
754 rte_eth_dev_start(uint8_t port_id)
756 struct rte_eth_dev *dev;
759 /* This function is only safe when called from the primary process
760 * in a multi-process setup*/
761 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
763 if (port_id >= nb_ports) {
764 PMD_DEBUG_TRACE("Invalid port_id=%" PRIu8 "\n", port_id);
767 dev = &rte_eth_devices[port_id];
769 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
771 if (dev->data->dev_started != 0) {
772 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
773 " already started\n",
778 diag = (*dev->dev_ops->dev_start)(dev);
780 dev->data->dev_started = 1;
784 rte_eth_dev_config_restore(port_id);
790 rte_eth_dev_stop(uint8_t port_id)
792 struct rte_eth_dev *dev;
794 /* This function is only safe when called from the primary process
795 * in a multi-process setup*/
796 PROC_PRIMARY_OR_RET();
798 if (port_id >= nb_ports) {
799 PMD_DEBUG_TRACE("Invalid port_id=%" PRIu8 "\n", port_id);
802 dev = &rte_eth_devices[port_id];
804 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
806 if (dev->data->dev_started == 0) {
807 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
808 " already stopped\n",
813 dev->data->dev_started = 0;
814 (*dev->dev_ops->dev_stop)(dev);
818 rte_eth_dev_close(uint8_t port_id)
820 struct rte_eth_dev *dev;
822 /* This function is only safe when called from the primary process
823 * in a multi-process setup*/
824 PROC_PRIMARY_OR_RET();
826 if (port_id >= nb_ports) {
827 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
831 dev = &rte_eth_devices[port_id];
833 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
834 dev->data->dev_started = 0;
835 (*dev->dev_ops->dev_close)(dev);
839 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
840 uint16_t nb_rx_desc, unsigned int socket_id,
841 const struct rte_eth_rxconf *rx_conf,
842 struct rte_mempool *mp)
844 struct rte_eth_dev *dev;
845 struct rte_pktmbuf_pool_private *mbp_priv;
846 struct rte_eth_dev_info dev_info;
848 /* This function is only safe when called from the primary process
849 * in a multi-process setup*/
850 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
852 if (port_id >= nb_ports) {
853 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
856 dev = &rte_eth_devices[port_id];
857 if (rx_queue_id >= dev->data->nb_rx_queues) {
858 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
862 if (dev->data->dev_started) {
864 "port %d must be stopped to allow configuration\n", port_id);
868 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
869 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
872 * Check the size of the mbuf data buffer.
873 * This value must be provided in the private data of the memory pool.
874 * First check that the memory pool has a valid private data.
876 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
877 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
878 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
879 mp->name, (int) mp->private_data_size,
880 (int) sizeof(struct rte_pktmbuf_pool_private));
883 mbp_priv = rte_mempool_get_priv(mp);
884 if ((uint32_t) (mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM) <
885 dev_info.min_rx_bufsize) {
886 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
887 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
890 (int)mbp_priv->mbuf_data_room_size,
891 (int)(RTE_PKTMBUF_HEADROOM +
892 dev_info.min_rx_bufsize),
893 (int)RTE_PKTMBUF_HEADROOM,
894 (int)dev_info.min_rx_bufsize);
898 return (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
899 socket_id, rx_conf, mp);
903 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
904 uint16_t nb_tx_desc, unsigned int socket_id,
905 const struct rte_eth_txconf *tx_conf)
907 struct rte_eth_dev *dev;
909 /* This function is only safe when called from the primary process
910 * in a multi-process setup*/
911 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
913 if (port_id >= RTE_MAX_ETHPORTS || port_id >= nb_ports) {
914 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
917 dev = &rte_eth_devices[port_id];
918 if (tx_queue_id >= dev->data->nb_tx_queues) {
919 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
923 if (dev->data->dev_started) {
925 "port %d must be stopped to allow configuration\n", port_id);
929 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
930 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
935 rte_eth_promiscuous_enable(uint8_t port_id)
937 struct rte_eth_dev *dev;
939 if (port_id >= nb_ports) {
940 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
943 dev = &rte_eth_devices[port_id];
945 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
946 (*dev->dev_ops->promiscuous_enable)(dev);
947 dev->data->promiscuous = 1;
951 rte_eth_promiscuous_disable(uint8_t port_id)
953 struct rte_eth_dev *dev;
955 if (port_id >= nb_ports) {
956 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
959 dev = &rte_eth_devices[port_id];
961 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
962 dev->data->promiscuous = 0;
963 (*dev->dev_ops->promiscuous_disable)(dev);
967 rte_eth_promiscuous_get(uint8_t port_id)
969 struct rte_eth_dev *dev;
971 if (port_id >= nb_ports) {
972 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
976 dev = &rte_eth_devices[port_id];
977 return dev->data->promiscuous;
981 rte_eth_allmulticast_enable(uint8_t port_id)
983 struct rte_eth_dev *dev;
985 if (port_id >= nb_ports) {
986 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
989 dev = &rte_eth_devices[port_id];
991 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
992 (*dev->dev_ops->allmulticast_enable)(dev);
993 dev->data->all_multicast = 1;
997 rte_eth_allmulticast_disable(uint8_t port_id)
999 struct rte_eth_dev *dev;
1001 if (port_id >= nb_ports) {
1002 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1005 dev = &rte_eth_devices[port_id];
1007 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1008 dev->data->all_multicast = 0;
1009 (*dev->dev_ops->allmulticast_disable)(dev);
1013 rte_eth_allmulticast_get(uint8_t port_id)
1015 struct rte_eth_dev *dev;
1017 if (port_id >= nb_ports) {
1018 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1022 dev = &rte_eth_devices[port_id];
1023 return dev->data->all_multicast;
1027 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1028 struct rte_eth_link *link)
1030 struct rte_eth_link *dst = link;
1031 struct rte_eth_link *src = &(dev->data->dev_link);
1033 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1034 *(uint64_t *)src) == 0)
1041 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1043 struct rte_eth_dev *dev;
1045 if (port_id >= nb_ports) {
1046 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1049 dev = &rte_eth_devices[port_id];
1050 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1052 if (dev->data->dev_conf.intr_conf.lsc != 0)
1053 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1055 (*dev->dev_ops->link_update)(dev, 1);
1056 *eth_link = dev->data->dev_link;
1061 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1063 struct rte_eth_dev *dev;
1065 if (port_id >= nb_ports) {
1066 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1069 dev = &rte_eth_devices[port_id];
1070 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1072 if (dev->data->dev_conf.intr_conf.lsc != 0)
1073 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1075 (*dev->dev_ops->link_update)(dev, 0);
1076 *eth_link = dev->data->dev_link;
1081 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1083 struct rte_eth_dev *dev;
1085 if (port_id >= nb_ports) {
1086 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1089 dev = &rte_eth_devices[port_id];
1090 memset(stats, 0, sizeof(*stats));
1092 FUNC_PTR_OR_RET(*dev->dev_ops->stats_get);
1093 (*dev->dev_ops->stats_get)(dev, stats);
1094 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1098 rte_eth_stats_reset(uint8_t port_id)
1100 struct rte_eth_dev *dev;
1102 if (port_id >= nb_ports) {
1103 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1106 dev = &rte_eth_devices[port_id];
1108 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1109 (*dev->dev_ops->stats_reset)(dev);
1114 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1117 struct rte_eth_dev *dev;
1119 if (port_id >= nb_ports) {
1120 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1123 dev = &rte_eth_devices[port_id];
1125 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1126 return (*dev->dev_ops->queue_stats_mapping_set)
1127 (dev, queue_id, stat_idx, is_rx);
1132 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1135 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1141 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1144 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1150 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1152 struct rte_eth_dev *dev;
1154 if (port_id >= nb_ports) {
1155 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1158 dev = &rte_eth_devices[port_id];
1160 /* Default device offload capabilities to zero */
1161 dev_info->rx_offload_capa = 0;
1162 dev_info->tx_offload_capa = 0;
1163 dev_info->if_index = 0;
1164 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1165 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1166 dev_info->pci_dev = dev->pci_dev;
1168 dev_info->driver_name = dev->driver->pci_drv.name;
1172 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1174 struct rte_eth_dev *dev;
1176 if (port_id >= nb_ports) {
1177 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1180 dev = &rte_eth_devices[port_id];
1181 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1185 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1187 struct rte_eth_dev *dev;
1189 if (port_id >= nb_ports) {
1190 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1193 dev = &rte_eth_devices[port_id];
1194 if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1195 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1199 if (vlan_id > 4095) {
1200 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1201 port_id, (unsigned) vlan_id);
1204 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1205 (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1210 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1212 struct rte_eth_dev *dev;
1214 if (port_id >= nb_ports) {
1215 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1219 dev = &rte_eth_devices[port_id];
1220 if (rx_queue_id >= dev->data->nb_rx_queues) {
1221 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1225 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1226 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1232 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1234 struct rte_eth_dev *dev;
1236 if (port_id >= nb_ports) {
1237 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1241 dev = &rte_eth_devices[port_id];
1242 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1243 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1249 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1251 struct rte_eth_dev *dev;
1256 if (port_id >= nb_ports) {
1257 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1261 dev = &rte_eth_devices[port_id];
1263 /*check which option changed by application*/
1264 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1265 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1267 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1268 mask |= ETH_VLAN_STRIP_MASK;
1271 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1272 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1274 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1275 mask |= ETH_VLAN_FILTER_MASK;
1278 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1279 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1281 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1282 mask |= ETH_VLAN_EXTEND_MASK;
1289 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1290 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1296 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1298 struct rte_eth_dev *dev;
1301 if (port_id >= nb_ports) {
1302 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1306 dev = &rte_eth_devices[port_id];
1308 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1309 ret |= ETH_VLAN_STRIP_OFFLOAD ;
1311 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1312 ret |= ETH_VLAN_FILTER_OFFLOAD ;
1314 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1315 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
1322 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1323 struct rte_fdir_filter *fdir_filter,
1326 struct rte_eth_dev *dev;
1328 if (port_id >= nb_ports) {
1329 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1333 dev = &rte_eth_devices[port_id];
1335 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1336 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1337 port_id, dev->data->dev_conf.fdir_conf.mode);
1341 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1342 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1343 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1344 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1345 "None l4type, source & destinations ports " \
1346 "should be null!\n");
1350 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1351 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1356 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1357 struct rte_fdir_filter *fdir_filter,
1360 struct rte_eth_dev *dev;
1362 if (port_id >= nb_ports) {
1363 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1367 dev = &rte_eth_devices[port_id];
1369 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1370 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1371 port_id, dev->data->dev_conf.fdir_conf.mode);
1375 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1376 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1377 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1378 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1379 "None l4type, source & destinations ports " \
1380 "should be null!\n");
1384 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
1385 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
1391 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
1392 struct rte_fdir_filter *fdir_filter)
1394 struct rte_eth_dev *dev;
1396 if (port_id >= nb_ports) {
1397 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1401 dev = &rte_eth_devices[port_id];
1403 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1404 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1405 port_id, dev->data->dev_conf.fdir_conf.mode);
1409 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1410 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1411 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1412 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1413 "None l4type source & destinations ports " \
1414 "should be null!\n");
1418 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
1419 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
1423 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
1425 struct rte_eth_dev *dev;
1427 if (port_id >= nb_ports) {
1428 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1432 dev = &rte_eth_devices[port_id];
1433 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1434 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1438 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
1440 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
1445 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
1446 struct rte_fdir_filter *fdir_filter,
1447 uint16_t soft_id, uint8_t queue,
1450 struct rte_eth_dev *dev;
1452 if (port_id >= nb_ports) {
1453 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1457 dev = &rte_eth_devices[port_id];
1459 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1460 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1461 port_id, dev->data->dev_conf.fdir_conf.mode);
1465 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1466 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1467 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1468 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1469 "None l4type, source & destinations ports " \
1470 "should be null!\n");
1474 /* For now IPv6 is not supported with perfect filter */
1475 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1478 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
1479 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
1485 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
1486 struct rte_fdir_filter *fdir_filter,
1487 uint16_t soft_id, uint8_t queue,
1490 struct rte_eth_dev *dev;
1492 if (port_id >= nb_ports) {
1493 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1497 dev = &rte_eth_devices[port_id];
1499 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1500 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1501 port_id, dev->data->dev_conf.fdir_conf.mode);
1505 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1506 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1507 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1508 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1509 "None l4type, source & destinations ports " \
1510 "should be null!\n");
1514 /* For now IPv6 is not supported with perfect filter */
1515 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1518 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
1519 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
1520 soft_id, queue, drop);
1524 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
1525 struct rte_fdir_filter *fdir_filter,
1528 struct rte_eth_dev *dev;
1530 if (port_id >= nb_ports) {
1531 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1535 dev = &rte_eth_devices[port_id];
1537 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1538 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1539 port_id, dev->data->dev_conf.fdir_conf.mode);
1543 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1544 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1545 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1546 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1547 "None l4type, source & destinations ports " \
1548 "should be null!\n");
1552 /* For now IPv6 is not supported with perfect filter */
1553 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1556 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
1557 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
1562 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
1564 struct rte_eth_dev *dev;
1566 if (port_id >= nb_ports) {
1567 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1571 dev = &rte_eth_devices[port_id];
1572 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1573 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1577 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
1578 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
1582 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1584 struct rte_eth_dev *dev;
1586 if (port_id >= nb_ports) {
1587 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1591 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1592 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1596 dev = &rte_eth_devices[port_id];
1597 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1598 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1602 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1604 struct rte_eth_dev *dev;
1606 if (port_id >= nb_ports) {
1607 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1611 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1612 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1616 dev = &rte_eth_devices[port_id];
1617 /* High water, low water validation are device specific */
1618 if (*dev->dev_ops->priority_flow_ctrl_set)
1619 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1624 rte_eth_dev_rss_reta_update(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
1626 struct rte_eth_dev *dev;
1630 if (port_id >= nb_ports) {
1631 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1635 /* Invalid mask bit(s) setting */
1636 if ((reta_conf->mask_lo == 0) && (reta_conf->mask_hi == 0)) {
1637 PMD_DEBUG_TRACE("Invalid update mask bits for port=%d\n",port_id);
1641 dev = &rte_eth_devices[port_id];
1642 max_rxq = (dev->data->nb_rx_queues <= ETH_RSS_RETA_MAX_QUEUE) ?
1643 dev->data->nb_rx_queues : ETH_RSS_RETA_MAX_QUEUE;
1644 if (reta_conf->mask_lo != 0) {
1645 for (i = 0; i < ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
1646 if ((reta_conf->mask_lo & (1ULL << i)) &&
1647 (reta_conf->reta[i] >= max_rxq)) {
1648 PMD_DEBUG_TRACE("RETA hash index output"
1649 "configration for port=%d,invalid"
1650 "queue=%d\n",port_id,reta_conf->reta[i]);
1657 if (reta_conf->mask_hi != 0) {
1658 for (i = 0; i< ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
1659 j = (uint8_t)(i + ETH_RSS_RETA_NUM_ENTRIES/2);
1661 /* Check if the max entry >= 128 */
1662 if ((reta_conf->mask_hi & (1ULL << i)) &&
1663 (reta_conf->reta[j] >= max_rxq)) {
1664 PMD_DEBUG_TRACE("RETA hash index output"
1665 "configration for port=%d,invalid"
1666 "queue=%d\n",port_id,reta_conf->reta[j]);
1673 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
1674 return (*dev->dev_ops->reta_update)(dev, reta_conf);
1678 rte_eth_dev_rss_reta_query(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
1680 struct rte_eth_dev *dev;
1682 if (port_id >= nb_ports) {
1683 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1687 if((reta_conf->mask_lo == 0) && (reta_conf->mask_hi == 0)) {
1688 PMD_DEBUG_TRACE("Invalid update mask bits for the port=%d\n",port_id);
1692 dev = &rte_eth_devices[port_id];
1693 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
1694 return (*dev->dev_ops->reta_query)(dev, reta_conf);
1698 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
1700 struct rte_eth_dev *dev;
1701 uint16_t rss_hash_protos;
1703 if (port_id >= nb_ports) {
1704 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1707 rss_hash_protos = rss_conf->rss_hf;
1708 if ((rss_hash_protos != 0) &&
1709 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
1710 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
1714 dev = &rte_eth_devices[port_id];
1715 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
1716 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
1720 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
1721 struct rte_eth_rss_conf *rss_conf)
1723 struct rte_eth_dev *dev;
1725 if (port_id >= nb_ports) {
1726 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1729 dev = &rte_eth_devices[port_id];
1730 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
1731 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
1735 rte_eth_led_on(uint8_t port_id)
1737 struct rte_eth_dev *dev;
1739 if (port_id >= nb_ports) {
1740 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1744 dev = &rte_eth_devices[port_id];
1745 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
1746 return ((*dev->dev_ops->dev_led_on)(dev));
1750 rte_eth_led_off(uint8_t port_id)
1752 struct rte_eth_dev *dev;
1754 if (port_id >= nb_ports) {
1755 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1759 dev = &rte_eth_devices[port_id];
1760 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
1761 return ((*dev->dev_ops->dev_led_off)(dev));
1765 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
1769 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
1771 struct rte_eth_dev_info dev_info;
1772 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1775 rte_eth_dev_info_get(port_id, &dev_info);
1777 for (i = 0; i < dev_info.max_mac_addrs; i++)
1778 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
1784 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
1787 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
1790 struct rte_eth_dev *dev;
1794 if (port_id >= nb_ports) {
1795 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1798 dev = &rte_eth_devices[port_id];
1799 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
1801 if (is_zero_ether_addr(addr)) {
1802 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
1806 if (pool >= ETH_64_POOLS) {
1807 PMD_DEBUG_TRACE("pool id must be 0-%d\n",ETH_64_POOLS - 1);
1811 index = get_mac_addr_index(port_id, addr);
1813 index = get_mac_addr_index(port_id, &null_mac_addr);
1815 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
1820 pool_mask = dev->data->mac_pool_sel[index];
1822 /* Check if both MAC address and pool is alread there, and do nothing */
1823 if (pool_mask & (1ULL << pool))
1828 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
1830 /* Update address in NIC data structure */
1831 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
1833 /* Update pool bitmap in NIC data structure */
1834 dev->data->mac_pool_sel[index] |= (1ULL << pool);
1840 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
1842 struct rte_eth_dev *dev;
1845 if (port_id >= nb_ports) {
1846 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1849 dev = &rte_eth_devices[port_id];
1850 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
1852 index = get_mac_addr_index(port_id, addr);
1854 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
1855 return (-EADDRINUSE);
1856 } else if (index < 0)
1857 return 0; /* Do nothing if address wasn't found */
1860 (*dev->dev_ops->mac_addr_remove)(dev, index);
1862 /* Update address in NIC data structure */
1863 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
1869 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
1870 uint16_t rx_mode, uint8_t on)
1873 struct rte_eth_dev *dev;
1874 struct rte_eth_dev_info dev_info;
1876 if (port_id >= nb_ports) {
1877 PMD_DEBUG_TRACE("set VF RX mode:Invalid port_id=%d\n",
1882 dev = &rte_eth_devices[port_id];
1883 rte_eth_dev_info_get(port_id, &dev_info);
1885 num_vfs = dev_info.max_vfs;
1888 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
1893 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
1896 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
1897 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
1901 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
1905 get_hash_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
1907 struct rte_eth_dev_info dev_info;
1908 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1911 rte_eth_dev_info_get(port_id, &dev_info);
1912 if (!dev->data->hash_mac_addrs)
1915 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
1916 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
1917 ETHER_ADDR_LEN) == 0)
1924 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
1929 struct rte_eth_dev *dev;
1931 if (port_id >= nb_ports) {
1932 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
1937 dev = &rte_eth_devices[port_id];
1938 if (is_zero_ether_addr(addr)) {
1939 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
1944 index = get_hash_mac_addr_index(port_id, addr);
1945 /* Check if it's already there, and do nothing */
1946 if ((index >= 0) && (on))
1951 PMD_DEBUG_TRACE("port %d: the MAC address was not"
1952 "set in UTA\n", port_id);
1956 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
1958 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
1964 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
1965 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
1967 /* Update address in NIC data structure */
1969 ether_addr_copy(addr,
1970 &dev->data->hash_mac_addrs[index]);
1972 ether_addr_copy(&null_mac_addr,
1973 &dev->data->hash_mac_addrs[index]);
1980 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
1982 struct rte_eth_dev *dev;
1984 if (port_id >= nb_ports) {
1985 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
1990 dev = &rte_eth_devices[port_id];
1992 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
1993 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
1997 rte_eth_dev_set_vf_rx(uint8_t port_id,uint16_t vf, uint8_t on)
2000 struct rte_eth_dev *dev;
2001 struct rte_eth_dev_info dev_info;
2003 if (port_id >= nb_ports) {
2004 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2008 dev = &rte_eth_devices[port_id];
2009 rte_eth_dev_info_get(port_id, &dev_info);
2011 num_vfs = dev_info.max_vfs;
2014 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2018 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2019 return (*dev->dev_ops->set_vf_rx)(dev, vf,on);
2023 rte_eth_dev_set_vf_tx(uint8_t port_id,uint16_t vf, uint8_t on)
2026 struct rte_eth_dev *dev;
2027 struct rte_eth_dev_info dev_info;
2029 if (port_id >= nb_ports) {
2030 PMD_DEBUG_TRACE("set pool tx:Invalid port_id=%d\n", port_id);
2034 dev = &rte_eth_devices[port_id];
2035 rte_eth_dev_info_get(port_id, &dev_info);
2037 num_vfs = dev_info.max_vfs;
2040 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2044 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2045 return (*dev->dev_ops->set_vf_tx)(dev, vf,on);
2049 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2050 uint64_t vf_mask,uint8_t vlan_on)
2052 struct rte_eth_dev *dev;
2054 if (port_id >= nb_ports) {
2055 PMD_DEBUG_TRACE("VF VLAN filter:invalid port id=%d\n",
2059 dev = &rte_eth_devices[port_id];
2061 if(vlan_id > ETHER_MAX_VLAN_ID)
2063 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2069 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2073 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2074 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2079 rte_eth_mirror_rule_set(uint8_t port_id,
2080 struct rte_eth_vmdq_mirror_conf *mirror_conf,
2081 uint8_t rule_id, uint8_t on)
2083 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2085 if (port_id >= nb_ports) {
2086 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2090 if (mirror_conf->rule_type_mask == 0) {
2091 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2095 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2096 PMD_DEBUG_TRACE("Invalid dst pool, pool id must"
2097 "be 0-%d\n",ETH_64_POOLS - 1);
2101 if ((mirror_conf->rule_type_mask & ETH_VMDQ_POOL_MIRROR) &&
2102 (mirror_conf->pool_mask == 0)) {
2103 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not"
2108 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2110 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2111 ETH_VMDQ_NUM_MIRROR_RULE - 1);
2115 dev = &rte_eth_devices[port_id];
2116 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2118 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2122 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2124 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2126 if (port_id >= nb_ports) {
2127 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2131 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2133 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2134 ETH_VMDQ_NUM_MIRROR_RULE-1);
2138 dev = &rte_eth_devices[port_id];
2139 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2141 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2144 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2146 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2147 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2149 struct rte_eth_dev *dev;
2151 if (port_id >= nb_ports) {
2152 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2155 dev = &rte_eth_devices[port_id];
2156 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, -ENOTSUP);
2157 if (queue_id >= dev->data->nb_rx_queues) {
2158 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2161 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2166 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2167 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2169 struct rte_eth_dev *dev;
2171 if (port_id >= nb_ports) {
2172 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2175 dev = &rte_eth_devices[port_id];
2177 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, -ENOTSUP);
2178 if (queue_id >= dev->data->nb_tx_queues) {
2179 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2182 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2187 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2189 struct rte_eth_dev *dev;
2191 if (port_id >= nb_ports) {
2192 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2195 dev = &rte_eth_devices[port_id];
2196 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, -ENOTSUP);
2197 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2201 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2203 struct rte_eth_dev *dev;
2205 if (port_id >= nb_ports) {
2206 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2209 dev = &rte_eth_devices[port_id];
2210 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2211 return (*dev->dev_ops->rx_descriptor_done)( \
2212 dev->data->rx_queues[queue_id], offset);
2217 rte_eth_dev_callback_register(uint8_t port_id,
2218 enum rte_eth_event_type event,
2219 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2221 struct rte_eth_dev *dev;
2222 struct rte_eth_dev_callback *user_cb;
2226 if (port_id >= nb_ports) {
2227 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2231 dev = &rte_eth_devices[port_id];
2232 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2234 TAILQ_FOREACH(user_cb, &(dev->callbacks), next) {
2235 if (user_cb->cb_fn == cb_fn &&
2236 user_cb->cb_arg == cb_arg &&
2237 user_cb->event == event) {
2242 /* create a new callback. */
2243 if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2244 sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
2245 user_cb->cb_fn = cb_fn;
2246 user_cb->cb_arg = cb_arg;
2247 user_cb->event = event;
2248 TAILQ_INSERT_TAIL(&(dev->callbacks), user_cb, next);
2251 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2252 return ((user_cb == NULL) ? -ENOMEM : 0);
2256 rte_eth_dev_callback_unregister(uint8_t port_id,
2257 enum rte_eth_event_type event,
2258 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2261 struct rte_eth_dev *dev;
2262 struct rte_eth_dev_callback *cb, *next;
2266 if (port_id >= nb_ports) {
2267 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2271 dev = &rte_eth_devices[port_id];
2272 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2275 for (cb = TAILQ_FIRST(&dev->callbacks); cb != NULL; cb = next) {
2277 next = TAILQ_NEXT(cb, next);
2279 if (cb->cb_fn != cb_fn || cb->event != event ||
2280 (cb->cb_arg != (void *)-1 &&
2281 cb->cb_arg != cb_arg))
2285 * if this callback is not executing right now,
2288 if (cb->active == 0) {
2289 TAILQ_REMOVE(&(dev->callbacks), cb, next);
2296 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2301 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2302 enum rte_eth_event_type event)
2304 struct rte_eth_dev_callback *cb_lst;
2305 struct rte_eth_dev_callback dev_cb;
2307 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2308 TAILQ_FOREACH(cb_lst, &(dev->callbacks), next) {
2309 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2313 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2314 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2316 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2319 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2321 #ifdef RTE_NIC_BYPASS
2322 int rte_eth_dev_bypass_init(uint8_t port_id)
2324 struct rte_eth_dev *dev;
2326 if (port_id >= nb_ports) {
2327 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2331 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2332 PMD_DEBUG_TRACE("Invalid port device\n");
2336 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2337 (*dev->dev_ops->bypass_init)(dev);
2342 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *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");
2355 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2356 (*dev->dev_ops->bypass_state_show)(dev, state);
2361 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2363 struct rte_eth_dev *dev;
2365 if (port_id >= nb_ports) {
2366 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2370 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2371 PMD_DEBUG_TRACE("Invalid port device\n");
2375 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2376 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2381 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2383 struct rte_eth_dev *dev;
2385 if (port_id >= nb_ports) {
2386 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2390 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2391 PMD_DEBUG_TRACE("Invalid port device\n");
2395 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2396 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2401 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2403 struct rte_eth_dev *dev;
2405 if (port_id >= nb_ports) {
2406 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2410 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2411 PMD_DEBUG_TRACE("Invalid port device\n");
2415 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2416 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2421 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2423 struct rte_eth_dev *dev;
2425 if (port_id >= nb_ports) {
2426 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2430 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2431 PMD_DEBUG_TRACE("Invalid port device\n");
2435 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2436 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2441 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2443 struct rte_eth_dev *dev;
2445 if (port_id >= nb_ports) {
2446 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2450 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2451 PMD_DEBUG_TRACE("Invalid port device\n");
2455 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2456 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2461 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2463 struct rte_eth_dev *dev;
2465 if (port_id >= nb_ports) {
2466 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2470 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2471 PMD_DEBUG_TRACE("Invalid port device\n");
2475 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2476 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2481 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2483 struct rte_eth_dev *dev;
2485 if (port_id >= nb_ports) {
2486 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2490 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2491 PMD_DEBUG_TRACE("Invalid port device\n");
2495 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2496 (*dev->dev_ops->bypass_wd_reset)(dev);