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 (*dev->dev_ops->dev_infos_get)(dev, &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 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1026 socket_id, rx_conf, mp);
1028 if (!dev->data->min_rx_buf_size ||
1029 dev->data->min_rx_buf_size > mbp_buf_size)
1030 dev->data->min_rx_buf_size = mbp_buf_size;
1037 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
1038 uint16_t nb_tx_desc, unsigned int socket_id,
1039 const struct rte_eth_txconf *tx_conf)
1041 struct rte_eth_dev *dev;
1043 /* This function is only safe when called from the primary process
1044 * in a multi-process setup*/
1045 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
1047 if (port_id >= RTE_MAX_ETHPORTS || port_id >= nb_ports) {
1048 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1051 dev = &rte_eth_devices[port_id];
1052 if (tx_queue_id >= dev->data->nb_tx_queues) {
1053 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1057 if (dev->data->dev_started) {
1059 "port %d must be stopped to allow configuration\n", port_id);
1063 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1064 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
1065 socket_id, tx_conf);
1069 rte_eth_promiscuous_enable(uint8_t port_id)
1071 struct rte_eth_dev *dev;
1073 if (port_id >= nb_ports) {
1074 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1077 dev = &rte_eth_devices[port_id];
1079 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1080 (*dev->dev_ops->promiscuous_enable)(dev);
1081 dev->data->promiscuous = 1;
1085 rte_eth_promiscuous_disable(uint8_t port_id)
1087 struct rte_eth_dev *dev;
1089 if (port_id >= nb_ports) {
1090 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1093 dev = &rte_eth_devices[port_id];
1095 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1096 dev->data->promiscuous = 0;
1097 (*dev->dev_ops->promiscuous_disable)(dev);
1101 rte_eth_promiscuous_get(uint8_t port_id)
1103 struct rte_eth_dev *dev;
1105 if (port_id >= nb_ports) {
1106 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1110 dev = &rte_eth_devices[port_id];
1111 return dev->data->promiscuous;
1115 rte_eth_allmulticast_enable(uint8_t port_id)
1117 struct rte_eth_dev *dev;
1119 if (port_id >= nb_ports) {
1120 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1123 dev = &rte_eth_devices[port_id];
1125 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1126 (*dev->dev_ops->allmulticast_enable)(dev);
1127 dev->data->all_multicast = 1;
1131 rte_eth_allmulticast_disable(uint8_t port_id)
1133 struct rte_eth_dev *dev;
1135 if (port_id >= nb_ports) {
1136 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1139 dev = &rte_eth_devices[port_id];
1141 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1142 dev->data->all_multicast = 0;
1143 (*dev->dev_ops->allmulticast_disable)(dev);
1147 rte_eth_allmulticast_get(uint8_t port_id)
1149 struct rte_eth_dev *dev;
1151 if (port_id >= nb_ports) {
1152 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1156 dev = &rte_eth_devices[port_id];
1157 return dev->data->all_multicast;
1161 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
1162 struct rte_eth_link *link)
1164 struct rte_eth_link *dst = link;
1165 struct rte_eth_link *src = &(dev->data->dev_link);
1167 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1168 *(uint64_t *)src) == 0)
1175 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
1177 struct rte_eth_dev *dev;
1179 if (port_id >= nb_ports) {
1180 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1183 dev = &rte_eth_devices[port_id];
1185 if (dev->data->dev_conf.intr_conf.lsc != 0)
1186 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1188 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1189 (*dev->dev_ops->link_update)(dev, 1);
1190 *eth_link = dev->data->dev_link;
1195 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
1197 struct rte_eth_dev *dev;
1199 if (port_id >= nb_ports) {
1200 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1203 dev = &rte_eth_devices[port_id];
1205 if (dev->data->dev_conf.intr_conf.lsc != 0)
1206 rte_eth_dev_atomic_read_link_status(dev, eth_link);
1208 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1209 (*dev->dev_ops->link_update)(dev, 0);
1210 *eth_link = dev->data->dev_link;
1215 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
1217 struct rte_eth_dev *dev;
1219 if (port_id >= nb_ports) {
1220 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1223 dev = &rte_eth_devices[port_id];
1224 memset(stats, 0, sizeof(*stats));
1226 FUNC_PTR_OR_RET(*dev->dev_ops->stats_get);
1227 (*dev->dev_ops->stats_get)(dev, stats);
1228 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1232 rte_eth_stats_reset(uint8_t port_id)
1234 struct rte_eth_dev *dev;
1236 if (port_id >= nb_ports) {
1237 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1240 dev = &rte_eth_devices[port_id];
1242 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
1243 (*dev->dev_ops->stats_reset)(dev);
1246 /* retrieve ethdev extended statistics */
1248 rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
1251 struct rte_eth_stats eth_stats;
1252 struct rte_eth_dev *dev;
1253 unsigned count, i, q;
1257 if (port_id >= nb_ports) {
1258 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1261 dev = &rte_eth_devices[port_id];
1263 /* implemented by the driver */
1264 if (dev->dev_ops->xstats_get != NULL)
1265 return (*dev->dev_ops->xstats_get)(dev, xstats, n);
1267 /* else, return generic statistics */
1268 count = RTE_NB_STATS;
1269 count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
1270 count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
1274 /* now fill the xstats structure */
1277 memset(ð_stats, 0, sizeof(eth_stats));
1278 rte_eth_stats_get(port_id, ð_stats);
1281 for (i = 0; i < RTE_NB_STATS; i++) {
1282 stats_ptr = (char *)ð_stats + rte_stats_strings[i].offset;
1283 val = *(uint64_t *)stats_ptr;
1284 snprintf(xstats[count].name, sizeof(xstats[count].name),
1285 "%s", rte_stats_strings[i].name);
1286 xstats[count++].value = val;
1290 for (q = 0; q < dev->data->nb_rx_queues; q++) {
1291 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
1292 stats_ptr = (char *)ð_stats;
1293 stats_ptr += rte_rxq_stats_strings[i].offset;
1294 stats_ptr += q * sizeof(uint64_t);
1295 val = *(uint64_t *)stats_ptr;
1296 snprintf(xstats[count].name, sizeof(xstats[count].name),
1297 "rx_queue_%u_%s", q,
1298 rte_rxq_stats_strings[i].name);
1299 xstats[count++].value = val;
1304 for (q = 0; q < dev->data->nb_tx_queues; q++) {
1305 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
1306 stats_ptr = (char *)ð_stats;
1307 stats_ptr += rte_txq_stats_strings[i].offset;
1308 stats_ptr += q * sizeof(uint64_t);
1309 val = *(uint64_t *)stats_ptr;
1310 snprintf(xstats[count].name, sizeof(xstats[count].name),
1311 "tx_queue_%u_%s", q,
1312 rte_txq_stats_strings[i].name);
1313 xstats[count++].value = val;
1320 /* reset ethdev extended statistics */
1322 rte_eth_xstats_reset(uint8_t port_id)
1324 struct rte_eth_dev *dev;
1326 if (port_id >= nb_ports) {
1327 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1330 dev = &rte_eth_devices[port_id];
1332 /* implemented by the driver */
1333 if (dev->dev_ops->xstats_reset != NULL) {
1334 (*dev->dev_ops->xstats_reset)(dev);
1338 /* fallback to default */
1339 rte_eth_stats_reset(port_id);
1343 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
1346 struct rte_eth_dev *dev;
1348 if (port_id >= nb_ports) {
1349 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1352 dev = &rte_eth_devices[port_id];
1354 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1355 return (*dev->dev_ops->queue_stats_mapping_set)
1356 (dev, queue_id, stat_idx, is_rx);
1361 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1364 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1370 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1373 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1379 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1381 struct rte_eth_dev *dev;
1383 if (port_id >= nb_ports) {
1384 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1387 dev = &rte_eth_devices[port_id];
1389 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
1391 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1392 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1393 dev_info->pci_dev = dev->pci_dev;
1395 dev_info->driver_name = dev->driver->pci_drv.name;
1399 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1401 struct rte_eth_dev *dev;
1403 if (port_id >= nb_ports) {
1404 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1407 dev = &rte_eth_devices[port_id];
1408 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1413 rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
1415 struct rte_eth_dev *dev;
1417 if (port_id >= nb_ports) {
1418 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1422 dev = &rte_eth_devices[port_id];
1423 *mtu = dev->data->mtu;
1428 rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
1431 struct rte_eth_dev *dev;
1433 if (port_id >= nb_ports) {
1434 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1438 dev = &rte_eth_devices[port_id];
1439 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
1441 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
1443 dev->data->mtu = mtu;
1449 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1451 struct rte_eth_dev *dev;
1453 if (port_id >= nb_ports) {
1454 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1457 dev = &rte_eth_devices[port_id];
1458 if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1459 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1463 if (vlan_id > 4095) {
1464 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1465 port_id, (unsigned) vlan_id);
1468 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1469 (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1474 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1476 struct rte_eth_dev *dev;
1478 if (port_id >= nb_ports) {
1479 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1483 dev = &rte_eth_devices[port_id];
1484 if (rx_queue_id >= dev->data->nb_rx_queues) {
1485 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1489 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1490 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1496 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1498 struct rte_eth_dev *dev;
1500 if (port_id >= nb_ports) {
1501 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1505 dev = &rte_eth_devices[port_id];
1506 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1507 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1513 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1515 struct rte_eth_dev *dev;
1520 if (port_id >= nb_ports) {
1521 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1525 dev = &rte_eth_devices[port_id];
1527 /*check which option changed by application*/
1528 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1529 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1531 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1532 mask |= ETH_VLAN_STRIP_MASK;
1535 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1536 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1538 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1539 mask |= ETH_VLAN_FILTER_MASK;
1542 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1543 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1545 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1546 mask |= ETH_VLAN_EXTEND_MASK;
1553 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1554 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1560 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1562 struct rte_eth_dev *dev;
1565 if (port_id >= nb_ports) {
1566 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1570 dev = &rte_eth_devices[port_id];
1572 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1573 ret |= ETH_VLAN_STRIP_OFFLOAD ;
1575 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1576 ret |= ETH_VLAN_FILTER_OFFLOAD ;
1578 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1579 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
1585 rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
1587 struct rte_eth_dev *dev;
1589 if (port_id >= nb_ports) {
1590 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1593 dev = &rte_eth_devices[port_id];
1594 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
1595 (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
1601 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1602 struct rte_fdir_filter *fdir_filter,
1605 struct rte_eth_dev *dev;
1607 if (port_id >= nb_ports) {
1608 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1612 dev = &rte_eth_devices[port_id];
1614 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1615 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1616 port_id, dev->data->dev_conf.fdir_conf.mode);
1620 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1621 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1622 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1623 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1624 "None l4type, source & destinations ports " \
1625 "should be null!\n");
1629 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1630 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1635 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1636 struct rte_fdir_filter *fdir_filter,
1639 struct rte_eth_dev *dev;
1641 if (port_id >= nb_ports) {
1642 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1646 dev = &rte_eth_devices[port_id];
1648 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1649 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1650 port_id, dev->data->dev_conf.fdir_conf.mode);
1654 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1655 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1656 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1657 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1658 "None l4type, source & destinations ports " \
1659 "should be null!\n");
1663 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
1664 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
1670 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
1671 struct rte_fdir_filter *fdir_filter)
1673 struct rte_eth_dev *dev;
1675 if (port_id >= nb_ports) {
1676 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1680 dev = &rte_eth_devices[port_id];
1682 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1683 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1684 port_id, dev->data->dev_conf.fdir_conf.mode);
1688 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1689 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1690 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1691 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1692 "None l4type source & destinations ports " \
1693 "should be null!\n");
1697 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
1698 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
1702 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
1704 struct rte_eth_dev *dev;
1706 if (port_id >= nb_ports) {
1707 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1711 dev = &rte_eth_devices[port_id];
1712 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1713 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1717 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
1719 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
1724 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
1725 struct rte_fdir_filter *fdir_filter,
1726 uint16_t soft_id, uint8_t queue,
1729 struct rte_eth_dev *dev;
1731 if (port_id >= nb_ports) {
1732 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1736 dev = &rte_eth_devices[port_id];
1738 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1739 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1740 port_id, dev->data->dev_conf.fdir_conf.mode);
1744 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1745 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1746 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1747 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1748 "None l4type, source & destinations ports " \
1749 "should be null!\n");
1753 /* For now IPv6 is not supported with perfect filter */
1754 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1757 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
1758 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
1764 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
1765 struct rte_fdir_filter *fdir_filter,
1766 uint16_t soft_id, uint8_t queue,
1769 struct rte_eth_dev *dev;
1771 if (port_id >= nb_ports) {
1772 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1776 dev = &rte_eth_devices[port_id];
1778 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1779 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1780 port_id, dev->data->dev_conf.fdir_conf.mode);
1784 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1785 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1786 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1787 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1788 "None l4type, source & destinations ports " \
1789 "should be null!\n");
1793 /* For now IPv6 is not supported with perfect filter */
1794 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1797 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
1798 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
1799 soft_id, queue, drop);
1803 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
1804 struct rte_fdir_filter *fdir_filter,
1807 struct rte_eth_dev *dev;
1809 if (port_id >= nb_ports) {
1810 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1814 dev = &rte_eth_devices[port_id];
1816 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1817 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1818 port_id, dev->data->dev_conf.fdir_conf.mode);
1822 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1823 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1824 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1825 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1826 "None l4type, source & destinations ports " \
1827 "should be null!\n");
1831 /* For now IPv6 is not supported with perfect filter */
1832 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1835 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
1836 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
1841 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
1843 struct rte_eth_dev *dev;
1845 if (port_id >= nb_ports) {
1846 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1850 dev = &rte_eth_devices[port_id];
1851 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1852 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1856 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
1857 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
1861 rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1863 struct rte_eth_dev *dev;
1865 if (port_id >= nb_ports) {
1866 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1870 dev = &rte_eth_devices[port_id];
1871 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
1872 memset(fc_conf, 0, sizeof(*fc_conf));
1873 return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
1877 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1879 struct rte_eth_dev *dev;
1881 if (port_id >= nb_ports) {
1882 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1886 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1887 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1891 dev = &rte_eth_devices[port_id];
1892 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1893 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1897 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1899 struct rte_eth_dev *dev;
1901 if (port_id >= nb_ports) {
1902 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1906 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1907 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1911 dev = &rte_eth_devices[port_id];
1912 /* High water, low water validation are device specific */
1913 if (*dev->dev_ops->priority_flow_ctrl_set)
1914 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1919 rte_eth_dev_rss_reta_update(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
1921 struct rte_eth_dev *dev;
1925 if (port_id >= nb_ports) {
1926 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1930 /* Invalid mask bit(s) setting */
1931 if ((reta_conf->mask_lo == 0) && (reta_conf->mask_hi == 0)) {
1932 PMD_DEBUG_TRACE("Invalid update mask bits for port=%d\n",port_id);
1936 dev = &rte_eth_devices[port_id];
1937 max_rxq = (dev->data->nb_rx_queues <= ETH_RSS_RETA_MAX_QUEUE) ?
1938 dev->data->nb_rx_queues : ETH_RSS_RETA_MAX_QUEUE;
1939 if (reta_conf->mask_lo != 0) {
1940 for (i = 0; i < ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
1941 if ((reta_conf->mask_lo & (1ULL << i)) &&
1942 (reta_conf->reta[i] >= max_rxq)) {
1943 PMD_DEBUG_TRACE("RETA hash index output"
1944 "configration for port=%d,invalid"
1945 "queue=%d\n",port_id,reta_conf->reta[i]);
1952 if (reta_conf->mask_hi != 0) {
1953 for (i = 0; i< ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
1954 j = (uint8_t)(i + ETH_RSS_RETA_NUM_ENTRIES/2);
1956 /* Check if the max entry >= 128 */
1957 if ((reta_conf->mask_hi & (1ULL << i)) &&
1958 (reta_conf->reta[j] >= max_rxq)) {
1959 PMD_DEBUG_TRACE("RETA hash index output"
1960 "configration for port=%d,invalid"
1961 "queue=%d\n",port_id,reta_conf->reta[j]);
1968 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
1969 return (*dev->dev_ops->reta_update)(dev, reta_conf);
1973 rte_eth_dev_rss_reta_query(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
1975 struct rte_eth_dev *dev;
1977 if (port_id >= nb_ports) {
1978 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1982 if((reta_conf->mask_lo == 0) && (reta_conf->mask_hi == 0)) {
1983 PMD_DEBUG_TRACE("Invalid update mask bits for the port=%d\n",port_id);
1987 dev = &rte_eth_devices[port_id];
1988 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
1989 return (*dev->dev_ops->reta_query)(dev, reta_conf);
1993 rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
1995 struct rte_eth_dev *dev;
1996 uint16_t rss_hash_protos;
1998 if (port_id >= nb_ports) {
1999 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2002 rss_hash_protos = rss_conf->rss_hf;
2003 if ((rss_hash_protos != 0) &&
2004 ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) {
2005 PMD_DEBUG_TRACE("Invalid rss_hash_protos=0x%x\n",
2009 dev = &rte_eth_devices[port_id];
2010 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2011 return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
2015 rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
2016 struct rte_eth_rss_conf *rss_conf)
2018 struct rte_eth_dev *dev;
2020 if (port_id >= nb_ports) {
2021 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2024 dev = &rte_eth_devices[port_id];
2025 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2026 return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
2030 rte_eth_led_on(uint8_t port_id)
2032 struct rte_eth_dev *dev;
2034 if (port_id >= nb_ports) {
2035 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2039 dev = &rte_eth_devices[port_id];
2040 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2041 return ((*dev->dev_ops->dev_led_on)(dev));
2045 rte_eth_led_off(uint8_t port_id)
2047 struct rte_eth_dev *dev;
2049 if (port_id >= nb_ports) {
2050 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2054 dev = &rte_eth_devices[port_id];
2055 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2056 return ((*dev->dev_ops->dev_led_off)(dev));
2060 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2064 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2066 struct rte_eth_dev_info dev_info;
2067 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2070 rte_eth_dev_info_get(port_id, &dev_info);
2072 for (i = 0; i < dev_info.max_mac_addrs; i++)
2073 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2079 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
2082 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
2085 struct rte_eth_dev *dev;
2089 if (port_id >= nb_ports) {
2090 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2093 dev = &rte_eth_devices[port_id];
2094 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2096 if (is_zero_ether_addr(addr)) {
2097 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2101 if (pool >= ETH_64_POOLS) {
2102 PMD_DEBUG_TRACE("pool id must be 0-%d\n",ETH_64_POOLS - 1);
2106 index = get_mac_addr_index(port_id, addr);
2108 index = get_mac_addr_index(port_id, &null_mac_addr);
2110 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2115 pool_mask = dev->data->mac_pool_sel[index];
2117 /* Check if both MAC address and pool is alread there, and do nothing */
2118 if (pool_mask & (1ULL << pool))
2123 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2125 /* Update address in NIC data structure */
2126 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2128 /* Update pool bitmap in NIC data structure */
2129 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2135 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
2137 struct rte_eth_dev *dev;
2140 if (port_id >= nb_ports) {
2141 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2144 dev = &rte_eth_devices[port_id];
2145 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2147 index = get_mac_addr_index(port_id, addr);
2149 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2150 return (-EADDRINUSE);
2151 } else if (index < 0)
2152 return 0; /* Do nothing if address wasn't found */
2155 (*dev->dev_ops->mac_addr_remove)(dev, index);
2157 /* Update address in NIC data structure */
2158 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2164 rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
2165 uint16_t rx_mode, uint8_t on)
2168 struct rte_eth_dev *dev;
2169 struct rte_eth_dev_info dev_info;
2171 if (port_id >= nb_ports) {
2172 PMD_DEBUG_TRACE("set VF RX mode:Invalid port_id=%d\n",
2177 dev = &rte_eth_devices[port_id];
2178 rte_eth_dev_info_get(port_id, &dev_info);
2180 num_vfs = dev_info.max_vfs;
2183 PMD_DEBUG_TRACE("set VF RX mode:invalid VF id %d\n", vf);
2188 PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
2191 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
2192 return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
2196 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2200 get_hash_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
2202 struct rte_eth_dev_info dev_info;
2203 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2206 rte_eth_dev_info_get(port_id, &dev_info);
2207 if (!dev->data->hash_mac_addrs)
2210 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
2211 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
2212 ETHER_ADDR_LEN) == 0)
2219 rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
2224 struct rte_eth_dev *dev;
2226 if (port_id >= nb_ports) {
2227 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2232 dev = &rte_eth_devices[port_id];
2233 if (is_zero_ether_addr(addr)) {
2234 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2239 index = get_hash_mac_addr_index(port_id, addr);
2240 /* Check if it's already there, and do nothing */
2241 if ((index >= 0) && (on))
2246 PMD_DEBUG_TRACE("port %d: the MAC address was not"
2247 "set in UTA\n", port_id);
2251 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
2253 PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2259 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
2260 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
2262 /* Update address in NIC data structure */
2264 ether_addr_copy(addr,
2265 &dev->data->hash_mac_addrs[index]);
2267 ether_addr_copy(&null_mac_addr,
2268 &dev->data->hash_mac_addrs[index]);
2275 rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
2277 struct rte_eth_dev *dev;
2279 if (port_id >= nb_ports) {
2280 PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
2285 dev = &rte_eth_devices[port_id];
2287 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
2288 return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
2292 rte_eth_dev_set_vf_rx(uint8_t port_id,uint16_t vf, uint8_t on)
2295 struct rte_eth_dev *dev;
2296 struct rte_eth_dev_info dev_info;
2298 if (port_id >= nb_ports) {
2299 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2303 dev = &rte_eth_devices[port_id];
2304 rte_eth_dev_info_get(port_id, &dev_info);
2306 num_vfs = dev_info.max_vfs;
2309 PMD_DEBUG_TRACE("port %d: invalid vf id\n", port_id);
2313 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
2314 return (*dev->dev_ops->set_vf_rx)(dev, vf,on);
2318 rte_eth_dev_set_vf_tx(uint8_t port_id,uint16_t vf, uint8_t on)
2321 struct rte_eth_dev *dev;
2322 struct rte_eth_dev_info dev_info;
2324 if (port_id >= nb_ports) {
2325 PMD_DEBUG_TRACE("set pool tx:Invalid port_id=%d\n", port_id);
2329 dev = &rte_eth_devices[port_id];
2330 rte_eth_dev_info_get(port_id, &dev_info);
2332 num_vfs = dev_info.max_vfs;
2335 PMD_DEBUG_TRACE("set pool tx:invalid pool id=%d\n", vf);
2339 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
2340 return (*dev->dev_ops->set_vf_tx)(dev, vf,on);
2344 rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
2345 uint64_t vf_mask,uint8_t vlan_on)
2347 struct rte_eth_dev *dev;
2349 if (port_id >= nb_ports) {
2350 PMD_DEBUG_TRACE("VF VLAN filter:invalid port id=%d\n",
2354 dev = &rte_eth_devices[port_id];
2356 if(vlan_id > ETHER_MAX_VLAN_ID)
2358 PMD_DEBUG_TRACE("VF VLAN filter:invalid VLAN id=%d\n",
2364 PMD_DEBUG_TRACE("VF VLAN filter:pool_mask can not be 0\n");
2368 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
2369 return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
2373 int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
2376 struct rte_eth_dev *dev;
2377 struct rte_eth_dev_info dev_info;
2378 struct rte_eth_link link;
2380 if (port_id >= nb_ports) {
2381 PMD_DEBUG_TRACE("set queue rate limit:invalid port id=%d\n",
2386 dev = &rte_eth_devices[port_id];
2387 rte_eth_dev_info_get(port_id, &dev_info);
2388 link = dev->data->dev_link;
2390 if (queue_idx > dev_info.max_tx_queues) {
2391 PMD_DEBUG_TRACE("set queue rate limit:port %d: "
2392 "invalid queue id=%d\n", port_id, queue_idx);
2396 if (tx_rate > link.link_speed) {
2397 PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
2398 "bigger than link speed= %d\n",
2399 tx_rate, link.link_speed);
2403 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
2404 return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
2407 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
2410 struct rte_eth_dev *dev;
2411 struct rte_eth_dev_info dev_info;
2412 struct rte_eth_link link;
2417 if (port_id >= nb_ports) {
2418 PMD_DEBUG_TRACE("set VF rate limit:invalid port id=%d\n",
2423 dev = &rte_eth_devices[port_id];
2424 rte_eth_dev_info_get(port_id, &dev_info);
2425 link = dev->data->dev_link;
2427 if (vf > dev_info.max_vfs) {
2428 PMD_DEBUG_TRACE("set VF rate limit:port %d: "
2429 "invalid vf id=%d\n", port_id, vf);
2433 if (tx_rate > link.link_speed) {
2434 PMD_DEBUG_TRACE("set VF rate limit:invalid tx_rate=%d, "
2435 "bigger than link speed= %d\n",
2436 tx_rate, link.link_speed);
2440 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
2441 return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
2445 rte_eth_mirror_rule_set(uint8_t port_id,
2446 struct rte_eth_vmdq_mirror_conf *mirror_conf,
2447 uint8_t rule_id, uint8_t on)
2449 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2451 if (port_id >= nb_ports) {
2452 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2456 if (mirror_conf->rule_type_mask == 0) {
2457 PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
2461 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
2462 PMD_DEBUG_TRACE("Invalid dst pool, pool id must"
2463 "be 0-%d\n",ETH_64_POOLS - 1);
2467 if ((mirror_conf->rule_type_mask & ETH_VMDQ_POOL_MIRROR) &&
2468 (mirror_conf->pool_mask == 0)) {
2469 PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not"
2474 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2476 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2477 ETH_VMDQ_NUM_MIRROR_RULE - 1);
2481 dev = &rte_eth_devices[port_id];
2482 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
2484 return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
2488 rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
2490 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2492 if (port_id >= nb_ports) {
2493 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2497 if(rule_id >= ETH_VMDQ_NUM_MIRROR_RULE)
2499 PMD_DEBUG_TRACE("Invalid rule_id, rule_id must be 0-%d\n",
2500 ETH_VMDQ_NUM_MIRROR_RULE-1);
2504 dev = &rte_eth_devices[port_id];
2505 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
2507 return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
2510 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
2512 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
2513 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2515 struct rte_eth_dev *dev;
2517 if (port_id >= nb_ports) {
2518 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2521 dev = &rte_eth_devices[port_id];
2522 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, -ENOTSUP);
2523 if (queue_id >= dev->data->nb_rx_queues) {
2524 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
2527 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
2532 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
2533 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2535 struct rte_eth_dev *dev;
2537 if (port_id >= nb_ports) {
2538 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2541 dev = &rte_eth_devices[port_id];
2543 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, -ENOTSUP);
2544 if (queue_id >= dev->data->nb_tx_queues) {
2545 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
2548 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
2553 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
2555 struct rte_eth_dev *dev;
2557 if (port_id >= nb_ports) {
2558 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2561 dev = &rte_eth_devices[port_id];
2562 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, -ENOTSUP);
2563 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
2567 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
2569 struct rte_eth_dev *dev;
2571 if (port_id >= nb_ports) {
2572 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2575 dev = &rte_eth_devices[port_id];
2576 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
2577 return (*dev->dev_ops->rx_descriptor_done)( \
2578 dev->data->rx_queues[queue_id], offset);
2583 rte_eth_dev_callback_register(uint8_t port_id,
2584 enum rte_eth_event_type event,
2585 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2587 struct rte_eth_dev *dev;
2588 struct rte_eth_dev_callback *user_cb;
2592 if (port_id >= nb_ports) {
2593 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2597 dev = &rte_eth_devices[port_id];
2598 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2600 TAILQ_FOREACH(user_cb, &(dev->callbacks), next) {
2601 if (user_cb->cb_fn == cb_fn &&
2602 user_cb->cb_arg == cb_arg &&
2603 user_cb->event == event) {
2608 /* create a new callback. */
2609 if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
2610 sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
2611 user_cb->cb_fn = cb_fn;
2612 user_cb->cb_arg = cb_arg;
2613 user_cb->event = event;
2614 TAILQ_INSERT_TAIL(&(dev->callbacks), user_cb, next);
2617 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2618 return ((user_cb == NULL) ? -ENOMEM : 0);
2622 rte_eth_dev_callback_unregister(uint8_t port_id,
2623 enum rte_eth_event_type event,
2624 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
2627 struct rte_eth_dev *dev;
2628 struct rte_eth_dev_callback *cb, *next;
2632 if (port_id >= nb_ports) {
2633 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2637 dev = &rte_eth_devices[port_id];
2638 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2641 for (cb = TAILQ_FIRST(&dev->callbacks); cb != NULL; cb = next) {
2643 next = TAILQ_NEXT(cb, next);
2645 if (cb->cb_fn != cb_fn || cb->event != event ||
2646 (cb->cb_arg != (void *)-1 &&
2647 cb->cb_arg != cb_arg))
2651 * if this callback is not executing right now,
2654 if (cb->active == 0) {
2655 TAILQ_REMOVE(&(dev->callbacks), cb, next);
2662 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2667 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
2668 enum rte_eth_event_type event)
2670 struct rte_eth_dev_callback *cb_lst;
2671 struct rte_eth_dev_callback dev_cb;
2673 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2674 TAILQ_FOREACH(cb_lst, &(dev->callbacks), next) {
2675 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
2679 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2680 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
2682 rte_spinlock_lock(&rte_eth_dev_cb_lock);
2685 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
2687 #ifdef RTE_NIC_BYPASS
2688 int rte_eth_dev_bypass_init(uint8_t port_id)
2690 struct rte_eth_dev *dev;
2692 if (port_id >= nb_ports) {
2693 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2697 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2698 PMD_DEBUG_TRACE("Invalid port device\n");
2702 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
2703 (*dev->dev_ops->bypass_init)(dev);
2708 rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
2710 struct rte_eth_dev *dev;
2712 if (port_id >= nb_ports) {
2713 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2717 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2718 PMD_DEBUG_TRACE("Invalid port device\n");
2721 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2722 (*dev->dev_ops->bypass_state_show)(dev, state);
2727 rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
2729 struct rte_eth_dev *dev;
2731 if (port_id >= nb_ports) {
2732 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2736 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2737 PMD_DEBUG_TRACE("Invalid port device\n");
2741 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
2742 (*dev->dev_ops->bypass_state_set)(dev, new_state);
2747 rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
2749 struct rte_eth_dev *dev;
2751 if (port_id >= nb_ports) {
2752 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2756 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2757 PMD_DEBUG_TRACE("Invalid port device\n");
2761 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
2762 (*dev->dev_ops->bypass_event_show)(dev, event, state);
2767 rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
2769 struct rte_eth_dev *dev;
2771 if (port_id >= nb_ports) {
2772 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2776 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2777 PMD_DEBUG_TRACE("Invalid port device\n");
2781 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
2782 (*dev->dev_ops->bypass_event_set)(dev, event, state);
2787 rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
2789 struct rte_eth_dev *dev;
2791 if (port_id >= nb_ports) {
2792 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2796 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2797 PMD_DEBUG_TRACE("Invalid port device\n");
2801 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
2802 (*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
2807 rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
2809 struct rte_eth_dev *dev;
2811 if (port_id >= nb_ports) {
2812 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2816 if ((dev= &rte_eth_devices[port_id]) == NULL) {
2817 PMD_DEBUG_TRACE("Invalid port device\n");
2821 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
2822 (*dev->dev_ops->bypass_ver_show)(dev, ver);
2827 rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
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_wd_timeout_show, -ENOTSUP);
2842 (*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
2847 rte_eth_dev_bypass_wd_reset(uint8_t port_id)
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_wd_reset, -ENOTSUP);
2862 (*dev->dev_ops->bypass_wd_reset)(dev);
2868 rte_eth_dev_add_syn_filter(uint8_t port_id,
2869 struct rte_syn_filter *filter, uint16_t rx_queue)
2871 struct rte_eth_dev *dev;
2873 if (port_id >= nb_ports) {
2874 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2878 dev = &rte_eth_devices[port_id];
2879 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_syn_filter, -ENOTSUP);
2880 return (*dev->dev_ops->add_syn_filter)(dev, filter, rx_queue);
2884 rte_eth_dev_remove_syn_filter(uint8_t port_id)
2886 struct rte_eth_dev *dev;
2888 if (port_id >= nb_ports) {
2889 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2893 dev = &rte_eth_devices[port_id];
2894 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_syn_filter, -ENOTSUP);
2895 return (*dev->dev_ops->remove_syn_filter)(dev);
2899 rte_eth_dev_get_syn_filter(uint8_t port_id,
2900 struct rte_syn_filter *filter, uint16_t *rx_queue)
2902 struct rte_eth_dev *dev;
2904 if (filter == NULL || rx_queue == NULL)
2907 if (port_id >= nb_ports) {
2908 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2912 dev = &rte_eth_devices[port_id];
2913 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_syn_filter, -ENOTSUP);
2914 return (*dev->dev_ops->get_syn_filter)(dev, filter, rx_queue);
2918 rte_eth_dev_add_ethertype_filter(uint8_t port_id, uint16_t index,
2919 struct rte_ethertype_filter *filter, uint16_t rx_queue)
2921 struct rte_eth_dev *dev;
2923 if (port_id >= nb_ports) {
2924 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2927 if (filter->ethertype == ETHER_TYPE_IPv4 ||
2928 filter->ethertype == ETHER_TYPE_IPv6){
2929 PMD_DEBUG_TRACE("IP and IPv6 are not supported"
2930 " in ethertype filter\n");
2933 dev = &rte_eth_devices[port_id];
2934 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_ethertype_filter, -ENOTSUP);
2935 return (*dev->dev_ops->add_ethertype_filter)(dev, index,
2940 rte_eth_dev_remove_ethertype_filter(uint8_t port_id, uint16_t index)
2942 struct rte_eth_dev *dev;
2944 if (port_id >= nb_ports) {
2945 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2949 dev = &rte_eth_devices[port_id];
2950 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_ethertype_filter, -ENOTSUP);
2951 return (*dev->dev_ops->remove_ethertype_filter)(dev, index);
2955 rte_eth_dev_get_ethertype_filter(uint8_t port_id, uint16_t index,
2956 struct rte_ethertype_filter *filter, uint16_t *rx_queue)
2958 struct rte_eth_dev *dev;
2960 if (filter == NULL || rx_queue == NULL)
2963 if (port_id >= nb_ports) {
2964 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2968 dev = &rte_eth_devices[port_id];
2969 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_ethertype_filter, -ENOTSUP);
2970 return (*dev->dev_ops->get_ethertype_filter)(dev, index,
2975 rte_eth_dev_add_2tuple_filter(uint8_t port_id, uint16_t index,
2976 struct rte_2tuple_filter *filter, uint16_t rx_queue)
2978 struct rte_eth_dev *dev;
2980 if (port_id >= nb_ports) {
2981 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
2984 if (filter->protocol != IPPROTO_TCP &&
2985 filter->tcp_flags != 0){
2986 PMD_DEBUG_TRACE("tcp flags is 0x%x, but the protocol value"
2992 dev = &rte_eth_devices[port_id];
2993 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_2tuple_filter, -ENOTSUP);
2994 return (*dev->dev_ops->add_2tuple_filter)(dev, index, filter, rx_queue);
2998 rte_eth_dev_remove_2tuple_filter(uint8_t port_id, uint16_t index)
3000 struct rte_eth_dev *dev;
3002 if (port_id >= nb_ports) {
3003 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3007 dev = &rte_eth_devices[port_id];
3008 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_2tuple_filter, -ENOTSUP);
3009 return (*dev->dev_ops->remove_2tuple_filter)(dev, index);
3013 rte_eth_dev_get_2tuple_filter(uint8_t port_id, uint16_t index,
3014 struct rte_2tuple_filter *filter, uint16_t *rx_queue)
3016 struct rte_eth_dev *dev;
3018 if (filter == NULL || rx_queue == NULL)
3021 if (port_id >= nb_ports) {
3022 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3026 dev = &rte_eth_devices[port_id];
3027 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_2tuple_filter, -ENOTSUP);
3028 return (*dev->dev_ops->get_2tuple_filter)(dev, index, filter, rx_queue);
3032 rte_eth_dev_add_5tuple_filter(uint8_t port_id, uint16_t index,
3033 struct rte_5tuple_filter *filter, uint16_t rx_queue)
3035 struct rte_eth_dev *dev;
3037 if (port_id >= nb_ports) {
3038 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3042 if (filter->protocol != IPPROTO_TCP &&
3043 filter->tcp_flags != 0){
3044 PMD_DEBUG_TRACE("tcp flags is 0x%x, but the protocol value"
3050 dev = &rte_eth_devices[port_id];
3051 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_5tuple_filter, -ENOTSUP);
3052 return (*dev->dev_ops->add_5tuple_filter)(dev, index, filter, rx_queue);
3056 rte_eth_dev_remove_5tuple_filter(uint8_t port_id, uint16_t index)
3058 struct rte_eth_dev *dev;
3060 if (port_id >= nb_ports) {
3061 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3065 dev = &rte_eth_devices[port_id];
3066 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_5tuple_filter, -ENOTSUP);
3067 return (*dev->dev_ops->remove_5tuple_filter)(dev, index);
3071 rte_eth_dev_get_5tuple_filter(uint8_t port_id, uint16_t index,
3072 struct rte_5tuple_filter *filter, uint16_t *rx_queue)
3074 struct rte_eth_dev *dev;
3076 if (filter == NULL || rx_queue == NULL)
3079 if (port_id >= nb_ports) {
3080 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3084 dev = &rte_eth_devices[port_id];
3085 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_5tuple_filter, -ENOTSUP);
3086 return (*dev->dev_ops->get_5tuple_filter)(dev, index, filter,
3091 rte_eth_dev_add_flex_filter(uint8_t port_id, uint16_t index,
3092 struct rte_flex_filter *filter, uint16_t rx_queue)
3094 struct rte_eth_dev *dev;
3096 if (port_id >= nb_ports) {
3097 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3101 dev = &rte_eth_devices[port_id];
3102 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->add_flex_filter, -ENOTSUP);
3103 return (*dev->dev_ops->add_flex_filter)(dev, index, filter, rx_queue);
3107 rte_eth_dev_remove_flex_filter(uint8_t port_id, uint16_t index)
3109 struct rte_eth_dev *dev;
3111 if (port_id >= nb_ports) {
3112 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3116 dev = &rte_eth_devices[port_id];
3117 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->remove_flex_filter, -ENOTSUP);
3118 return (*dev->dev_ops->remove_flex_filter)(dev, index);
3122 rte_eth_dev_get_flex_filter(uint8_t port_id, uint16_t index,
3123 struct rte_flex_filter *filter, uint16_t *rx_queue)
3125 struct rte_eth_dev *dev;
3127 if (filter == NULL || rx_queue == NULL)
3130 if (port_id >= nb_ports) {
3131 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
3135 dev = &rte_eth_devices[port_id];
3136 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_flex_filter, -ENOTSUP);
3137 return (*dev->dev_ops->get_flex_filter)(dev, index, filter,