4 * Copyright(c) 2010-2012 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 */
135 rte_eth_dev_data_alloc(void)
137 const unsigned flags = 0;
138 const struct rte_memzone *mz;
140 if (rte_eal_process_type() == RTE_PROC_PRIMARY){
141 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
142 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
143 rte_socket_id(), flags);
145 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
147 rte_panic("Cannot allocate memzone for ethernet port data\n");
149 rte_eth_dev_data = mz->addr;
150 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
151 memset(rte_eth_dev_data, 0,
152 RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
155 static inline struct rte_eth_dev *
156 rte_eth_dev_allocate(void)
158 struct rte_eth_dev *eth_dev;
160 if (nb_ports == RTE_MAX_ETHPORTS) {
161 PMD_DEBUG_TRACE("Reached maximum number of ethernet ports\n");
165 if (rte_eth_dev_data == NULL)
166 rte_eth_dev_data_alloc();
168 eth_dev = &rte_eth_devices[nb_ports];
169 eth_dev->data = &rte_eth_dev_data[nb_ports];
170 eth_dev->data->port_id = nb_ports++;
175 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
176 struct rte_pci_device *pci_dev)
178 struct eth_driver *eth_drv;
179 struct rte_eth_dev *eth_dev;
182 eth_drv = (struct eth_driver *)pci_drv;
184 eth_dev = rte_eth_dev_allocate();
188 if (rte_eal_process_type() == RTE_PROC_PRIMARY){
189 eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
190 eth_drv->dev_private_size,
192 if (eth_dev->data->dev_private == NULL)
193 rte_panic("Cannot allocate memzone for private port data\n");
195 eth_dev->pci_dev = pci_dev;
196 eth_dev->driver = eth_drv;
197 eth_dev->data->rx_mbuf_alloc_failed = 0;
199 /* init user callbacks */
200 TAILQ_INIT(&(eth_dev->callbacks));
203 * Set the default maximum frame size.
205 eth_dev->data->max_frame_size = ETHER_MAX_LEN;
207 /* Invoke PMD device initialization function */
208 diag = (*eth_drv->eth_dev_init)(eth_drv, eth_dev);
212 PMD_DEBUG_TRACE("driver %s: eth_dev_init(vendor_id=0x%u device_id=0x%x)"
213 " failed\n", pci_drv->name,
214 (unsigned) pci_dev->id.vendor_id,
215 (unsigned) pci_dev->id.device_id);
216 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
217 rte_free(eth_dev->data->dev_private);
223 * Register an Ethernet [Poll Mode] driver.
225 * Function invoked by the initialization function of an Ethernet driver
226 * to simultaneously register itself as a PCI driver and as an Ethernet
228 * Invokes the rte_eal_pci_register() function to register the *pci_drv*
229 * structure embedded in the *eth_drv* structure, after having stored the
230 * address of the rte_eth_dev_init() function in the *devinit* field of
231 * the *pci_drv* structure.
232 * During the PCI probing phase, the rte_eth_dev_init() function is
233 * invoked for each PCI [Ethernet device] matching the embedded PCI
234 * identifiers provided by the driver.
237 rte_eth_driver_register(struct eth_driver *eth_drv)
239 eth_drv->pci_drv.devinit = rte_eth_dev_init;
240 rte_eal_pci_register(ð_drv->pci_drv);
244 rte_eth_dev_count(void)
250 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
252 uint16_t old_nb_queues = dev->data->nb_rx_queues;
256 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
258 if (dev->data->rx_queues == NULL) {
259 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
260 sizeof(dev->data->rx_queues[0]) * nb_queues,
262 if (dev->data->rx_queues == NULL) {
263 dev->data->nb_rx_queues = 0;
267 rxq = dev->data->rx_queues;
269 for (i = nb_queues; i < old_nb_queues; i++)
270 (*dev->dev_ops->rx_queue_release)(rxq[i]);
271 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
276 if (nb_queues > old_nb_queues)
277 memset(rxq + old_nb_queues, 0,
278 sizeof(rxq[0]) * (nb_queues - old_nb_queues));
280 dev->data->rx_queues = rxq;
283 dev->data->nb_rx_queues = nb_queues;
288 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
290 uint16_t old_nb_queues = dev->data->nb_tx_queues;
294 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
296 if (dev->data->tx_queues == NULL) {
297 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
298 sizeof(dev->data->tx_queues[0]) * nb_queues,
300 if (dev->data->tx_queues == NULL) {
301 dev->data->nb_tx_queues = 0;
305 txq = dev->data->tx_queues;
307 for (i = nb_queues; i < old_nb_queues; i++)
308 (*dev->dev_ops->tx_queue_release)(txq[i]);
309 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
314 if (nb_queues > old_nb_queues)
315 memset(txq + old_nb_queues, 0,
316 sizeof(txq[0]) * (nb_queues - old_nb_queues));
318 dev->data->tx_queues = txq;
321 dev->data->nb_tx_queues = nb_queues;
326 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
327 const struct rte_eth_conf *dev_conf)
329 struct rte_eth_dev *dev;
330 struct rte_eth_dev_info dev_info;
333 /* This function is only safe when called from the primary process
334 * in a multi-process setup*/
335 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
337 if (port_id >= nb_ports || port_id >= RTE_MAX_ETHPORTS) {
338 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
341 dev = &rte_eth_devices[port_id];
343 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
344 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
346 if (dev->data->dev_started) {
348 "port %d must be stopped to allow configuration\n", port_id);
353 * Check that the numbers of RX and TX queues are not greater
354 * than the maximum number of RX and TX queues supported by the
357 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
358 if (nb_rx_q > dev_info.max_rx_queues) {
359 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
360 port_id, nb_rx_q, dev_info.max_rx_queues);
364 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
368 if (nb_tx_q > dev_info.max_tx_queues) {
369 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
370 port_id, nb_tx_q, dev_info.max_tx_queues);
374 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
378 /* Copy the dev_conf parameter into the dev structure */
379 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
382 * If jumbo frames are enabled, check that the maximum RX packet
383 * length is supported by the configured device.
385 if (dev_conf->rxmode.jumbo_frame == 1) {
386 if (dev_conf->rxmode.max_rx_pkt_len >
387 dev_info.max_rx_pktlen) {
388 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
389 " > max valid value %u\n",
391 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
392 (unsigned)dev_info.max_rx_pktlen);
395 else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
396 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
397 " < min valid value %u\n",
399 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
400 (unsigned)ETHER_MIN_LEN);
404 /* Use default value */
405 dev->data->dev_conf.rxmode.max_rx_pkt_len = ETHER_MAX_LEN;
407 /* For vmdb+dcb mode check our configuration before we go further */
408 if (dev_conf->rxmode.mq_mode == ETH_VMDQ_DCB) {
409 const struct rte_eth_vmdq_dcb_conf *conf;
411 if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
412 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
414 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
417 conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
418 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
419 conf->nb_queue_pools == ETH_32_POOLS)) {
420 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
421 "nb_queue_pools must be %d or %d\n",
422 port_id, ETH_16_POOLS, ETH_32_POOLS);
426 if (dev_conf->txmode.mq_mode == ETH_VMDQ_DCB_TX) {
427 const struct rte_eth_vmdq_dcb_tx_conf *conf;
429 if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
430 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
432 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
435 conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
436 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
437 conf->nb_queue_pools == ETH_32_POOLS)) {
438 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
439 "nb_queue_pools != %d or nb_queue_pools "
441 port_id, ETH_16_POOLS, ETH_32_POOLS);
446 /* For DCB mode check our configuration before we go further */
447 if (dev_conf->rxmode.mq_mode == ETH_DCB_RX) {
448 const struct rte_eth_dcb_rx_conf *conf;
450 if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
451 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
453 port_id, ETH_DCB_NUM_QUEUES);
456 conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
457 if (! (conf->nb_tcs == ETH_4_TCS ||
458 conf->nb_tcs == ETH_8_TCS)) {
459 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
460 "nb_tcs != %d or nb_tcs "
462 port_id, ETH_4_TCS, ETH_8_TCS);
467 if (dev_conf->txmode.mq_mode == ETH_DCB_TX) {
468 const struct rte_eth_dcb_tx_conf *conf;
470 if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
471 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
473 port_id, ETH_DCB_NUM_QUEUES);
476 conf = &(dev_conf->tx_adv_conf.dcb_tx_conf);
477 if (! (conf->nb_tcs == ETH_4_TCS ||
478 conf->nb_tcs == ETH_8_TCS)) {
479 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
480 "nb_tcs != %d or nb_tcs "
482 port_id, ETH_4_TCS, ETH_8_TCS);
488 * Setup new number of RX/TX queues and reconfigure device.
490 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
492 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
497 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
499 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
501 rte_eth_dev_rx_queue_config(dev, 0);
505 diag = (*dev->dev_ops->dev_configure)(dev);
507 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
509 rte_eth_dev_rx_queue_config(dev, 0);
510 rte_eth_dev_tx_queue_config(dev, 0);
518 rte_eth_dev_config_restore(uint8_t port_id)
520 struct rte_eth_dev *dev;
521 struct rte_eth_dev_info dev_info;
522 struct ether_addr addr;
525 dev = &rte_eth_devices[port_id];
527 rte_eth_dev_info_get(port_id, &dev_info);
529 /* replay MAC address configuration */
530 for (i = 0; i < dev_info.max_mac_addrs; i++) {
531 addr = dev->data->mac_addrs[i];
533 /* skip zero address */
534 if (is_zero_ether_addr(&addr))
537 /* add address to the hardware */
538 if (*dev->dev_ops->mac_addr_add)
539 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, 0);
541 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
543 /* exit the loop but not return an error */
548 /* replay promiscuous configuration */
549 if (rte_eth_promiscuous_get(port_id) == 1)
550 rte_eth_promiscuous_enable(port_id);
551 else if (rte_eth_promiscuous_get(port_id) == 0)
552 rte_eth_promiscuous_disable(port_id);
554 /* replay allmulticast configuration */
555 if (rte_eth_allmulticast_get(port_id) == 1)
556 rte_eth_allmulticast_enable(port_id);
557 else if (rte_eth_allmulticast_get(port_id) == 0)
558 rte_eth_allmulticast_disable(port_id);
562 rte_eth_dev_start(uint8_t port_id)
564 struct rte_eth_dev *dev;
567 /* This function is only safe when called from the primary process
568 * in a multi-process setup*/
569 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
571 if (port_id >= nb_ports) {
572 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
575 dev = &rte_eth_devices[port_id];
577 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
578 diag = (*dev->dev_ops->dev_start)(dev);
580 dev->data->dev_started = 1;
584 rte_eth_dev_config_restore(port_id);
590 rte_eth_dev_stop(uint8_t port_id)
592 struct rte_eth_dev *dev;
594 /* This function is only safe when called from the primary process
595 * in a multi-process setup*/
596 PROC_PRIMARY_OR_RET();
598 if (port_id >= nb_ports) {
599 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
602 dev = &rte_eth_devices[port_id];
604 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
605 dev->data->dev_started = 0;
606 (*dev->dev_ops->dev_stop)(dev);
610 rte_eth_dev_close(uint8_t port_id)
612 struct rte_eth_dev *dev;
614 /* This function is only safe when called from the primary process
615 * in a multi-process setup*/
616 PROC_PRIMARY_OR_RET();
618 if (port_id >= nb_ports) {
619 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
623 dev = &rte_eth_devices[port_id];
625 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
626 dev->data->dev_started = 0;
627 (*dev->dev_ops->dev_close)(dev);
631 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
632 uint16_t nb_rx_desc, unsigned int socket_id,
633 const struct rte_eth_rxconf *rx_conf,
634 struct rte_mempool *mp)
636 struct rte_eth_dev *dev;
637 struct rte_pktmbuf_pool_private *mbp_priv;
638 struct rte_eth_dev_info dev_info;
640 /* This function is only safe when called from the primary process
641 * in a multi-process setup*/
642 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
644 if (port_id >= nb_ports) {
645 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
648 dev = &rte_eth_devices[port_id];
649 if (rx_queue_id >= dev->data->nb_rx_queues) {
650 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
654 if (dev->data->dev_started) {
656 "port %d must be stopped to allow configuration\n", port_id);
660 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
661 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
664 * Check the size of the mbuf data buffer.
665 * This value must be provided in the private data of the memory pool.
666 * First check that the memory pool has a valid private data.
668 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
669 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
670 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
671 mp->name, (int) mp->private_data_size,
672 (int) sizeof(struct rte_pktmbuf_pool_private));
675 mbp_priv = (struct rte_pktmbuf_pool_private *)
676 ((char *)mp + sizeof(struct rte_mempool));
677 if ((uint32_t) (mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM) <
678 dev_info.min_rx_bufsize) {
679 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
680 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
683 (int)mbp_priv->mbuf_data_room_size,
684 (int)(RTE_PKTMBUF_HEADROOM +
685 dev_info.min_rx_bufsize),
686 (int)RTE_PKTMBUF_HEADROOM,
687 (int)dev_info.min_rx_bufsize);
691 return (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
692 socket_id, rx_conf, mp);
696 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
697 uint16_t nb_tx_desc, unsigned int socket_id,
698 const struct rte_eth_txconf *tx_conf)
700 struct rte_eth_dev *dev;
702 /* This function is only safe when called from the primary process
703 * in a multi-process setup*/
704 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
706 if (port_id >= RTE_MAX_ETHPORTS || port_id >= nb_ports) {
707 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
710 dev = &rte_eth_devices[port_id];
711 if (tx_queue_id >= dev->data->nb_tx_queues) {
712 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
716 if (dev->data->dev_started) {
718 "port %d must be stopped to allow configuration\n", port_id);
722 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
723 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
728 rte_eth_promiscuous_enable(uint8_t port_id)
730 struct rte_eth_dev *dev;
732 if (port_id >= nb_ports) {
733 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
736 dev = &rte_eth_devices[port_id];
738 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
739 (*dev->dev_ops->promiscuous_enable)(dev);
740 dev->data->promiscuous = 1;
744 rte_eth_promiscuous_disable(uint8_t port_id)
746 struct rte_eth_dev *dev;
748 if (port_id >= nb_ports) {
749 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
752 dev = &rte_eth_devices[port_id];
754 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
755 dev->data->promiscuous = 0;
756 (*dev->dev_ops->promiscuous_disable)(dev);
760 rte_eth_promiscuous_get(uint8_t port_id)
762 struct rte_eth_dev *dev;
764 if (port_id >= nb_ports) {
765 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
769 dev = &rte_eth_devices[port_id];
770 return dev->data->promiscuous;
774 rte_eth_allmulticast_enable(uint8_t port_id)
776 struct rte_eth_dev *dev;
778 if (port_id >= nb_ports) {
779 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
782 dev = &rte_eth_devices[port_id];
784 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
785 (*dev->dev_ops->allmulticast_enable)(dev);
786 dev->data->all_multicast = 1;
790 rte_eth_allmulticast_disable(uint8_t port_id)
792 struct rte_eth_dev *dev;
794 if (port_id >= nb_ports) {
795 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
798 dev = &rte_eth_devices[port_id];
800 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
801 dev->data->all_multicast = 0;
802 (*dev->dev_ops->allmulticast_disable)(dev);
806 rte_eth_allmulticast_get(uint8_t port_id)
808 struct rte_eth_dev *dev;
810 if (port_id >= nb_ports) {
811 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
815 dev = &rte_eth_devices[port_id];
816 return dev->data->all_multicast;
820 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
821 struct rte_eth_link *link)
823 struct rte_eth_link *dst = link;
824 struct rte_eth_link *src = &(dev->data->dev_link);
826 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
827 *(uint64_t *)src) == 0)
834 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
836 struct rte_eth_dev *dev;
838 if (port_id >= nb_ports) {
839 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
842 dev = &rte_eth_devices[port_id];
843 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
845 if (dev->data->dev_conf.intr_conf.lsc != 0)
846 rte_eth_dev_atomic_read_link_status(dev, eth_link);
848 (*dev->dev_ops->link_update)(dev, 1);
849 *eth_link = dev->data->dev_link;
854 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
856 struct rte_eth_dev *dev;
858 if (port_id >= nb_ports) {
859 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
862 dev = &rte_eth_devices[port_id];
863 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
865 if (dev->data->dev_conf.intr_conf.lsc != 0)
866 rte_eth_dev_atomic_read_link_status(dev, eth_link);
868 (*dev->dev_ops->link_update)(dev, 0);
869 *eth_link = dev->data->dev_link;
874 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
876 struct rte_eth_dev *dev;
878 if (port_id >= nb_ports) {
879 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
882 dev = &rte_eth_devices[port_id];
884 FUNC_PTR_OR_RET(*dev->dev_ops->stats_get);
885 (*dev->dev_ops->stats_get)(dev, stats);
886 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
890 rte_eth_stats_reset(uint8_t port_id)
892 struct rte_eth_dev *dev;
894 if (port_id >= nb_ports) {
895 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
898 dev = &rte_eth_devices[port_id];
900 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
901 (*dev->dev_ops->stats_reset)(dev);
906 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
909 struct rte_eth_dev *dev;
911 if (port_id >= nb_ports) {
912 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
915 dev = &rte_eth_devices[port_id];
917 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
918 return (*dev->dev_ops->queue_stats_mapping_set)
919 (dev, queue_id, stat_idx, is_rx);
924 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
927 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
933 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
936 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
942 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
944 struct rte_eth_dev *dev;
946 if (port_id >= nb_ports) {
947 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
950 dev = &rte_eth_devices[port_id];
952 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
953 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
954 dev_info->pci_dev = dev->pci_dev;
955 dev_info->driver_name = dev->driver->pci_drv.name;
959 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
961 struct rte_eth_dev *dev;
963 if (port_id >= nb_ports) {
964 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
967 dev = &rte_eth_devices[port_id];
968 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
972 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
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 if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
982 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
986 if (vlan_id > 4095) {
987 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
988 port_id, (unsigned) vlan_id);
991 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
992 (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
997 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
998 struct rte_fdir_filter *fdir_filter,
1001 struct rte_eth_dev *dev;
1003 if (port_id >= nb_ports) {
1004 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1008 dev = &rte_eth_devices[port_id];
1010 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1011 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1012 port_id, dev->data->dev_conf.fdir_conf.mode);
1016 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1017 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1018 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1019 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1020 "None l4type, source & destinations ports " \
1021 "should be null!\n");
1025 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1026 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1031 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1032 struct rte_fdir_filter *fdir_filter,
1035 struct rte_eth_dev *dev;
1037 if (port_id >= nb_ports) {
1038 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1042 dev = &rte_eth_devices[port_id];
1044 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1045 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1046 port_id, dev->data->dev_conf.fdir_conf.mode);
1050 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1051 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1052 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1053 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1054 "None l4type, source & destinations ports " \
1055 "should be null!\n");
1059 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
1060 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
1066 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
1067 struct rte_fdir_filter *fdir_filter)
1069 struct rte_eth_dev *dev;
1071 if (port_id >= nb_ports) {
1072 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1076 dev = &rte_eth_devices[port_id];
1078 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1079 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1080 port_id, dev->data->dev_conf.fdir_conf.mode);
1084 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1085 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1086 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1087 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1088 "None l4type source & destinations ports " \
1089 "should be null!\n");
1093 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
1094 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
1098 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
1100 struct rte_eth_dev *dev;
1102 if (port_id >= nb_ports) {
1103 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1107 dev = &rte_eth_devices[port_id];
1108 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1109 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1113 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
1115 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
1120 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
1121 struct rte_fdir_filter *fdir_filter,
1122 uint16_t soft_id, uint8_t queue,
1125 struct rte_eth_dev *dev;
1127 if (port_id >= nb_ports) {
1128 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1132 dev = &rte_eth_devices[port_id];
1134 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1135 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1136 port_id, dev->data->dev_conf.fdir_conf.mode);
1140 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1141 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1142 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1143 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1144 "None l4type, source & destinations ports " \
1145 "should be null!\n");
1149 /* For now IPv6 is not supported with perfect filter */
1150 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1153 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
1154 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
1160 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
1161 struct rte_fdir_filter *fdir_filter,
1162 uint16_t soft_id, uint8_t queue,
1165 struct rte_eth_dev *dev;
1167 if (port_id >= nb_ports) {
1168 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1172 dev = &rte_eth_devices[port_id];
1174 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1175 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1176 port_id, dev->data->dev_conf.fdir_conf.mode);
1180 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1181 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1182 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1183 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1184 "None l4type, source & destinations ports " \
1185 "should be null!\n");
1189 /* For now IPv6 is not supported with perfect filter */
1190 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1193 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
1194 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
1195 soft_id, queue, drop);
1199 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
1200 struct rte_fdir_filter *fdir_filter,
1203 struct rte_eth_dev *dev;
1205 if (port_id >= nb_ports) {
1206 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1210 dev = &rte_eth_devices[port_id];
1212 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1213 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1214 port_id, dev->data->dev_conf.fdir_conf.mode);
1218 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1219 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1220 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1221 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1222 "None l4type, source & destinations ports " \
1223 "should be null!\n");
1227 /* For now IPv6 is not supported with perfect filter */
1228 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1231 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
1232 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
1237 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
1239 struct rte_eth_dev *dev;
1241 if (port_id >= nb_ports) {
1242 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1246 dev = &rte_eth_devices[port_id];
1247 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1248 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1252 /* IPv6 mask are not supported */
1253 if (fdir_mask->src_ipv6_mask)
1256 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
1257 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
1261 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1263 struct rte_eth_dev *dev;
1265 if (port_id >= nb_ports) {
1266 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1270 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1271 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1275 dev = &rte_eth_devices[port_id];
1277 /* High water, low water validation are device specific */
1278 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1279 if (*dev->dev_ops->flow_ctrl_set)
1280 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1286 rte_eth_led_on(uint8_t port_id)
1288 struct rte_eth_dev *dev;
1290 if (port_id >= nb_ports) {
1291 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1295 dev = &rte_eth_devices[port_id];
1296 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
1297 return ((*dev->dev_ops->dev_led_on)(dev));
1301 rte_eth_led_off(uint8_t port_id)
1303 struct rte_eth_dev *dev;
1305 if (port_id >= nb_ports) {
1306 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1310 dev = &rte_eth_devices[port_id];
1311 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
1312 return ((*dev->dev_ops->dev_led_off)(dev));
1316 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
1320 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
1322 struct rte_eth_dev_info dev_info;
1323 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1326 rte_eth_dev_info_get(port_id, &dev_info);
1328 for (i = 0; i < dev_info.max_mac_addrs; i++)
1329 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
1335 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
1338 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
1341 struct rte_eth_dev *dev;
1344 if (port_id >= nb_ports) {
1345 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1348 dev = &rte_eth_devices[port_id];
1349 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
1351 if (is_zero_ether_addr(addr)) {
1352 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n", port_id);
1356 /* Check if it's already there, and do nothing */
1357 index = get_mac_addr_index(port_id, addr);
1361 index = get_mac_addr_index(port_id, &null_mac_addr);
1363 PMD_DEBUG_TRACE("port %d: MAC address array full\n", port_id);
1368 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
1370 /* Update address in NIC data structure */
1371 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
1377 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
1379 struct rte_eth_dev *dev;
1382 if (port_id >= nb_ports) {
1383 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1386 dev = &rte_eth_devices[port_id];
1387 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
1389 index = get_mac_addr_index(port_id, addr);
1391 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
1392 return (-EADDRINUSE);
1393 } else if (index < 0)
1394 return 0; /* Do nothing if address wasn't found */
1397 (*dev->dev_ops->mac_addr_remove)(dev, index);
1399 /* Update address in NIC data structure */
1400 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
1405 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
1407 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
1408 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
1410 struct rte_eth_dev *dev;
1412 if (port_id >= nb_ports) {
1413 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1416 dev = &rte_eth_devices[port_id];
1417 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, -ENOTSUP);
1418 if (queue_id >= dev->data->nb_rx_queues) {
1419 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
1422 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
1427 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
1428 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1430 struct rte_eth_dev *dev;
1432 if (port_id >= nb_ports) {
1433 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1436 dev = &rte_eth_devices[port_id];
1438 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, -ENOTSUP);
1439 if (queue_id >= dev->data->nb_tx_queues) {
1440 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
1443 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
1449 rte_eth_dev_callback_register(uint8_t port_id,
1450 enum rte_eth_event_type event,
1451 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
1454 struct rte_eth_dev *dev;
1455 struct rte_eth_dev_callback *user_cb = NULL;
1459 if (port_id >= nb_ports) {
1460 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1463 dev = &rte_eth_devices[port_id];
1464 rte_spinlock_lock(&rte_eth_dev_cb_lock);
1465 TAILQ_FOREACH(user_cb, &(dev->callbacks), next) {
1466 if (user_cb->cb_fn == cb_fn &&
1467 user_cb->cb_arg == cb_arg &&
1468 user_cb->event == event) {
1473 user_cb = rte_malloc("INTR_USER_CALLBACK",
1474 sizeof(struct rte_eth_dev_callback), 0);
1477 user_cb->cb_fn = cb_fn;
1478 user_cb->cb_arg = cb_arg;
1479 user_cb->event = event;
1480 TAILQ_INSERT_TAIL(&(dev->callbacks), user_cb, next);
1484 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
1490 rte_eth_dev_callback_unregister(uint8_t port_id,
1491 enum rte_eth_event_type event,
1492 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
1495 struct rte_eth_dev *dev;
1496 struct rte_eth_dev_callback *cb_lst = NULL;
1500 if (port_id >= nb_ports) {
1501 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1504 dev = &rte_eth_devices[port_id];
1505 rte_spinlock_lock(&rte_eth_dev_cb_lock);
1506 TAILQ_FOREACH(cb_lst, &(dev->callbacks), next) {
1507 if (cb_lst->cb_fn != cb_fn || cb_lst->event != event)
1509 if (cb_lst->cb_arg == (void *)-1 ||
1510 cb_lst->cb_arg == cb_arg) {
1511 TAILQ_REMOVE(&(dev->callbacks), cb_lst, next);
1517 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
1523 _rte_eth_dev_callback_process(struct rte_eth_dev *dev, enum rte_eth_event_type event)
1525 struct rte_eth_dev_callback *cb_lst = NULL;
1526 struct rte_eth_dev_callback dev_cb;
1528 rte_spinlock_lock(&rte_eth_dev_cb_lock);
1529 TAILQ_FOREACH(cb_lst, &(dev->callbacks), next) {
1530 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
1533 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
1534 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
1536 rte_spinlock_lock(&rte_eth_dev_cb_lock);
1538 rte_spinlock_unlock(&rte_eth_dev_cb_lock);