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 */
179 rte_eth_dev_data_alloc(void)
181 const unsigned flags = 0;
182 const struct rte_memzone *mz;
184 if (rte_eal_process_type() == RTE_PROC_PRIMARY){
185 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
186 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
187 rte_socket_id(), flags);
189 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
191 rte_panic("Cannot allocate memzone for ethernet port data\n");
193 rte_eth_dev_data = mz->addr;
194 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
195 memset(rte_eth_dev_data, 0,
196 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
199 static struct rte_eth_dev *
200 rte_eth_dev_allocated(const char *name)
204 for (i = 0; i < nb_ports; i++) {
205 if (strcmp(rte_eth_devices[i].data->name, name) == 0)
206 return &rte_eth_devices[i];
212 rte_eth_dev_allocate(const char *name)
214 struct rte_eth_dev *eth_dev;
216 if (nb_ports == RTE_MAX_ETHPORTS) {
217 PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
221 if (rte_eth_dev_data == NULL)
222 rte_eth_dev_data_alloc();
224 if (rte_eth_dev_allocated(name) != NULL) {
225 PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n", name);
229 eth_dev = &rte_eth_devices[nb_ports];
230 eth_dev->data = &rte_eth_dev_data[nb_ports];
231 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
232 eth_dev->data->port_id = nb_ports++;
237 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
238 struct rte_pci_device *pci_dev)
240 struct eth_driver *eth_drv;
241 struct rte_eth_dev *eth_dev;
242 char ethdev_name[RTE_ETH_NAME_MAX_LEN];
246 eth_drv = (struct eth_driver *)pci_drv;
248 /* Create unique Ethernet device name using PCI address */
249 snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "%d:%d.%d",
250 pci_dev->addr.bus, pci_dev->addr.devid, pci_dev->addr.function);
252 eth_dev = rte_eth_dev_allocate(ethdev_name);
256 if (rte_eal_process_type() == RTE_PROC_PRIMARY){
257 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
258 eth_drv->dev_private_size,
259 RTE_CACHE_LINE_SIZE);
260 if (eth_dev->data->dev_private == NULL)
261 rte_panic("Cannot allocate memzone for private port data\n");
263 eth_dev->pci_dev = pci_dev;
264 eth_dev->driver = eth_drv;
265 eth_dev->data->rx_mbuf_alloc_failed = 0;
267 /* init user callbacks */
268 TAILQ_INIT(&(eth_dev->link_intr_cbs));
271 * Set the default MTU.
273 eth_dev->data->mtu = ETHER_MTU;
275 /* Invoke PMD device initialization function */
276 diag = (*eth_drv->eth_dev_init)(eth_drv, eth_dev);
280 PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x)"
281 " failed\n", pci_drv->name,
282 (unsigned) pci_dev->id.vendor_id,
283 (unsigned) pci_dev->id.device_id);
284 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
285 rte_free(eth_dev->data->dev_private);
291 * Register an Ethernet [Poll Mode] driver.
293 * Function invoked by the initialization function of an Ethernet driver
294 * to simultaneously register itself as a PCI driver and as an Ethernet
296 * Invokes the rte_eal_pci_register() function to register the *pci_drv*
297 * structure embedded in the *eth_drv* structure, after having stored the
298 * address of the rte_eth_dev_init() function in the *devinit* field of
299 * the *pci_drv* structure.
300 * During the PCI probing phase, the rte_eth_dev_init() function is
301 * invoked for each PCI [Ethernet device] matching the embedded PCI
302 * identifiers provided by the driver.
305 rte_eth_driver_register(struct eth_driver *eth_drv)
307 eth_drv->pci_drv.devinit = rte_eth_dev_init;
308 rte_eal_pci_register(ð_drv->pci_drv);
312 rte_eth_dev_socket_id(uint8_t port_id)
314 if (port_id >= nb_ports)
316 return rte_eth_devices[port_id].pci_dev->numa_node;
320 rte_eth_dev_count(void)
326 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
328 uint16_t old_nb_queues = dev->data->nb_rx_queues;
332 if (dev->data->rx_queues == NULL) { /* first time configuration */
333 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
334 sizeof(dev->data->rx_queues[0]) * nb_queues,
335 RTE_CACHE_LINE_SIZE);
336 if (dev->data->rx_queues == NULL) {
337 dev->data->nb_rx_queues = 0;
340 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
341 dev->post_rx_burst_cbs = rte_zmalloc(
342 "ethdev->post_rx_burst_cbs",
343 sizeof(*dev->post_rx_burst_cbs) * nb_queues,
344 RTE_CACHE_LINE_SIZE);
345 if (dev->post_rx_burst_cbs == NULL) {
346 rte_free(dev->data->rx_queues);
347 dev->data->rx_queues = NULL;
348 dev->data->nb_rx_queues = 0;
353 } else { /* re-configure */
354 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
356 rxq = dev->data->rx_queues;
358 for (i = nb_queues; i < old_nb_queues; i++)
359 (*dev->dev_ops->rx_queue_release)(rxq[i]);
360 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
361 RTE_CACHE_LINE_SIZE);
364 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
365 dev->post_rx_burst_cbs = rte_realloc(
366 dev->post_rx_burst_cbs,
367 sizeof(*dev->post_rx_burst_cbs) *
368 nb_queues, RTE_CACHE_LINE_SIZE);
369 if (dev->post_rx_burst_cbs == NULL)
372 if (nb_queues > old_nb_queues) {
373 uint16_t new_qs = nb_queues - old_nb_queues;
374 memset(rxq + old_nb_queues, 0,
375 sizeof(rxq[0]) * new_qs);
376 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
377 memset(dev->post_rx_burst_cbs + old_nb_queues, 0,
378 sizeof(dev->post_rx_burst_cbs[0]) * new_qs);
382 dev->data->rx_queues = rxq;
385 dev->data->nb_rx_queues = nb_queues;
390 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
392 struct rte_eth_dev *dev;
394 /* This function is only safe when called from the primary process
395 * in a multi-process setup*/
396 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
398 if (port_id >= nb_ports) {
399 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
403 dev = &rte_eth_devices[port_id];
404 if (rx_queue_id >= dev->data->nb_rx_queues) {
405 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
409 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
411 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
416 rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
418 struct rte_eth_dev *dev;
420 /* This function is only safe when called from the primary process
421 * in a multi-process setup*/
422 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
424 if (port_id >= nb_ports) {
425 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
429 dev = &rte_eth_devices[port_id];
430 if (rx_queue_id >= dev->data->nb_rx_queues) {
431 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
435 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
437 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
442 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
444 struct rte_eth_dev *dev;
446 /* This function is only safe when called from the primary process
447 * in a multi-process setup*/
448 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
450 if (port_id >= nb_ports) {
451 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
455 dev = &rte_eth_devices[port_id];
456 if (tx_queue_id >= dev->data->nb_tx_queues) {
457 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
461 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
463 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
468 rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
470 struct rte_eth_dev *dev;
472 /* This function is only safe when called from the primary process
473 * in a multi-process setup*/
474 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
476 if (port_id >= nb_ports) {
477 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
481 dev = &rte_eth_devices[port_id];
482 if (tx_queue_id >= dev->data->nb_tx_queues) {
483 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
487 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
489 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
494 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
496 uint16_t old_nb_queues = dev->data->nb_tx_queues;
500 if (dev->data->tx_queues == NULL) { /* first time configuration */
501 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
502 sizeof(dev->data->tx_queues[0]) * nb_queues,
503 RTE_CACHE_LINE_SIZE);
504 if (dev->data->tx_queues == NULL) {
505 dev->data->nb_tx_queues = 0;
508 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
509 dev->pre_tx_burst_cbs = rte_zmalloc(
510 "ethdev->pre_tx_burst_cbs",
511 sizeof(*dev->pre_tx_burst_cbs) * nb_queues,
512 RTE_CACHE_LINE_SIZE);
513 if (dev->pre_tx_burst_cbs == NULL) {
514 rte_free(dev->data->tx_queues);
515 dev->data->tx_queues = NULL;
516 dev->data->nb_tx_queues = 0;
521 } else { /* re-configure */
522 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
524 txq = dev->data->tx_queues;
526 for (i = nb_queues; i < old_nb_queues; i++)
527 (*dev->dev_ops->tx_queue_release)(txq[i]);
528 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
529 RTE_CACHE_LINE_SIZE);
532 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
533 dev->pre_tx_burst_cbs = rte_realloc(
534 dev->pre_tx_burst_cbs,
535 sizeof(*dev->pre_tx_burst_cbs) *
536 nb_queues, RTE_CACHE_LINE_SIZE);
537 if (dev->pre_tx_burst_cbs == NULL)
540 if (nb_queues > old_nb_queues) {
541 uint16_t new_qs = nb_queues - old_nb_queues;
542 memset(txq + old_nb_queues, 0,
543 sizeof(txq[0]) * new_qs);
544 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
545 memset(dev->pre_tx_burst_cbs + old_nb_queues, 0,
546 sizeof(dev->pre_tx_burst_cbs[0]) * new_qs);
550 dev->data->tx_queues = txq;
553 dev->data->nb_tx_queues = nb_queues;
558 rte_eth_dev_check_vf_rss_rxq_num(uint8_t port_id, uint16_t nb_rx_q)
560 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
564 RTE_ETH_DEV_SRIOV(dev).active =
568 RTE_ETH_DEV_SRIOV(dev).active =
575 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = nb_rx_q;
576 RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx =
577 dev->pci_dev->max_vfs * nb_rx_q;
583 rte_eth_dev_check_mq_mode(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
584 const struct rte_eth_conf *dev_conf)
586 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
588 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
589 /* check multi-queue mode */
590 if ((dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) ||
591 (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB_RSS) ||
592 (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB)) {
593 /* SRIOV only works in VMDq enable mode */
594 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
596 "wrong VMDQ mq_mode rx %u tx %u\n",
598 dev_conf->rxmode.mq_mode,
599 dev_conf->txmode.mq_mode);
603 switch (dev_conf->rxmode.mq_mode) {
604 case ETH_MQ_RX_VMDQ_DCB:
605 case ETH_MQ_RX_VMDQ_DCB_RSS:
606 /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
607 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
609 "unsupported VMDQ mq_mode rx %u\n",
610 port_id, dev_conf->rxmode.mq_mode);
613 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
615 "Rx mq mode is changed from:"
616 "mq_mode %u into VMDQ mq_mode %u\n",
618 dev_conf->rxmode.mq_mode,
619 dev->data->dev_conf.rxmode.mq_mode);
620 case ETH_MQ_RX_VMDQ_RSS:
621 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_RSS;
622 if (nb_rx_q <= RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)
623 if (rte_eth_dev_check_vf_rss_rxq_num(port_id, nb_rx_q) != 0) {
624 PMD_DEBUG_TRACE("ethdev port_id=%d"
625 " SRIOV active, invalid queue"
626 " number for VMDQ RSS, allowed"
627 " value are 1, 2 or 4\n",
632 default: /* ETH_MQ_RX_VMDQ_ONLY or ETH_MQ_RX_NONE */
633 /* if nothing mq mode configure, use default scheme */
634 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
635 if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
636 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
640 switch (dev_conf->txmode.mq_mode) {
641 case ETH_MQ_TX_VMDQ_DCB:
642 /* DCB VMDQ in SRIOV mode, not implement yet */
643 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
645 "unsupported VMDQ mq_mode tx %u\n",
646 port_id, dev_conf->txmode.mq_mode);
648 default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
649 /* if nothing mq mode configure, use default scheme */
650 dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
654 /* check valid queue number */
655 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
656 (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
657 PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
658 "queue number must less equal to %d\n",
659 port_id, RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
663 /* For vmdb+dcb mode check our configuration before we go further */
664 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB) {
665 const struct rte_eth_vmdq_dcb_conf *conf;
667 if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
668 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
670 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
673 conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
674 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
675 conf->nb_queue_pools == ETH_32_POOLS)) {
676 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
677 "nb_queue_pools must be %d or %d\n",
678 port_id, ETH_16_POOLS, ETH_32_POOLS);
682 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
683 const struct rte_eth_vmdq_dcb_tx_conf *conf;
685 if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
686 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
688 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
691 conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
692 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
693 conf->nb_queue_pools == ETH_32_POOLS)) {
694 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
695 "nb_queue_pools != %d or nb_queue_pools "
697 port_id, ETH_16_POOLS, ETH_32_POOLS);
702 /* For DCB mode check our configuration before we go further */
703 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) {
704 const struct rte_eth_dcb_rx_conf *conf;
706 if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
707 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
709 port_id, ETH_DCB_NUM_QUEUES);
712 conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
713 if (! (conf->nb_tcs == ETH_4_TCS ||
714 conf->nb_tcs == ETH_8_TCS)) {
715 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
716 "nb_tcs != %d or nb_tcs "
718 port_id, ETH_4_TCS, ETH_8_TCS);
723 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
724 const struct rte_eth_dcb_tx_conf *conf;
726 if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
727 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
729 port_id, ETH_DCB_NUM_QUEUES);
732 conf = &(dev_conf->tx_adv_conf.dcb_tx_conf);
733 if (! (conf->nb_tcs == ETH_4_TCS ||
734 conf->nb_tcs == ETH_8_TCS)) {
735 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
736 "nb_tcs != %d or nb_tcs "
738 port_id, ETH_4_TCS, ETH_8_TCS);
747 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
748 const struct rte_eth_conf *dev_conf)
750 struct rte_eth_dev *dev;
751 struct rte_eth_dev_info dev_info;
754 /* This function is only safe when called from the primary process
755 * in a multi-process setup*/
756 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
758 if (port_id >= nb_ports || port_id >= RTE_MAX_ETHPORTS) {
759 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
762 dev = &rte_eth_devices[port_id];
764 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
765 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
767 if (dev->data->dev_started) {
769 "port %d must be stopped to allow configuration\n", port_id);
774 * Check that the numbers of RX and TX queues are not greater
775 * than the maximum number of RX and TX queues supported by the
778 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
779 if (nb_rx_q > dev_info.max_rx_queues) {
780 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
781 port_id, nb_rx_q, dev_info.max_rx_queues);
785 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
789 if (nb_tx_q > dev_info.max_tx_queues) {
790 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
791 port_id, nb_tx_q, dev_info.max_tx_queues);
795 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
799 /* Copy the dev_conf parameter into the dev structure */
800 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
803 * If link state interrupt is enabled, check that the
804 * device supports it.
806 if (dev_conf->intr_conf.lsc == 1) {
807 const struct rte_pci_driver *pci_drv = &dev->driver->pci_drv;
809 if (!(pci_drv->drv_flags & RTE_PCI_DRV_INTR_LSC)) {
810 PMD_DEBUG_TRACE("driver %s does not support lsc\n",
817 * If jumbo frames are enabled, check that the maximum RX packet
818 * length is supported by the configured device.
820 if (dev_conf->rxmode.jumbo_frame == 1) {
821 if (dev_conf->rxmode.max_rx_pkt_len >
822 dev_info.max_rx_pktlen) {
823 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
824 " > max valid value %u\n",
826 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
827 (unsigned)dev_info.max_rx_pktlen);
830 else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
831 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
832 " < min valid value %u\n",
834 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
835 (unsigned)ETHER_MIN_LEN);
839 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
840 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
841 /* Use default value */
842 dev->data->dev_conf.rxmode.max_rx_pkt_len =
846 /* multipe queue mode checking */
847 diag = rte_eth_dev_check_mq_mode(port_id, nb_rx_q, nb_tx_q, dev_conf);
849 PMD_DEBUG_TRACE("port%d rte_eth_dev_check_mq_mode = %d\n",
855 * Setup new number of RX/TX queues and reconfigure device.
857 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
859 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
864 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
866 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
868 rte_eth_dev_rx_queue_config(dev, 0);
872 diag = (*dev->dev_ops->dev_configure)(dev);
874 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
876 rte_eth_dev_rx_queue_config(dev, 0);
877 rte_eth_dev_tx_queue_config(dev, 0);
885 rte_eth_dev_config_restore(uint8_t port_id)
887 struct rte_eth_dev *dev;
888 struct rte_eth_dev_info dev_info;
889 struct ether_addr addr;
893 dev = &rte_eth_devices[port_id];
895 rte_eth_dev_info_get(port_id, &dev_info);
897 if (RTE_ETH_DEV_SRIOV(dev).active)
898 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
900 /* replay MAC address configuration */
901 for (i = 0; i < dev_info.max_mac_addrs; i++) {
902 addr = dev->data->mac_addrs[i];
904 /* skip zero address */
905 if (is_zero_ether_addr(&addr))
908 /* add address to the hardware */
909 if (*dev->dev_ops->mac_addr_add &&
910 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
911 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
913 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
915 /* exit the loop but not return an error */
920 /* replay promiscuous configuration */
921 if (rte_eth_promiscuous_get(port_id) == 1)
922 rte_eth_promiscuous_enable(port_id);
923 else if (rte_eth_promiscuous_get(port_id) == 0)
924 rte_eth_promiscuous_disable(port_id);
926 /* replay allmulticast configuration */
927 if (rte_eth_allmulticast_get(port_id) == 1)
928 rte_eth_allmulticast_enable(port_id);
929 else if (rte_eth_allmulticast_get(port_id) == 0)
930 rte_eth_allmulticast_disable(port_id);
934 rte_eth_dev_start(uint8_t port_id)
936 struct rte_eth_dev *dev;
939 /* This function is only safe when called from the primary process
940 * in a multi-process setup*/
941 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
943 if (port_id >= nb_ports) {
944 PMD_DEBUG_TRACE("Invalid port_id=%" PRIu8 "\n", port_id);
947 dev = &rte_eth_devices[port_id];
949 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
951 if (dev->data->dev_started != 0) {
952 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
953 " already started\n",
958 diag = (*dev->dev_ops->dev_start)(dev);
960 dev->data->dev_started = 1;
964 rte_eth_dev_config_restore(port_id);
966 if (dev->data->dev_conf.intr_conf.lsc != 0) {
967 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
968 (*dev->dev_ops->link_update)(dev, 0);
974 rte_eth_dev_stop(uint8_t port_id)
976 struct rte_eth_dev *dev;
978 /* This function is only safe when called from the primary process
979 * in a multi-process setup*/
980 PROC_PRIMARY_OR_RET();
982 if (port_id >= nb_ports) {
983 PMD_DEBUG_TRACE("Invalid port_id=%" PRIu8 "\n", port_id);
986 dev = &rte_eth_devices[port_id];
988 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
990 if (dev->data->dev_started == 0) {
991 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
992 " already stopped\n",
997 dev->data->dev_started = 0;
998 (*dev->dev_ops->dev_stop)(dev);
1002 rte_eth_dev_set_link_up(uint8_t port_id)
1004 struct rte_eth_dev *dev;
1006 /* This function is only safe when called from the primary process
1007 * in a multi-process setup*/
1008 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1010 if (port_id >= nb_ports) {
1011 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1014 dev = &rte_eth_devices[port_id];
1016 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1017 return (*dev->dev_ops->dev_set_link_up)(dev);
1021 rte_eth_dev_set_link_down(uint8_t port_id)
1023 struct rte_eth_dev *dev;
1025 /* This function is only safe when called from the primary process
1026 * in a multi-process setup*/
1027 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1029 if (port_id >= nb_ports) {
1030 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1033 dev = &rte_eth_devices[port_id];
1035 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1036 return (*dev->dev_ops->dev_set_link_down)(dev);
1040 rte_eth_dev_close(uint8_t port_id)
1042 struct rte_eth_dev *dev;
1044 /* This function is only safe when called from the primary process
1045 * in a multi-process setup*/
1046 PROC_PRIMARY_OR_RET();
1048 if (port_id >= nb_ports) {
1049 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1053 dev = &rte_eth_devices[port_id];
1055 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1056 dev->data->dev_started = 0;
1057 (*dev->dev_ops->dev_close)(dev);
1061 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1062 uint16_t nb_rx_desc, unsigned int socket_id,
1063 const struct rte_eth_rxconf *rx_conf,
1064 struct rte_mempool *mp)
1067 uint32_t mbp_buf_size;
1068 struct rte_eth_dev *dev;
1069 struct rte_pktmbuf_pool_private *mbp_priv;
1070 struct rte_eth_dev_info dev_info;
1072 /* This function is only safe when called from the primary process
1073 * in a multi-process setup*/
1074 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1076 if (port_id >= nb_ports) {
1077 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1080 dev = &rte_eth_devices[port_id];
1081 if (rx_queue_id >= dev->data->nb_rx_queues) {
1082 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1086 if (dev->data->dev_started) {
1088 "port %d must be stopped to allow configuration\n", port_id);
1092 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1093 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1096 * Check the size of the mbuf data buffer.
1097 * This value must be provided in the private data of the memory pool.
1098 * First check that the memory pool has a valid private data.
1100 rte_eth_dev_info_get(port_id, &dev_info);
1101 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1102 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1103 mp->name, (int) mp->private_data_size,
1104 (int) sizeof(struct rte_pktmbuf_pool_private));
1107 mbp_priv = rte_mempool_get_priv(mp);
1108 mbp_buf_size = mbp_priv->mbuf_data_room_size;
1110 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1111 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1112 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1116 (int)(RTE_PKTMBUF_HEADROOM +
1117 dev_info.min_rx_bufsize),
1118 (int)RTE_PKTMBUF_HEADROOM,
1119 (int)dev_info.min_rx_bufsize);
1123 if (rx_conf == NULL)
1124 rx_conf = &dev_info.default_rxconf;
1126 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1127 socket_id, rx_conf, mp);
1129 if (!dev->data->min_rx_buf_size ||
1130 dev->data->min_rx_buf_size > mbp_buf_size)
1131 dev->data->min_rx_buf_size = mbp_buf_size;
1138 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1139 uint16_t nb_tx_desc, unsigned int socket_id,
1140 const struct rte_eth_txconf *tx_conf)
1142 struct rte_eth_dev *dev;
1143 struct rte_eth_dev_info dev_info;
1145 /* This function is only safe when called from the primary process
1146 * in a multi-process setup*/
1147 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1149 if (port_id >= RTE_MAX_ETHPORTS || port_id >= nb_ports) {
1150 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1153 dev = &rte_eth_devices[port_id];
1154 if (tx_queue_id >= dev->data->nb_tx_queues) {
1155 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1159 if (dev->data->dev_started) {
1161 "port %d must be stopped to allow configuration\n", port_id);
1165 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1166 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1168 rte_eth_dev_info_get(port_id, &dev_info);
1170 if (tx_conf == NULL)
1171 tx_conf = &dev_info.default_txconf;
1173 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1174 socket_id, tx_conf);
1178 rte_eth_promiscuous_enable(uint8_t port_id)
1180 struct rte_eth_dev *dev;
1182 if (port_id >= nb_ports) {
1183 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1186 dev = &rte_eth_devices[port_id];
1188 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1189 (*dev->dev_ops->promiscuous_enable)(dev);
1190 dev->data->promiscuous = 1;
1194 rte_eth_promiscuous_disable(uint8_t port_id)
1196 struct rte_eth_dev *dev;
1198 if (port_id >= nb_ports) {
1199 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1202 dev = &rte_eth_devices[port_id];
1204 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1205 dev->data->promiscuous = 0;
1206 (*dev->dev_ops->promiscuous_disable)(dev);
1210 rte_eth_promiscuous_get(uint8_t port_id)
1212 struct rte_eth_dev *dev;
1214 if (port_id >= nb_ports) {
1215 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1219 dev = &rte_eth_devices[port_id];
1220 return dev->data->promiscuous;
1224 rte_eth_allmulticast_enable(uint8_t port_id)
1226 struct rte_eth_dev *dev;
1228 if (port_id >= nb_ports) {
1229 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1232 dev = &rte_eth_devices[port_id];
1234 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1235 (*dev->dev_ops->allmulticast_enable)(dev);
1236 dev->data->all_multicast = 1;
1240 rte_eth_allmulticast_disable(uint8_t port_id)
1242 struct rte_eth_dev *dev;
1244 if (port_id >= nb_ports) {
1245 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1248 dev = &rte_eth_devices[port_id];
1250 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1251 dev->data->all_multicast = 0;
1252 (*dev->dev_ops->allmulticast_disable)(dev);
1256 rte_eth_allmulticast_get(uint8_t port_id)
1258 struct rte_eth_dev *dev;
1260 if (port_id >= nb_ports) {
1261 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1265 dev = &rte_eth_devices[port_id];
1266 return dev->data->all_multicast;
1270 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1271 struct rte_eth_link *link)
1273 struct rte_eth_link *dst = link;
1274 struct rte_eth_link *src = &(dev->data->dev_link);
1276 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1277 *(uint64_t *)src) == 0)
1284 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1286 struct rte_eth_dev *dev;
1288 if (port_id >= nb_ports) {
1289 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1292 dev = &rte_eth_devices[port_id];
1294 if (dev->data->dev_conf.intr_conf.lsc != 0)
1295 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1297 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1298 (*dev->dev_ops->link_update)(dev, 1);
1299 *eth_link = dev->data->dev_link;
1304 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1306 struct rte_eth_dev *dev;
1308 if (port_id >= nb_ports) {
1309 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1312 dev = &rte_eth_devices[port_id];
1314 if (dev->data->dev_conf.intr_conf.lsc != 0)
1315 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1317 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1318 (*dev->dev_ops->link_update)(dev, 0);
1319 *eth_link = dev->data->dev_link;
1324 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1326 struct rte_eth_dev *dev;
1328 if (port_id >= nb_ports) {
1329 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1332 dev = &rte_eth_devices[port_id];
1333 memset(stats, 0, sizeof(*stats));
1335 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1336 (*dev->dev_ops->stats_get)(dev, stats);
1337 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1342 rte_eth_stats_reset(uint8_t port_id)
1344 struct rte_eth_dev *dev;
1346 if (port_id >= nb_ports) {
1347 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1350 dev = &rte_eth_devices[port_id];
1352 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1353 (*dev->dev_ops->stats_reset)(dev);
1356 /* retrieve ethdev extended statistics */
1358 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1361 struct rte_eth_stats eth_stats;
1362 struct rte_eth_dev *dev;
1363 unsigned count, i, q;
1367 if (port_id >= nb_ports) {
1368 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1371 dev = &rte_eth_devices[port_id];
1373 /* implemented by the driver */
1374 if (dev->dev_ops->xstats_get != NULL)
1375 return (*dev->dev_ops->xstats_get)(dev, xstats, n);
1377 /* else, return generic statistics */
1378 count = RTE_NB_STATS;
1379 count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
1380 count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
1384 /* now fill the xstats structure */
1387 memset(ð_stats, 0, sizeof(eth_stats));
1388 rte_eth_stats_get(port_id, ð_stats);
1391 for (i = 0; i < RTE_NB_STATS; i++) {
1392 stats_ptr = (char *)ð_stats + rte_stats_strings[i].offset;
1393 val = *(uint64_t *)stats_ptr;
1394 snprintf(xstats[count].name, sizeof(xstats[count].name),
1395 "%s", rte_stats_strings[i].name);
1396 xstats[count++].value = val;
1400 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1401 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1402 stats_ptr = (char *)ð_stats;
1403 stats_ptr += rte_rxq_stats_strings[i].offset;
1404 stats_ptr += q * sizeof(uint64_t);
1405 val = *(uint64_t *)stats_ptr;
1406 snprintf(xstats[count].name, sizeof(xstats[count].name),
1407 "rx_queue_%u_%s", q,
1408 rte_rxq_stats_strings[i].name);
1409 xstats[count++].value = val;
1414 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1415 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1416 stats_ptr = (char *)ð_stats;
1417 stats_ptr += rte_txq_stats_strings[i].offset;
1418 stats_ptr += q * sizeof(uint64_t);
1419 val = *(uint64_t *)stats_ptr;
1420 snprintf(xstats[count].name, sizeof(xstats[count].name),
1421 "tx_queue_%u_%s", q,
1422 rte_txq_stats_strings[i].name);
1423 xstats[count++].value = val;
1430 /* reset ethdev extended statistics */
1432 rte_eth_xstats_reset(uint8_t port_id)
1434 struct rte_eth_dev *dev;
1436 if (port_id >= nb_ports) {
1437 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1440 dev = &rte_eth_devices[port_id];
1442 /* implemented by the driver */
1443 if (dev->dev_ops->xstats_reset != NULL) {
1444 (*dev->dev_ops->xstats_reset)(dev);
1448 /* fallback to default */
1449 rte_eth_stats_reset(port_id);
1453 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1456 struct rte_eth_dev *dev;
1458 if (port_id >= nb_ports) {
1459 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1462 dev = &rte_eth_devices[port_id];
1464 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1465 return (*dev->dev_ops->queue_stats_mapping_set)
1466 (dev, queue_id, stat_idx, is_rx);
1471 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1474 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1480 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1483 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1489 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1491 struct rte_eth_dev *dev;
1493 if (port_id >= nb_ports) {
1494 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1497 dev = &rte_eth_devices[port_id];
1499 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1501 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1502 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1503 dev_info->pci_dev = dev->pci_dev;
1505 dev_info->driver_name = dev->driver->pci_drv.name;
1509 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1511 struct rte_eth_dev *dev;
1513 if (port_id >= nb_ports) {
1514 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1517 dev = &rte_eth_devices[port_id];
1518 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1523 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1525 struct rte_eth_dev *dev;
1527 if (port_id >= nb_ports) {
1528 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1532 dev = &rte_eth_devices[port_id];
1533 *mtu = dev->data->mtu;
1538 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1541 struct rte_eth_dev *dev;
1543 if (port_id >= nb_ports) {
1544 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1548 dev = &rte_eth_devices[port_id];
1549 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1551 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1553 dev->data->mtu = mtu;
1559 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1561 struct rte_eth_dev *dev;
1563 if (port_id >= nb_ports) {
1564 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1567 dev = &rte_eth_devices[port_id];
1568 if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1569 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1573 if (vlan_id > 4095) {
1574 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1575 port_id, (unsigned) vlan_id);
1578 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1579 (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1584 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1586 struct rte_eth_dev *dev;
1588 if (port_id >= nb_ports) {
1589 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1593 dev = &rte_eth_devices[port_id];
1594 if (rx_queue_id >= dev->data->nb_rx_queues) {
1595 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1599 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1600 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1606 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1608 struct rte_eth_dev *dev;
1610 if (port_id >= nb_ports) {
1611 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1615 dev = &rte_eth_devices[port_id];
1616 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1617 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1623 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1625 struct rte_eth_dev *dev;
1630 if (port_id >= nb_ports) {
1631 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1635 dev = &rte_eth_devices[port_id];
1637 /*check which option changed by application*/
1638 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1639 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1641 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1642 mask |= ETH_VLAN_STRIP_MASK;
1645 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1646 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1648 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1649 mask |= ETH_VLAN_FILTER_MASK;
1652 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1653 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1655 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1656 mask |= ETH_VLAN_EXTEND_MASK;
1663 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1664 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1670 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1672 struct rte_eth_dev *dev;
1675 if (port_id >= nb_ports) {
1676 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1680 dev = &rte_eth_devices[port_id];
1682 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1683 ret |= ETH_VLAN_STRIP_OFFLOAD ;
1685 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1686 ret |= ETH_VLAN_FILTER_OFFLOAD ;
1688 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1689 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
1695 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1697 struct rte_eth_dev *dev;
1699 if (port_id >= nb_ports) {
1700 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1703 dev = &rte_eth_devices[port_id];
1704 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1705 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1711 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1712 struct rte_fdir_filter *fdir_filter,
1715 struct rte_eth_dev *dev;
1717 if (port_id >= nb_ports) {
1718 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1722 dev = &rte_eth_devices[port_id];
1724 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1725 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1726 port_id, dev->data->dev_conf.fdir_conf.mode);
1730 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1731 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1732 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1733 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1734 "None l4type, source & destinations ports " \
1735 "should be null!\n");
1739 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1740 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1745 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1746 struct rte_fdir_filter *fdir_filter,
1749 struct rte_eth_dev *dev;
1751 if (port_id >= nb_ports) {
1752 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1756 dev = &rte_eth_devices[port_id];
1758 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1759 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1760 port_id, dev->data->dev_conf.fdir_conf.mode);
1764 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1765 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1766 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1767 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1768 "None l4type, source & destinations ports " \
1769 "should be null!\n");
1773 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
1774 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
1780 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
1781 struct rte_fdir_filter *fdir_filter)
1783 struct rte_eth_dev *dev;
1785 if (port_id >= nb_ports) {
1786 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1790 dev = &rte_eth_devices[port_id];
1792 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1793 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1794 port_id, dev->data->dev_conf.fdir_conf.mode);
1798 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1799 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1800 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1801 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1802 "None l4type source & destinations ports " \
1803 "should be null!\n");
1807 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
1808 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
1812 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
1814 struct rte_eth_dev *dev;
1816 if (port_id >= nb_ports) {
1817 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1821 dev = &rte_eth_devices[port_id];
1822 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1823 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1827 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
1829 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
1834 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
1835 struct rte_fdir_filter *fdir_filter,
1836 uint16_t soft_id, uint8_t queue,
1839 struct rte_eth_dev *dev;
1841 if (port_id >= nb_ports) {
1842 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1846 dev = &rte_eth_devices[port_id];
1848 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1849 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1850 port_id, dev->data->dev_conf.fdir_conf.mode);
1854 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1855 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1856 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1857 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1858 "None l4type, source & destinations ports " \
1859 "should be null!\n");
1863 /* For now IPv6 is not supported with perfect filter */
1864 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1867 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
1868 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
1874 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
1875 struct rte_fdir_filter *fdir_filter,
1876 uint16_t soft_id, uint8_t queue,
1879 struct rte_eth_dev *dev;
1881 if (port_id >= nb_ports) {
1882 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1886 dev = &rte_eth_devices[port_id];
1888 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1889 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1890 port_id, dev->data->dev_conf.fdir_conf.mode);
1894 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1895 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1896 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1897 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1898 "None l4type, source & destinations ports " \
1899 "should be null!\n");
1903 /* For now IPv6 is not supported with perfect filter */
1904 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1907 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
1908 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
1909 soft_id, queue, drop);
1913 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
1914 struct rte_fdir_filter *fdir_filter,
1917 struct rte_eth_dev *dev;
1919 if (port_id >= nb_ports) {
1920 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1924 dev = &rte_eth_devices[port_id];
1926 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1927 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1928 port_id, dev->data->dev_conf.fdir_conf.mode);
1932 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1933 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1934 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1935 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1936 "None l4type, source & destinations ports " \
1937 "should be null!\n");
1941 /* For now IPv6 is not supported with perfect filter */
1942 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1945 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
1946 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
1951 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
1953 struct rte_eth_dev *dev;
1955 if (port_id >= nb_ports) {
1956 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1960 dev = &rte_eth_devices[port_id];
1961 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1962 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1966 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
1967 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
1971 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1973 struct rte_eth_dev *dev;
1975 if (port_id >= nb_ports) {
1976 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1980 dev = &rte_eth_devices[port_id];
1981 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1982 memset(fc_conf, 0, sizeof(*fc_conf));
1983 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1987 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1989 struct rte_eth_dev *dev;
1991 if (port_id >= nb_ports) {
1992 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1996 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1997 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2001 dev = &rte_eth_devices[port_id];
2002 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2003 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
2007 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
2009 struct rte_eth_dev *dev;
2011 if (port_id >= nb_ports) {
2012 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2016 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2017 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2021 dev = &rte_eth_devices[port_id];
2022 /* High water, low water validation are device specific */
2023 if (*dev->dev_ops->priority_flow_ctrl_set)
2024 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
2029 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2037 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
2038 PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
2039 RTE_RETA_GROUP_SIZE);
2043 num = reta_size / RTE_RETA_GROUP_SIZE;
2044 for (i = 0; i < num; i++) {
2045 if (reta_conf[i].mask)
2053 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2057 uint16_t i, idx, shift;
2063 PMD_DEBUG_TRACE("No receive queue is available\n");
2067 for (i = 0; i < reta_size; i++) {
2068 idx = i / RTE_RETA_GROUP_SIZE;
2069 shift = i % RTE_RETA_GROUP_SIZE;
2070 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2071 (reta_conf[idx].reta[shift] >= max_rxq)) {
2072 PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2073 "the maximum rxq index: %u\n", idx, shift,
2074 reta_conf[idx].reta[shift], max_rxq);
2083 rte_eth_dev_rss_reta_update(uint8_t port_id,
2084 struct rte_eth_rss_reta_entry64 *reta_conf,
2087 struct rte_eth_dev *dev;
2090 if (port_id >= nb_ports) {
2091 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2095 /* Check mask bits */
2096 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2100 dev = &rte_eth_devices[port_id];
2102 /* Check entry value */
2103 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2104 dev->data->nb_rx_queues);
2108 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2109 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2113 rte_eth_dev_rss_reta_query(uint8_t port_id,
2114 struct rte_eth_rss_reta_entry64 *reta_conf,
2117 struct rte_eth_dev *dev;
2120 if (port_id >= nb_ports) {
2121 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2125 /* Check mask bits */
2126 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2130 dev = &rte_eth_devices[port_id];
2131 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2132 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2136 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2138 struct rte_eth_dev *dev;
2139 uint16_t rss_hash_protos;
2141 if (port_id >= nb_ports) {
2142 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2145 rss_hash_protos = rss_conf->rss_hf;
2146 if ((rss_hash_protos != 0) &&
2147 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2148 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2152 dev = &rte_eth_devices[port_id];
2153 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2154 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2158 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2159 struct rte_eth_rss_conf *rss_conf)
2161 struct rte_eth_dev *dev;
2163 if (port_id >= nb_ports) {
2164 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2167 dev = &rte_eth_devices[port_id];
2168 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2169 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2173 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
2174 struct rte_eth_udp_tunnel *udp_tunnel)
2176 struct rte_eth_dev *dev;
2178 if (port_id >= nb_ports) {
2179 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2183 if (udp_tunnel == NULL) {
2184 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2188 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2189 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2193 dev = &rte_eth_devices[port_id];
2194 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
2195 return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
2199 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
2200 struct rte_eth_udp_tunnel *udp_tunnel)
2202 struct rte_eth_dev *dev;
2204 if (port_id >= nb_ports) {
2205 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2208 dev = &rte_eth_devices[port_id];
2210 if (udp_tunnel == NULL) {
2211 PMD_DEBUG_TRACE("Invalid udp_tunnel parametr\n");
2215 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2216 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2220 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2221 return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2225 rte_eth_led_on(uint8_t port_id)
2227 struct rte_eth_dev *dev;
2229 if (port_id >= nb_ports) {
2230 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2234 dev = &rte_eth_devices[port_id];
2235 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2236 return ((*dev->dev_ops->dev_led_on)(dev));
2240 rte_eth_led_off(uint8_t port_id)
2242 struct rte_eth_dev *dev;
2244 if (port_id >= nb_ports) {
2245 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2249 dev = &rte_eth_devices[port_id];
2250 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2251 return ((*dev->dev_ops->dev_led_off)(dev));
2255 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2259 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2261 struct rte_eth_dev_info dev_info;
2262 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2265 rte_eth_dev_info_get(port_id, &dev_info);
2267 for (i = 0; i < dev_info.max_mac_addrs; i++)
2268 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2274 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
2277 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2280 struct rte_eth_dev *dev;
2284 if (port_id >= nb_ports) {
2285 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2288 dev = &rte_eth_devices[port_id];
2289 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2291 if (is_zero_ether_addr(addr)) {
2292 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2296 if (pool >= ETH_64_POOLS) {
2297 PMD_DEBUG_TRACE("pool id must be 0-%d\n",ETH_64_POOLS - 1);
2301 index = get_mac_addr_index(port_id, addr);
2303 index = get_mac_addr_index(port_id, &null_mac_addr);
2305 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2310 pool_mask = dev->data->mac_pool_sel[index];
2312 /* Check if both MAC address and pool is alread there, and do nothing */
2313 if (pool_mask & (1ULL << pool))
2318 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2320 /* Update address in NIC data structure */
2321 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2323 /* Update pool bitmap in NIC data structure */
2324 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2330 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2332 struct rte_eth_dev *dev;
2335 if (port_id >= nb_ports) {
2336 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2339 dev = &rte_eth_devices[port_id];
2340 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2342 index = get_mac_addr_index(port_id, addr);
2344 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2345 return (-EADDRINUSE);
2346 } else if (index < 0)
2347 return 0; /* Do nothing if address wasn't found */
2350 (*dev->dev_ops->mac_addr_remove)(dev, index);
2352 /* Update address in NIC data structure */
2353 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2355 /* reset pool bitmap */
2356 dev->data->mac_pool_sel[index] = 0;
2362 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2363 uint16_t rx_mode, uint8_t on)
2366 struct rte_eth_dev *dev;
2367 struct rte_eth_dev_info dev_info;
2369 if (port_id >= nb_ports) {
2370 PMD_DEBUG_TRACE("set VF RX mode:Invalid port_id=%d\n",
2375 dev = &rte_eth_devices[port_id];
2376 rte_eth_dev_info_get(port_id, &dev_info);
2378 num_vfs = dev_info.max_vfs;
2381 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2386 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2389 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2390 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2394 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2398 get_hash_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2400 struct rte_eth_dev_info dev_info;
2401 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2404 rte_eth_dev_info_get(port_id, &dev_info);
2405 if (!dev->data->hash_mac_addrs)
2408 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2409 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2410 ETHER_ADDR_LEN) == 0)
2417 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2422 struct rte_eth_dev *dev;
2424 if (port_id >= nb_ports) {
2425 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2430 dev = &rte_eth_devices[port_id];
2431 if (is_zero_ether_addr(addr)) {
2432 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2437 index = get_hash_mac_addr_index(port_id, addr);
2438 /* Check if it's already there, and do nothing */
2439 if ((index >= 0) && (on))
2444 PMD_DEBUG_TRACE("port %d: the MAC address was not"
2445 "set in UTA\n", port_id);
2449 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2451 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2457 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2458 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2460 /* Update address in NIC data structure */
2462 ether_addr_copy(addr,
2463 &dev->data->hash_mac_addrs[index]);
2465 ether_addr_copy(&null_mac_addr,
2466 &dev->data->hash_mac_addrs[index]);
2473 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2475 struct rte_eth_dev *dev;
2477 if (port_id >= nb_ports) {
2478 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2483 dev = &rte_eth_devices[port_id];
2485 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2486 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2490 rte_eth_dev_set_vf_rx(uint8_t port_id,uint16_t vf, uint8_t on)
2493 struct rte_eth_dev *dev;
2494 struct rte_eth_dev_info dev_info;
2496 if (port_id >= nb_ports) {
2497 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2501 dev = &rte_eth_devices[port_id];
2502 rte_eth_dev_info_get(port_id, &dev_info);
2504 num_vfs = dev_info.max_vfs;
2507 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2511 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2512 return (*dev->dev_ops->set_vf_rx)(dev, vf,on);
2516 rte_eth_dev_set_vf_tx(uint8_t port_id,uint16_t vf, uint8_t on)
2519 struct rte_eth_dev *dev;
2520 struct rte_eth_dev_info dev_info;
2522 if (port_id >= nb_ports) {
2523 PMD_DEBUG_TRACE("set pool tx:Invalid port_id=%d\n", port_id);
2527 dev = &rte_eth_devices[port_id];
2528 rte_eth_dev_info_get(port_id, &dev_info);
2530 num_vfs = dev_info.max_vfs;
2533 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2537 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2538 return (*dev->dev_ops->set_vf_tx)(dev, vf,on);
2542 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2543 uint64_t vf_mask,uint8_t vlan_on)
2545 struct rte_eth_dev *dev;
2547 if (port_id >= nb_ports) {
2548 PMD_DEBUG_TRACE("VF VLAN filter:invalid port id=%d\n",
2552 dev = &rte_eth_devices[port_id];
2554 if(vlan_id > ETHER_MAX_VLAN_ID)
2556 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2562 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2566 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2567 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2571 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2574 struct rte_eth_dev *dev;
2575 struct rte_eth_dev_info dev_info;
2576 struct rte_eth_link link;
2578 if (port_id >= nb_ports) {
2579 PMD_DEBUG_TRACE("set queue rate limit:invalid port id=%d\n",
2584 dev = &rte_eth_devices[port_id];
2585 rte_eth_dev_info_get(port_id, &dev_info);
2586 link = dev->data->dev_link;
2588 if (queue_idx > dev_info.max_tx_queues) {
2589 PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2590 "invalid queue id=%d\n", port_id, queue_idx);
2594 if (tx_rate > link.link_speed) {
2595 PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2596 "bigger than link speed= %d\n",
2597 tx_rate, link.link_speed);
2601 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2602 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2605 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2608 struct rte_eth_dev *dev;
2609 struct rte_eth_dev_info dev_info;
2610 struct rte_eth_link link;
2615 if (port_id >= nb_ports) {
2616 PMD_DEBUG_TRACE("set VF rate limit:invalid port id=%d\n",
2621 dev = &rte_eth_devices[port_id];
2622 rte_eth_dev_info_get(port_id, &dev_info);
2623 link = dev->data->dev_link;
2625 if (vf > dev_info.max_vfs) {
2626 PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2627 "invalid vf id=%d\n", port_id, vf);
2631 if (tx_rate > link.link_speed) {
2632 PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2633 "bigger than link speed= %d\n",
2634 tx_rate, link.link_speed);
2638 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2639 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2643 rte_eth_mirror_rule_set(uint8_t port_id,
2644 struct rte_eth_vmdq_mirror_conf *mirror_conf,
2645 uint8_t rule_id, uint8_t on)
2647 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2649 if (port_id >= nb_ports) {
2650 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2654 if (mirror_conf->rule_type_mask == 0) {
2655 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2659 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2660 PMD_DEBUG_TRACE("Invalid dst pool, pool id must"
2661 "be 0-%d\n",ETH_64_POOLS - 1);
2665 if ((mirror_conf->rule_type_mask & ETH_VMDQ_POOL_MIRROR) &&
2666 (mirror_conf->pool_mask == 0)) {
2667 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not"
2672 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2674 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2675 ETH_VMDQ_NUM_MIRROR_RULE - 1);
2679 dev = &rte_eth_devices[port_id];
2680 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2682 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2686 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2688 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2690 if (port_id >= nb_ports) {
2691 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2695 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2697 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2698 ETH_VMDQ_NUM_MIRROR_RULE-1);
2702 dev = &rte_eth_devices[port_id];
2703 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2705 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2708 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2710 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2711 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2713 struct rte_eth_dev *dev;
2715 if (port_id >= nb_ports) {
2716 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2719 dev = &rte_eth_devices[port_id];
2720 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);
2721 if (queue_id >= dev->data->nb_rx_queues) {
2722 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2725 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2730 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2731 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2733 struct rte_eth_dev *dev;
2735 if (port_id >= nb_ports) {
2736 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2739 dev = &rte_eth_devices[port_id];
2741 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0);
2742 if (queue_id >= dev->data->nb_tx_queues) {
2743 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2746 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2751 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2753 struct rte_eth_dev *dev;
2755 if (port_id >= nb_ports) {
2756 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2759 dev = &rte_eth_devices[port_id];
2760 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0);
2761 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2765 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2767 struct rte_eth_dev *dev;
2769 if (port_id >= nb_ports) {
2770 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2773 dev = &rte_eth_devices[port_id];
2774 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2775 return (*dev->dev_ops->rx_descriptor_done)( \
2776 dev->data->rx_queues[queue_id], offset);
2781 rte_eth_dev_callback_register(uint8_t port_id,
2782 enum rte_eth_event_type event,
2783 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2785 struct rte_eth_dev *dev;
2786 struct rte_eth_dev_callback *user_cb;
2790 if (port_id >= nb_ports) {
2791 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2795 dev = &rte_eth_devices[port_id];
2796 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2798 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2799 if (user_cb->cb_fn == cb_fn &&
2800 user_cb->cb_arg == cb_arg &&
2801 user_cb->event == event) {
2806 /* create a new callback. */
2807 if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2808 sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
2809 user_cb->cb_fn = cb_fn;
2810 user_cb->cb_arg = cb_arg;
2811 user_cb->event = event;
2812 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2815 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2816 return ((user_cb == NULL) ? -ENOMEM : 0);
2820 rte_eth_dev_callback_unregister(uint8_t port_id,
2821 enum rte_eth_event_type event,
2822 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2825 struct rte_eth_dev *dev;
2826 struct rte_eth_dev_callback *cb, *next;
2830 if (port_id >= nb_ports) {
2831 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2835 dev = &rte_eth_devices[port_id];
2836 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2839 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2841 next = TAILQ_NEXT(cb, next);
2843 if (cb->cb_fn != cb_fn || cb->event != event ||
2844 (cb->cb_arg != (void *)-1 &&
2845 cb->cb_arg != cb_arg))
2849 * if this callback is not executing right now,
2852 if (cb->active == 0) {
2853 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2860 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2865 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2866 enum rte_eth_event_type event)
2868 struct rte_eth_dev_callback *cb_lst;
2869 struct rte_eth_dev_callback dev_cb;
2871 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2872 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2873 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2877 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2878 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2880 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2883 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2885 #ifdef RTE_NIC_BYPASS
2886 int rte_eth_dev_bypass_init(uint8_t port_id)
2888 struct rte_eth_dev *dev;
2890 if (port_id >= nb_ports) {
2891 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2895 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2896 PMD_DEBUG_TRACE("Invalid port device\n");
2900 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2901 (*dev->dev_ops->bypass_init)(dev);
2906 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2908 struct rte_eth_dev *dev;
2910 if (port_id >= nb_ports) {
2911 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2915 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2916 PMD_DEBUG_TRACE("Invalid port device\n");
2919 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2920 (*dev->dev_ops->bypass_state_show)(dev, state);
2925 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2927 struct rte_eth_dev *dev;
2929 if (port_id >= nb_ports) {
2930 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2934 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2935 PMD_DEBUG_TRACE("Invalid port device\n");
2939 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2940 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2945 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2947 struct rte_eth_dev *dev;
2949 if (port_id >= nb_ports) {
2950 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2954 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2955 PMD_DEBUG_TRACE("Invalid port device\n");
2959 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2960 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2965 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2967 struct rte_eth_dev *dev;
2969 if (port_id >= nb_ports) {
2970 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2974 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2975 PMD_DEBUG_TRACE("Invalid port device\n");
2979 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2980 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2985 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2987 struct rte_eth_dev *dev;
2989 if (port_id >= nb_ports) {
2990 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2994 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2995 PMD_DEBUG_TRACE("Invalid port device\n");
2999 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
3000 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
3005 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
3007 struct rte_eth_dev *dev;
3009 if (port_id >= nb_ports) {
3010 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3014 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3015 PMD_DEBUG_TRACE("Invalid port device\n");
3019 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
3020 (*dev->dev_ops->bypass_ver_show)(dev, ver);
3025 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
3027 struct rte_eth_dev *dev;
3029 if (port_id >= nb_ports) {
3030 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3034 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3035 PMD_DEBUG_TRACE("Invalid port device\n");
3039 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
3040 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
3045 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
3047 struct rte_eth_dev *dev;
3049 if (port_id >= nb_ports) {
3050 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3054 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3055 PMD_DEBUG_TRACE("Invalid port device\n");
3059 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
3060 (*dev->dev_ops->bypass_wd_reset)(dev);
3066 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
3068 struct rte_eth_dev *dev;
3070 if (port_id >= nb_ports) {
3071 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3075 dev = &rte_eth_devices[port_id];
3076 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3077 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3078 RTE_ETH_FILTER_NOP, NULL);
3082 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
3083 enum rte_filter_op filter_op, void *arg)
3085 struct rte_eth_dev *dev;
3087 if (port_id >= nb_ports) {
3088 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3092 dev = &rte_eth_devices[port_id];
3093 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3094 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
3098 rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
3099 rte_rxtx_callback_fn fn, void *user_param)
3101 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3102 rte_errno = ENOTSUP;
3105 /* check input parameters */
3106 if (port_id >= nb_ports || fn == NULL ||
3107 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3112 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3120 cb->param = user_param;
3121 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3122 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3127 rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
3128 rte_rxtx_callback_fn fn, void *user_param)
3130 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3131 rte_errno = ENOTSUP;
3134 /* check input parameters */
3135 if (port_id >= nb_ports || fn == NULL ||
3136 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3141 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3149 cb->param = user_param;
3150 cb->next = rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3151 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3156 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
3157 struct rte_eth_rxtx_callback *user_cb)
3159 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3162 /* Check input parameters. */
3163 if (port_id >= nb_ports || user_cb == NULL ||
3164 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3168 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3169 struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
3170 struct rte_eth_rxtx_callback *prev_cb;
3172 /* Reset head pointer and remove user cb if first in the list. */
3173 if (cb == user_cb) {
3174 dev->post_rx_burst_cbs[queue_id] = user_cb->next;
3178 /* Remove the user cb from the callback list. */
3183 if (cb == user_cb) {
3184 prev_cb->next = user_cb->next;
3188 } while (cb != NULL);
3190 /* Callback wasn't found. */
3195 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
3196 struct rte_eth_rxtx_callback *user_cb)
3198 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3201 /* Check input parameters. */
3202 if (port_id >= nb_ports || user_cb == NULL ||
3203 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3207 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3208 struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
3209 struct rte_eth_rxtx_callback *prev_cb;
3211 /* Reset head pointer and remove user cb if first in the list. */
3212 if (cb == user_cb) {
3213 dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
3217 /* Remove the user cb from the callback list. */
3222 if (cb == user_cb) {
3223 prev_cb->next = user_cb->next;
3227 } while (cb != NULL);
3229 /* Callback wasn't found. */