1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2017 Intel Corporation
15 #include <netinet/in.h>
17 #include <rte_byteorder.h>
19 #include <rte_debug.h>
20 #include <rte_interrupts.h>
21 #include <rte_memory.h>
22 #include <rte_memcpy.h>
23 #include <rte_memzone.h>
24 #include <rte_launch.h>
26 #include <rte_per_lcore.h>
27 #include <rte_lcore.h>
28 #include <rte_atomic.h>
29 #include <rte_branch_prediction.h>
30 #include <rte_common.h>
31 #include <rte_mempool.h>
32 #include <rte_malloc.h>
34 #include <rte_errno.h>
35 #include <rte_spinlock.h>
36 #include <rte_string_fns.h>
38 #include "rte_ether.h"
39 #include "rte_ethdev.h"
40 #include "rte_ethdev_driver.h"
41 #include "ethdev_profile.h"
43 static int ethdev_logtype;
45 #define ethdev_log(level, fmt, ...) \
46 rte_log(RTE_LOG_ ## level, ethdev_logtype, fmt "\n", ## __VA_ARGS__)
48 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
49 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
50 static uint8_t eth_dev_last_created_port;
52 /* spinlock for eth device callbacks */
53 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
55 /* spinlock for add/remove rx callbacks */
56 static rte_spinlock_t rte_eth_rx_cb_lock = RTE_SPINLOCK_INITIALIZER;
58 /* spinlock for add/remove tx callbacks */
59 static rte_spinlock_t rte_eth_tx_cb_lock = RTE_SPINLOCK_INITIALIZER;
61 /* spinlock for shared data allocation */
62 static rte_spinlock_t rte_eth_shared_data_lock = RTE_SPINLOCK_INITIALIZER;
64 /* store statistics names and its offset in stats structure */
65 struct rte_eth_xstats_name_off {
66 char name[RTE_ETH_XSTATS_NAME_SIZE];
70 /* Shared memory between primary and secondary processes. */
72 uint64_t next_owner_id;
73 rte_spinlock_t ownership_lock;
74 struct rte_eth_dev_data data[RTE_MAX_ETHPORTS];
75 } *rte_eth_dev_shared_data;
77 static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
78 {"rx_good_packets", offsetof(struct rte_eth_stats, ipackets)},
79 {"tx_good_packets", offsetof(struct rte_eth_stats, opackets)},
80 {"rx_good_bytes", offsetof(struct rte_eth_stats, ibytes)},
81 {"tx_good_bytes", offsetof(struct rte_eth_stats, obytes)},
82 {"rx_missed_errors", offsetof(struct rte_eth_stats, imissed)},
83 {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
84 {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
85 {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats,
89 #define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
91 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
92 {"packets", offsetof(struct rte_eth_stats, q_ipackets)},
93 {"bytes", offsetof(struct rte_eth_stats, q_ibytes)},
94 {"errors", offsetof(struct rte_eth_stats, q_errors)},
97 #define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) / \
98 sizeof(rte_rxq_stats_strings[0]))
100 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
101 {"packets", offsetof(struct rte_eth_stats, q_opackets)},
102 {"bytes", offsetof(struct rte_eth_stats, q_obytes)},
104 #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) / \
105 sizeof(rte_txq_stats_strings[0]))
107 #define RTE_RX_OFFLOAD_BIT2STR(_name) \
108 { DEV_RX_OFFLOAD_##_name, #_name }
110 static const struct {
113 } rte_rx_offload_names[] = {
114 RTE_RX_OFFLOAD_BIT2STR(VLAN_STRIP),
115 RTE_RX_OFFLOAD_BIT2STR(IPV4_CKSUM),
116 RTE_RX_OFFLOAD_BIT2STR(UDP_CKSUM),
117 RTE_RX_OFFLOAD_BIT2STR(TCP_CKSUM),
118 RTE_RX_OFFLOAD_BIT2STR(TCP_LRO),
119 RTE_RX_OFFLOAD_BIT2STR(QINQ_STRIP),
120 RTE_RX_OFFLOAD_BIT2STR(OUTER_IPV4_CKSUM),
121 RTE_RX_OFFLOAD_BIT2STR(MACSEC_STRIP),
122 RTE_RX_OFFLOAD_BIT2STR(HEADER_SPLIT),
123 RTE_RX_OFFLOAD_BIT2STR(VLAN_FILTER),
124 RTE_RX_OFFLOAD_BIT2STR(VLAN_EXTEND),
125 RTE_RX_OFFLOAD_BIT2STR(JUMBO_FRAME),
126 RTE_RX_OFFLOAD_BIT2STR(CRC_STRIP),
127 RTE_RX_OFFLOAD_BIT2STR(SCATTER),
128 RTE_RX_OFFLOAD_BIT2STR(TIMESTAMP),
129 RTE_RX_OFFLOAD_BIT2STR(SECURITY),
132 #undef RTE_RX_OFFLOAD_BIT2STR
134 #define RTE_TX_OFFLOAD_BIT2STR(_name) \
135 { DEV_TX_OFFLOAD_##_name, #_name }
137 static const struct {
140 } rte_tx_offload_names[] = {
141 RTE_TX_OFFLOAD_BIT2STR(VLAN_INSERT),
142 RTE_TX_OFFLOAD_BIT2STR(IPV4_CKSUM),
143 RTE_TX_OFFLOAD_BIT2STR(UDP_CKSUM),
144 RTE_TX_OFFLOAD_BIT2STR(TCP_CKSUM),
145 RTE_TX_OFFLOAD_BIT2STR(SCTP_CKSUM),
146 RTE_TX_OFFLOAD_BIT2STR(TCP_TSO),
147 RTE_TX_OFFLOAD_BIT2STR(UDP_TSO),
148 RTE_TX_OFFLOAD_BIT2STR(OUTER_IPV4_CKSUM),
149 RTE_TX_OFFLOAD_BIT2STR(QINQ_INSERT),
150 RTE_TX_OFFLOAD_BIT2STR(VXLAN_TNL_TSO),
151 RTE_TX_OFFLOAD_BIT2STR(GRE_TNL_TSO),
152 RTE_TX_OFFLOAD_BIT2STR(IPIP_TNL_TSO),
153 RTE_TX_OFFLOAD_BIT2STR(GENEVE_TNL_TSO),
154 RTE_TX_OFFLOAD_BIT2STR(MACSEC_INSERT),
155 RTE_TX_OFFLOAD_BIT2STR(MT_LOCKFREE),
156 RTE_TX_OFFLOAD_BIT2STR(MULTI_SEGS),
157 RTE_TX_OFFLOAD_BIT2STR(MBUF_FAST_FREE),
158 RTE_TX_OFFLOAD_BIT2STR(SECURITY),
161 #undef RTE_TX_OFFLOAD_BIT2STR
164 * The user application callback description.
166 * It contains callback address to be registered by user application,
167 * the pointer to the parameters for callback, and the event type.
169 struct rte_eth_dev_callback {
170 TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
171 rte_eth_dev_cb_fn cb_fn; /**< Callback address */
172 void *cb_arg; /**< Parameter for callback */
173 void *ret_param; /**< Return parameter */
174 enum rte_eth_event_type event; /**< Interrupt event type */
175 uint32_t active; /**< Callback is executing */
184 rte_eth_find_next(uint16_t port_id)
186 while (port_id < RTE_MAX_ETHPORTS &&
187 rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
188 rte_eth_devices[port_id].state != RTE_ETH_DEV_REMOVED)
191 if (port_id >= RTE_MAX_ETHPORTS)
192 return RTE_MAX_ETHPORTS;
198 rte_eth_dev_shared_data_prepare(void)
200 const unsigned flags = 0;
201 const struct rte_memzone *mz;
203 rte_spinlock_lock(&rte_eth_shared_data_lock);
205 if (rte_eth_dev_shared_data == NULL) {
206 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
207 /* Allocate port data and ownership shared memory. */
208 mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
209 sizeof(*rte_eth_dev_shared_data),
210 rte_socket_id(), flags);
212 mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
214 rte_panic("Cannot allocate ethdev shared data\n");
216 rte_eth_dev_shared_data = mz->addr;
217 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
218 rte_eth_dev_shared_data->next_owner_id =
219 RTE_ETH_DEV_NO_OWNER + 1;
220 rte_spinlock_init(&rte_eth_dev_shared_data->ownership_lock);
221 memset(rte_eth_dev_shared_data->data, 0,
222 sizeof(rte_eth_dev_shared_data->data));
226 rte_spinlock_unlock(&rte_eth_shared_data_lock);
230 rte_eth_dev_allocated(const char *name)
234 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
235 if ((rte_eth_devices[i].state == RTE_ETH_DEV_ATTACHED) &&
236 strcmp(rte_eth_devices[i].data->name, name) == 0)
237 return &rte_eth_devices[i];
243 rte_eth_dev_find_free_port(void)
247 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
248 /* Using shared name field to find a free port. */
249 if (rte_eth_dev_shared_data->data[i].name[0] == '\0') {
250 RTE_ASSERT(rte_eth_devices[i].state ==
255 return RTE_MAX_ETHPORTS;
258 static struct rte_eth_dev *
259 eth_dev_get(uint16_t port_id)
261 struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
263 eth_dev->data = &rte_eth_dev_shared_data->data[port_id];
264 eth_dev->state = RTE_ETH_DEV_ATTACHED;
266 eth_dev_last_created_port = port_id;
272 rte_eth_dev_allocate(const char *name)
275 struct rte_eth_dev *eth_dev = NULL;
277 rte_eth_dev_shared_data_prepare();
279 /* Synchronize port creation between primary and secondary threads. */
280 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
282 port_id = rte_eth_dev_find_free_port();
283 if (port_id == RTE_MAX_ETHPORTS) {
284 ethdev_log(ERR, "Reached maximum number of Ethernet ports");
288 if (rte_eth_dev_allocated(name) != NULL) {
290 "Ethernet Device with name %s already allocated!",
295 eth_dev = eth_dev_get(port_id);
296 snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
297 eth_dev->data->port_id = port_id;
298 eth_dev->data->mtu = ETHER_MTU;
301 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
304 _rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_NEW, NULL);
310 * Attach to a port already registered by the primary process, which
311 * makes sure that the same device would have the same port id both
312 * in the primary and secondary process.
315 rte_eth_dev_attach_secondary(const char *name)
318 struct rte_eth_dev *eth_dev = NULL;
320 rte_eth_dev_shared_data_prepare();
322 /* Synchronize port attachment to primary port creation and release. */
323 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
325 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
326 if (strcmp(rte_eth_dev_shared_data->data[i].name, name) == 0)
329 if (i == RTE_MAX_ETHPORTS) {
331 "device %s is not driven by the primary process\n",
334 eth_dev = eth_dev_get(i);
335 RTE_ASSERT(eth_dev->data->port_id == i);
338 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
343 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
348 rte_eth_dev_shared_data_prepare();
350 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
352 eth_dev->state = RTE_ETH_DEV_UNUSED;
354 memset(eth_dev->data, 0, sizeof(struct rte_eth_dev_data));
356 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
358 _rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_DESTROY, NULL);
364 rte_eth_dev_is_valid_port(uint16_t port_id)
366 if (port_id >= RTE_MAX_ETHPORTS ||
367 (rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED))
374 rte_eth_is_valid_owner_id(uint64_t owner_id)
376 if (owner_id == RTE_ETH_DEV_NO_OWNER ||
377 rte_eth_dev_shared_data->next_owner_id <= owner_id) {
378 RTE_PMD_DEBUG_TRACE("Invalid owner_id=%016lX.\n", owner_id);
384 uint64_t __rte_experimental
385 rte_eth_find_next_owned_by(uint16_t port_id, const uint64_t owner_id)
387 while (port_id < RTE_MAX_ETHPORTS &&
388 ((rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
389 rte_eth_devices[port_id].state != RTE_ETH_DEV_REMOVED) ||
390 rte_eth_devices[port_id].data->owner.id != owner_id))
393 if (port_id >= RTE_MAX_ETHPORTS)
394 return RTE_MAX_ETHPORTS;
399 int __rte_experimental
400 rte_eth_dev_owner_new(uint64_t *owner_id)
402 rte_eth_dev_shared_data_prepare();
404 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
406 *owner_id = rte_eth_dev_shared_data->next_owner_id++;
408 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
413 _rte_eth_dev_owner_set(const uint16_t port_id, const uint64_t old_owner_id,
414 const struct rte_eth_dev_owner *new_owner)
416 struct rte_eth_dev_owner *port_owner;
419 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
421 if (!rte_eth_is_valid_owner_id(new_owner->id) &&
422 !rte_eth_is_valid_owner_id(old_owner_id))
425 port_owner = &rte_eth_devices[port_id].data->owner;
426 if (port_owner->id != old_owner_id) {
427 RTE_PMD_DEBUG_TRACE("Cannot set owner to port %d already owned"
428 " by %s_%016lX.\n", port_id,
429 port_owner->name, port_owner->id);
433 sret = snprintf(port_owner->name, RTE_ETH_MAX_OWNER_NAME_LEN, "%s",
435 if (sret < 0 || sret >= RTE_ETH_MAX_OWNER_NAME_LEN)
436 RTE_PMD_DEBUG_TRACE("Port %d owner name was truncated.\n",
439 port_owner->id = new_owner->id;
441 RTE_PMD_DEBUG_TRACE("Port %d owner is %s_%016lX.\n", port_id,
442 new_owner->name, new_owner->id);
447 int __rte_experimental
448 rte_eth_dev_owner_set(const uint16_t port_id,
449 const struct rte_eth_dev_owner *owner)
453 rte_eth_dev_shared_data_prepare();
455 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
457 ret = _rte_eth_dev_owner_set(port_id, RTE_ETH_DEV_NO_OWNER, owner);
459 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
463 int __rte_experimental
464 rte_eth_dev_owner_unset(const uint16_t port_id, const uint64_t owner_id)
466 const struct rte_eth_dev_owner new_owner = (struct rte_eth_dev_owner)
467 {.id = RTE_ETH_DEV_NO_OWNER, .name = ""};
470 rte_eth_dev_shared_data_prepare();
472 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
474 ret = _rte_eth_dev_owner_set(port_id, owner_id, &new_owner);
476 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
480 void __rte_experimental
481 rte_eth_dev_owner_delete(const uint64_t owner_id)
485 rte_eth_dev_shared_data_prepare();
487 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
489 if (rte_eth_is_valid_owner_id(owner_id)) {
490 RTE_ETH_FOREACH_DEV_OWNED_BY(port_id, owner_id)
491 memset(&rte_eth_devices[port_id].data->owner, 0,
492 sizeof(struct rte_eth_dev_owner));
493 RTE_PMD_DEBUG_TRACE("All port owners owned by %016X identifier"
494 " have removed.\n", owner_id);
497 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
500 int __rte_experimental
501 rte_eth_dev_owner_get(const uint16_t port_id, struct rte_eth_dev_owner *owner)
505 rte_eth_dev_shared_data_prepare();
507 rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
509 if (!rte_eth_dev_is_valid_port(port_id)) {
510 RTE_PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
513 rte_memcpy(owner, &rte_eth_devices[port_id].data->owner,
517 rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
522 rte_eth_dev_socket_id(uint16_t port_id)
524 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
525 return rte_eth_devices[port_id].data->numa_node;
529 rte_eth_dev_get_sec_ctx(uint16_t port_id)
531 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, NULL);
532 return rte_eth_devices[port_id].security_ctx;
536 rte_eth_dev_count(void)
543 RTE_ETH_FOREACH_DEV(p)
550 rte_eth_dev_get_name_by_port(uint16_t port_id, char *name)
554 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
557 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
561 /* shouldn't check 'rte_eth_devices[i].data',
562 * because it might be overwritten by VDEV PMD */
563 tmp = rte_eth_dev_shared_data->data[port_id].name;
569 rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
574 RTE_PMD_DEBUG_TRACE("Null pointer is specified\n");
578 for (pid = 0; pid < RTE_MAX_ETHPORTS; pid++) {
579 if (rte_eth_devices[pid].state != RTE_ETH_DEV_UNUSED &&
580 !strcmp(name, rte_eth_dev_shared_data->data[pid].name)) {
590 eth_err(uint16_t port_id, int ret)
594 if (rte_eth_dev_is_removed(port_id))
599 /* attach the new device, then store port_id of the device */
601 rte_eth_dev_attach(const char *devargs, uint16_t *port_id)
604 int current = rte_eth_dev_count();
608 if ((devargs == NULL) || (port_id == NULL)) {
613 /* parse devargs, then retrieve device name and args */
614 if (rte_eal_parse_devargs_str(devargs, &name, &args))
617 ret = rte_eal_dev_attach(name, args);
621 /* no point looking at the port count if no port exists */
622 if (!rte_eth_dev_count()) {
623 ethdev_log(ERR, "No port found for device (%s)", name);
628 /* if nothing happened, there is a bug here, since some driver told us
629 * it did attach a device, but did not create a port.
631 if (current == rte_eth_dev_count()) {
636 *port_id = eth_dev_last_created_port;
645 /* detach the device, then store the name of the device */
647 rte_eth_dev_detach(uint16_t port_id, char *name)
652 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
659 dev_flags = rte_eth_devices[port_id].data->dev_flags;
660 if (dev_flags & RTE_ETH_DEV_BONDED_SLAVE) {
662 "Port %" PRIu16 " is bonded, cannot detach", port_id);
667 snprintf(name, sizeof(rte_eth_devices[port_id].data->name),
668 "%s", rte_eth_devices[port_id].data->name);
670 ret = rte_eal_dev_detach(rte_eth_devices[port_id].device);
674 rte_eth_dev_release_port(&rte_eth_devices[port_id]);
682 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
684 uint16_t old_nb_queues = dev->data->nb_rx_queues;
688 if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */
689 dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
690 sizeof(dev->data->rx_queues[0]) * nb_queues,
691 RTE_CACHE_LINE_SIZE);
692 if (dev->data->rx_queues == NULL) {
693 dev->data->nb_rx_queues = 0;
696 } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */
697 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
699 rxq = dev->data->rx_queues;
701 for (i = nb_queues; i < old_nb_queues; i++)
702 (*dev->dev_ops->rx_queue_release)(rxq[i]);
703 rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
704 RTE_CACHE_LINE_SIZE);
707 if (nb_queues > old_nb_queues) {
708 uint16_t new_qs = nb_queues - old_nb_queues;
710 memset(rxq + old_nb_queues, 0,
711 sizeof(rxq[0]) * new_qs);
714 dev->data->rx_queues = rxq;
716 } else if (dev->data->rx_queues != NULL && nb_queues == 0) {
717 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
719 rxq = dev->data->rx_queues;
721 for (i = nb_queues; i < old_nb_queues; i++)
722 (*dev->dev_ops->rx_queue_release)(rxq[i]);
724 rte_free(dev->data->rx_queues);
725 dev->data->rx_queues = NULL;
727 dev->data->nb_rx_queues = nb_queues;
732 rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id)
734 struct rte_eth_dev *dev;
736 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
738 dev = &rte_eth_devices[port_id];
739 if (!dev->data->dev_started) {
741 "port %d must be started before start any queue\n", port_id);
745 if (rx_queue_id >= dev->data->nb_rx_queues) {
746 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
750 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
752 if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
753 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
754 " already started\n",
755 rx_queue_id, port_id);
759 return eth_err(port_id, dev->dev_ops->rx_queue_start(dev,
765 rte_eth_dev_rx_queue_stop(uint16_t port_id, uint16_t rx_queue_id)
767 struct rte_eth_dev *dev;
769 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
771 dev = &rte_eth_devices[port_id];
772 if (rx_queue_id >= dev->data->nb_rx_queues) {
773 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
777 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
779 if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
780 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
781 " already stopped\n",
782 rx_queue_id, port_id);
786 return eth_err(port_id, dev->dev_ops->rx_queue_stop(dev, rx_queue_id));
791 rte_eth_dev_tx_queue_start(uint16_t port_id, uint16_t tx_queue_id)
793 struct rte_eth_dev *dev;
795 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
797 dev = &rte_eth_devices[port_id];
798 if (!dev->data->dev_started) {
800 "port %d must be started before start any queue\n", port_id);
804 if (tx_queue_id >= dev->data->nb_tx_queues) {
805 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
809 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
811 if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
812 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
813 " already started\n",
814 tx_queue_id, port_id);
818 return eth_err(port_id, dev->dev_ops->tx_queue_start(dev,
824 rte_eth_dev_tx_queue_stop(uint16_t port_id, uint16_t tx_queue_id)
826 struct rte_eth_dev *dev;
828 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
830 dev = &rte_eth_devices[port_id];
831 if (tx_queue_id >= dev->data->nb_tx_queues) {
832 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
836 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
838 if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
839 RTE_PMD_DEBUG_TRACE("Queue %" PRIu16" of device with port_id=%" PRIu8
840 " already stopped\n",
841 tx_queue_id, port_id);
845 return eth_err(port_id, dev->dev_ops->tx_queue_stop(dev, tx_queue_id));
850 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
852 uint16_t old_nb_queues = dev->data->nb_tx_queues;
856 if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */
857 dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
858 sizeof(dev->data->tx_queues[0]) * nb_queues,
859 RTE_CACHE_LINE_SIZE);
860 if (dev->data->tx_queues == NULL) {
861 dev->data->nb_tx_queues = 0;
864 } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */
865 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
867 txq = dev->data->tx_queues;
869 for (i = nb_queues; i < old_nb_queues; i++)
870 (*dev->dev_ops->tx_queue_release)(txq[i]);
871 txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
872 RTE_CACHE_LINE_SIZE);
875 if (nb_queues > old_nb_queues) {
876 uint16_t new_qs = nb_queues - old_nb_queues;
878 memset(txq + old_nb_queues, 0,
879 sizeof(txq[0]) * new_qs);
882 dev->data->tx_queues = txq;
884 } else if (dev->data->tx_queues != NULL && nb_queues == 0) {
885 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
887 txq = dev->data->tx_queues;
889 for (i = nb_queues; i < old_nb_queues; i++)
890 (*dev->dev_ops->tx_queue_release)(txq[i]);
892 rte_free(dev->data->tx_queues);
893 dev->data->tx_queues = NULL;
895 dev->data->nb_tx_queues = nb_queues;
900 rte_eth_speed_bitflag(uint32_t speed, int duplex)
903 case ETH_SPEED_NUM_10M:
904 return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD;
905 case ETH_SPEED_NUM_100M:
906 return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD;
907 case ETH_SPEED_NUM_1G:
908 return ETH_LINK_SPEED_1G;
909 case ETH_SPEED_NUM_2_5G:
910 return ETH_LINK_SPEED_2_5G;
911 case ETH_SPEED_NUM_5G:
912 return ETH_LINK_SPEED_5G;
913 case ETH_SPEED_NUM_10G:
914 return ETH_LINK_SPEED_10G;
915 case ETH_SPEED_NUM_20G:
916 return ETH_LINK_SPEED_20G;
917 case ETH_SPEED_NUM_25G:
918 return ETH_LINK_SPEED_25G;
919 case ETH_SPEED_NUM_40G:
920 return ETH_LINK_SPEED_40G;
921 case ETH_SPEED_NUM_50G:
922 return ETH_LINK_SPEED_50G;
923 case ETH_SPEED_NUM_56G:
924 return ETH_LINK_SPEED_56G;
925 case ETH_SPEED_NUM_100G:
926 return ETH_LINK_SPEED_100G;
933 * A conversion function from rxmode bitfield API.
936 rte_eth_convert_rx_offload_bitfield(const struct rte_eth_rxmode *rxmode,
937 uint64_t *rx_offloads)
939 uint64_t offloads = 0;
941 if (rxmode->header_split == 1)
942 offloads |= DEV_RX_OFFLOAD_HEADER_SPLIT;
943 if (rxmode->hw_ip_checksum == 1)
944 offloads |= DEV_RX_OFFLOAD_CHECKSUM;
945 if (rxmode->hw_vlan_filter == 1)
946 offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
947 if (rxmode->hw_vlan_strip == 1)
948 offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
949 if (rxmode->hw_vlan_extend == 1)
950 offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
951 if (rxmode->jumbo_frame == 1)
952 offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
953 if (rxmode->hw_strip_crc == 1)
954 offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
955 if (rxmode->enable_scatter == 1)
956 offloads |= DEV_RX_OFFLOAD_SCATTER;
957 if (rxmode->enable_lro == 1)
958 offloads |= DEV_RX_OFFLOAD_TCP_LRO;
959 if (rxmode->hw_timestamp == 1)
960 offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
961 if (rxmode->security == 1)
962 offloads |= DEV_RX_OFFLOAD_SECURITY;
964 *rx_offloads = offloads;
968 * A conversion function from rxmode offloads API.
971 rte_eth_convert_rx_offloads(const uint64_t rx_offloads,
972 struct rte_eth_rxmode *rxmode)
975 if (rx_offloads & DEV_RX_OFFLOAD_HEADER_SPLIT)
976 rxmode->header_split = 1;
978 rxmode->header_split = 0;
979 if (rx_offloads & DEV_RX_OFFLOAD_CHECKSUM)
980 rxmode->hw_ip_checksum = 1;
982 rxmode->hw_ip_checksum = 0;
983 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
984 rxmode->hw_vlan_filter = 1;
986 rxmode->hw_vlan_filter = 0;
987 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
988 rxmode->hw_vlan_strip = 1;
990 rxmode->hw_vlan_strip = 0;
991 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND)
992 rxmode->hw_vlan_extend = 1;
994 rxmode->hw_vlan_extend = 0;
995 if (rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME)
996 rxmode->jumbo_frame = 1;
998 rxmode->jumbo_frame = 0;
999 if (rx_offloads & DEV_RX_OFFLOAD_CRC_STRIP)
1000 rxmode->hw_strip_crc = 1;
1002 rxmode->hw_strip_crc = 0;
1003 if (rx_offloads & DEV_RX_OFFLOAD_SCATTER)
1004 rxmode->enable_scatter = 1;
1006 rxmode->enable_scatter = 0;
1007 if (rx_offloads & DEV_RX_OFFLOAD_TCP_LRO)
1008 rxmode->enable_lro = 1;
1010 rxmode->enable_lro = 0;
1011 if (rx_offloads & DEV_RX_OFFLOAD_TIMESTAMP)
1012 rxmode->hw_timestamp = 1;
1014 rxmode->hw_timestamp = 0;
1015 if (rx_offloads & DEV_RX_OFFLOAD_SECURITY)
1016 rxmode->security = 1;
1018 rxmode->security = 0;
1021 const char * __rte_experimental
1022 rte_eth_dev_rx_offload_name(uint64_t offload)
1024 const char *name = "UNKNOWN";
1027 for (i = 0; i < RTE_DIM(rte_rx_offload_names); ++i) {
1028 if (offload == rte_rx_offload_names[i].offload) {
1029 name = rte_rx_offload_names[i].name;
1037 const char * __rte_experimental
1038 rte_eth_dev_tx_offload_name(uint64_t offload)
1040 const char *name = "UNKNOWN";
1043 for (i = 0; i < RTE_DIM(rte_tx_offload_names); ++i) {
1044 if (offload == rte_tx_offload_names[i].offload) {
1045 name = rte_tx_offload_names[i].name;
1054 rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
1055 const struct rte_eth_conf *dev_conf)
1057 struct rte_eth_dev *dev;
1058 struct rte_eth_dev_info dev_info;
1059 struct rte_eth_conf local_conf = *dev_conf;
1062 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1064 if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
1065 RTE_PMD_DEBUG_TRACE(
1066 "Number of RX queues requested (%u) is greater than max supported(%d)\n",
1067 nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
1071 if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
1072 RTE_PMD_DEBUG_TRACE(
1073 "Number of TX queues requested (%u) is greater than max supported(%d)\n",
1074 nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
1078 dev = &rte_eth_devices[port_id];
1080 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1081 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
1083 if (dev->data->dev_started) {
1084 RTE_PMD_DEBUG_TRACE(
1085 "port %d must be stopped to allow configuration\n", port_id);
1090 * Convert between the offloads API to enable PMDs to support
1093 if (dev_conf->rxmode.ignore_offload_bitfield == 0) {
1094 rte_eth_convert_rx_offload_bitfield(
1095 &dev_conf->rxmode, &local_conf.rxmode.offloads);
1097 rte_eth_convert_rx_offloads(dev_conf->rxmode.offloads,
1098 &local_conf.rxmode);
1101 /* Copy the dev_conf parameter into the dev structure */
1102 memcpy(&dev->data->dev_conf, &local_conf, sizeof(dev->data->dev_conf));
1105 * Check that the numbers of RX and TX queues are not greater
1106 * than the maximum number of RX and TX queues supported by the
1107 * configured device.
1109 (*dev->dev_ops->dev_infos_get)(dev, &dev_info);
1111 if (nb_rx_q == 0 && nb_tx_q == 0) {
1112 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d both rx and tx queue cannot be 0\n", port_id);
1116 if (nb_rx_q > dev_info.max_rx_queues) {
1117 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
1118 port_id, nb_rx_q, dev_info.max_rx_queues);
1122 if (nb_tx_q > dev_info.max_tx_queues) {
1123 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
1124 port_id, nb_tx_q, dev_info.max_tx_queues);
1128 /* Check that the device supports requested interrupts */
1129 if ((dev_conf->intr_conf.lsc == 1) &&
1130 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
1131 RTE_PMD_DEBUG_TRACE("driver %s does not support lsc\n",
1132 dev->device->driver->name);
1135 if ((dev_conf->intr_conf.rmv == 1) &&
1136 (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_RMV))) {
1137 RTE_PMD_DEBUG_TRACE("driver %s does not support rmv\n",
1138 dev->device->driver->name);
1143 * If jumbo frames are enabled, check that the maximum RX packet
1144 * length is supported by the configured device.
1146 if (local_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
1147 if (dev_conf->rxmode.max_rx_pkt_len >
1148 dev_info.max_rx_pktlen) {
1149 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
1150 " > max valid value %u\n",
1152 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
1153 (unsigned)dev_info.max_rx_pktlen);
1155 } else if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN) {
1156 RTE_PMD_DEBUG_TRACE("ethdev port_id=%d max_rx_pkt_len %u"
1157 " < min valid value %u\n",
1159 (unsigned)dev_conf->rxmode.max_rx_pkt_len,
1160 (unsigned)ETHER_MIN_LEN);
1164 if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
1165 dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
1166 /* Use default value */
1167 dev->data->dev_conf.rxmode.max_rx_pkt_len =
1172 * Setup new number of RX/TX queues and reconfigure device.
1174 diag = rte_eth_dev_rx_queue_config(dev, nb_rx_q);
1176 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_rx_queue_config = %d\n",
1181 diag = rte_eth_dev_tx_queue_config(dev, nb_tx_q);
1183 RTE_PMD_DEBUG_TRACE("port%d rte_eth_dev_tx_queue_config = %d\n",
1185 rte_eth_dev_rx_queue_config(dev, 0);
1189 diag = (*dev->dev_ops->dev_configure)(dev);
1191 RTE_PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
1193 rte_eth_dev_rx_queue_config(dev, 0);
1194 rte_eth_dev_tx_queue_config(dev, 0);
1195 return eth_err(port_id, diag);
1198 /* Initialize Rx profiling if enabled at compilation time. */
1199 diag = __rte_eth_profile_rx_init(port_id, dev);
1201 RTE_PMD_DEBUG_TRACE("port%d __rte_eth_profile_rx_init = %d\n",
1203 rte_eth_dev_rx_queue_config(dev, 0);
1204 rte_eth_dev_tx_queue_config(dev, 0);
1205 return eth_err(port_id, diag);
1212 _rte_eth_dev_reset(struct rte_eth_dev *dev)
1214 if (dev->data->dev_started) {
1215 RTE_PMD_DEBUG_TRACE(
1216 "port %d must be stopped to allow reset\n",
1217 dev->data->port_id);
1221 rte_eth_dev_rx_queue_config(dev, 0);
1222 rte_eth_dev_tx_queue_config(dev, 0);
1224 memset(&dev->data->dev_conf, 0, sizeof(dev->data->dev_conf));
1228 rte_eth_dev_config_restore(uint16_t port_id)
1230 struct rte_eth_dev *dev;
1231 struct rte_eth_dev_info dev_info;
1232 struct ether_addr *addr;
1237 dev = &rte_eth_devices[port_id];
1239 rte_eth_dev_info_get(port_id, &dev_info);
1241 /* replay MAC address configuration including default MAC */
1242 addr = &dev->data->mac_addrs[0];
1243 if (*dev->dev_ops->mac_addr_set != NULL)
1244 (*dev->dev_ops->mac_addr_set)(dev, addr);
1245 else if (*dev->dev_ops->mac_addr_add != NULL)
1246 (*dev->dev_ops->mac_addr_add)(dev, addr, 0, pool);
1248 if (*dev->dev_ops->mac_addr_add != NULL) {
1249 for (i = 1; i < dev_info.max_mac_addrs; i++) {
1250 addr = &dev->data->mac_addrs[i];
1252 /* skip zero address */
1253 if (is_zero_ether_addr(addr))
1257 pool_mask = dev->data->mac_pool_sel[i];
1260 if (pool_mask & 1ULL)
1261 (*dev->dev_ops->mac_addr_add)(dev,
1265 } while (pool_mask);
1269 /* replay promiscuous configuration */
1270 if (rte_eth_promiscuous_get(port_id) == 1)
1271 rte_eth_promiscuous_enable(port_id);
1272 else if (rte_eth_promiscuous_get(port_id) == 0)
1273 rte_eth_promiscuous_disable(port_id);
1275 /* replay all multicast configuration */
1276 if (rte_eth_allmulticast_get(port_id) == 1)
1277 rte_eth_allmulticast_enable(port_id);
1278 else if (rte_eth_allmulticast_get(port_id) == 0)
1279 rte_eth_allmulticast_disable(port_id);
1283 rte_eth_dev_start(uint16_t port_id)
1285 struct rte_eth_dev *dev;
1288 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1290 dev = &rte_eth_devices[port_id];
1292 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1294 if (dev->data->dev_started != 0) {
1295 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu16
1296 " already started\n",
1301 diag = (*dev->dev_ops->dev_start)(dev);
1303 dev->data->dev_started = 1;
1305 return eth_err(port_id, diag);
1307 rte_eth_dev_config_restore(port_id);
1309 if (dev->data->dev_conf.intr_conf.lsc == 0) {
1310 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
1311 (*dev->dev_ops->link_update)(dev, 0);
1317 rte_eth_dev_stop(uint16_t port_id)
1319 struct rte_eth_dev *dev;
1321 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1322 dev = &rte_eth_devices[port_id];
1324 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1326 if (dev->data->dev_started == 0) {
1327 RTE_PMD_DEBUG_TRACE("Device with port_id=%" PRIu16
1328 " already stopped\n",
1333 dev->data->dev_started = 0;
1334 (*dev->dev_ops->dev_stop)(dev);
1338 rte_eth_dev_set_link_up(uint16_t port_id)
1340 struct rte_eth_dev *dev;
1342 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1344 dev = &rte_eth_devices[port_id];
1346 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
1347 return eth_err(port_id, (*dev->dev_ops->dev_set_link_up)(dev));
1351 rte_eth_dev_set_link_down(uint16_t port_id)
1353 struct rte_eth_dev *dev;
1355 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1357 dev = &rte_eth_devices[port_id];
1359 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
1360 return eth_err(port_id, (*dev->dev_ops->dev_set_link_down)(dev));
1364 rte_eth_dev_close(uint16_t port_id)
1366 struct rte_eth_dev *dev;
1368 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1369 dev = &rte_eth_devices[port_id];
1371 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
1372 dev->data->dev_started = 0;
1373 (*dev->dev_ops->dev_close)(dev);
1375 dev->data->nb_rx_queues = 0;
1376 rte_free(dev->data->rx_queues);
1377 dev->data->rx_queues = NULL;
1378 dev->data->nb_tx_queues = 0;
1379 rte_free(dev->data->tx_queues);
1380 dev->data->tx_queues = NULL;
1384 rte_eth_dev_reset(uint16_t port_id)
1386 struct rte_eth_dev *dev;
1389 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1390 dev = &rte_eth_devices[port_id];
1392 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_reset, -ENOTSUP);
1394 rte_eth_dev_stop(port_id);
1395 ret = dev->dev_ops->dev_reset(dev);
1397 return eth_err(port_id, ret);
1400 int __rte_experimental
1401 rte_eth_dev_is_removed(uint16_t port_id)
1403 struct rte_eth_dev *dev;
1406 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0);
1408 dev = &rte_eth_devices[port_id];
1410 if (dev->state == RTE_ETH_DEV_REMOVED)
1413 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->is_removed, 0);
1415 ret = dev->dev_ops->is_removed(dev);
1417 /* Device is physically removed. */
1418 dev->state = RTE_ETH_DEV_REMOVED;
1424 rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
1425 uint16_t nb_rx_desc, unsigned int socket_id,
1426 const struct rte_eth_rxconf *rx_conf,
1427 struct rte_mempool *mp)
1430 uint32_t mbp_buf_size;
1431 struct rte_eth_dev *dev;
1432 struct rte_eth_dev_info dev_info;
1433 struct rte_eth_rxconf local_conf;
1436 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1438 dev = &rte_eth_devices[port_id];
1439 if (rx_queue_id >= dev->data->nb_rx_queues) {
1440 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
1444 if (dev->data->dev_started) {
1445 RTE_PMD_DEBUG_TRACE(
1446 "port %d must be stopped to allow configuration\n", port_id);
1450 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1451 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
1454 * Check the size of the mbuf data buffer.
1455 * This value must be provided in the private data of the memory pool.
1456 * First check that the memory pool has a valid private data.
1458 rte_eth_dev_info_get(port_id, &dev_info);
1459 if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private)) {
1460 RTE_PMD_DEBUG_TRACE("%s private_data_size %d < %d\n",
1461 mp->name, (int) mp->private_data_size,
1462 (int) sizeof(struct rte_pktmbuf_pool_private));
1465 mbp_buf_size = rte_pktmbuf_data_room_size(mp);
1467 if ((mbp_buf_size - RTE_PKTMBUF_HEADROOM) < dev_info.min_rx_bufsize) {
1468 RTE_PMD_DEBUG_TRACE("%s mbuf_data_room_size %d < %d "
1469 "(RTE_PKTMBUF_HEADROOM=%d + min_rx_bufsize(dev)"
1473 (int)(RTE_PKTMBUF_HEADROOM +
1474 dev_info.min_rx_bufsize),
1475 (int)RTE_PKTMBUF_HEADROOM,
1476 (int)dev_info.min_rx_bufsize);
1480 if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
1481 nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
1482 nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
1484 RTE_PMD_DEBUG_TRACE("Invalid value for nb_rx_desc(=%hu), "
1485 "should be: <= %hu, = %hu, and a product of %hu\n",
1487 dev_info.rx_desc_lim.nb_max,
1488 dev_info.rx_desc_lim.nb_min,
1489 dev_info.rx_desc_lim.nb_align);
1493 rxq = dev->data->rx_queues;
1494 if (rxq[rx_queue_id]) {
1495 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release,
1497 (*dev->dev_ops->rx_queue_release)(rxq[rx_queue_id]);
1498 rxq[rx_queue_id] = NULL;
1501 if (rx_conf == NULL)
1502 rx_conf = &dev_info.default_rxconf;
1504 local_conf = *rx_conf;
1505 if (dev->data->dev_conf.rxmode.ignore_offload_bitfield == 0) {
1507 * Reflect port offloads to queue offloads in order for
1508 * offloads to not be discarded.
1510 rte_eth_convert_rx_offload_bitfield(&dev->data->dev_conf.rxmode,
1511 &local_conf.offloads);
1514 ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
1515 socket_id, &local_conf, mp);
1517 if (!dev->data->min_rx_buf_size ||
1518 dev->data->min_rx_buf_size > mbp_buf_size)
1519 dev->data->min_rx_buf_size = mbp_buf_size;
1522 return eth_err(port_id, ret);
1526 * A conversion function from txq_flags API.
1529 rte_eth_convert_txq_flags(const uint32_t txq_flags, uint64_t *tx_offloads)
1531 uint64_t offloads = 0;
1533 if (!(txq_flags & ETH_TXQ_FLAGS_NOMULTSEGS))
1534 offloads |= DEV_TX_OFFLOAD_MULTI_SEGS;
1535 if (!(txq_flags & ETH_TXQ_FLAGS_NOVLANOFFL))
1536 offloads |= DEV_TX_OFFLOAD_VLAN_INSERT;
1537 if (!(txq_flags & ETH_TXQ_FLAGS_NOXSUMSCTP))
1538 offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
1539 if (!(txq_flags & ETH_TXQ_FLAGS_NOXSUMUDP))
1540 offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
1541 if (!(txq_flags & ETH_TXQ_FLAGS_NOXSUMTCP))
1542 offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
1543 if ((txq_flags & ETH_TXQ_FLAGS_NOREFCOUNT) &&
1544 (txq_flags & ETH_TXQ_FLAGS_NOMULTMEMP))
1545 offloads |= DEV_TX_OFFLOAD_MBUF_FAST_FREE;
1547 *tx_offloads = offloads;
1551 * A conversion function from offloads API.
1554 rte_eth_convert_txq_offloads(const uint64_t tx_offloads, uint32_t *txq_flags)
1558 if (!(tx_offloads & DEV_TX_OFFLOAD_MULTI_SEGS))
1559 flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
1560 if (!(tx_offloads & DEV_TX_OFFLOAD_VLAN_INSERT))
1561 flags |= ETH_TXQ_FLAGS_NOVLANOFFL;
1562 if (!(tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM))
1563 flags |= ETH_TXQ_FLAGS_NOXSUMSCTP;
1564 if (!(tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM))
1565 flags |= ETH_TXQ_FLAGS_NOXSUMUDP;
1566 if (!(tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM))
1567 flags |= ETH_TXQ_FLAGS_NOXSUMTCP;
1568 if (tx_offloads & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
1569 flags |= (ETH_TXQ_FLAGS_NOREFCOUNT | ETH_TXQ_FLAGS_NOMULTMEMP);
1575 rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
1576 uint16_t nb_tx_desc, unsigned int socket_id,
1577 const struct rte_eth_txconf *tx_conf)
1579 struct rte_eth_dev *dev;
1580 struct rte_eth_dev_info dev_info;
1581 struct rte_eth_txconf local_conf;
1584 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1586 dev = &rte_eth_devices[port_id];
1587 if (tx_queue_id >= dev->data->nb_tx_queues) {
1588 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
1592 if (dev->data->dev_started) {
1593 RTE_PMD_DEBUG_TRACE(
1594 "port %d must be stopped to allow configuration\n", port_id);
1598 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
1599 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
1601 rte_eth_dev_info_get(port_id, &dev_info);
1603 if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
1604 nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
1605 nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
1606 RTE_PMD_DEBUG_TRACE("Invalid value for nb_tx_desc(=%hu), "
1607 "should be: <= %hu, = %hu, and a product of %hu\n",
1609 dev_info.tx_desc_lim.nb_max,
1610 dev_info.tx_desc_lim.nb_min,
1611 dev_info.tx_desc_lim.nb_align);
1615 txq = dev->data->tx_queues;
1616 if (txq[tx_queue_id]) {
1617 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release,
1619 (*dev->dev_ops->tx_queue_release)(txq[tx_queue_id]);
1620 txq[tx_queue_id] = NULL;
1623 if (tx_conf == NULL)
1624 tx_conf = &dev_info.default_txconf;
1627 * Convert between the offloads API to enable PMDs to support
1630 local_conf = *tx_conf;
1631 if (tx_conf->txq_flags & ETH_TXQ_FLAGS_IGNORE) {
1632 rte_eth_convert_txq_offloads(tx_conf->offloads,
1633 &local_conf.txq_flags);
1634 /* Keep the ignore flag. */
1635 local_conf.txq_flags |= ETH_TXQ_FLAGS_IGNORE;
1637 rte_eth_convert_txq_flags(tx_conf->txq_flags,
1638 &local_conf.offloads);
1641 return eth_err(port_id, (*dev->dev_ops->tx_queue_setup)(dev,
1642 tx_queue_id, nb_tx_desc, socket_id, &local_conf));
1646 rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
1647 void *userdata __rte_unused)
1651 for (i = 0; i < unsent; i++)
1652 rte_pktmbuf_free(pkts[i]);
1656 rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
1659 uint64_t *count = userdata;
1662 for (i = 0; i < unsent; i++)
1663 rte_pktmbuf_free(pkts[i]);
1669 rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
1670 buffer_tx_error_fn cbfn, void *userdata)
1672 buffer->error_callback = cbfn;
1673 buffer->error_userdata = userdata;
1678 rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
1685 buffer->size = size;
1686 if (buffer->error_callback == NULL) {
1687 ret = rte_eth_tx_buffer_set_err_callback(
1688 buffer, rte_eth_tx_buffer_drop_callback, NULL);
1695 rte_eth_tx_done_cleanup(uint16_t port_id, uint16_t queue_id, uint32_t free_cnt)
1697 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1700 /* Validate Input Data. Bail if not valid or not supported. */
1701 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1702 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_done_cleanup, -ENOTSUP);
1704 /* Call driver to free pending mbufs. */
1705 ret = (*dev->dev_ops->tx_done_cleanup)(dev->data->tx_queues[queue_id],
1707 return eth_err(port_id, ret);
1711 rte_eth_promiscuous_enable(uint16_t port_id)
1713 struct rte_eth_dev *dev;
1715 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1716 dev = &rte_eth_devices[port_id];
1718 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
1719 (*dev->dev_ops->promiscuous_enable)(dev);
1720 dev->data->promiscuous = 1;
1724 rte_eth_promiscuous_disable(uint16_t port_id)
1726 struct rte_eth_dev *dev;
1728 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1729 dev = &rte_eth_devices[port_id];
1731 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
1732 dev->data->promiscuous = 0;
1733 (*dev->dev_ops->promiscuous_disable)(dev);
1737 rte_eth_promiscuous_get(uint16_t port_id)
1739 struct rte_eth_dev *dev;
1741 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1743 dev = &rte_eth_devices[port_id];
1744 return dev->data->promiscuous;
1748 rte_eth_allmulticast_enable(uint16_t port_id)
1750 struct rte_eth_dev *dev;
1752 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1753 dev = &rte_eth_devices[port_id];
1755 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
1756 (*dev->dev_ops->allmulticast_enable)(dev);
1757 dev->data->all_multicast = 1;
1761 rte_eth_allmulticast_disable(uint16_t port_id)
1763 struct rte_eth_dev *dev;
1765 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1766 dev = &rte_eth_devices[port_id];
1768 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
1769 dev->data->all_multicast = 0;
1770 (*dev->dev_ops->allmulticast_disable)(dev);
1774 rte_eth_allmulticast_get(uint16_t port_id)
1776 struct rte_eth_dev *dev;
1778 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1780 dev = &rte_eth_devices[port_id];
1781 return dev->data->all_multicast;
1785 rte_eth_link_get(uint16_t port_id, struct rte_eth_link *eth_link)
1787 struct rte_eth_dev *dev;
1789 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1790 dev = &rte_eth_devices[port_id];
1792 if (dev->data->dev_conf.intr_conf.lsc)
1793 rte_eth_linkstatus_get(dev, eth_link);
1795 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1796 (*dev->dev_ops->link_update)(dev, 1);
1797 *eth_link = dev->data->dev_link;
1802 rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link)
1804 struct rte_eth_dev *dev;
1806 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1807 dev = &rte_eth_devices[port_id];
1809 if (dev->data->dev_conf.intr_conf.lsc)
1810 rte_eth_linkstatus_get(dev, eth_link);
1812 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
1813 (*dev->dev_ops->link_update)(dev, 0);
1814 *eth_link = dev->data->dev_link;
1819 rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats)
1821 struct rte_eth_dev *dev;
1823 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1825 dev = &rte_eth_devices[port_id];
1826 memset(stats, 0, sizeof(*stats));
1828 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
1829 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1830 return eth_err(port_id, (*dev->dev_ops->stats_get)(dev, stats));
1834 rte_eth_stats_reset(uint16_t port_id)
1836 struct rte_eth_dev *dev;
1838 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1839 dev = &rte_eth_devices[port_id];
1841 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_reset, -ENOTSUP);
1842 (*dev->dev_ops->stats_reset)(dev);
1843 dev->data->rx_mbuf_alloc_failed = 0;
1849 get_xstats_basic_count(struct rte_eth_dev *dev)
1851 uint16_t nb_rxqs, nb_txqs;
1854 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1855 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1857 count = RTE_NB_STATS;
1858 count += nb_rxqs * RTE_NB_RXQ_STATS;
1859 count += nb_txqs * RTE_NB_TXQ_STATS;
1865 get_xstats_count(uint16_t port_id)
1867 struct rte_eth_dev *dev;
1870 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
1871 dev = &rte_eth_devices[port_id];
1872 if (dev->dev_ops->xstats_get_names_by_id != NULL) {
1873 count = (*dev->dev_ops->xstats_get_names_by_id)(dev, NULL,
1876 return eth_err(port_id, count);
1878 if (dev->dev_ops->xstats_get_names != NULL) {
1879 count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0);
1881 return eth_err(port_id, count);
1886 count += get_xstats_basic_count(dev);
1892 rte_eth_xstats_get_id_by_name(uint16_t port_id, const char *xstat_name,
1895 int cnt_xstats, idx_xstat;
1897 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1900 RTE_PMD_DEBUG_TRACE("Error: id pointer is NULL\n");
1905 RTE_PMD_DEBUG_TRACE("Error: xstat_name pointer is NULL\n");
1910 cnt_xstats = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
1911 if (cnt_xstats < 0) {
1912 RTE_PMD_DEBUG_TRACE("Error: Cannot get count of xstats\n");
1916 /* Get id-name lookup table */
1917 struct rte_eth_xstat_name xstats_names[cnt_xstats];
1919 if (cnt_xstats != rte_eth_xstats_get_names_by_id(
1920 port_id, xstats_names, cnt_xstats, NULL)) {
1921 RTE_PMD_DEBUG_TRACE("Error: Cannot get xstats lookup\n");
1925 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
1926 if (!strcmp(xstats_names[idx_xstat].name, xstat_name)) {
1935 /* retrieve basic stats names */
1937 rte_eth_basic_stats_get_names(struct rte_eth_dev *dev,
1938 struct rte_eth_xstat_name *xstats_names)
1940 int cnt_used_entries = 0;
1941 uint32_t idx, id_queue;
1944 for (idx = 0; idx < RTE_NB_STATS; idx++) {
1945 snprintf(xstats_names[cnt_used_entries].name,
1946 sizeof(xstats_names[0].name),
1947 "%s", rte_stats_strings[idx].name);
1950 num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1951 for (id_queue = 0; id_queue < num_q; id_queue++) {
1952 for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
1953 snprintf(xstats_names[cnt_used_entries].name,
1954 sizeof(xstats_names[0].name),
1956 id_queue, rte_rxq_stats_strings[idx].name);
1961 num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1962 for (id_queue = 0; id_queue < num_q; id_queue++) {
1963 for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
1964 snprintf(xstats_names[cnt_used_entries].name,
1965 sizeof(xstats_names[0].name),
1967 id_queue, rte_txq_stats_strings[idx].name);
1971 return cnt_used_entries;
1974 /* retrieve ethdev extended statistics names */
1976 rte_eth_xstats_get_names_by_id(uint16_t port_id,
1977 struct rte_eth_xstat_name *xstats_names, unsigned int size,
1980 struct rte_eth_xstat_name *xstats_names_copy;
1981 unsigned int no_basic_stat_requested = 1;
1982 unsigned int no_ext_stat_requested = 1;
1983 unsigned int expected_entries;
1984 unsigned int basic_count;
1985 struct rte_eth_dev *dev;
1989 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1990 dev = &rte_eth_devices[port_id];
1992 basic_count = get_xstats_basic_count(dev);
1993 ret = get_xstats_count(port_id);
1996 expected_entries = (unsigned int)ret;
1998 /* Return max number of stats if no ids given */
2001 return expected_entries;
2002 else if (xstats_names && size < expected_entries)
2003 return expected_entries;
2006 if (ids && !xstats_names)
2009 if (ids && dev->dev_ops->xstats_get_names_by_id != NULL && size > 0) {
2010 uint64_t ids_copy[size];
2012 for (i = 0; i < size; i++) {
2013 if (ids[i] < basic_count) {
2014 no_basic_stat_requested = 0;
2019 * Convert ids to xstats ids that PMD knows.
2020 * ids known by user are basic + extended stats.
2022 ids_copy[i] = ids[i] - basic_count;
2025 if (no_basic_stat_requested)
2026 return (*dev->dev_ops->xstats_get_names_by_id)(dev,
2027 xstats_names, ids_copy, size);
2030 /* Retrieve all stats */
2032 int num_stats = rte_eth_xstats_get_names(port_id, xstats_names,
2034 if (num_stats < 0 || num_stats > (int)expected_entries)
2037 return expected_entries;
2040 xstats_names_copy = calloc(expected_entries,
2041 sizeof(struct rte_eth_xstat_name));
2043 if (!xstats_names_copy) {
2044 RTE_PMD_DEBUG_TRACE("ERROR: can't allocate memory");
2049 for (i = 0; i < size; i++) {
2050 if (ids[i] >= basic_count) {
2051 no_ext_stat_requested = 0;
2057 /* Fill xstats_names_copy structure */
2058 if (ids && no_ext_stat_requested) {
2059 rte_eth_basic_stats_get_names(dev, xstats_names_copy);
2061 ret = rte_eth_xstats_get_names(port_id, xstats_names_copy,
2064 free(xstats_names_copy);
2070 for (i = 0; i < size; i++) {
2071 if (ids[i] >= expected_entries) {
2072 RTE_PMD_DEBUG_TRACE("ERROR: id value isn't valid\n");
2073 free(xstats_names_copy);
2076 xstats_names[i] = xstats_names_copy[ids[i]];
2079 free(xstats_names_copy);
2084 rte_eth_xstats_get_names(uint16_t port_id,
2085 struct rte_eth_xstat_name *xstats_names,
2088 struct rte_eth_dev *dev;
2089 int cnt_used_entries;
2090 int cnt_expected_entries;
2091 int cnt_driver_entries;
2093 cnt_expected_entries = get_xstats_count(port_id);
2094 if (xstats_names == NULL || cnt_expected_entries < 0 ||
2095 (int)size < cnt_expected_entries)
2096 return cnt_expected_entries;
2098 /* port_id checked in get_xstats_count() */
2099 dev = &rte_eth_devices[port_id];
2101 cnt_used_entries = rte_eth_basic_stats_get_names(
2104 if (dev->dev_ops->xstats_get_names != NULL) {
2105 /* If there are any driver-specific xstats, append them
2108 cnt_driver_entries = (*dev->dev_ops->xstats_get_names)(
2110 xstats_names + cnt_used_entries,
2111 size - cnt_used_entries);
2112 if (cnt_driver_entries < 0)
2113 return eth_err(port_id, cnt_driver_entries);
2114 cnt_used_entries += cnt_driver_entries;
2117 return cnt_used_entries;
2122 rte_eth_basic_stats_get(uint16_t port_id, struct rte_eth_xstat *xstats)
2124 struct rte_eth_dev *dev;
2125 struct rte_eth_stats eth_stats;
2126 unsigned int count = 0, i, q;
2127 uint64_t val, *stats_ptr;
2128 uint16_t nb_rxqs, nb_txqs;
2131 ret = rte_eth_stats_get(port_id, ð_stats);
2135 dev = &rte_eth_devices[port_id];
2137 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2138 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2141 for (i = 0; i < RTE_NB_STATS; i++) {
2142 stats_ptr = RTE_PTR_ADD(ð_stats,
2143 rte_stats_strings[i].offset);
2145 xstats[count++].value = val;
2149 for (q = 0; q < nb_rxqs; q++) {
2150 for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
2151 stats_ptr = RTE_PTR_ADD(ð_stats,
2152 rte_rxq_stats_strings[i].offset +
2153 q * sizeof(uint64_t));
2155 xstats[count++].value = val;
2160 for (q = 0; q < nb_txqs; q++) {
2161 for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
2162 stats_ptr = RTE_PTR_ADD(ð_stats,
2163 rte_txq_stats_strings[i].offset +
2164 q * sizeof(uint64_t));
2166 xstats[count++].value = val;
2172 /* retrieve ethdev extended statistics */
2174 rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
2175 uint64_t *values, unsigned int size)
2177 unsigned int no_basic_stat_requested = 1;
2178 unsigned int no_ext_stat_requested = 1;
2179 unsigned int num_xstats_filled;
2180 unsigned int basic_count;
2181 uint16_t expected_entries;
2182 struct rte_eth_dev *dev;
2186 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2187 ret = get_xstats_count(port_id);
2190 expected_entries = (uint16_t)ret;
2191 struct rte_eth_xstat xstats[expected_entries];
2192 dev = &rte_eth_devices[port_id];
2193 basic_count = get_xstats_basic_count(dev);
2195 /* Return max number of stats if no ids given */
2198 return expected_entries;
2199 else if (values && size < expected_entries)
2200 return expected_entries;
2206 if (ids && dev->dev_ops->xstats_get_by_id != NULL && size) {
2207 unsigned int basic_count = get_xstats_basic_count(dev);
2208 uint64_t ids_copy[size];
2210 for (i = 0; i < size; i++) {
2211 if (ids[i] < basic_count) {
2212 no_basic_stat_requested = 0;
2217 * Convert ids to xstats ids that PMD knows.
2218 * ids known by user are basic + extended stats.
2220 ids_copy[i] = ids[i] - basic_count;
2223 if (no_basic_stat_requested)
2224 return (*dev->dev_ops->xstats_get_by_id)(dev, ids_copy,
2229 for (i = 0; i < size; i++) {
2230 if (ids[i] >= basic_count) {
2231 no_ext_stat_requested = 0;
2237 /* Fill the xstats structure */
2238 if (ids && no_ext_stat_requested)
2239 ret = rte_eth_basic_stats_get(port_id, xstats);
2241 ret = rte_eth_xstats_get(port_id, xstats, expected_entries);
2245 num_xstats_filled = (unsigned int)ret;
2247 /* Return all stats */
2249 for (i = 0; i < num_xstats_filled; i++)
2250 values[i] = xstats[i].value;
2251 return expected_entries;
2255 for (i = 0; i < size; i++) {
2256 if (ids[i] >= expected_entries) {
2257 RTE_PMD_DEBUG_TRACE("ERROR: id value isn't valid\n");
2260 values[i] = xstats[ids[i]].value;
2266 rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats,
2269 struct rte_eth_dev *dev;
2270 unsigned int count = 0, i;
2271 signed int xcount = 0;
2272 uint16_t nb_rxqs, nb_txqs;
2275 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
2277 dev = &rte_eth_devices[port_id];
2279 nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2280 nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
2282 /* Return generic statistics */
2283 count = RTE_NB_STATS + (nb_rxqs * RTE_NB_RXQ_STATS) +
2284 (nb_txqs * RTE_NB_TXQ_STATS);
2286 /* implemented by the driver */
2287 if (dev->dev_ops->xstats_get != NULL) {
2288 /* Retrieve the xstats from the driver at the end of the
2291 xcount = (*dev->dev_ops->xstats_get)(dev,
2292 xstats ? xstats + count : NULL,
2293 (n > count) ? n - count : 0);
2296 return eth_err(port_id, xcount);
2299 if (n < count + xcount || xstats == NULL)
2300 return count + xcount;
2302 /* now fill the xstats structure */
2303 ret = rte_eth_basic_stats_get(port_id, xstats);
2308 for (i = 0; i < count; i++)
2310 /* add an offset to driver-specific stats */
2311 for ( ; i < count + xcount; i++)
2312 xstats[i].id += count;
2314 return count + xcount;
2317 /* reset ethdev extended statistics */
2319 rte_eth_xstats_reset(uint16_t port_id)
2321 struct rte_eth_dev *dev;
2323 RTE_ETH_VALID_PORTID_OR_RET(port_id);
2324 dev = &rte_eth_devices[port_id];
2326 /* implemented by the driver */
2327 if (dev->dev_ops->xstats_reset != NULL) {
2328 (*dev->dev_ops->xstats_reset)(dev);
2332 /* fallback to default */
2333 rte_eth_stats_reset(port_id);
2337 set_queue_stats_mapping(uint16_t port_id, uint16_t queue_id, uint8_t stat_idx,
2340 struct rte_eth_dev *dev;
2342 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2344 dev = &rte_eth_devices[port_id];
2346 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
2347 return (*dev->dev_ops->queue_stats_mapping_set)
2348 (dev, queue_id, stat_idx, is_rx);
2353 rte_eth_dev_set_tx_queue_stats_mapping(uint16_t port_id, uint16_t tx_queue_id,
2356 return eth_err(port_id, set_queue_stats_mapping(port_id, tx_queue_id,
2357 stat_idx, STAT_QMAP_TX));
2362 rte_eth_dev_set_rx_queue_stats_mapping(uint16_t port_id, uint16_t rx_queue_id,
2365 return eth_err(port_id, set_queue_stats_mapping(port_id, rx_queue_id,
2366 stat_idx, STAT_QMAP_RX));
2370 rte_eth_dev_fw_version_get(uint16_t port_id, char *fw_version, size_t fw_size)
2372 struct rte_eth_dev *dev;
2374 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2375 dev = &rte_eth_devices[port_id];
2377 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP);
2378 return eth_err(port_id, (*dev->dev_ops->fw_version_get)(dev,
2379 fw_version, fw_size));
2383 rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)
2385 struct rte_eth_dev *dev;
2386 const struct rte_eth_desc_lim lim = {
2387 .nb_max = UINT16_MAX,
2392 RTE_ETH_VALID_PORTID_OR_RET(port_id);
2393 dev = &rte_eth_devices[port_id];
2395 memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
2396 dev_info->rx_desc_lim = lim;
2397 dev_info->tx_desc_lim = lim;
2398 dev_info->device = dev->device;
2400 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
2401 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
2402 dev_info->driver_name = dev->device->driver->name;
2403 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
2404 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
2408 rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
2409 uint32_t *ptypes, int num)
2412 struct rte_eth_dev *dev;
2413 const uint32_t *all_ptypes;
2415 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2416 dev = &rte_eth_devices[port_id];
2417 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
2418 all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
2423 for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i)
2424 if (all_ptypes[i] & ptype_mask) {
2426 ptypes[j] = all_ptypes[i];
2434 rte_eth_macaddr_get(uint16_t port_id, struct ether_addr *mac_addr)
2436 struct rte_eth_dev *dev;
2438 RTE_ETH_VALID_PORTID_OR_RET(port_id);
2439 dev = &rte_eth_devices[port_id];
2440 ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
2445 rte_eth_dev_get_mtu(uint16_t port_id, uint16_t *mtu)
2447 struct rte_eth_dev *dev;
2449 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2451 dev = &rte_eth_devices[port_id];
2452 *mtu = dev->data->mtu;
2457 rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
2460 struct rte_eth_dev *dev;
2462 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2463 dev = &rte_eth_devices[port_id];
2464 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
2466 ret = (*dev->dev_ops->mtu_set)(dev, mtu);
2468 dev->data->mtu = mtu;
2470 return eth_err(port_id, ret);
2474 rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on)
2476 struct rte_eth_dev *dev;
2479 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2480 dev = &rte_eth_devices[port_id];
2481 if (!(dev->data->dev_conf.rxmode.offloads &
2482 DEV_RX_OFFLOAD_VLAN_FILTER)) {
2483 RTE_PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
2487 if (vlan_id > 4095) {
2488 RTE_PMD_DEBUG_TRACE("(port_id=%d) invalid vlan_id=%u > 4095\n",
2489 port_id, (unsigned) vlan_id);
2492 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
2494 ret = (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
2496 struct rte_vlan_filter_conf *vfc;
2500 vfc = &dev->data->vlan_filter_conf;
2501 vidx = vlan_id / 64;
2502 vbit = vlan_id % 64;
2505 vfc->ids[vidx] |= UINT64_C(1) << vbit;
2507 vfc->ids[vidx] &= ~(UINT64_C(1) << vbit);
2510 return eth_err(port_id, ret);
2514 rte_eth_dev_set_vlan_strip_on_queue(uint16_t port_id, uint16_t rx_queue_id,
2517 struct rte_eth_dev *dev;
2519 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2520 dev = &rte_eth_devices[port_id];
2521 if (rx_queue_id >= dev->data->nb_rx_queues) {
2522 RTE_PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
2526 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
2527 (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
2533 rte_eth_dev_set_vlan_ether_type(uint16_t port_id,
2534 enum rte_vlan_type vlan_type,
2537 struct rte_eth_dev *dev;
2539 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2540 dev = &rte_eth_devices[port_id];
2541 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
2543 return eth_err(port_id, (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type,
2548 rte_eth_dev_set_vlan_offload(uint16_t port_id, int offload_mask)
2550 struct rte_eth_dev *dev;
2554 uint64_t orig_offloads;
2556 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2557 dev = &rte_eth_devices[port_id];
2559 /* save original values in case of failure */
2560 orig_offloads = dev->data->dev_conf.rxmode.offloads;
2562 /*check which option changed by application*/
2563 cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
2564 org = !!(dev->data->dev_conf.rxmode.offloads &
2565 DEV_RX_OFFLOAD_VLAN_STRIP);
2568 dev->data->dev_conf.rxmode.offloads |=
2569 DEV_RX_OFFLOAD_VLAN_STRIP;
2571 dev->data->dev_conf.rxmode.offloads &=
2572 ~DEV_RX_OFFLOAD_VLAN_STRIP;
2573 mask |= ETH_VLAN_STRIP_MASK;
2576 cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
2577 org = !!(dev->data->dev_conf.rxmode.offloads &
2578 DEV_RX_OFFLOAD_VLAN_FILTER);
2581 dev->data->dev_conf.rxmode.offloads |=
2582 DEV_RX_OFFLOAD_VLAN_FILTER;
2584 dev->data->dev_conf.rxmode.offloads &=
2585 ~DEV_RX_OFFLOAD_VLAN_FILTER;
2586 mask |= ETH_VLAN_FILTER_MASK;
2589 cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
2590 org = !!(dev->data->dev_conf.rxmode.offloads &
2591 DEV_RX_OFFLOAD_VLAN_EXTEND);
2594 dev->data->dev_conf.rxmode.offloads |=
2595 DEV_RX_OFFLOAD_VLAN_EXTEND;
2597 dev->data->dev_conf.rxmode.offloads &=
2598 ~DEV_RX_OFFLOAD_VLAN_EXTEND;
2599 mask |= ETH_VLAN_EXTEND_MASK;
2606 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
2609 * Convert to the offload bitfield API just in case the underlying PMD
2610 * still supporting it.
2612 rte_eth_convert_rx_offloads(dev->data->dev_conf.rxmode.offloads,
2613 &dev->data->dev_conf.rxmode);
2614 ret = (*dev->dev_ops->vlan_offload_set)(dev, mask);
2616 /* hit an error restore original values */
2617 dev->data->dev_conf.rxmode.offloads = orig_offloads;
2618 rte_eth_convert_rx_offloads(dev->data->dev_conf.rxmode.offloads,
2619 &dev->data->dev_conf.rxmode);
2622 return eth_err(port_id, ret);
2626 rte_eth_dev_get_vlan_offload(uint16_t port_id)
2628 struct rte_eth_dev *dev;
2631 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2632 dev = &rte_eth_devices[port_id];
2634 if (dev->data->dev_conf.rxmode.offloads &
2635 DEV_RX_OFFLOAD_VLAN_STRIP)
2636 ret |= ETH_VLAN_STRIP_OFFLOAD;
2638 if (dev->data->dev_conf.rxmode.offloads &
2639 DEV_RX_OFFLOAD_VLAN_FILTER)
2640 ret |= ETH_VLAN_FILTER_OFFLOAD;
2642 if (dev->data->dev_conf.rxmode.offloads &
2643 DEV_RX_OFFLOAD_VLAN_EXTEND)
2644 ret |= ETH_VLAN_EXTEND_OFFLOAD;
2650 rte_eth_dev_set_vlan_pvid(uint16_t port_id, uint16_t pvid, int on)
2652 struct rte_eth_dev *dev;
2654 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2655 dev = &rte_eth_devices[port_id];
2656 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
2658 return eth_err(port_id, (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on));
2662 rte_eth_dev_flow_ctrl_get(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
2664 struct rte_eth_dev *dev;
2666 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2667 dev = &rte_eth_devices[port_id];
2668 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
2669 memset(fc_conf, 0, sizeof(*fc_conf));
2670 return eth_err(port_id, (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf));
2674 rte_eth_dev_flow_ctrl_set(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
2676 struct rte_eth_dev *dev;
2678 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2679 if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
2680 RTE_PMD_DEBUG_TRACE("Invalid send_xon, only 0/1 allowed\n");
2684 dev = &rte_eth_devices[port_id];
2685 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
2686 return eth_err(port_id, (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf));
2690 rte_eth_dev_priority_flow_ctrl_set(uint16_t port_id,
2691 struct rte_eth_pfc_conf *pfc_conf)
2693 struct rte_eth_dev *dev;
2695 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2696 if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) {
2697 RTE_PMD_DEBUG_TRACE("Invalid priority, only 0-7 allowed\n");
2701 dev = &rte_eth_devices[port_id];
2702 /* High water, low water validation are device specific */
2703 if (*dev->dev_ops->priority_flow_ctrl_set)
2704 return eth_err(port_id, (*dev->dev_ops->priority_flow_ctrl_set)
2710 rte_eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
2718 num = (reta_size + RTE_RETA_GROUP_SIZE - 1) / RTE_RETA_GROUP_SIZE;
2719 for (i = 0; i < num; i++) {
2720 if (reta_conf[i].mask)
2728 rte_eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
2732 uint16_t i, idx, shift;
2738 RTE_PMD_DEBUG_TRACE("No receive queue is available\n");
2742 for (i = 0; i < reta_size; i++) {
2743 idx = i / RTE_RETA_GROUP_SIZE;
2744 shift = i % RTE_RETA_GROUP_SIZE;
2745 if ((reta_conf[idx].mask & (1ULL << shift)) &&
2746 (reta_conf[idx].reta[shift] >= max_rxq)) {
2747 RTE_PMD_DEBUG_TRACE("reta_conf[%u]->reta[%u]: %u exceeds "
2748 "the maximum rxq index: %u\n", idx, shift,
2749 reta_conf[idx].reta[shift], max_rxq);
2758 rte_eth_dev_rss_reta_update(uint16_t port_id,
2759 struct rte_eth_rss_reta_entry64 *reta_conf,
2762 struct rte_eth_dev *dev;
2765 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2766 /* Check mask bits */
2767 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2771 dev = &rte_eth_devices[port_id];
2773 /* Check entry value */
2774 ret = rte_eth_check_reta_entry(reta_conf, reta_size,
2775 dev->data->nb_rx_queues);
2779 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
2780 return eth_err(port_id, (*dev->dev_ops->reta_update)(dev, reta_conf,
2785 rte_eth_dev_rss_reta_query(uint16_t port_id,
2786 struct rte_eth_rss_reta_entry64 *reta_conf,
2789 struct rte_eth_dev *dev;
2792 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2794 /* Check mask bits */
2795 ret = rte_eth_check_reta_mask(reta_conf, reta_size);
2799 dev = &rte_eth_devices[port_id];
2800 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
2801 return eth_err(port_id, (*dev->dev_ops->reta_query)(dev, reta_conf,
2806 rte_eth_dev_rss_hash_update(uint16_t port_id,
2807 struct rte_eth_rss_conf *rss_conf)
2809 struct rte_eth_dev *dev;
2811 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2812 dev = &rte_eth_devices[port_id];
2813 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
2814 return eth_err(port_id, (*dev->dev_ops->rss_hash_update)(dev,
2819 rte_eth_dev_rss_hash_conf_get(uint16_t port_id,
2820 struct rte_eth_rss_conf *rss_conf)
2822 struct rte_eth_dev *dev;
2824 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2825 dev = &rte_eth_devices[port_id];
2826 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
2827 return eth_err(port_id, (*dev->dev_ops->rss_hash_conf_get)(dev,
2832 rte_eth_dev_udp_tunnel_port_add(uint16_t port_id,
2833 struct rte_eth_udp_tunnel *udp_tunnel)
2835 struct rte_eth_dev *dev;
2837 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2838 if (udp_tunnel == NULL) {
2839 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2843 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2844 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2848 dev = &rte_eth_devices[port_id];
2849 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP);
2850 return eth_err(port_id, (*dev->dev_ops->udp_tunnel_port_add)(dev,
2855 rte_eth_dev_udp_tunnel_port_delete(uint16_t port_id,
2856 struct rte_eth_udp_tunnel *udp_tunnel)
2858 struct rte_eth_dev *dev;
2860 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2861 dev = &rte_eth_devices[port_id];
2863 if (udp_tunnel == NULL) {
2864 RTE_PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n");
2868 if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) {
2869 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
2873 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP);
2874 return eth_err(port_id, (*dev->dev_ops->udp_tunnel_port_del)(dev,
2879 rte_eth_led_on(uint16_t port_id)
2881 struct rte_eth_dev *dev;
2883 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2884 dev = &rte_eth_devices[port_id];
2885 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
2886 return eth_err(port_id, (*dev->dev_ops->dev_led_on)(dev));
2890 rte_eth_led_off(uint16_t port_id)
2892 struct rte_eth_dev *dev;
2894 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2895 dev = &rte_eth_devices[port_id];
2896 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
2897 return eth_err(port_id, (*dev->dev_ops->dev_led_off)(dev));
2901 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
2905 get_mac_addr_index(uint16_t port_id, const struct ether_addr *addr)
2907 struct rte_eth_dev_info dev_info;
2908 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2911 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2912 rte_eth_dev_info_get(port_id, &dev_info);
2914 for (i = 0; i < dev_info.max_mac_addrs; i++)
2915 if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
2921 static const struct ether_addr null_mac_addr;
2924 rte_eth_dev_mac_addr_add(uint16_t port_id, struct ether_addr *addr,
2927 struct rte_eth_dev *dev;
2932 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2933 dev = &rte_eth_devices[port_id];
2934 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
2936 if (is_zero_ether_addr(addr)) {
2937 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
2941 if (pool >= ETH_64_POOLS) {
2942 RTE_PMD_DEBUG_TRACE("pool id must be 0-%d\n", ETH_64_POOLS - 1);
2946 index = get_mac_addr_index(port_id, addr);
2948 index = get_mac_addr_index(port_id, &null_mac_addr);
2950 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
2955 pool_mask = dev->data->mac_pool_sel[index];
2957 /* Check if both MAC address and pool is already there, and do nothing */
2958 if (pool_mask & (1ULL << pool))
2963 ret = (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
2966 /* Update address in NIC data structure */
2967 ether_addr_copy(addr, &dev->data->mac_addrs[index]);
2969 /* Update pool bitmap in NIC data structure */
2970 dev->data->mac_pool_sel[index] |= (1ULL << pool);
2973 return eth_err(port_id, ret);
2977 rte_eth_dev_mac_addr_remove(uint16_t port_id, struct ether_addr *addr)
2979 struct rte_eth_dev *dev;
2982 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2983 dev = &rte_eth_devices[port_id];
2984 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
2986 index = get_mac_addr_index(port_id, addr);
2988 RTE_PMD_DEBUG_TRACE("port %d: Cannot remove default MAC address\n", port_id);
2990 } else if (index < 0)
2991 return 0; /* Do nothing if address wasn't found */
2994 (*dev->dev_ops->mac_addr_remove)(dev, index);
2996 /* Update address in NIC data structure */
2997 ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
2999 /* reset pool bitmap */
3000 dev->data->mac_pool_sel[index] = 0;
3006 rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct ether_addr *addr)
3008 struct rte_eth_dev *dev;
3010 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3012 if (!is_valid_assigned_ether_addr(addr))
3015 dev = &rte_eth_devices[port_id];
3016 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP);
3018 /* Update default address in NIC data structure */
3019 ether_addr_copy(addr, &dev->data->mac_addrs[0]);
3021 (*dev->dev_ops->mac_addr_set)(dev, addr);
3028 * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
3032 get_hash_mac_addr_index(uint16_t port_id, const struct ether_addr *addr)
3034 struct rte_eth_dev_info dev_info;
3035 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3038 rte_eth_dev_info_get(port_id, &dev_info);
3039 if (!dev->data->hash_mac_addrs)
3042 for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
3043 if (memcmp(addr, &dev->data->hash_mac_addrs[i],
3044 ETHER_ADDR_LEN) == 0)
3051 rte_eth_dev_uc_hash_table_set(uint16_t port_id, struct ether_addr *addr,
3056 struct rte_eth_dev *dev;
3058 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3060 dev = &rte_eth_devices[port_id];
3061 if (is_zero_ether_addr(addr)) {
3062 RTE_PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
3067 index = get_hash_mac_addr_index(port_id, addr);
3068 /* Check if it's already there, and do nothing */
3069 if ((index >= 0) && on)
3074 RTE_PMD_DEBUG_TRACE("port %d: the MAC address was not "
3075 "set in UTA\n", port_id);
3079 index = get_hash_mac_addr_index(port_id, &null_mac_addr);
3081 RTE_PMD_DEBUG_TRACE("port %d: MAC address array full\n",
3087 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
3088 ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
3090 /* Update address in NIC data structure */
3092 ether_addr_copy(addr,
3093 &dev->data->hash_mac_addrs[index]);
3095 ether_addr_copy(&null_mac_addr,
3096 &dev->data->hash_mac_addrs[index]);
3099 return eth_err(port_id, ret);
3103 rte_eth_dev_uc_all_hash_table_set(uint16_t port_id, uint8_t on)
3105 struct rte_eth_dev *dev;
3107 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3109 dev = &rte_eth_devices[port_id];
3111 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
3112 return eth_err(port_id, (*dev->dev_ops->uc_all_hash_table_set)(dev,
3116 int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx,
3119 struct rte_eth_dev *dev;
3120 struct rte_eth_dev_info dev_info;
3121 struct rte_eth_link link;
3123 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3125 dev = &rte_eth_devices[port_id];
3126 rte_eth_dev_info_get(port_id, &dev_info);
3127 link = dev->data->dev_link;
3129 if (queue_idx > dev_info.max_tx_queues) {
3130 RTE_PMD_DEBUG_TRACE("set queue rate limit:port %d: "
3131 "invalid queue id=%d\n", port_id, queue_idx);
3135 if (tx_rate > link.link_speed) {
3136 RTE_PMD_DEBUG_TRACE("set queue rate limit:invalid tx_rate=%d, "
3137 "bigger than link speed= %d\n",
3138 tx_rate, link.link_speed);
3142 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
3143 return eth_err(port_id, (*dev->dev_ops->set_queue_rate_limit)(dev,
3144 queue_idx, tx_rate));
3148 rte_eth_mirror_rule_set(uint16_t port_id,
3149 struct rte_eth_mirror_conf *mirror_conf,
3150 uint8_t rule_id, uint8_t on)
3152 struct rte_eth_dev *dev;
3154 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3155 if (mirror_conf->rule_type == 0) {
3156 RTE_PMD_DEBUG_TRACE("mirror rule type can not be 0.\n");
3160 if (mirror_conf->dst_pool >= ETH_64_POOLS) {
3161 RTE_PMD_DEBUG_TRACE("Invalid dst pool, pool id must be 0-%d\n",
3166 if ((mirror_conf->rule_type & (ETH_MIRROR_VIRTUAL_POOL_UP |
3167 ETH_MIRROR_VIRTUAL_POOL_DOWN)) &&
3168 (mirror_conf->pool_mask == 0)) {
3169 RTE_PMD_DEBUG_TRACE("Invalid mirror pool, pool mask can not be 0.\n");
3173 if ((mirror_conf->rule_type & ETH_MIRROR_VLAN) &&
3174 mirror_conf->vlan.vlan_mask == 0) {
3175 RTE_PMD_DEBUG_TRACE("Invalid vlan mask, vlan mask can not be 0.\n");
3179 dev = &rte_eth_devices[port_id];
3180 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
3182 return eth_err(port_id, (*dev->dev_ops->mirror_rule_set)(dev,
3183 mirror_conf, rule_id, on));
3187 rte_eth_mirror_rule_reset(uint16_t port_id, uint8_t rule_id)
3189 struct rte_eth_dev *dev;
3191 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3193 dev = &rte_eth_devices[port_id];
3194 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
3196 return eth_err(port_id, (*dev->dev_ops->mirror_rule_reset)(dev,
3200 RTE_INIT(eth_dev_init_cb_lists)
3204 for (i = 0; i < RTE_MAX_ETHPORTS; i++)
3205 TAILQ_INIT(&rte_eth_devices[i].link_intr_cbs);
3209 rte_eth_dev_callback_register(uint16_t port_id,
3210 enum rte_eth_event_type event,
3211 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
3213 struct rte_eth_dev *dev;
3214 struct rte_eth_dev_callback *user_cb;
3215 uint32_t next_port; /* size is 32-bit to prevent loop wrap-around */
3221 if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
3222 ethdev_log(ERR, "Invalid port_id=%d", port_id);
3226 if (port_id == RTE_ETH_ALL) {
3228 last_port = RTE_MAX_ETHPORTS - 1;
3230 next_port = last_port = port_id;
3233 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3236 dev = &rte_eth_devices[next_port];
3238 TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
3239 if (user_cb->cb_fn == cb_fn &&
3240 user_cb->cb_arg == cb_arg &&
3241 user_cb->event == event) {
3246 /* create a new callback. */
3247 if (user_cb == NULL) {
3248 user_cb = rte_zmalloc("INTR_USER_CALLBACK",
3249 sizeof(struct rte_eth_dev_callback), 0);
3250 if (user_cb != NULL) {
3251 user_cb->cb_fn = cb_fn;
3252 user_cb->cb_arg = cb_arg;
3253 user_cb->event = event;
3254 TAILQ_INSERT_TAIL(&(dev->link_intr_cbs),
3257 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3258 rte_eth_dev_callback_unregister(port_id, event,
3264 } while (++next_port <= last_port);
3266 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3271 rte_eth_dev_callback_unregister(uint16_t port_id,
3272 enum rte_eth_event_type event,
3273 rte_eth_dev_cb_fn cb_fn, void *cb_arg)
3276 struct rte_eth_dev *dev;
3277 struct rte_eth_dev_callback *cb, *next;
3278 uint32_t next_port; /* size is 32-bit to prevent loop wrap-around */
3284 if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
3285 ethdev_log(ERR, "Invalid port_id=%d", port_id);
3289 if (port_id == RTE_ETH_ALL) {
3291 last_port = RTE_MAX_ETHPORTS - 1;
3293 next_port = last_port = port_id;
3296 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3299 dev = &rte_eth_devices[next_port];
3301 for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL;
3304 next = TAILQ_NEXT(cb, next);
3306 if (cb->cb_fn != cb_fn || cb->event != event ||
3307 (cb->cb_arg != (void *)-1 && cb->cb_arg != cb_arg))
3311 * if this callback is not executing right now,
3314 if (cb->active == 0) {
3315 TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
3321 } while (++next_port <= last_port);
3323 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3328 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
3329 enum rte_eth_event_type event, void *ret_param)
3331 struct rte_eth_dev_callback *cb_lst;
3332 struct rte_eth_dev_callback dev_cb;
3335 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3336 TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
3337 if (cb_lst->cb_fn == NULL || cb_lst->event != event)
3341 if (ret_param != NULL)
3342 dev_cb.ret_param = ret_param;
3344 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3345 rc = dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
3346 dev_cb.cb_arg, dev_cb.ret_param);
3347 rte_spinlock_lock(&rte_eth_dev_cb_lock);
3350 rte_spinlock_unlock(&rte_eth_dev_cb_lock);
3355 rte_eth_dev_rx_intr_ctl(uint16_t port_id, int epfd, int op, void *data)
3358 struct rte_eth_dev *dev;
3359 struct rte_intr_handle *intr_handle;
3363 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3365 dev = &rte_eth_devices[port_id];
3367 if (!dev->intr_handle) {
3368 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
3372 intr_handle = dev->intr_handle;
3373 if (!intr_handle->intr_vec) {
3374 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
3378 for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
3379 vec = intr_handle->intr_vec[qid];
3380 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
3381 if (rc && rc != -EEXIST) {
3382 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
3383 " op %d epfd %d vec %u\n",
3384 port_id, qid, op, epfd, vec);
3391 const struct rte_memzone *
3392 rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
3393 uint16_t queue_id, size_t size, unsigned align,
3396 char z_name[RTE_MEMZONE_NAMESIZE];
3397 const struct rte_memzone *mz;
3399 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
3400 dev->device->driver->name, ring_name,
3401 dev->data->port_id, queue_id);
3403 mz = rte_memzone_lookup(z_name);
3407 return rte_memzone_reserve_aligned(z_name, size, socket_id,
3408 RTE_MEMZONE_IOVA_CONTIG, align);
3412 rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id,
3413 int epfd, int op, void *data)
3416 struct rte_eth_dev *dev;
3417 struct rte_intr_handle *intr_handle;
3420 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3422 dev = &rte_eth_devices[port_id];
3423 if (queue_id >= dev->data->nb_rx_queues) {
3424 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
3428 if (!dev->intr_handle) {
3429 RTE_PMD_DEBUG_TRACE("RX Intr handle unset\n");
3433 intr_handle = dev->intr_handle;
3434 if (!intr_handle->intr_vec) {
3435 RTE_PMD_DEBUG_TRACE("RX Intr vector unset\n");
3439 vec = intr_handle->intr_vec[queue_id];
3440 rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
3441 if (rc && rc != -EEXIST) {
3442 RTE_PMD_DEBUG_TRACE("p %u q %u rx ctl error"
3443 " op %d epfd %d vec %u\n",
3444 port_id, queue_id, op, epfd, vec);
3452 rte_eth_dev_rx_intr_enable(uint16_t port_id,
3455 struct rte_eth_dev *dev;
3457 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3459 dev = &rte_eth_devices[port_id];
3461 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
3462 return eth_err(port_id, (*dev->dev_ops->rx_queue_intr_enable)(dev,
3467 rte_eth_dev_rx_intr_disable(uint16_t port_id,
3470 struct rte_eth_dev *dev;
3472 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3474 dev = &rte_eth_devices[port_id];
3476 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
3477 return eth_err(port_id, (*dev->dev_ops->rx_queue_intr_disable)(dev,
3483 rte_eth_dev_filter_supported(uint16_t port_id,
3484 enum rte_filter_type filter_type)
3486 struct rte_eth_dev *dev;
3488 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3490 dev = &rte_eth_devices[port_id];
3491 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3492 return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3493 RTE_ETH_FILTER_NOP, NULL);
3497 rte_eth_dev_filter_ctrl(uint16_t port_id, enum rte_filter_type filter_type,
3498 enum rte_filter_op filter_op, void *arg)
3500 struct rte_eth_dev *dev;
3502 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3504 dev = &rte_eth_devices[port_id];
3505 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
3506 return eth_err(port_id, (*dev->dev_ops->filter_ctrl)(dev, filter_type,
3510 const struct rte_eth_rxtx_callback *
3511 rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
3512 rte_rx_callback_fn fn, void *user_param)
3514 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3515 rte_errno = ENOTSUP;
3518 /* check input parameters */
3519 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3520 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3524 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3532 cb->param = user_param;
3534 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3535 /* Add the callbacks in fifo order. */
3536 struct rte_eth_rxtx_callback *tail =
3537 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3540 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3547 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3552 const struct rte_eth_rxtx_callback *
3553 rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
3554 rte_rx_callback_fn fn, void *user_param)
3556 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3557 rte_errno = ENOTSUP;
3560 /* check input parameters */
3561 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3562 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
3567 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3575 cb->param = user_param;
3577 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3578 /* Add the callbacks at fisrt position*/
3579 cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
3581 rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
3582 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3587 const struct rte_eth_rxtx_callback *
3588 rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
3589 rte_tx_callback_fn fn, void *user_param)
3591 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3592 rte_errno = ENOTSUP;
3595 /* check input parameters */
3596 if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
3597 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
3602 struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
3610 cb->param = user_param;
3612 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3613 /* Add the callbacks in fifo order. */
3614 struct rte_eth_rxtx_callback *tail =
3615 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
3618 rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
3625 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3631 rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
3632 const struct rte_eth_rxtx_callback *user_cb)
3634 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3637 /* Check input parameters. */
3638 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3639 if (user_cb == NULL ||
3640 queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
3643 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3644 struct rte_eth_rxtx_callback *cb;
3645 struct rte_eth_rxtx_callback **prev_cb;
3648 rte_spinlock_lock(&rte_eth_rx_cb_lock);
3649 prev_cb = &dev->post_rx_burst_cbs[queue_id];
3650 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3652 if (cb == user_cb) {
3653 /* Remove the user cb from the callback list. */
3654 *prev_cb = cb->next;
3659 rte_spinlock_unlock(&rte_eth_rx_cb_lock);
3665 rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
3666 const struct rte_eth_rxtx_callback *user_cb)
3668 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
3671 /* Check input parameters. */
3672 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
3673 if (user_cb == NULL ||
3674 queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
3677 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3679 struct rte_eth_rxtx_callback *cb;
3680 struct rte_eth_rxtx_callback **prev_cb;
3682 rte_spinlock_lock(&rte_eth_tx_cb_lock);
3683 prev_cb = &dev->pre_tx_burst_cbs[queue_id];
3684 for (; *prev_cb != NULL; prev_cb = &cb->next) {
3686 if (cb == user_cb) {
3687 /* Remove the user cb from the callback list. */
3688 *prev_cb = cb->next;
3693 rte_spinlock_unlock(&rte_eth_tx_cb_lock);
3699 rte_eth_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
3700 struct rte_eth_rxq_info *qinfo)
3702 struct rte_eth_dev *dev;
3704 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3709 dev = &rte_eth_devices[port_id];
3710 if (queue_id >= dev->data->nb_rx_queues) {
3711 RTE_PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
3715 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP);
3717 memset(qinfo, 0, sizeof(*qinfo));
3718 dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
3723 rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,
3724 struct rte_eth_txq_info *qinfo)
3726 struct rte_eth_dev *dev;
3728 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3733 dev = &rte_eth_devices[port_id];
3734 if (queue_id >= dev->data->nb_tx_queues) {
3735 RTE_PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
3739 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP);
3741 memset(qinfo, 0, sizeof(*qinfo));
3742 dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
3747 rte_eth_dev_set_mc_addr_list(uint16_t port_id,
3748 struct ether_addr *mc_addr_set,
3749 uint32_t nb_mc_addr)
3751 struct rte_eth_dev *dev;
3753 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3755 dev = &rte_eth_devices[port_id];
3756 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP);
3757 return eth_err(port_id, dev->dev_ops->set_mc_addr_list(dev,
3758 mc_addr_set, nb_mc_addr));
3762 rte_eth_timesync_enable(uint16_t port_id)
3764 struct rte_eth_dev *dev;
3766 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3767 dev = &rte_eth_devices[port_id];
3769 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP);
3770 return eth_err(port_id, (*dev->dev_ops->timesync_enable)(dev));
3774 rte_eth_timesync_disable(uint16_t port_id)
3776 struct rte_eth_dev *dev;
3778 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3779 dev = &rte_eth_devices[port_id];
3781 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP);
3782 return eth_err(port_id, (*dev->dev_ops->timesync_disable)(dev));
3786 rte_eth_timesync_read_rx_timestamp(uint16_t port_id, struct timespec *timestamp,
3789 struct rte_eth_dev *dev;
3791 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3792 dev = &rte_eth_devices[port_id];
3794 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP);
3795 return eth_err(port_id, (*dev->dev_ops->timesync_read_rx_timestamp)
3796 (dev, timestamp, flags));
3800 rte_eth_timesync_read_tx_timestamp(uint16_t port_id,
3801 struct timespec *timestamp)
3803 struct rte_eth_dev *dev;
3805 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3806 dev = &rte_eth_devices[port_id];
3808 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP);
3809 return eth_err(port_id, (*dev->dev_ops->timesync_read_tx_timestamp)
3814 rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta)
3816 struct rte_eth_dev *dev;
3818 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3819 dev = &rte_eth_devices[port_id];
3821 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP);
3822 return eth_err(port_id, (*dev->dev_ops->timesync_adjust_time)(dev,
3827 rte_eth_timesync_read_time(uint16_t port_id, struct timespec *timestamp)
3829 struct rte_eth_dev *dev;
3831 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3832 dev = &rte_eth_devices[port_id];
3834 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP);
3835 return eth_err(port_id, (*dev->dev_ops->timesync_read_time)(dev,
3840 rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *timestamp)
3842 struct rte_eth_dev *dev;
3844 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3845 dev = &rte_eth_devices[port_id];
3847 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP);
3848 return eth_err(port_id, (*dev->dev_ops->timesync_write_time)(dev,
3853 rte_eth_dev_get_reg_info(uint16_t port_id, struct rte_dev_reg_info *info)
3855 struct rte_eth_dev *dev;
3857 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3859 dev = &rte_eth_devices[port_id];
3860 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
3861 return eth_err(port_id, (*dev->dev_ops->get_reg)(dev, info));
3865 rte_eth_dev_get_eeprom_length(uint16_t port_id)
3867 struct rte_eth_dev *dev;
3869 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3871 dev = &rte_eth_devices[port_id];
3872 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP);
3873 return eth_err(port_id, (*dev->dev_ops->get_eeprom_length)(dev));
3877 rte_eth_dev_get_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
3879 struct rte_eth_dev *dev;
3881 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3883 dev = &rte_eth_devices[port_id];
3884 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
3885 return eth_err(port_id, (*dev->dev_ops->get_eeprom)(dev, info));
3889 rte_eth_dev_set_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
3891 struct rte_eth_dev *dev;
3893 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3895 dev = &rte_eth_devices[port_id];
3896 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
3897 return eth_err(port_id, (*dev->dev_ops->set_eeprom)(dev, info));
3901 rte_eth_dev_get_dcb_info(uint16_t port_id,
3902 struct rte_eth_dcb_info *dcb_info)
3904 struct rte_eth_dev *dev;
3906 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3908 dev = &rte_eth_devices[port_id];
3909 memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
3911 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP);
3912 return eth_err(port_id, (*dev->dev_ops->get_dcb_info)(dev, dcb_info));
3916 rte_eth_dev_l2_tunnel_eth_type_conf(uint16_t port_id,
3917 struct rte_eth_l2_tunnel_conf *l2_tunnel)
3919 struct rte_eth_dev *dev;
3921 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3922 if (l2_tunnel == NULL) {
3923 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3927 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3928 RTE_PMD_DEBUG_TRACE("Invalid tunnel type\n");
3932 dev = &rte_eth_devices[port_id];
3933 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
3935 return eth_err(port_id, (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev,
3940 rte_eth_dev_l2_tunnel_offload_set(uint16_t port_id,
3941 struct rte_eth_l2_tunnel_conf *l2_tunnel,
3945 struct rte_eth_dev *dev;
3947 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3949 if (l2_tunnel == NULL) {
3950 RTE_PMD_DEBUG_TRACE("Invalid l2_tunnel parameter\n");
3954 if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
3955 RTE_PMD_DEBUG_TRACE("Invalid tunnel type.\n");
3960 RTE_PMD_DEBUG_TRACE("Mask should have a value.\n");
3964 dev = &rte_eth_devices[port_id];
3965 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
3967 return eth_err(port_id, (*dev->dev_ops->l2_tunnel_offload_set)(dev,
3968 l2_tunnel, mask, en));
3972 rte_eth_dev_adjust_nb_desc(uint16_t *nb_desc,
3973 const struct rte_eth_desc_lim *desc_lim)
3975 if (desc_lim->nb_align != 0)
3976 *nb_desc = RTE_ALIGN_CEIL(*nb_desc, desc_lim->nb_align);
3978 if (desc_lim->nb_max != 0)
3979 *nb_desc = RTE_MIN(*nb_desc, desc_lim->nb_max);
3981 *nb_desc = RTE_MAX(*nb_desc, desc_lim->nb_min);
3985 rte_eth_dev_adjust_nb_rx_tx_desc(uint16_t port_id,
3986 uint16_t *nb_rx_desc,
3987 uint16_t *nb_tx_desc)
3989 struct rte_eth_dev *dev;
3990 struct rte_eth_dev_info dev_info;
3992 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3994 dev = &rte_eth_devices[port_id];
3995 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
3997 rte_eth_dev_info_get(port_id, &dev_info);
3999 if (nb_rx_desc != NULL)
4000 rte_eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim);
4002 if (nb_tx_desc != NULL)
4003 rte_eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim);
4009 rte_eth_dev_pool_ops_supported(uint16_t port_id, const char *pool)
4011 struct rte_eth_dev *dev;
4013 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4018 dev = &rte_eth_devices[port_id];
4020 if (*dev->dev_ops->pool_ops_supported == NULL)
4021 return 1; /* all pools are supported */
4023 return (*dev->dev_ops->pool_ops_supported)(dev, pool);
4026 RTE_INIT(ethdev_init_log);
4028 ethdev_init_log(void)
4030 ethdev_logtype = rte_log_register("lib.ethdev");
4031 if (ethdev_logtype >= 0)
4032 rte_log_set_level(ethdev_logtype, RTE_LOG_INFO);