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->data->mac_pool_sel[i] & (1ULL << pool))
818 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
820 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
822 /* exit the loop but not return an error */
827 /* replay promiscuous configuration */
828 if (rte_eth_promiscuous_get(port_id) == 1)
829 rte_eth_promiscuous_enable(port_id);
830 else if (rte_eth_promiscuous_get(port_id) == 0)
831 rte_eth_promiscuous_disable(port_id);
833 /* replay allmulticast configuration */
834 if (rte_eth_allmulticast_get(port_id) == 1)
835 rte_eth_allmulticast_enable(port_id);
836 else if (rte_eth_allmulticast_get(port_id) == 0)
837 rte_eth_allmulticast_disable(port_id);
841 rte_eth_dev_start(uint8_t port_id)
843 struct rte_eth_dev *dev;
846 /* This function is only safe when called from the primary process
847 * in a multi-process setup*/
848 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
850 if (port_id >= nb_ports) {
851 PMD_DEBUG_TRACE("Invalid port_id=%" PRIu8 "\n", port_id);
854 dev = &rte_eth_devices[port_id];
856 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
858 if (dev->data->dev_started != 0) {
859 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
860 " already started\n",
865 diag = (*dev->dev_ops->dev_start)(dev);
867 dev->data->dev_started = 1;
871 rte_eth_dev_config_restore(port_id);
877 rte_eth_dev_stop(uint8_t port_id)
879 struct rte_eth_dev *dev;
881 /* This function is only safe when called from the primary process
882 * in a multi-process setup*/
883 PROC_PRIMARY_OR_RET();
885 if (port_id >= nb_ports) {
886 PMD_DEBUG_TRACE("Invalid port_id=%" PRIu8 "\n", port_id);
889 dev = &rte_eth_devices[port_id];
891 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
893 if (dev->data->dev_started == 0) {
894 PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
895 " already stopped\n",
900 dev->data->dev_started = 0;
901 (*dev->dev_ops->dev_stop)(dev);
905 rte_eth_dev_set_link_up(uint8_t port_id)
907 struct rte_eth_dev *dev;
909 /* This function is only safe when called from the primary process
910 * in a multi-process setup*/
911 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
913 if (port_id >= nb_ports) {
914 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
917 dev = &rte_eth_devices[port_id];
919 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
920 return (*dev->dev_ops->dev_set_link_up)(dev);
924 rte_eth_dev_set_link_down(uint8_t port_id)
926 struct rte_eth_dev *dev;
928 /* This function is only safe when called from the primary process
929 * in a multi-process setup*/
930 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
932 if (port_id >= nb_ports) {
933 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
936 dev = &rte_eth_devices[port_id];
938 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
939 return (*dev->dev_ops->dev_set_link_down)(dev);
943 rte_eth_dev_close(uint8_t port_id)
945 struct rte_eth_dev *dev;
947 /* This function is only safe when called from the primary process
948 * in a multi-process setup*/
949 PROC_PRIMARY_OR_RET();
951 if (port_id >= nb_ports) {
952 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
956 dev = &rte_eth_devices[port_id];
958 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
959 dev->data->dev_started = 0;
960 (*dev->dev_ops->dev_close)(dev);
964 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
965 uint16_t nb_rx_desc, unsigned int socket_id,
966 const struct rte_eth_rxconf *rx_conf,
967 struct rte_mempool *mp)
970 uint32_t mbp_buf_size;
971 struct rte_eth_dev *dev;
972 struct rte_pktmbuf_pool_private *mbp_priv;
973 struct rte_eth_dev_info dev_info;
975 /* This function is only safe when called from the primary process
976 * in a multi-process setup*/
977 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
979 if (port_id >= nb_ports) {
980 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
983 dev = &rte_eth_devices[port_id];
984 if (rx_queue_id >= dev->data->nb_rx_queues) {
985 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
989 if (dev->data->dev_started) {
991 "port %d must be stopped to allow configuration\n", port_id);
995 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
996 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
999 * Check the size of the mbuf data buffer.
1000 * This value must be provided in the private data of the memory pool.
1001 * First check that the memory pool has a valid private data.
1003 rte_eth_dev_info_get(port_id, &dev_info);
1004 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1005 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1006 mp->name, (int) mp->private_data_size,
1007 (int) sizeof(struct rte_pktmbuf_pool_private));
1010 mbp_priv = rte_mempool_get_priv(mp);
1011 mbp_buf_size = mbp_priv->mbuf_data_room_size;
1013 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1014 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1015 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1019 (int)(RTE_PKTMBUF_HEADROOM +
1020 dev_info.min_rx_bufsize),
1021 (int)RTE_PKTMBUF_HEADROOM,
1022 (int)dev_info.min_rx_bufsize);
1026 if (rx_conf == NULL)
1027 rx_conf = &dev_info.default_rxconf;
1029 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1030 socket_id, rx_conf, mp);
1032 if (!dev->data->min_rx_buf_size ||
1033 dev->data->min_rx_buf_size > mbp_buf_size)
1034 dev->data->min_rx_buf_size = mbp_buf_size;
1041 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1042 uint16_t nb_tx_desc, unsigned int socket_id,
1043 const struct rte_eth_txconf *tx_conf)
1045 struct rte_eth_dev *dev;
1046 struct rte_eth_dev_info dev_info;
1048 /* This function is only safe when called from the primary process
1049 * in a multi-process setup*/
1050 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1052 if (port_id >= RTE_MAX_ETHPORTS || port_id >= nb_ports) {
1053 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1056 dev = &rte_eth_devices[port_id];
1057 if (tx_queue_id >= dev->data->nb_tx_queues) {
1058 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1062 if (dev->data->dev_started) {
1064 "port %d must be stopped to allow configuration\n", port_id);
1068 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1069 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1071 rte_eth_dev_info_get(port_id, &dev_info);
1073 if (tx_conf == NULL)
1074 tx_conf = &dev_info.default_txconf;
1076 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1077 socket_id, tx_conf);
1081 rte_eth_promiscuous_enable(uint8_t port_id)
1083 struct rte_eth_dev *dev;
1085 if (port_id >= nb_ports) {
1086 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1089 dev = &rte_eth_devices[port_id];
1091 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1092 (*dev->dev_ops->promiscuous_enable)(dev);
1093 dev->data->promiscuous = 1;
1097 rte_eth_promiscuous_disable(uint8_t port_id)
1099 struct rte_eth_dev *dev;
1101 if (port_id >= nb_ports) {
1102 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1105 dev = &rte_eth_devices[port_id];
1107 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1108 dev->data->promiscuous = 0;
1109 (*dev->dev_ops->promiscuous_disable)(dev);
1113 rte_eth_promiscuous_get(uint8_t port_id)
1115 struct rte_eth_dev *dev;
1117 if (port_id >= nb_ports) {
1118 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1122 dev = &rte_eth_devices[port_id];
1123 return dev->data->promiscuous;
1127 rte_eth_allmulticast_enable(uint8_t port_id)
1129 struct rte_eth_dev *dev;
1131 if (port_id >= nb_ports) {
1132 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1135 dev = &rte_eth_devices[port_id];
1137 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1138 (*dev->dev_ops->allmulticast_enable)(dev);
1139 dev->data->all_multicast = 1;
1143 rte_eth_allmulticast_disable(uint8_t port_id)
1145 struct rte_eth_dev *dev;
1147 if (port_id >= nb_ports) {
1148 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1151 dev = &rte_eth_devices[port_id];
1153 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1154 dev->data->all_multicast = 0;
1155 (*dev->dev_ops->allmulticast_disable)(dev);
1159 rte_eth_allmulticast_get(uint8_t port_id)
1161 struct rte_eth_dev *dev;
1163 if (port_id >= nb_ports) {
1164 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1168 dev = &rte_eth_devices[port_id];
1169 return dev->data->all_multicast;
1173 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1174 struct rte_eth_link *link)
1176 struct rte_eth_link *dst = link;
1177 struct rte_eth_link *src = &(dev->data->dev_link);
1179 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1180 *(uint64_t *)src) == 0)
1187 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1189 struct rte_eth_dev *dev;
1191 if (port_id >= nb_ports) {
1192 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1195 dev = &rte_eth_devices[port_id];
1197 if (dev->data->dev_conf.intr_conf.lsc != 0)
1198 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1200 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1201 (*dev->dev_ops->link_update)(dev, 1);
1202 *eth_link = dev->data->dev_link;
1207 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1209 struct rte_eth_dev *dev;
1211 if (port_id >= nb_ports) {
1212 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1215 dev = &rte_eth_devices[port_id];
1217 if (dev->data->dev_conf.intr_conf.lsc != 0)
1218 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1220 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1221 (*dev->dev_ops->link_update)(dev, 0);
1222 *eth_link = dev->data->dev_link;
1227 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1229 struct rte_eth_dev *dev;
1231 if (port_id >= nb_ports) {
1232 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1235 dev = &rte_eth_devices[port_id];
1236 memset(stats, 0, sizeof(*stats));
1238 FUNC_PTR_OR_RET(*dev->dev_ops->stats_get);
1239 (*dev->dev_ops->stats_get)(dev, stats);
1240 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1244 rte_eth_stats_reset(uint8_t port_id)
1246 struct rte_eth_dev *dev;
1248 if (port_id >= nb_ports) {
1249 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1252 dev = &rte_eth_devices[port_id];
1254 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1255 (*dev->dev_ops->stats_reset)(dev);
1258 /* retrieve ethdev extended statistics */
1260 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1263 struct rte_eth_stats eth_stats;
1264 struct rte_eth_dev *dev;
1265 unsigned count, i, q;
1269 if (port_id >= nb_ports) {
1270 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1273 dev = &rte_eth_devices[port_id];
1275 /* implemented by the driver */
1276 if (dev->dev_ops->xstats_get != NULL)
1277 return (*dev->dev_ops->xstats_get)(dev, xstats, n);
1279 /* else, return generic statistics */
1280 count = RTE_NB_STATS;
1281 count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
1282 count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
1286 /* now fill the xstats structure */
1289 memset(ð_stats, 0, sizeof(eth_stats));
1290 rte_eth_stats_get(port_id, ð_stats);
1293 for (i = 0; i < RTE_NB_STATS; i++) {
1294 stats_ptr = (char *)ð_stats + rte_stats_strings[i].offset;
1295 val = *(uint64_t *)stats_ptr;
1296 snprintf(xstats[count].name, sizeof(xstats[count].name),
1297 "%s", rte_stats_strings[i].name);
1298 xstats[count++].value = val;
1302 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1303 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1304 stats_ptr = (char *)ð_stats;
1305 stats_ptr += rte_rxq_stats_strings[i].offset;
1306 stats_ptr += q * sizeof(uint64_t);
1307 val = *(uint64_t *)stats_ptr;
1308 snprintf(xstats[count].name, sizeof(xstats[count].name),
1309 "rx_queue_%u_%s", q,
1310 rte_rxq_stats_strings[i].name);
1311 xstats[count++].value = val;
1316 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1317 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1318 stats_ptr = (char *)ð_stats;
1319 stats_ptr += rte_txq_stats_strings[i].offset;
1320 stats_ptr += q * sizeof(uint64_t);
1321 val = *(uint64_t *)stats_ptr;
1322 snprintf(xstats[count].name, sizeof(xstats[count].name),
1323 "tx_queue_%u_%s", q,
1324 rte_txq_stats_strings[i].name);
1325 xstats[count++].value = val;
1332 /* reset ethdev extended statistics */
1334 rte_eth_xstats_reset(uint8_t port_id)
1336 struct rte_eth_dev *dev;
1338 if (port_id >= nb_ports) {
1339 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1342 dev = &rte_eth_devices[port_id];
1344 /* implemented by the driver */
1345 if (dev->dev_ops->xstats_reset != NULL) {
1346 (*dev->dev_ops->xstats_reset)(dev);
1350 /* fallback to default */
1351 rte_eth_stats_reset(port_id);
1355 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1358 struct rte_eth_dev *dev;
1360 if (port_id >= nb_ports) {
1361 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1364 dev = &rte_eth_devices[port_id];
1366 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1367 return (*dev->dev_ops->queue_stats_mapping_set)
1368 (dev, queue_id, stat_idx, is_rx);
1373 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1376 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1382 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1385 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1391 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1393 struct rte_eth_dev *dev;
1395 if (port_id >= nb_ports) {
1396 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1399 dev = &rte_eth_devices[port_id];
1401 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1403 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1404 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1405 dev_info->pci_dev = dev->pci_dev;
1407 dev_info->driver_name = dev->driver->pci_drv.name;
1411 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1413 struct rte_eth_dev *dev;
1415 if (port_id >= nb_ports) {
1416 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1419 dev = &rte_eth_devices[port_id];
1420 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1425 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1427 struct rte_eth_dev *dev;
1429 if (port_id >= nb_ports) {
1430 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1434 dev = &rte_eth_devices[port_id];
1435 *mtu = dev->data->mtu;
1440 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1443 struct rte_eth_dev *dev;
1445 if (port_id >= nb_ports) {
1446 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1450 dev = &rte_eth_devices[port_id];
1451 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1453 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1455 dev->data->mtu = mtu;
1461 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1463 struct rte_eth_dev *dev;
1465 if (port_id >= nb_ports) {
1466 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1469 dev = &rte_eth_devices[port_id];
1470 if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1471 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1475 if (vlan_id > 4095) {
1476 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1477 port_id, (unsigned) vlan_id);
1480 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1481 (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1486 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1488 struct rte_eth_dev *dev;
1490 if (port_id >= nb_ports) {
1491 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1495 dev = &rte_eth_devices[port_id];
1496 if (rx_queue_id >= dev->data->nb_rx_queues) {
1497 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1501 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1502 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1508 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1510 struct rte_eth_dev *dev;
1512 if (port_id >= nb_ports) {
1513 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1517 dev = &rte_eth_devices[port_id];
1518 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1519 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1525 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1527 struct rte_eth_dev *dev;
1532 if (port_id >= nb_ports) {
1533 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1537 dev = &rte_eth_devices[port_id];
1539 /*check which option changed by application*/
1540 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1541 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1543 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1544 mask |= ETH_VLAN_STRIP_MASK;
1547 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1548 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1550 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1551 mask |= ETH_VLAN_FILTER_MASK;
1554 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1555 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1557 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1558 mask |= ETH_VLAN_EXTEND_MASK;
1565 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1566 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1572 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1574 struct rte_eth_dev *dev;
1577 if (port_id >= nb_ports) {
1578 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1582 dev = &rte_eth_devices[port_id];
1584 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1585 ret |= ETH_VLAN_STRIP_OFFLOAD ;
1587 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1588 ret |= ETH_VLAN_FILTER_OFFLOAD ;
1590 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1591 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
1597 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1599 struct rte_eth_dev *dev;
1601 if (port_id >= nb_ports) {
1602 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1605 dev = &rte_eth_devices[port_id];
1606 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1607 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1613 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1614 struct rte_fdir_filter *fdir_filter,
1617 struct rte_eth_dev *dev;
1619 if (port_id >= nb_ports) {
1620 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1624 dev = &rte_eth_devices[port_id];
1626 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1627 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1628 port_id, dev->data->dev_conf.fdir_conf.mode);
1632 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1633 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1634 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1635 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1636 "None l4type, source & destinations ports " \
1637 "should be null!\n");
1641 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1642 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1647 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1648 struct rte_fdir_filter *fdir_filter,
1651 struct rte_eth_dev *dev;
1653 if (port_id >= nb_ports) {
1654 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1658 dev = &rte_eth_devices[port_id];
1660 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1661 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1662 port_id, dev->data->dev_conf.fdir_conf.mode);
1666 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1667 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1668 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1669 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1670 "None l4type, source & destinations ports " \
1671 "should be null!\n");
1675 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
1676 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
1682 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
1683 struct rte_fdir_filter *fdir_filter)
1685 struct rte_eth_dev *dev;
1687 if (port_id >= nb_ports) {
1688 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1692 dev = &rte_eth_devices[port_id];
1694 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1695 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1696 port_id, dev->data->dev_conf.fdir_conf.mode);
1700 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1701 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1702 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1703 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1704 "None l4type source & destinations ports " \
1705 "should be null!\n");
1709 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
1710 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
1714 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
1716 struct rte_eth_dev *dev;
1718 if (port_id >= nb_ports) {
1719 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1723 dev = &rte_eth_devices[port_id];
1724 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1725 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1729 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
1731 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
1736 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
1737 struct rte_fdir_filter *fdir_filter,
1738 uint16_t soft_id, uint8_t queue,
1741 struct rte_eth_dev *dev;
1743 if (port_id >= nb_ports) {
1744 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1748 dev = &rte_eth_devices[port_id];
1750 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1751 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1752 port_id, dev->data->dev_conf.fdir_conf.mode);
1756 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1757 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1758 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1759 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1760 "None l4type, source & destinations ports " \
1761 "should be null!\n");
1765 /* For now IPv6 is not supported with perfect filter */
1766 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1769 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
1770 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
1776 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
1777 struct rte_fdir_filter *fdir_filter,
1778 uint16_t soft_id, uint8_t queue,
1781 struct rte_eth_dev *dev;
1783 if (port_id >= nb_ports) {
1784 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1788 dev = &rte_eth_devices[port_id];
1790 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1791 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1792 port_id, dev->data->dev_conf.fdir_conf.mode);
1796 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1797 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1798 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1799 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1800 "None l4type, source & destinations ports " \
1801 "should be null!\n");
1805 /* For now IPv6 is not supported with perfect filter */
1806 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1809 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
1810 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
1811 soft_id, queue, drop);
1815 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
1816 struct rte_fdir_filter *fdir_filter,
1819 struct rte_eth_dev *dev;
1821 if (port_id >= nb_ports) {
1822 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1826 dev = &rte_eth_devices[port_id];
1828 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1829 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1830 port_id, dev->data->dev_conf.fdir_conf.mode);
1834 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1835 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1836 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1837 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1838 "None l4type, source & destinations ports " \
1839 "should be null!\n");
1843 /* For now IPv6 is not supported with perfect filter */
1844 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1847 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
1848 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
1853 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
1855 struct rte_eth_dev *dev;
1857 if (port_id >= nb_ports) {
1858 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1862 dev = &rte_eth_devices[port_id];
1863 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1864 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1868 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
1869 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
1873 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1875 struct rte_eth_dev *dev;
1877 if (port_id >= nb_ports) {
1878 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1882 dev = &rte_eth_devices[port_id];
1883 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1884 memset(fc_conf, 0, sizeof(*fc_conf));
1885 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1889 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1891 struct rte_eth_dev *dev;
1893 if (port_id >= nb_ports) {
1894 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1898 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1899 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1903 dev = &rte_eth_devices[port_id];
1904 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1905 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1909 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1911 struct rte_eth_dev *dev;
1913 if (port_id >= nb_ports) {
1914 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1918 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1919 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1923 dev = &rte_eth_devices[port_id];
1924 /* High water, low water validation are device specific */
1925 if (*dev->dev_ops->priority_flow_ctrl_set)
1926 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1931 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
1939 if (reta_size != RTE_ALIGN(reta_size, RTE_RETA_GROUP_SIZE)) {
1940 PMD_DEBUG_TRACE("Invalid reta size, should be %u aligned\n",
1941 RTE_RETA_GROUP_SIZE);
1945 num = reta_size / RTE_RETA_GROUP_SIZE;
1946 for (i = 0; i < num; i++) {
1947 if (reta_conf[i].mask)
1955 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
1959 uint16_t i, idx, shift;
1965 PMD_DEBUG_TRACE("No receive queue is available\n");
1969 for (i = 0; i < reta_size; i++) {
1970 idx = i / RTE_RETA_GROUP_SIZE;
1971 shift = i % RTE_RETA_GROUP_SIZE;
1972 if ((reta_conf[idx].mask & (1ULL << shift)) &&
1973 (reta_conf[idx].reta[shift] >= max_rxq)) {
1974 PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
1975 "the maximum rxq index: %u\n", idx, shift,
1976 reta_conf[idx].reta[shift], max_rxq);
1985 rte_eth_dev_rss_reta_update(uint8_t port_id,
1986 struct rte_eth_rss_reta_entry64 *reta_conf,
1989 struct rte_eth_dev *dev;
1992 if (port_id >= nb_ports) {
1993 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1997 /* Check mask bits */
1998 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2002 dev = &rte_eth_devices[port_id];
2004 /* Check entry value */
2005 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2006 dev->data->nb_rx_queues);
2010 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2011 return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
2015 rte_eth_dev_rss_reta_query(uint8_t port_id,
2016 struct rte_eth_rss_reta_entry64 *reta_conf,
2019 struct rte_eth_dev *dev;
2022 if (port_id >= nb_ports) {
2023 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2027 /* Check mask bits */
2028 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2032 dev = &rte_eth_devices[port_id];
2033 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2034 return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
2038 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
2040 struct rte_eth_dev *dev;
2041 uint16_t rss_hash_protos;
2043 if (port_id >= nb_ports) {
2044 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2047 rss_hash_protos = rss_conf->rss_hf;
2048 if ((rss_hash_protos != 0) &&
2049 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2050 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2054 dev = &rte_eth_devices[port_id];
2055 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2056 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2060 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2061 struct rte_eth_rss_conf *rss_conf)
2063 struct rte_eth_dev *dev;
2065 if (port_id >= nb_ports) {
2066 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2069 dev = &rte_eth_devices[port_id];
2070 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2071 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2075 rte_eth_dev_udp_tunnel_add(uint8_t port_id,
2076 struct rte_eth_udp_tunnel *udp_tunnel)
2078 struct rte_eth_dev *dev;
2080 if (port_id >= nb_ports) {
2081 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2085 if (udp_tunnel == NULL) {
2086 PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2090 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2091 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2095 dev = &rte_eth_devices[port_id];
2096 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
2097 return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
2101 rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
2102 struct rte_eth_udp_tunnel *udp_tunnel)
2104 struct rte_eth_dev *dev;
2106 if (port_id >= nb_ports) {
2107 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2110 dev = &rte_eth_devices[port_id];
2112 if (udp_tunnel == NULL) {
2113 PMD_DEBUG_TRACE("Invalid udp_tunnel parametr\n");
2117 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2118 PMD_DEBUG_TRACE("Invalid tunnel type\n");
2122 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
2123 return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
2127 rte_eth_led_on(uint8_t port_id)
2129 struct rte_eth_dev *dev;
2131 if (port_id >= nb_ports) {
2132 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2136 dev = &rte_eth_devices[port_id];
2137 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2138 return ((*dev->dev_ops->dev_led_on)(dev));
2142 rte_eth_led_off(uint8_t port_id)
2144 struct rte_eth_dev *dev;
2146 if (port_id >= nb_ports) {
2147 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2151 dev = &rte_eth_devices[port_id];
2152 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2153 return ((*dev->dev_ops->dev_led_off)(dev));
2157 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2161 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2163 struct rte_eth_dev_info dev_info;
2164 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2167 rte_eth_dev_info_get(port_id, &dev_info);
2169 for (i = 0; i < dev_info.max_mac_addrs; i++)
2170 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2176 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
2179 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2182 struct rte_eth_dev *dev;
2186 if (port_id >= nb_ports) {
2187 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2190 dev = &rte_eth_devices[port_id];
2191 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2193 if (is_zero_ether_addr(addr)) {
2194 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2198 if (pool >= ETH_64_POOLS) {
2199 PMD_DEBUG_TRACE("pool id must be 0-%d\n",ETH_64_POOLS - 1);
2203 index = get_mac_addr_index(port_id, addr);
2205 index = get_mac_addr_index(port_id, &null_mac_addr);
2207 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2212 pool_mask = dev->data->mac_pool_sel[index];
2214 /* Check if both MAC address and pool is alread there, and do nothing */
2215 if (pool_mask & (1ULL << pool))
2220 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2222 /* Update address in NIC data structure */
2223 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2225 /* Update pool bitmap in NIC data structure */
2226 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2232 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2234 struct rte_eth_dev *dev;
2237 if (port_id >= nb_ports) {
2238 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2241 dev = &rte_eth_devices[port_id];
2242 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2244 index = get_mac_addr_index(port_id, addr);
2246 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2247 return (-EADDRINUSE);
2248 } else if (index < 0)
2249 return 0; /* Do nothing if address wasn't found */
2252 (*dev->dev_ops->mac_addr_remove)(dev, index);
2254 /* Update address in NIC data structure */
2255 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2257 /* reset pool bitmap */
2258 dev->data->mac_pool_sel[index] = 0;
2264 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2265 uint16_t rx_mode, uint8_t on)
2268 struct rte_eth_dev *dev;
2269 struct rte_eth_dev_info dev_info;
2271 if (port_id >= nb_ports) {
2272 PMD_DEBUG_TRACE("set VF RX mode:Invalid port_id=%d\n",
2277 dev = &rte_eth_devices[port_id];
2278 rte_eth_dev_info_get(port_id, &dev_info);
2280 num_vfs = dev_info.max_vfs;
2283 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2288 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2291 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2292 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2296 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2300 get_hash_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2302 struct rte_eth_dev_info dev_info;
2303 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2306 rte_eth_dev_info_get(port_id, &dev_info);
2307 if (!dev->data->hash_mac_addrs)
2310 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2311 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2312 ETHER_ADDR_LEN) == 0)
2319 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2324 struct rte_eth_dev *dev;
2326 if (port_id >= nb_ports) {
2327 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2332 dev = &rte_eth_devices[port_id];
2333 if (is_zero_ether_addr(addr)) {
2334 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2339 index = get_hash_mac_addr_index(port_id, addr);
2340 /* Check if it's already there, and do nothing */
2341 if ((index >= 0) && (on))
2346 PMD_DEBUG_TRACE("port %d: the MAC address was not"
2347 "set in UTA\n", port_id);
2351 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2353 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2359 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2360 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2362 /* Update address in NIC data structure */
2364 ether_addr_copy(addr,
2365 &dev->data->hash_mac_addrs[index]);
2367 ether_addr_copy(&null_mac_addr,
2368 &dev->data->hash_mac_addrs[index]);
2375 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2377 struct rte_eth_dev *dev;
2379 if (port_id >= nb_ports) {
2380 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2385 dev = &rte_eth_devices[port_id];
2387 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2388 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2392 rte_eth_dev_set_vf_rx(uint8_t port_id,uint16_t vf, uint8_t on)
2395 struct rte_eth_dev *dev;
2396 struct rte_eth_dev_info dev_info;
2398 if (port_id >= nb_ports) {
2399 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2403 dev = &rte_eth_devices[port_id];
2404 rte_eth_dev_info_get(port_id, &dev_info);
2406 num_vfs = dev_info.max_vfs;
2409 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2413 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2414 return (*dev->dev_ops->set_vf_rx)(dev, vf,on);
2418 rte_eth_dev_set_vf_tx(uint8_t port_id,uint16_t vf, uint8_t on)
2421 struct rte_eth_dev *dev;
2422 struct rte_eth_dev_info dev_info;
2424 if (port_id >= nb_ports) {
2425 PMD_DEBUG_TRACE("set pool tx:Invalid port_id=%d\n", port_id);
2429 dev = &rte_eth_devices[port_id];
2430 rte_eth_dev_info_get(port_id, &dev_info);
2432 num_vfs = dev_info.max_vfs;
2435 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2439 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2440 return (*dev->dev_ops->set_vf_tx)(dev, vf,on);
2444 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2445 uint64_t vf_mask,uint8_t vlan_on)
2447 struct rte_eth_dev *dev;
2449 if (port_id >= nb_ports) {
2450 PMD_DEBUG_TRACE("VF VLAN filter:invalid port id=%d\n",
2454 dev = &rte_eth_devices[port_id];
2456 if(vlan_id > ETHER_MAX_VLAN_ID)
2458 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2464 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2468 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2469 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2473 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2476 struct rte_eth_dev *dev;
2477 struct rte_eth_dev_info dev_info;
2478 struct rte_eth_link link;
2480 if (port_id >= nb_ports) {
2481 PMD_DEBUG_TRACE("set queue 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 (queue_idx > dev_info.max_tx_queues) {
2491 PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2492 "invalid queue id=%d\n", port_id, queue_idx);
2496 if (tx_rate > link.link_speed) {
2497 PMD_DEBUG_TRACE("set queue 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_queue_rate_limit, -ENOTSUP);
2504 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2507 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2510 struct rte_eth_dev *dev;
2511 struct rte_eth_dev_info dev_info;
2512 struct rte_eth_link link;
2517 if (port_id >= nb_ports) {
2518 PMD_DEBUG_TRACE("set VF rate limit:invalid port id=%d\n",
2523 dev = &rte_eth_devices[port_id];
2524 rte_eth_dev_info_get(port_id, &dev_info);
2525 link = dev->data->dev_link;
2527 if (vf > dev_info.max_vfs) {
2528 PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2529 "invalid vf id=%d\n", port_id, vf);
2533 if (tx_rate > link.link_speed) {
2534 PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2535 "bigger than link speed= %d\n",
2536 tx_rate, link.link_speed);
2540 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2541 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2545 rte_eth_mirror_rule_set(uint8_t port_id,
2546 struct rte_eth_vmdq_mirror_conf *mirror_conf,
2547 uint8_t rule_id, uint8_t on)
2549 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2551 if (port_id >= nb_ports) {
2552 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2556 if (mirror_conf->rule_type_mask == 0) {
2557 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2561 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2562 PMD_DEBUG_TRACE("Invalid dst pool, pool id must"
2563 "be 0-%d\n",ETH_64_POOLS - 1);
2567 if ((mirror_conf->rule_type_mask & ETH_VMDQ_POOL_MIRROR) &&
2568 (mirror_conf->pool_mask == 0)) {
2569 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not"
2574 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2576 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2577 ETH_VMDQ_NUM_MIRROR_RULE - 1);
2581 dev = &rte_eth_devices[port_id];
2582 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2584 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2588 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2590 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2592 if (port_id >= nb_ports) {
2593 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2597 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2599 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2600 ETH_VMDQ_NUM_MIRROR_RULE-1);
2604 dev = &rte_eth_devices[port_id];
2605 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2607 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2610 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2612 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2613 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2615 struct rte_eth_dev *dev;
2617 if (port_id >= nb_ports) {
2618 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2621 dev = &rte_eth_devices[port_id];
2622 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);
2623 if (queue_id >= dev->data->nb_rx_queues) {
2624 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2627 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2632 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2633 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2635 struct rte_eth_dev *dev;
2637 if (port_id >= nb_ports) {
2638 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2641 dev = &rte_eth_devices[port_id];
2643 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0);
2644 if (queue_id >= dev->data->nb_tx_queues) {
2645 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2648 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2653 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2655 struct rte_eth_dev *dev;
2657 if (port_id >= nb_ports) {
2658 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2661 dev = &rte_eth_devices[port_id];
2662 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0);
2663 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2667 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2669 struct rte_eth_dev *dev;
2671 if (port_id >= nb_ports) {
2672 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2675 dev = &rte_eth_devices[port_id];
2676 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2677 return (*dev->dev_ops->rx_descriptor_done)( \
2678 dev->data->rx_queues[queue_id], offset);
2683 rte_eth_dev_callback_register(uint8_t port_id,
2684 enum rte_eth_event_type event,
2685 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2687 struct rte_eth_dev *dev;
2688 struct rte_eth_dev_callback *user_cb;
2692 if (port_id >= nb_ports) {
2693 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2697 dev = &rte_eth_devices[port_id];
2698 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2700 TAILQ_FOREACH(user_cb, &(dev->callbacks), next) {
2701 if (user_cb->cb_fn == cb_fn &&
2702 user_cb->cb_arg == cb_arg &&
2703 user_cb->event == event) {
2708 /* create a new callback. */
2709 if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2710 sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
2711 user_cb->cb_fn = cb_fn;
2712 user_cb->cb_arg = cb_arg;
2713 user_cb->event = event;
2714 TAILQ_INSERT_TAIL(&(dev->callbacks), user_cb, next);
2717 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2718 return ((user_cb == NULL) ? -ENOMEM : 0);
2722 rte_eth_dev_callback_unregister(uint8_t port_id,
2723 enum rte_eth_event_type event,
2724 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2727 struct rte_eth_dev *dev;
2728 struct rte_eth_dev_callback *cb, *next;
2732 if (port_id >= nb_ports) {
2733 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2737 dev = &rte_eth_devices[port_id];
2738 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2741 for (cb = TAILQ_FIRST(&dev->callbacks); cb != NULL; cb = next) {
2743 next = TAILQ_NEXT(cb, next);
2745 if (cb->cb_fn != cb_fn || cb->event != event ||
2746 (cb->cb_arg != (void *)-1 &&
2747 cb->cb_arg != cb_arg))
2751 * if this callback is not executing right now,
2754 if (cb->active == 0) {
2755 TAILQ_REMOVE(&(dev->callbacks), cb, next);
2762 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2767 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2768 enum rte_eth_event_type event)
2770 struct rte_eth_dev_callback *cb_lst;
2771 struct rte_eth_dev_callback dev_cb;
2773 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2774 TAILQ_FOREACH(cb_lst, &(dev->callbacks), next) {
2775 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2779 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2780 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2782 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2785 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2787 #ifdef RTE_NIC_BYPASS
2788 int rte_eth_dev_bypass_init(uint8_t port_id)
2790 struct rte_eth_dev *dev;
2792 if (port_id >= nb_ports) {
2793 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2797 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2798 PMD_DEBUG_TRACE("Invalid port device\n");
2802 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2803 (*dev->dev_ops->bypass_init)(dev);
2808 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2810 struct rte_eth_dev *dev;
2812 if (port_id >= nb_ports) {
2813 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2817 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2818 PMD_DEBUG_TRACE("Invalid port device\n");
2821 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2822 (*dev->dev_ops->bypass_state_show)(dev, state);
2827 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2829 struct rte_eth_dev *dev;
2831 if (port_id >= nb_ports) {
2832 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2836 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2837 PMD_DEBUG_TRACE("Invalid port device\n");
2841 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2842 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2847 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2849 struct rte_eth_dev *dev;
2851 if (port_id >= nb_ports) {
2852 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2856 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2857 PMD_DEBUG_TRACE("Invalid port device\n");
2861 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2862 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2867 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2869 struct rte_eth_dev *dev;
2871 if (port_id >= nb_ports) {
2872 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2876 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2877 PMD_DEBUG_TRACE("Invalid port device\n");
2881 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2882 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2887 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2889 struct rte_eth_dev *dev;
2891 if (port_id >= nb_ports) {
2892 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2896 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2897 PMD_DEBUG_TRACE("Invalid port device\n");
2901 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2902 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2907 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2909 struct rte_eth_dev *dev;
2911 if (port_id >= nb_ports) {
2912 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2916 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2917 PMD_DEBUG_TRACE("Invalid port device\n");
2921 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2922 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2927 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
2929 struct rte_eth_dev *dev;
2931 if (port_id >= nb_ports) {
2932 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2936 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2937 PMD_DEBUG_TRACE("Invalid port device\n");
2941 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
2942 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2947 rte_eth_dev_bypass_wd_reset(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 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2957 PMD_DEBUG_TRACE("Invalid port device\n");
2961 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
2962 (*dev->dev_ops->bypass_wd_reset)(dev);
2968 rte_eth_dev_add_syn_filter(uint8_t port_id,
2969 struct rte_syn_filter *filter, uint16_t rx_queue)
2971 struct rte_eth_dev *dev;
2973 if (port_id >= nb_ports) {
2974 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2978 dev = &rte_eth_devices[port_id];
2979 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_syn_filter, -ENOTSUP);
2980 return (*dev->dev_ops->add_syn_filter)(dev, filter, rx_queue);
2984 rte_eth_dev_remove_syn_filter(uint8_t port_id)
2986 struct rte_eth_dev *dev;
2988 if (port_id >= nb_ports) {
2989 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2993 dev = &rte_eth_devices[port_id];
2994 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_syn_filter, -ENOTSUP);
2995 return (*dev->dev_ops->remove_syn_filter)(dev);
2999 rte_eth_dev_get_syn_filter(uint8_t port_id,
3000 struct rte_syn_filter *filter, uint16_t *rx_queue)
3002 struct rte_eth_dev *dev;
3004 if (filter == NULL || rx_queue == NULL)
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->get_syn_filter, -ENOTSUP);
3014 return (*dev->dev_ops->get_syn_filter)(dev, filter, rx_queue);
3018 rte_eth_dev_add_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 (port_id >= nb_ports) {
3024 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3027 if (filter->ethertype == ETHER_TYPE_IPv4 ||
3028 filter->ethertype == ETHER_TYPE_IPv6){
3029 PMD_DEBUG_TRACE("IP and IPv6 are not supported"
3030 " in ethertype filter\n");
3033 dev = &rte_eth_devices[port_id];
3034 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_ethertype_filter, -ENOTSUP);
3035 return (*dev->dev_ops->add_ethertype_filter)(dev, index,
3040 rte_eth_dev_remove_ethertype_filter(uint8_t port_id, uint16_t index)
3042 struct rte_eth_dev *dev;
3044 if (port_id >= nb_ports) {
3045 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3049 dev = &rte_eth_devices[port_id];
3050 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_ethertype_filter, -ENOTSUP);
3051 return (*dev->dev_ops->remove_ethertype_filter)(dev, index);
3055 rte_eth_dev_get_ethertype_filter(uint8_t port_id, uint16_t index,
3056 struct rte_ethertype_filter *filter, uint16_t *rx_queue)
3058 struct rte_eth_dev *dev;
3060 if (filter == NULL || rx_queue == NULL)
3063 if (port_id >= nb_ports) {
3064 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3068 dev = &rte_eth_devices[port_id];
3069 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_ethertype_filter, -ENOTSUP);
3070 return (*dev->dev_ops->get_ethertype_filter)(dev, index,
3075 rte_eth_dev_add_2tuple_filter(uint8_t port_id, uint16_t index,
3076 struct rte_2tuple_filter *filter, uint16_t rx_queue)
3078 struct rte_eth_dev *dev;
3080 if (port_id >= nb_ports) {
3081 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3084 if (filter->protocol != IPPROTO_TCP &&
3085 filter->tcp_flags != 0){
3086 PMD_DEBUG_TRACE("tcp flags is 0x%x, but the protocol value"
3092 dev = &rte_eth_devices[port_id];
3093 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_2tuple_filter, -ENOTSUP);
3094 return (*dev->dev_ops->add_2tuple_filter)(dev, index, filter, rx_queue);
3098 rte_eth_dev_remove_2tuple_filter(uint8_t port_id, uint16_t index)
3100 struct rte_eth_dev *dev;
3102 if (port_id >= nb_ports) {
3103 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3107 dev = &rte_eth_devices[port_id];
3108 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_2tuple_filter, -ENOTSUP);
3109 return (*dev->dev_ops->remove_2tuple_filter)(dev, index);
3113 rte_eth_dev_get_2tuple_filter(uint8_t port_id, uint16_t index,
3114 struct rte_2tuple_filter *filter, uint16_t *rx_queue)
3116 struct rte_eth_dev *dev;
3118 if (filter == NULL || rx_queue == NULL)
3121 if (port_id >= nb_ports) {
3122 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3126 dev = &rte_eth_devices[port_id];
3127 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_2tuple_filter, -ENOTSUP);
3128 return (*dev->dev_ops->get_2tuple_filter)(dev, index, filter, rx_queue);
3132 rte_eth_dev_add_5tuple_filter(uint8_t port_id, uint16_t index,
3133 struct rte_5tuple_filter *filter, uint16_t rx_queue)
3135 struct rte_eth_dev *dev;
3137 if (port_id >= nb_ports) {
3138 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3142 if (filter->protocol != IPPROTO_TCP &&
3143 filter->tcp_flags != 0){
3144 PMD_DEBUG_TRACE("tcp flags is 0x%x, but the protocol value"
3150 dev = &rte_eth_devices[port_id];
3151 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_5tuple_filter, -ENOTSUP);
3152 return (*dev->dev_ops->add_5tuple_filter)(dev, index, filter, rx_queue);
3156 rte_eth_dev_remove_5tuple_filter(uint8_t port_id, uint16_t index)
3158 struct rte_eth_dev *dev;
3160 if (port_id >= nb_ports) {
3161 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3165 dev = &rte_eth_devices[port_id];
3166 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_5tuple_filter, -ENOTSUP);
3167 return (*dev->dev_ops->remove_5tuple_filter)(dev, index);
3171 rte_eth_dev_get_5tuple_filter(uint8_t port_id, uint16_t index,
3172 struct rte_5tuple_filter *filter, uint16_t *rx_queue)
3174 struct rte_eth_dev *dev;
3176 if (filter == NULL || rx_queue == NULL)
3179 if (port_id >= nb_ports) {
3180 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3184 dev = &rte_eth_devices[port_id];
3185 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_5tuple_filter, -ENOTSUP);
3186 return (*dev->dev_ops->get_5tuple_filter)(dev, index, filter,
3191 rte_eth_dev_add_flex_filter(uint8_t port_id, uint16_t index,
3192 struct rte_flex_filter *filter, uint16_t rx_queue)
3194 struct rte_eth_dev *dev;
3196 if (port_id >= nb_ports) {
3197 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3201 dev = &rte_eth_devices[port_id];
3202 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_flex_filter, -ENOTSUP);
3203 return (*dev->dev_ops->add_flex_filter)(dev, index, filter, rx_queue);
3207 rte_eth_dev_remove_flex_filter(uint8_t port_id, uint16_t index)
3209 struct rte_eth_dev *dev;
3211 if (port_id >= nb_ports) {
3212 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3216 dev = &rte_eth_devices[port_id];
3217 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_flex_filter, -ENOTSUP);
3218 return (*dev->dev_ops->remove_flex_filter)(dev, index);
3222 rte_eth_dev_get_flex_filter(uint8_t port_id, uint16_t index,
3223 struct rte_flex_filter *filter, uint16_t *rx_queue)
3225 struct rte_eth_dev *dev;
3227 if (filter == NULL || rx_queue == NULL)
3230 if (port_id >= nb_ports) {
3231 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3235 dev = &rte_eth_devices[port_id];
3236 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_flex_filter, -ENOTSUP);
3237 return (*dev->dev_ops->get_flex_filter)(dev, index, filter,
3242 rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
3244 struct rte_eth_dev *dev;
3246 if (port_id >= nb_ports) {
3247 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3251 dev = &rte_eth_devices[port_id];
3252 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3253 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3254 RTE_ETH_FILTER_NOP, NULL);
3258 rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
3259 enum rte_filter_op filter_op, void *arg)
3261 struct rte_eth_dev *dev;
3263 if (port_id >= nb_ports) {
3264 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3268 dev = &rte_eth_devices[port_id];
3269 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3270 return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);