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;
534 dev = &rte_eth_devices[port_id];
536 rte_eth_dev_info_get(port_id, &dev_info);
538 /* replay MAC address configuration */
539 for (i = 0; i < dev_info.max_mac_addrs; i++) {
540 addr = dev->data->mac_addrs[i];
542 /* skip zero address */
543 if (is_zero_ether_addr(&addr))
546 /* add address to the hardware */
547 if (*dev->dev_ops->mac_addr_add)
548 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, 0);
550 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
552 /* exit the loop but not return an error */
557 /* replay promiscuous configuration */
558 if (rte_eth_promiscuous_get(port_id) == 1)
559 rte_eth_promiscuous_enable(port_id);
560 else if (rte_eth_promiscuous_get(port_id) == 0)
561 rte_eth_promiscuous_disable(port_id);
563 /* replay allmulticast configuration */
564 if (rte_eth_allmulticast_get(port_id) == 1)
565 rte_eth_allmulticast_enable(port_id);
566 else if (rte_eth_allmulticast_get(port_id) == 0)
567 rte_eth_allmulticast_disable(port_id);
571 rte_eth_dev_start(uint8_t port_id)
573 struct rte_eth_dev *dev;
576 /* This function is only safe when called from the primary process
577 * in a multi-process setup*/
578 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
580 if (port_id >= nb_ports) {
581 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
584 dev = &rte_eth_devices[port_id];
586 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
587 diag = (*dev->dev_ops->dev_start)(dev);
589 dev->data->dev_started = 1;
593 rte_eth_dev_config_restore(port_id);
599 rte_eth_dev_stop(uint8_t port_id)
601 struct rte_eth_dev *dev;
603 /* This function is only safe when called from the primary process
604 * in a multi-process setup*/
605 PROC_PRIMARY_OR_RET();
607 if (port_id >= nb_ports) {
608 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
611 dev = &rte_eth_devices[port_id];
613 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
614 dev->data->dev_started = 0;
615 (*dev->dev_ops->dev_stop)(dev);
619 rte_eth_dev_close(uint8_t port_id)
621 struct rte_eth_dev *dev;
623 /* This function is only safe when called from the primary process
624 * in a multi-process setup*/
625 PROC_PRIMARY_OR_RET();
627 if (port_id >= nb_ports) {
628 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
632 dev = &rte_eth_devices[port_id];
634 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
635 dev->data->dev_started = 0;
636 (*dev->dev_ops->dev_close)(dev);
640 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
641 uint16_t nb_rx_desc, unsigned int socket_id,
642 const struct rte_eth_rxconf *rx_conf,
643 struct rte_mempool *mp)
645 struct rte_eth_dev *dev;
646 struct rte_pktmbuf_pool_private *mbp_priv;
647 struct rte_eth_dev_info dev_info;
649 /* This function is only safe when called from the primary process
650 * in a multi-process setup*/
651 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
653 if (port_id >= nb_ports) {
654 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
657 dev = &rte_eth_devices[port_id];
658 if (rx_queue_id >= dev->data->nb_rx_queues) {
659 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
663 if (dev->data->dev_started) {
665 "port %d must be stopped to allow configuration\n", port_id);
669 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
670 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
673 * Check the size of the mbuf data buffer.
674 * This value must be provided in the private data of the memory pool.
675 * First check that the memory pool has a valid private data.
677 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
678 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
679 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
680 mp->name, (int) mp->private_data_size,
681 (int) sizeof(struct rte_pktmbuf_pool_private));
684 mbp_priv = (struct rte_pktmbuf_pool_private *)
685 ((char *)mp + sizeof(struct rte_mempool));
686 if ((uint32_t) (mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM) <
687 dev_info.min_rx_bufsize) {
688 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
689 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
692 (int)mbp_priv->mbuf_data_room_size,
693 (int)(RTE_PKTMBUF_HEADROOM +
694 dev_info.min_rx_bufsize),
695 (int)RTE_PKTMBUF_HEADROOM,
696 (int)dev_info.min_rx_bufsize);
700 return (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
701 socket_id, rx_conf, mp);
705 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
706 uint16_t nb_tx_desc, unsigned int socket_id,
707 const struct rte_eth_txconf *tx_conf)
709 struct rte_eth_dev *dev;
711 /* This function is only safe when called from the primary process
712 * in a multi-process setup*/
713 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
715 if (port_id >= RTE_MAX_ETHPORTS || port_id >= nb_ports) {
716 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
719 dev = &rte_eth_devices[port_id];
720 if (tx_queue_id >= dev->data->nb_tx_queues) {
721 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
725 if (dev->data->dev_started) {
727 "port %d must be stopped to allow configuration\n", port_id);
731 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
732 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
737 rte_eth_promiscuous_enable(uint8_t port_id)
739 struct rte_eth_dev *dev;
741 if (port_id >= nb_ports) {
742 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
745 dev = &rte_eth_devices[port_id];
747 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
748 (*dev->dev_ops->promiscuous_enable)(dev);
749 dev->data->promiscuous = 1;
753 rte_eth_promiscuous_disable(uint8_t port_id)
755 struct rte_eth_dev *dev;
757 if (port_id >= nb_ports) {
758 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
761 dev = &rte_eth_devices[port_id];
763 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
764 dev->data->promiscuous = 0;
765 (*dev->dev_ops->promiscuous_disable)(dev);
769 rte_eth_promiscuous_get(uint8_t port_id)
771 struct rte_eth_dev *dev;
773 if (port_id >= nb_ports) {
774 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
778 dev = &rte_eth_devices[port_id];
779 return dev->data->promiscuous;
783 rte_eth_allmulticast_enable(uint8_t port_id)
785 struct rte_eth_dev *dev;
787 if (port_id >= nb_ports) {
788 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
791 dev = &rte_eth_devices[port_id];
793 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
794 (*dev->dev_ops->allmulticast_enable)(dev);
795 dev->data->all_multicast = 1;
799 rte_eth_allmulticast_disable(uint8_t port_id)
801 struct rte_eth_dev *dev;
803 if (port_id >= nb_ports) {
804 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
807 dev = &rte_eth_devices[port_id];
809 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
810 dev->data->all_multicast = 0;
811 (*dev->dev_ops->allmulticast_disable)(dev);
815 rte_eth_allmulticast_get(uint8_t port_id)
817 struct rte_eth_dev *dev;
819 if (port_id >= nb_ports) {
820 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
824 dev = &rte_eth_devices[port_id];
825 return dev->data->all_multicast;
829 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
830 struct rte_eth_link *link)
832 struct rte_eth_link *dst = link;
833 struct rte_eth_link *src = &(dev->data->dev_link);
835 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
836 *(uint64_t *)src) == 0)
843 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
845 struct rte_eth_dev *dev;
847 if (port_id >= nb_ports) {
848 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
851 dev = &rte_eth_devices[port_id];
852 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
854 if (dev->data->dev_conf.intr_conf.lsc != 0)
855 rte_eth_dev_atomic_read_link_status(dev, eth_link);
857 (*dev->dev_ops->link_update)(dev, 1);
858 *eth_link = dev->data->dev_link;
863 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
865 struct rte_eth_dev *dev;
867 if (port_id >= nb_ports) {
868 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
871 dev = &rte_eth_devices[port_id];
872 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
874 if (dev->data->dev_conf.intr_conf.lsc != 0)
875 rte_eth_dev_atomic_read_link_status(dev, eth_link);
877 (*dev->dev_ops->link_update)(dev, 0);
878 *eth_link = dev->data->dev_link;
883 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
885 struct rte_eth_dev *dev;
887 if (port_id >= nb_ports) {
888 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
891 dev = &rte_eth_devices[port_id];
893 FUNC_PTR_OR_RET(*dev->dev_ops->stats_get);
894 (*dev->dev_ops->stats_get)(dev, stats);
895 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
899 rte_eth_stats_reset(uint8_t port_id)
901 struct rte_eth_dev *dev;
903 if (port_id >= nb_ports) {
904 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
907 dev = &rte_eth_devices[port_id];
909 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
910 (*dev->dev_ops->stats_reset)(dev);
915 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
918 struct rte_eth_dev *dev;
920 if (port_id >= nb_ports) {
921 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
924 dev = &rte_eth_devices[port_id];
926 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
927 return (*dev->dev_ops->queue_stats_mapping_set)
928 (dev, queue_id, stat_idx, is_rx);
933 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
936 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
942 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
945 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
951 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
953 struct rte_eth_dev *dev;
955 if (port_id >= nb_ports) {
956 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
959 dev = &rte_eth_devices[port_id];
961 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
962 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
963 dev_info->pci_dev = dev->pci_dev;
964 dev_info->driver_name = dev->driver->pci_drv.name;
968 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
970 struct rte_eth_dev *dev;
972 if (port_id >= nb_ports) {
973 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
976 dev = &rte_eth_devices[port_id];
977 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
981 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
983 struct rte_eth_dev *dev;
985 if (port_id >= nb_ports) {
986 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
989 dev = &rte_eth_devices[port_id];
990 if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
991 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
995 if (vlan_id > 4095) {
996 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
997 port_id, (unsigned) vlan_id);
1000 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1001 (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1006 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1008 struct rte_eth_dev *dev;
1010 if (port_id >= nb_ports) {
1011 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1015 dev = &rte_eth_devices[port_id];
1016 if (rx_queue_id >= dev->data->nb_rx_queues) {
1017 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1021 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1022 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1028 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1030 struct rte_eth_dev *dev;
1032 if (port_id >= nb_ports) {
1033 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1037 dev = &rte_eth_devices[port_id];
1038 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1039 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1045 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1047 struct rte_eth_dev *dev;
1052 if (port_id >= nb_ports) {
1053 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1057 dev = &rte_eth_devices[port_id];
1059 /*check which option changed by application*/
1060 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1061 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1063 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1064 mask |= ETH_VLAN_STRIP_MASK;
1067 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1068 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1070 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1071 mask |= ETH_VLAN_FILTER_MASK;
1074 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1075 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1077 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1078 mask |= ETH_VLAN_EXTEND_MASK;
1085 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1086 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1092 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1094 struct rte_eth_dev *dev;
1097 if (port_id >= nb_ports) {
1098 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1102 dev = &rte_eth_devices[port_id];
1104 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1105 ret |= ETH_VLAN_STRIP_OFFLOAD ;
1107 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1108 ret |= ETH_VLAN_FILTER_OFFLOAD ;
1110 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1111 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
1118 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1119 struct rte_fdir_filter *fdir_filter,
1122 struct rte_eth_dev *dev;
1124 if (port_id >= nb_ports) {
1125 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1129 dev = &rte_eth_devices[port_id];
1131 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1132 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1133 port_id, dev->data->dev_conf.fdir_conf.mode);
1137 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1138 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1139 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1140 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1141 "None l4type, source & destinations ports " \
1142 "should be null!\n");
1146 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1147 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1152 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1153 struct rte_fdir_filter *fdir_filter,
1156 struct rte_eth_dev *dev;
1158 if (port_id >= nb_ports) {
1159 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1163 dev = &rte_eth_devices[port_id];
1165 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1166 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1167 port_id, dev->data->dev_conf.fdir_conf.mode);
1171 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1172 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1173 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1174 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1175 "None l4type, source & destinations ports " \
1176 "should be null!\n");
1180 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
1181 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
1187 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
1188 struct rte_fdir_filter *fdir_filter)
1190 struct rte_eth_dev *dev;
1192 if (port_id >= nb_ports) {
1193 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1197 dev = &rte_eth_devices[port_id];
1199 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1200 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1201 port_id, dev->data->dev_conf.fdir_conf.mode);
1205 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1206 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1207 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1208 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1209 "None l4type source & destinations ports " \
1210 "should be null!\n");
1214 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
1215 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
1219 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
1221 struct rte_eth_dev *dev;
1223 if (port_id >= nb_ports) {
1224 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1228 dev = &rte_eth_devices[port_id];
1229 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1230 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1234 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
1236 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
1241 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
1242 struct rte_fdir_filter *fdir_filter,
1243 uint16_t soft_id, uint8_t queue,
1246 struct rte_eth_dev *dev;
1248 if (port_id >= nb_ports) {
1249 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1253 dev = &rte_eth_devices[port_id];
1255 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1256 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1257 port_id, dev->data->dev_conf.fdir_conf.mode);
1261 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1262 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1263 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1264 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1265 "None l4type, source & destinations ports " \
1266 "should be null!\n");
1270 /* For now IPv6 is not supported with perfect filter */
1271 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1274 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
1275 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
1281 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
1282 struct rte_fdir_filter *fdir_filter,
1283 uint16_t soft_id, uint8_t queue,
1286 struct rte_eth_dev *dev;
1288 if (port_id >= nb_ports) {
1289 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1293 dev = &rte_eth_devices[port_id];
1295 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1296 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1297 port_id, dev->data->dev_conf.fdir_conf.mode);
1301 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1302 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1303 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1304 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1305 "None l4type, source & destinations ports " \
1306 "should be null!\n");
1310 /* For now IPv6 is not supported with perfect filter */
1311 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1314 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
1315 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
1316 soft_id, queue, drop);
1320 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
1321 struct rte_fdir_filter *fdir_filter,
1324 struct rte_eth_dev *dev;
1326 if (port_id >= nb_ports) {
1327 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1331 dev = &rte_eth_devices[port_id];
1333 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1334 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1335 port_id, dev->data->dev_conf.fdir_conf.mode);
1339 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1340 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1341 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1342 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1343 "None l4type, source & destinations ports " \
1344 "should be null!\n");
1348 /* For now IPv6 is not supported with perfect filter */
1349 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1352 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
1353 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
1358 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
1360 struct rte_eth_dev *dev;
1362 if (port_id >= nb_ports) {
1363 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1367 dev = &rte_eth_devices[port_id];
1368 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1369 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1373 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
1374 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
1378 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1380 struct rte_eth_dev *dev;
1382 if (port_id >= nb_ports) {
1383 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1387 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1388 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1392 dev = &rte_eth_devices[port_id];
1393 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1394 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1398 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1400 struct rte_eth_dev *dev;
1402 if (port_id >= nb_ports) {
1403 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1407 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1408 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1412 dev = &rte_eth_devices[port_id];
1413 /* High water, low water validation are device specific */
1414 if (*dev->dev_ops->priority_flow_ctrl_set)
1415 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1420 rte_eth_led_on(uint8_t port_id)
1422 struct rte_eth_dev *dev;
1424 if (port_id >= nb_ports) {
1425 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1429 dev = &rte_eth_devices[port_id];
1430 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
1431 return ((*dev->dev_ops->dev_led_on)(dev));
1435 rte_eth_led_off(uint8_t port_id)
1437 struct rte_eth_dev *dev;
1439 if (port_id >= nb_ports) {
1440 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1444 dev = &rte_eth_devices[port_id];
1445 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
1446 return ((*dev->dev_ops->dev_led_off)(dev));
1450 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
1454 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
1456 struct rte_eth_dev_info dev_info;
1457 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1460 rte_eth_dev_info_get(port_id, &dev_info);
1462 for (i = 0; i < dev_info.max_mac_addrs; i++)
1463 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
1469 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
1472 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
1475 struct rte_eth_dev *dev;
1478 if (port_id >= nb_ports) {
1479 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1482 dev = &rte_eth_devices[port_id];
1483 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
1485 if (is_zero_ether_addr(addr)) {
1486 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n", port_id);
1490 /* Check if it's already there, and do nothing */
1491 index = get_mac_addr_index(port_id, addr);
1495 index = get_mac_addr_index(port_id, &null_mac_addr);
1497 PMD_DEBUG_TRACE("port %d: MAC address array full\n", port_id);
1502 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
1504 /* Update address in NIC data structure */
1505 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
1511 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
1513 struct rte_eth_dev *dev;
1516 if (port_id >= nb_ports) {
1517 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->mac_addr_remove, -ENOTSUP);
1523 index = get_mac_addr_index(port_id, addr);
1525 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
1526 return (-EADDRINUSE);
1527 } else if (index < 0)
1528 return 0; /* Do nothing if address wasn't found */
1531 (*dev->dev_ops->mac_addr_remove)(dev, index);
1533 /* Update address in NIC data structure */
1534 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
1539 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
1541 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
1542 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
1544 struct rte_eth_dev *dev;
1546 if (port_id >= nb_ports) {
1547 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1550 dev = &rte_eth_devices[port_id];
1551 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, -ENOTSUP);
1552 if (queue_id >= dev->data->nb_rx_queues) {
1553 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
1556 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
1561 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
1562 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1564 struct rte_eth_dev *dev;
1566 if (port_id >= nb_ports) {
1567 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1570 dev = &rte_eth_devices[port_id];
1572 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, -ENOTSUP);
1573 if (queue_id >= dev->data->nb_tx_queues) {
1574 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
1577 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
1583 rte_eth_dev_callback_register(uint8_t port_id,
1584 enum rte_eth_event_type event,
1585 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
1587 struct rte_eth_dev *dev;
1588 struct rte_eth_dev_callback *user_cb;
1592 if (port_id >= nb_ports) {
1593 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1597 dev = &rte_eth_devices[port_id];
1598 rte_spinlock_lock(&rte_eth_dev_cb_lock);
1600 TAILQ_FOREACH(user_cb, &(dev->callbacks), next) {
1601 if (user_cb->cb_fn == cb_fn &&
1602 user_cb->cb_arg == cb_arg &&
1603 user_cb->event == event) {
1608 /* create a new callback. */
1609 if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
1610 sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
1611 user_cb->cb_fn = cb_fn;
1612 user_cb->cb_arg = cb_arg;
1613 user_cb->event = event;
1614 TAILQ_INSERT_TAIL(&(dev->callbacks), user_cb, next);
1617 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
1618 return ((user_cb == NULL) ? -ENOMEM : 0);
1622 rte_eth_dev_callback_unregister(uint8_t port_id,
1623 enum rte_eth_event_type event,
1624 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
1627 struct rte_eth_dev *dev;
1628 struct rte_eth_dev_callback *cb, *next;
1632 if (port_id >= nb_ports) {
1633 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1637 dev = &rte_eth_devices[port_id];
1638 rte_spinlock_lock(&rte_eth_dev_cb_lock);
1641 for (cb = TAILQ_FIRST(&dev->callbacks); cb != NULL; cb = next) {
1643 next = TAILQ_NEXT(cb, next);
1645 if (cb->cb_fn != cb_fn || cb->event != event ||
1646 (cb->cb_arg != (void *)-1 &&
1647 cb->cb_arg != cb_arg))
1651 * if this callback is not executing right now,
1654 if (cb->active == 0) {
1655 TAILQ_REMOVE(&(dev->callbacks), cb, next);
1662 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
1667 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
1668 enum rte_eth_event_type event)
1670 struct rte_eth_dev_callback *cb_lst;
1671 struct rte_eth_dev_callback dev_cb;
1673 rte_spinlock_lock(&rte_eth_dev_cb_lock);
1674 TAILQ_FOREACH(cb_lst, &(dev->callbacks), next) {
1675 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
1679 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
1680 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
1682 rte_spinlock_lock(&rte_eth_dev_cb_lock);
1685 rte_spinlock_unlock(&rte_eth_dev_cb_lock);