4 * Copyright(c) 2010-2013 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.
35 #include <sys/types.h>
36 #include <sys/queue.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>
69 #include "rte_ether.h"
70 #include "rte_ethdev.h"
72 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
73 #define PMD_DEBUG_TRACE(fmt, args...) do { \
74 RTE_LOG(ERR, PMD, "%s: " fmt, __func__, ## args); \
77 #define PMD_DEBUG_TRACE(fmt, args...)
80 /* Macros for checking for restricting functions to primary instance only */
81 #define PROC_PRIMARY_OR_ERR_RET(retval) do { \
82 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
83 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
87 #define PROC_PRIMARY_OR_RET() do { \
88 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
89 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
94 /* Macros to check for invlaid function pointers in dev_ops structure */
95 #define FUNC_PTR_OR_ERR_RET(func, retval) do { \
96 if ((func) == NULL) { \
97 PMD_DEBUG_TRACE("Function not supported\n"); \
101 #define FUNC_PTR_OR_RET(func) do { \
102 if ((func) == NULL) { \
103 PMD_DEBUG_TRACE("Function not supported\n"); \
108 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
109 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
110 static struct rte_eth_dev_data *rte_eth_dev_data = NULL;
111 static uint8_t nb_ports = 0;
113 /* spinlock for eth device callbacks */
114 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
117 * The user application callback description.
119 * It contains callback address to be registered by user application,
120 * the pointer to the parameters for callback, and the event type.
122 struct rte_eth_dev_callback {
123 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
124 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
125 void *cb_arg; /**< Parameter for callback */
126 enum rte_eth_event_type event; /**< Interrupt event type */
127 uint32_t active; /**< Callback is executing */
136 rte_eth_dev_data_alloc(void)
138 const unsigned flags = 0;
139 const struct rte_memzone *mz;
141 if (rte_eal_process_type() == RTE_PROC_PRIMARY){
142 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
143 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
144 rte_socket_id(), flags);
146 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
148 rte_panic("Cannot allocate memzone for ethernet port data\n");
150 rte_eth_dev_data = mz->addr;
151 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
152 memset(rte_eth_dev_data, 0,
153 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
156 static inline struct rte_eth_dev *
157 rte_eth_dev_allocate(void)
159 struct rte_eth_dev *eth_dev;
161 if (nb_ports == RTE_MAX_ETHPORTS) {
162 PMD_DEBUG_TRACE("Reached maximum number of ethernet ports\n");
166 if (rte_eth_dev_data == NULL)
167 rte_eth_dev_data_alloc();
169 eth_dev = &rte_eth_devices[nb_ports];
170 eth_dev->data = &rte_eth_dev_data[nb_ports];
171 eth_dev->data->port_id = nb_ports++;
176 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
177 struct rte_pci_device *pci_dev)
179 struct eth_driver *eth_drv;
180 struct rte_eth_dev *eth_dev;
183 eth_drv = (struct eth_driver *)pci_drv;
185 eth_dev = rte_eth_dev_allocate();
189 if (rte_eal_process_type() == RTE_PROC_PRIMARY){
190 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
191 eth_drv->dev_private_size,
193 if (eth_dev->data->dev_private == NULL)
194 rte_panic("Cannot allocate memzone for private port data\n");
196 eth_dev->pci_dev = pci_dev;
197 eth_dev->driver = eth_drv;
198 eth_dev->data->rx_mbuf_alloc_failed = 0;
200 /* init user callbacks */
201 TAILQ_INIT(&(eth_dev->callbacks));
204 * Set the default maximum frame size.
206 eth_dev->data->max_frame_size = ETHER_MAX_LEN;
208 /* Invoke PMD device initialization function */
209 diag = (*eth_drv->eth_dev_init)(eth_drv, eth_dev);
213 PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x)"
214 " failed\n", pci_drv->name,
215 (unsigned) pci_dev->id.vendor_id,
216 (unsigned) pci_dev->id.device_id);
217 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
218 rte_free(eth_dev->data->dev_private);
224 * Register an Ethernet [Poll Mode] driver.
226 * Function invoked by the initialization function of an Ethernet driver
227 * to simultaneously register itself as a PCI driver and as an Ethernet
229 * Invokes the rte_eal_pci_register() function to register the *pci_drv*
230 * structure embedded in the *eth_drv* structure, after having stored the
231 * address of the rte_eth_dev_init() function in the *devinit* field of
232 * the *pci_drv* structure.
233 * During the PCI probing phase, the rte_eth_dev_init() function is
234 * invoked for each PCI [Ethernet device] matching the embedded PCI
235 * identifiers provided by the driver.
238 rte_eth_driver_register(struct eth_driver *eth_drv)
240 eth_drv->pci_drv.devinit = rte_eth_dev_init;
241 rte_eal_pci_register(ð_drv->pci_drv);
245 rte_eth_dev_socket_id(uint8_t port_id)
247 if (port_id >= nb_ports)
249 return rte_eth_devices[port_id].pci_dev->numa_node;
253 rte_eth_dev_count(void)
259 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
261 uint16_t old_nb_queues = dev->data->nb_rx_queues;
265 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
267 if (dev->data->rx_queues == NULL) {
268 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
269 sizeof(dev->data->rx_queues[0]) * nb_queues,
271 if (dev->data->rx_queues == NULL) {
272 dev->data->nb_rx_queues = 0;
276 rxq = dev->data->rx_queues;
278 for (i = nb_queues; i < old_nb_queues; i++)
279 (*dev->dev_ops->rx_queue_release)(rxq[i]);
280 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
285 if (nb_queues > old_nb_queues)
286 memset(rxq + old_nb_queues, 0,
287 sizeof(rxq[0]) * (nb_queues - old_nb_queues));
289 dev->data->rx_queues = rxq;
292 dev->data->nb_rx_queues = nb_queues;
297 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
299 uint16_t old_nb_queues = dev->data->nb_tx_queues;
303 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
305 if (dev->data->tx_queues == NULL) {
306 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
307 sizeof(dev->data->tx_queues[0]) * nb_queues,
309 if (dev->data->tx_queues == NULL) {
310 dev->data->nb_tx_queues = 0;
314 txq = dev->data->tx_queues;
316 for (i = nb_queues; i < old_nb_queues; i++)
317 (*dev->dev_ops->tx_queue_release)(txq[i]);
318 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
323 if (nb_queues > old_nb_queues)
324 memset(txq + old_nb_queues, 0,
325 sizeof(txq[0]) * (nb_queues - old_nb_queues));
327 dev->data->tx_queues = txq;
330 dev->data->nb_tx_queues = nb_queues;
335 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
336 const struct rte_eth_conf *dev_conf)
338 struct rte_eth_dev *dev;
339 struct rte_eth_dev_info dev_info;
342 /* This function is only safe when called from the primary process
343 * in a multi-process setup*/
344 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
346 if (port_id >= nb_ports || port_id >= RTE_MAX_ETHPORTS) {
347 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
350 dev = &rte_eth_devices[port_id];
352 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
353 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
355 if (dev->data->dev_started) {
357 "port %d must be stopped to allow configuration\n", port_id);
362 * Check that the numbers of RX and TX queues are not greater
363 * than the maximum number of RX and TX queues supported by the
366 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
367 if (nb_rx_q > dev_info.max_rx_queues) {
368 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
369 port_id, nb_rx_q, dev_info.max_rx_queues);
373 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
377 if (nb_tx_q > dev_info.max_tx_queues) {
378 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
379 port_id, nb_tx_q, dev_info.max_tx_queues);
383 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
387 /* Copy the dev_conf parameter into the dev structure */
388 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
391 * If jumbo frames are enabled, check that the maximum RX packet
392 * length is supported by the configured device.
394 if (dev_conf->rxmode.jumbo_frame == 1) {
395 if (dev_conf->rxmode.max_rx_pkt_len >
396 dev_info.max_rx_pktlen) {
397 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
398 " > max valid value %u\n",
400 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
401 (unsigned)dev_info.max_rx_pktlen);
404 else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
405 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
406 " < min valid value %u\n",
408 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
409 (unsigned)ETHER_MIN_LEN);
413 /* Use default value */
414 dev->data->dev_conf.rxmode.max_rx_pkt_len = ETHER_MAX_LEN;
416 /* For vmdb+dcb mode check our configuration before we go further */
417 if (dev_conf->rxmode.mq_mode == ETH_VMDQ_DCB) {
418 const struct rte_eth_vmdq_dcb_conf *conf;
420 if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
421 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
423 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
426 conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
427 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
428 conf->nb_queue_pools == ETH_32_POOLS)) {
429 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
430 "nb_queue_pools must be %d or %d\n",
431 port_id, ETH_16_POOLS, ETH_32_POOLS);
435 if (dev_conf->txmode.mq_mode == ETH_VMDQ_DCB_TX) {
436 const struct rte_eth_vmdq_dcb_tx_conf *conf;
438 if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
439 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
441 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
444 conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
445 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
446 conf->nb_queue_pools == ETH_32_POOLS)) {
447 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
448 "nb_queue_pools != %d or nb_queue_pools "
450 port_id, ETH_16_POOLS, ETH_32_POOLS);
455 /* For DCB mode check our configuration before we go further */
456 if (dev_conf->rxmode.mq_mode == ETH_DCB_RX) {
457 const struct rte_eth_dcb_rx_conf *conf;
459 if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
460 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
462 port_id, ETH_DCB_NUM_QUEUES);
465 conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
466 if (! (conf->nb_tcs == ETH_4_TCS ||
467 conf->nb_tcs == ETH_8_TCS)) {
468 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
469 "nb_tcs != %d or nb_tcs "
471 port_id, ETH_4_TCS, ETH_8_TCS);
476 if (dev_conf->txmode.mq_mode == ETH_DCB_TX) {
477 const struct rte_eth_dcb_tx_conf *conf;
479 if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
480 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
482 port_id, ETH_DCB_NUM_QUEUES);
485 conf = &(dev_conf->tx_adv_conf.dcb_tx_conf);
486 if (! (conf->nb_tcs == ETH_4_TCS ||
487 conf->nb_tcs == ETH_8_TCS)) {
488 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
489 "nb_tcs != %d or nb_tcs "
491 port_id, ETH_4_TCS, ETH_8_TCS);
497 * Setup new number of RX/TX queues and reconfigure device.
499 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
501 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
506 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
508 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
510 rte_eth_dev_rx_queue_config(dev, 0);
514 diag = (*dev->dev_ops->dev_configure)(dev);
516 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
518 rte_eth_dev_rx_queue_config(dev, 0);
519 rte_eth_dev_tx_queue_config(dev, 0);
527 rte_eth_dev_config_restore(uint8_t port_id)
529 struct rte_eth_dev *dev;
530 struct rte_eth_dev_info dev_info;
531 struct ether_addr addr;
535 dev = &rte_eth_devices[port_id];
537 rte_eth_dev_info_get(port_id, &dev_info);
539 if (RTE_ETH_DEV_SRIOV(dev).active)
540 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
542 /* replay MAC address configuration */
543 for (i = 0; i < dev_info.max_mac_addrs; i++) {
544 addr = dev->data->mac_addrs[i];
546 /* skip zero address */
547 if (is_zero_ether_addr(&addr))
550 /* add address to the hardware */
551 if (*dev->dev_ops->mac_addr_add)
552 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
554 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
556 /* exit the loop but not return an error */
561 /* replay promiscuous configuration */
562 if (rte_eth_promiscuous_get(port_id) == 1)
563 rte_eth_promiscuous_enable(port_id);
564 else if (rte_eth_promiscuous_get(port_id) == 0)
565 rte_eth_promiscuous_disable(port_id);
567 /* replay allmulticast configuration */
568 if (rte_eth_allmulticast_get(port_id) == 1)
569 rte_eth_allmulticast_enable(port_id);
570 else if (rte_eth_allmulticast_get(port_id) == 0)
571 rte_eth_allmulticast_disable(port_id);
575 rte_eth_dev_start(uint8_t port_id)
577 struct rte_eth_dev *dev;
580 /* This function is only safe when called from the primary process
581 * in a multi-process setup*/
582 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
584 if (port_id >= nb_ports) {
585 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
588 dev = &rte_eth_devices[port_id];
590 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
591 diag = (*dev->dev_ops->dev_start)(dev);
593 dev->data->dev_started = 1;
597 rte_eth_dev_config_restore(port_id);
603 rte_eth_dev_stop(uint8_t port_id)
605 struct rte_eth_dev *dev;
607 /* This function is only safe when called from the primary process
608 * in a multi-process setup*/
609 PROC_PRIMARY_OR_RET();
611 if (port_id >= nb_ports) {
612 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
615 dev = &rte_eth_devices[port_id];
617 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
618 dev->data->dev_started = 0;
619 (*dev->dev_ops->dev_stop)(dev);
623 rte_eth_dev_close(uint8_t port_id)
625 struct rte_eth_dev *dev;
627 /* This function is only safe when called from the primary process
628 * in a multi-process setup*/
629 PROC_PRIMARY_OR_RET();
631 if (port_id >= nb_ports) {
632 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
636 dev = &rte_eth_devices[port_id];
638 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
639 dev->data->dev_started = 0;
640 (*dev->dev_ops->dev_close)(dev);
644 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
645 uint16_t nb_rx_desc, unsigned int socket_id,
646 const struct rte_eth_rxconf *rx_conf,
647 struct rte_mempool *mp)
649 struct rte_eth_dev *dev;
650 struct rte_pktmbuf_pool_private *mbp_priv;
651 struct rte_eth_dev_info dev_info;
653 /* This function is only safe when called from the primary process
654 * in a multi-process setup*/
655 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
657 if (port_id >= nb_ports) {
658 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
661 dev = &rte_eth_devices[port_id];
662 if (rx_queue_id >= dev->data->nb_rx_queues) {
663 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
667 if (dev->data->dev_started) {
669 "port %d must be stopped to allow configuration\n", port_id);
673 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
674 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
677 * Check the size of the mbuf data buffer.
678 * This value must be provided in the private data of the memory pool.
679 * First check that the memory pool has a valid private data.
681 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
682 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
683 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
684 mp->name, (int) mp->private_data_size,
685 (int) sizeof(struct rte_pktmbuf_pool_private));
688 mbp_priv = (struct rte_pktmbuf_pool_private *)
689 ((char *)mp + sizeof(struct rte_mempool));
690 if ((uint32_t) (mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM) <
691 dev_info.min_rx_bufsize) {
692 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
693 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
696 (int)mbp_priv->mbuf_data_room_size,
697 (int)(RTE_PKTMBUF_HEADROOM +
698 dev_info.min_rx_bufsize),
699 (int)RTE_PKTMBUF_HEADROOM,
700 (int)dev_info.min_rx_bufsize);
704 return (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
705 socket_id, rx_conf, mp);
709 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
710 uint16_t nb_tx_desc, unsigned int socket_id,
711 const struct rte_eth_txconf *tx_conf)
713 struct rte_eth_dev *dev;
715 /* This function is only safe when called from the primary process
716 * in a multi-process setup*/
717 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
719 if (port_id >= RTE_MAX_ETHPORTS || port_id >= nb_ports) {
720 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
723 dev = &rte_eth_devices[port_id];
724 if (tx_queue_id >= dev->data->nb_tx_queues) {
725 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
729 if (dev->data->dev_started) {
731 "port %d must be stopped to allow configuration\n", port_id);
735 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
736 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
741 rte_eth_promiscuous_enable(uint8_t port_id)
743 struct rte_eth_dev *dev;
745 if (port_id >= nb_ports) {
746 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
749 dev = &rte_eth_devices[port_id];
751 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
752 (*dev->dev_ops->promiscuous_enable)(dev);
753 dev->data->promiscuous = 1;
757 rte_eth_promiscuous_disable(uint8_t port_id)
759 struct rte_eth_dev *dev;
761 if (port_id >= nb_ports) {
762 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
765 dev = &rte_eth_devices[port_id];
767 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
768 dev->data->promiscuous = 0;
769 (*dev->dev_ops->promiscuous_disable)(dev);
773 rte_eth_promiscuous_get(uint8_t port_id)
775 struct rte_eth_dev *dev;
777 if (port_id >= nb_ports) {
778 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
782 dev = &rte_eth_devices[port_id];
783 return dev->data->promiscuous;
787 rte_eth_allmulticast_enable(uint8_t port_id)
789 struct rte_eth_dev *dev;
791 if (port_id >= nb_ports) {
792 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
795 dev = &rte_eth_devices[port_id];
797 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
798 (*dev->dev_ops->allmulticast_enable)(dev);
799 dev->data->all_multicast = 1;
803 rte_eth_allmulticast_disable(uint8_t port_id)
805 struct rte_eth_dev *dev;
807 if (port_id >= nb_ports) {
808 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
811 dev = &rte_eth_devices[port_id];
813 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
814 dev->data->all_multicast = 0;
815 (*dev->dev_ops->allmulticast_disable)(dev);
819 rte_eth_allmulticast_get(uint8_t port_id)
821 struct rte_eth_dev *dev;
823 if (port_id >= nb_ports) {
824 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
828 dev = &rte_eth_devices[port_id];
829 return dev->data->all_multicast;
833 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
834 struct rte_eth_link *link)
836 struct rte_eth_link *dst = link;
837 struct rte_eth_link *src = &(dev->data->dev_link);
839 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
840 *(uint64_t *)src) == 0)
847 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
849 struct rte_eth_dev *dev;
851 if (port_id >= nb_ports) {
852 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
855 dev = &rte_eth_devices[port_id];
856 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
858 if (dev->data->dev_conf.intr_conf.lsc != 0)
859 rte_eth_dev_atomic_read_link_status(dev, eth_link);
861 (*dev->dev_ops->link_update)(dev, 1);
862 *eth_link = dev->data->dev_link;
867 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
869 struct rte_eth_dev *dev;
871 if (port_id >= nb_ports) {
872 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
875 dev = &rte_eth_devices[port_id];
876 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
878 if (dev->data->dev_conf.intr_conf.lsc != 0)
879 rte_eth_dev_atomic_read_link_status(dev, eth_link);
881 (*dev->dev_ops->link_update)(dev, 0);
882 *eth_link = dev->data->dev_link;
887 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
889 struct rte_eth_dev *dev;
891 if (port_id >= nb_ports) {
892 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
895 dev = &rte_eth_devices[port_id];
897 FUNC_PTR_OR_RET(*dev->dev_ops->stats_get);
898 (*dev->dev_ops->stats_get)(dev, stats);
899 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
903 rte_eth_stats_reset(uint8_t port_id)
905 struct rte_eth_dev *dev;
907 if (port_id >= nb_ports) {
908 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
911 dev = &rte_eth_devices[port_id];
913 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
914 (*dev->dev_ops->stats_reset)(dev);
919 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
922 struct rte_eth_dev *dev;
924 if (port_id >= nb_ports) {
925 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
928 dev = &rte_eth_devices[port_id];
930 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
931 return (*dev->dev_ops->queue_stats_mapping_set)
932 (dev, queue_id, stat_idx, is_rx);
937 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
940 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
946 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
949 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
955 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
957 struct rte_eth_dev *dev;
959 if (port_id >= nb_ports) {
960 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
963 dev = &rte_eth_devices[port_id];
965 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
966 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
967 dev_info->pci_dev = dev->pci_dev;
968 dev_info->driver_name = dev->driver->pci_drv.name;
972 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
974 struct rte_eth_dev *dev;
976 if (port_id >= nb_ports) {
977 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
980 dev = &rte_eth_devices[port_id];
981 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
985 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
987 struct rte_eth_dev *dev;
989 if (port_id >= nb_ports) {
990 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
993 dev = &rte_eth_devices[port_id];
994 if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
995 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
999 if (vlan_id > 4095) {
1000 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1001 port_id, (unsigned) vlan_id);
1004 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1005 (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1010 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1012 struct rte_eth_dev *dev;
1014 if (port_id >= nb_ports) {
1015 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1019 dev = &rte_eth_devices[port_id];
1020 if (rx_queue_id >= dev->data->nb_rx_queues) {
1021 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1025 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1026 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1032 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1034 struct rte_eth_dev *dev;
1036 if (port_id >= nb_ports) {
1037 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1041 dev = &rte_eth_devices[port_id];
1042 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1043 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1049 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1051 struct rte_eth_dev *dev;
1056 if (port_id >= nb_ports) {
1057 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1061 dev = &rte_eth_devices[port_id];
1063 /*check which option changed by application*/
1064 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1065 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1067 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1068 mask |= ETH_VLAN_STRIP_MASK;
1071 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1072 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1074 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1075 mask |= ETH_VLAN_FILTER_MASK;
1078 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1079 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1081 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1082 mask |= ETH_VLAN_EXTEND_MASK;
1089 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1090 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1096 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1098 struct rte_eth_dev *dev;
1101 if (port_id >= nb_ports) {
1102 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1106 dev = &rte_eth_devices[port_id];
1108 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1109 ret |= ETH_VLAN_STRIP_OFFLOAD ;
1111 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1112 ret |= ETH_VLAN_FILTER_OFFLOAD ;
1114 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1115 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
1122 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1123 struct rte_fdir_filter *fdir_filter,
1126 struct rte_eth_dev *dev;
1128 if (port_id >= nb_ports) {
1129 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1133 dev = &rte_eth_devices[port_id];
1135 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1136 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1137 port_id, dev->data->dev_conf.fdir_conf.mode);
1141 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1142 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1143 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1144 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1145 "None l4type, source & destinations ports " \
1146 "should be null!\n");
1150 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1151 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1156 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1157 struct rte_fdir_filter *fdir_filter,
1160 struct rte_eth_dev *dev;
1162 if (port_id >= nb_ports) {
1163 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1167 dev = &rte_eth_devices[port_id];
1169 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1170 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1171 port_id, dev->data->dev_conf.fdir_conf.mode);
1175 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1176 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1177 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1178 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1179 "None l4type, source & destinations ports " \
1180 "should be null!\n");
1184 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
1185 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
1191 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
1192 struct rte_fdir_filter *fdir_filter)
1194 struct rte_eth_dev *dev;
1196 if (port_id >= nb_ports) {
1197 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1201 dev = &rte_eth_devices[port_id];
1203 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1204 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1205 port_id, dev->data->dev_conf.fdir_conf.mode);
1209 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1210 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1211 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1212 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1213 "None l4type source & destinations ports " \
1214 "should be null!\n");
1218 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
1219 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
1223 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
1225 struct rte_eth_dev *dev;
1227 if (port_id >= nb_ports) {
1228 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1232 dev = &rte_eth_devices[port_id];
1233 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1234 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1238 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
1240 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
1245 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
1246 struct rte_fdir_filter *fdir_filter,
1247 uint16_t soft_id, uint8_t queue,
1250 struct rte_eth_dev *dev;
1252 if (port_id >= nb_ports) {
1253 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1257 dev = &rte_eth_devices[port_id];
1259 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1260 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1261 port_id, dev->data->dev_conf.fdir_conf.mode);
1265 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1266 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1267 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1268 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1269 "None l4type, source & destinations ports " \
1270 "should be null!\n");
1274 /* For now IPv6 is not supported with perfect filter */
1275 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1278 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
1279 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
1285 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
1286 struct rte_fdir_filter *fdir_filter,
1287 uint16_t soft_id, uint8_t queue,
1290 struct rte_eth_dev *dev;
1292 if (port_id >= nb_ports) {
1293 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1297 dev = &rte_eth_devices[port_id];
1299 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1300 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1301 port_id, dev->data->dev_conf.fdir_conf.mode);
1305 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1306 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1307 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1308 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1309 "None l4type, source & destinations ports " \
1310 "should be null!\n");
1314 /* For now IPv6 is not supported with perfect filter */
1315 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1318 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
1319 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
1320 soft_id, queue, drop);
1324 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
1325 struct rte_fdir_filter *fdir_filter,
1328 struct rte_eth_dev *dev;
1330 if (port_id >= nb_ports) {
1331 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1335 dev = &rte_eth_devices[port_id];
1337 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1338 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1339 port_id, dev->data->dev_conf.fdir_conf.mode);
1343 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1344 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1345 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1346 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1347 "None l4type, source & destinations ports " \
1348 "should be null!\n");
1352 /* For now IPv6 is not supported with perfect filter */
1353 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1356 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
1357 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
1362 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
1364 struct rte_eth_dev *dev;
1366 if (port_id >= nb_ports) {
1367 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1371 dev = &rte_eth_devices[port_id];
1372 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1373 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1377 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
1378 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
1382 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1384 struct rte_eth_dev *dev;
1386 if (port_id >= nb_ports) {
1387 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1391 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1392 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1396 dev = &rte_eth_devices[port_id];
1397 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1398 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1402 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1404 struct rte_eth_dev *dev;
1406 if (port_id >= nb_ports) {
1407 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1411 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1412 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1416 dev = &rte_eth_devices[port_id];
1417 /* High water, low water validation are device specific */
1418 if (*dev->dev_ops->priority_flow_ctrl_set)
1419 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1424 rte_eth_dev_rss_reta_update(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
1426 struct rte_eth_dev *dev;
1429 if (port_id >= nb_ports) {
1430 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1434 /* Invalid mask bit(s) setting */
1435 if ((reta_conf->mask_lo == 0) && (reta_conf->mask_hi == 0)) {
1436 PMD_DEBUG_TRACE("Invalid update mask bits for port=%d\n",port_id);
1440 if (reta_conf->mask_lo != 0) {
1441 for (i = 0; i < ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
1442 if ((reta_conf->mask_lo & (1ULL << i)) &&
1443 (reta_conf->reta[i] >= ETH_RSS_RETA_MAX_QUEUE)) {
1444 PMD_DEBUG_TRACE("RETA hash index output"
1445 "configration for port=%d,invalid"
1446 "queue=%d\n",port_id,reta_conf->reta[i]);
1453 if (reta_conf->mask_hi != 0) {
1454 for (i = 0; i< ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
1455 j = (uint8_t)(i + ETH_RSS_RETA_NUM_ENTRIES/2);
1457 /* Check if the max entry >= 128 */
1458 if ((reta_conf->mask_hi & (1ULL << i)) &&
1459 (reta_conf->reta[j] >= ETH_RSS_RETA_MAX_QUEUE)) {
1460 PMD_DEBUG_TRACE("RETA hash index output"
1461 "configration for port=%d,invalid"
1462 "queue=%d\n",port_id,reta_conf->reta[j]);
1469 dev = &rte_eth_devices[port_id];
1471 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
1472 return (*dev->dev_ops->reta_update)(dev, reta_conf);
1476 rte_eth_dev_rss_reta_query(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
1478 struct rte_eth_dev *dev;
1480 if (port_id >= nb_ports) {
1481 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1485 if((reta_conf->mask_lo == 0) && (reta_conf->mask_hi == 0)) {
1486 PMD_DEBUG_TRACE("Invalid update mask bits for the port=%d\n",port_id);
1490 dev = &rte_eth_devices[port_id];
1491 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
1492 return (*dev->dev_ops->reta_query)(dev, reta_conf);
1496 rte_eth_led_on(uint8_t port_id)
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->dev_led_on, -ENOTSUP);
1507 return ((*dev->dev_ops->dev_led_on)(dev));
1511 rte_eth_led_off(uint8_t port_id)
1513 struct rte_eth_dev *dev;
1515 if (port_id >= nb_ports) {
1516 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1520 dev = &rte_eth_devices[port_id];
1521 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
1522 return ((*dev->dev_ops->dev_led_off)(dev));
1526 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
1530 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
1532 struct rte_eth_dev_info dev_info;
1533 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1536 rte_eth_dev_info_get(port_id, &dev_info);
1538 for (i = 0; i < dev_info.max_mac_addrs; i++)
1539 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
1545 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
1548 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
1551 struct rte_eth_dev *dev;
1554 if (port_id >= nb_ports) {
1555 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1558 dev = &rte_eth_devices[port_id];
1559 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
1561 if (is_zero_ether_addr(addr)) {
1562 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n", port_id);
1566 /* Check if it's already there, and do nothing */
1567 index = get_mac_addr_index(port_id, addr);
1571 index = get_mac_addr_index(port_id, &null_mac_addr);
1573 PMD_DEBUG_TRACE("port %d: MAC address array full\n", port_id);
1578 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
1580 /* Update address in NIC data structure */
1581 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
1587 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
1589 struct rte_eth_dev *dev;
1592 if (port_id >= nb_ports) {
1593 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1596 dev = &rte_eth_devices[port_id];
1597 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
1599 index = get_mac_addr_index(port_id, addr);
1601 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
1602 return (-EADDRINUSE);
1603 } else if (index < 0)
1604 return 0; /* Do nothing if address wasn't found */
1607 (*dev->dev_ops->mac_addr_remove)(dev, index);
1609 /* Update address in NIC data structure */
1610 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
1615 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
1617 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
1618 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
1620 struct rte_eth_dev *dev;
1622 if (port_id >= nb_ports) {
1623 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1626 dev = &rte_eth_devices[port_id];
1627 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, -ENOTSUP);
1628 if (queue_id >= dev->data->nb_rx_queues) {
1629 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
1632 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
1637 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
1638 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1640 struct rte_eth_dev *dev;
1642 if (port_id >= nb_ports) {
1643 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1646 dev = &rte_eth_devices[port_id];
1648 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, -ENOTSUP);
1649 if (queue_id >= dev->data->nb_tx_queues) {
1650 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
1653 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
1658 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
1660 struct rte_eth_dev *dev;
1662 if (port_id >= nb_ports) {
1663 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1666 dev = &rte_eth_devices[port_id];
1667 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, -ENOTSUP);
1668 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
1673 rte_eth_dev_callback_register(uint8_t port_id,
1674 enum rte_eth_event_type event,
1675 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
1677 struct rte_eth_dev *dev;
1678 struct rte_eth_dev_callback *user_cb;
1682 if (port_id >= nb_ports) {
1683 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1687 dev = &rte_eth_devices[port_id];
1688 rte_spinlock_lock(&rte_eth_dev_cb_lock);
1690 TAILQ_FOREACH(user_cb, &(dev->callbacks), next) {
1691 if (user_cb->cb_fn == cb_fn &&
1692 user_cb->cb_arg == cb_arg &&
1693 user_cb->event == event) {
1698 /* create a new callback. */
1699 if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
1700 sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
1701 user_cb->cb_fn = cb_fn;
1702 user_cb->cb_arg = cb_arg;
1703 user_cb->event = event;
1704 TAILQ_INSERT_TAIL(&(dev->callbacks), user_cb, next);
1707 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
1708 return ((user_cb == NULL) ? -ENOMEM : 0);
1712 rte_eth_dev_callback_unregister(uint8_t port_id,
1713 enum rte_eth_event_type event,
1714 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
1717 struct rte_eth_dev *dev;
1718 struct rte_eth_dev_callback *cb, *next;
1722 if (port_id >= nb_ports) {
1723 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1727 dev = &rte_eth_devices[port_id];
1728 rte_spinlock_lock(&rte_eth_dev_cb_lock);
1731 for (cb = TAILQ_FIRST(&dev->callbacks); cb != NULL; cb = next) {
1733 next = TAILQ_NEXT(cb, next);
1735 if (cb->cb_fn != cb_fn || cb->event != event ||
1736 (cb->cb_arg != (void *)-1 &&
1737 cb->cb_arg != cb_arg))
1741 * if this callback is not executing right now,
1744 if (cb->active == 0) {
1745 TAILQ_REMOVE(&(dev->callbacks), cb, next);
1752 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
1757 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
1758 enum rte_eth_event_type event)
1760 struct rte_eth_dev_callback *cb_lst;
1761 struct rte_eth_dev_callback dev_cb;
1763 rte_spinlock_lock(&rte_eth_dev_cb_lock);
1764 TAILQ_FOREACH(cb_lst, &(dev->callbacks), next) {
1765 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
1769 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
1770 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
1772 rte_spinlock_lock(&rte_eth_dev_cb_lock);
1775 rte_spinlock_unlock(&rte_eth_dev_cb_lock);