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,
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->callbacks));
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,
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,
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,
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,
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_mq_mode(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
507 const struct rte_eth_conf *dev_conf)
509 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
511 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
512 /* check multi-queue mode */
513 if ((dev_conf->rxmode.mq_mode == ETH_MQ_RX_RSS) ||
514 (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) ||
515 (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB_RSS) ||
516 (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB)) {
517 /* SRIOV only works in VMDq enable mode */
518 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
520 "wrong VMDQ mq_mode rx %u tx %u\n",
522 dev_conf->rxmode.mq_mode,
523 dev_conf->txmode.mq_mode);
527 switch (dev_conf->rxmode.mq_mode) {
528 case ETH_MQ_RX_VMDQ_RSS:
529 case ETH_MQ_RX_VMDQ_DCB:
530 case ETH_MQ_RX_VMDQ_DCB_RSS:
531 /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
532 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
534 "unsupported VMDQ mq_mode rx %u\n",
535 port_id, dev_conf->rxmode.mq_mode);
537 default: /* ETH_MQ_RX_VMDQ_ONLY or ETH_MQ_RX_NONE */
538 /* if nothing mq mode configure, use default scheme */
539 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
540 if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
541 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
545 switch (dev_conf->txmode.mq_mode) {
546 case ETH_MQ_TX_VMDQ_DCB:
547 /* DCB VMDQ in SRIOV mode, not implement yet */
548 PMD_DEBUG_TRACE("ethdev port_id=%" PRIu8
550 "unsupported VMDQ mq_mode tx %u\n",
551 port_id, dev_conf->txmode.mq_mode);
553 default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
554 /* if nothing mq mode configure, use default scheme */
555 dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
556 if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
557 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
561 /* check valid queue number */
562 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
563 (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
564 PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
565 "queue number must less equal to %d\n",
566 port_id, RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
570 /* For vmdb+dcb mode check our configuration before we go further */
571 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB) {
572 const struct rte_eth_vmdq_dcb_conf *conf;
574 if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
575 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
577 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
580 conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
581 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
582 conf->nb_queue_pools == ETH_32_POOLS)) {
583 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
584 "nb_queue_pools must be %d or %d\n",
585 port_id, ETH_16_POOLS, ETH_32_POOLS);
589 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
590 const struct rte_eth_vmdq_dcb_tx_conf *conf;
592 if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
593 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
595 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
598 conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
599 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
600 conf->nb_queue_pools == ETH_32_POOLS)) {
601 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
602 "nb_queue_pools != %d or nb_queue_pools "
604 port_id, ETH_16_POOLS, ETH_32_POOLS);
609 /* For DCB mode check our configuration before we go further */
610 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) {
611 const struct rte_eth_dcb_rx_conf *conf;
613 if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
614 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
616 port_id, ETH_DCB_NUM_QUEUES);
619 conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
620 if (! (conf->nb_tcs == ETH_4_TCS ||
621 conf->nb_tcs == ETH_8_TCS)) {
622 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
623 "nb_tcs != %d or nb_tcs "
625 port_id, ETH_4_TCS, ETH_8_TCS);
630 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
631 const struct rte_eth_dcb_tx_conf *conf;
633 if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
634 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
636 port_id, ETH_DCB_NUM_QUEUES);
639 conf = &(dev_conf->tx_adv_conf.dcb_tx_conf);
640 if (! (conf->nb_tcs == ETH_4_TCS ||
641 conf->nb_tcs == ETH_8_TCS)) {
642 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
643 "nb_tcs != %d or nb_tcs "
645 port_id, ETH_4_TCS, ETH_8_TCS);
654 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
655 const struct rte_eth_conf *dev_conf)
657 struct rte_eth_dev *dev;
658 struct rte_eth_dev_info dev_info;
661 /* This function is only safe when called from the primary process
662 * in a multi-process setup*/
663 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
665 if (port_id >= nb_ports || port_id >= RTE_MAX_ETHPORTS) {
666 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
669 dev = &rte_eth_devices[port_id];
671 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
672 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
674 if (dev->data->dev_started) {
676 "port %d must be stopped to allow configuration\n", port_id);
681 * Check that the numbers of RX and TX queues are not greater
682 * than the maximum number of RX and TX queues supported by the
685 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
686 if (nb_rx_q > dev_info.max_rx_queues) {
687 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
688 port_id, nb_rx_q, dev_info.max_rx_queues);
692 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
696 if (nb_tx_q > dev_info.max_tx_queues) {
697 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
698 port_id, nb_tx_q, dev_info.max_tx_queues);
702 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
706 /* Copy the dev_conf parameter into the dev structure */
707 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
710 * If link state interrupt is enabled, check that the
711 * device supports it.
713 if (dev_conf->intr_conf.lsc == 1) {
714 const struct rte_pci_driver *pci_drv = &dev->driver->pci_drv;
716 if (!(pci_drv->drv_flags & RTE_PCI_DRV_INTR_LSC)) {
717 PMD_DEBUG_TRACE("driver %s does not support lsc\n",
724 * If jumbo frames are enabled, check that the maximum RX packet
725 * length is supported by the configured device.
727 if (dev_conf->rxmode.jumbo_frame == 1) {
728 if (dev_conf->rxmode.max_rx_pkt_len >
729 dev_info.max_rx_pktlen) {
730 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
731 " > max valid value %u\n",
733 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
734 (unsigned)dev_info.max_rx_pktlen);
737 else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
738 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
739 " < min valid value %u\n",
741 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
742 (unsigned)ETHER_MIN_LEN);
746 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
747 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
748 /* Use default value */
749 dev->data->dev_conf.rxmode.max_rx_pkt_len =
753 /* multipe queue mode checking */
754 diag = rte_eth_dev_check_mq_mode(port_id, nb_rx_q, nb_tx_q, dev_conf);
756 PMD_DEBUG_TRACE("port%d rte_eth_dev_check_mq_mode = %d\n",
762 * Setup new number of RX/TX queues and reconfigure device.
764 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
766 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
771 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
773 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
775 rte_eth_dev_rx_queue_config(dev, 0);
779 diag = (*dev->dev_ops->dev_configure)(dev);
781 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
783 rte_eth_dev_rx_queue_config(dev, 0);
784 rte_eth_dev_tx_queue_config(dev, 0);
792 rte_eth_dev_config_restore(uint8_t port_id)
794 struct rte_eth_dev *dev;
795 struct rte_eth_dev_info dev_info;
796 struct ether_addr addr;
800 dev = &rte_eth_devices[port_id];
802 rte_eth_dev_info_get(port_id, &dev_info);
804 if (RTE_ETH_DEV_SRIOV(dev).active)
805 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
807 /* replay MAC address configuration */
808 for (i = 0; i < dev_info.max_mac_addrs; i++) {
809 addr = dev->data->mac_addrs[i];
811 /* skip zero address */
812 if (is_zero_ether_addr(&addr))
815 /* add address to the hardware */
816 if (*dev->dev_ops->mac_addr_add)
817 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
819 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
821 /* exit the loop but not return an error */
826 /* replay promiscuous configuration */
827 if (rte_eth_promiscuous_get(port_id) == 1)
828 rte_eth_promiscuous_enable(port_id);
829 else if (rte_eth_promiscuous_get(port_id) == 0)
830 rte_eth_promiscuous_disable(port_id);
832 /* replay allmulticast configuration */
833 if (rte_eth_allmulticast_get(port_id) == 1)
834 rte_eth_allmulticast_enable(port_id);
835 else if (rte_eth_allmulticast_get(port_id) == 0)
836 rte_eth_allmulticast_disable(port_id);
840 rte_eth_dev_start(uint8_t port_id)
842 struct rte_eth_dev *dev;
845 /* This function is only safe when called from the primary process
846 * in a multi-process setup*/
847 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
849 if (port_id >= nb_ports) {
850 PMD_DEBUG_TRACE("Invalid port_id=%" PRIu8 "\n", port_id);
853 dev = &rte_eth_devices[port_id];
855 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
857 if (dev->data->dev_started != 0) {
858 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
859 " already started\n",
864 diag = (*dev->dev_ops->dev_start)(dev);
866 dev->data->dev_started = 1;
870 rte_eth_dev_config_restore(port_id);
876 rte_eth_dev_stop(uint8_t port_id)
878 struct rte_eth_dev *dev;
880 /* This function is only safe when called from the primary process
881 * in a multi-process setup*/
882 PROC_PRIMARY_OR_RET();
884 if (port_id >= nb_ports) {
885 PMD_DEBUG_TRACE("Invalid port_id=%" PRIu8 "\n", port_id);
888 dev = &rte_eth_devices[port_id];
890 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
892 if (dev->data->dev_started == 0) {
893 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
894 " already stopped\n",
899 dev->data->dev_started = 0;
900 (*dev->dev_ops->dev_stop)(dev);
904 rte_eth_dev_set_link_up(uint8_t port_id)
906 struct rte_eth_dev *dev;
908 /* This function is only safe when called from the primary process
909 * in a multi-process setup*/
910 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
912 if (port_id >= nb_ports) {
913 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
916 dev = &rte_eth_devices[port_id];
918 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
919 return (*dev->dev_ops->dev_set_link_up)(dev);
923 rte_eth_dev_set_link_down(uint8_t port_id)
925 struct rte_eth_dev *dev;
927 /* This function is only safe when called from the primary process
928 * in a multi-process setup*/
929 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
931 if (port_id >= nb_ports) {
932 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
935 dev = &rte_eth_devices[port_id];
937 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
938 return (*dev->dev_ops->dev_set_link_down)(dev);
942 rte_eth_dev_close(uint8_t port_id)
944 struct rte_eth_dev *dev;
946 /* This function is only safe when called from the primary process
947 * in a multi-process setup*/
948 PROC_PRIMARY_OR_RET();
950 if (port_id >= nb_ports) {
951 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
955 dev = &rte_eth_devices[port_id];
957 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
958 dev->data->dev_started = 0;
959 (*dev->dev_ops->dev_close)(dev);
963 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
964 uint16_t nb_rx_desc, unsigned int socket_id,
965 const struct rte_eth_rxconf *rx_conf,
966 struct rte_mempool *mp)
969 uint32_t mbp_buf_size;
970 struct rte_eth_dev *dev;
971 struct rte_pktmbuf_pool_private *mbp_priv;
972 struct rte_eth_dev_info dev_info;
974 /* This function is only safe when called from the primary process
975 * in a multi-process setup*/
976 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
978 if (port_id >= nb_ports) {
979 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
982 dev = &rte_eth_devices[port_id];
983 if (rx_queue_id >= dev->data->nb_rx_queues) {
984 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
988 if (dev->data->dev_started) {
990 "port %d must be stopped to allow configuration\n", port_id);
994 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
995 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
998 * Check the size of the mbuf data buffer.
999 * This value must be provided in the private data of the memory pool.
1000 * First check that the memory pool has a valid private data.
1002 rte_eth_dev_info_get(port_id, &dev_info);
1003 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1004 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1005 mp->name, (int) mp->private_data_size,
1006 (int) sizeof(struct rte_pktmbuf_pool_private));
1009 mbp_priv = rte_mempool_get_priv(mp);
1010 mbp_buf_size = mbp_priv->mbuf_data_room_size;
1012 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1013 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1014 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1018 (int)(RTE_PKTMBUF_HEADROOM +
1019 dev_info.min_rx_bufsize),
1020 (int)RTE_PKTMBUF_HEADROOM,
1021 (int)dev_info.min_rx_bufsize);
1025 if (rx_conf == NULL)
1026 rx_conf = &dev_info.default_rxconf;
1028 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1029 socket_id, rx_conf, mp);
1031 if (!dev->data->min_rx_buf_size ||
1032 dev->data->min_rx_buf_size > mbp_buf_size)
1033 dev->data->min_rx_buf_size = mbp_buf_size;
1040 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1041 uint16_t nb_tx_desc, unsigned int socket_id,
1042 const struct rte_eth_txconf *tx_conf)
1044 struct rte_eth_dev *dev;
1045 struct rte_eth_dev_info dev_info;
1047 /* This function is only safe when called from the primary process
1048 * in a multi-process setup*/
1049 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1051 if (port_id >= RTE_MAX_ETHPORTS || port_id >= nb_ports) {
1052 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1055 dev = &rte_eth_devices[port_id];
1056 if (tx_queue_id >= dev->data->nb_tx_queues) {
1057 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1061 if (dev->data->dev_started) {
1063 "port %d must be stopped to allow configuration\n", port_id);
1067 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1068 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1070 rte_eth_dev_info_get(port_id, &dev_info);
1072 if (tx_conf == NULL)
1073 tx_conf = &dev_info.default_txconf;
1075 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1076 socket_id, tx_conf);
1080 rte_eth_promiscuous_enable(uint8_t port_id)
1082 struct rte_eth_dev *dev;
1084 if (port_id >= nb_ports) {
1085 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1088 dev = &rte_eth_devices[port_id];
1090 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1091 (*dev->dev_ops->promiscuous_enable)(dev);
1092 dev->data->promiscuous = 1;
1096 rte_eth_promiscuous_disable(uint8_t port_id)
1098 struct rte_eth_dev *dev;
1100 if (port_id >= nb_ports) {
1101 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1104 dev = &rte_eth_devices[port_id];
1106 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1107 dev->data->promiscuous = 0;
1108 (*dev->dev_ops->promiscuous_disable)(dev);
1112 rte_eth_promiscuous_get(uint8_t port_id)
1114 struct rte_eth_dev *dev;
1116 if (port_id >= nb_ports) {
1117 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1121 dev = &rte_eth_devices[port_id];
1122 return dev->data->promiscuous;
1126 rte_eth_allmulticast_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->allmulticast_enable);
1137 (*dev->dev_ops->allmulticast_enable)(dev);
1138 dev->data->all_multicast = 1;
1142 rte_eth_allmulticast_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->allmulticast_disable);
1153 dev->data->all_multicast = 0;
1154 (*dev->dev_ops->allmulticast_disable)(dev);
1158 rte_eth_allmulticast_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->all_multicast;
1172 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1173 struct rte_eth_link *link)
1175 struct rte_eth_link *dst = link;
1176 struct rte_eth_link *src = &(dev->data->dev_link);
1178 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1179 *(uint64_t *)src) == 0)
1186 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1188 struct rte_eth_dev *dev;
1190 if (port_id >= nb_ports) {
1191 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1194 dev = &rte_eth_devices[port_id];
1196 if (dev->data->dev_conf.intr_conf.lsc != 0)
1197 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1199 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1200 (*dev->dev_ops->link_update)(dev, 1);
1201 *eth_link = dev->data->dev_link;
1206 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1208 struct rte_eth_dev *dev;
1210 if (port_id >= nb_ports) {
1211 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1214 dev = &rte_eth_devices[port_id];
1216 if (dev->data->dev_conf.intr_conf.lsc != 0)
1217 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1219 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1220 (*dev->dev_ops->link_update)(dev, 0);
1221 *eth_link = dev->data->dev_link;
1226 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1228 struct rte_eth_dev *dev;
1230 if (port_id >= nb_ports) {
1231 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1234 dev = &rte_eth_devices[port_id];
1235 memset(stats, 0, sizeof(*stats));
1237 FUNC_PTR_OR_RET(*dev->dev_ops->stats_get);
1238 (*dev->dev_ops->stats_get)(dev, stats);
1239 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1243 rte_eth_stats_reset(uint8_t port_id)
1245 struct rte_eth_dev *dev;
1247 if (port_id >= nb_ports) {
1248 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1251 dev = &rte_eth_devices[port_id];
1253 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1254 (*dev->dev_ops->stats_reset)(dev);
1257 /* retrieve ethdev extended statistics */
1259 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1262 struct rte_eth_stats eth_stats;
1263 struct rte_eth_dev *dev;
1264 unsigned count, i, q;
1268 if (port_id >= nb_ports) {
1269 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1272 dev = &rte_eth_devices[port_id];
1274 /* implemented by the driver */
1275 if (dev->dev_ops->xstats_get != NULL)
1276 return (*dev->dev_ops->xstats_get)(dev, xstats, n);
1278 /* else, return generic statistics */
1279 count = RTE_NB_STATS;
1280 count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
1281 count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
1285 /* now fill the xstats structure */
1288 memset(ð_stats, 0, sizeof(eth_stats));
1289 rte_eth_stats_get(port_id, ð_stats);
1292 for (i = 0; i < RTE_NB_STATS; i++) {
1293 stats_ptr = (char *)ð_stats + rte_stats_strings[i].offset;
1294 val = *(uint64_t *)stats_ptr;
1295 snprintf(xstats[count].name, sizeof(xstats[count].name),
1296 "%s", rte_stats_strings[i].name);
1297 xstats[count++].value = val;
1301 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1302 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1303 stats_ptr = (char *)ð_stats;
1304 stats_ptr += rte_rxq_stats_strings[i].offset;
1305 stats_ptr += q * sizeof(uint64_t);
1306 val = *(uint64_t *)stats_ptr;
1307 snprintf(xstats[count].name, sizeof(xstats[count].name),
1308 "rx_queue_%u_%s", q,
1309 rte_rxq_stats_strings[i].name);
1310 xstats[count++].value = val;
1315 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1316 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1317 stats_ptr = (char *)ð_stats;
1318 stats_ptr += rte_txq_stats_strings[i].offset;
1319 stats_ptr += q * sizeof(uint64_t);
1320 val = *(uint64_t *)stats_ptr;
1321 snprintf(xstats[count].name, sizeof(xstats[count].name),
1322 "tx_queue_%u_%s", q,
1323 rte_txq_stats_strings[i].name);
1324 xstats[count++].value = val;
1331 /* reset ethdev extended statistics */
1333 rte_eth_xstats_reset(uint8_t port_id)
1335 struct rte_eth_dev *dev;
1337 if (port_id >= nb_ports) {
1338 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1341 dev = &rte_eth_devices[port_id];
1343 /* implemented by the driver */
1344 if (dev->dev_ops->xstats_reset != NULL) {
1345 (*dev->dev_ops->xstats_reset)(dev);
1349 /* fallback to default */
1350 rte_eth_stats_reset(port_id);
1354 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1357 struct rte_eth_dev *dev;
1359 if (port_id >= nb_ports) {
1360 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1363 dev = &rte_eth_devices[port_id];
1365 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1366 return (*dev->dev_ops->queue_stats_mapping_set)
1367 (dev, queue_id, stat_idx, is_rx);
1372 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1375 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1381 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1384 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1390 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1392 struct rte_eth_dev *dev;
1394 if (port_id >= nb_ports) {
1395 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1398 dev = &rte_eth_devices[port_id];
1400 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1402 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1403 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1404 dev_info->pci_dev = dev->pci_dev;
1406 dev_info->driver_name = dev->driver->pci_drv.name;
1410 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1412 struct rte_eth_dev *dev;
1414 if (port_id >= nb_ports) {
1415 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1418 dev = &rte_eth_devices[port_id];
1419 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1424 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1426 struct rte_eth_dev *dev;
1428 if (port_id >= nb_ports) {
1429 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1433 dev = &rte_eth_devices[port_id];
1434 *mtu = dev->data->mtu;
1439 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1442 struct rte_eth_dev *dev;
1444 if (port_id >= nb_ports) {
1445 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1449 dev = &rte_eth_devices[port_id];
1450 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1452 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1454 dev->data->mtu = mtu;
1460 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1462 struct rte_eth_dev *dev;
1464 if (port_id >= nb_ports) {
1465 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1468 dev = &rte_eth_devices[port_id];
1469 if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1470 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1474 if (vlan_id > 4095) {
1475 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1476 port_id, (unsigned) vlan_id);
1479 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1480 (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1485 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1487 struct rte_eth_dev *dev;
1489 if (port_id >= nb_ports) {
1490 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1494 dev = &rte_eth_devices[port_id];
1495 if (rx_queue_id >= dev->data->nb_rx_queues) {
1496 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1500 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1501 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1507 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1509 struct rte_eth_dev *dev;
1511 if (port_id >= nb_ports) {
1512 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1516 dev = &rte_eth_devices[port_id];
1517 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1518 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1524 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1526 struct rte_eth_dev *dev;
1531 if (port_id >= nb_ports) {
1532 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1536 dev = &rte_eth_devices[port_id];
1538 /*check which option changed by application*/
1539 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1540 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1542 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1543 mask |= ETH_VLAN_STRIP_MASK;
1546 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1547 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1549 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1550 mask |= ETH_VLAN_FILTER_MASK;
1553 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1554 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1556 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1557 mask |= ETH_VLAN_EXTEND_MASK;
1564 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1565 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1571 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1573 struct rte_eth_dev *dev;
1576 if (port_id >= nb_ports) {
1577 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1581 dev = &rte_eth_devices[port_id];
1583 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1584 ret |= ETH_VLAN_STRIP_OFFLOAD ;
1586 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1587 ret |= ETH_VLAN_FILTER_OFFLOAD ;
1589 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1590 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
1596 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1598 struct rte_eth_dev *dev;
1600 if (port_id >= nb_ports) {
1601 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1604 dev = &rte_eth_devices[port_id];
1605 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1606 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1612 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1613 struct rte_fdir_filter *fdir_filter,
1616 struct rte_eth_dev *dev;
1618 if (port_id >= nb_ports) {
1619 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1623 dev = &rte_eth_devices[port_id];
1625 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1626 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1627 port_id, dev->data->dev_conf.fdir_conf.mode);
1631 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1632 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1633 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1634 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1635 "None l4type, source & destinations ports " \
1636 "should be null!\n");
1640 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1641 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1646 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1647 struct rte_fdir_filter *fdir_filter,
1650 struct rte_eth_dev *dev;
1652 if (port_id >= nb_ports) {
1653 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1657 dev = &rte_eth_devices[port_id];
1659 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1660 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1661 port_id, dev->data->dev_conf.fdir_conf.mode);
1665 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1666 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1667 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1668 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1669 "None l4type, source & destinations ports " \
1670 "should be null!\n");
1674 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
1675 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
1681 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
1682 struct rte_fdir_filter *fdir_filter)
1684 struct rte_eth_dev *dev;
1686 if (port_id >= nb_ports) {
1687 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1691 dev = &rte_eth_devices[port_id];
1693 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1694 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1695 port_id, dev->data->dev_conf.fdir_conf.mode);
1699 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1700 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1701 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1702 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1703 "None l4type source & destinations ports " \
1704 "should be null!\n");
1708 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
1709 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
1713 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
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];
1723 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1724 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1728 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
1730 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
1735 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
1736 struct rte_fdir_filter *fdir_filter,
1737 uint16_t soft_id, uint8_t queue,
1740 struct rte_eth_dev *dev;
1742 if (port_id >= nb_ports) {
1743 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1747 dev = &rte_eth_devices[port_id];
1749 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1750 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1751 port_id, dev->data->dev_conf.fdir_conf.mode);
1755 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1756 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1757 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1758 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1759 "None l4type, source & destinations ports " \
1760 "should be null!\n");
1764 /* For now IPv6 is not supported with perfect filter */
1765 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1768 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
1769 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
1775 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
1776 struct rte_fdir_filter *fdir_filter,
1777 uint16_t soft_id, uint8_t queue,
1780 struct rte_eth_dev *dev;
1782 if (port_id >= nb_ports) {
1783 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1787 dev = &rte_eth_devices[port_id];
1789 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1790 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1791 port_id, dev->data->dev_conf.fdir_conf.mode);
1795 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1796 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1797 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1798 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1799 "None l4type, source & destinations ports " \
1800 "should be null!\n");
1804 /* For now IPv6 is not supported with perfect filter */
1805 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1808 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
1809 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
1810 soft_id, queue, drop);
1814 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
1815 struct rte_fdir_filter *fdir_filter,
1818 struct rte_eth_dev *dev;
1820 if (port_id >= nb_ports) {
1821 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1825 dev = &rte_eth_devices[port_id];
1827 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1828 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1829 port_id, dev->data->dev_conf.fdir_conf.mode);
1833 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1834 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1835 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1836 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1837 "None l4type, source & destinations ports " \
1838 "should be null!\n");
1842 /* For now IPv6 is not supported with perfect filter */
1843 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1846 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
1847 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
1852 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
1854 struct rte_eth_dev *dev;
1856 if (port_id >= nb_ports) {
1857 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1861 dev = &rte_eth_devices[port_id];
1862 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1863 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1867 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
1868 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
1872 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1874 struct rte_eth_dev *dev;
1876 if (port_id >= nb_ports) {
1877 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1881 dev = &rte_eth_devices[port_id];
1882 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1883 memset(fc_conf, 0, sizeof(*fc_conf));
1884 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1888 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1890 struct rte_eth_dev *dev;
1892 if (port_id >= nb_ports) {
1893 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1897 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1898 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1902 dev = &rte_eth_devices[port_id];
1903 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1904 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1908 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1910 struct rte_eth_dev *dev;
1912 if (port_id >= nb_ports) {
1913 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1917 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1918 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1922 dev = &rte_eth_devices[port_id];
1923 /* High water, low water validation are device specific */
1924 if (*dev->dev_ops->priority_flow_ctrl_set)
1925 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1930 rte_eth_dev_rss_reta_update(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
1932 struct rte_eth_dev *dev;
1936 if (port_id >= nb_ports) {
1937 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1941 /* Invalid mask bit(s) setting */
1942 if ((reta_conf->mask_lo == 0) && (reta_conf->mask_hi == 0)) {
1943 PMD_DEBUG_TRACE("Invalid update mask bits for port=%d\n",port_id);
1947 dev = &rte_eth_devices[port_id];
1948 max_rxq = (dev->data->nb_rx_queues <= ETH_RSS_RETA_MAX_QUEUE) ?
1949 dev->data->nb_rx_queues : ETH_RSS_RETA_MAX_QUEUE;
1950 if (reta_conf->mask_lo != 0) {
1951 for (i = 0; i < ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
1952 if ((reta_conf->mask_lo & (1ULL << i)) &&
1953 (reta_conf->reta[i] >= max_rxq)) {
1954 PMD_DEBUG_TRACE("RETA hash index output"
1955 "configration for port=%d,invalid"
1956 "queue=%d\n",port_id,reta_conf->reta[i]);
1963 if (reta_conf->mask_hi != 0) {
1964 for (i = 0; i< ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
1965 j = (uint8_t)(i + ETH_RSS_RETA_NUM_ENTRIES/2);
1967 /* Check if the max entry >= 128 */
1968 if ((reta_conf->mask_hi & (1ULL << i)) &&
1969 (reta_conf->reta[j] >= max_rxq)) {
1970 PMD_DEBUG_TRACE("RETA hash index output"
1971 "configration for port=%d,invalid"
1972 "queue=%d\n",port_id,reta_conf->reta[j]);
1979 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
1980 return (*dev->dev_ops->reta_update)(dev, reta_conf);
1984 rte_eth_dev_rss_reta_query(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
1986 struct rte_eth_dev *dev;
1988 if (port_id >= nb_ports) {
1989 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1993 if((reta_conf->mask_lo == 0) && (reta_conf->mask_hi == 0)) {
1994 PMD_DEBUG_TRACE("Invalid update mask bits for the port=%d\n",port_id);
1998 dev = &rte_eth_devices[port_id];
1999 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2000 return (*dev->dev_ops->reta_query)(dev, reta_conf);
2004 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2006 struct rte_eth_dev *dev;
2007 uint16_t rss_hash_protos;
2009 if (port_id >= nb_ports) {
2010 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2013 rss_hash_protos = rss_conf->rss_hf;
2014 if ((rss_hash_protos != 0) &&
2015 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2016 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2020 dev = &rte_eth_devices[port_id];
2021 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2022 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2026 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2027 struct rte_eth_rss_conf *rss_conf)
2029 struct rte_eth_dev *dev;
2031 if (port_id >= nb_ports) {
2032 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2035 dev = &rte_eth_devices[port_id];
2036 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2037 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2041 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
2042 struct rte_eth_udp_tunnel *udp_tunnel)
2044 struct rte_eth_dev *dev;
2046 if (port_id >= nb_ports) {
2047 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2051 if (udp_tunnel == NULL) {
2052 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2056 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2057 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2061 dev = &rte_eth_devices[port_id];
2062 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
2063 return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
2067 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
2068 struct rte_eth_udp_tunnel *udp_tunnel)
2070 struct rte_eth_dev *dev;
2072 if (port_id >= nb_ports) {
2073 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2076 dev = &rte_eth_devices[port_id];
2078 if (udp_tunnel == NULL) {
2079 PMD_DEBUG_TRACE("Invalid udp_tunnel parametr\n");
2083 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2084 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2088 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2089 return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2093 rte_eth_led_on(uint8_t port_id)
2095 struct rte_eth_dev *dev;
2097 if (port_id >= nb_ports) {
2098 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2102 dev = &rte_eth_devices[port_id];
2103 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2104 return ((*dev->dev_ops->dev_led_on)(dev));
2108 rte_eth_led_off(uint8_t port_id)
2110 struct rte_eth_dev *dev;
2112 if (port_id >= nb_ports) {
2113 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2117 dev = &rte_eth_devices[port_id];
2118 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2119 return ((*dev->dev_ops->dev_led_off)(dev));
2123 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2127 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2129 struct rte_eth_dev_info dev_info;
2130 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2133 rte_eth_dev_info_get(port_id, &dev_info);
2135 for (i = 0; i < dev_info.max_mac_addrs; i++)
2136 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2142 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
2145 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2148 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];
2157 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2159 if (is_zero_ether_addr(addr)) {
2160 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2164 if (pool >= ETH_64_POOLS) {
2165 PMD_DEBUG_TRACE("pool id must be 0-%d\n",ETH_64_POOLS - 1);
2169 index = get_mac_addr_index(port_id, addr);
2171 index = get_mac_addr_index(port_id, &null_mac_addr);
2173 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2178 pool_mask = dev->data->mac_pool_sel[index];
2180 /* Check if both MAC address and pool is alread there, and do nothing */
2181 if (pool_mask & (1ULL << pool))
2186 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2188 /* Update address in NIC data structure */
2189 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2191 /* Update pool bitmap in NIC data structure */
2192 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2198 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2200 struct rte_eth_dev *dev;
2203 if (port_id >= nb_ports) {
2204 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2207 dev = &rte_eth_devices[port_id];
2208 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2210 index = get_mac_addr_index(port_id, addr);
2212 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2213 return (-EADDRINUSE);
2214 } else if (index < 0)
2215 return 0; /* Do nothing if address wasn't found */
2218 (*dev->dev_ops->mac_addr_remove)(dev, index);
2220 /* Update address in NIC data structure */
2221 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2227 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2228 uint16_t rx_mode, uint8_t on)
2231 struct rte_eth_dev *dev;
2232 struct rte_eth_dev_info dev_info;
2234 if (port_id >= nb_ports) {
2235 PMD_DEBUG_TRACE("set VF RX mode:Invalid port_id=%d\n",
2240 dev = &rte_eth_devices[port_id];
2241 rte_eth_dev_info_get(port_id, &dev_info);
2243 num_vfs = dev_info.max_vfs;
2246 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2251 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2254 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2255 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2259 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2263 get_hash_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2265 struct rte_eth_dev_info dev_info;
2266 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2269 rte_eth_dev_info_get(port_id, &dev_info);
2270 if (!dev->data->hash_mac_addrs)
2273 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2274 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2275 ETHER_ADDR_LEN) == 0)
2282 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2287 struct rte_eth_dev *dev;
2289 if (port_id >= nb_ports) {
2290 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2295 dev = &rte_eth_devices[port_id];
2296 if (is_zero_ether_addr(addr)) {
2297 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2302 index = get_hash_mac_addr_index(port_id, addr);
2303 /* Check if it's already there, and do nothing */
2304 if ((index >= 0) && (on))
2309 PMD_DEBUG_TRACE("port %d: the MAC address was not"
2310 "set in UTA\n", port_id);
2314 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2316 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2322 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2323 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2325 /* Update address in NIC data structure */
2327 ether_addr_copy(addr,
2328 &dev->data->hash_mac_addrs[index]);
2330 ether_addr_copy(&null_mac_addr,
2331 &dev->data->hash_mac_addrs[index]);
2338 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2340 struct rte_eth_dev *dev;
2342 if (port_id >= nb_ports) {
2343 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2348 dev = &rte_eth_devices[port_id];
2350 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2351 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2355 rte_eth_dev_set_vf_rx(uint8_t port_id,uint16_t vf, uint8_t on)
2358 struct rte_eth_dev *dev;
2359 struct rte_eth_dev_info dev_info;
2361 if (port_id >= nb_ports) {
2362 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2366 dev = &rte_eth_devices[port_id];
2367 rte_eth_dev_info_get(port_id, &dev_info);
2369 num_vfs = dev_info.max_vfs;
2372 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2376 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2377 return (*dev->dev_ops->set_vf_rx)(dev, vf,on);
2381 rte_eth_dev_set_vf_tx(uint8_t port_id,uint16_t vf, uint8_t on)
2384 struct rte_eth_dev *dev;
2385 struct rte_eth_dev_info dev_info;
2387 if (port_id >= nb_ports) {
2388 PMD_DEBUG_TRACE("set pool tx:Invalid port_id=%d\n", port_id);
2392 dev = &rte_eth_devices[port_id];
2393 rte_eth_dev_info_get(port_id, &dev_info);
2395 num_vfs = dev_info.max_vfs;
2398 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2402 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2403 return (*dev->dev_ops->set_vf_tx)(dev, vf,on);
2407 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2408 uint64_t vf_mask,uint8_t vlan_on)
2410 struct rte_eth_dev *dev;
2412 if (port_id >= nb_ports) {
2413 PMD_DEBUG_TRACE("VF VLAN filter:invalid port id=%d\n",
2417 dev = &rte_eth_devices[port_id];
2419 if(vlan_id > ETHER_MAX_VLAN_ID)
2421 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2427 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2431 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2432 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2436 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2439 struct rte_eth_dev *dev;
2440 struct rte_eth_dev_info dev_info;
2441 struct rte_eth_link link;
2443 if (port_id >= nb_ports) {
2444 PMD_DEBUG_TRACE("set queue rate limit:invalid port id=%d\n",
2449 dev = &rte_eth_devices[port_id];
2450 rte_eth_dev_info_get(port_id, &dev_info);
2451 link = dev->data->dev_link;
2453 if (queue_idx > dev_info.max_tx_queues) {
2454 PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2455 "invalid queue id=%d\n", port_id, queue_idx);
2459 if (tx_rate > link.link_speed) {
2460 PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2461 "bigger than link speed= %d\n",
2462 tx_rate, link.link_speed);
2466 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2467 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2470 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2473 struct rte_eth_dev *dev;
2474 struct rte_eth_dev_info dev_info;
2475 struct rte_eth_link link;
2480 if (port_id >= nb_ports) {
2481 PMD_DEBUG_TRACE("set VF rate limit:invalid port id=%d\n",
2486 dev = &rte_eth_devices[port_id];
2487 rte_eth_dev_info_get(port_id, &dev_info);
2488 link = dev->data->dev_link;
2490 if (vf > dev_info.max_vfs) {
2491 PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2492 "invalid vf id=%d\n", port_id, vf);
2496 if (tx_rate > link.link_speed) {
2497 PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2498 "bigger than link speed= %d\n",
2499 tx_rate, link.link_speed);
2503 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2504 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2508 rte_eth_mirror_rule_set(uint8_t port_id,
2509 struct rte_eth_vmdq_mirror_conf *mirror_conf,
2510 uint8_t rule_id, uint8_t on)
2512 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2514 if (port_id >= nb_ports) {
2515 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2519 if (mirror_conf->rule_type_mask == 0) {
2520 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2524 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2525 PMD_DEBUG_TRACE("Invalid dst pool, pool id must"
2526 "be 0-%d\n",ETH_64_POOLS - 1);
2530 if ((mirror_conf->rule_type_mask & ETH_VMDQ_POOL_MIRROR) &&
2531 (mirror_conf->pool_mask == 0)) {
2532 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not"
2537 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2539 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2540 ETH_VMDQ_NUM_MIRROR_RULE - 1);
2544 dev = &rte_eth_devices[port_id];
2545 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2547 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2551 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2553 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2555 if (port_id >= nb_ports) {
2556 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2560 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2562 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2563 ETH_VMDQ_NUM_MIRROR_RULE-1);
2567 dev = &rte_eth_devices[port_id];
2568 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2570 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2573 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2575 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2576 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2578 struct rte_eth_dev *dev;
2580 if (port_id >= nb_ports) {
2581 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2584 dev = &rte_eth_devices[port_id];
2585 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, -ENOTSUP);
2586 if (queue_id >= dev->data->nb_rx_queues) {
2587 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2590 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2595 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2596 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2598 struct rte_eth_dev *dev;
2600 if (port_id >= nb_ports) {
2601 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2604 dev = &rte_eth_devices[port_id];
2606 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, -ENOTSUP);
2607 if (queue_id >= dev->data->nb_tx_queues) {
2608 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2611 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2616 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2618 struct rte_eth_dev *dev;
2620 if (port_id >= nb_ports) {
2621 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2624 dev = &rte_eth_devices[port_id];
2625 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, -ENOTSUP);
2626 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2630 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2632 struct rte_eth_dev *dev;
2634 if (port_id >= nb_ports) {
2635 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2638 dev = &rte_eth_devices[port_id];
2639 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2640 return (*dev->dev_ops->rx_descriptor_done)( \
2641 dev->data->rx_queues[queue_id], offset);
2646 rte_eth_dev_callback_register(uint8_t port_id,
2647 enum rte_eth_event_type event,
2648 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2650 struct rte_eth_dev *dev;
2651 struct rte_eth_dev_callback *user_cb;
2655 if (port_id >= nb_ports) {
2656 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2660 dev = &rte_eth_devices[port_id];
2661 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2663 TAILQ_FOREACH(user_cb, &(dev->callbacks), next) {
2664 if (user_cb->cb_fn == cb_fn &&
2665 user_cb->cb_arg == cb_arg &&
2666 user_cb->event == event) {
2671 /* create a new callback. */
2672 if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2673 sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
2674 user_cb->cb_fn = cb_fn;
2675 user_cb->cb_arg = cb_arg;
2676 user_cb->event = event;
2677 TAILQ_INSERT_TAIL(&(dev->callbacks), user_cb, next);
2680 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2681 return ((user_cb == NULL) ? -ENOMEM : 0);
2685 rte_eth_dev_callback_unregister(uint8_t port_id,
2686 enum rte_eth_event_type event,
2687 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2690 struct rte_eth_dev *dev;
2691 struct rte_eth_dev_callback *cb, *next;
2695 if (port_id >= nb_ports) {
2696 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2700 dev = &rte_eth_devices[port_id];
2701 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2704 for (cb = TAILQ_FIRST(&dev->callbacks); cb != NULL; cb = next) {
2706 next = TAILQ_NEXT(cb, next);
2708 if (cb->cb_fn != cb_fn || cb->event != event ||
2709 (cb->cb_arg != (void *)-1 &&
2710 cb->cb_arg != cb_arg))
2714 * if this callback is not executing right now,
2717 if (cb->active == 0) {
2718 TAILQ_REMOVE(&(dev->callbacks), cb, next);
2725 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2730 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2731 enum rte_eth_event_type event)
2733 struct rte_eth_dev_callback *cb_lst;
2734 struct rte_eth_dev_callback dev_cb;
2736 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2737 TAILQ_FOREACH(cb_lst, &(dev->callbacks), next) {
2738 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2742 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2743 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2745 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2748 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2750 #ifdef RTE_NIC_BYPASS
2751 int rte_eth_dev_bypass_init(uint8_t port_id)
2753 struct rte_eth_dev *dev;
2755 if (port_id >= nb_ports) {
2756 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2760 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2761 PMD_DEBUG_TRACE("Invalid port device\n");
2765 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2766 (*dev->dev_ops->bypass_init)(dev);
2771 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2773 struct rte_eth_dev *dev;
2775 if (port_id >= nb_ports) {
2776 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2780 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2781 PMD_DEBUG_TRACE("Invalid port device\n");
2784 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2785 (*dev->dev_ops->bypass_state_show)(dev, state);
2790 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2792 struct rte_eth_dev *dev;
2794 if (port_id >= nb_ports) {
2795 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2799 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2800 PMD_DEBUG_TRACE("Invalid port device\n");
2804 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2805 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2810 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2812 struct rte_eth_dev *dev;
2814 if (port_id >= nb_ports) {
2815 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2819 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2820 PMD_DEBUG_TRACE("Invalid port device\n");
2824 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2825 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2830 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2832 struct rte_eth_dev *dev;
2834 if (port_id >= nb_ports) {
2835 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2839 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2840 PMD_DEBUG_TRACE("Invalid port device\n");
2844 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2845 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2850 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2852 struct rte_eth_dev *dev;
2854 if (port_id >= nb_ports) {
2855 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2859 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2860 PMD_DEBUG_TRACE("Invalid port device\n");
2864 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2865 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2870 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2872 struct rte_eth_dev *dev;
2874 if (port_id >= nb_ports) {
2875 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2879 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2880 PMD_DEBUG_TRACE("Invalid port device\n");
2884 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2885 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2890 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2892 struct rte_eth_dev *dev;
2894 if (port_id >= nb_ports) {
2895 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2899 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2900 PMD_DEBUG_TRACE("Invalid port device\n");
2904 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2905 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2910 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
2912 struct rte_eth_dev *dev;
2914 if (port_id >= nb_ports) {
2915 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2919 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2920 PMD_DEBUG_TRACE("Invalid port device\n");
2924 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2925 (*dev->dev_ops->bypass_wd_reset)(dev);
2931 rte_eth_dev_add_syn_filter(uint8_t port_id,
2932 struct rte_syn_filter *filter, uint16_t rx_queue)
2934 struct rte_eth_dev *dev;
2936 if (port_id >= nb_ports) {
2937 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2941 dev = &rte_eth_devices[port_id];
2942 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_syn_filter, -ENOTSUP);
2943 return (*dev->dev_ops->add_syn_filter)(dev, filter, rx_queue);
2947 rte_eth_dev_remove_syn_filter(uint8_t port_id)
2949 struct rte_eth_dev *dev;
2951 if (port_id >= nb_ports) {
2952 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2956 dev = &rte_eth_devices[port_id];
2957 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_syn_filter, -ENOTSUP);
2958 return (*dev->dev_ops->remove_syn_filter)(dev);
2962 rte_eth_dev_get_syn_filter(uint8_t port_id,
2963 struct rte_syn_filter *filter, uint16_t *rx_queue)
2965 struct rte_eth_dev *dev;
2967 if (filter == NULL || rx_queue == NULL)
2970 if (port_id >= nb_ports) {
2971 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2975 dev = &rte_eth_devices[port_id];
2976 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_syn_filter, -ENOTSUP);
2977 return (*dev->dev_ops->get_syn_filter)(dev, filter, rx_queue);
2981 rte_eth_dev_add_ethertype_filter(uint8_t port_id, uint16_t index,
2982 struct rte_ethertype_filter *filter, uint16_t rx_queue)
2984 struct rte_eth_dev *dev;
2986 if (port_id >= nb_ports) {
2987 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2990 if (filter->ethertype == ETHER_TYPE_IPv4 ||
2991 filter->ethertype == ETHER_TYPE_IPv6){
2992 PMD_DEBUG_TRACE("IP and IPv6 are not supported"
2993 " in ethertype filter\n");
2996 dev = &rte_eth_devices[port_id];
2997 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_ethertype_filter, -ENOTSUP);
2998 return (*dev->dev_ops->add_ethertype_filter)(dev, index,
3003 rte_eth_dev_remove_ethertype_filter(uint8_t port_id, uint16_t index)
3005 struct rte_eth_dev *dev;
3007 if (port_id >= nb_ports) {
3008 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3012 dev = &rte_eth_devices[port_id];
3013 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_ethertype_filter, -ENOTSUP);
3014 return (*dev->dev_ops->remove_ethertype_filter)(dev, index);
3018 rte_eth_dev_get_ethertype_filter(uint8_t port_id, uint16_t index,
3019 struct rte_ethertype_filter *filter, uint16_t *rx_queue)
3021 struct rte_eth_dev *dev;
3023 if (filter == NULL || rx_queue == NULL)
3026 if (port_id >= nb_ports) {
3027 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3031 dev = &rte_eth_devices[port_id];
3032 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_ethertype_filter, -ENOTSUP);
3033 return (*dev->dev_ops->get_ethertype_filter)(dev, index,
3038 rte_eth_dev_add_2tuple_filter(uint8_t port_id, uint16_t index,
3039 struct rte_2tuple_filter *filter, uint16_t rx_queue)
3041 struct rte_eth_dev *dev;
3043 if (port_id >= nb_ports) {
3044 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3047 if (filter->protocol != IPPROTO_TCP &&
3048 filter->tcp_flags != 0){
3049 PMD_DEBUG_TRACE("tcp flags is 0x%x, but the protocol value"
3055 dev = &rte_eth_devices[port_id];
3056 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_2tuple_filter, -ENOTSUP);
3057 return (*dev->dev_ops->add_2tuple_filter)(dev, index, filter, rx_queue);
3061 rte_eth_dev_remove_2tuple_filter(uint8_t port_id, uint16_t index)
3063 struct rte_eth_dev *dev;
3065 if (port_id >= nb_ports) {
3066 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3070 dev = &rte_eth_devices[port_id];
3071 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_2tuple_filter, -ENOTSUP);
3072 return (*dev->dev_ops->remove_2tuple_filter)(dev, index);
3076 rte_eth_dev_get_2tuple_filter(uint8_t port_id, uint16_t index,
3077 struct rte_2tuple_filter *filter, uint16_t *rx_queue)
3079 struct rte_eth_dev *dev;
3081 if (filter == NULL || rx_queue == NULL)
3084 if (port_id >= nb_ports) {
3085 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3089 dev = &rte_eth_devices[port_id];
3090 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_2tuple_filter, -ENOTSUP);
3091 return (*dev->dev_ops->get_2tuple_filter)(dev, index, filter, rx_queue);
3095 rte_eth_dev_add_5tuple_filter(uint8_t port_id, uint16_t index,
3096 struct rte_5tuple_filter *filter, uint16_t rx_queue)
3098 struct rte_eth_dev *dev;
3100 if (port_id >= nb_ports) {
3101 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3105 if (filter->protocol != IPPROTO_TCP &&
3106 filter->tcp_flags != 0){
3107 PMD_DEBUG_TRACE("tcp flags is 0x%x, but the protocol value"
3113 dev = &rte_eth_devices[port_id];
3114 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_5tuple_filter, -ENOTSUP);
3115 return (*dev->dev_ops->add_5tuple_filter)(dev, index, filter, rx_queue);
3119 rte_eth_dev_remove_5tuple_filter(uint8_t port_id, uint16_t index)
3121 struct rte_eth_dev *dev;
3123 if (port_id >= nb_ports) {
3124 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3128 dev = &rte_eth_devices[port_id];
3129 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_5tuple_filter, -ENOTSUP);
3130 return (*dev->dev_ops->remove_5tuple_filter)(dev, index);
3134 rte_eth_dev_get_5tuple_filter(uint8_t port_id, uint16_t index,
3135 struct rte_5tuple_filter *filter, uint16_t *rx_queue)
3137 struct rte_eth_dev *dev;
3139 if (filter == NULL || rx_queue == NULL)
3142 if (port_id >= nb_ports) {
3143 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3147 dev = &rte_eth_devices[port_id];
3148 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_5tuple_filter, -ENOTSUP);
3149 return (*dev->dev_ops->get_5tuple_filter)(dev, index, filter,
3154 rte_eth_dev_add_flex_filter(uint8_t port_id, uint16_t index,
3155 struct rte_flex_filter *filter, uint16_t rx_queue)
3157 struct rte_eth_dev *dev;
3159 if (port_id >= nb_ports) {
3160 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3164 dev = &rte_eth_devices[port_id];
3165 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_flex_filter, -ENOTSUP);
3166 return (*dev->dev_ops->add_flex_filter)(dev, index, filter, rx_queue);
3170 rte_eth_dev_remove_flex_filter(uint8_t port_id, uint16_t index)
3172 struct rte_eth_dev *dev;
3174 if (port_id >= nb_ports) {
3175 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3179 dev = &rte_eth_devices[port_id];
3180 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_flex_filter, -ENOTSUP);
3181 return (*dev->dev_ops->remove_flex_filter)(dev, index);
3185 rte_eth_dev_get_flex_filter(uint8_t port_id, uint16_t index,
3186 struct rte_flex_filter *filter, uint16_t *rx_queue)
3188 struct rte_eth_dev *dev;
3190 if (filter == NULL || rx_queue == NULL)
3193 if (port_id >= nb_ports) {
3194 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3198 dev = &rte_eth_devices[port_id];
3199 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_flex_filter, -ENOTSUP);
3200 return (*dev->dev_ops->get_flex_filter)(dev, index, filter,
3205 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
3207 struct rte_eth_dev *dev;
3209 if (port_id >= nb_ports) {
3210 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3214 dev = &rte_eth_devices[port_id];
3215 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3216 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3217 RTE_ETH_FILTER_NOP, NULL);
3221 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
3222 enum rte_filter_op filter_op, void *arg)
3224 struct rte_eth_dev *dev;
3226 if (port_id >= nb_ports) {
3227 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3231 dev = &rte_eth_devices[port_id];
3232 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3233 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);