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 } else { /* re-configure */
341 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
343 rxq = dev->data->rx_queues;
345 for (i = nb_queues; i < old_nb_queues; i++)
346 (*dev->dev_ops->rx_queue_release)(rxq[i]);
347 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
348 RTE_CACHE_LINE_SIZE);
352 if (nb_queues > old_nb_queues)
353 memset(rxq + old_nb_queues, 0,
354 sizeof(rxq[0]) * (nb_queues - old_nb_queues));
356 dev->data->rx_queues = rxq;
359 dev->data->nb_rx_queues = nb_queues;
364 rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
366 struct rte_eth_dev *dev;
368 /* This function is only safe when called from the primary process
369 * in a multi-process setup*/
370 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
372 if (port_id >= nb_ports) {
373 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
377 dev = &rte_eth_devices[port_id];
378 if (rx_queue_id >= dev->data->nb_rx_queues) {
379 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
383 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
385 return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
390 rte_eth_dev_rx_queue_stop(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_stop, -ENOTSUP);
411 return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
416 rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_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 (tx_queue_id >= dev->data->nb_tx_queues) {
431 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
435 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
437 return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
442 rte_eth_dev_tx_queue_stop(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_stop, -ENOTSUP);
463 return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
468 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
470 uint16_t old_nb_queues = dev->data->nb_tx_queues;
474 if (dev->data->tx_queues == NULL) { /* first time configuration */
475 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
476 sizeof(dev->data->tx_queues[0]) * nb_queues,
477 RTE_CACHE_LINE_SIZE);
478 if (dev->data->tx_queues == NULL) {
479 dev->data->nb_tx_queues = 0;
482 } else { /* re-configure */
483 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
485 txq = dev->data->tx_queues;
487 for (i = nb_queues; i < old_nb_queues; i++)
488 (*dev->dev_ops->tx_queue_release)(txq[i]);
489 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
490 RTE_CACHE_LINE_SIZE);
494 if (nb_queues > old_nb_queues)
495 memset(txq + old_nb_queues, 0,
496 sizeof(txq[0]) * (nb_queues - old_nb_queues));
498 dev->data->tx_queues = txq;
501 dev->data->nb_tx_queues = nb_queues;
506 rte_eth_dev_check_vf_rss_rxq_num(uint8_t port_id, uint16_t nb_rx_q)
508 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
512 RTE_ETH_DEV_SRIOV(dev).active =
516 RTE_ETH_DEV_SRIOV(dev).active =
523 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = nb_rx_q;
524 RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx =
525 dev->pci_dev->max_vfs * nb_rx_q;
531 rte_eth_dev_check_mq_mode(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
532 const struct rte_eth_conf *dev_conf)
534 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
536 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
537 /* check multi-queue mode */
538 if ((dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) ||
539 (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB_RSS) ||
540 (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB)) {
541 /* SRIOV only works in VMDq enable mode */
542 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
544 "wrong VMDQ mq_mode rx %u tx %u\n",
546 dev_conf->rxmode.mq_mode,
547 dev_conf->txmode.mq_mode);
551 switch (dev_conf->rxmode.mq_mode) {
552 case ETH_MQ_RX_VMDQ_DCB:
553 case ETH_MQ_RX_VMDQ_DCB_RSS:
554 /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
555 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
557 "unsupported VMDQ mq_mode rx %u\n",
558 port_id, dev_conf->rxmode.mq_mode);
561 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
563 "Rx mq mode is changed from:"
564 "mq_mode %u into VMDQ mq_mode %u\n",
566 dev_conf->rxmode.mq_mode,
567 dev->data->dev_conf.rxmode.mq_mode);
568 case ETH_MQ_RX_VMDQ_RSS:
569 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_RSS;
570 if (nb_rx_q <= RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)
571 if (rte_eth_dev_check_vf_rss_rxq_num(port_id, nb_rx_q) != 0) {
572 PMD_DEBUG_TRACE("ethdev port_id=%d"
573 " SRIOV active, invalid queue"
574 " number for VMDQ RSS, allowed"
575 " value are 1, 2 or 4\n",
580 default: /* ETH_MQ_RX_VMDQ_ONLY or ETH_MQ_RX_NONE */
581 /* if nothing mq mode configure, use default scheme */
582 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
583 if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
584 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
588 switch (dev_conf->txmode.mq_mode) {
589 case ETH_MQ_TX_VMDQ_DCB:
590 /* DCB VMDQ in SRIOV mode, not implement yet */
591 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
593 "unsupported VMDQ mq_mode tx %u\n",
594 port_id, dev_conf->txmode.mq_mode);
596 default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
597 /* if nothing mq mode configure, use default scheme */
598 dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
602 /* check valid queue number */
603 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
604 (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
605 PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
606 "queue number must less equal to %d\n",
607 port_id, RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
611 /* For vmdb+dcb mode check our configuration before we go further */
612 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB) {
613 const struct rte_eth_vmdq_dcb_conf *conf;
615 if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
616 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
618 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
621 conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
622 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
623 conf->nb_queue_pools == ETH_32_POOLS)) {
624 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
625 "nb_queue_pools must be %d or %d\n",
626 port_id, ETH_16_POOLS, ETH_32_POOLS);
630 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
631 const struct rte_eth_vmdq_dcb_tx_conf *conf;
633 if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
634 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
636 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
639 conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
640 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
641 conf->nb_queue_pools == ETH_32_POOLS)) {
642 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
643 "nb_queue_pools != %d or nb_queue_pools "
645 port_id, ETH_16_POOLS, ETH_32_POOLS);
650 /* For DCB mode check our configuration before we go further */
651 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) {
652 const struct rte_eth_dcb_rx_conf *conf;
654 if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
655 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
657 port_id, ETH_DCB_NUM_QUEUES);
660 conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
661 if (! (conf->nb_tcs == ETH_4_TCS ||
662 conf->nb_tcs == ETH_8_TCS)) {
663 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
664 "nb_tcs != %d or nb_tcs "
666 port_id, ETH_4_TCS, ETH_8_TCS);
671 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
672 const struct rte_eth_dcb_tx_conf *conf;
674 if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
675 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
677 port_id, ETH_DCB_NUM_QUEUES);
680 conf = &(dev_conf->tx_adv_conf.dcb_tx_conf);
681 if (! (conf->nb_tcs == ETH_4_TCS ||
682 conf->nb_tcs == ETH_8_TCS)) {
683 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
684 "nb_tcs != %d or nb_tcs "
686 port_id, ETH_4_TCS, ETH_8_TCS);
695 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
696 const struct rte_eth_conf *dev_conf)
698 struct rte_eth_dev *dev;
699 struct rte_eth_dev_info dev_info;
702 /* This function is only safe when called from the primary process
703 * in a multi-process setup*/
704 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
706 if (port_id >= nb_ports || port_id >= RTE_MAX_ETHPORTS) {
707 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
710 dev = &rte_eth_devices[port_id];
712 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
713 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
715 if (dev->data->dev_started) {
717 "port %d must be stopped to allow configuration\n", port_id);
722 * Check that the numbers of RX and TX queues are not greater
723 * than the maximum number of RX and TX queues supported by the
726 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
727 if (nb_rx_q > dev_info.max_rx_queues) {
728 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
729 port_id, nb_rx_q, dev_info.max_rx_queues);
733 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
737 if (nb_tx_q > dev_info.max_tx_queues) {
738 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
739 port_id, nb_tx_q, dev_info.max_tx_queues);
743 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
747 /* Copy the dev_conf parameter into the dev structure */
748 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
751 * If link state interrupt is enabled, check that the
752 * device supports it.
754 if (dev_conf->intr_conf.lsc == 1) {
755 const struct rte_pci_driver *pci_drv = &dev->driver->pci_drv;
757 if (!(pci_drv->drv_flags & RTE_PCI_DRV_INTR_LSC)) {
758 PMD_DEBUG_TRACE("driver %s does not support lsc\n",
765 * If jumbo frames are enabled, check that the maximum RX packet
766 * length is supported by the configured device.
768 if (dev_conf->rxmode.jumbo_frame == 1) {
769 if (dev_conf->rxmode.max_rx_pkt_len >
770 dev_info.max_rx_pktlen) {
771 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
772 " > max valid value %u\n",
774 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
775 (unsigned)dev_info.max_rx_pktlen);
778 else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
779 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
780 " < min valid value %u\n",
782 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
783 (unsigned)ETHER_MIN_LEN);
787 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
788 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
789 /* Use default value */
790 dev->data->dev_conf.rxmode.max_rx_pkt_len =
794 /* multipe queue mode checking */
795 diag = rte_eth_dev_check_mq_mode(port_id, nb_rx_q, nb_tx_q, dev_conf);
797 PMD_DEBUG_TRACE("port%d rte_eth_dev_check_mq_mode = %d\n",
803 * Setup new number of RX/TX queues and reconfigure device.
805 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
807 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
812 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
814 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
816 rte_eth_dev_rx_queue_config(dev, 0);
820 diag = (*dev->dev_ops->dev_configure)(dev);
822 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
824 rte_eth_dev_rx_queue_config(dev, 0);
825 rte_eth_dev_tx_queue_config(dev, 0);
833 rte_eth_dev_config_restore(uint8_t port_id)
835 struct rte_eth_dev *dev;
836 struct rte_eth_dev_info dev_info;
837 struct ether_addr addr;
841 dev = &rte_eth_devices[port_id];
843 rte_eth_dev_info_get(port_id, &dev_info);
845 if (RTE_ETH_DEV_SRIOV(dev).active)
846 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
848 /* replay MAC address configuration */
849 for (i = 0; i < dev_info.max_mac_addrs; i++) {
850 addr = dev->data->mac_addrs[i];
852 /* skip zero address */
853 if (is_zero_ether_addr(&addr))
856 /* add address to the hardware */
857 if (*dev->dev_ops->mac_addr_add &&
858 (dev->data->mac_pool_sel[i] & (1ULL << pool)))
859 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
861 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
863 /* exit the loop but not return an error */
868 /* replay promiscuous configuration */
869 if (rte_eth_promiscuous_get(port_id) == 1)
870 rte_eth_promiscuous_enable(port_id);
871 else if (rte_eth_promiscuous_get(port_id) == 0)
872 rte_eth_promiscuous_disable(port_id);
874 /* replay allmulticast configuration */
875 if (rte_eth_allmulticast_get(port_id) == 1)
876 rte_eth_allmulticast_enable(port_id);
877 else if (rte_eth_allmulticast_get(port_id) == 0)
878 rte_eth_allmulticast_disable(port_id);
882 rte_eth_dev_start(uint8_t port_id)
884 struct rte_eth_dev *dev;
887 /* This function is only safe when called from the primary process
888 * in a multi-process setup*/
889 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
891 if (port_id >= nb_ports) {
892 PMD_DEBUG_TRACE("Invalid port_id=%" PRIu8 "\n", port_id);
895 dev = &rte_eth_devices[port_id];
897 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
899 if (dev->data->dev_started != 0) {
900 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
901 " already started\n",
906 diag = (*dev->dev_ops->dev_start)(dev);
908 dev->data->dev_started = 1;
912 rte_eth_dev_config_restore(port_id);
914 if (dev->data->dev_conf.intr_conf.lsc != 0) {
915 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
916 (*dev->dev_ops->link_update)(dev, 0);
922 rte_eth_dev_stop(uint8_t port_id)
924 struct rte_eth_dev *dev;
926 /* This function is only safe when called from the primary process
927 * in a multi-process setup*/
928 PROC_PRIMARY_OR_RET();
930 if (port_id >= nb_ports) {
931 PMD_DEBUG_TRACE("Invalid port_id=%" PRIu8 "\n", port_id);
934 dev = &rte_eth_devices[port_id];
936 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
938 if (dev->data->dev_started == 0) {
939 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
940 " already stopped\n",
945 dev->data->dev_started = 0;
946 (*dev->dev_ops->dev_stop)(dev);
950 rte_eth_dev_set_link_up(uint8_t port_id)
952 struct rte_eth_dev *dev;
954 /* This function is only safe when called from the primary process
955 * in a multi-process setup*/
956 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
958 if (port_id >= nb_ports) {
959 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
962 dev = &rte_eth_devices[port_id];
964 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
965 return (*dev->dev_ops->dev_set_link_up)(dev);
969 rte_eth_dev_set_link_down(uint8_t port_id)
971 struct rte_eth_dev *dev;
973 /* This function is only safe when called from the primary process
974 * in a multi-process setup*/
975 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
977 if (port_id >= nb_ports) {
978 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
981 dev = &rte_eth_devices[port_id];
983 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
984 return (*dev->dev_ops->dev_set_link_down)(dev);
988 rte_eth_dev_close(uint8_t port_id)
990 struct rte_eth_dev *dev;
992 /* This function is only safe when called from the primary process
993 * in a multi-process setup*/
994 PROC_PRIMARY_OR_RET();
996 if (port_id >= nb_ports) {
997 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1001 dev = &rte_eth_devices[port_id];
1003 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1004 dev->data->dev_started = 0;
1005 (*dev->dev_ops->dev_close)(dev);
1009 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
1010 uint16_t nb_rx_desc, unsigned int socket_id,
1011 const struct rte_eth_rxconf *rx_conf,
1012 struct rte_mempool *mp)
1015 uint32_t mbp_buf_size;
1016 struct rte_eth_dev *dev;
1017 struct rte_pktmbuf_pool_private *mbp_priv;
1018 struct rte_eth_dev_info dev_info;
1020 /* This function is only safe when called from the primary process
1021 * in a multi-process setup*/
1022 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1024 if (port_id >= nb_ports) {
1025 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1028 dev = &rte_eth_devices[port_id];
1029 if (rx_queue_id >= dev->data->nb_rx_queues) {
1030 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1034 if (dev->data->dev_started) {
1036 "port %d must be stopped to allow configuration\n", port_id);
1040 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1041 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1044 * Check the size of the mbuf data buffer.
1045 * This value must be provided in the private data of the memory pool.
1046 * First check that the memory pool has a valid private data.
1048 rte_eth_dev_info_get(port_id, &dev_info);
1049 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1050 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1051 mp->name, (int) mp->private_data_size,
1052 (int) sizeof(struct rte_pktmbuf_pool_private));
1055 mbp_priv = rte_mempool_get_priv(mp);
1056 mbp_buf_size = mbp_priv->mbuf_data_room_size;
1058 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1059 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1060 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1064 (int)(RTE_PKTMBUF_HEADROOM +
1065 dev_info.min_rx_bufsize),
1066 (int)RTE_PKTMBUF_HEADROOM,
1067 (int)dev_info.min_rx_bufsize);
1071 if (rx_conf == NULL)
1072 rx_conf = &dev_info.default_rxconf;
1074 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1075 socket_id, rx_conf, mp);
1077 if (!dev->data->min_rx_buf_size ||
1078 dev->data->min_rx_buf_size > mbp_buf_size)
1079 dev->data->min_rx_buf_size = mbp_buf_size;
1086 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1087 uint16_t nb_tx_desc, unsigned int socket_id,
1088 const struct rte_eth_txconf *tx_conf)
1090 struct rte_eth_dev *dev;
1091 struct rte_eth_dev_info dev_info;
1093 /* This function is only safe when called from the primary process
1094 * in a multi-process setup*/
1095 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1097 if (port_id >= RTE_MAX_ETHPORTS || port_id >= nb_ports) {
1098 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1101 dev = &rte_eth_devices[port_id];
1102 if (tx_queue_id >= dev->data->nb_tx_queues) {
1103 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1107 if (dev->data->dev_started) {
1109 "port %d must be stopped to allow configuration\n", port_id);
1113 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1114 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1116 rte_eth_dev_info_get(port_id, &dev_info);
1118 if (tx_conf == NULL)
1119 tx_conf = &dev_info.default_txconf;
1121 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1122 socket_id, tx_conf);
1126 rte_eth_promiscuous_enable(uint8_t port_id)
1128 struct rte_eth_dev *dev;
1130 if (port_id >= nb_ports) {
1131 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1134 dev = &rte_eth_devices[port_id];
1136 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1137 (*dev->dev_ops->promiscuous_enable)(dev);
1138 dev->data->promiscuous = 1;
1142 rte_eth_promiscuous_disable(uint8_t port_id)
1144 struct rte_eth_dev *dev;
1146 if (port_id >= nb_ports) {
1147 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1150 dev = &rte_eth_devices[port_id];
1152 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1153 dev->data->promiscuous = 0;
1154 (*dev->dev_ops->promiscuous_disable)(dev);
1158 rte_eth_promiscuous_get(uint8_t port_id)
1160 struct rte_eth_dev *dev;
1162 if (port_id >= nb_ports) {
1163 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1167 dev = &rte_eth_devices[port_id];
1168 return dev->data->promiscuous;
1172 rte_eth_allmulticast_enable(uint8_t port_id)
1174 struct rte_eth_dev *dev;
1176 if (port_id >= nb_ports) {
1177 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1180 dev = &rte_eth_devices[port_id];
1182 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1183 (*dev->dev_ops->allmulticast_enable)(dev);
1184 dev->data->all_multicast = 1;
1188 rte_eth_allmulticast_disable(uint8_t port_id)
1190 struct rte_eth_dev *dev;
1192 if (port_id >= nb_ports) {
1193 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1196 dev = &rte_eth_devices[port_id];
1198 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1199 dev->data->all_multicast = 0;
1200 (*dev->dev_ops->allmulticast_disable)(dev);
1204 rte_eth_allmulticast_get(uint8_t port_id)
1206 struct rte_eth_dev *dev;
1208 if (port_id >= nb_ports) {
1209 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1213 dev = &rte_eth_devices[port_id];
1214 return dev->data->all_multicast;
1218 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1219 struct rte_eth_link *link)
1221 struct rte_eth_link *dst = link;
1222 struct rte_eth_link *src = &(dev->data->dev_link);
1224 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1225 *(uint64_t *)src) == 0)
1232 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1234 struct rte_eth_dev *dev;
1236 if (port_id >= nb_ports) {
1237 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1240 dev = &rte_eth_devices[port_id];
1242 if (dev->data->dev_conf.intr_conf.lsc != 0)
1243 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1245 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1246 (*dev->dev_ops->link_update)(dev, 1);
1247 *eth_link = dev->data->dev_link;
1252 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1254 struct rte_eth_dev *dev;
1256 if (port_id >= nb_ports) {
1257 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1260 dev = &rte_eth_devices[port_id];
1262 if (dev->data->dev_conf.intr_conf.lsc != 0)
1263 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1265 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1266 (*dev->dev_ops->link_update)(dev, 0);
1267 *eth_link = dev->data->dev_link;
1272 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1274 struct rte_eth_dev *dev;
1276 if (port_id >= nb_ports) {
1277 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1280 dev = &rte_eth_devices[port_id];
1281 memset(stats, 0, sizeof(*stats));
1283 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1284 (*dev->dev_ops->stats_get)(dev, stats);
1285 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1290 rte_eth_stats_reset(uint8_t port_id)
1292 struct rte_eth_dev *dev;
1294 if (port_id >= nb_ports) {
1295 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1298 dev = &rte_eth_devices[port_id];
1300 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1301 (*dev->dev_ops->stats_reset)(dev);
1304 /* retrieve ethdev extended statistics */
1306 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1309 struct rte_eth_stats eth_stats;
1310 struct rte_eth_dev *dev;
1311 unsigned count, i, q;
1315 if (port_id >= nb_ports) {
1316 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1319 dev = &rte_eth_devices[port_id];
1321 /* implemented by the driver */
1322 if (dev->dev_ops->xstats_get != NULL)
1323 return (*dev->dev_ops->xstats_get)(dev, xstats, n);
1325 /* else, return generic statistics */
1326 count = RTE_NB_STATS;
1327 count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
1328 count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
1332 /* now fill the xstats structure */
1335 memset(ð_stats, 0, sizeof(eth_stats));
1336 rte_eth_stats_get(port_id, ð_stats);
1339 for (i = 0; i < RTE_NB_STATS; i++) {
1340 stats_ptr = (char *)ð_stats + rte_stats_strings[i].offset;
1341 val = *(uint64_t *)stats_ptr;
1342 snprintf(xstats[count].name, sizeof(xstats[count].name),
1343 "%s", rte_stats_strings[i].name);
1344 xstats[count++].value = val;
1348 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1349 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1350 stats_ptr = (char *)ð_stats;
1351 stats_ptr += rte_rxq_stats_strings[i].offset;
1352 stats_ptr += q * sizeof(uint64_t);
1353 val = *(uint64_t *)stats_ptr;
1354 snprintf(xstats[count].name, sizeof(xstats[count].name),
1355 "rx_queue_%u_%s", q,
1356 rte_rxq_stats_strings[i].name);
1357 xstats[count++].value = val;
1362 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1363 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1364 stats_ptr = (char *)ð_stats;
1365 stats_ptr += rte_txq_stats_strings[i].offset;
1366 stats_ptr += q * sizeof(uint64_t);
1367 val = *(uint64_t *)stats_ptr;
1368 snprintf(xstats[count].name, sizeof(xstats[count].name),
1369 "tx_queue_%u_%s", q,
1370 rte_txq_stats_strings[i].name);
1371 xstats[count++].value = val;
1378 /* reset ethdev extended statistics */
1380 rte_eth_xstats_reset(uint8_t port_id)
1382 struct rte_eth_dev *dev;
1384 if (port_id >= nb_ports) {
1385 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1388 dev = &rte_eth_devices[port_id];
1390 /* implemented by the driver */
1391 if (dev->dev_ops->xstats_reset != NULL) {
1392 (*dev->dev_ops->xstats_reset)(dev);
1396 /* fallback to default */
1397 rte_eth_stats_reset(port_id);
1401 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1404 struct rte_eth_dev *dev;
1406 if (port_id >= nb_ports) {
1407 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1410 dev = &rte_eth_devices[port_id];
1412 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1413 return (*dev->dev_ops->queue_stats_mapping_set)
1414 (dev, queue_id, stat_idx, is_rx);
1419 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1422 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1428 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1431 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1437 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1439 struct rte_eth_dev *dev;
1441 if (port_id >= nb_ports) {
1442 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1445 dev = &rte_eth_devices[port_id];
1447 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1449 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1450 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1451 dev_info->pci_dev = dev->pci_dev;
1453 dev_info->driver_name = dev->driver->pci_drv.name;
1457 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1459 struct rte_eth_dev *dev;
1461 if (port_id >= nb_ports) {
1462 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1465 dev = &rte_eth_devices[port_id];
1466 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1471 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1473 struct rte_eth_dev *dev;
1475 if (port_id >= nb_ports) {
1476 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1480 dev = &rte_eth_devices[port_id];
1481 *mtu = dev->data->mtu;
1486 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1489 struct rte_eth_dev *dev;
1491 if (port_id >= nb_ports) {
1492 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1496 dev = &rte_eth_devices[port_id];
1497 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1499 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1501 dev->data->mtu = mtu;
1507 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1509 struct rte_eth_dev *dev;
1511 if (port_id >= nb_ports) {
1512 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1515 dev = &rte_eth_devices[port_id];
1516 if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1517 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1521 if (vlan_id > 4095) {
1522 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1523 port_id, (unsigned) vlan_id);
1526 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1527 (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1532 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1534 struct rte_eth_dev *dev;
1536 if (port_id >= nb_ports) {
1537 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1541 dev = &rte_eth_devices[port_id];
1542 if (rx_queue_id >= dev->data->nb_rx_queues) {
1543 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1547 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1548 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1554 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1556 struct rte_eth_dev *dev;
1558 if (port_id >= nb_ports) {
1559 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1563 dev = &rte_eth_devices[port_id];
1564 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1565 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1571 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1573 struct rte_eth_dev *dev;
1578 if (port_id >= nb_ports) {
1579 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1583 dev = &rte_eth_devices[port_id];
1585 /*check which option changed by application*/
1586 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1587 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1589 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1590 mask |= ETH_VLAN_STRIP_MASK;
1593 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1594 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1596 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1597 mask |= ETH_VLAN_FILTER_MASK;
1600 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1601 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1603 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1604 mask |= ETH_VLAN_EXTEND_MASK;
1611 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1612 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1618 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1620 struct rte_eth_dev *dev;
1623 if (port_id >= nb_ports) {
1624 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1628 dev = &rte_eth_devices[port_id];
1630 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1631 ret |= ETH_VLAN_STRIP_OFFLOAD ;
1633 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1634 ret |= ETH_VLAN_FILTER_OFFLOAD ;
1636 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1637 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
1643 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1645 struct rte_eth_dev *dev;
1647 if (port_id >= nb_ports) {
1648 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1651 dev = &rte_eth_devices[port_id];
1652 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1653 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1659 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1660 struct rte_fdir_filter *fdir_filter,
1663 struct rte_eth_dev *dev;
1665 if (port_id >= nb_ports) {
1666 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1670 dev = &rte_eth_devices[port_id];
1672 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1673 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1674 port_id, dev->data->dev_conf.fdir_conf.mode);
1678 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1679 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1680 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1681 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1682 "None l4type, source & destinations ports " \
1683 "should be null!\n");
1687 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1688 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1693 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1694 struct rte_fdir_filter *fdir_filter,
1697 struct rte_eth_dev *dev;
1699 if (port_id >= nb_ports) {
1700 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1704 dev = &rte_eth_devices[port_id];
1706 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1707 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1708 port_id, dev->data->dev_conf.fdir_conf.mode);
1712 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1713 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1714 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1715 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1716 "None l4type, source & destinations ports " \
1717 "should be null!\n");
1721 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
1722 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
1728 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
1729 struct rte_fdir_filter *fdir_filter)
1731 struct rte_eth_dev *dev;
1733 if (port_id >= nb_ports) {
1734 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1738 dev = &rte_eth_devices[port_id];
1740 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1741 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1742 port_id, dev->data->dev_conf.fdir_conf.mode);
1746 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1747 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1748 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1749 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1750 "None l4type source & destinations ports " \
1751 "should be null!\n");
1755 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
1756 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
1760 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
1762 struct rte_eth_dev *dev;
1764 if (port_id >= nb_ports) {
1765 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1769 dev = &rte_eth_devices[port_id];
1770 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1771 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1775 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
1777 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
1782 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
1783 struct rte_fdir_filter *fdir_filter,
1784 uint16_t soft_id, uint8_t queue,
1787 struct rte_eth_dev *dev;
1789 if (port_id >= nb_ports) {
1790 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1794 dev = &rte_eth_devices[port_id];
1796 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1797 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1798 port_id, dev->data->dev_conf.fdir_conf.mode);
1802 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1803 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1804 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1805 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1806 "None l4type, source & destinations ports " \
1807 "should be null!\n");
1811 /* For now IPv6 is not supported with perfect filter */
1812 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1815 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
1816 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
1822 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
1823 struct rte_fdir_filter *fdir_filter,
1824 uint16_t soft_id, uint8_t queue,
1827 struct rte_eth_dev *dev;
1829 if (port_id >= nb_ports) {
1830 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1834 dev = &rte_eth_devices[port_id];
1836 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1837 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1838 port_id, dev->data->dev_conf.fdir_conf.mode);
1842 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1843 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1844 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1845 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1846 "None l4type, source & destinations ports " \
1847 "should be null!\n");
1851 /* For now IPv6 is not supported with perfect filter */
1852 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1855 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
1856 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
1857 soft_id, queue, drop);
1861 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
1862 struct rte_fdir_filter *fdir_filter,
1865 struct rte_eth_dev *dev;
1867 if (port_id >= nb_ports) {
1868 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1872 dev = &rte_eth_devices[port_id];
1874 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1875 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1876 port_id, dev->data->dev_conf.fdir_conf.mode);
1880 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1881 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1882 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1883 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1884 "None l4type, source & destinations ports " \
1885 "should be null!\n");
1889 /* For now IPv6 is not supported with perfect filter */
1890 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1893 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
1894 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
1899 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
1901 struct rte_eth_dev *dev;
1903 if (port_id >= nb_ports) {
1904 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1908 dev = &rte_eth_devices[port_id];
1909 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1910 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1914 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
1915 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
1919 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1921 struct rte_eth_dev *dev;
1923 if (port_id >= nb_ports) {
1924 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1928 dev = &rte_eth_devices[port_id];
1929 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1930 memset(fc_conf, 0, sizeof(*fc_conf));
1931 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1935 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1937 struct rte_eth_dev *dev;
1939 if (port_id >= nb_ports) {
1940 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1944 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1945 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1949 dev = &rte_eth_devices[port_id];
1950 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1951 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1955 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1957 struct rte_eth_dev *dev;
1959 if (port_id >= nb_ports) {
1960 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1964 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1965 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1969 dev = &rte_eth_devices[port_id];
1970 /* High water, low water validation are device specific */
1971 if (*dev->dev_ops->priority_flow_ctrl_set)
1972 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1977 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
1985 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
1986 PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
1987 RTE_RETA_GROUP_SIZE);
1991 num = reta_size / RTE_RETA_GROUP_SIZE;
1992 for (i = 0; i < num; i++) {
1993 if (reta_conf[i].mask)
2001 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2005 uint16_t i, idx, shift;
2011 PMD_DEBUG_TRACE("No receive queue is available\n");
2015 for (i = 0; i < reta_size; i++) {
2016 idx = i / RTE_RETA_GROUP_SIZE;
2017 shift = i % RTE_RETA_GROUP_SIZE;
2018 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2019 (reta_conf[idx].reta[shift] >= max_rxq)) {
2020 PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2021 "the maximum rxq index: %u\n", idx, shift,
2022 reta_conf[idx].reta[shift], max_rxq);
2031 rte_eth_dev_rss_reta_update(uint8_t port_id,
2032 struct rte_eth_rss_reta_entry64 *reta_conf,
2035 struct rte_eth_dev *dev;
2038 if (port_id >= nb_ports) {
2039 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2043 /* Check mask bits */
2044 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2048 dev = &rte_eth_devices[port_id];
2050 /* Check entry value */
2051 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2052 dev->data->nb_rx_queues);
2056 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2057 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2061 rte_eth_dev_rss_reta_query(uint8_t port_id,
2062 struct rte_eth_rss_reta_entry64 *reta_conf,
2065 struct rte_eth_dev *dev;
2068 if (port_id >= nb_ports) {
2069 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2073 /* Check mask bits */
2074 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2078 dev = &rte_eth_devices[port_id];
2079 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2080 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2084 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2086 struct rte_eth_dev *dev;
2087 uint16_t rss_hash_protos;
2089 if (port_id >= nb_ports) {
2090 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2093 rss_hash_protos = rss_conf->rss_hf;
2094 if ((rss_hash_protos != 0) &&
2095 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2096 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2100 dev = &rte_eth_devices[port_id];
2101 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2102 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2106 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2107 struct rte_eth_rss_conf *rss_conf)
2109 struct rte_eth_dev *dev;
2111 if (port_id >= nb_ports) {
2112 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2115 dev = &rte_eth_devices[port_id];
2116 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2117 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2121 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
2122 struct rte_eth_udp_tunnel *udp_tunnel)
2124 struct rte_eth_dev *dev;
2126 if (port_id >= nb_ports) {
2127 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2131 if (udp_tunnel == NULL) {
2132 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2136 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2137 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2141 dev = &rte_eth_devices[port_id];
2142 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
2143 return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
2147 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
2148 struct rte_eth_udp_tunnel *udp_tunnel)
2150 struct rte_eth_dev *dev;
2152 if (port_id >= nb_ports) {
2153 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2156 dev = &rte_eth_devices[port_id];
2158 if (udp_tunnel == NULL) {
2159 PMD_DEBUG_TRACE("Invalid udp_tunnel parametr\n");
2163 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2164 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2168 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2169 return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2173 rte_eth_led_on(uint8_t port_id)
2175 struct rte_eth_dev *dev;
2177 if (port_id >= nb_ports) {
2178 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2182 dev = &rte_eth_devices[port_id];
2183 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2184 return ((*dev->dev_ops->dev_led_on)(dev));
2188 rte_eth_led_off(uint8_t port_id)
2190 struct rte_eth_dev *dev;
2192 if (port_id >= nb_ports) {
2193 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2197 dev = &rte_eth_devices[port_id];
2198 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2199 return ((*dev->dev_ops->dev_led_off)(dev));
2203 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2207 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2209 struct rte_eth_dev_info dev_info;
2210 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2213 rte_eth_dev_info_get(port_id, &dev_info);
2215 for (i = 0; i < dev_info.max_mac_addrs; i++)
2216 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2222 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
2225 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2228 struct rte_eth_dev *dev;
2232 if (port_id >= nb_ports) {
2233 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2236 dev = &rte_eth_devices[port_id];
2237 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2239 if (is_zero_ether_addr(addr)) {
2240 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2244 if (pool >= ETH_64_POOLS) {
2245 PMD_DEBUG_TRACE("pool id must be 0-%d\n",ETH_64_POOLS - 1);
2249 index = get_mac_addr_index(port_id, addr);
2251 index = get_mac_addr_index(port_id, &null_mac_addr);
2253 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2258 pool_mask = dev->data->mac_pool_sel[index];
2260 /* Check if both MAC address and pool is alread there, and do nothing */
2261 if (pool_mask & (1ULL << pool))
2266 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2268 /* Update address in NIC data structure */
2269 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2271 /* Update pool bitmap in NIC data structure */
2272 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2278 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2280 struct rte_eth_dev *dev;
2283 if (port_id >= nb_ports) {
2284 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2287 dev = &rte_eth_devices[port_id];
2288 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2290 index = get_mac_addr_index(port_id, addr);
2292 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2293 return (-EADDRINUSE);
2294 } else if (index < 0)
2295 return 0; /* Do nothing if address wasn't found */
2298 (*dev->dev_ops->mac_addr_remove)(dev, index);
2300 /* Update address in NIC data structure */
2301 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2303 /* reset pool bitmap */
2304 dev->data->mac_pool_sel[index] = 0;
2310 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2311 uint16_t rx_mode, uint8_t on)
2314 struct rte_eth_dev *dev;
2315 struct rte_eth_dev_info dev_info;
2317 if (port_id >= nb_ports) {
2318 PMD_DEBUG_TRACE("set VF RX mode:Invalid port_id=%d\n",
2323 dev = &rte_eth_devices[port_id];
2324 rte_eth_dev_info_get(port_id, &dev_info);
2326 num_vfs = dev_info.max_vfs;
2329 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2334 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2337 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2338 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2342 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2346 get_hash_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2348 struct rte_eth_dev_info dev_info;
2349 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2352 rte_eth_dev_info_get(port_id, &dev_info);
2353 if (!dev->data->hash_mac_addrs)
2356 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2357 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2358 ETHER_ADDR_LEN) == 0)
2365 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2370 struct rte_eth_dev *dev;
2372 if (port_id >= nb_ports) {
2373 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2378 dev = &rte_eth_devices[port_id];
2379 if (is_zero_ether_addr(addr)) {
2380 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2385 index = get_hash_mac_addr_index(port_id, addr);
2386 /* Check if it's already there, and do nothing */
2387 if ((index >= 0) && (on))
2392 PMD_DEBUG_TRACE("port %d: the MAC address was not"
2393 "set in UTA\n", port_id);
2397 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2399 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2405 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2406 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2408 /* Update address in NIC data structure */
2410 ether_addr_copy(addr,
2411 &dev->data->hash_mac_addrs[index]);
2413 ether_addr_copy(&null_mac_addr,
2414 &dev->data->hash_mac_addrs[index]);
2421 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2423 struct rte_eth_dev *dev;
2425 if (port_id >= nb_ports) {
2426 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2431 dev = &rte_eth_devices[port_id];
2433 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2434 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2438 rte_eth_dev_set_vf_rx(uint8_t port_id,uint16_t vf, uint8_t on)
2441 struct rte_eth_dev *dev;
2442 struct rte_eth_dev_info dev_info;
2444 if (port_id >= nb_ports) {
2445 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2449 dev = &rte_eth_devices[port_id];
2450 rte_eth_dev_info_get(port_id, &dev_info);
2452 num_vfs = dev_info.max_vfs;
2455 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2459 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2460 return (*dev->dev_ops->set_vf_rx)(dev, vf,on);
2464 rte_eth_dev_set_vf_tx(uint8_t port_id,uint16_t vf, uint8_t on)
2467 struct rte_eth_dev *dev;
2468 struct rte_eth_dev_info dev_info;
2470 if (port_id >= nb_ports) {
2471 PMD_DEBUG_TRACE("set pool tx:Invalid port_id=%d\n", port_id);
2475 dev = &rte_eth_devices[port_id];
2476 rte_eth_dev_info_get(port_id, &dev_info);
2478 num_vfs = dev_info.max_vfs;
2481 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2485 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2486 return (*dev->dev_ops->set_vf_tx)(dev, vf,on);
2490 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2491 uint64_t vf_mask,uint8_t vlan_on)
2493 struct rte_eth_dev *dev;
2495 if (port_id >= nb_ports) {
2496 PMD_DEBUG_TRACE("VF VLAN filter:invalid port id=%d\n",
2500 dev = &rte_eth_devices[port_id];
2502 if(vlan_id > ETHER_MAX_VLAN_ID)
2504 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2510 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2514 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2515 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2519 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2522 struct rte_eth_dev *dev;
2523 struct rte_eth_dev_info dev_info;
2524 struct rte_eth_link link;
2526 if (port_id >= nb_ports) {
2527 PMD_DEBUG_TRACE("set queue rate limit:invalid port id=%d\n",
2532 dev = &rte_eth_devices[port_id];
2533 rte_eth_dev_info_get(port_id, &dev_info);
2534 link = dev->data->dev_link;
2536 if (queue_idx > dev_info.max_tx_queues) {
2537 PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2538 "invalid queue id=%d\n", port_id, queue_idx);
2542 if (tx_rate > link.link_speed) {
2543 PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2544 "bigger than link speed= %d\n",
2545 tx_rate, link.link_speed);
2549 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2550 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2553 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2556 struct rte_eth_dev *dev;
2557 struct rte_eth_dev_info dev_info;
2558 struct rte_eth_link link;
2563 if (port_id >= nb_ports) {
2564 PMD_DEBUG_TRACE("set VF rate limit:invalid port id=%d\n",
2569 dev = &rte_eth_devices[port_id];
2570 rte_eth_dev_info_get(port_id, &dev_info);
2571 link = dev->data->dev_link;
2573 if (vf > dev_info.max_vfs) {
2574 PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2575 "invalid vf id=%d\n", port_id, vf);
2579 if (tx_rate > link.link_speed) {
2580 PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2581 "bigger than link speed= %d\n",
2582 tx_rate, link.link_speed);
2586 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2587 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2591 rte_eth_mirror_rule_set(uint8_t port_id,
2592 struct rte_eth_vmdq_mirror_conf *mirror_conf,
2593 uint8_t rule_id, uint8_t on)
2595 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2597 if (port_id >= nb_ports) {
2598 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2602 if (mirror_conf->rule_type_mask == 0) {
2603 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2607 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2608 PMD_DEBUG_TRACE("Invalid dst pool, pool id must"
2609 "be 0-%d\n",ETH_64_POOLS - 1);
2613 if ((mirror_conf->rule_type_mask & ETH_VMDQ_POOL_MIRROR) &&
2614 (mirror_conf->pool_mask == 0)) {
2615 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not"
2620 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2622 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2623 ETH_VMDQ_NUM_MIRROR_RULE - 1);
2627 dev = &rte_eth_devices[port_id];
2628 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2630 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2634 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2636 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2638 if (port_id >= nb_ports) {
2639 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2643 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2645 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2646 ETH_VMDQ_NUM_MIRROR_RULE-1);
2650 dev = &rte_eth_devices[port_id];
2651 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2653 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2656 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2658 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2659 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2661 struct rte_eth_dev *dev;
2663 if (port_id >= nb_ports) {
2664 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2667 dev = &rte_eth_devices[port_id];
2668 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);
2669 if (queue_id >= dev->data->nb_rx_queues) {
2670 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2673 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2678 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2679 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2681 struct rte_eth_dev *dev;
2683 if (port_id >= nb_ports) {
2684 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2687 dev = &rte_eth_devices[port_id];
2689 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0);
2690 if (queue_id >= dev->data->nb_tx_queues) {
2691 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2694 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2699 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2701 struct rte_eth_dev *dev;
2703 if (port_id >= nb_ports) {
2704 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2707 dev = &rte_eth_devices[port_id];
2708 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0);
2709 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2713 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2715 struct rte_eth_dev *dev;
2717 if (port_id >= nb_ports) {
2718 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2721 dev = &rte_eth_devices[port_id];
2722 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2723 return (*dev->dev_ops->rx_descriptor_done)( \
2724 dev->data->rx_queues[queue_id], offset);
2729 rte_eth_dev_callback_register(uint8_t port_id,
2730 enum rte_eth_event_type event,
2731 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2733 struct rte_eth_dev *dev;
2734 struct rte_eth_dev_callback *user_cb;
2738 if (port_id >= nb_ports) {
2739 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2743 dev = &rte_eth_devices[port_id];
2744 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2746 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
2747 if (user_cb->cb_fn == cb_fn &&
2748 user_cb->cb_arg == cb_arg &&
2749 user_cb->event == event) {
2754 /* create a new callback. */
2755 if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2756 sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
2757 user_cb->cb_fn = cb_fn;
2758 user_cb->cb_arg = cb_arg;
2759 user_cb->event = event;
2760 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
2763 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2764 return ((user_cb == NULL) ? -ENOMEM : 0);
2768 rte_eth_dev_callback_unregister(uint8_t port_id,
2769 enum rte_eth_event_type event,
2770 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2773 struct rte_eth_dev *dev;
2774 struct rte_eth_dev_callback *cb, *next;
2778 if (port_id >= nb_ports) {
2779 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2783 dev = &rte_eth_devices[port_id];
2784 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2787 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
2789 next = TAILQ_NEXT(cb, next);
2791 if (cb->cb_fn != cb_fn || cb->event != event ||
2792 (cb->cb_arg != (void *)-1 &&
2793 cb->cb_arg != cb_arg))
2797 * if this callback is not executing right now,
2800 if (cb->active == 0) {
2801 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
2808 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2813 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2814 enum rte_eth_event_type event)
2816 struct rte_eth_dev_callback *cb_lst;
2817 struct rte_eth_dev_callback dev_cb;
2819 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2820 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
2821 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2825 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2826 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2828 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2831 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2833 #ifdef RTE_NIC_BYPASS
2834 int rte_eth_dev_bypass_init(uint8_t port_id)
2836 struct rte_eth_dev *dev;
2838 if (port_id >= nb_ports) {
2839 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2843 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2844 PMD_DEBUG_TRACE("Invalid port device\n");
2848 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2849 (*dev->dev_ops->bypass_init)(dev);
2854 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2856 struct rte_eth_dev *dev;
2858 if (port_id >= nb_ports) {
2859 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2863 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2864 PMD_DEBUG_TRACE("Invalid port device\n");
2867 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2868 (*dev->dev_ops->bypass_state_show)(dev, state);
2873 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2875 struct rte_eth_dev *dev;
2877 if (port_id >= nb_ports) {
2878 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2882 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2883 PMD_DEBUG_TRACE("Invalid port device\n");
2887 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2888 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2893 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2895 struct rte_eth_dev *dev;
2897 if (port_id >= nb_ports) {
2898 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2902 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2903 PMD_DEBUG_TRACE("Invalid port device\n");
2907 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2908 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2913 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2915 struct rte_eth_dev *dev;
2917 if (port_id >= nb_ports) {
2918 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2922 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2923 PMD_DEBUG_TRACE("Invalid port device\n");
2927 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2928 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2933 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2935 struct rte_eth_dev *dev;
2937 if (port_id >= nb_ports) {
2938 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2942 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2943 PMD_DEBUG_TRACE("Invalid port device\n");
2947 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2948 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2953 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2955 struct rte_eth_dev *dev;
2957 if (port_id >= nb_ports) {
2958 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2962 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2963 PMD_DEBUG_TRACE("Invalid port device\n");
2967 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2968 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2973 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2975 struct rte_eth_dev *dev;
2977 if (port_id >= nb_ports) {
2978 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2982 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2983 PMD_DEBUG_TRACE("Invalid port device\n");
2987 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2988 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2993 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2995 struct rte_eth_dev *dev;
2997 if (port_id >= nb_ports) {
2998 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3002 if ((dev= &rte_eth_devices[port_id]) == NULL) {
3003 PMD_DEBUG_TRACE("Invalid port device\n");
3007 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
3008 (*dev->dev_ops->bypass_wd_reset)(dev);
3014 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
3016 struct rte_eth_dev *dev;
3018 if (port_id >= nb_ports) {
3019 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3023 dev = &rte_eth_devices[port_id];
3024 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3025 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3026 RTE_ETH_FILTER_NOP, NULL);
3030 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
3031 enum rte_filter_op filter_op, void *arg)
3033 struct rte_eth_dev *dev;
3035 if (port_id >= nb_ports) {
3036 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3040 dev = &rte_eth_devices[port_id];
3041 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3042 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);