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.
34 #include <sys/types.h>
35 #include <sys/queue.h>
45 #include <rte_byteorder.h>
47 #include <rte_debug.h>
48 #include <rte_interrupts.h>
50 #include <rte_memory.h>
51 #include <rte_memcpy.h>
52 #include <rte_memzone.h>
53 #include <rte_launch.h>
54 #include <rte_tailq.h>
56 #include <rte_per_lcore.h>
57 #include <rte_lcore.h>
58 #include <rte_atomic.h>
59 #include <rte_branch_prediction.h>
60 #include <rte_common.h>
62 #include <rte_mempool.h>
63 #include <rte_malloc.h>
65 #include <rte_errno.h>
66 #include <rte_spinlock.h>
68 #include "rte_ether.h"
69 #include "rte_ethdev.h"
71 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
72 #define PMD_DEBUG_TRACE(fmt, args...) do { \
73 RTE_LOG(ERR, PMD, "%s: " fmt, __func__, ## args); \
76 #define PMD_DEBUG_TRACE(fmt, args...)
79 /* Macros for checking for restricting functions to primary instance only */
80 #define PROC_PRIMARY_OR_ERR_RET(retval) do { \
81 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
82 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
86 #define PROC_PRIMARY_OR_RET() do { \
87 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
88 PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
93 /* Macros to check for invlaid function pointers in dev_ops structure */
94 #define FUNC_PTR_OR_ERR_RET(func, retval) do { \
95 if ((func) == NULL) { \
96 PMD_DEBUG_TRACE("Function not supported\n"); \
100 #define FUNC_PTR_OR_RET(func) do { \
101 if ((func) == NULL) { \
102 PMD_DEBUG_TRACE("Function not supported\n"); \
107 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
108 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
109 static struct rte_eth_dev_data *rte_eth_dev_data = NULL;
110 static uint8_t nb_ports = 0;
112 /* spinlock for eth device callbacks */
113 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
116 * The user application callback description.
118 * It contains callback address to be registered by user application,
119 * the pointer to the parameters for callback, and the event type.
121 struct rte_eth_dev_callback {
122 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
123 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
124 void *cb_arg; /**< Parameter for callback */
125 enum rte_eth_event_type event; /**< Interrupt event type */
126 uint32_t active; /**< Callback is executing */
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_socket_id(uint8_t port_id)
246 if (port_id >= nb_ports)
248 return rte_eth_devices[port_id].pci_dev->numa_node;
252 rte_eth_dev_count(void)
258 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
260 uint16_t old_nb_queues = dev->data->nb_rx_queues;
264 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
266 if (dev->data->rx_queues == NULL) {
267 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
268 sizeof(dev->data->rx_queues[0]) * nb_queues,
270 if (dev->data->rx_queues == NULL) {
271 dev->data->nb_rx_queues = 0;
275 rxq = dev->data->rx_queues;
277 for (i = nb_queues; i < old_nb_queues; i++)
278 (*dev->dev_ops->rx_queue_release)(rxq[i]);
279 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
284 if (nb_queues > old_nb_queues)
285 memset(rxq + old_nb_queues, 0,
286 sizeof(rxq[0]) * (nb_queues - old_nb_queues));
288 dev->data->rx_queues = rxq;
291 dev->data->nb_rx_queues = nb_queues;
296 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
298 uint16_t old_nb_queues = dev->data->nb_tx_queues;
302 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
304 if (dev->data->tx_queues == NULL) {
305 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
306 sizeof(dev->data->tx_queues[0]) * nb_queues,
308 if (dev->data->tx_queues == NULL) {
309 dev->data->nb_tx_queues = 0;
313 txq = dev->data->tx_queues;
315 for (i = nb_queues; i < old_nb_queues; i++)
316 (*dev->dev_ops->tx_queue_release)(txq[i]);
317 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
322 if (nb_queues > old_nb_queues)
323 memset(txq + old_nb_queues, 0,
324 sizeof(txq[0]) * (nb_queues - old_nb_queues));
326 dev->data->tx_queues = txq;
329 dev->data->nb_tx_queues = nb_queues;
334 rte_eth_dev_check_mq_mode(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
335 const struct rte_eth_conf *dev_conf)
337 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
339 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
340 /* check multi-queue mode */
341 if ((dev_conf->rxmode.mq_mode == ETH_MQ_RX_RSS) ||
342 (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) ||
343 (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB_RSS) ||
344 (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB)) {
345 /* SRIOV only works in VMDq enable mode */
346 PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
347 "wrong VMDQ mq_mode rx %d tx %d\n",
348 port_id, dev_conf->rxmode.mq_mode,
349 dev_conf->txmode.mq_mode);
353 switch (dev_conf->rxmode.mq_mode) {
354 case ETH_MQ_RX_VMDQ_RSS:
355 case ETH_MQ_RX_VMDQ_DCB:
356 case ETH_MQ_RX_VMDQ_DCB_RSS:
357 /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
358 PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
359 "unsupported VMDQ mq_mode rx %d\n",
360 port_id, dev_conf->rxmode.mq_mode);
362 default: /* ETH_MQ_RX_VMDQ_ONLY or ETH_MQ_RX_NONE */
363 /* if nothing mq mode configure, use default scheme */
364 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
365 if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
366 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
370 switch (dev_conf->txmode.mq_mode) {
371 case ETH_MQ_TX_VMDQ_DCB:
372 /* DCB VMDQ in SRIOV mode, not implement yet */
373 PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
374 "unsupported VMDQ mq_mode tx %d\n",
375 port_id, dev_conf->txmode.mq_mode);
377 default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
378 /* if nothing mq mode configure, use default scheme */
379 dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
380 if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
381 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
385 /* check valid queue number */
386 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
387 (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
388 PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
389 "queue number must less equal to %d\n",
390 port_id, RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
394 /* For vmdb+dcb mode check our configuration before we go further */
395 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB) {
396 const struct rte_eth_vmdq_dcb_conf *conf;
398 if (nb_rx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
399 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_rx_q "
401 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
404 conf = &(dev_conf->rx_adv_conf.vmdq_dcb_conf);
405 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
406 conf->nb_queue_pools == ETH_32_POOLS)) {
407 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
408 "nb_queue_pools must be %d or %d\n",
409 port_id, ETH_16_POOLS, ETH_32_POOLS);
413 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
414 const struct rte_eth_vmdq_dcb_tx_conf *conf;
416 if (nb_tx_q != ETH_VMDQ_DCB_NUM_QUEUES) {
417 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB, nb_tx_q "
419 port_id, ETH_VMDQ_DCB_NUM_QUEUES);
422 conf = &(dev_conf->tx_adv_conf.vmdq_dcb_tx_conf);
423 if (! (conf->nb_queue_pools == ETH_16_POOLS ||
424 conf->nb_queue_pools == ETH_32_POOLS)) {
425 PMD_DEBUG_TRACE("ethdev port_id=%d VMDQ+DCB selected, "
426 "nb_queue_pools != %d or nb_queue_pools "
428 port_id, ETH_16_POOLS, ETH_32_POOLS);
433 /* For DCB mode check our configuration before we go further */
434 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) {
435 const struct rte_eth_dcb_rx_conf *conf;
437 if (nb_rx_q != ETH_DCB_NUM_QUEUES) {
438 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_rx_q "
440 port_id, ETH_DCB_NUM_QUEUES);
443 conf = &(dev_conf->rx_adv_conf.dcb_rx_conf);
444 if (! (conf->nb_tcs == ETH_4_TCS ||
445 conf->nb_tcs == ETH_8_TCS)) {
446 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
447 "nb_tcs != %d or nb_tcs "
449 port_id, ETH_4_TCS, ETH_8_TCS);
454 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
455 const struct rte_eth_dcb_tx_conf *conf;
457 if (nb_tx_q != ETH_DCB_NUM_QUEUES) {
458 PMD_DEBUG_TRACE("ethdev port_id=%d DCB, nb_tx_q "
460 port_id, ETH_DCB_NUM_QUEUES);
463 conf = &(dev_conf->tx_adv_conf.dcb_tx_conf);
464 if (! (conf->nb_tcs == ETH_4_TCS ||
465 conf->nb_tcs == ETH_8_TCS)) {
466 PMD_DEBUG_TRACE("ethdev port_id=%d DCB selected, "
467 "nb_tcs != %d or nb_tcs "
469 port_id, ETH_4_TCS, ETH_8_TCS);
478 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
479 const struct rte_eth_conf *dev_conf)
481 struct rte_eth_dev *dev;
482 struct rte_eth_dev_info dev_info;
485 /* This function is only safe when called from the primary process
486 * in a multi-process setup*/
487 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
489 if (port_id >= nb_ports || port_id >= RTE_MAX_ETHPORTS) {
490 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
493 dev = &rte_eth_devices[port_id];
495 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
496 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
498 if (dev->data->dev_started) {
500 "port %d must be stopped to allow configuration\n", port_id);
505 * Check that the numbers of RX and TX queues are not greater
506 * than the maximum number of RX and TX queues supported by the
509 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
510 if (nb_rx_q > dev_info.max_rx_queues) {
511 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
512 port_id, nb_rx_q, dev_info.max_rx_queues);
516 PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_q == 0\n", port_id);
520 if (nb_tx_q > dev_info.max_tx_queues) {
521 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
522 port_id, nb_tx_q, dev_info.max_tx_queues);
526 PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_q == 0\n", port_id);
530 /* Copy the dev_conf parameter into the dev structure */
531 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
534 * If jumbo frames are enabled, check that the maximum RX packet
535 * length is supported by the configured device.
537 if (dev_conf->rxmode.jumbo_frame == 1) {
538 if (dev_conf->rxmode.max_rx_pkt_len >
539 dev_info.max_rx_pktlen) {
540 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
541 " > max valid value %u\n",
543 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
544 (unsigned)dev_info.max_rx_pktlen);
547 else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
548 PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
549 " < min valid value %u\n",
551 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
552 (unsigned)ETHER_MIN_LEN);
556 /* Use default value */
557 dev->data->dev_conf.rxmode.max_rx_pkt_len = ETHER_MAX_LEN;
559 /* multipe queue mode checking */
560 diag = rte_eth_dev_check_mq_mode(port_id, nb_rx_q, nb_tx_q, dev_conf);
562 PMD_DEBUG_TRACE("port%d rte_eth_dev_check_mq_mode = %d\n",
568 * Setup new number of RX/TX queues and reconfigure device.
570 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
572 PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
577 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
579 PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
581 rte_eth_dev_rx_queue_config(dev, 0);
585 diag = (*dev->dev_ops->dev_configure)(dev);
587 PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
589 rte_eth_dev_rx_queue_config(dev, 0);
590 rte_eth_dev_tx_queue_config(dev, 0);
598 rte_eth_dev_config_restore(uint8_t port_id)
600 struct rte_eth_dev *dev;
601 struct rte_eth_dev_info dev_info;
602 struct ether_addr addr;
606 dev = &rte_eth_devices[port_id];
608 rte_eth_dev_info_get(port_id, &dev_info);
610 if (RTE_ETH_DEV_SRIOV(dev).active)
611 pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
613 /* replay MAC address configuration */
614 for (i = 0; i < dev_info.max_mac_addrs; i++) {
615 addr = dev->data->mac_addrs[i];
617 /* skip zero address */
618 if (is_zero_ether_addr(&addr))
621 /* add address to the hardware */
622 if (*dev->dev_ops->mac_addr_add)
623 (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
625 PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
627 /* exit the loop but not return an error */
632 /* replay promiscuous configuration */
633 if (rte_eth_promiscuous_get(port_id) == 1)
634 rte_eth_promiscuous_enable(port_id);
635 else if (rte_eth_promiscuous_get(port_id) == 0)
636 rte_eth_promiscuous_disable(port_id);
638 /* replay allmulticast configuration */
639 if (rte_eth_allmulticast_get(port_id) == 1)
640 rte_eth_allmulticast_enable(port_id);
641 else if (rte_eth_allmulticast_get(port_id) == 0)
642 rte_eth_allmulticast_disable(port_id);
646 rte_eth_dev_start(uint8_t port_id)
648 struct rte_eth_dev *dev;
651 /* This function is only safe when called from the primary process
652 * in a multi-process setup*/
653 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
655 if (port_id >= nb_ports) {
656 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
659 dev = &rte_eth_devices[port_id];
661 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
662 diag = (*dev->dev_ops->dev_start)(dev);
664 dev->data->dev_started = 1;
668 rte_eth_dev_config_restore(port_id);
674 rte_eth_dev_stop(uint8_t port_id)
676 struct rte_eth_dev *dev;
678 /* This function is only safe when called from the primary process
679 * in a multi-process setup*/
680 PROC_PRIMARY_OR_RET();
682 if (port_id >= nb_ports) {
683 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
686 dev = &rte_eth_devices[port_id];
688 FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
689 dev->data->dev_started = 0;
690 (*dev->dev_ops->dev_stop)(dev);
694 rte_eth_dev_close(uint8_t port_id)
696 struct rte_eth_dev *dev;
698 /* This function is only safe when called from the primary process
699 * in a multi-process setup*/
700 PROC_PRIMARY_OR_RET();
702 if (port_id >= nb_ports) {
703 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
707 dev = &rte_eth_devices[port_id];
709 FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
710 dev->data->dev_started = 0;
711 (*dev->dev_ops->dev_close)(dev);
715 rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
716 uint16_t nb_rx_desc, unsigned int socket_id,
717 const struct rte_eth_rxconf *rx_conf,
718 struct rte_mempool *mp)
720 struct rte_eth_dev *dev;
721 struct rte_pktmbuf_pool_private *mbp_priv;
722 struct rte_eth_dev_info dev_info;
724 /* This function is only safe when called from the primary process
725 * in a multi-process setup*/
726 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
728 if (port_id >= nb_ports) {
729 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
732 dev = &rte_eth_devices[port_id];
733 if (rx_queue_id >= dev->data->nb_rx_queues) {
734 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
738 if (dev->data->dev_started) {
740 "port %d must be stopped to allow configuration\n", port_id);
744 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
745 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
748 * Check the size of the mbuf data buffer.
749 * This value must be provided in the private data of the memory pool.
750 * First check that the memory pool has a valid private data.
752 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
753 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
754 PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
755 mp->name, (int) mp->private_data_size,
756 (int) sizeof(struct rte_pktmbuf_pool_private));
759 mbp_priv = (struct rte_pktmbuf_pool_private *)
760 ((char *)mp + sizeof(struct rte_mempool));
761 if ((uint32_t) (mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM) <
762 dev_info.min_rx_bufsize) {
763 PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
764 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
767 (int)mbp_priv->mbuf_data_room_size,
768 (int)(RTE_PKTMBUF_HEADROOM +
769 dev_info.min_rx_bufsize),
770 (int)RTE_PKTMBUF_HEADROOM,
771 (int)dev_info.min_rx_bufsize);
775 return (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
776 socket_id, rx_conf, mp);
780 rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
781 uint16_t nb_tx_desc, unsigned int socket_id,
782 const struct rte_eth_txconf *tx_conf)
784 struct rte_eth_dev *dev;
786 /* This function is only safe when called from the primary process
787 * in a multi-process setup*/
788 PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
790 if (port_id >= RTE_MAX_ETHPORTS || port_id >= nb_ports) {
791 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
794 dev = &rte_eth_devices[port_id];
795 if (tx_queue_id >= dev->data->nb_tx_queues) {
796 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
800 if (dev->data->dev_started) {
802 "port %d must be stopped to allow configuration\n", port_id);
806 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
807 return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
812 rte_eth_promiscuous_enable(uint8_t port_id)
814 struct rte_eth_dev *dev;
816 if (port_id >= nb_ports) {
817 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
820 dev = &rte_eth_devices[port_id];
822 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
823 (*dev->dev_ops->promiscuous_enable)(dev);
824 dev->data->promiscuous = 1;
828 rte_eth_promiscuous_disable(uint8_t port_id)
830 struct rte_eth_dev *dev;
832 if (port_id >= nb_ports) {
833 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
836 dev = &rte_eth_devices[port_id];
838 FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
839 dev->data->promiscuous = 0;
840 (*dev->dev_ops->promiscuous_disable)(dev);
844 rte_eth_promiscuous_get(uint8_t port_id)
846 struct rte_eth_dev *dev;
848 if (port_id >= nb_ports) {
849 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
853 dev = &rte_eth_devices[port_id];
854 return dev->data->promiscuous;
858 rte_eth_allmulticast_enable(uint8_t port_id)
860 struct rte_eth_dev *dev;
862 if (port_id >= nb_ports) {
863 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
866 dev = &rte_eth_devices[port_id];
868 FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
869 (*dev->dev_ops->allmulticast_enable)(dev);
870 dev->data->all_multicast = 1;
874 rte_eth_allmulticast_disable(uint8_t port_id)
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->allmulticast_disable);
885 dev->data->all_multicast = 0;
886 (*dev->dev_ops->allmulticast_disable)(dev);
890 rte_eth_allmulticast_get(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);
899 dev = &rte_eth_devices[port_id];
900 return dev->data->all_multicast;
904 rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
905 struct rte_eth_link *link)
907 struct rte_eth_link *dst = link;
908 struct rte_eth_link *src = &(dev->data->dev_link);
910 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
911 *(uint64_t *)src) == 0)
918 rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
920 struct rte_eth_dev *dev;
922 if (port_id >= nb_ports) {
923 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
926 dev = &rte_eth_devices[port_id];
927 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
929 if (dev->data->dev_conf.intr_conf.lsc != 0)
930 rte_eth_dev_atomic_read_link_status(dev, eth_link);
932 (*dev->dev_ops->link_update)(dev, 1);
933 *eth_link = dev->data->dev_link;
938 rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
940 struct rte_eth_dev *dev;
942 if (port_id >= nb_ports) {
943 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
946 dev = &rte_eth_devices[port_id];
947 FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
949 if (dev->data->dev_conf.intr_conf.lsc != 0)
950 rte_eth_dev_atomic_read_link_status(dev, eth_link);
952 (*dev->dev_ops->link_update)(dev, 0);
953 *eth_link = dev->data->dev_link;
958 rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
960 struct rte_eth_dev *dev;
962 if (port_id >= nb_ports) {
963 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
966 dev = &rte_eth_devices[port_id];
968 FUNC_PTR_OR_RET(*dev->dev_ops->stats_get);
969 (*dev->dev_ops->stats_get)(dev, stats);
970 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
974 rte_eth_stats_reset(uint8_t port_id)
976 struct rte_eth_dev *dev;
978 if (port_id >= nb_ports) {
979 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
982 dev = &rte_eth_devices[port_id];
984 FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
985 (*dev->dev_ops->stats_reset)(dev);
990 set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
993 struct rte_eth_dev *dev;
995 if (port_id >= nb_ports) {
996 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
999 dev = &rte_eth_devices[port_id];
1001 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
1002 return (*dev->dev_ops->queue_stats_mapping_set)
1003 (dev, queue_id, stat_idx, is_rx);
1008 rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t tx_queue_id,
1011 return set_queue_stats_mapping(port_id, tx_queue_id, stat_idx,
1017 rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
1020 return set_queue_stats_mapping(port_id, rx_queue_id, stat_idx,
1026 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
1028 struct rte_eth_dev *dev;
1030 if (port_id >= nb_ports) {
1031 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1034 dev = &rte_eth_devices[port_id];
1036 FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
1037 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
1038 dev_info->pci_dev = dev->pci_dev;
1039 dev_info->driver_name = dev->driver->pci_drv.name;
1043 rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
1045 struct rte_eth_dev *dev;
1047 if (port_id >= nb_ports) {
1048 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1051 dev = &rte_eth_devices[port_id];
1052 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
1056 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
1058 struct rte_eth_dev *dev;
1060 if (port_id >= nb_ports) {
1061 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1064 dev = &rte_eth_devices[port_id];
1065 if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
1066 PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
1070 if (vlan_id > 4095) {
1071 PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
1072 port_id, (unsigned) vlan_id);
1075 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
1076 (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
1081 rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int on)
1083 struct rte_eth_dev *dev;
1085 if (port_id >= nb_ports) {
1086 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1090 dev = &rte_eth_devices[port_id];
1091 if (rx_queue_id >= dev->data->nb_rx_queues) {
1092 PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
1096 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
1097 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
1103 rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
1105 struct rte_eth_dev *dev;
1107 if (port_id >= nb_ports) {
1108 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1112 dev = &rte_eth_devices[port_id];
1113 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
1114 (*dev->dev_ops->vlan_tpid_set)(dev, tpid);
1120 rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
1122 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 /*check which option changed by application*/
1135 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
1136 org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
1138 dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
1139 mask |= ETH_VLAN_STRIP_MASK;
1142 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
1143 org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
1145 dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
1146 mask |= ETH_VLAN_FILTER_MASK;
1149 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
1150 org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
1152 dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
1153 mask |= ETH_VLAN_EXTEND_MASK;
1160 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
1161 (*dev->dev_ops->vlan_offload_set)(dev, mask);
1167 rte_eth_dev_get_vlan_offload(uint8_t port_id)
1169 struct rte_eth_dev *dev;
1172 if (port_id >= nb_ports) {
1173 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1177 dev = &rte_eth_devices[port_id];
1179 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1180 ret |= ETH_VLAN_STRIP_OFFLOAD ;
1182 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1183 ret |= ETH_VLAN_FILTER_OFFLOAD ;
1185 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1186 ret |= ETH_VLAN_EXTEND_OFFLOAD ;
1193 rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
1194 struct rte_fdir_filter *fdir_filter,
1197 struct rte_eth_dev *dev;
1199 if (port_id >= nb_ports) {
1200 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1204 dev = &rte_eth_devices[port_id];
1206 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1207 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1208 port_id, dev->data->dev_conf.fdir_conf.mode);
1212 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1213 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1214 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1215 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1216 "None l4type, source & destinations ports " \
1217 "should be null!\n");
1221 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
1222 return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
1227 rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
1228 struct rte_fdir_filter *fdir_filter,
1231 struct rte_eth_dev *dev;
1233 if (port_id >= nb_ports) {
1234 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1238 dev = &rte_eth_devices[port_id];
1240 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1241 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1242 port_id, dev->data->dev_conf.fdir_conf.mode);
1246 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1247 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1248 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1249 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1250 "None l4type, source & destinations ports " \
1251 "should be null!\n");
1255 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
1256 return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
1262 rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
1263 struct rte_fdir_filter *fdir_filter)
1265 struct rte_eth_dev *dev;
1267 if (port_id >= nb_ports) {
1268 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1272 dev = &rte_eth_devices[port_id];
1274 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
1275 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1276 port_id, dev->data->dev_conf.fdir_conf.mode);
1280 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1281 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1282 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1283 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1284 "None l4type source & destinations ports " \
1285 "should be null!\n");
1289 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
1290 return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
1294 rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
1296 struct rte_eth_dev *dev;
1298 if (port_id >= nb_ports) {
1299 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1303 dev = &rte_eth_devices[port_id];
1304 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1305 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1309 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
1311 (*dev->dev_ops->fdir_infos_get)(dev, fdir);
1316 rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
1317 struct rte_fdir_filter *fdir_filter,
1318 uint16_t soft_id, uint8_t queue,
1321 struct rte_eth_dev *dev;
1323 if (port_id >= nb_ports) {
1324 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1328 dev = &rte_eth_devices[port_id];
1330 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1331 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1332 port_id, dev->data->dev_conf.fdir_conf.mode);
1336 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1337 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1338 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1339 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1340 "None l4type, source & destinations ports " \
1341 "should be null!\n");
1345 /* For now IPv6 is not supported with perfect filter */
1346 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1349 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
1350 return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
1356 rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
1357 struct rte_fdir_filter *fdir_filter,
1358 uint16_t soft_id, uint8_t queue,
1361 struct rte_eth_dev *dev;
1363 if (port_id >= nb_ports) {
1364 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1368 dev = &rte_eth_devices[port_id];
1370 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1371 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1372 port_id, dev->data->dev_conf.fdir_conf.mode);
1376 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1377 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1378 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1379 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1380 "None l4type, source & destinations ports " \
1381 "should be null!\n");
1385 /* For now IPv6 is not supported with perfect filter */
1386 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1389 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
1390 return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
1391 soft_id, queue, drop);
1395 rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
1396 struct rte_fdir_filter *fdir_filter,
1399 struct rte_eth_dev *dev;
1401 if (port_id >= nb_ports) {
1402 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1406 dev = &rte_eth_devices[port_id];
1408 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1409 PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
1410 port_id, dev->data->dev_conf.fdir_conf.mode);
1414 if ((fdir_filter->l4type == RTE_FDIR_L4TYPE_SCTP
1415 || fdir_filter->l4type == RTE_FDIR_L4TYPE_NONE)
1416 && (fdir_filter->port_src || fdir_filter->port_dst)) {
1417 PMD_DEBUG_TRACE(" Port are meaningless for SCTP and " \
1418 "None l4type, source & destinations ports " \
1419 "should be null!\n");
1423 /* For now IPv6 is not supported with perfect filter */
1424 if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
1427 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
1428 return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
1433 rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
1435 struct rte_eth_dev *dev;
1437 if (port_id >= nb_ports) {
1438 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1442 dev = &rte_eth_devices[port_id];
1443 if (! (dev->data->dev_conf.fdir_conf.mode)) {
1444 PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
1448 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
1449 return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
1453 rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
1455 struct rte_eth_dev *dev;
1457 if (port_id >= nb_ports) {
1458 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1462 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
1463 PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
1467 dev = &rte_eth_devices[port_id];
1468 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
1469 return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
1473 rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc_conf)
1475 struct rte_eth_dev *dev;
1477 if (port_id >= nb_ports) {
1478 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1482 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
1483 PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
1487 dev = &rte_eth_devices[port_id];
1488 /* High water, low water validation are device specific */
1489 if (*dev->dev_ops->priority_flow_ctrl_set)
1490 return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
1495 rte_eth_dev_rss_reta_update(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
1497 struct rte_eth_dev *dev;
1500 if (port_id >= nb_ports) {
1501 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1505 /* Invalid mask bit(s) setting */
1506 if ((reta_conf->mask_lo == 0) && (reta_conf->mask_hi == 0)) {
1507 PMD_DEBUG_TRACE("Invalid update mask bits for port=%d\n",port_id);
1511 if (reta_conf->mask_lo != 0) {
1512 for (i = 0; i < ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
1513 if ((reta_conf->mask_lo & (1ULL << i)) &&
1514 (reta_conf->reta[i] >= ETH_RSS_RETA_MAX_QUEUE)) {
1515 PMD_DEBUG_TRACE("RETA hash index output"
1516 "configration for port=%d,invalid"
1517 "queue=%d\n",port_id,reta_conf->reta[i]);
1524 if (reta_conf->mask_hi != 0) {
1525 for (i = 0; i< ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
1526 j = (uint8_t)(i + ETH_RSS_RETA_NUM_ENTRIES/2);
1528 /* Check if the max entry >= 128 */
1529 if ((reta_conf->mask_hi & (1ULL << i)) &&
1530 (reta_conf->reta[j] >= ETH_RSS_RETA_MAX_QUEUE)) {
1531 PMD_DEBUG_TRACE("RETA hash index output"
1532 "configration for port=%d,invalid"
1533 "queue=%d\n",port_id,reta_conf->reta[j]);
1540 dev = &rte_eth_devices[port_id];
1542 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
1543 return (*dev->dev_ops->reta_update)(dev, reta_conf);
1547 rte_eth_dev_rss_reta_query(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
1549 struct rte_eth_dev *dev;
1551 if (port_id >= nb_ports) {
1552 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1556 if((reta_conf->mask_lo == 0) && (reta_conf->mask_hi == 0)) {
1557 PMD_DEBUG_TRACE("Invalid update mask bits for the port=%d\n",port_id);
1561 dev = &rte_eth_devices[port_id];
1562 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
1563 return (*dev->dev_ops->reta_query)(dev, reta_conf);
1567 rte_eth_led_on(uint8_t port_id)
1569 struct rte_eth_dev *dev;
1571 if (port_id >= nb_ports) {
1572 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1576 dev = &rte_eth_devices[port_id];
1577 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
1578 return ((*dev->dev_ops->dev_led_on)(dev));
1582 rte_eth_led_off(uint8_t port_id)
1584 struct rte_eth_dev *dev;
1586 if (port_id >= nb_ports) {
1587 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1591 dev = &rte_eth_devices[port_id];
1592 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
1593 return ((*dev->dev_ops->dev_led_off)(dev));
1597 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
1601 get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
1603 struct rte_eth_dev_info dev_info;
1604 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1607 rte_eth_dev_info_get(port_id, &dev_info);
1609 for (i = 0; i < dev_info.max_mac_addrs; i++)
1610 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
1616 static struct ether_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
1619 rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
1622 struct rte_eth_dev *dev;
1625 if (port_id >= nb_ports) {
1626 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1629 dev = &rte_eth_devices[port_id];
1630 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
1632 if (is_zero_ether_addr(addr)) {
1633 PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n", port_id);
1637 /* Check if it's already there, and do nothing */
1638 index = get_mac_addr_index(port_id, addr);
1642 index = get_mac_addr_index(port_id, &null_mac_addr);
1644 PMD_DEBUG_TRACE("port %d: MAC address array full\n", port_id);
1649 (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
1651 /* Update address in NIC data structure */
1652 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
1658 rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
1660 struct rte_eth_dev *dev;
1663 if (port_id >= nb_ports) {
1664 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1667 dev = &rte_eth_devices[port_id];
1668 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
1670 index = get_mac_addr_index(port_id, addr);
1672 PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
1673 return (-EADDRINUSE);
1674 } else if (index < 0)
1675 return 0; /* Do nothing if address wasn't found */
1678 (*dev->dev_ops->mac_addr_remove)(dev, index);
1680 /* Update address in NIC data structure */
1681 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
1686 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
1688 rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
1689 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
1691 struct rte_eth_dev *dev;
1693 if (port_id >= nb_ports) {
1694 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1697 dev = &rte_eth_devices[port_id];
1698 FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, -ENOTSUP);
1699 if (queue_id >= dev->data->nb_rx_queues) {
1700 PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
1703 return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
1708 rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
1709 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1711 struct rte_eth_dev *dev;
1713 if (port_id >= nb_ports) {
1714 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1717 dev = &rte_eth_devices[port_id];
1719 FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, -ENOTSUP);
1720 if (queue_id >= dev->data->nb_tx_queues) {
1721 PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
1724 return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
1729 rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
1731 struct rte_eth_dev *dev;
1733 if (port_id >= nb_ports) {
1734 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1737 dev = &rte_eth_devices[port_id];
1738 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, -ENOTSUP);
1739 return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
1743 rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
1745 struct rte_eth_dev *dev;
1747 if (port_id >= nb_ports) {
1748 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1751 dev = &rte_eth_devices[port_id];
1752 FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
1753 return (*dev->dev_ops->rx_descriptor_done)( \
1754 dev->data->rx_queues[queue_id], offset);
1759 rte_eth_dev_callback_register(uint8_t port_id,
1760 enum rte_eth_event_type event,
1761 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
1763 struct rte_eth_dev *dev;
1764 struct rte_eth_dev_callback *user_cb;
1768 if (port_id >= nb_ports) {
1769 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1773 dev = &rte_eth_devices[port_id];
1774 rte_spinlock_lock(&rte_eth_dev_cb_lock);
1776 TAILQ_FOREACH(user_cb, &(dev->callbacks), next) {
1777 if (user_cb->cb_fn == cb_fn &&
1778 user_cb->cb_arg == cb_arg &&
1779 user_cb->event == event) {
1784 /* create a new callback. */
1785 if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
1786 sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
1787 user_cb->cb_fn = cb_fn;
1788 user_cb->cb_arg = cb_arg;
1789 user_cb->event = event;
1790 TAILQ_INSERT_TAIL(&(dev->callbacks), user_cb, next);
1793 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
1794 return ((user_cb == NULL) ? -ENOMEM : 0);
1798 rte_eth_dev_callback_unregister(uint8_t port_id,
1799 enum rte_eth_event_type event,
1800 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
1803 struct rte_eth_dev *dev;
1804 struct rte_eth_dev_callback *cb, *next;
1808 if (port_id >= nb_ports) {
1809 PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
1813 dev = &rte_eth_devices[port_id];
1814 rte_spinlock_lock(&rte_eth_dev_cb_lock);
1817 for (cb = TAILQ_FIRST(&dev->callbacks); cb != NULL; cb = next) {
1819 next = TAILQ_NEXT(cb, next);
1821 if (cb->cb_fn != cb_fn || cb->event != event ||
1822 (cb->cb_arg != (void *)-1 &&
1823 cb->cb_arg != cb_arg))
1827 * if this callback is not executing right now,
1830 if (cb->active == 0) {
1831 TAILQ_REMOVE(&(dev->callbacks), cb, next);
1838 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
1843 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
1844 enum rte_eth_event_type event)
1846 struct rte_eth_dev_callback *cb_lst;
1847 struct rte_eth_dev_callback dev_cb;
1849 rte_spinlock_lock(&rte_eth_dev_cb_lock);
1850 TAILQ_FOREACH(cb_lst, &(dev->callbacks), next) {
1851 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
1855 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
1856 dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
1858 rte_spinlock_lock(&rte_eth_dev_cb_lock);
1861 rte_spinlock_unlock(&rte_eth_dev_cb_lock);