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);
768 if (dev->data->dev_started != 0) {
769 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
770 " already started\n",
775 diag = (*dev->dev_ops->dev_start)(dev);
777 dev->data->dev_started = 1;
781 rte_eth_dev_config_restore(port_id);
787 rte_eth_dev_stop(uint8_t port_id)
789 struct rte_eth_dev *dev;
791 /* This function is only safe when called from the primary process
792 * in a multi-process setup*/
793 PROC_PRIMARY_OR_RET();
795 if (port_id >= nb_ports) {
796 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
799 dev = &rte_eth_devices[port_id];
801 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
803 if (dev->data->dev_started == 0) {
804 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
805 " already stopped\n",
810 dev->data->dev_started = 0;
811 (*dev->dev_ops->dev_stop)(dev);
815 rte_eth_dev_close(uint8_t port_id)
817 struct rte_eth_dev *dev;
819 /* This function is only safe when called from the primary process
820 * in a multi-process setup*/
821 PROC_PRIMARY_OR_RET();
823 if (port_id >= nb_ports) {
824 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
828 dev = &rte_eth_devices[port_id];
830 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
831 dev->data->dev_started = 0;
832 (*dev->dev_ops->dev_close)(dev);
836 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
837 uint16_t nb_rx_desc, unsigned int socket_id,
838 const struct rte_eth_rxconf *rx_conf,
839 struct rte_mempool *mp)
841 struct rte_eth_dev *dev;
842 struct rte_pktmbuf_pool_private *mbp_priv;
843 struct rte_eth_dev_info dev_info;
845 /* This function is only safe when called from the primary process
846 * in a multi-process setup*/
847 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
849 if (port_id >= nb_ports) {
850 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
853 dev = &rte_eth_devices[port_id];
854 if (rx_queue_id >= dev->data->nb_rx_queues) {
855 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
859 if (dev->data->dev_started) {
861 "port %d must be stopped to allow configuration\n", port_id);
865 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
866 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
869 * Check the size of the mbuf data buffer.
870 * This value must be provided in the private data of the memory pool.
871 * First check that the memory pool has a valid private data.
873 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
874 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
875 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
876 mp->name, (int) mp->private_data_size,
877 (int) sizeof(struct rte_pktmbuf_pool_private));
880 mbp_priv = rte_mempool_get_priv(mp);
881 if ((uint32_t) (mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM) <
882 dev_info.min_rx_bufsize) {
883 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
884 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
887 (int)mbp_priv->mbuf_data_room_size,
888 (int)(RTE_PKTMBUF_HEADROOM +
889 dev_info.min_rx_bufsize),
890 (int)RTE_PKTMBUF_HEADROOM,
891 (int)dev_info.min_rx_bufsize);
895 return (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
896 socket_id, rx_conf, mp);
900 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
901 uint16_t nb_tx_desc, unsigned int socket_id,
902 const struct rte_eth_txconf *tx_conf)
904 struct rte_eth_dev *dev;
906 /* This function is only safe when called from the primary process
907 * in a multi-process setup*/
908 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
910 if (port_id >= RTE_MAX_ETHPORTS || port_id >= nb_ports) {
911 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
914 dev = &rte_eth_devices[port_id];
915 if (tx_queue_id >= dev->data->nb_tx_queues) {
916 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
920 if (dev->data->dev_started) {
922 "port %d must be stopped to allow configuration\n", port_id);
926 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
927 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
932 rte_eth_promiscuous_enable(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_enable);
943 (*dev->dev_ops->promiscuous_enable)(dev);
944 dev->data->promiscuous = 1;
948 rte_eth_promiscuous_disable(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);
956 dev = &rte_eth_devices[port_id];
958 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
959 dev->data->promiscuous = 0;
960 (*dev->dev_ops->promiscuous_disable)(dev);
964 rte_eth_promiscuous_get(uint8_t port_id)
966 struct rte_eth_dev *dev;
968 if (port_id >= nb_ports) {
969 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
973 dev = &rte_eth_devices[port_id];
974 return dev->data->promiscuous;
978 rte_eth_allmulticast_enable(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_enable);
989 (*dev->dev_ops->allmulticast_enable)(dev);
990 dev->data->all_multicast = 1;
994 rte_eth_allmulticast_disable(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);
1002 dev = &rte_eth_devices[port_id];
1004 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1005 dev->data->all_multicast = 0;
1006 (*dev->dev_ops->allmulticast_disable)(dev);
1010 rte_eth_allmulticast_get(uint8_t port_id)
1012 struct rte_eth_dev *dev;
1014 if (port_id >= nb_ports) {
1015 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1019 dev = &rte_eth_devices[port_id];
1020 return dev->data->all_multicast;
1024 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1025 struct rte_eth_link *link)
1027 struct rte_eth_link *dst = link;
1028 struct rte_eth_link *src = &(dev->data->dev_link);
1030 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1031 *(uint64_t *)src) == 0)
1038 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1040 struct rte_eth_dev *dev;
1042 if (port_id >= nb_ports) {
1043 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1046 dev = &rte_eth_devices[port_id];
1047 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1049 if (dev->data->dev_conf.intr_conf.lsc != 0)
1050 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1052 (*dev->dev_ops->link_update)(dev, 1);
1053 *eth_link = dev->data->dev_link;
1058 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1060 struct rte_eth_dev *dev;
1062 if (port_id >= nb_ports) {
1063 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1066 dev = &rte_eth_devices[port_id];
1067 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1069 if (dev->data->dev_conf.intr_conf.lsc != 0)
1070 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1072 (*dev->dev_ops->link_update)(dev, 0);
1073 *eth_link = dev->data->dev_link;
1078 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1080 struct rte_eth_dev *dev;
1082 if (port_id >= nb_ports) {
1083 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1086 dev = &rte_eth_devices[port_id];
1087 memset(stats, 0, sizeof(*stats));
1089 FUNC_PTR_OR_RET(*dev->dev_ops->stats_get);
1090 (*dev->dev_ops->stats_get)(dev, stats);
1091 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1095 rte_eth_stats_reset(uint8_t port_id)
1097 struct rte_eth_dev *dev;
1099 if (port_id >= nb_ports) {
1100 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1103 dev = &rte_eth_devices[port_id];
1105 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1106 (*dev->dev_ops->stats_reset)(dev);
1111 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1114 struct rte_eth_dev *dev;
1116 if (port_id >= nb_ports) {
1117 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1120 dev = &rte_eth_devices[port_id];
1122 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1123 return (*dev->dev_ops->queue_stats_mapping_set)
1124 (dev, queue_id, stat_idx, is_rx);
1129 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1132 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1138 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1141 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1147 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1149 struct rte_eth_dev *dev;
1151 if (port_id >= nb_ports) {
1152 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1155 dev = &rte_eth_devices[port_id];
1157 /* Default device offload capabilities to zero */
1158 dev_info->rx_offload_capa = 0;
1159 dev_info->tx_offload_capa = 0;
1160 dev_info->if_index = 0;
1161 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1162 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1163 dev_info->pci_dev = dev->pci_dev;
1165 dev_info->driver_name = dev->driver->pci_drv.name;
1169 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1171 struct rte_eth_dev *dev;
1173 if (port_id >= nb_ports) {
1174 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1177 dev = &rte_eth_devices[port_id];
1178 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1182 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1184 struct rte_eth_dev *dev;
1186 if (port_id >= nb_ports) {
1187 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1190 dev = &rte_eth_devices[port_id];
1191 if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1192 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1196 if (vlan_id > 4095) {
1197 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1198 port_id, (unsigned) vlan_id);
1201 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1202 (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1207 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1209 struct rte_eth_dev *dev;
1211 if (port_id >= nb_ports) {
1212 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1216 dev = &rte_eth_devices[port_id];
1217 if (rx_queue_id >= dev->data->nb_rx_queues) {
1218 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1222 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1223 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1229 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1231 struct rte_eth_dev *dev;
1233 if (port_id >= nb_ports) {
1234 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1238 dev = &rte_eth_devices[port_id];
1239 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1240 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1246 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1248 struct rte_eth_dev *dev;
1253 if (port_id >= nb_ports) {
1254 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1258 dev = &rte_eth_devices[port_id];
1260 /*check which option changed by application*/
1261 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1262 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1264 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1265 mask |= ETH_VLAN_STRIP_MASK;
1268 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1269 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1271 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1272 mask |= ETH_VLAN_FILTER_MASK;
1275 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1276 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1278 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1279 mask |= ETH_VLAN_EXTEND_MASK;
1286 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1287 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1293 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1295 struct rte_eth_dev *dev;
1298 if (port_id >= nb_ports) {
1299 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1303 dev = &rte_eth_devices[port_id];
1305 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1306 ret |= ETH_VLAN_STRIP_OFFLOAD ;
1308 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1309 ret |= ETH_VLAN_FILTER_OFFLOAD ;
1311 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1312 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
1319 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1320 struct rte_fdir_filter *fdir_filter,
1323 struct rte_eth_dev *dev;
1325 if (port_id >= nb_ports) {
1326 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1330 dev = &rte_eth_devices[port_id];
1332 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1333 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1334 port_id, dev->data->dev_conf.fdir_conf.mode);
1338 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1339 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1340 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1341 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1342 "None l4type, source & destinations ports " \
1343 "should be null!\n");
1347 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1348 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1353 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1354 struct rte_fdir_filter *fdir_filter,
1357 struct rte_eth_dev *dev;
1359 if (port_id >= nb_ports) {
1360 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1364 dev = &rte_eth_devices[port_id];
1366 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1367 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1368 port_id, dev->data->dev_conf.fdir_conf.mode);
1372 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1373 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1374 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1375 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1376 "None l4type, source & destinations ports " \
1377 "should be null!\n");
1381 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
1382 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
1388 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
1389 struct rte_fdir_filter *fdir_filter)
1391 struct rte_eth_dev *dev;
1393 if (port_id >= nb_ports) {
1394 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1398 dev = &rte_eth_devices[port_id];
1400 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1401 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1402 port_id, dev->data->dev_conf.fdir_conf.mode);
1406 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1407 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1408 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1409 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1410 "None l4type source & destinations ports " \
1411 "should be null!\n");
1415 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
1416 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
1420 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
1422 struct rte_eth_dev *dev;
1424 if (port_id >= nb_ports) {
1425 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1429 dev = &rte_eth_devices[port_id];
1430 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1431 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1435 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
1437 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
1442 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
1443 struct rte_fdir_filter *fdir_filter,
1444 uint16_t soft_id, uint8_t queue,
1447 struct rte_eth_dev *dev;
1449 if (port_id >= nb_ports) {
1450 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1454 dev = &rte_eth_devices[port_id];
1456 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1457 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1458 port_id, dev->data->dev_conf.fdir_conf.mode);
1462 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1463 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1464 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1465 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1466 "None l4type, source & destinations ports " \
1467 "should be null!\n");
1471 /* For now IPv6 is not supported with perfect filter */
1472 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1475 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
1476 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
1482 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
1483 struct rte_fdir_filter *fdir_filter,
1484 uint16_t soft_id, uint8_t queue,
1487 struct rte_eth_dev *dev;
1489 if (port_id >= nb_ports) {
1490 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1494 dev = &rte_eth_devices[port_id];
1496 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1497 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1498 port_id, dev->data->dev_conf.fdir_conf.mode);
1502 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1503 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1504 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1505 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1506 "None l4type, source & destinations ports " \
1507 "should be null!\n");
1511 /* For now IPv6 is not supported with perfect filter */
1512 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1515 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
1516 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
1517 soft_id, queue, drop);
1521 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
1522 struct rte_fdir_filter *fdir_filter,
1525 struct rte_eth_dev *dev;
1527 if (port_id >= nb_ports) {
1528 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1532 dev = &rte_eth_devices[port_id];
1534 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1535 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1536 port_id, dev->data->dev_conf.fdir_conf.mode);
1540 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1541 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1542 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1543 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1544 "None l4type, source & destinations ports " \
1545 "should be null!\n");
1549 /* For now IPv6 is not supported with perfect filter */
1550 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1553 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
1554 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
1559 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
1561 struct rte_eth_dev *dev;
1563 if (port_id >= nb_ports) {
1564 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1568 dev = &rte_eth_devices[port_id];
1569 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1570 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1574 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
1575 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
1579 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1581 struct rte_eth_dev *dev;
1583 if (port_id >= nb_ports) {
1584 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1588 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1589 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1593 dev = &rte_eth_devices[port_id];
1594 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1595 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1599 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1601 struct rte_eth_dev *dev;
1603 if (port_id >= nb_ports) {
1604 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1608 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1609 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1613 dev = &rte_eth_devices[port_id];
1614 /* High water, low water validation are device specific */
1615 if (*dev->dev_ops->priority_flow_ctrl_set)
1616 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1621 rte_eth_dev_rss_reta_update(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
1623 struct rte_eth_dev *dev;
1627 if (port_id >= nb_ports) {
1628 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1632 /* Invalid mask bit(s) setting */
1633 if ((reta_conf->mask_lo == 0) && (reta_conf->mask_hi == 0)) {
1634 PMD_DEBUG_TRACE("Invalid update mask bits for port=%d\n",port_id);
1638 dev = &rte_eth_devices[port_id];
1639 max_rxq = (dev->data->nb_rx_queues <= ETH_RSS_RETA_MAX_QUEUE) ?
1640 dev->data->nb_rx_queues : ETH_RSS_RETA_MAX_QUEUE;
1641 if (reta_conf->mask_lo != 0) {
1642 for (i = 0; i < ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
1643 if ((reta_conf->mask_lo & (1ULL << i)) &&
1644 (reta_conf->reta[i] >= 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[i]);
1654 if (reta_conf->mask_hi != 0) {
1655 for (i = 0; i< ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
1656 j = (uint8_t)(i + ETH_RSS_RETA_NUM_ENTRIES/2);
1658 /* Check if the max entry >= 128 */
1659 if ((reta_conf->mask_hi & (1ULL << i)) &&
1660 (reta_conf->reta[j] >= max_rxq)) {
1661 PMD_DEBUG_TRACE("RETA hash index output"
1662 "configration for port=%d,invalid"
1663 "queue=%d\n",port_id,reta_conf->reta[j]);
1670 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
1671 return (*dev->dev_ops->reta_update)(dev, reta_conf);
1675 rte_eth_dev_rss_reta_query(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
1677 struct rte_eth_dev *dev;
1679 if (port_id >= nb_ports) {
1680 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1684 if((reta_conf->mask_lo == 0) && (reta_conf->mask_hi == 0)) {
1685 PMD_DEBUG_TRACE("Invalid update mask bits for the port=%d\n",port_id);
1689 dev = &rte_eth_devices[port_id];
1690 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
1691 return (*dev->dev_ops->reta_query)(dev, reta_conf);
1695 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
1697 struct rte_eth_dev *dev;
1698 uint16_t rss_hash_protos;
1700 if (port_id >= nb_ports) {
1701 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1704 rss_hash_protos = rss_conf->rss_hf;
1705 if ((rss_hash_protos != 0) &&
1706 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
1707 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
1711 dev = &rte_eth_devices[port_id];
1712 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
1713 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
1717 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
1718 struct rte_eth_rss_conf *rss_conf)
1720 struct rte_eth_dev *dev;
1722 if (port_id >= nb_ports) {
1723 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1726 dev = &rte_eth_devices[port_id];
1727 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
1728 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
1732 rte_eth_led_on(uint8_t port_id)
1734 struct rte_eth_dev *dev;
1736 if (port_id >= nb_ports) {
1737 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1741 dev = &rte_eth_devices[port_id];
1742 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
1743 return ((*dev->dev_ops->dev_led_on)(dev));
1747 rte_eth_led_off(uint8_t port_id)
1749 struct rte_eth_dev *dev;
1751 if (port_id >= nb_ports) {
1752 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1756 dev = &rte_eth_devices[port_id];
1757 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
1758 return ((*dev->dev_ops->dev_led_off)(dev));
1762 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
1766 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
1768 struct rte_eth_dev_info dev_info;
1769 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1772 rte_eth_dev_info_get(port_id, &dev_info);
1774 for (i = 0; i < dev_info.max_mac_addrs; i++)
1775 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
1781 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
1784 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
1787 struct rte_eth_dev *dev;
1791 if (port_id >= nb_ports) {
1792 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1795 dev = &rte_eth_devices[port_id];
1796 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
1798 if (is_zero_ether_addr(addr)) {
1799 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
1803 if (pool >= ETH_64_POOLS) {
1804 PMD_DEBUG_TRACE("pool id must be 0-%d\n",ETH_64_POOLS - 1);
1808 index = get_mac_addr_index(port_id, addr);
1810 index = get_mac_addr_index(port_id, &null_mac_addr);
1812 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
1817 pool_mask = dev->data->mac_pool_sel[index];
1819 /* Check if both MAC address and pool is alread there, and do nothing */
1820 if (pool_mask & (1ULL << pool))
1825 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
1827 /* Update address in NIC data structure */
1828 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
1830 /* Update pool bitmap in NIC data structure */
1831 dev->data->mac_pool_sel[index] |= (1ULL << pool);
1837 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
1839 struct rte_eth_dev *dev;
1842 if (port_id >= nb_ports) {
1843 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1846 dev = &rte_eth_devices[port_id];
1847 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
1849 index = get_mac_addr_index(port_id, addr);
1851 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
1852 return (-EADDRINUSE);
1853 } else if (index < 0)
1854 return 0; /* Do nothing if address wasn't found */
1857 (*dev->dev_ops->mac_addr_remove)(dev, index);
1859 /* Update address in NIC data structure */
1860 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
1866 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
1867 uint16_t rx_mode, uint8_t on)
1870 struct rte_eth_dev *dev;
1871 struct rte_eth_dev_info dev_info;
1873 if (port_id >= nb_ports) {
1874 PMD_DEBUG_TRACE("set VF RX mode:Invalid port_id=%d\n",
1879 dev = &rte_eth_devices[port_id];
1880 rte_eth_dev_info_get(port_id, &dev_info);
1882 num_vfs = dev_info.max_vfs;
1885 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
1890 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
1893 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
1894 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
1898 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
1902 get_hash_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
1904 struct rte_eth_dev_info dev_info;
1905 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1908 rte_eth_dev_info_get(port_id, &dev_info);
1909 if (!dev->data->hash_mac_addrs)
1912 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
1913 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
1914 ETHER_ADDR_LEN) == 0)
1921 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
1926 struct rte_eth_dev *dev;
1928 if (port_id >= nb_ports) {
1929 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
1934 dev = &rte_eth_devices[port_id];
1935 if (is_zero_ether_addr(addr)) {
1936 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
1941 index = get_hash_mac_addr_index(port_id, addr);
1942 /* Check if it's already there, and do nothing */
1943 if ((index >= 0) && (on))
1948 PMD_DEBUG_TRACE("port %d: the MAC address was not"
1949 "set in UTA\n", port_id);
1953 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
1955 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
1961 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
1962 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
1964 /* Update address in NIC data structure */
1966 ether_addr_copy(addr,
1967 &dev->data->hash_mac_addrs[index]);
1969 ether_addr_copy(&null_mac_addr,
1970 &dev->data->hash_mac_addrs[index]);
1977 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
1979 struct rte_eth_dev *dev;
1981 if (port_id >= nb_ports) {
1982 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
1987 dev = &rte_eth_devices[port_id];
1989 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
1990 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
1994 rte_eth_dev_set_vf_rx(uint8_t port_id,uint16_t vf, uint8_t on)
1997 struct rte_eth_dev *dev;
1998 struct rte_eth_dev_info dev_info;
2000 if (port_id >= nb_ports) {
2001 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2005 dev = &rte_eth_devices[port_id];
2006 rte_eth_dev_info_get(port_id, &dev_info);
2008 num_vfs = dev_info.max_vfs;
2011 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2015 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2016 return (*dev->dev_ops->set_vf_rx)(dev, vf,on);
2020 rte_eth_dev_set_vf_tx(uint8_t port_id,uint16_t vf, uint8_t on)
2023 struct rte_eth_dev *dev;
2024 struct rte_eth_dev_info dev_info;
2026 if (port_id >= nb_ports) {
2027 PMD_DEBUG_TRACE("set pool tx:Invalid port_id=%d\n", port_id);
2031 dev = &rte_eth_devices[port_id];
2032 rte_eth_dev_info_get(port_id, &dev_info);
2034 num_vfs = dev_info.max_vfs;
2037 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2041 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2042 return (*dev->dev_ops->set_vf_tx)(dev, vf,on);
2046 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2047 uint64_t vf_mask,uint8_t vlan_on)
2049 struct rte_eth_dev *dev;
2051 if (port_id >= nb_ports) {
2052 PMD_DEBUG_TRACE("VF VLAN filter:invalid port id=%d\n",
2056 dev = &rte_eth_devices[port_id];
2058 if(vlan_id > ETHER_MAX_VLAN_ID)
2060 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2066 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2070 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2071 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2076 rte_eth_mirror_rule_set(uint8_t port_id,
2077 struct rte_eth_vmdq_mirror_conf *mirror_conf,
2078 uint8_t rule_id, uint8_t on)
2080 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2082 if (port_id >= nb_ports) {
2083 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2087 if (mirror_conf->rule_type_mask == 0) {
2088 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2092 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2093 PMD_DEBUG_TRACE("Invalid dst pool, pool id must"
2094 "be 0-%d\n",ETH_64_POOLS - 1);
2098 if ((mirror_conf->rule_type_mask & ETH_VMDQ_POOL_MIRROR) &&
2099 (mirror_conf->pool_mask == 0)) {
2100 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not"
2105 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2107 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2108 ETH_VMDQ_NUM_MIRROR_RULE - 1);
2112 dev = &rte_eth_devices[port_id];
2113 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2115 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2119 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2121 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2123 if (port_id >= nb_ports) {
2124 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2128 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2130 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2131 ETH_VMDQ_NUM_MIRROR_RULE-1);
2135 dev = &rte_eth_devices[port_id];
2136 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2138 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2141 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2143 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2144 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2146 struct rte_eth_dev *dev;
2148 if (port_id >= nb_ports) {
2149 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2152 dev = &rte_eth_devices[port_id];
2153 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, -ENOTSUP);
2154 if (queue_id >= dev->data->nb_rx_queues) {
2155 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2158 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2163 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2164 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2166 struct rte_eth_dev *dev;
2168 if (port_id >= nb_ports) {
2169 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2172 dev = &rte_eth_devices[port_id];
2174 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, -ENOTSUP);
2175 if (queue_id >= dev->data->nb_tx_queues) {
2176 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2179 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2184 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2186 struct rte_eth_dev *dev;
2188 if (port_id >= nb_ports) {
2189 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2192 dev = &rte_eth_devices[port_id];
2193 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, -ENOTSUP);
2194 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2198 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2200 struct rte_eth_dev *dev;
2202 if (port_id >= nb_ports) {
2203 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2206 dev = &rte_eth_devices[port_id];
2207 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2208 return (*dev->dev_ops->rx_descriptor_done)( \
2209 dev->data->rx_queues[queue_id], offset);
2214 rte_eth_dev_callback_register(uint8_t port_id,
2215 enum rte_eth_event_type event,
2216 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2218 struct rte_eth_dev *dev;
2219 struct rte_eth_dev_callback *user_cb;
2223 if (port_id >= nb_ports) {
2224 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2228 dev = &rte_eth_devices[port_id];
2229 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2231 TAILQ_FOREACH(user_cb, &(dev->callbacks), next) {
2232 if (user_cb->cb_fn == cb_fn &&
2233 user_cb->cb_arg == cb_arg &&
2234 user_cb->event == event) {
2239 /* create a new callback. */
2240 if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2241 sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
2242 user_cb->cb_fn = cb_fn;
2243 user_cb->cb_arg = cb_arg;
2244 user_cb->event = event;
2245 TAILQ_INSERT_TAIL(&(dev->callbacks), user_cb, next);
2248 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2249 return ((user_cb == NULL) ? -ENOMEM : 0);
2253 rte_eth_dev_callback_unregister(uint8_t port_id,
2254 enum rte_eth_event_type event,
2255 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2258 struct rte_eth_dev *dev;
2259 struct rte_eth_dev_callback *cb, *next;
2263 if (port_id >= nb_ports) {
2264 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2268 dev = &rte_eth_devices[port_id];
2269 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2272 for (cb = TAILQ_FIRST(&dev->callbacks); cb != NULL; cb = next) {
2274 next = TAILQ_NEXT(cb, next);
2276 if (cb->cb_fn != cb_fn || cb->event != event ||
2277 (cb->cb_arg != (void *)-1 &&
2278 cb->cb_arg != cb_arg))
2282 * if this callback is not executing right now,
2285 if (cb->active == 0) {
2286 TAILQ_REMOVE(&(dev->callbacks), cb, next);
2293 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2298 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2299 enum rte_eth_event_type event)
2301 struct rte_eth_dev_callback *cb_lst;
2302 struct rte_eth_dev_callback dev_cb;
2304 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2305 TAILQ_FOREACH(cb_lst, &(dev->callbacks), next) {
2306 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2310 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2311 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2313 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2316 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2318 #ifdef RTE_NIC_BYPASS
2319 int rte_eth_dev_bypass_init(uint8_t port_id)
2321 struct rte_eth_dev *dev;
2323 if (port_id >= nb_ports) {
2324 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2328 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2329 PMD_DEBUG_TRACE("Invalid port device\n");
2333 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2334 (*dev->dev_ops->bypass_init)(dev);
2339 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2341 struct rte_eth_dev *dev;
2343 if (port_id >= nb_ports) {
2344 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2348 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2349 PMD_DEBUG_TRACE("Invalid port device\n");
2352 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2353 (*dev->dev_ops->bypass_state_show)(dev, state);
2358 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2360 struct rte_eth_dev *dev;
2362 if (port_id >= nb_ports) {
2363 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2367 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2368 PMD_DEBUG_TRACE("Invalid port device\n");
2372 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2373 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2378 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2380 struct rte_eth_dev *dev;
2382 if (port_id >= nb_ports) {
2383 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2387 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2388 PMD_DEBUG_TRACE("Invalid port device\n");
2392 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2393 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2398 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2400 struct rte_eth_dev *dev;
2402 if (port_id >= nb_ports) {
2403 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2407 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2408 PMD_DEBUG_TRACE("Invalid port device\n");
2412 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2413 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2418 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2420 struct rte_eth_dev *dev;
2422 if (port_id >= nb_ports) {
2423 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2427 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2428 PMD_DEBUG_TRACE("Invalid port device\n");
2432 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2433 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2438 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2440 struct rte_eth_dev *dev;
2442 if (port_id >= nb_ports) {
2443 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2447 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2448 PMD_DEBUG_TRACE("Invalid port device\n");
2452 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2453 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2458 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2460 struct rte_eth_dev *dev;
2462 if (port_id >= nb_ports) {
2463 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2467 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2468 PMD_DEBUG_TRACE("Invalid port device\n");
2472 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2473 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2478 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2480 struct rte_eth_dev *dev;
2482 if (port_id >= nb_ports) {
2483 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2487 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2488 PMD_DEBUG_TRACE("Invalid port device\n");
2492 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2493 (*dev->dev_ops->bypass_wd_reset)(dev);