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_count(void)
251 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
253 uint16_t old_nb_queues = dev->data->nb_rx_queues;
257 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
259 if (dev->data->rx_queues == NULL) {
260 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
261 sizeof(dev->data->rx_queues[0]) * nb_queues,
263 if (dev->data->rx_queues == NULL) {
264 dev->data->nb_rx_queues = 0;
268 rxq = dev->data->rx_queues;
270 for (i = nb_queues; i < old_nb_queues; i++)
271 (*dev->dev_ops->rx_queue_release)(rxq[i]);
272 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
277 if (nb_queues > old_nb_queues)
278 memset(rxq + old_nb_queues, 0,
279 sizeof(rxq[0]) * (nb_queues - old_nb_queues));
281 dev->data->rx_queues = rxq;
284 dev->data->nb_rx_queues = nb_queues;
289 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
291 uint16_t old_nb_queues = dev->data->nb_tx_queues;
295 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
297 if (dev->data->tx_queues == NULL) {
298 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
299 sizeof(dev->data->tx_queues[0]) * nb_queues,
301 if (dev->data->tx_queues == NULL) {
302 dev->data->nb_tx_queues = 0;
306 txq = dev->data->tx_queues;
308 for (i = nb_queues; i < old_nb_queues; i++)
309 (*dev->dev_ops->tx_queue_release)(txq[i]);
310 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
315 if (nb_queues > old_nb_queues)
316 memset(txq + old_nb_queues, 0,
317 sizeof(txq[0]) * (nb_queues - old_nb_queues));
319 dev->data->tx_queues = txq;
322 dev->data->nb_tx_queues = nb_queues;
327 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
328 const struct rte_eth_conf *dev_conf)
330 struct rte_eth_dev *dev;
331 struct rte_eth_dev_info dev_info;
334 /* This function is only safe when called from the primary process
335 * in a multi-process setup*/
336 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
338 if (port_id >= nb_ports || port_id >= RTE_MAX_ETHPORTS) {
339 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
342 dev = &rte_eth_devices[port_id];
344 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
345 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
347 if (dev->data->dev_started) {
349 "port %d must be stopped to allow configuration\n", port_id);
354 * Check that the numbers of RX and TX queues are not greater
355 * than the maximum number of RX and TX queues supported by the
358 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
359 if (nb_rx_q > dev_info.max_rx_queues) {
360 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
361 port_id, nb_rx_q, dev_info.max_rx_queues);
365 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
369 if (nb_tx_q > dev_info.max_tx_queues) {
370 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
371 port_id, nb_tx_q, dev_info.max_tx_queues);
375 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
379 /* Copy the dev_conf parameter into the dev structure */
380 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
383 * If jumbo frames are enabled, check that the maximum RX packet
384 * length is supported by the configured device.
386 if (dev_conf->rxmode.jumbo_frame == 1) {
387 if (dev_conf->rxmode.max_rx_pkt_len >
388 dev_info.max_rx_pktlen) {
389 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
390 " > max valid value %u\n",
392 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
393 (unsigned)dev_info.max_rx_pktlen);
396 else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
397 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
398 " < min valid value %u\n",
400 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
401 (unsigned)ETHER_MIN_LEN);
405 /* Use default value */
406 dev->data->dev_conf.rxmode.max_rx_pkt_len = ETHER_MAX_LEN;
408 /* For vmdb+dcb mode check our configuration before we go further */
409 if (dev_conf->rxmode.mq_mode == ETH_VMDQ_DCB) {
410 const struct rte_eth_vmdq_dcb_conf *conf;
412 if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
413 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
415 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
418 conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
419 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
420 conf->nb_queue_pools == ETH_32_POOLS)) {
421 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
422 "nb_queue_pools must be %d or %d\n",
423 port_id, ETH_16_POOLS, ETH_32_POOLS);
427 if (dev_conf->txmode.mq_mode == ETH_VMDQ_DCB_TX) {
428 const struct rte_eth_vmdq_dcb_tx_conf *conf;
430 if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
431 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
433 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
436 conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
437 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
438 conf->nb_queue_pools == ETH_32_POOLS)) {
439 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
440 "nb_queue_pools != %d or nb_queue_pools "
442 port_id, ETH_16_POOLS, ETH_32_POOLS);
447 /* For DCB mode check our configuration before we go further */
448 if (dev_conf->rxmode.mq_mode == ETH_DCB_RX) {
449 const struct rte_eth_dcb_rx_conf *conf;
451 if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
452 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
454 port_id, ETH_DCB_NUM_QUEUES);
457 conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
458 if (! (conf->nb_tcs == ETH_4_TCS ||
459 conf->nb_tcs == ETH_8_TCS)) {
460 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
461 "nb_tcs != %d or nb_tcs "
463 port_id, ETH_4_TCS, ETH_8_TCS);
468 if (dev_conf->txmode.mq_mode == ETH_DCB_TX) {
469 const struct rte_eth_dcb_tx_conf *conf;
471 if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
472 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
474 port_id, ETH_DCB_NUM_QUEUES);
477 conf = &(dev_conf->tx_adv_conf.dcb_tx_conf);
478 if (! (conf->nb_tcs == ETH_4_TCS ||
479 conf->nb_tcs == ETH_8_TCS)) {
480 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
481 "nb_tcs != %d or nb_tcs "
483 port_id, ETH_4_TCS, ETH_8_TCS);
489 * Setup new number of RX/TX queues and reconfigure device.
491 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
493 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
498 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
500 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
502 rte_eth_dev_rx_queue_config(dev, 0);
506 diag = (*dev->dev_ops->dev_configure)(dev);
508 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
510 rte_eth_dev_rx_queue_config(dev, 0);
511 rte_eth_dev_tx_queue_config(dev, 0);
519 rte_eth_dev_config_restore(uint8_t port_id)
521 struct rte_eth_dev *dev;
522 struct rte_eth_dev_info dev_info;
523 struct ether_addr addr;
526 dev = &rte_eth_devices[port_id];
528 rte_eth_dev_info_get(port_id, &dev_info);
530 /* replay MAC address configuration */
531 for (i = 0; i < dev_info.max_mac_addrs; i++) {
532 addr = dev->data->mac_addrs[i];
534 /* skip zero address */
535 if (is_zero_ether_addr(&addr))
538 /* add address to the hardware */
539 if (*dev->dev_ops->mac_addr_add)
540 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, 0);
542 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
544 /* exit the loop but not return an error */
549 /* replay promiscuous configuration */
550 if (rte_eth_promiscuous_get(port_id) == 1)
551 rte_eth_promiscuous_enable(port_id);
552 else if (rte_eth_promiscuous_get(port_id) == 0)
553 rte_eth_promiscuous_disable(port_id);
555 /* replay allmulticast configuration */
556 if (rte_eth_allmulticast_get(port_id) == 1)
557 rte_eth_allmulticast_enable(port_id);
558 else if (rte_eth_allmulticast_get(port_id) == 0)
559 rte_eth_allmulticast_disable(port_id);
563 rte_eth_dev_start(uint8_t port_id)
565 struct rte_eth_dev *dev;
568 /* This function is only safe when called from the primary process
569 * in a multi-process setup*/
570 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
572 if (port_id >= nb_ports) {
573 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
576 dev = &rte_eth_devices[port_id];
578 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
579 diag = (*dev->dev_ops->dev_start)(dev);
581 dev->data->dev_started = 1;
585 rte_eth_dev_config_restore(port_id);
591 rte_eth_dev_stop(uint8_t port_id)
593 struct rte_eth_dev *dev;
595 /* This function is only safe when called from the primary process
596 * in a multi-process setup*/
597 PROC_PRIMARY_OR_RET();
599 if (port_id >= nb_ports) {
600 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
603 dev = &rte_eth_devices[port_id];
605 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
606 dev->data->dev_started = 0;
607 (*dev->dev_ops->dev_stop)(dev);
611 rte_eth_dev_close(uint8_t port_id)
613 struct rte_eth_dev *dev;
615 /* This function is only safe when called from the primary process
616 * in a multi-process setup*/
617 PROC_PRIMARY_OR_RET();
619 if (port_id >= nb_ports) {
620 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
624 dev = &rte_eth_devices[port_id];
626 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
627 dev->data->dev_started = 0;
628 (*dev->dev_ops->dev_close)(dev);
632 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
633 uint16_t nb_rx_desc, unsigned int socket_id,
634 const struct rte_eth_rxconf *rx_conf,
635 struct rte_mempool *mp)
637 struct rte_eth_dev *dev;
638 struct rte_pktmbuf_pool_private *mbp_priv;
639 struct rte_eth_dev_info dev_info;
641 /* This function is only safe when called from the primary process
642 * in a multi-process setup*/
643 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
645 if (port_id >= nb_ports) {
646 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
649 dev = &rte_eth_devices[port_id];
650 if (rx_queue_id >= dev->data->nb_rx_queues) {
651 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
655 if (dev->data->dev_started) {
657 "port %d must be stopped to allow configuration\n", port_id);
661 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
662 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
665 * Check the size of the mbuf data buffer.
666 * This value must be provided in the private data of the memory pool.
667 * First check that the memory pool has a valid private data.
669 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
670 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
671 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
672 mp->name, (int) mp->private_data_size,
673 (int) sizeof(struct rte_pktmbuf_pool_private));
676 mbp_priv = (struct rte_pktmbuf_pool_private *)
677 ((char *)mp + sizeof(struct rte_mempool));
678 if ((uint32_t) (mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM) <
679 dev_info.min_rx_bufsize) {
680 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
681 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
684 (int)mbp_priv->mbuf_data_room_size,
685 (int)(RTE_PKTMBUF_HEADROOM +
686 dev_info.min_rx_bufsize),
687 (int)RTE_PKTMBUF_HEADROOM,
688 (int)dev_info.min_rx_bufsize);
692 return (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
693 socket_id, rx_conf, mp);
697 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
698 uint16_t nb_tx_desc, unsigned int socket_id,
699 const struct rte_eth_txconf *tx_conf)
701 struct rte_eth_dev *dev;
703 /* This function is only safe when called from the primary process
704 * in a multi-process setup*/
705 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
707 if (port_id >= RTE_MAX_ETHPORTS || port_id >= nb_ports) {
708 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
711 dev = &rte_eth_devices[port_id];
712 if (tx_queue_id >= dev->data->nb_tx_queues) {
713 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
717 if (dev->data->dev_started) {
719 "port %d must be stopped to allow configuration\n", port_id);
723 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
724 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
729 rte_eth_promiscuous_enable(uint8_t port_id)
731 struct rte_eth_dev *dev;
733 if (port_id >= nb_ports) {
734 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
737 dev = &rte_eth_devices[port_id];
739 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
740 (*dev->dev_ops->promiscuous_enable)(dev);
741 dev->data->promiscuous = 1;
745 rte_eth_promiscuous_disable(uint8_t port_id)
747 struct rte_eth_dev *dev;
749 if (port_id >= nb_ports) {
750 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
753 dev = &rte_eth_devices[port_id];
755 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
756 dev->data->promiscuous = 0;
757 (*dev->dev_ops->promiscuous_disable)(dev);
761 rte_eth_promiscuous_get(uint8_t port_id)
763 struct rte_eth_dev *dev;
765 if (port_id >= nb_ports) {
766 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
770 dev = &rte_eth_devices[port_id];
771 return dev->data->promiscuous;
775 rte_eth_allmulticast_enable(uint8_t port_id)
777 struct rte_eth_dev *dev;
779 if (port_id >= nb_ports) {
780 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
783 dev = &rte_eth_devices[port_id];
785 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
786 (*dev->dev_ops->allmulticast_enable)(dev);
787 dev->data->all_multicast = 1;
791 rte_eth_allmulticast_disable(uint8_t port_id)
793 struct rte_eth_dev *dev;
795 if (port_id >= nb_ports) {
796 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
799 dev = &rte_eth_devices[port_id];
801 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
802 dev->data->all_multicast = 0;
803 (*dev->dev_ops->allmulticast_disable)(dev);
807 rte_eth_allmulticast_get(uint8_t port_id)
809 struct rte_eth_dev *dev;
811 if (port_id >= nb_ports) {
812 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
816 dev = &rte_eth_devices[port_id];
817 return dev->data->all_multicast;
821 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
822 struct rte_eth_link *link)
824 struct rte_eth_link *dst = link;
825 struct rte_eth_link *src = &(dev->data->dev_link);
827 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
828 *(uint64_t *)src) == 0)
835 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
837 struct rte_eth_dev *dev;
839 if (port_id >= nb_ports) {
840 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
843 dev = &rte_eth_devices[port_id];
844 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
846 if (dev->data->dev_conf.intr_conf.lsc != 0)
847 rte_eth_dev_atomic_read_link_status(dev, eth_link);
849 (*dev->dev_ops->link_update)(dev, 1);
850 *eth_link = dev->data->dev_link;
855 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
857 struct rte_eth_dev *dev;
859 if (port_id >= nb_ports) {
860 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
863 dev = &rte_eth_devices[port_id];
864 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
866 if (dev->data->dev_conf.intr_conf.lsc != 0)
867 rte_eth_dev_atomic_read_link_status(dev, eth_link);
869 (*dev->dev_ops->link_update)(dev, 0);
870 *eth_link = dev->data->dev_link;
875 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
877 struct rte_eth_dev *dev;
879 if (port_id >= nb_ports) {
880 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
883 dev = &rte_eth_devices[port_id];
885 FUNC_PTR_OR_RET(*dev->dev_ops->stats_get);
886 (*dev->dev_ops->stats_get)(dev, stats);
887 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
891 rte_eth_stats_reset(uint8_t port_id)
893 struct rte_eth_dev *dev;
895 if (port_id >= nb_ports) {
896 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
899 dev = &rte_eth_devices[port_id];
901 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
902 (*dev->dev_ops->stats_reset)(dev);
907 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
910 struct rte_eth_dev *dev;
912 if (port_id >= nb_ports) {
913 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
916 dev = &rte_eth_devices[port_id];
918 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
919 return (*dev->dev_ops->queue_stats_mapping_set)
920 (dev, queue_id, stat_idx, is_rx);
925 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
928 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
934 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
937 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
943 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
945 struct rte_eth_dev *dev;
947 if (port_id >= nb_ports) {
948 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
951 dev = &rte_eth_devices[port_id];
953 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
954 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
955 dev_info->pci_dev = dev->pci_dev;
956 dev_info->driver_name = dev->driver->pci_drv.name;
960 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
962 struct rte_eth_dev *dev;
964 if (port_id >= nb_ports) {
965 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
968 dev = &rte_eth_devices[port_id];
969 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
973 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
975 struct rte_eth_dev *dev;
977 if (port_id >= nb_ports) {
978 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
981 dev = &rte_eth_devices[port_id];
982 if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
983 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
987 if (vlan_id > 4095) {
988 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
989 port_id, (unsigned) vlan_id);
992 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
993 (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
998 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1000 struct rte_eth_dev *dev;
1002 if (port_id >= nb_ports) {
1003 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1007 dev = &rte_eth_devices[port_id];
1008 if (rx_queue_id >= dev->data->nb_rx_queues) {
1009 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1013 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1014 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1020 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1022 struct rte_eth_dev *dev;
1024 if (port_id >= nb_ports) {
1025 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1029 dev = &rte_eth_devices[port_id];
1030 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1031 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1037 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1039 struct rte_eth_dev *dev;
1044 if (port_id >= nb_ports) {
1045 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1049 dev = &rte_eth_devices[port_id];
1051 /*check which option changed by application*/
1052 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1053 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1055 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1056 mask |= ETH_VLAN_STRIP_MASK;
1059 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1060 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1062 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1063 mask |= ETH_VLAN_FILTER_MASK;
1066 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1067 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1069 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1070 mask |= ETH_VLAN_EXTEND_MASK;
1077 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1078 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1084 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1086 struct rte_eth_dev *dev;
1089 if (port_id >= nb_ports) {
1090 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1094 dev = &rte_eth_devices[port_id];
1096 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1097 ret |= ETH_VLAN_STRIP_OFFLOAD ;
1099 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1100 ret |= ETH_VLAN_FILTER_OFFLOAD ;
1102 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1103 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
1110 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1111 struct rte_fdir_filter *fdir_filter,
1114 struct rte_eth_dev *dev;
1116 if (port_id >= nb_ports) {
1117 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1121 dev = &rte_eth_devices[port_id];
1123 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1124 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1125 port_id, dev->data->dev_conf.fdir_conf.mode);
1129 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1130 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1131 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1132 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1133 "None l4type, source & destinations ports " \
1134 "should be null!\n");
1138 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1139 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1144 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1145 struct rte_fdir_filter *fdir_filter,
1148 struct rte_eth_dev *dev;
1150 if (port_id >= nb_ports) {
1151 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1155 dev = &rte_eth_devices[port_id];
1157 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1158 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1159 port_id, dev->data->dev_conf.fdir_conf.mode);
1163 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1164 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1165 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1166 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1167 "None l4type, source & destinations ports " \
1168 "should be null!\n");
1172 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
1173 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
1179 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
1180 struct rte_fdir_filter *fdir_filter)
1182 struct rte_eth_dev *dev;
1184 if (port_id >= nb_ports) {
1185 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1189 dev = &rte_eth_devices[port_id];
1191 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1192 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1193 port_id, dev->data->dev_conf.fdir_conf.mode);
1197 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1198 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1199 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1200 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1201 "None l4type source & destinations ports " \
1202 "should be null!\n");
1206 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
1207 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
1211 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
1213 struct rte_eth_dev *dev;
1215 if (port_id >= nb_ports) {
1216 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1220 dev = &rte_eth_devices[port_id];
1221 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1222 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1226 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
1228 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
1233 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
1234 struct rte_fdir_filter *fdir_filter,
1235 uint16_t soft_id, uint8_t queue,
1238 struct rte_eth_dev *dev;
1240 if (port_id >= nb_ports) {
1241 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1245 dev = &rte_eth_devices[port_id];
1247 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1248 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1249 port_id, dev->data->dev_conf.fdir_conf.mode);
1253 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1254 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1255 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1256 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1257 "None l4type, source & destinations ports " \
1258 "should be null!\n");
1262 /* For now IPv6 is not supported with perfect filter */
1263 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1266 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
1267 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
1273 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
1274 struct rte_fdir_filter *fdir_filter,
1275 uint16_t soft_id, uint8_t queue,
1278 struct rte_eth_dev *dev;
1280 if (port_id >= nb_ports) {
1281 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1285 dev = &rte_eth_devices[port_id];
1287 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1288 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1289 port_id, dev->data->dev_conf.fdir_conf.mode);
1293 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1294 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1295 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1296 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1297 "None l4type, source & destinations ports " \
1298 "should be null!\n");
1302 /* For now IPv6 is not supported with perfect filter */
1303 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1306 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
1307 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
1308 soft_id, queue, drop);
1312 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
1313 struct rte_fdir_filter *fdir_filter,
1316 struct rte_eth_dev *dev;
1318 if (port_id >= nb_ports) {
1319 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1323 dev = &rte_eth_devices[port_id];
1325 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1326 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1327 port_id, dev->data->dev_conf.fdir_conf.mode);
1331 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1332 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1333 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1334 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1335 "None l4type, source & destinations ports " \
1336 "should be null!\n");
1340 /* For now IPv6 is not supported with perfect filter */
1341 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1344 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
1345 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
1350 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
1352 struct rte_eth_dev *dev;
1354 if (port_id >= nb_ports) {
1355 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1359 dev = &rte_eth_devices[port_id];
1360 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1361 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1365 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
1366 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
1370 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1372 struct rte_eth_dev *dev;
1374 if (port_id >= nb_ports) {
1375 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1379 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1380 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1384 dev = &rte_eth_devices[port_id];
1385 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1386 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1390 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1392 struct rte_eth_dev *dev;
1394 if (port_id >= nb_ports) {
1395 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1399 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1400 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1404 dev = &rte_eth_devices[port_id];
1405 /* High water, low water validation are device specific */
1406 if (*dev->dev_ops->priority_flow_ctrl_set)
1407 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1412 rte_eth_led_on(uint8_t port_id)
1414 struct rte_eth_dev *dev;
1416 if (port_id >= nb_ports) {
1417 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1421 dev = &rte_eth_devices[port_id];
1422 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
1423 return ((*dev->dev_ops->dev_led_on)(dev));
1427 rte_eth_led_off(uint8_t port_id)
1429 struct rte_eth_dev *dev;
1431 if (port_id >= nb_ports) {
1432 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1436 dev = &rte_eth_devices[port_id];
1437 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
1438 return ((*dev->dev_ops->dev_led_off)(dev));
1442 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
1446 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
1448 struct rte_eth_dev_info dev_info;
1449 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1452 rte_eth_dev_info_get(port_id, &dev_info);
1454 for (i = 0; i < dev_info.max_mac_addrs; i++)
1455 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
1461 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
1464 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
1467 struct rte_eth_dev *dev;
1470 if (port_id >= nb_ports) {
1471 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1474 dev = &rte_eth_devices[port_id];
1475 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
1477 if (is_zero_ether_addr(addr)) {
1478 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n", port_id);
1482 /* Check if it's already there, and do nothing */
1483 index = get_mac_addr_index(port_id, addr);
1487 index = get_mac_addr_index(port_id, &null_mac_addr);
1489 PMD_DEBUG_TRACE("port %d: MAC address array full\n", port_id);
1494 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
1496 /* Update address in NIC data structure */
1497 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
1503 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
1505 struct rte_eth_dev *dev;
1508 if (port_id >= nb_ports) {
1509 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1512 dev = &rte_eth_devices[port_id];
1513 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
1515 index = get_mac_addr_index(port_id, addr);
1517 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
1518 return (-EADDRINUSE);
1519 } else if (index < 0)
1520 return 0; /* Do nothing if address wasn't found */
1523 (*dev->dev_ops->mac_addr_remove)(dev, index);
1525 /* Update address in NIC data structure */
1526 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
1531 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
1533 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
1534 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
1536 struct rte_eth_dev *dev;
1538 if (port_id >= nb_ports) {
1539 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1542 dev = &rte_eth_devices[port_id];
1543 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, -ENOTSUP);
1544 if (queue_id >= dev->data->nb_rx_queues) {
1545 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
1548 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
1553 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
1554 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1556 struct rte_eth_dev *dev;
1558 if (port_id >= nb_ports) {
1559 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1562 dev = &rte_eth_devices[port_id];
1564 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, -ENOTSUP);
1565 if (queue_id >= dev->data->nb_tx_queues) {
1566 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
1569 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
1575 rte_eth_dev_callback_register(uint8_t port_id,
1576 enum rte_eth_event_type event,
1577 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
1579 struct rte_eth_dev *dev;
1580 struct rte_eth_dev_callback *user_cb;
1584 if (port_id >= nb_ports) {
1585 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1589 dev = &rte_eth_devices[port_id];
1590 rte_spinlock_lock(&rte_eth_dev_cb_lock);
1592 TAILQ_FOREACH(user_cb, &(dev->callbacks), next) {
1593 if (user_cb->cb_fn == cb_fn &&
1594 user_cb->cb_arg == cb_arg &&
1595 user_cb->event == event) {
1600 /* create a new callback. */
1601 if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
1602 sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
1603 user_cb->cb_fn = cb_fn;
1604 user_cb->cb_arg = cb_arg;
1605 user_cb->event = event;
1606 TAILQ_INSERT_TAIL(&(dev->callbacks), user_cb, next);
1609 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
1610 return ((user_cb == NULL) ? -ENOMEM : 0);
1614 rte_eth_dev_callback_unregister(uint8_t port_id,
1615 enum rte_eth_event_type event,
1616 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
1619 struct rte_eth_dev *dev;
1620 struct rte_eth_dev_callback *cb, *next;
1624 if (port_id >= nb_ports) {
1625 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1629 dev = &rte_eth_devices[port_id];
1630 rte_spinlock_lock(&rte_eth_dev_cb_lock);
1633 for (cb = TAILQ_FIRST(&dev->callbacks); cb != NULL; cb = next) {
1635 next = TAILQ_NEXT(cb, next);
1637 if (cb->cb_fn != cb_fn || cb->event != event ||
1638 (cb->cb_arg != (void *)-1 &&
1639 cb->cb_arg != cb_arg))
1643 * if this callback is not executing right now,
1646 if (cb->active == 0) {
1647 TAILQ_REMOVE(&(dev->callbacks), cb, next);
1654 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
1659 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
1660 enum rte_eth_event_type event)
1662 struct rte_eth_dev_callback *cb_lst;
1663 struct rte_eth_dev_callback dev_cb;
1665 rte_spinlock_lock(&rte_eth_dev_cb_lock);
1666 TAILQ_FOREACH(cb_lst, &(dev->callbacks), next) {
1667 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
1671 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
1672 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
1674 rte_spinlock_lock(&rte_eth_dev_cb_lock);
1677 rte_spinlock_unlock(&rte_eth_dev_cb_lock);