4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/types.h>
35 #include <sys/queue.h>
44 #include <netinet/in.h>
46 #include <rte_byteorder.h>
48 #include <rte_debug.h>
49 #include <rte_interrupts.h>
51 #include <rte_memory.h>
52 #include <rte_memcpy.h>
53 #include <rte_memzone.h>
54 #include <rte_launch.h>
55 #include <rte_tailq.h>
57 #include <rte_per_lcore.h>
58 #include <rte_lcore.h>
59 #include <rte_atomic.h>
60 #include <rte_branch_prediction.h>
61 #include <rte_common.h>
63 #include <rte_mempool.h>
64 #include <rte_malloc.h>
66 #include <rte_errno.h>
67 #include <rte_spinlock.h>
68 #include <rte_string_fns.h>
70 #include "rte_ether.h"
71 #include "rte_ethdev.h"
73 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
74 #define PMD_DEBUG_TRACE(fmt, args...) do { \
75 RTE_LOG(ERR, PMD, "%s: " fmt, __func__, ## args); \
78 #define PMD_DEBUG_TRACE(fmt, args...)
81 /* Macros for checking for restricting functions to primary instance only */
82 #define PROC_PRIMARY_OR_ERR_RET(retval) do { \
83 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
84 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
88 #define PROC_PRIMARY_OR_RET() do { \
89 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
90 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
95 /* Macros to check for invlaid function pointers in dev_ops structure */
96 #define FUNC_PTR_OR_ERR_RET(func, retval) do { \
97 if ((func) == NULL) { \
98 PMD_DEBUG_TRACE("Function not supported\n"); \
102 #define FUNC_PTR_OR_RET(func) do { \
103 if ((func) == NULL) { \
104 PMD_DEBUG_TRACE("Function not supported\n"); \
109 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
110 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
111 static struct rte_eth_dev_data *rte_eth_dev_data = NULL;
112 static uint8_t nb_ports = 0;
114 /* spinlock for eth device callbacks */
115 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
117 /* store statistics names and its offset in stats structure */
118 struct rte_eth_xstats_name_off {
119 char name[RTE_ETH_XSTATS_NAME_SIZE];
123 static struct rte_eth_xstats_name_off rte_stats_strings[] = {
124 {"rx_packets", offsetof(struct rte_eth_stats, ipackets)},
125 {"tx_packets", offsetof(struct rte_eth_stats, opackets)},
126 {"rx_bytes", offsetof(struct rte_eth_stats, ibytes)},
127 {"tx_bytes", offsetof(struct rte_eth_stats, obytes)},
128 {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
129 {"rx_missed_errors", offsetof(struct rte_eth_stats, imissed)},
130 {"rx_crc_errors", offsetof(struct rte_eth_stats, ibadcrc)},
131 {"rx_bad_length_errors", offsetof(struct rte_eth_stats, ibadlen)},
132 {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
133 {"alloc_rx_buff_failed", offsetof(struct rte_eth_stats, rx_nombuf)},
134 {"fdir_match", offsetof(struct rte_eth_stats, fdirmatch)},
135 {"fdir_miss", offsetof(struct rte_eth_stats, fdirmiss)},
136 {"tx_flow_control_xon", offsetof(struct rte_eth_stats, tx_pause_xon)},
137 {"rx_flow_control_xon", offsetof(struct rte_eth_stats, rx_pause_xon)},
138 {"tx_flow_control_xoff", offsetof(struct rte_eth_stats, tx_pause_xoff)},
139 {"rx_flow_control_xoff", offsetof(struct rte_eth_stats, rx_pause_xoff)},
141 #define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
143 static struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
144 {"rx_packets", offsetof(struct rte_eth_stats, q_ipackets)},
145 {"rx_bytes", offsetof(struct rte_eth_stats, q_ibytes)},
147 #define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) / \
148 sizeof(rte_rxq_stats_strings[0]))
150 static struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
151 {"tx_packets", offsetof(struct rte_eth_stats, q_opackets)},
152 {"tx_bytes", offsetof(struct rte_eth_stats, q_obytes)},
153 {"tx_errors", offsetof(struct rte_eth_stats, q_errors)},
155 #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) / \
156 sizeof(rte_txq_stats_strings[0]))
160 * The user application callback description.
162 * It contains callback address to be registered by user application,
163 * the pointer to the parameters for callback, and the event type.
165 struct rte_eth_dev_callback {
166 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
167 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
168 void *cb_arg; /**< Parameter for callback */
169 enum rte_eth_event_type event; /**< Interrupt event type */
170 uint32_t active; /**< Callback is executing */
184 rte_eth_dev_data_alloc(void)
186 const unsigned flags = 0;
187 const struct rte_memzone *mz;
189 if (rte_eal_process_type() == RTE_PROC_PRIMARY){
190 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
191 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
192 rte_socket_id(), flags);
194 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
196 rte_panic("Cannot allocate memzone for ethernet port data\n");
198 rte_eth_dev_data = mz->addr;
199 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
200 memset(rte_eth_dev_data, 0,
201 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
204 static struct rte_eth_dev *
205 rte_eth_dev_allocated(const char *name)
209 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
210 if ((rte_eth_devices[i].attached == DEV_ATTACHED) &&
211 strcmp(rte_eth_devices[i].data->name, name) == 0)
212 return &rte_eth_devices[i];
218 rte_eth_dev_find_free_port(void)
222 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
223 if (rte_eth_devices[i].attached == DEV_DETACHED)
226 return RTE_MAX_ETHPORTS;
230 rte_eth_dev_allocate(const char *name)
233 struct rte_eth_dev *eth_dev;
235 port_id = rte_eth_dev_find_free_port();
236 if (port_id == RTE_MAX_ETHPORTS) {
237 PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
241 if (rte_eth_dev_data == NULL)
242 rte_eth_dev_data_alloc();
244 if (rte_eth_dev_allocated(name) != NULL) {
245 PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n", name);
249 eth_dev = &rte_eth_devices[port_id];
250 eth_dev->data = &rte_eth_dev_data[port_id];
251 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
252 eth_dev->data->port_id = port_id;
253 eth_dev->attached = DEV_ATTACHED;
259 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
260 struct rte_pci_device *pci_dev)
262 struct eth_driver *eth_drv;
263 struct rte_eth_dev *eth_dev;
264 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
268 eth_drv = (struct eth_driver *)pci_drv;
270 /* Create unique Ethernet device name using PCI address */
271 snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "%d:%d.%d",
272 pci_dev->addr.bus, pci_dev->addr.devid, pci_dev->addr.function);
274 eth_dev = rte_eth_dev_allocate(ethdev_name);
278 if (rte_eal_process_type() == RTE_PROC_PRIMARY){
279 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
280 eth_drv->dev_private_size,
281 RTE_CACHE_LINE_SIZE);
282 if (eth_dev->data->dev_private == NULL)
283 rte_panic("Cannot allocate memzone for private port data\n");
285 eth_dev->pci_dev = pci_dev;
286 eth_dev->driver = eth_drv;
287 eth_dev->data->rx_mbuf_alloc_failed = 0;
289 /* init user callbacks */
290 TAILQ_INIT(&(eth_dev->link_intr_cbs));
293 * Set the default MTU.
295 eth_dev->data->mtu = ETHER_MTU;
297 /* Invoke PMD device initialization function */
298 diag = (*eth_drv->eth_dev_init)(eth_drv, eth_dev);
302 PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x)"
303 " failed\n", pci_drv->name,
304 (unsigned) pci_dev->id.vendor_id,
305 (unsigned) pci_dev->id.device_id);
306 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
307 rte_free(eth_dev->data->dev_private);
308 eth_dev->attached = DEV_DETACHED;
314 * Register an Ethernet [Poll Mode] driver.
316 * Function invoked by the initialization function of an Ethernet driver
317 * to simultaneously register itself as a PCI driver and as an Ethernet
319 * Invokes the rte_eal_pci_register() function to register the *pci_drv*
320 * structure embedded in the *eth_drv* structure, after having stored the
321 * address of the rte_eth_dev_init() function in the *devinit* field of
322 * the *pci_drv* structure.
323 * During the PCI probing phase, the rte_eth_dev_init() function is
324 * invoked for each PCI [Ethernet device] matching the embedded PCI
325 * identifiers provided by the driver.
328 rte_eth_driver_register(struct eth_driver *eth_drv)
330 eth_drv->pci_drv.devinit = rte_eth_dev_init;
331 rte_eal_pci_register(ð_drv->pci_drv);
335 rte_eth_dev_is_valid_port(uint8_t port_id)
337 if (port_id >= RTE_MAX_ETHPORTS ||
338 rte_eth_devices[port_id].attached != DEV_ATTACHED)
345 rte_eth_dev_socket_id(uint8_t port_id)
347 if (!rte_eth_dev_is_valid_port(port_id))
349 return rte_eth_devices[port_id].pci_dev->numa_node;
353 rte_eth_dev_count(void)
359 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
361 uint16_t old_nb_queues = dev->data->nb_rx_queues;
365 if (dev->data->rx_queues == NULL) { /* first time configuration */
366 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
367 sizeof(dev->data->rx_queues[0]) * nb_queues,
368 RTE_CACHE_LINE_SIZE);
369 if (dev->data->rx_queues == NULL) {
370 dev->data->nb_rx_queues = 0;
373 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
374 dev->post_rx_burst_cbs = rte_zmalloc(
375 "ethdev->post_rx_burst_cbs",
376 sizeof(*dev->post_rx_burst_cbs) * nb_queues,
377 RTE_CACHE_LINE_SIZE);
378 if (dev->post_rx_burst_cbs == NULL) {
379 rte_free(dev->data->rx_queues);
380 dev->data->rx_queues = NULL;
381 dev->data->nb_rx_queues = 0;
386 } else { /* re-configure */
387 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
389 rxq = dev->data->rx_queues;
391 for (i = nb_queues; i < old_nb_queues; i++)
392 (*dev->dev_ops->rx_queue_release)(rxq[i]);
393 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
394 RTE_CACHE_LINE_SIZE);
397 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
398 dev->post_rx_burst_cbs = rte_realloc(
399 dev->post_rx_burst_cbs,
400 sizeof(*dev->post_rx_burst_cbs) *
401 nb_queues, RTE_CACHE_LINE_SIZE);
402 if (dev->post_rx_burst_cbs == NULL)
405 if (nb_queues > old_nb_queues) {
406 uint16_t new_qs = nb_queues - old_nb_queues;
407 memset(rxq + old_nb_queues, 0,
408 sizeof(rxq[0]) * new_qs);
409 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
410 memset(dev->post_rx_burst_cbs + old_nb_queues, 0,
411 sizeof(dev->post_rx_burst_cbs[0]) * new_qs);
415 dev->data->rx_queues = rxq;
418 dev->data->nb_rx_queues = nb_queues;
423 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
425 struct rte_eth_dev *dev;
427 /* This function is only safe when called from the primary process
428 * in a multi-process setup*/
429 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
431 if (!rte_eth_dev_is_valid_port(port_id)) {
432 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
436 dev = &rte_eth_devices[port_id];
437 if (rx_queue_id >= dev->data->nb_rx_queues) {
438 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
442 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
444 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
449 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
451 struct rte_eth_dev *dev;
453 /* This function is only safe when called from the primary process
454 * in a multi-process setup*/
455 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
457 if (!rte_eth_dev_is_valid_port(port_id)) {
458 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
462 dev = &rte_eth_devices[port_id];
463 if (rx_queue_id >= dev->data->nb_rx_queues) {
464 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
468 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
470 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
475 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
477 struct rte_eth_dev *dev;
479 /* This function is only safe when called from the primary process
480 * in a multi-process setup*/
481 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
483 if (!rte_eth_dev_is_valid_port(port_id)) {
484 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
488 dev = &rte_eth_devices[port_id];
489 if (tx_queue_id >= dev->data->nb_tx_queues) {
490 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
494 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
496 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
501 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
503 struct rte_eth_dev *dev;
505 /* This function is only safe when called from the primary process
506 * in a multi-process setup*/
507 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
509 if (!rte_eth_dev_is_valid_port(port_id)) {
510 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
514 dev = &rte_eth_devices[port_id];
515 if (tx_queue_id >= dev->data->nb_tx_queues) {
516 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
520 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
522 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
527 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
529 uint16_t old_nb_queues = dev->data->nb_tx_queues;
533 if (dev->data->tx_queues == NULL) { /* first time configuration */
534 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
535 sizeof(dev->data->tx_queues[0]) * nb_queues,
536 RTE_CACHE_LINE_SIZE);
537 if (dev->data->tx_queues == NULL) {
538 dev->data->nb_tx_queues = 0;
541 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
542 dev->pre_tx_burst_cbs = rte_zmalloc(
543 "ethdev->pre_tx_burst_cbs",
544 sizeof(*dev->pre_tx_burst_cbs) * nb_queues,
545 RTE_CACHE_LINE_SIZE);
546 if (dev->pre_tx_burst_cbs == NULL) {
547 rte_free(dev->data->tx_queues);
548 dev->data->tx_queues = NULL;
549 dev->data->nb_tx_queues = 0;
554 } else { /* re-configure */
555 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
557 txq = dev->data->tx_queues;
559 for (i = nb_queues; i < old_nb_queues; i++)
560 (*dev->dev_ops->tx_queue_release)(txq[i]);
561 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
562 RTE_CACHE_LINE_SIZE);
565 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
566 dev->pre_tx_burst_cbs = rte_realloc(
567 dev->pre_tx_burst_cbs,
568 sizeof(*dev->pre_tx_burst_cbs) *
569 nb_queues, RTE_CACHE_LINE_SIZE);
570 if (dev->pre_tx_burst_cbs == NULL)
573 if (nb_queues > old_nb_queues) {
574 uint16_t new_qs = nb_queues - old_nb_queues;
575 memset(txq + old_nb_queues, 0,
576 sizeof(txq[0]) * new_qs);
577 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
578 memset(dev->pre_tx_burst_cbs + old_nb_queues, 0,
579 sizeof(dev->pre_tx_burst_cbs[0]) * new_qs);
583 dev->data->tx_queues = txq;
586 dev->data->nb_tx_queues = nb_queues;
591 rte_eth_dev_check_vf_rss_rxq_num(uint8_t port_id, uint16_t nb_rx_q)
593 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
597 RTE_ETH_DEV_SRIOV(dev).active =
601 RTE_ETH_DEV_SRIOV(dev).active =
608 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = nb_rx_q;
609 RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx =
610 dev->pci_dev->max_vfs * nb_rx_q;
616 rte_eth_dev_check_mq_mode(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
617 const struct rte_eth_conf *dev_conf)
619 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
621 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
622 /* check multi-queue mode */
623 if ((dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) ||
624 (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB_RSS) ||
625 (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB)) {
626 /* SRIOV only works in VMDq enable mode */
627 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
629 "wrong VMDQ mq_mode rx %u tx %u\n",
631 dev_conf->rxmode.mq_mode,
632 dev_conf->txmode.mq_mode);
636 switch (dev_conf->rxmode.mq_mode) {
637 case ETH_MQ_RX_VMDQ_DCB:
638 case ETH_MQ_RX_VMDQ_DCB_RSS:
639 /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
640 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
642 "unsupported VMDQ mq_mode rx %u\n",
643 port_id, dev_conf->rxmode.mq_mode);
646 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
648 "Rx mq mode is changed from:"
649 "mq_mode %u into VMDQ mq_mode %u\n",
651 dev_conf->rxmode.mq_mode,
652 dev->data->dev_conf.rxmode.mq_mode);
653 case ETH_MQ_RX_VMDQ_RSS:
654 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_RSS;
655 if (nb_rx_q <= RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)
656 if (rte_eth_dev_check_vf_rss_rxq_num(port_id, nb_rx_q) != 0) {
657 PMD_DEBUG_TRACE("ethdev port_id=%d"
658 " SRIOV active, invalid queue"
659 " number for VMDQ RSS, allowed"
660 " value are 1, 2 or 4\n",
665 default: /* ETH_MQ_RX_VMDQ_ONLY or ETH_MQ_RX_NONE */
666 /* if nothing mq mode configure, use default scheme */
667 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
668 if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
669 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
673 switch (dev_conf->txmode.mq_mode) {
674 case ETH_MQ_TX_VMDQ_DCB:
675 /* DCB VMDQ in SRIOV mode, not implement yet */
676 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
678 "unsupported VMDQ mq_mode tx %u\n",
679 port_id, dev_conf->txmode.mq_mode);
681 default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
682 /* if nothing mq mode configure, use default scheme */
683 dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
687 /* check valid queue number */
688 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
689 (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
690 PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
691 "queue number must less equal to %d\n",
692 port_id, RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
696 /* For vmdb+dcb mode check our configuration before we go further */
697 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB) {
698 const struct rte_eth_vmdq_dcb_conf *conf;
700 if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
701 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
703 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
706 conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
707 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
708 conf->nb_queue_pools == ETH_32_POOLS)) {
709 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
710 "nb_queue_pools must be %d or %d\n",
711 port_id, ETH_16_POOLS, ETH_32_POOLS);
715 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
716 const struct rte_eth_vmdq_dcb_tx_conf *conf;
718 if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
719 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
721 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
724 conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
725 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
726 conf->nb_queue_pools == ETH_32_POOLS)) {
727 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
728 "nb_queue_pools != %d or nb_queue_pools "
730 port_id, ETH_16_POOLS, ETH_32_POOLS);
735 /* For DCB mode check our configuration before we go further */
736 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) {
737 const struct rte_eth_dcb_rx_conf *conf;
739 if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
740 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
742 port_id, ETH_DCB_NUM_QUEUES);
745 conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
746 if (! (conf->nb_tcs == ETH_4_TCS ||
747 conf->nb_tcs == ETH_8_TCS)) {
748 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
749 "nb_tcs != %d or nb_tcs "
751 port_id, ETH_4_TCS, ETH_8_TCS);
756 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
757 const struct rte_eth_dcb_tx_conf *conf;
759 if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
760 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
762 port_id, ETH_DCB_NUM_QUEUES);
765 conf = &(dev_conf->tx_adv_conf.dcb_tx_conf);
766 if (! (conf->nb_tcs == ETH_4_TCS ||
767 conf->nb_tcs == ETH_8_TCS)) {
768 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
769 "nb_tcs != %d or nb_tcs "
771 port_id, ETH_4_TCS, ETH_8_TCS);
780 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
781 const struct rte_eth_conf *dev_conf)
783 struct rte_eth_dev *dev;
784 struct rte_eth_dev_info dev_info;
787 /* This function is only safe when called from the primary process
788 * in a multi-process setup*/
789 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
791 if (!rte_eth_dev_is_valid_port(port_id)) {
792 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
796 dev = &rte_eth_devices[port_id];
798 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
799 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
801 if (dev->data->dev_started) {
803 "port %d must be stopped to allow configuration\n", port_id);
808 * Check that the numbers of RX and TX queues are not greater
809 * than the maximum number of RX and TX queues supported by the
812 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
813 if (nb_rx_q > dev_info.max_rx_queues) {
814 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
815 port_id, nb_rx_q, dev_info.max_rx_queues);
819 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
823 if (nb_tx_q > dev_info.max_tx_queues) {
824 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
825 port_id, nb_tx_q, dev_info.max_tx_queues);
829 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
833 /* Copy the dev_conf parameter into the dev structure */
834 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
837 * If link state interrupt is enabled, check that the
838 * device supports it.
840 if (dev_conf->intr_conf.lsc == 1) {
841 const struct rte_pci_driver *pci_drv = &dev->driver->pci_drv;
843 if (!(pci_drv->drv_flags & RTE_PCI_DRV_INTR_LSC)) {
844 PMD_DEBUG_TRACE("driver %s does not support lsc\n",
851 * If jumbo frames are enabled, check that the maximum RX packet
852 * length is supported by the configured device.
854 if (dev_conf->rxmode.jumbo_frame == 1) {
855 if (dev_conf->rxmode.max_rx_pkt_len >
856 dev_info.max_rx_pktlen) {
857 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
858 " > max valid value %u\n",
860 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
861 (unsigned)dev_info.max_rx_pktlen);
864 else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
865 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
866 " < min valid value %u\n",
868 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
869 (unsigned)ETHER_MIN_LEN);
873 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
874 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
875 /* Use default value */
876 dev->data->dev_conf.rxmode.max_rx_pkt_len =
880 /* multipe queue mode checking */
881 diag = rte_eth_dev_check_mq_mode(port_id, nb_rx_q, nb_tx_q, dev_conf);
883 PMD_DEBUG_TRACE("port%d rte_eth_dev_check_mq_mode = %d\n",
889 * Setup new number of RX/TX queues and reconfigure device.
891 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
893 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
898 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
900 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
902 rte_eth_dev_rx_queue_config(dev, 0);
906 diag = (*dev->dev_ops->dev_configure)(dev);
908 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
910 rte_eth_dev_rx_queue_config(dev, 0);
911 rte_eth_dev_tx_queue_config(dev, 0);
919 rte_eth_dev_config_restore(uint8_t port_id)
921 struct rte_eth_dev *dev;
922 struct rte_eth_dev_info dev_info;
923 struct ether_addr addr;
927 dev = &rte_eth_devices[port_id];
929 rte_eth_dev_info_get(port_id, &dev_info);
931 if (RTE_ETH_DEV_SRIOV(dev).active)
932 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
934 /* replay MAC address configuration */
935 for (i = 0; i < dev_info.max_mac_addrs; i++) {
936 addr = dev->data->mac_addrs[i];
938 /* skip zero address */
939 if (is_zero_ether_addr(&addr))
942 /* add address to the hardware */
943 if (*dev->dev_ops->mac_addr_add &&
944 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
945 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
947 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
949 /* exit the loop but not return an error */
954 /* replay promiscuous configuration */
955 if (rte_eth_promiscuous_get(port_id) == 1)
956 rte_eth_promiscuous_enable(port_id);
957 else if (rte_eth_promiscuous_get(port_id) == 0)
958 rte_eth_promiscuous_disable(port_id);
960 /* replay allmulticast configuration */
961 if (rte_eth_allmulticast_get(port_id) == 1)
962 rte_eth_allmulticast_enable(port_id);
963 else if (rte_eth_allmulticast_get(port_id) == 0)
964 rte_eth_allmulticast_disable(port_id);
968 rte_eth_dev_start(uint8_t port_id)
970 struct rte_eth_dev *dev;
973 /* This function is only safe when called from the primary process
974 * in a multi-process setup*/
975 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
977 if (!rte_eth_dev_is_valid_port(port_id)) {
978 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
982 dev = &rte_eth_devices[port_id];
984 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
986 if (dev->data->dev_started != 0) {
987 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
988 " already started\n",
993 diag = (*dev->dev_ops->dev_start)(dev);
995 dev->data->dev_started = 1;
999 rte_eth_dev_config_restore(port_id);
1001 if (dev->data->dev_conf.intr_conf.lsc != 0) {
1002 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1003 (*dev->dev_ops->link_update)(dev, 0);
1009 rte_eth_dev_stop(uint8_t port_id)
1011 struct rte_eth_dev *dev;
1013 /* This function is only safe when called from the primary process
1014 * in a multi-process setup*/
1015 PROC_PRIMARY_OR_RET();
1017 if (!rte_eth_dev_is_valid_port(port_id)) {
1018 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1022 dev = &rte_eth_devices[port_id];
1024 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1026 if (dev->data->dev_started == 0) {
1027 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1028 " already stopped\n",
1033 dev->data->dev_started = 0;
1034 (*dev->dev_ops->dev_stop)(dev);
1038 rte_eth_dev_set_link_up(uint8_t port_id)
1040 struct rte_eth_dev *dev;
1042 /* This function is only safe when called from the primary process
1043 * in a multi-process setup*/
1044 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1046 if (!rte_eth_dev_is_valid_port(port_id)) {
1047 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1051 dev = &rte_eth_devices[port_id];
1053 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1054 return (*dev->dev_ops->dev_set_link_up)(dev);
1058 rte_eth_dev_set_link_down(uint8_t port_id)
1060 struct rte_eth_dev *dev;
1062 /* This function is only safe when called from the primary process
1063 * in a multi-process setup*/
1064 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1066 if (!rte_eth_dev_is_valid_port(port_id)) {
1067 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1071 dev = &rte_eth_devices[port_id];
1073 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1074 return (*dev->dev_ops->dev_set_link_down)(dev);
1078 rte_eth_dev_close(uint8_t port_id)
1080 struct rte_eth_dev *dev;
1082 /* This function is only safe when called from the primary process
1083 * in a multi-process setup*/
1084 PROC_PRIMARY_OR_RET();
1086 if (!rte_eth_dev_is_valid_port(port_id)) {
1087 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1091 dev = &rte_eth_devices[port_id];
1093 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1094 dev->data->dev_started = 0;
1095 (*dev->dev_ops->dev_close)(dev);
1099 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1100 uint16_t nb_rx_desc, unsigned int socket_id,
1101 const struct rte_eth_rxconf *rx_conf,
1102 struct rte_mempool *mp)
1105 uint32_t mbp_buf_size;
1106 struct rte_eth_dev *dev;
1107 struct rte_pktmbuf_pool_private *mbp_priv;
1108 struct rte_eth_dev_info dev_info;
1110 /* This function is only safe when called from the primary process
1111 * in a multi-process setup*/
1112 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1114 if (!rte_eth_dev_is_valid_port(port_id)) {
1115 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1119 dev = &rte_eth_devices[port_id];
1120 if (rx_queue_id >= dev->data->nb_rx_queues) {
1121 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1125 if (dev->data->dev_started) {
1127 "port %d must be stopped to allow configuration\n", port_id);
1131 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1132 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1135 * Check the size of the mbuf data buffer.
1136 * This value must be provided in the private data of the memory pool.
1137 * First check that the memory pool has a valid private data.
1139 rte_eth_dev_info_get(port_id, &dev_info);
1140 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1141 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1142 mp->name, (int) mp->private_data_size,
1143 (int) sizeof(struct rte_pktmbuf_pool_private));
1146 mbp_priv = rte_mempool_get_priv(mp);
1147 mbp_buf_size = mbp_priv->mbuf_data_room_size;
1149 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1150 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1151 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1155 (int)(RTE_PKTMBUF_HEADROOM +
1156 dev_info.min_rx_bufsize),
1157 (int)RTE_PKTMBUF_HEADROOM,
1158 (int)dev_info.min_rx_bufsize);
1162 if (rx_conf == NULL)
1163 rx_conf = &dev_info.default_rxconf;
1165 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1166 socket_id, rx_conf, mp);
1168 if (!dev->data->min_rx_buf_size ||
1169 dev->data->min_rx_buf_size > mbp_buf_size)
1170 dev->data->min_rx_buf_size = mbp_buf_size;
1177 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1178 uint16_t nb_tx_desc, unsigned int socket_id,
1179 const struct rte_eth_txconf *tx_conf)
1181 struct rte_eth_dev *dev;
1182 struct rte_eth_dev_info dev_info;
1184 /* This function is only safe when called from the primary process
1185 * in a multi-process setup*/
1186 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1188 if (!rte_eth_dev_is_valid_port(port_id)) {
1189 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1193 dev = &rte_eth_devices[port_id];
1194 if (tx_queue_id >= dev->data->nb_tx_queues) {
1195 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1199 if (dev->data->dev_started) {
1201 "port %d must be stopped to allow configuration\n", port_id);
1205 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1206 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1208 rte_eth_dev_info_get(port_id, &dev_info);
1210 if (tx_conf == NULL)
1211 tx_conf = &dev_info.default_txconf;
1213 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1214 socket_id, tx_conf);
1218 rte_eth_promiscuous_enable(uint8_t port_id)
1220 struct rte_eth_dev *dev;
1222 if (!rte_eth_dev_is_valid_port(port_id)) {
1223 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1227 dev = &rte_eth_devices[port_id];
1229 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1230 (*dev->dev_ops->promiscuous_enable)(dev);
1231 dev->data->promiscuous = 1;
1235 rte_eth_promiscuous_disable(uint8_t port_id)
1237 struct rte_eth_dev *dev;
1239 if (!rte_eth_dev_is_valid_port(port_id)) {
1240 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1244 dev = &rte_eth_devices[port_id];
1246 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1247 dev->data->promiscuous = 0;
1248 (*dev->dev_ops->promiscuous_disable)(dev);
1252 rte_eth_promiscuous_get(uint8_t port_id)
1254 struct rte_eth_dev *dev;
1256 if (!rte_eth_dev_is_valid_port(port_id)) {
1257 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1261 dev = &rte_eth_devices[port_id];
1262 return dev->data->promiscuous;
1266 rte_eth_allmulticast_enable(uint8_t port_id)
1268 struct rte_eth_dev *dev;
1270 if (!rte_eth_dev_is_valid_port(port_id)) {
1271 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1275 dev = &rte_eth_devices[port_id];
1277 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1278 (*dev->dev_ops->allmulticast_enable)(dev);
1279 dev->data->all_multicast = 1;
1283 rte_eth_allmulticast_disable(uint8_t port_id)
1285 struct rte_eth_dev *dev;
1287 if (!rte_eth_dev_is_valid_port(port_id)) {
1288 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1292 dev = &rte_eth_devices[port_id];
1294 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1295 dev->data->all_multicast = 0;
1296 (*dev->dev_ops->allmulticast_disable)(dev);
1300 rte_eth_allmulticast_get(uint8_t port_id)
1302 struct rte_eth_dev *dev;
1304 if (!rte_eth_dev_is_valid_port(port_id)) {
1305 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1309 dev = &rte_eth_devices[port_id];
1310 return dev->data->all_multicast;
1314 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1315 struct rte_eth_link *link)
1317 struct rte_eth_link *dst = link;
1318 struct rte_eth_link *src = &(dev->data->dev_link);
1320 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1321 *(uint64_t *)src) == 0)
1328 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1330 struct rte_eth_dev *dev;
1332 if (!rte_eth_dev_is_valid_port(port_id)) {
1333 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1337 dev = &rte_eth_devices[port_id];
1339 if (dev->data->dev_conf.intr_conf.lsc != 0)
1340 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1342 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1343 (*dev->dev_ops->link_update)(dev, 1);
1344 *eth_link = dev->data->dev_link;
1349 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1351 struct rte_eth_dev *dev;
1353 if (!rte_eth_dev_is_valid_port(port_id)) {
1354 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1358 dev = &rte_eth_devices[port_id];
1360 if (dev->data->dev_conf.intr_conf.lsc != 0)
1361 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1363 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1364 (*dev->dev_ops->link_update)(dev, 0);
1365 *eth_link = dev->data->dev_link;
1370 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1372 struct rte_eth_dev *dev;
1374 if (!rte_eth_dev_is_valid_port(port_id)) {
1375 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1379 dev = &rte_eth_devices[port_id];
1380 memset(stats, 0, sizeof(*stats));
1382 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1383 (*dev->dev_ops->stats_get)(dev, stats);
1384 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1389 rte_eth_stats_reset(uint8_t port_id)
1391 struct rte_eth_dev *dev;
1393 if (!rte_eth_dev_is_valid_port(port_id)) {
1394 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1398 dev = &rte_eth_devices[port_id];
1400 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1401 (*dev->dev_ops->stats_reset)(dev);
1404 /* retrieve ethdev extended statistics */
1406 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1409 struct rte_eth_stats eth_stats;
1410 struct rte_eth_dev *dev;
1411 unsigned count, i, q;
1415 if (!rte_eth_dev_is_valid_port(port_id)) {
1416 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1420 dev = &rte_eth_devices[port_id];
1422 /* implemented by the driver */
1423 if (dev->dev_ops->xstats_get != NULL)
1424 return (*dev->dev_ops->xstats_get)(dev, xstats, n);
1426 /* else, return generic statistics */
1427 count = RTE_NB_STATS;
1428 count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
1429 count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
1433 /* now fill the xstats structure */
1436 memset(ð_stats, 0, sizeof(eth_stats));
1437 rte_eth_stats_get(port_id, ð_stats);
1440 for (i = 0; i < RTE_NB_STATS; i++) {
1441 stats_ptr = (char *)ð_stats + rte_stats_strings[i].offset;
1442 val = *(uint64_t *)stats_ptr;
1443 snprintf(xstats[count].name, sizeof(xstats[count].name),
1444 "%s", rte_stats_strings[i].name);
1445 xstats[count++].value = val;
1449 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1450 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1451 stats_ptr = (char *)ð_stats;
1452 stats_ptr += rte_rxq_stats_strings[i].offset;
1453 stats_ptr += q * sizeof(uint64_t);
1454 val = *(uint64_t *)stats_ptr;
1455 snprintf(xstats[count].name, sizeof(xstats[count].name),
1456 "rx_queue_%u_%s", q,
1457 rte_rxq_stats_strings[i].name);
1458 xstats[count++].value = val;
1463 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1464 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1465 stats_ptr = (char *)ð_stats;
1466 stats_ptr += rte_txq_stats_strings[i].offset;
1467 stats_ptr += q * sizeof(uint64_t);
1468 val = *(uint64_t *)stats_ptr;
1469 snprintf(xstats[count].name, sizeof(xstats[count].name),
1470 "tx_queue_%u_%s", q,
1471 rte_txq_stats_strings[i].name);
1472 xstats[count++].value = val;
1479 /* reset ethdev extended statistics */
1481 rte_eth_xstats_reset(uint8_t port_id)
1483 struct rte_eth_dev *dev;
1485 if (!rte_eth_dev_is_valid_port(port_id)) {
1486 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1490 dev = &rte_eth_devices[port_id];
1492 /* implemented by the driver */
1493 if (dev->dev_ops->xstats_reset != NULL) {
1494 (*dev->dev_ops->xstats_reset)(dev);
1498 /* fallback to default */
1499 rte_eth_stats_reset(port_id);
1503 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1506 struct rte_eth_dev *dev;
1508 if (!rte_eth_dev_is_valid_port(port_id)) {
1509 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1513 dev = &rte_eth_devices[port_id];
1515 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1516 return (*dev->dev_ops->queue_stats_mapping_set)
1517 (dev, queue_id, stat_idx, is_rx);
1522 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1525 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1531 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1534 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1540 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1542 struct rte_eth_dev *dev;
1544 if (!rte_eth_dev_is_valid_port(port_id)) {
1545 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1549 dev = &rte_eth_devices[port_id];
1551 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1553 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1554 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1555 dev_info->pci_dev = dev->pci_dev;
1557 dev_info->driver_name = dev->driver->pci_drv.name;
1561 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1563 struct rte_eth_dev *dev;
1565 if (!rte_eth_dev_is_valid_port(port_id)) {
1566 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1570 dev = &rte_eth_devices[port_id];
1571 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1576 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1578 struct rte_eth_dev *dev;
1580 if (!rte_eth_dev_is_valid_port(port_id)) {
1581 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1585 dev = &rte_eth_devices[port_id];
1586 *mtu = dev->data->mtu;
1591 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1594 struct rte_eth_dev *dev;
1596 if (!rte_eth_dev_is_valid_port(port_id)) {
1597 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1601 dev = &rte_eth_devices[port_id];
1602 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1604 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1606 dev->data->mtu = mtu;
1612 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1614 struct rte_eth_dev *dev;
1616 if (!rte_eth_dev_is_valid_port(port_id)) {
1617 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1621 dev = &rte_eth_devices[port_id];
1622 if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1623 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1627 if (vlan_id > 4095) {
1628 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1629 port_id, (unsigned) vlan_id);
1632 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1633 (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1638 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1640 struct rte_eth_dev *dev;
1642 if (!rte_eth_dev_is_valid_port(port_id)) {
1643 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1647 dev = &rte_eth_devices[port_id];
1648 if (rx_queue_id >= dev->data->nb_rx_queues) {
1649 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1653 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1654 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1660 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1662 struct rte_eth_dev *dev;
1664 if (!rte_eth_dev_is_valid_port(port_id)) {
1665 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1669 dev = &rte_eth_devices[port_id];
1670 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1671 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1677 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1679 struct rte_eth_dev *dev;
1684 if (!rte_eth_dev_is_valid_port(port_id)) {
1685 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1689 dev = &rte_eth_devices[port_id];
1691 /*check which option changed by application*/
1692 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1693 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1695 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1696 mask |= ETH_VLAN_STRIP_MASK;
1699 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1700 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1702 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1703 mask |= ETH_VLAN_FILTER_MASK;
1706 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1707 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1709 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1710 mask |= ETH_VLAN_EXTEND_MASK;
1717 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1718 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1724 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1726 struct rte_eth_dev *dev;
1729 if (!rte_eth_dev_is_valid_port(port_id)) {
1730 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1734 dev = &rte_eth_devices[port_id];
1736 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1737 ret |= ETH_VLAN_STRIP_OFFLOAD ;
1739 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1740 ret |= ETH_VLAN_FILTER_OFFLOAD ;
1742 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1743 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
1749 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1751 struct rte_eth_dev *dev;
1753 if (!rte_eth_dev_is_valid_port(port_id)) {
1754 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1758 dev = &rte_eth_devices[port_id];
1759 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1760 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1766 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1767 struct rte_fdir_filter *fdir_filter,
1770 struct rte_eth_dev *dev;
1772 if (!rte_eth_dev_is_valid_port(port_id)) {
1773 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1777 dev = &rte_eth_devices[port_id];
1779 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1780 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1781 port_id, dev->data->dev_conf.fdir_conf.mode);
1785 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1786 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1787 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1788 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1789 "None l4type, source & destinations ports " \
1790 "should be null!\n");
1794 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1795 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1800 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1801 struct rte_fdir_filter *fdir_filter,
1804 struct rte_eth_dev *dev;
1806 if (!rte_eth_dev_is_valid_port(port_id)) {
1807 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1811 dev = &rte_eth_devices[port_id];
1813 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1814 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1815 port_id, dev->data->dev_conf.fdir_conf.mode);
1819 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1820 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1821 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1822 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1823 "None l4type, source & destinations ports " \
1824 "should be null!\n");
1828 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
1829 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
1835 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
1836 struct rte_fdir_filter *fdir_filter)
1838 struct rte_eth_dev *dev;
1840 if (!rte_eth_dev_is_valid_port(port_id)) {
1841 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1845 dev = &rte_eth_devices[port_id];
1847 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1848 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1849 port_id, dev->data->dev_conf.fdir_conf.mode);
1853 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1854 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1855 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1856 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1857 "None l4type source & destinations ports " \
1858 "should be null!\n");
1862 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
1863 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
1867 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
1869 struct rte_eth_dev *dev;
1871 if (!rte_eth_dev_is_valid_port(port_id)) {
1872 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1876 dev = &rte_eth_devices[port_id];
1877 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1878 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1882 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
1884 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
1889 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
1890 struct rte_fdir_filter *fdir_filter,
1891 uint16_t soft_id, uint8_t queue,
1894 struct rte_eth_dev *dev;
1896 if (!rte_eth_dev_is_valid_port(port_id)) {
1897 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1901 dev = &rte_eth_devices[port_id];
1903 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1904 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1905 port_id, dev->data->dev_conf.fdir_conf.mode);
1909 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1910 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1911 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1912 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1913 "None l4type, source & destinations ports " \
1914 "should be null!\n");
1918 /* For now IPv6 is not supported with perfect filter */
1919 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1922 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
1923 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
1929 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
1930 struct rte_fdir_filter *fdir_filter,
1931 uint16_t soft_id, uint8_t queue,
1934 struct rte_eth_dev *dev;
1936 if (!rte_eth_dev_is_valid_port(port_id)) {
1937 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1941 dev = &rte_eth_devices[port_id];
1943 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1944 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1945 port_id, dev->data->dev_conf.fdir_conf.mode);
1949 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1950 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1951 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1952 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1953 "None l4type, source & destinations ports " \
1954 "should be null!\n");
1958 /* For now IPv6 is not supported with perfect filter */
1959 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1962 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
1963 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
1964 soft_id, queue, drop);
1968 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
1969 struct rte_fdir_filter *fdir_filter,
1972 struct rte_eth_dev *dev;
1974 if (!rte_eth_dev_is_valid_port(port_id)) {
1975 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1979 dev = &rte_eth_devices[port_id];
1981 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1982 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1983 port_id, dev->data->dev_conf.fdir_conf.mode);
1987 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1988 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1989 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1990 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1991 "None l4type, source & destinations ports " \
1992 "should be null!\n");
1996 /* For now IPv6 is not supported with perfect filter */
1997 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2000 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
2001 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
2006 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
2008 struct rte_eth_dev *dev;
2010 if (!rte_eth_dev_is_valid_port(port_id)) {
2011 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2015 dev = &rte_eth_devices[port_id];
2016 if (! (dev->data->dev_conf.fdir_conf.mode)) {
2017 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
2021 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
2022 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
2026 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2028 struct rte_eth_dev *dev;
2030 if (!rte_eth_dev_is_valid_port(port_id)) {
2031 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2035 dev = &rte_eth_devices[port_id];
2036 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2037 memset(fc_conf, 0, sizeof(*fc_conf));
2038 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
2042 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2044 struct rte_eth_dev *dev;
2046 if (!rte_eth_dev_is_valid_port(port_id)) {
2047 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2051 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2052 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2056 dev = &rte_eth_devices[port_id];
2057 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2058 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
2062 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
2064 struct rte_eth_dev *dev;
2066 if (!rte_eth_dev_is_valid_port(port_id)) {
2067 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2071 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2072 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2076 dev = &rte_eth_devices[port_id];
2077 /* High water, low water validation are device specific */
2078 if (*dev->dev_ops->priority_flow_ctrl_set)
2079 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
2084 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2092 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
2093 PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
2094 RTE_RETA_GROUP_SIZE);
2098 num = reta_size / RTE_RETA_GROUP_SIZE;
2099 for (i = 0; i < num; i++) {
2100 if (reta_conf[i].mask)
2108 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2112 uint16_t i, idx, shift;
2118 PMD_DEBUG_TRACE("No receive queue is available\n");
2122 for (i = 0; i < reta_size; i++) {
2123 idx = i / RTE_RETA_GROUP_SIZE;
2124 shift = i % RTE_RETA_GROUP_SIZE;
2125 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2126 (reta_conf[idx].reta[shift] >= max_rxq)) {
2127 PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2128 "the maximum rxq index: %u\n", idx, shift,
2129 reta_conf[idx].reta[shift], max_rxq);
2138 rte_eth_dev_rss_reta_update(uint8_t port_id,
2139 struct rte_eth_rss_reta_entry64 *reta_conf,
2142 struct rte_eth_dev *dev;
2145 if (!rte_eth_dev_is_valid_port(port_id)) {
2146 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2150 /* Check mask bits */
2151 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2155 dev = &rte_eth_devices[port_id];
2157 /* Check entry value */
2158 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2159 dev->data->nb_rx_queues);
2163 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2164 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2168 rte_eth_dev_rss_reta_query(uint8_t port_id,
2169 struct rte_eth_rss_reta_entry64 *reta_conf,
2172 struct rte_eth_dev *dev;
2175 if (port_id >= nb_ports) {
2176 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2180 /* Check mask bits */
2181 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2185 dev = &rte_eth_devices[port_id];
2186 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2187 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2191 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2193 struct rte_eth_dev *dev;
2194 uint16_t rss_hash_protos;
2196 if (!rte_eth_dev_is_valid_port(port_id)) {
2197 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2201 rss_hash_protos = rss_conf->rss_hf;
2202 if ((rss_hash_protos != 0) &&
2203 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2204 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2208 dev = &rte_eth_devices[port_id];
2209 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2210 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2214 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2215 struct rte_eth_rss_conf *rss_conf)
2217 struct rte_eth_dev *dev;
2219 if (!rte_eth_dev_is_valid_port(port_id)) {
2220 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2224 dev = &rte_eth_devices[port_id];
2225 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2226 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2230 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
2231 struct rte_eth_udp_tunnel *udp_tunnel)
2233 struct rte_eth_dev *dev;
2235 if (!rte_eth_dev_is_valid_port(port_id)) {
2236 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2240 if (udp_tunnel == NULL) {
2241 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2245 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2246 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2250 dev = &rte_eth_devices[port_id];
2251 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
2252 return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
2256 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
2257 struct rte_eth_udp_tunnel *udp_tunnel)
2259 struct rte_eth_dev *dev;
2261 if (!rte_eth_dev_is_valid_port(port_id)) {
2262 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2266 dev = &rte_eth_devices[port_id];
2268 if (udp_tunnel == NULL) {
2269 PMD_DEBUG_TRACE("Invalid udp_tunnel parametr\n");
2273 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2274 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2278 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2279 return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2283 rte_eth_led_on(uint8_t port_id)
2285 struct rte_eth_dev *dev;
2287 if (!rte_eth_dev_is_valid_port(port_id)) {
2288 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2292 dev = &rte_eth_devices[port_id];
2293 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2294 return ((*dev->dev_ops->dev_led_on)(dev));
2298 rte_eth_led_off(uint8_t port_id)
2300 struct rte_eth_dev *dev;
2302 if (!rte_eth_dev_is_valid_port(port_id)) {
2303 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2307 dev = &rte_eth_devices[port_id];
2308 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2309 return ((*dev->dev_ops->dev_led_off)(dev));
2313 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2317 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2319 struct rte_eth_dev_info dev_info;
2320 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2323 rte_eth_dev_info_get(port_id, &dev_info);
2325 for (i = 0; i < dev_info.max_mac_addrs; i++)
2326 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2332 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
2335 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2338 struct rte_eth_dev *dev;
2342 if (!rte_eth_dev_is_valid_port(port_id)) {
2343 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2347 dev = &rte_eth_devices[port_id];
2348 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2350 if (is_zero_ether_addr(addr)) {
2351 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2355 if (pool >= ETH_64_POOLS) {
2356 PMD_DEBUG_TRACE("pool id must be 0-%d\n",ETH_64_POOLS - 1);
2360 index = get_mac_addr_index(port_id, addr);
2362 index = get_mac_addr_index(port_id, &null_mac_addr);
2364 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2369 pool_mask = dev->data->mac_pool_sel[index];
2371 /* Check if both MAC address and pool is alread there, and do nothing */
2372 if (pool_mask & (1ULL << pool))
2377 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2379 /* Update address in NIC data structure */
2380 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2382 /* Update pool bitmap in NIC data structure */
2383 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2389 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2391 struct rte_eth_dev *dev;
2394 if (!rte_eth_dev_is_valid_port(port_id)) {
2395 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2399 dev = &rte_eth_devices[port_id];
2400 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2402 index = get_mac_addr_index(port_id, addr);
2404 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2405 return (-EADDRINUSE);
2406 } else if (index < 0)
2407 return 0; /* Do nothing if address wasn't found */
2410 (*dev->dev_ops->mac_addr_remove)(dev, index);
2412 /* Update address in NIC data structure */
2413 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2415 /* reset pool bitmap */
2416 dev->data->mac_pool_sel[index] = 0;
2422 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2423 uint16_t rx_mode, uint8_t on)
2426 struct rte_eth_dev *dev;
2427 struct rte_eth_dev_info dev_info;
2429 if (!rte_eth_dev_is_valid_port(port_id)) {
2430 PMD_DEBUG_TRACE("set VF RX mode:Invalid port_id=%d\n",
2435 dev = &rte_eth_devices[port_id];
2436 rte_eth_dev_info_get(port_id, &dev_info);
2438 num_vfs = dev_info.max_vfs;
2441 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2446 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2449 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2450 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2454 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2458 get_hash_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2460 struct rte_eth_dev_info dev_info;
2461 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2464 rte_eth_dev_info_get(port_id, &dev_info);
2465 if (!dev->data->hash_mac_addrs)
2468 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2469 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2470 ETHER_ADDR_LEN) == 0)
2477 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2482 struct rte_eth_dev *dev;
2484 if (!rte_eth_dev_is_valid_port(port_id)) {
2485 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2490 dev = &rte_eth_devices[port_id];
2491 if (is_zero_ether_addr(addr)) {
2492 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2497 index = get_hash_mac_addr_index(port_id, addr);
2498 /* Check if it's already there, and do nothing */
2499 if ((index >= 0) && (on))
2504 PMD_DEBUG_TRACE("port %d: the MAC address was not"
2505 "set in UTA\n", port_id);
2509 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2511 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2517 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2518 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2520 /* Update address in NIC data structure */
2522 ether_addr_copy(addr,
2523 &dev->data->hash_mac_addrs[index]);
2525 ether_addr_copy(&null_mac_addr,
2526 &dev->data->hash_mac_addrs[index]);
2533 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2535 struct rte_eth_dev *dev;
2537 if (!rte_eth_dev_is_valid_port(port_id)) {
2538 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2543 dev = &rte_eth_devices[port_id];
2545 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2546 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2550 rte_eth_dev_set_vf_rx(uint8_t port_id,uint16_t vf, uint8_t on)
2553 struct rte_eth_dev *dev;
2554 struct rte_eth_dev_info dev_info;
2556 if (!rte_eth_dev_is_valid_port(port_id)) {
2557 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2561 dev = &rte_eth_devices[port_id];
2562 rte_eth_dev_info_get(port_id, &dev_info);
2564 num_vfs = dev_info.max_vfs;
2567 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2571 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2572 return (*dev->dev_ops->set_vf_rx)(dev, vf,on);
2576 rte_eth_dev_set_vf_tx(uint8_t port_id,uint16_t vf, uint8_t on)
2579 struct rte_eth_dev *dev;
2580 struct rte_eth_dev_info dev_info;
2582 if (!rte_eth_dev_is_valid_port(port_id)) {
2583 PMD_DEBUG_TRACE("set pool tx:Invalid port_id=%d\n", port_id);
2587 dev = &rte_eth_devices[port_id];
2588 rte_eth_dev_info_get(port_id, &dev_info);
2590 num_vfs = dev_info.max_vfs;
2593 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2597 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2598 return (*dev->dev_ops->set_vf_tx)(dev, vf,on);
2602 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2603 uint64_t vf_mask,uint8_t vlan_on)
2605 struct rte_eth_dev *dev;
2607 if (!rte_eth_dev_is_valid_port(port_id)) {
2608 PMD_DEBUG_TRACE("VF VLAN filter:invalid port id=%d\n",
2612 dev = &rte_eth_devices[port_id];
2614 if(vlan_id > ETHER_MAX_VLAN_ID)
2616 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2622 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2626 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2627 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2631 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2634 struct rte_eth_dev *dev;
2635 struct rte_eth_dev_info dev_info;
2636 struct rte_eth_link link;
2638 if (!rte_eth_dev_is_valid_port(port_id)) {
2639 PMD_DEBUG_TRACE("set queue rate limit:invalid port id=%d\n",
2644 dev = &rte_eth_devices[port_id];
2645 rte_eth_dev_info_get(port_id, &dev_info);
2646 link = dev->data->dev_link;
2648 if (queue_idx > dev_info.max_tx_queues) {
2649 PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2650 "invalid queue id=%d\n", port_id, queue_idx);
2654 if (tx_rate > link.link_speed) {
2655 PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2656 "bigger than link speed= %d\n",
2657 tx_rate, link.link_speed);
2661 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2662 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2665 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2668 struct rte_eth_dev *dev;
2669 struct rte_eth_dev_info dev_info;
2670 struct rte_eth_link link;
2675 if (!rte_eth_dev_is_valid_port(port_id)) {
2676 PMD_DEBUG_TRACE("set VF rate limit:invalid port id=%d\n",
2681 dev = &rte_eth_devices[port_id];
2682 rte_eth_dev_info_get(port_id, &dev_info);
2683 link = dev->data->dev_link;
2685 if (vf > dev_info.max_vfs) {
2686 PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2687 "invalid vf id=%d\n", port_id, vf);
2691 if (tx_rate > link.link_speed) {
2692 PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2693 "bigger than link speed= %d\n",
2694 tx_rate, link.link_speed);
2698 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2699 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2703 rte_eth_mirror_rule_set(uint8_t port_id,
2704 struct rte_eth_vmdq_mirror_conf *mirror_conf,
2705 uint8_t rule_id, uint8_t on)
2707 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2709 if (!rte_eth_dev_is_valid_port(port_id)) {
2710 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2714 if (mirror_conf->rule_type_mask == 0) {
2715 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2719 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2720 PMD_DEBUG_TRACE("Invalid dst pool, pool id must"
2721 "be 0-%d\n",ETH_64_POOLS - 1);
2725 if ((mirror_conf->rule_type_mask & ETH_VMDQ_POOL_MIRROR) &&
2726 (mirror_conf->pool_mask == 0)) {
2727 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not"
2732 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2734 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2735 ETH_VMDQ_NUM_MIRROR_RULE - 1);
2739 dev = &rte_eth_devices[port_id];
2740 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2742 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2746 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2748 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2750 if (!rte_eth_dev_is_valid_port(port_id)) {
2751 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2755 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2757 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2758 ETH_VMDQ_NUM_MIRROR_RULE-1);
2762 dev = &rte_eth_devices[port_id];
2763 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2765 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2768 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2770 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2771 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2773 struct rte_eth_dev *dev;
2775 if (!rte_eth_dev_is_valid_port(port_id)) {
2776 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2780 dev = &rte_eth_devices[port_id];
2781 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);
2782 if (queue_id >= dev->data->nb_rx_queues) {
2783 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2786 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2791 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2792 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2794 struct rte_eth_dev *dev;
2796 if (!rte_eth_dev_is_valid_port(port_id)) {
2797 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2801 dev = &rte_eth_devices[port_id];
2803 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0);
2804 if (queue_id >= dev->data->nb_tx_queues) {
2805 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2808 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2813 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2815 struct rte_eth_dev *dev;
2817 if (!rte_eth_dev_is_valid_port(port_id)) {
2818 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2822 dev = &rte_eth_devices[port_id];
2823 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0);
2824 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2828 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2830 struct rte_eth_dev *dev;
2832 if (!rte_eth_dev_is_valid_port(port_id)) {
2833 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2837 dev = &rte_eth_devices[port_id];
2838 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2839 return (*dev->dev_ops->rx_descriptor_done)( \
2840 dev->data->rx_queues[queue_id], offset);
2845 rte_eth_dev_callback_register(uint8_t port_id,
2846 enum rte_eth_event_type event,
2847 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2849 struct rte_eth_dev *dev;
2850 struct rte_eth_dev_callback *user_cb;
2855 if (!rte_eth_dev_is_valid_port(port_id)) {
2856 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2860 dev = &rte_eth_devices[port_id];
2861 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2863 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2864 if (user_cb->cb_fn == cb_fn &&
2865 user_cb->cb_arg == cb_arg &&
2866 user_cb->event == event) {
2871 /* create a new callback. */
2872 if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2873 sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
2874 user_cb->cb_fn = cb_fn;
2875 user_cb->cb_arg = cb_arg;
2876 user_cb->event = event;
2877 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2880 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2881 return ((user_cb == NULL) ? -ENOMEM : 0);
2885 rte_eth_dev_callback_unregister(uint8_t port_id,
2886 enum rte_eth_event_type event,
2887 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2890 struct rte_eth_dev *dev;
2891 struct rte_eth_dev_callback *cb, *next;
2896 if (!rte_eth_dev_is_valid_port(port_id)) {
2897 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2901 dev = &rte_eth_devices[port_id];
2902 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2905 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2907 next = TAILQ_NEXT(cb, next);
2909 if (cb->cb_fn != cb_fn || cb->event != event ||
2910 (cb->cb_arg != (void *)-1 &&
2911 cb->cb_arg != cb_arg))
2915 * if this callback is not executing right now,
2918 if (cb->active == 0) {
2919 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2926 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2931 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2932 enum rte_eth_event_type event)
2934 struct rte_eth_dev_callback *cb_lst;
2935 struct rte_eth_dev_callback dev_cb;
2937 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2938 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2939 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2943 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2944 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2946 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2949 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2951 #ifdef RTE_NIC_BYPASS
2952 int rte_eth_dev_bypass_init(uint8_t port_id)
2954 struct rte_eth_dev *dev;
2956 if (!rte_eth_dev_is_valid_port(port_id)) {
2957 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2961 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2962 PMD_DEBUG_TRACE("Invalid port device\n");
2966 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2967 (*dev->dev_ops->bypass_init)(dev);
2972 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2974 struct rte_eth_dev *dev;
2976 if (!rte_eth_dev_is_valid_port(port_id)) {
2977 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2981 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2982 PMD_DEBUG_TRACE("Invalid port device\n");
2985 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2986 (*dev->dev_ops->bypass_state_show)(dev, state);
2991 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2993 struct rte_eth_dev *dev;
2995 if (!rte_eth_dev_is_valid_port(port_id)) {
2996 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3000 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3001 PMD_DEBUG_TRACE("Invalid port device\n");
3005 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
3006 (*dev->dev_ops->bypass_state_set)(dev, new_state);
3011 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
3013 struct rte_eth_dev *dev;
3015 if (!rte_eth_dev_is_valid_port(port_id)) {
3016 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3020 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3021 PMD_DEBUG_TRACE("Invalid port device\n");
3025 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
3026 (*dev->dev_ops->bypass_event_show)(dev, event, state);
3031 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
3033 struct rte_eth_dev *dev;
3035 if (!rte_eth_dev_is_valid_port(port_id)) {
3036 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3040 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3041 PMD_DEBUG_TRACE("Invalid port device\n");
3045 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
3046 (*dev->dev_ops->bypass_event_set)(dev, event, state);
3051 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
3053 struct rte_eth_dev *dev;
3055 if (!rte_eth_dev_is_valid_port(port_id)) {
3056 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3060 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3061 PMD_DEBUG_TRACE("Invalid port device\n");
3065 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
3066 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
3071 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
3073 struct rte_eth_dev *dev;
3075 if (!rte_eth_dev_is_valid_port(port_id)) {
3076 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3080 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3081 PMD_DEBUG_TRACE("Invalid port device\n");
3085 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
3086 (*dev->dev_ops->bypass_ver_show)(dev, ver);
3091 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
3093 struct rte_eth_dev *dev;
3095 if (!rte_eth_dev_is_valid_port(port_id)) {
3096 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3100 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3101 PMD_DEBUG_TRACE("Invalid port device\n");
3105 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
3106 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
3111 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
3113 struct rte_eth_dev *dev;
3115 if (!rte_eth_dev_is_valid_port(port_id)) {
3116 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3120 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3121 PMD_DEBUG_TRACE("Invalid port device\n");
3125 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
3126 (*dev->dev_ops->bypass_wd_reset)(dev);
3132 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
3134 struct rte_eth_dev *dev;
3136 if (!rte_eth_dev_is_valid_port(port_id)) {
3137 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3141 dev = &rte_eth_devices[port_id];
3142 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3143 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3144 RTE_ETH_FILTER_NOP, NULL);
3148 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
3149 enum rte_filter_op filter_op, void *arg)
3151 struct rte_eth_dev *dev;
3153 if (!rte_eth_dev_is_valid_port(port_id)) {
3154 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3158 dev = &rte_eth_devices[port_id];
3159 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3160 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
3164 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
3165 rte_rxtx_callback_fn fn, void *user_param)
3167 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3168 rte_errno = ENOTSUP;
3171 /* check input parameters */
3172 if (port_id >= nb_ports || fn == NULL ||
3173 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3178 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3186 cb->param = user_param;
3187 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3188 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3193 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
3194 rte_rxtx_callback_fn fn, void *user_param)
3196 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3197 rte_errno = ENOTSUP;
3200 /* check input parameters */
3201 if (port_id >= nb_ports || fn == NULL ||
3202 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3207 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3215 cb->param = user_param;
3216 cb->next = rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3217 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3222 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3223 struct rte_eth_rxtx_callback *user_cb)
3225 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3228 /* Check input parameters. */
3229 if (port_id >= nb_ports || user_cb == NULL ||
3230 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3234 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3235 struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
3236 struct rte_eth_rxtx_callback *prev_cb;
3238 /* Reset head pointer and remove user cb if first in the list. */
3239 if (cb == user_cb) {
3240 dev->post_rx_burst_cbs[queue_id] = user_cb->next;
3244 /* Remove the user cb from the callback list. */
3249 if (cb == user_cb) {
3250 prev_cb->next = user_cb->next;
3254 } while (cb != NULL);
3256 /* Callback wasn't found. */
3261 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3262 struct rte_eth_rxtx_callback *user_cb)
3264 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3267 /* Check input parameters. */
3268 if (port_id >= nb_ports || user_cb == NULL ||
3269 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3273 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3274 struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
3275 struct rte_eth_rxtx_callback *prev_cb;
3277 /* Reset head pointer and remove user cb if first in the list. */
3278 if (cb == user_cb) {
3279 dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
3283 /* Remove the user cb from the callback list. */
3288 if (cb == user_cb) {
3289 prev_cb->next = user_cb->next;
3293 } while (cb != NULL);
3295 /* Callback wasn't found. */