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_release_port(struct rte_eth_dev *eth_dev)
264 eth_dev->attached = 0;
270 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
271 struct rte_pci_device *pci_dev)
273 struct eth_driver *eth_drv;
274 struct rte_eth_dev *eth_dev;
275 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
279 eth_drv = (struct eth_driver *)pci_drv;
281 /* Create unique Ethernet device name using PCI address */
282 snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "%d:%d.%d",
283 pci_dev->addr.bus, pci_dev->addr.devid, pci_dev->addr.function);
285 eth_dev = rte_eth_dev_allocate(ethdev_name);
289 if (rte_eal_process_type() == RTE_PROC_PRIMARY){
290 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
291 eth_drv->dev_private_size,
292 RTE_CACHE_LINE_SIZE);
293 if (eth_dev->data->dev_private == NULL)
294 rte_panic("Cannot allocate memzone for private port data\n");
296 eth_dev->pci_dev = pci_dev;
297 eth_dev->driver = eth_drv;
298 eth_dev->data->rx_mbuf_alloc_failed = 0;
300 /* init user callbacks */
301 TAILQ_INIT(&(eth_dev->link_intr_cbs));
304 * Set the default MTU.
306 eth_dev->data->mtu = ETHER_MTU;
308 /* Invoke PMD device initialization function */
309 diag = (*eth_drv->eth_dev_init)(eth_drv, eth_dev);
313 PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x)"
314 " failed\n", pci_drv->name,
315 (unsigned) pci_dev->id.vendor_id,
316 (unsigned) pci_dev->id.device_id);
317 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
318 rte_free(eth_dev->data->dev_private);
319 eth_dev->attached = DEV_DETACHED;
325 * Register an Ethernet [Poll Mode] driver.
327 * Function invoked by the initialization function of an Ethernet driver
328 * to simultaneously register itself as a PCI driver and as an Ethernet
330 * Invokes the rte_eal_pci_register() function to register the *pci_drv*
331 * structure embedded in the *eth_drv* structure, after having stored the
332 * address of the rte_eth_dev_init() function in the *devinit* field of
333 * the *pci_drv* structure.
334 * During the PCI probing phase, the rte_eth_dev_init() function is
335 * invoked for each PCI [Ethernet device] matching the embedded PCI
336 * identifiers provided by the driver.
339 rte_eth_driver_register(struct eth_driver *eth_drv)
341 eth_drv->pci_drv.devinit = rte_eth_dev_init;
342 rte_eal_pci_register(ð_drv->pci_drv);
346 rte_eth_dev_is_valid_port(uint8_t port_id)
348 if (port_id >= RTE_MAX_ETHPORTS ||
349 rte_eth_devices[port_id].attached != DEV_ATTACHED)
356 rte_eth_dev_socket_id(uint8_t port_id)
358 if (!rte_eth_dev_is_valid_port(port_id))
360 return rte_eth_devices[port_id].pci_dev->numa_node;
364 rte_eth_dev_count(void)
370 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
372 uint16_t old_nb_queues = dev->data->nb_rx_queues;
376 if (dev->data->rx_queues == NULL) { /* first time configuration */
377 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
378 sizeof(dev->data->rx_queues[0]) * nb_queues,
379 RTE_CACHE_LINE_SIZE);
380 if (dev->data->rx_queues == NULL) {
381 dev->data->nb_rx_queues = 0;
384 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
385 dev->post_rx_burst_cbs = rte_zmalloc(
386 "ethdev->post_rx_burst_cbs",
387 sizeof(*dev->post_rx_burst_cbs) * nb_queues,
388 RTE_CACHE_LINE_SIZE);
389 if (dev->post_rx_burst_cbs == NULL) {
390 rte_free(dev->data->rx_queues);
391 dev->data->rx_queues = NULL;
392 dev->data->nb_rx_queues = 0;
397 } else { /* re-configure */
398 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
400 rxq = dev->data->rx_queues;
402 for (i = nb_queues; i < old_nb_queues; i++)
403 (*dev->dev_ops->rx_queue_release)(rxq[i]);
404 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
405 RTE_CACHE_LINE_SIZE);
408 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
409 dev->post_rx_burst_cbs = rte_realloc(
410 dev->post_rx_burst_cbs,
411 sizeof(*dev->post_rx_burst_cbs) *
412 nb_queues, RTE_CACHE_LINE_SIZE);
413 if (dev->post_rx_burst_cbs == NULL)
416 if (nb_queues > old_nb_queues) {
417 uint16_t new_qs = nb_queues - old_nb_queues;
418 memset(rxq + old_nb_queues, 0,
419 sizeof(rxq[0]) * new_qs);
420 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
421 memset(dev->post_rx_burst_cbs + old_nb_queues, 0,
422 sizeof(dev->post_rx_burst_cbs[0]) * new_qs);
426 dev->data->rx_queues = rxq;
429 dev->data->nb_rx_queues = nb_queues;
434 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
436 struct rte_eth_dev *dev;
438 /* This function is only safe when called from the primary process
439 * in a multi-process setup*/
440 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
442 if (!rte_eth_dev_is_valid_port(port_id)) {
443 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
447 dev = &rte_eth_devices[port_id];
448 if (rx_queue_id >= dev->data->nb_rx_queues) {
449 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
453 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
455 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
460 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
462 struct rte_eth_dev *dev;
464 /* This function is only safe when called from the primary process
465 * in a multi-process setup*/
466 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
468 if (!rte_eth_dev_is_valid_port(port_id)) {
469 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
473 dev = &rte_eth_devices[port_id];
474 if (rx_queue_id >= dev->data->nb_rx_queues) {
475 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
479 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
481 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
486 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
488 struct rte_eth_dev *dev;
490 /* This function is only safe when called from the primary process
491 * in a multi-process setup*/
492 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
494 if (!rte_eth_dev_is_valid_port(port_id)) {
495 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
499 dev = &rte_eth_devices[port_id];
500 if (tx_queue_id >= dev->data->nb_tx_queues) {
501 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
505 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
507 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
512 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
514 struct rte_eth_dev *dev;
516 /* This function is only safe when called from the primary process
517 * in a multi-process setup*/
518 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
520 if (!rte_eth_dev_is_valid_port(port_id)) {
521 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
525 dev = &rte_eth_devices[port_id];
526 if (tx_queue_id >= dev->data->nb_tx_queues) {
527 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
531 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
533 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
538 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
540 uint16_t old_nb_queues = dev->data->nb_tx_queues;
544 if (dev->data->tx_queues == NULL) { /* first time configuration */
545 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
546 sizeof(dev->data->tx_queues[0]) * nb_queues,
547 RTE_CACHE_LINE_SIZE);
548 if (dev->data->tx_queues == NULL) {
549 dev->data->nb_tx_queues = 0;
552 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
553 dev->pre_tx_burst_cbs = rte_zmalloc(
554 "ethdev->pre_tx_burst_cbs",
555 sizeof(*dev->pre_tx_burst_cbs) * nb_queues,
556 RTE_CACHE_LINE_SIZE);
557 if (dev->pre_tx_burst_cbs == NULL) {
558 rte_free(dev->data->tx_queues);
559 dev->data->tx_queues = NULL;
560 dev->data->nb_tx_queues = 0;
565 } else { /* re-configure */
566 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
568 txq = dev->data->tx_queues;
570 for (i = nb_queues; i < old_nb_queues; i++)
571 (*dev->dev_ops->tx_queue_release)(txq[i]);
572 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
573 RTE_CACHE_LINE_SIZE);
576 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
577 dev->pre_tx_burst_cbs = rte_realloc(
578 dev->pre_tx_burst_cbs,
579 sizeof(*dev->pre_tx_burst_cbs) *
580 nb_queues, RTE_CACHE_LINE_SIZE);
581 if (dev->pre_tx_burst_cbs == NULL)
584 if (nb_queues > old_nb_queues) {
585 uint16_t new_qs = nb_queues - old_nb_queues;
586 memset(txq + old_nb_queues, 0,
587 sizeof(txq[0]) * new_qs);
588 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
589 memset(dev->pre_tx_burst_cbs + old_nb_queues, 0,
590 sizeof(dev->pre_tx_burst_cbs[0]) * new_qs);
594 dev->data->tx_queues = txq;
597 dev->data->nb_tx_queues = nb_queues;
602 rte_eth_dev_check_vf_rss_rxq_num(uint8_t port_id, uint16_t nb_rx_q)
604 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
608 RTE_ETH_DEV_SRIOV(dev).active =
612 RTE_ETH_DEV_SRIOV(dev).active =
619 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = nb_rx_q;
620 RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx =
621 dev->pci_dev->max_vfs * nb_rx_q;
627 rte_eth_dev_check_mq_mode(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
628 const struct rte_eth_conf *dev_conf)
630 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
632 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
633 /* check multi-queue mode */
634 if ((dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) ||
635 (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB_RSS) ||
636 (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB)) {
637 /* SRIOV only works in VMDq enable mode */
638 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
640 "wrong VMDQ mq_mode rx %u tx %u\n",
642 dev_conf->rxmode.mq_mode,
643 dev_conf->txmode.mq_mode);
647 switch (dev_conf->rxmode.mq_mode) {
648 case ETH_MQ_RX_VMDQ_DCB:
649 case ETH_MQ_RX_VMDQ_DCB_RSS:
650 /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
651 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
653 "unsupported VMDQ mq_mode rx %u\n",
654 port_id, dev_conf->rxmode.mq_mode);
657 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
659 "Rx mq mode is changed from:"
660 "mq_mode %u into VMDQ mq_mode %u\n",
662 dev_conf->rxmode.mq_mode,
663 dev->data->dev_conf.rxmode.mq_mode);
664 case ETH_MQ_RX_VMDQ_RSS:
665 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_RSS;
666 if (nb_rx_q <= RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)
667 if (rte_eth_dev_check_vf_rss_rxq_num(port_id, nb_rx_q) != 0) {
668 PMD_DEBUG_TRACE("ethdev port_id=%d"
669 " SRIOV active, invalid queue"
670 " number for VMDQ RSS, allowed"
671 " value are 1, 2 or 4\n",
676 default: /* ETH_MQ_RX_VMDQ_ONLY or ETH_MQ_RX_NONE */
677 /* if nothing mq mode configure, use default scheme */
678 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
679 if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
680 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
684 switch (dev_conf->txmode.mq_mode) {
685 case ETH_MQ_TX_VMDQ_DCB:
686 /* DCB VMDQ in SRIOV mode, not implement yet */
687 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
689 "unsupported VMDQ mq_mode tx %u\n",
690 port_id, dev_conf->txmode.mq_mode);
692 default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
693 /* if nothing mq mode configure, use default scheme */
694 dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
698 /* check valid queue number */
699 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
700 (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
701 PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
702 "queue number must less equal to %d\n",
703 port_id, RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
707 /* For vmdb+dcb mode check our configuration before we go further */
708 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB) {
709 const struct rte_eth_vmdq_dcb_conf *conf;
711 if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
712 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
714 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
717 conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
718 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
719 conf->nb_queue_pools == ETH_32_POOLS)) {
720 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
721 "nb_queue_pools must be %d or %d\n",
722 port_id, ETH_16_POOLS, ETH_32_POOLS);
726 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
727 const struct rte_eth_vmdq_dcb_tx_conf *conf;
729 if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
730 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
732 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
735 conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
736 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
737 conf->nb_queue_pools == ETH_32_POOLS)) {
738 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
739 "nb_queue_pools != %d or nb_queue_pools "
741 port_id, ETH_16_POOLS, ETH_32_POOLS);
746 /* For DCB mode check our configuration before we go further */
747 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) {
748 const struct rte_eth_dcb_rx_conf *conf;
750 if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
751 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
753 port_id, ETH_DCB_NUM_QUEUES);
756 conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
757 if (! (conf->nb_tcs == ETH_4_TCS ||
758 conf->nb_tcs == ETH_8_TCS)) {
759 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
760 "nb_tcs != %d or nb_tcs "
762 port_id, ETH_4_TCS, ETH_8_TCS);
767 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
768 const struct rte_eth_dcb_tx_conf *conf;
770 if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
771 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
773 port_id, ETH_DCB_NUM_QUEUES);
776 conf = &(dev_conf->tx_adv_conf.dcb_tx_conf);
777 if (! (conf->nb_tcs == ETH_4_TCS ||
778 conf->nb_tcs == ETH_8_TCS)) {
779 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
780 "nb_tcs != %d or nb_tcs "
782 port_id, ETH_4_TCS, ETH_8_TCS);
791 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
792 const struct rte_eth_conf *dev_conf)
794 struct rte_eth_dev *dev;
795 struct rte_eth_dev_info dev_info;
798 /* This function is only safe when called from the primary process
799 * in a multi-process setup*/
800 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
802 if (!rte_eth_dev_is_valid_port(port_id)) {
803 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
807 dev = &rte_eth_devices[port_id];
809 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
810 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
812 if (dev->data->dev_started) {
814 "port %d must be stopped to allow configuration\n", port_id);
819 * Check that the numbers of RX and TX queues are not greater
820 * than the maximum number of RX and TX queues supported by the
823 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
824 if (nb_rx_q > dev_info.max_rx_queues) {
825 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
826 port_id, nb_rx_q, dev_info.max_rx_queues);
830 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
834 if (nb_tx_q > dev_info.max_tx_queues) {
835 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
836 port_id, nb_tx_q, dev_info.max_tx_queues);
840 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
844 /* Copy the dev_conf parameter into the dev structure */
845 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
848 * If link state interrupt is enabled, check that the
849 * device supports it.
851 if (dev_conf->intr_conf.lsc == 1) {
852 const struct rte_pci_driver *pci_drv = &dev->driver->pci_drv;
854 if (!(pci_drv->drv_flags & RTE_PCI_DRV_INTR_LSC)) {
855 PMD_DEBUG_TRACE("driver %s does not support lsc\n",
862 * If jumbo frames are enabled, check that the maximum RX packet
863 * length is supported by the configured device.
865 if (dev_conf->rxmode.jumbo_frame == 1) {
866 if (dev_conf->rxmode.max_rx_pkt_len >
867 dev_info.max_rx_pktlen) {
868 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
869 " > max valid value %u\n",
871 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
872 (unsigned)dev_info.max_rx_pktlen);
875 else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
876 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
877 " < min valid value %u\n",
879 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
880 (unsigned)ETHER_MIN_LEN);
884 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
885 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
886 /* Use default value */
887 dev->data->dev_conf.rxmode.max_rx_pkt_len =
891 /* multipe queue mode checking */
892 diag = rte_eth_dev_check_mq_mode(port_id, nb_rx_q, nb_tx_q, dev_conf);
894 PMD_DEBUG_TRACE("port%d rte_eth_dev_check_mq_mode = %d\n",
900 * Setup new number of RX/TX queues and reconfigure device.
902 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
904 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
909 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
911 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
913 rte_eth_dev_rx_queue_config(dev, 0);
917 diag = (*dev->dev_ops->dev_configure)(dev);
919 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
921 rte_eth_dev_rx_queue_config(dev, 0);
922 rte_eth_dev_tx_queue_config(dev, 0);
930 rte_eth_dev_config_restore(uint8_t port_id)
932 struct rte_eth_dev *dev;
933 struct rte_eth_dev_info dev_info;
934 struct ether_addr addr;
938 dev = &rte_eth_devices[port_id];
940 rte_eth_dev_info_get(port_id, &dev_info);
942 if (RTE_ETH_DEV_SRIOV(dev).active)
943 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
945 /* replay MAC address configuration */
946 for (i = 0; i < dev_info.max_mac_addrs; i++) {
947 addr = dev->data->mac_addrs[i];
949 /* skip zero address */
950 if (is_zero_ether_addr(&addr))
953 /* add address to the hardware */
954 if (*dev->dev_ops->mac_addr_add &&
955 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
956 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
958 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
960 /* exit the loop but not return an error */
965 /* replay promiscuous configuration */
966 if (rte_eth_promiscuous_get(port_id) == 1)
967 rte_eth_promiscuous_enable(port_id);
968 else if (rte_eth_promiscuous_get(port_id) == 0)
969 rte_eth_promiscuous_disable(port_id);
971 /* replay allmulticast configuration */
972 if (rte_eth_allmulticast_get(port_id) == 1)
973 rte_eth_allmulticast_enable(port_id);
974 else if (rte_eth_allmulticast_get(port_id) == 0)
975 rte_eth_allmulticast_disable(port_id);
979 rte_eth_dev_start(uint8_t port_id)
981 struct rte_eth_dev *dev;
984 /* This function is only safe when called from the primary process
985 * in a multi-process setup*/
986 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
988 if (!rte_eth_dev_is_valid_port(port_id)) {
989 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
993 dev = &rte_eth_devices[port_id];
995 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
997 if (dev->data->dev_started != 0) {
998 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
999 " already started\n",
1004 diag = (*dev->dev_ops->dev_start)(dev);
1006 dev->data->dev_started = 1;
1010 rte_eth_dev_config_restore(port_id);
1012 if (dev->data->dev_conf.intr_conf.lsc != 0) {
1013 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1014 (*dev->dev_ops->link_update)(dev, 0);
1020 rte_eth_dev_stop(uint8_t port_id)
1022 struct rte_eth_dev *dev;
1024 /* This function is only safe when called from the primary process
1025 * in a multi-process setup*/
1026 PROC_PRIMARY_OR_RET();
1028 if (!rte_eth_dev_is_valid_port(port_id)) {
1029 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1033 dev = &rte_eth_devices[port_id];
1035 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1037 if (dev->data->dev_started == 0) {
1038 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
1039 " already stopped\n",
1044 dev->data->dev_started = 0;
1045 (*dev->dev_ops->dev_stop)(dev);
1049 rte_eth_dev_set_link_up(uint8_t port_id)
1051 struct rte_eth_dev *dev;
1053 /* This function is only safe when called from the primary process
1054 * in a multi-process setup*/
1055 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1057 if (!rte_eth_dev_is_valid_port(port_id)) {
1058 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1062 dev = &rte_eth_devices[port_id];
1064 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1065 return (*dev->dev_ops->dev_set_link_up)(dev);
1069 rte_eth_dev_set_link_down(uint8_t port_id)
1071 struct rte_eth_dev *dev;
1073 /* This function is only safe when called from the primary process
1074 * in a multi-process setup*/
1075 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1077 if (!rte_eth_dev_is_valid_port(port_id)) {
1078 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1082 dev = &rte_eth_devices[port_id];
1084 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1085 return (*dev->dev_ops->dev_set_link_down)(dev);
1089 rte_eth_dev_close(uint8_t port_id)
1091 struct rte_eth_dev *dev;
1093 /* This function is only safe when called from the primary process
1094 * in a multi-process setup*/
1095 PROC_PRIMARY_OR_RET();
1097 if (!rte_eth_dev_is_valid_port(port_id)) {
1098 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1102 dev = &rte_eth_devices[port_id];
1104 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1105 dev->data->dev_started = 0;
1106 (*dev->dev_ops->dev_close)(dev);
1110 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1111 uint16_t nb_rx_desc, unsigned int socket_id,
1112 const struct rte_eth_rxconf *rx_conf,
1113 struct rte_mempool *mp)
1116 uint32_t mbp_buf_size;
1117 struct rte_eth_dev *dev;
1118 struct rte_pktmbuf_pool_private *mbp_priv;
1119 struct rte_eth_dev_info dev_info;
1121 /* This function is only safe when called from the primary process
1122 * in a multi-process setup*/
1123 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1125 if (!rte_eth_dev_is_valid_port(port_id)) {
1126 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1130 dev = &rte_eth_devices[port_id];
1131 if (rx_queue_id >= dev->data->nb_rx_queues) {
1132 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1136 if (dev->data->dev_started) {
1138 "port %d must be stopped to allow configuration\n", port_id);
1142 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1143 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1146 * Check the size of the mbuf data buffer.
1147 * This value must be provided in the private data of the memory pool.
1148 * First check that the memory pool has a valid private data.
1150 rte_eth_dev_info_get(port_id, &dev_info);
1151 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1152 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1153 mp->name, (int) mp->private_data_size,
1154 (int) sizeof(struct rte_pktmbuf_pool_private));
1157 mbp_priv = rte_mempool_get_priv(mp);
1158 mbp_buf_size = mbp_priv->mbuf_data_room_size;
1160 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1161 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1162 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1166 (int)(RTE_PKTMBUF_HEADROOM +
1167 dev_info.min_rx_bufsize),
1168 (int)RTE_PKTMBUF_HEADROOM,
1169 (int)dev_info.min_rx_bufsize);
1173 if (rx_conf == NULL)
1174 rx_conf = &dev_info.default_rxconf;
1176 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1177 socket_id, rx_conf, mp);
1179 if (!dev->data->min_rx_buf_size ||
1180 dev->data->min_rx_buf_size > mbp_buf_size)
1181 dev->data->min_rx_buf_size = mbp_buf_size;
1188 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1189 uint16_t nb_tx_desc, unsigned int socket_id,
1190 const struct rte_eth_txconf *tx_conf)
1192 struct rte_eth_dev *dev;
1193 struct rte_eth_dev_info dev_info;
1195 /* This function is only safe when called from the primary process
1196 * in a multi-process setup*/
1197 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1199 if (!rte_eth_dev_is_valid_port(port_id)) {
1200 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1204 dev = &rte_eth_devices[port_id];
1205 if (tx_queue_id >= dev->data->nb_tx_queues) {
1206 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1210 if (dev->data->dev_started) {
1212 "port %d must be stopped to allow configuration\n", port_id);
1216 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1217 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1219 rte_eth_dev_info_get(port_id, &dev_info);
1221 if (tx_conf == NULL)
1222 tx_conf = &dev_info.default_txconf;
1224 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1225 socket_id, tx_conf);
1229 rte_eth_promiscuous_enable(uint8_t port_id)
1231 struct rte_eth_dev *dev;
1233 if (!rte_eth_dev_is_valid_port(port_id)) {
1234 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1238 dev = &rte_eth_devices[port_id];
1240 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1241 (*dev->dev_ops->promiscuous_enable)(dev);
1242 dev->data->promiscuous = 1;
1246 rte_eth_promiscuous_disable(uint8_t port_id)
1248 struct rte_eth_dev *dev;
1250 if (!rte_eth_dev_is_valid_port(port_id)) {
1251 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1255 dev = &rte_eth_devices[port_id];
1257 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1258 dev->data->promiscuous = 0;
1259 (*dev->dev_ops->promiscuous_disable)(dev);
1263 rte_eth_promiscuous_get(uint8_t port_id)
1265 struct rte_eth_dev *dev;
1267 if (!rte_eth_dev_is_valid_port(port_id)) {
1268 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1272 dev = &rte_eth_devices[port_id];
1273 return dev->data->promiscuous;
1277 rte_eth_allmulticast_enable(uint8_t port_id)
1279 struct rte_eth_dev *dev;
1281 if (!rte_eth_dev_is_valid_port(port_id)) {
1282 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1286 dev = &rte_eth_devices[port_id];
1288 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1289 (*dev->dev_ops->allmulticast_enable)(dev);
1290 dev->data->all_multicast = 1;
1294 rte_eth_allmulticast_disable(uint8_t port_id)
1296 struct rte_eth_dev *dev;
1298 if (!rte_eth_dev_is_valid_port(port_id)) {
1299 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1303 dev = &rte_eth_devices[port_id];
1305 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1306 dev->data->all_multicast = 0;
1307 (*dev->dev_ops->allmulticast_disable)(dev);
1311 rte_eth_allmulticast_get(uint8_t port_id)
1313 struct rte_eth_dev *dev;
1315 if (!rte_eth_dev_is_valid_port(port_id)) {
1316 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1320 dev = &rte_eth_devices[port_id];
1321 return dev->data->all_multicast;
1325 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1326 struct rte_eth_link *link)
1328 struct rte_eth_link *dst = link;
1329 struct rte_eth_link *src = &(dev->data->dev_link);
1331 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1332 *(uint64_t *)src) == 0)
1339 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1341 struct rte_eth_dev *dev;
1343 if (!rte_eth_dev_is_valid_port(port_id)) {
1344 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1348 dev = &rte_eth_devices[port_id];
1350 if (dev->data->dev_conf.intr_conf.lsc != 0)
1351 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1353 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1354 (*dev->dev_ops->link_update)(dev, 1);
1355 *eth_link = dev->data->dev_link;
1360 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1362 struct rte_eth_dev *dev;
1364 if (!rte_eth_dev_is_valid_port(port_id)) {
1365 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1369 dev = &rte_eth_devices[port_id];
1371 if (dev->data->dev_conf.intr_conf.lsc != 0)
1372 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1374 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1375 (*dev->dev_ops->link_update)(dev, 0);
1376 *eth_link = dev->data->dev_link;
1381 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1383 struct rte_eth_dev *dev;
1385 if (!rte_eth_dev_is_valid_port(port_id)) {
1386 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1390 dev = &rte_eth_devices[port_id];
1391 memset(stats, 0, sizeof(*stats));
1393 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1394 (*dev->dev_ops->stats_get)(dev, stats);
1395 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1400 rte_eth_stats_reset(uint8_t port_id)
1402 struct rte_eth_dev *dev;
1404 if (!rte_eth_dev_is_valid_port(port_id)) {
1405 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1409 dev = &rte_eth_devices[port_id];
1411 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1412 (*dev->dev_ops->stats_reset)(dev);
1415 /* retrieve ethdev extended statistics */
1417 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1420 struct rte_eth_stats eth_stats;
1421 struct rte_eth_dev *dev;
1422 unsigned count, i, q;
1426 if (!rte_eth_dev_is_valid_port(port_id)) {
1427 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1431 dev = &rte_eth_devices[port_id];
1433 /* implemented by the driver */
1434 if (dev->dev_ops->xstats_get != NULL)
1435 return (*dev->dev_ops->xstats_get)(dev, xstats, n);
1437 /* else, return generic statistics */
1438 count = RTE_NB_STATS;
1439 count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
1440 count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
1444 /* now fill the xstats structure */
1447 memset(ð_stats, 0, sizeof(eth_stats));
1448 rte_eth_stats_get(port_id, ð_stats);
1451 for (i = 0; i < RTE_NB_STATS; i++) {
1452 stats_ptr = (char *)ð_stats + rte_stats_strings[i].offset;
1453 val = *(uint64_t *)stats_ptr;
1454 snprintf(xstats[count].name, sizeof(xstats[count].name),
1455 "%s", rte_stats_strings[i].name);
1456 xstats[count++].value = val;
1460 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1461 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1462 stats_ptr = (char *)ð_stats;
1463 stats_ptr += rte_rxq_stats_strings[i].offset;
1464 stats_ptr += q * sizeof(uint64_t);
1465 val = *(uint64_t *)stats_ptr;
1466 snprintf(xstats[count].name, sizeof(xstats[count].name),
1467 "rx_queue_%u_%s", q,
1468 rte_rxq_stats_strings[i].name);
1469 xstats[count++].value = val;
1474 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1475 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1476 stats_ptr = (char *)ð_stats;
1477 stats_ptr += rte_txq_stats_strings[i].offset;
1478 stats_ptr += q * sizeof(uint64_t);
1479 val = *(uint64_t *)stats_ptr;
1480 snprintf(xstats[count].name, sizeof(xstats[count].name),
1481 "tx_queue_%u_%s", q,
1482 rte_txq_stats_strings[i].name);
1483 xstats[count++].value = val;
1490 /* reset ethdev extended statistics */
1492 rte_eth_xstats_reset(uint8_t port_id)
1494 struct rte_eth_dev *dev;
1496 if (!rte_eth_dev_is_valid_port(port_id)) {
1497 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1501 dev = &rte_eth_devices[port_id];
1503 /* implemented by the driver */
1504 if (dev->dev_ops->xstats_reset != NULL) {
1505 (*dev->dev_ops->xstats_reset)(dev);
1509 /* fallback to default */
1510 rte_eth_stats_reset(port_id);
1514 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1517 struct rte_eth_dev *dev;
1519 if (!rte_eth_dev_is_valid_port(port_id)) {
1520 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1524 dev = &rte_eth_devices[port_id];
1526 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1527 return (*dev->dev_ops->queue_stats_mapping_set)
1528 (dev, queue_id, stat_idx, is_rx);
1533 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1536 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1542 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1545 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1551 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1553 struct rte_eth_dev *dev;
1555 if (!rte_eth_dev_is_valid_port(port_id)) {
1556 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1560 dev = &rte_eth_devices[port_id];
1562 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1564 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1565 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1566 dev_info->pci_dev = dev->pci_dev;
1568 dev_info->driver_name = dev->driver->pci_drv.name;
1572 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1574 struct rte_eth_dev *dev;
1576 if (!rte_eth_dev_is_valid_port(port_id)) {
1577 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1581 dev = &rte_eth_devices[port_id];
1582 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1587 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1589 struct rte_eth_dev *dev;
1591 if (!rte_eth_dev_is_valid_port(port_id)) {
1592 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1596 dev = &rte_eth_devices[port_id];
1597 *mtu = dev->data->mtu;
1602 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1605 struct rte_eth_dev *dev;
1607 if (!rte_eth_dev_is_valid_port(port_id)) {
1608 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1612 dev = &rte_eth_devices[port_id];
1613 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1615 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1617 dev->data->mtu = mtu;
1623 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1625 struct rte_eth_dev *dev;
1627 if (!rte_eth_dev_is_valid_port(port_id)) {
1628 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1632 dev = &rte_eth_devices[port_id];
1633 if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1634 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1638 if (vlan_id > 4095) {
1639 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1640 port_id, (unsigned) vlan_id);
1643 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1644 (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1649 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1651 struct rte_eth_dev *dev;
1653 if (!rte_eth_dev_is_valid_port(port_id)) {
1654 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1658 dev = &rte_eth_devices[port_id];
1659 if (rx_queue_id >= dev->data->nb_rx_queues) {
1660 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1664 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1665 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1671 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1673 struct rte_eth_dev *dev;
1675 if (!rte_eth_dev_is_valid_port(port_id)) {
1676 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1680 dev = &rte_eth_devices[port_id];
1681 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1682 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1688 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1690 struct rte_eth_dev *dev;
1695 if (!rte_eth_dev_is_valid_port(port_id)) {
1696 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1700 dev = &rte_eth_devices[port_id];
1702 /*check which option changed by application*/
1703 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1704 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1706 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1707 mask |= ETH_VLAN_STRIP_MASK;
1710 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1711 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1713 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1714 mask |= ETH_VLAN_FILTER_MASK;
1717 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1718 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1720 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1721 mask |= ETH_VLAN_EXTEND_MASK;
1728 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1729 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1735 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1737 struct rte_eth_dev *dev;
1740 if (!rte_eth_dev_is_valid_port(port_id)) {
1741 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1745 dev = &rte_eth_devices[port_id];
1747 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1748 ret |= ETH_VLAN_STRIP_OFFLOAD ;
1750 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1751 ret |= ETH_VLAN_FILTER_OFFLOAD ;
1753 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1754 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
1760 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1762 struct rte_eth_dev *dev;
1764 if (!rte_eth_dev_is_valid_port(port_id)) {
1765 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1769 dev = &rte_eth_devices[port_id];
1770 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1771 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1777 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1778 struct rte_fdir_filter *fdir_filter,
1781 struct rte_eth_dev *dev;
1783 if (!rte_eth_dev_is_valid_port(port_id)) {
1784 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1788 dev = &rte_eth_devices[port_id];
1790 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1791 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1792 port_id, dev->data->dev_conf.fdir_conf.mode);
1796 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1797 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1798 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1799 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1800 "None l4type, source & destinations ports " \
1801 "should be null!\n");
1805 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1806 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1811 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1812 struct rte_fdir_filter *fdir_filter,
1815 struct rte_eth_dev *dev;
1817 if (!rte_eth_dev_is_valid_port(port_id)) {
1818 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1822 dev = &rte_eth_devices[port_id];
1824 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1825 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1826 port_id, dev->data->dev_conf.fdir_conf.mode);
1830 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1831 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1832 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1833 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1834 "None l4type, source & destinations ports " \
1835 "should be null!\n");
1839 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
1840 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
1846 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
1847 struct rte_fdir_filter *fdir_filter)
1849 struct rte_eth_dev *dev;
1851 if (!rte_eth_dev_is_valid_port(port_id)) {
1852 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1856 dev = &rte_eth_devices[port_id];
1858 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1859 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1860 port_id, dev->data->dev_conf.fdir_conf.mode);
1864 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1865 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1866 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1867 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1868 "None l4type source & destinations ports " \
1869 "should be null!\n");
1873 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
1874 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
1878 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
1880 struct rte_eth_dev *dev;
1882 if (!rte_eth_dev_is_valid_port(port_id)) {
1883 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1887 dev = &rte_eth_devices[port_id];
1888 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1889 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1893 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
1895 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
1900 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
1901 struct rte_fdir_filter *fdir_filter,
1902 uint16_t soft_id, uint8_t queue,
1905 struct rte_eth_dev *dev;
1907 if (!rte_eth_dev_is_valid_port(port_id)) {
1908 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1912 dev = &rte_eth_devices[port_id];
1914 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1915 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1916 port_id, dev->data->dev_conf.fdir_conf.mode);
1920 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1921 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1922 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1923 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1924 "None l4type, source & destinations ports " \
1925 "should be null!\n");
1929 /* For now IPv6 is not supported with perfect filter */
1930 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1933 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
1934 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
1940 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
1941 struct rte_fdir_filter *fdir_filter,
1942 uint16_t soft_id, uint8_t queue,
1945 struct rte_eth_dev *dev;
1947 if (!rte_eth_dev_is_valid_port(port_id)) {
1948 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1952 dev = &rte_eth_devices[port_id];
1954 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1955 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1956 port_id, dev->data->dev_conf.fdir_conf.mode);
1960 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1961 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1962 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1963 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1964 "None l4type, source & destinations ports " \
1965 "should be null!\n");
1969 /* For now IPv6 is not supported with perfect filter */
1970 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1973 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
1974 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
1975 soft_id, queue, drop);
1979 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
1980 struct rte_fdir_filter *fdir_filter,
1983 struct rte_eth_dev *dev;
1985 if (!rte_eth_dev_is_valid_port(port_id)) {
1986 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1990 dev = &rte_eth_devices[port_id];
1992 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1993 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1994 port_id, dev->data->dev_conf.fdir_conf.mode);
1998 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1999 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
2000 && (fdir_filter->port_src || fdir_filter->port_dst)) {
2001 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
2002 "None l4type, source & destinations ports " \
2003 "should be null!\n");
2007 /* For now IPv6 is not supported with perfect filter */
2008 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
2011 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
2012 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
2017 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
2019 struct rte_eth_dev *dev;
2021 if (!rte_eth_dev_is_valid_port(port_id)) {
2022 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2026 dev = &rte_eth_devices[port_id];
2027 if (! (dev->data->dev_conf.fdir_conf.mode)) {
2028 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
2032 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
2033 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
2037 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2039 struct rte_eth_dev *dev;
2041 if (!rte_eth_dev_is_valid_port(port_id)) {
2042 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2046 dev = &rte_eth_devices[port_id];
2047 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2048 memset(fc_conf, 0, sizeof(*fc_conf));
2049 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
2053 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
2055 struct rte_eth_dev *dev;
2057 if (!rte_eth_dev_is_valid_port(port_id)) {
2058 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2062 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2063 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2067 dev = &rte_eth_devices[port_id];
2068 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2069 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
2073 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
2075 struct rte_eth_dev *dev;
2077 if (!rte_eth_dev_is_valid_port(port_id)) {
2078 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2082 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2083 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2087 dev = &rte_eth_devices[port_id];
2088 /* High water, low water validation are device specific */
2089 if (*dev->dev_ops->priority_flow_ctrl_set)
2090 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
2095 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2103 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
2104 PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
2105 RTE_RETA_GROUP_SIZE);
2109 num = reta_size / RTE_RETA_GROUP_SIZE;
2110 for (i = 0; i < num; i++) {
2111 if (reta_conf[i].mask)
2119 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2123 uint16_t i, idx, shift;
2129 PMD_DEBUG_TRACE("No receive queue is available\n");
2133 for (i = 0; i < reta_size; i++) {
2134 idx = i / RTE_RETA_GROUP_SIZE;
2135 shift = i % RTE_RETA_GROUP_SIZE;
2136 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2137 (reta_conf[idx].reta[shift] >= max_rxq)) {
2138 PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2139 "the maximum rxq index: %u\n", idx, shift,
2140 reta_conf[idx].reta[shift], max_rxq);
2149 rte_eth_dev_rss_reta_update(uint8_t port_id,
2150 struct rte_eth_rss_reta_entry64 *reta_conf,
2153 struct rte_eth_dev *dev;
2156 if (!rte_eth_dev_is_valid_port(port_id)) {
2157 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2161 /* Check mask bits */
2162 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2166 dev = &rte_eth_devices[port_id];
2168 /* Check entry value */
2169 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2170 dev->data->nb_rx_queues);
2174 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2175 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2179 rte_eth_dev_rss_reta_query(uint8_t port_id,
2180 struct rte_eth_rss_reta_entry64 *reta_conf,
2183 struct rte_eth_dev *dev;
2186 if (port_id >= nb_ports) {
2187 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2191 /* Check mask bits */
2192 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2196 dev = &rte_eth_devices[port_id];
2197 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2198 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2202 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2204 struct rte_eth_dev *dev;
2205 uint16_t rss_hash_protos;
2207 if (!rte_eth_dev_is_valid_port(port_id)) {
2208 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2212 rss_hash_protos = rss_conf->rss_hf;
2213 if ((rss_hash_protos != 0) &&
2214 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2215 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2219 dev = &rte_eth_devices[port_id];
2220 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2221 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2225 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2226 struct rte_eth_rss_conf *rss_conf)
2228 struct rte_eth_dev *dev;
2230 if (!rte_eth_dev_is_valid_port(port_id)) {
2231 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2235 dev = &rte_eth_devices[port_id];
2236 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2237 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2241 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
2242 struct rte_eth_udp_tunnel *udp_tunnel)
2244 struct rte_eth_dev *dev;
2246 if (!rte_eth_dev_is_valid_port(port_id)) {
2247 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2251 if (udp_tunnel == NULL) {
2252 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2256 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2257 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2261 dev = &rte_eth_devices[port_id];
2262 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
2263 return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
2267 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
2268 struct rte_eth_udp_tunnel *udp_tunnel)
2270 struct rte_eth_dev *dev;
2272 if (!rte_eth_dev_is_valid_port(port_id)) {
2273 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2277 dev = &rte_eth_devices[port_id];
2279 if (udp_tunnel == NULL) {
2280 PMD_DEBUG_TRACE("Invalid udp_tunnel parametr\n");
2284 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2285 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2289 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2290 return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2294 rte_eth_led_on(uint8_t port_id)
2296 struct rte_eth_dev *dev;
2298 if (!rte_eth_dev_is_valid_port(port_id)) {
2299 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2303 dev = &rte_eth_devices[port_id];
2304 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2305 return ((*dev->dev_ops->dev_led_on)(dev));
2309 rte_eth_led_off(uint8_t port_id)
2311 struct rte_eth_dev *dev;
2313 if (!rte_eth_dev_is_valid_port(port_id)) {
2314 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2318 dev = &rte_eth_devices[port_id];
2319 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2320 return ((*dev->dev_ops->dev_led_off)(dev));
2324 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2328 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2330 struct rte_eth_dev_info dev_info;
2331 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2334 rte_eth_dev_info_get(port_id, &dev_info);
2336 for (i = 0; i < dev_info.max_mac_addrs; i++)
2337 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2343 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
2346 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2349 struct rte_eth_dev *dev;
2353 if (!rte_eth_dev_is_valid_port(port_id)) {
2354 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2358 dev = &rte_eth_devices[port_id];
2359 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2361 if (is_zero_ether_addr(addr)) {
2362 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2366 if (pool >= ETH_64_POOLS) {
2367 PMD_DEBUG_TRACE("pool id must be 0-%d\n",ETH_64_POOLS - 1);
2371 index = get_mac_addr_index(port_id, addr);
2373 index = get_mac_addr_index(port_id, &null_mac_addr);
2375 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2380 pool_mask = dev->data->mac_pool_sel[index];
2382 /* Check if both MAC address and pool is alread there, and do nothing */
2383 if (pool_mask & (1ULL << pool))
2388 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2390 /* Update address in NIC data structure */
2391 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2393 /* Update pool bitmap in NIC data structure */
2394 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2400 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2402 struct rte_eth_dev *dev;
2405 if (!rte_eth_dev_is_valid_port(port_id)) {
2406 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2410 dev = &rte_eth_devices[port_id];
2411 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2413 index = get_mac_addr_index(port_id, addr);
2415 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2416 return (-EADDRINUSE);
2417 } else if (index < 0)
2418 return 0; /* Do nothing if address wasn't found */
2421 (*dev->dev_ops->mac_addr_remove)(dev, index);
2423 /* Update address in NIC data structure */
2424 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2426 /* reset pool bitmap */
2427 dev->data->mac_pool_sel[index] = 0;
2433 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2434 uint16_t rx_mode, uint8_t on)
2437 struct rte_eth_dev *dev;
2438 struct rte_eth_dev_info dev_info;
2440 if (!rte_eth_dev_is_valid_port(port_id)) {
2441 PMD_DEBUG_TRACE("set VF RX mode:Invalid port_id=%d\n",
2446 dev = &rte_eth_devices[port_id];
2447 rte_eth_dev_info_get(port_id, &dev_info);
2449 num_vfs = dev_info.max_vfs;
2452 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2457 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2460 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2461 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2465 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2469 get_hash_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2471 struct rte_eth_dev_info dev_info;
2472 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2475 rte_eth_dev_info_get(port_id, &dev_info);
2476 if (!dev->data->hash_mac_addrs)
2479 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2480 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2481 ETHER_ADDR_LEN) == 0)
2488 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2493 struct rte_eth_dev *dev;
2495 if (!rte_eth_dev_is_valid_port(port_id)) {
2496 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2501 dev = &rte_eth_devices[port_id];
2502 if (is_zero_ether_addr(addr)) {
2503 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2508 index = get_hash_mac_addr_index(port_id, addr);
2509 /* Check if it's already there, and do nothing */
2510 if ((index >= 0) && (on))
2515 PMD_DEBUG_TRACE("port %d: the MAC address was not"
2516 "set in UTA\n", port_id);
2520 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2522 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2528 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2529 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2531 /* Update address in NIC data structure */
2533 ether_addr_copy(addr,
2534 &dev->data->hash_mac_addrs[index]);
2536 ether_addr_copy(&null_mac_addr,
2537 &dev->data->hash_mac_addrs[index]);
2544 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2546 struct rte_eth_dev *dev;
2548 if (!rte_eth_dev_is_valid_port(port_id)) {
2549 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2554 dev = &rte_eth_devices[port_id];
2556 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2557 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2561 rte_eth_dev_set_vf_rx(uint8_t port_id,uint16_t vf, uint8_t on)
2564 struct rte_eth_dev *dev;
2565 struct rte_eth_dev_info dev_info;
2567 if (!rte_eth_dev_is_valid_port(port_id)) {
2568 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2572 dev = &rte_eth_devices[port_id];
2573 rte_eth_dev_info_get(port_id, &dev_info);
2575 num_vfs = dev_info.max_vfs;
2578 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2582 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2583 return (*dev->dev_ops->set_vf_rx)(dev, vf,on);
2587 rte_eth_dev_set_vf_tx(uint8_t port_id,uint16_t vf, uint8_t on)
2590 struct rte_eth_dev *dev;
2591 struct rte_eth_dev_info dev_info;
2593 if (!rte_eth_dev_is_valid_port(port_id)) {
2594 PMD_DEBUG_TRACE("set pool tx:Invalid port_id=%d\n", port_id);
2598 dev = &rte_eth_devices[port_id];
2599 rte_eth_dev_info_get(port_id, &dev_info);
2601 num_vfs = dev_info.max_vfs;
2604 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2608 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2609 return (*dev->dev_ops->set_vf_tx)(dev, vf,on);
2613 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2614 uint64_t vf_mask,uint8_t vlan_on)
2616 struct rte_eth_dev *dev;
2618 if (!rte_eth_dev_is_valid_port(port_id)) {
2619 PMD_DEBUG_TRACE("VF VLAN filter:invalid port id=%d\n",
2623 dev = &rte_eth_devices[port_id];
2625 if(vlan_id > ETHER_MAX_VLAN_ID)
2627 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2633 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2637 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2638 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2642 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2645 struct rte_eth_dev *dev;
2646 struct rte_eth_dev_info dev_info;
2647 struct rte_eth_link link;
2649 if (!rte_eth_dev_is_valid_port(port_id)) {
2650 PMD_DEBUG_TRACE("set queue rate limit:invalid port id=%d\n",
2655 dev = &rte_eth_devices[port_id];
2656 rte_eth_dev_info_get(port_id, &dev_info);
2657 link = dev->data->dev_link;
2659 if (queue_idx > dev_info.max_tx_queues) {
2660 PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2661 "invalid queue id=%d\n", port_id, queue_idx);
2665 if (tx_rate > link.link_speed) {
2666 PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2667 "bigger than link speed= %d\n",
2668 tx_rate, link.link_speed);
2672 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2673 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2676 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2679 struct rte_eth_dev *dev;
2680 struct rte_eth_dev_info dev_info;
2681 struct rte_eth_link link;
2686 if (!rte_eth_dev_is_valid_port(port_id)) {
2687 PMD_DEBUG_TRACE("set VF rate limit:invalid port id=%d\n",
2692 dev = &rte_eth_devices[port_id];
2693 rte_eth_dev_info_get(port_id, &dev_info);
2694 link = dev->data->dev_link;
2696 if (vf > dev_info.max_vfs) {
2697 PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2698 "invalid vf id=%d\n", port_id, vf);
2702 if (tx_rate > link.link_speed) {
2703 PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2704 "bigger than link speed= %d\n",
2705 tx_rate, link.link_speed);
2709 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2710 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2714 rte_eth_mirror_rule_set(uint8_t port_id,
2715 struct rte_eth_vmdq_mirror_conf *mirror_conf,
2716 uint8_t rule_id, uint8_t on)
2718 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2720 if (!rte_eth_dev_is_valid_port(port_id)) {
2721 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2725 if (mirror_conf->rule_type_mask == 0) {
2726 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2730 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2731 PMD_DEBUG_TRACE("Invalid dst pool, pool id must"
2732 "be 0-%d\n",ETH_64_POOLS - 1);
2736 if ((mirror_conf->rule_type_mask & ETH_VMDQ_POOL_MIRROR) &&
2737 (mirror_conf->pool_mask == 0)) {
2738 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not"
2743 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2745 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2746 ETH_VMDQ_NUM_MIRROR_RULE - 1);
2750 dev = &rte_eth_devices[port_id];
2751 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2753 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2757 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2759 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2761 if (!rte_eth_dev_is_valid_port(port_id)) {
2762 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2766 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2768 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2769 ETH_VMDQ_NUM_MIRROR_RULE-1);
2773 dev = &rte_eth_devices[port_id];
2774 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2776 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2779 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2781 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2782 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2784 struct rte_eth_dev *dev;
2786 if (!rte_eth_dev_is_valid_port(port_id)) {
2787 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2791 dev = &rte_eth_devices[port_id];
2792 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);
2793 if (queue_id >= dev->data->nb_rx_queues) {
2794 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2797 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2802 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2803 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2805 struct rte_eth_dev *dev;
2807 if (!rte_eth_dev_is_valid_port(port_id)) {
2808 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2812 dev = &rte_eth_devices[port_id];
2814 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0);
2815 if (queue_id >= dev->data->nb_tx_queues) {
2816 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2819 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2824 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2826 struct rte_eth_dev *dev;
2828 if (!rte_eth_dev_is_valid_port(port_id)) {
2829 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2833 dev = &rte_eth_devices[port_id];
2834 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0);
2835 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2839 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2841 struct rte_eth_dev *dev;
2843 if (!rte_eth_dev_is_valid_port(port_id)) {
2844 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2848 dev = &rte_eth_devices[port_id];
2849 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2850 return (*dev->dev_ops->rx_descriptor_done)( \
2851 dev->data->rx_queues[queue_id], offset);
2856 rte_eth_dev_callback_register(uint8_t port_id,
2857 enum rte_eth_event_type event,
2858 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2860 struct rte_eth_dev *dev;
2861 struct rte_eth_dev_callback *user_cb;
2866 if (!rte_eth_dev_is_valid_port(port_id)) {
2867 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2871 dev = &rte_eth_devices[port_id];
2872 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2874 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2875 if (user_cb->cb_fn == cb_fn &&
2876 user_cb->cb_arg == cb_arg &&
2877 user_cb->event == event) {
2882 /* create a new callback. */
2883 if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2884 sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
2885 user_cb->cb_fn = cb_fn;
2886 user_cb->cb_arg = cb_arg;
2887 user_cb->event = event;
2888 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2891 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2892 return ((user_cb == NULL) ? -ENOMEM : 0);
2896 rte_eth_dev_callback_unregister(uint8_t port_id,
2897 enum rte_eth_event_type event,
2898 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2901 struct rte_eth_dev *dev;
2902 struct rte_eth_dev_callback *cb, *next;
2907 if (!rte_eth_dev_is_valid_port(port_id)) {
2908 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2912 dev = &rte_eth_devices[port_id];
2913 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2916 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2918 next = TAILQ_NEXT(cb, next);
2920 if (cb->cb_fn != cb_fn || cb->event != event ||
2921 (cb->cb_arg != (void *)-1 &&
2922 cb->cb_arg != cb_arg))
2926 * if this callback is not executing right now,
2929 if (cb->active == 0) {
2930 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2937 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2942 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2943 enum rte_eth_event_type event)
2945 struct rte_eth_dev_callback *cb_lst;
2946 struct rte_eth_dev_callback dev_cb;
2948 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2949 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2950 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2954 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2955 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2957 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2960 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2962 #ifdef RTE_NIC_BYPASS
2963 int rte_eth_dev_bypass_init(uint8_t port_id)
2965 struct rte_eth_dev *dev;
2967 if (!rte_eth_dev_is_valid_port(port_id)) {
2968 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2972 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2973 PMD_DEBUG_TRACE("Invalid port device\n");
2977 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2978 (*dev->dev_ops->bypass_init)(dev);
2983 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2985 struct rte_eth_dev *dev;
2987 if (!rte_eth_dev_is_valid_port(port_id)) {
2988 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2992 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2993 PMD_DEBUG_TRACE("Invalid port device\n");
2996 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2997 (*dev->dev_ops->bypass_state_show)(dev, state);
3002 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
3004 struct rte_eth_dev *dev;
3006 if (!rte_eth_dev_is_valid_port(port_id)) {
3007 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3011 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3012 PMD_DEBUG_TRACE("Invalid port device\n");
3016 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
3017 (*dev->dev_ops->bypass_state_set)(dev, new_state);
3022 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
3024 struct rte_eth_dev *dev;
3026 if (!rte_eth_dev_is_valid_port(port_id)) {
3027 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3031 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3032 PMD_DEBUG_TRACE("Invalid port device\n");
3036 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
3037 (*dev->dev_ops->bypass_event_show)(dev, event, state);
3042 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
3044 struct rte_eth_dev *dev;
3046 if (!rte_eth_dev_is_valid_port(port_id)) {
3047 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3051 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3052 PMD_DEBUG_TRACE("Invalid port device\n");
3056 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
3057 (*dev->dev_ops->bypass_event_set)(dev, event, state);
3062 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
3064 struct rte_eth_dev *dev;
3066 if (!rte_eth_dev_is_valid_port(port_id)) {
3067 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3071 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3072 PMD_DEBUG_TRACE("Invalid port device\n");
3076 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
3077 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
3082 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
3084 struct rte_eth_dev *dev;
3086 if (!rte_eth_dev_is_valid_port(port_id)) {
3087 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3091 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3092 PMD_DEBUG_TRACE("Invalid port device\n");
3096 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
3097 (*dev->dev_ops->bypass_ver_show)(dev, ver);
3102 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
3104 struct rte_eth_dev *dev;
3106 if (!rte_eth_dev_is_valid_port(port_id)) {
3107 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3111 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3112 PMD_DEBUG_TRACE("Invalid port device\n");
3116 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
3117 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
3122 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
3124 struct rte_eth_dev *dev;
3126 if (!rte_eth_dev_is_valid_port(port_id)) {
3127 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3131 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3132 PMD_DEBUG_TRACE("Invalid port device\n");
3136 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
3137 (*dev->dev_ops->bypass_wd_reset)(dev);
3143 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
3145 struct rte_eth_dev *dev;
3147 if (!rte_eth_dev_is_valid_port(port_id)) {
3148 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3152 dev = &rte_eth_devices[port_id];
3153 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3154 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3155 RTE_ETH_FILTER_NOP, NULL);
3159 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
3160 enum rte_filter_op filter_op, void *arg)
3162 struct rte_eth_dev *dev;
3164 if (!rte_eth_dev_is_valid_port(port_id)) {
3165 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3169 dev = &rte_eth_devices[port_id];
3170 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3171 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
3175 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
3176 rte_rxtx_callback_fn fn, void *user_param)
3178 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3179 rte_errno = ENOTSUP;
3182 /* check input parameters */
3183 if (port_id >= nb_ports || fn == NULL ||
3184 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3189 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3197 cb->param = user_param;
3198 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3199 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3204 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
3205 rte_rxtx_callback_fn fn, void *user_param)
3207 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3208 rte_errno = ENOTSUP;
3211 /* check input parameters */
3212 if (port_id >= nb_ports || fn == NULL ||
3213 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3218 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3226 cb->param = user_param;
3227 cb->next = rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3228 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3233 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3234 struct rte_eth_rxtx_callback *user_cb)
3236 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3239 /* Check input parameters. */
3240 if (port_id >= nb_ports || user_cb == NULL ||
3241 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3245 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3246 struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
3247 struct rte_eth_rxtx_callback *prev_cb;
3249 /* Reset head pointer and remove user cb if first in the list. */
3250 if (cb == user_cb) {
3251 dev->post_rx_burst_cbs[queue_id] = user_cb->next;
3255 /* Remove the user cb from the callback list. */
3260 if (cb == user_cb) {
3261 prev_cb->next = user_cb->next;
3265 } while (cb != NULL);
3267 /* Callback wasn't found. */
3272 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3273 struct rte_eth_rxtx_callback *user_cb)
3275 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3278 /* Check input parameters. */
3279 if (port_id >= nb_ports || user_cb == NULL ||
3280 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3284 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3285 struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
3286 struct rte_eth_rxtx_callback *prev_cb;
3288 /* Reset head pointer and remove user cb if first in the list. */
3289 if (cb == user_cb) {
3290 dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
3294 /* Remove the user cb from the callback list. */
3299 if (cb == user_cb) {
3300 prev_cb->next = user_cb->next;
3304 } while (cb != NULL);
3306 /* Callback wasn't found. */